0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
Commit graph

246 commits

Author SHA1 Message Date
Alex Rønne Petersen
5cbafcfd56
std.Thread: remove pointless clobbers in LinuxThreadImpl.freeAndExit()
The function is noreturn and destroys the thread; clobbers serve no purpose.

Also remove a pointless blr in the powerpc prong.
2026-08-09 17:53:04 +02:00
Alex Rønne Petersen
5102fe31bd
std.Thread: fix typo in or1k LinuxThreadImpl.freeAndExit() 2026-08-09 17:53:04 +02:00
Alex Rønne Petersen
f0292b5703
std.Thread: remove mips o32 workaround in LinuxThreadImpl.freeAndExit()
Our minimum kernel version was released several years after this kernel bug was
fixed. On top of that, it's a hacky workaround that depends on abicalls to work.
Well past time to get rid of it.
2026-08-09 17:53:03 +02:00
Alex Rønne Petersen
3b947932ab
std: avoid pointless delay slots and lr writes in inline assembly
And fill in some delay slots where we can't avoid them.
2026-08-09 16:56:23 +02:00
Elaine Gibson
ad6a79f327 std.c.haiku: cleanup 2026-08-03 09:59:04 +01:00
Elaine Gibson
12dc2f2611 std: pass null for infinite NtWaitForSingleObject timeout
fixes #31954
2026-08-02 12:04:20 +02:00
Alex Rønne Petersen
2085096f50
std.Thread: fix freeAndExit() on sparc[64]-linux hardware
On SPARC, the kernel needs to be able to restore the current register window
from the stack when returning from a syscall. That presents a bit of a problem
in freeAndExit() since we're deallocating the stack! The good news is that,
since we do not care about the contents of the incoming and local registers at
that point, we can just tell the kernel that our stack is an undefined global
buffer.

