Commit graph

133 commits

Author SHA1 Message Date
Alex Rønne Petersen
d1d95294fd std.Target.Cpu.Arch: Remove the aarch64_32 tag.
This is a misfeature that we inherited from LLVM:

* https://reviews.llvm.org/D61259
* https://reviews.llvm.org/D61939

(`aarch64_32` and `arm64_32` are equivalent.)

I truly have no idea why this triple passed review in LLVM. It is, to date, the
*only* tag in the architecture component that is not, in fact, an architecture.
In reality, it is just an ILP32 ABI for AArch64 (*not* AArch32).

The triples that use `aarch64_32` look like `aarch64_32-apple-watchos`. Yes,
that triple is exactly what you think; it has no ABI component. They really,
seriously did this.

Since only Apple could come up with silliness like this, it should come as no
surprise that no one else uses `aarch64_32`. Later on, a GNU ILP32 ABI for
AArch64 was developed, and support was added to LLVM:

* https://reviews.llvm.org/D94143
* https://reviews.llvm.org/D104931

Here, sanity seems to have prevailed, and a triple using this ABI looks like
`aarch64-linux-gnu_ilp32` as you would expect.

As can be seen from the diffs in this commit, there was plenty of confusion
throughout the Zig codebase about what exactly `aarch64_32` was. So let's just
remove it. In its place, we'll use `aarch64-watchos-ilp32`,
`aarch64-linux-gnuilp32`, and so on. We'll then translate these appropriately
when talking to LLVM. Hence, this commit adds the `ilp32` ABI tag (we already
have `gnuilp32`).
2024-07-28 19:44:52 -07:00
David Rubin
c20def73af
riscv: workarounds for riscv threading 2024-07-26 14:53:50 -07:00
Lucas Santos
1e74904aa2 Replace some dynamic functions with static ones.
PR [19271](https://github.com/ziglang/zig/pull/19271) added some static function implementations from kernel32, but some parts of the library still used the dynamically loaded versions.
2024-07-24 01:04:38 -07:00
Lucas Santos
89942ebd03
Better implementation of GetLastError. (#20623)
Instead of calling the dynamically loaded kernel32.GetLastError, we can extract it from the TEB.
As shown by [Wine](34b1606019/include/winternl.h (L439)), the last error lives at offset 0x34 of the TEB in 32-bit Windows and at offset 0x68 in 64-bit Windows.
2024-07-15 10:49:51 -07:00
mochalins
c8e0095362 test: Add spawn behavior test 2024-07-09 21:15:29 -04:00
Jacob Young
166402c16b bootstrap: fix build 2024-07-07 22:59:52 -04:00
Bram
5f58956264 std: Extended type checks for Thread startFn return type 2024-06-23 04:35:00 +01:00
Isaac Freund
a1777cb5cb
std: fix pthread_{get,set}name_np return type ABI
I believe this was accidentally broken when the E enum for errno values
was introduces. These functions are quite the special case in that they
return the error value directly rather than returning -1 and passing the
error value through the errno variable.

In any case, using a u16 as the return type at the ABI boundary where a
c_int is expected is asking for trouble.
2024-06-17 23:26:53 +02:00
Jakub Konka
2e1fc0dd14 handle visionos target OS tag in the compiler
* rename .xros to .visionos as agreed in the tracking issue
* add support for VisionOS platform in the MachO linker
2024-05-09 15:04:15 +02:00
Frank Denis
fefdbca6e6 Fix WASI threads, again
Properly call the entrypoint when it doesn't return an optional error,
and use the per-thread copy of the arguments list.
2024-04-22 15:27:05 -07:00
Andrew Kelley
54c08579e4
Merge pull request #19348 from jedisct1/wasi-threads-compfix
Unbreak support for WASI threads
2024-03-21 15:13:15 -07:00
Michael Dusan
e4ed63f138 bsd: followup to std.posix extraction from std.os
netbsd fix:
- `Futex.zig:542:56: error: expected error union type, found 'c_int'`

openbsd fix:
- `emutls.zig:10:21: error: root struct of file 'os' has no member named 'abort'`
- `Thread.zig:627:22: error: expected 6 argument(s), found 5`
2024-03-20 14:06:35 -07:00
Andrew Kelley
cd62005f19 extract std.posix from std.os
closes #5019
2024-03-19 11:45:09 -07:00
Frank Denis
9b454a8ce2 WASI-thread: panic if no allocator is given 2024-03-19 13:11:33 +01:00
Frank Denis
c470016743 Unbreak support for WASI threads 2024-03-18 16:51:41 +01:00
Stephen Gregoratto
9532f72937 Windows: Replace CreatePipe with ntdll implementation
This implementation is now a direct replacement for the `kernel32` one.
New bitflags for named pipes and other generic ones were added based on
browsing the ReactOS sources.

`UNICODE_STRING.Buffer` has also been changed to be nullable, as
this is what makes the implementation work.
This required some changes to places accesssing the buffer after a
`SUCCESS`ful return, most notably `QueryObjectName` which even referred
to it being nullable.
2024-03-16 23:37:50 +11:00
Tristan Ross
6067d39522
std.builtin: make atomic order fields lowercase 2024-03-11 07:09:10 -07:00
Ryan Liptak
726a1149e0 Change many test blocks to doctests/decltests 2024-02-26 15:18:31 -08:00
Ryan Liptak
16b3d1004e Remove redundant test name prefixes now that test names are fully qualified
Follow up to #19079, which made test names fully qualified.

This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit:

"priority_queue.test.std.PriorityQueue: shrinkAndFree"

and the same test's name after the changes in this commit:

"priority_queue.test.shrinkAndFree"
2024-02-26 15:18:31 -08:00
Ryan Liptak
68b87918df Fix handling of Windows (WTF-16) and WASI (UTF-8) paths
Windows paths now use WTF-16 <-> WTF-8 conversion everywhere, which is lossless. Previously, conversion of ill-formed UTF-16 paths would either fail or invoke illegal behavior.

WASI paths must be valid UTF-8, and the relevant function calls have been updated to handle the possibility of failure due to paths not being encoded/encodable as valid UTF-8.

Closes #18694
Closes #1774
Closes #2565
2024-02-24 14:05:24 -08:00
Ryan Liptak
80508b98c2 Update deprecated std.unicode function usages 2024-02-24 14:04:59 -08:00
Andrew Kelley
9f3165540e std.os.linux.MAP: use a packed struct
Introduces type safety to this constant. Eliminates one use of
`usingnamespace`.
2024-02-06 21:12:11 -07:00
Christian Flicker
9c7fa358c1
std.Thread: fix off-by-one in PosixThreadImpl (#18711)
by removing ZST special case
2024-01-29 11:07:21 -05:00
Leonardo Gatti
4129996211 doc: possible typo at std.Thread.spawn comment 2023-12-30 14:17:36 +02:00
Andrew Kelley
70931dbdea rework std.atomic
* move std.atomic.Atomic to std.atomic.Value
* fix incorrect argument order passed to testing.expectEqual
* make the functions be a thin wrapper over the atomic builtins and
  stick to the naming conventions.
* remove pointless functions loadUnchecked and storeUnchecked. Instead,
  name the field `raw` instead of `value` (which is redundant with the
  type name).
* simplify the tests by not passing every possible combination. Many
  cases were iterating over every possible combinations but then not
  even using the for loop element value!
* remove the redundant compile errors which are already implemented by
  the language itself.
* remove dead x86 inline assembly. this should be implemented in the
  language if at all.
2023-11-22 19:08:55 -07:00
XXIV
34aac2bae1
std/Thread: remove unnecessary @ptrCast (#17766) 2023-10-31 00:17:39 -04:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00
Andrew Kelley
e84cda0ebf
Merge pull request #16622 from jacobly0/cbe-asm-compat
CBE: fix regressions and get new targets passing behavior tests
2023-07-31 15:34:32 -07:00
Andrew Kelley
1b9ffa0824 Revert "std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791)"
This reverts commit 41502c6aa5.
2023-07-31 10:54:35 -07:00
Jacob Young
817fa3af86 std: cleanup asm usage
After fixing some issues with inline assembly in the C backend, the std
cleanups have the side effect of making these functions compatible with
the backend, allowing it to be used on linux without linking libc.
2023-07-31 01:58:10 -04:00
Jim Price
584b062a30
Fix counting in SingleThreadedRwLock's tryLockShared (#16560)
Additionally we add RwLock to Thread.zig's list of tests
2023-07-26 08:19:52 -05:00
Luuk de Gram
87b8a0567b
default to single-threaded for WebAssembly
When targeting WebAssembly, we default to building a single-threaded build
as threads are still experimental. The user however can enable a multi-
threaded build by specifying '-fno-single-threaded'. It's a compile-error
to enable this flag, but not also enable shared-memory.
2023-06-26 20:00:58 +02:00
Luuk de Gram
e06ab1b010
std: implement detach for WASI-threads
When a thread is detached from the main thread, we automatically
cleanup any allocated memory. For this we first reset the stack-pointer
to the original stack-pointer of the main-thread so we can safely clear
the memory which also contains the thread's stack.
2023-06-26 20:00:58 +02:00
Luuk de Gram
622b7c4746
free allocated memory upon call join
When `join` detects a thread has completed, it will free the allocated
memory of the thread. For this we must first copy the allocator. This is
required as the allocated memory holds a reference to the original
allocator. If we free the memory, we would end up with UB as the
allocator would free itself.
2023-06-26 20:00:57 +02:00
Luuk de Gram
834609038c
std: implement join for WASI-threads
We now reset the Thread ID to 0 and wake up the main thread listening
for the thread to finish. We use inline assembly as we cannot use
the stack to set the thread ID as it could possibly clobber any
of the memory.

Currently, we leak the memory that was allocated for the thread.
We need to implement a way where we can clean up the memory without
using the stack (as the stack is stored inside this same memory).
2023-06-26 20:00:57 +02:00
Luuk de Gram
10bf58b2db
store allocator & remove global assembly
We now store the original allocator that was used to allocate the
memory required for the thread. This allocator can then be used
in any cleanup functionality to ensure the memory is freed correctly.

Secondly, we now use a function to set the stack pointer instead of
generating a function using global assembly. This is a lot cleaner
and more readable.
2023-06-26 20:00:57 +02:00
Luuk de Gram
a97dbdfa0b
std: implement Thread spawn for WASI
This implements a first version to spawn a WASI-thread. For a new thread
to be created, we calculate the size required to store TLS, the new stack,
and metadata. This size is then allocated using a user-provided allocator.

After a new thread is spawn, the HOST will call into our bootstrap procedure.
This bootstrap procedure will then initialize the TLS segment and set the
newly spawned thread's TID. It will also set the stack pointer to the newly
created stack to ensure we do not clobber the main thread's stack.

When bootstrapping the thread is completed, we will call the user's
function on this new thread.
2023-06-26 20:00:57 +02:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Andrew Kelley
96acc204b2
Merge pull request #16052 from mikdusan/bsd-getdents
fix bad return types for BSDs getdents and debitrot openbsd
2023-06-17 13:01:52 -07:00
Motiejus Jakštys
d41111d7ef mem: rename align*Generic to mem.align*
Anecdote 1: The generic version is way more popular than the non-generic
one in Zig codebase:

     git grep -w alignForward | wc -l
    56
     git grep -w alignForwardGeneric | wc -l
    149

     git grep -w alignBackward | wc -l
    6
     git grep -w alignBackwardGeneric | wc -l
    15

Anecdote 2: In my project (turbonss) that does much arithmetic and
alignment I exclusively use the Generic functions.

Anecdote 3: we used only the Generic versions in the Macho Man's linker
workshop.
2023-06-17 12:49:13 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Michael Dusan
40fc71bf71
openbsd: fix std.c.getdents and debitrot
- fix getdents return type usize → c_int
- special-case process.zig to use sysctl instead of sysctlbyname
- use struct/field pattern for sysctl HW_* constants
2023-06-15 14:48:20 -04:00
David CARLIER
41502c6aa5
std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791) 2023-05-25 14:32:17 -05:00
Linus Groh
94e30a756e std: fix a bunch of typos
The majority of these are in comments, some in doc comments which might
affect the generated documentation, and a few in parameter names -
nothing that should be breaking, however.
2023-04-30 18:16:04 -07:00
Andrew Kelley
6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
Jacob Young
3f1c51ca90 std: remove names from incorrectly named tests
Tests that only reference decls for the purpose of analyzing more tests
should be unnamed, otherwise trying to filter for just a referenced test
can become impossible depending on the names.
2023-04-21 23:08:48 -04:00
Andrew Kelley
a1f7c8d860
Merge pull request #14696 from r00ster91/thread
std.Thread: use dead code
2023-04-20 16:03:12 -07:00
Michael Dusan
490a411fd4 openbsd: fix thread name buffer size
OpenBSD 7.3 changed its implementation of
pthread_get_name_np/pthread_set_name_np to wrap new libc functions
getthrname/setthrname and lowered the max buffer size from 32 to 24.

This is not a backwards-compatible change because if we were to put in
comptime version logic to use size 32 when target < 7.3 the binaries
would be undefined when running on >= 7.3. It also could simply be that
OpenBSD has a policy to not support older binaries running on newer
releases? Regardless, the safest course is to simply use the smallest
known buffer size.

As an aside, this bug manifested as a "hung" std.Thread test because 7.3
pthread API never checks for error result when wrapping getthrname/setthrname.
This is not a problem in std.Thread when we use the correct max buffer
size because ERANGE/EINVAL become unreachable.
2023-04-12 15:36:03 -04:00
Andrew Kelley
5b90fa05a4 extract ThreadPool and WaitGroup from compiler to std lib 2023-03-15 10:48:12 -07:00