Commit graph

221 commits

Author SHA1 Message Date
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
qilme
8347791ce3
std.os.windows: eliminate forwarder function in kernel32 (#25766)
#1840

kernel32.AddVectoredExceptionHandler -> ntdll.RtlAddVectoredExceptionHandler
kernel32.RemoveVectoredExceptionHandler -> ntdll.RtlRemoveVectoredExceptionHandler
kernel32.ExitProcess -> ntdll.RtlExitUserProcess
kernel32.InitializeCriticalSection -> ntdll.RtlInitializeCriticalSection
kernel32.EnterCriticalSection -> ntdll.RtlEnterCriticalSection
kernel32.LeaveCriticalSection -> ntdll.RtlLeaveCriticalSection
kernel32.DeleteCriticalSection -> ntdll.RtlDeleteCriticalSection
kernel32.TryAcquireSRWLockExclusive -> ntdll.RtlTryAcquireSRWLockExclusive
kernel32.AcquireSRWLockExclusive -> ntdll.RtlAcquireSRWLockExclusive
kernel32.ReleaseSRWLockExclusive -> ntdll.RtlReleaseSRWLockExclusive
kernel32.WakeConditionVariable -> ntdll.RtlWakeConditionVariable
kernel32.WakeAllConditionVariable -> ntdll.RtlWakeAllConditionVariable
kernel32.HeapReAlloc -> ntdll.RtlReAllocateHeap
kernel32.HeapAlloc -> ntdll.RtlAllocateHeap
2025-10-31 13:54:50 +00:00
Andrew Kelley
46f7e3ea9f std.Io.Threaded: add ioBasic which disables networking 2025-10-29 06:20:51 -07:00
Andrew Kelley
aadd8d4a3e std: back out the StackTrace byval changes
Let's keep passing this thing by pointer
2025-10-29 06:20:50 -07:00
Andrew Kelley
10b1eef2d3 std: fix compilation errors on Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
2d7d98da0c std.fs: use BadPathName rather than InvalidWtf8 on Windows 2025-10-29 06:20:50 -07:00
Andrew Kelley
8a1e6c8c39 std.Io: implement dirStatPath 2025-10-29 06:20:49 -07:00
Andrew Kelley
774df26835 WIP: hack at std.Io on a plane 2025-10-29 06:20:48 -07:00
Andrew Kelley
00f26cb0a4 WIP land the std.Io interface
fix std lib compilation errors caused by introducing std.Io
2025-10-29 06:20:48 -07:00
Andrew Kelley
5469db66e4 std.Thread.ResetEvent: make it more reusable 2025-10-29 06:20:48 -07:00
Andrew Kelley
f762597724 std.Io: add asyncConcurrent and asyncParallel 2025-10-29 06:20:48 -07:00
Alex Rønne Petersen
dba1bf9353 remove all Oracle Solaris support
There is no straightforward way for the Zig team to access the Solaris system
headers; to do this, one has to create an Oracle account, accept their EULA to
download the installer ISO, and finally install it on a machine or VM. We do not
have to jump through hoops like this for any other OS that we support, and no
one on the team has expressed willingness to do it.

As a result, we cannot audit any Solaris contributions to std.c or other
similarly sensitive parts of the standard library. The best we would be able to
do is assume that Solaris and illumos are 100% compatible with no way to verify
that assumption. But at that point, the solaris and illumos OS tags would be
functionally identical anyway.

For Solaris especially, any contributions that involve APIs introduced after the
OS was made closed-source would also be inherently more risky than equivalent
contributions for other proprietary OSs due to the case of Google LLC v. Oracle
America, Inc., wherein Oracle clearly demonstrated its willingness to pursue
legal action against entities that merely copy API declarations.

Finally, Oracle laid off most of the Solaris team in 2017; the OS has been in
maintenance mode since, presumably to be retired completely sometime in the 2030s.

For these reasons, this commit removes all Oracle Solaris support.

Anyone who still wishes to use Zig on Solaris can try their luck by simply using
illumos instead of solaris in target triples - chances are it'll work. But there
will be no effort from the Zig team to support this use case; we recommend that
people move to illumos instead.
2025-10-27 07:35:38 -07:00
Alex Rønne Petersen
493889d5eb
std.Thread: implement freeAndExit() for sh-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
3777d3c25b
std.Thread: implement freeAndExit() for microblaze-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
f6c06d7069
std.Thread: implement freeAndExit() for hppa-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
de87c856e7
std.Thread: implement freeAndExit() for alpha-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
3d1b7811d4
std.Thread: implement freeAndExit() for m68k-linux 2025-10-23 09:27:17 +02:00
Alex Rønne Petersen
328b121240
Merge pull request #25627 from alexrp/qemu-10.1.1-patched
`ci`: switch to patched QEMU 10.1.1.1
2025-10-19 11:50:23 +02:00
Alex Rønne Petersen
5e57ed9fda
std.Thread: implement freeAndExit() for or1k 2025-10-18 22:27:35 +02:00
Alex Rønne Petersen
653a191965
Revert "std.Thread: disable test on armeb in addition to thumbeb"
This reverts commit a73f246b29.
2025-10-18 20:50:19 +02:00
Alex Rønne Petersen
adcfdce6be
std.Thread: fix some issues in x86_64/x32 inline asm
Wrong syscall on x32; return exit code 0 instead of 1 on both.

ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:36:26 +02:00
Alex Rønne Petersen
e59f2995a5
std.Thread: fix inline asm for mipsn32
This was using the mips64 syscalls.

ref https://github.com/ziglang/zig/issues/22189
2025-10-18 11:36:02 +02:00
usebeforefree
62e3d46287 replaced https://simonsapin.github.io/wtf-8/ with https://wtf-8.codeberg.page/ 2025-10-10 23:53:00 +02:00
mlugg
202aeacc05
std: fixes 2025-09-30 13:44:51 +01:00
Alex Rønne Petersen
a73f246b29
std.Thread: disable test on armeb in addition to thumbeb
Same falky failure on both. See ed7ff0b693.
2025-09-25 17:49:47 +02:00
Andrew Kelley
ed7ff0b693 allow some test cases to regress
tracked by #24061 - these should be re-enabled once that is solved.
2025-09-20 18:33:01 -07:00