This didn't manifest in QEMU but does reproduce deterministically on a real
kernel/machine.
2026-08-01 15:20:07 +02:00
Justus Klausecker
69a26976ed zig fmt
Converts usages of `@intFromEnum` and `@enumFromInt` to instead use the
new `@backingInt` and `@fromBackingInt` builtins.
2026-07-17 23:30:26 +02:00
Alex Rønne Petersen
6aaea5af41
std.Target: add abin32 and x32 Abi tags
We only had gnu/musl variants of these previously.
2026-06-18 02:37:52 +02:00
Alex Rønne Petersen
df3a4468f1
std: fix some mistakes in microblaze inline asm 2026-06-04 16:08:36 +02:00
Alex Rønne Petersen
cefd23c9bc
std.Thread: fix comment syntax in 32-bit sparc inline asm 2026-06-04 00:54:35 +02:00
Alex Rønne Petersen
ef6341ee8d Merge pull request 'std: add missing csky-linux bits' (#35548) from alexrp/zig:csky-linux into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35548
2026-05-30 23:17:52 +02:00
Alex Rønne Petersen
9c58eb4a84
std.Thread: implement LinuxThreadImpl.freeAndExit() for csky 2026-05-30 20:55:06 +02:00
Alex Rønne Petersen
14b43a0e9e
std.Thread: implement LinuxThreadImpl.freeAndExit() for arc 2026-05-30 18:49:44 +02:00
Alex Rønne Petersen
b0bda2d744
std.Thread: implement LinuxThreadImpl.freeAndExit() for xtensa 2026-05-26 08:11:04 +02:00
Mai-Lapyst
7534ac7367
Adding more support for DEC Alpha to std
This adds support to std, primarily for linux, to support the Alpha architecture.

closes #30940
closes #30926
2026-05-23 06:15:24 +02:00
jeffkdev
0cdc2fa5fb fix getCpuCount() for emscripten 2026-05-04 16:56:48 -04:00
Matthew Lugg
fdac89d6cd
remove uses of array multiplication
In preparation for its removal as accepted in
https://github.com/ziglang/zig/issues/24738.
2026-04-30 08:57:51 +01:00
Mason Remaley
87fb7df257 Updates stack trace vs error return trace in more places 2026-04-12 04:01:30 -07:00
Brandon Black
1226bb9268 LinuxThreadImpl: be precise in tls.prepareArea arg
This isn't causing any functional problem today, but technically
`mapped[tls_offset..]` runs past the tls part of `mapped` and into
the `Instance` storage, and currently `prepareArea()` memsets its
entire argument to zero.  It is only the current layout and
initialization order of `mapped` that prevents this from being a
problem.  Being more precise here avoids future footguns if any of
that changes.
2026-03-31 14:48:03 -05:00
Brandon Black
614cd66e7e LinuxThreadImpl: clear tidptr during detached exit
Fixes: #31714
2026-03-31 14:47:44 -05:00
rpkak
8f6bad065e std.Thread.setName/getName: remove wrong error handling
std.posix.prctl already does error handling.
According to the man page PR_SET_NAME(2const), 0 is returned on success.
2026-03-25 08:10:25 +01:00
Jacob Young
3c8b96df6d windows: use enums for boolean types 2026-03-20 02:25:16 +01:00
Jacob Young
9ac1386c10 std.Io.Threaded: windows networking without ws2_32 2026-03-18 20:13:59 -04:00
inf
c38e6ed686 feat: remove kernel32.CreateThread, implement ntdll.NtCreateThreadEx inside WindowsThreadImpl (#31519)
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31519
Reviewed-by: Ryan Liptak <squeek502@noreply.codeberg.org>
Co-authored-by: inf <infirms@protonmail.com>
Co-committed-by: inf <infirms@protonmail.com>
2026-03-17 23:06:55 +01:00
Jacob Young
b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Jacob Young
ffc6da29e3 std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05:00
Andrew Kelley
d45f9aca14 std.Thread: delete Mutex.Recursive
Replaced by the lockStderr functions of std.Io. Trying to make
`std.process.stderr_thread_mutex` be a bridge across different Io
implementations didn't work in practice.
2026-02-03 20:46:25 -08:00
Andrew Kelley
550da1b676 std: migrate remaining sync primitives to Io
- delete std.Thread.Futex
- delete std.Thread.Mutex
- delete std.Thread.Semaphore
- delete std.Thread.Condition
- delete std.Thread.RwLock
- delete std.once

std.Thread.Mutex.Recursive remains... for now. it will be replaced with
a special purpose mechanism used only by panic logic.

std.Io.Threaded exposes mutexLock and mutexUnlock for the advanced case
when you need to call them directly.
2026-02-02 18:57:17 -08:00
Andrew Kelley
b191e50be5 std.Thread: remove ResetEvent and WaitGroup
* std.Thread.ResetEvent -> Io.Event
* std.Thread.WaitGroup -> Io.Group
2026-02-02 00:09:48 -08:00
Andrew Kelley
36eb8dec98 std.posix: goodbye to some functions
- fstat
- inotify_init1
- inotify_add_watch, inotify_add_watchZ
- inotify_rm_watch
- sysctlbynameZ
2026-01-30 01:58:49 -08:00
Matthew Lugg
85cac9e5b6 std: use sigaltstack for default segfault handler
This allows stack overflows to print stack traces. The size of the
sigaltstack (and whether it is actually set) can be configured by
setting `std.Options.signal_stack_size`.

The default value for the signal stack size was chosen experimentally by
doubling the value required to get stack traces on stack overflow with
the self-hosted x86_64 backend. While some targets may typically use
more stack space than x86_64-linux, the self-hosted x86_64 backend is
quite wasteful with stack at the moment, making it a fair benchmark.
Executables produced by the LLVM backend should have lower stack usage.
2026-01-13 07:24:49 +01:00
Andrew Kelley
4d6d2922b8 std: move memory locking and memory protection to process
and introduce type safety for posix.PROT (mmap, mprotect)

progress towards #6600
2026-01-09 13:52:00 -08:00
Andrew Kelley
2f372b3dc0 goodbye posix.write
see #6600
2026-01-07 17:33:06 -08:00
Matthew Lugg
073ef0f393
std.Thread: mask all signals before unmapping stack
As the comment explains, if a signal were to arrive between a detached
thread's `munmap` and `exit` calls, the signal handler would immediately
trigger SIGSEGV due to the stack being unmapped. To solve this, we need
to block all signals before entering this logic. The musl implementation
which this logic was ported from does this exact thing; that logic was
just lost when porting.

Notably, this would lead to a crash with no stack trace, because the
SIGSEGV handler would itself crash due to the missing stack.
2026-01-06 11:15:33 +00:00
Matthew Lugg
0cbaaa5eb9 std.Thread: stop clobbering syscall args
TL;DR: "r" considered harmful.

If LLVM chose registers badly, the inline asm which cleans up a thread
on Linux could, on all architectures other than x86_64, clobber either
`munmap` argument with the other argument *or* with the syscall number.
This would cause munmap to return EINVAL, and we would literally *never*
free the thread memory, which isn't ideal.

As it turns out, this was happening on MIPS, and was the cause of the
failures we've recently been seeing for that target: QEMU genuinely was
running out of memory (or at least, the virtualized address space was
getting too fragmented to map many contiguous pages). I've therefore
re-enabled a test which was disabled due to that flakiness.

This bug was accidentally fixed for x86_64 back in 2022 (see 59e33b447),
which probably helped it to go unnoticed for as long as it did!

Resolves: https://codeberg.org/ziglang/zig/issues/30216
2026-01-04 01:35:27 +01:00
Andrew Kelley
7c1236e267 std: different way of doing some options
to avoid dependency loops
2025-12-23 22:15:12 -08:00
Andrew Kelley
3c2f5adf41 std: integrate Io.Threaded with environment variables
* std.option allows overriding the debug Io instance
* if the default is used, start code initializes environ and argv0

also fix some places that needed recancel(), thanks mlugg!

See #30562
2025-12-23 22:15:12 -08:00
Andrew Kelley
77d2ad8c92 std: consolidate all instances of std.Io.Threaded into a singleton
It's better to avoid references to this global variable, but, in the
cases where it's needed, such as in std.debug.print and collecting stack
traces, better to share the same instance.
2025-12-23 22:15:11 -08:00
Andrew Kelley
7ce5ee2e92 std: update remaining unit tests for std.Io API changes 2025-12-23 22:15:10 -08:00
Andrew Kelley
f53248a409 update all std.fs.cwd() to std.Io.Dir.cwd() 2025-12-23 22:15:08 -08:00
Andrew Kelley
8328de24f1 update all occurrences of openFile to receive an io instance 2025-12-23 22:15:08 -08:00
Andrew Kelley
3204fb7569 update all occurrences of std.fs.File to std.Io.File 2025-12-23 22:15:07 -08:00
Andrew Kelley
aafddc2ea1 update all occurrences of close() to close(io) 2025-12-23 22:15:07 -08:00
Matthew Lugg
23e5a17187
std: delete Thread.Pool in favour of Io 2025-12-22 12:55:16 +00:00
Jacob Young
c13857e504 windows: type safety improvements and more ntdll functions 2025-12-12 01:58:21 -05:00
Andrew Kelley
7096e66ca9 std.Thread: update doc comments 2025-11-21 19:54:41 -08:00
rpkak
6b4f45f782 system specific errno 2025-11-20 15:03:23 -08:00
Alex Rønne Petersen
83d9a5968f
std.Thread: disable thread local storage test on 32-bit targets
https://github.com/ziglang/zig/issues/25498
2025-11-16 00:08:20 +01:00
Alex Rønne Petersen
9ab7eec23e represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi
Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct
OS target. Earlier, when DriverKit support was added to LLVM, it was represented
a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in
the target triple is beyond me. But this isn't the first time they've ignored
established target triple norms (see: armv7k and aarch64_32) and it probably
won't be the last.

While doing this, I also audited all Darwin OS prongs throughout the codebase
and made sure they cover all the tags.
2025-11-14 11:33:35 +01:00