Commit graph

1714 commits

Author SHA1 Message Date
Alex Rønne Petersen
2386bfe854
std.os.linux.start_pie: Rewrite relocate() to avoid jump tables and libcalls.
The code would cause LLVM to emit a jump table for the switch in the loop over
the dynamic tags. That jump table was far enough away that the compiler decided
to go through the GOT, which would of course break at this early stage as we
haven't applied MIPS's local GOT relocations yet, nor can we until we've walked
through the _DYNAMIC array.

The first attempt at rewriting this used code like this:

    var sorted_dynv = [_]elf.Addr{0} ** elf.DT_NUM;

But this is also problematic as it results in a memcpy() call. Instead, we
explicitly initialize it to undefined and use a loop of volatile stores to
clear it.
2024-07-30 01:26:10 +02:00
Alex Rønne Petersen
68cebde186
std.os.linux.start_pie: Inline the getDynamicSymbol() function.
On MIPS, this call will require a relocation, which we can't do until after PIE
relocations have been applied.
2024-07-30 01:26:10 +02:00
Alex Rønne Petersen
5633767b20
std.os.linux.start_pie: Add powerpc and powerpc64 support.
Closes #20305.
2024-07-30 01:26:09 +02:00
Alex Rønne Petersen
adfbd8a98b
std.os.linux.start_pie: Add mips and mips64 support. 2024-07-30 01:24:55 +02:00
Andrew Kelley
38e0f049c5
Merge pull request #20389 from alexrp/riscv32
Some `riscv32-linux` porting work
2024-07-29 16:13:35 -07:00
Ryan Liptak
efde3ed04a Fix compile error due to GetModuleFileNameW binding change
In https://github.com/ziglang/zig/pull/19641, this binding changed from `[*]u16` to `LPWSTR` which made it a sentinel-terminated pointer. This introduced a compiler error in the `std.os.windows.GetModuleFileNameW` wrapper since it takes a `[*]u16` pointer. This commit changes the binding back to what it was before instead of introducing a breaking change to `std.os.windows.GetModuleFileNameW`

Related: https://github.com/ziglang/zig/issues/20858
2024-07-29 16:06:36 -07:00
Alex Rønne Petersen
4e5068c35c
std: Stop supporting Linux/glibc versions older than declared in std.Target. 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
6eb9cb6f28
std.os.linux.tls: Handle riscv32 in setThreadPointer(). 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
aeb3abc7e6
std.os.linux.start_pie: Handle riscv32 in getDynamicSymbol(). 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
43410cdfe9
std.os.linux: Remove the sparc64 workaround in fadvise().
This does not seem to be needed anymore, and it's unclear if it was ever truly
needed or if it was just there to deal with a QEMU/strace bug.

See: https://github.com/ziglang/zig/pull/8301#issuecomment-2184995749
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
890433e292
std.os.linux: Define timespec as kernel_timespec (64-bit) for riscv32.
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
cafce8c767
std.os.linux.test: Partially skip statx() test on riscv32.
No fstatat(), so there's no point doing the rest of it.
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
7532a8a584
std.os.linux: Add riscv32 support. 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
2d1ee678eb
std.os.linux: Some adjustments after syscall generation strategy changes. 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
4e7c3cca91
std.os.linux.syscalls: Regenerate based on Linux v6.7.
loongarch64 syscalls not updated because it seems like that kernel port hasn't
been working for a year or so:

    In file included from arch/loongarch/include/uapi/asm/unistd.h:5:
    include/uapi/asm-generic/unistd.h:2:10: fatal error: 'asm/bitsperlong.h' file not found

That file is just missing from the tree. 🤷
2024-07-29 09:50:41 +02:00
matt ettler
ed7f11ffa7 chore: correct non-standard comments.
Comments throughout the codebase start with a space.
This commit corrects comments that do not adhere to this
norm.
2024-07-28 21:34:14 -07:00
Andrew Kelley
3a0da431db
Merge pull request #20667 from jayrod246/windows-watch
Build Runner: Initial Implementation for File System Watching on Windows
2024-07-28 20:35:18 -07:00
Matthew Ettler
d30d37e356
feat(std.os.uefi.protocol): add Serial IO 2024-07-28 12:37:53 +00:00
Jarrod Meyer
2de0e2eca3 Watch.zig: add initial windows implementation 2024-07-27 11:32:43 -04:00
Jarrod Meyer
2b8f444dde windows: reintroduce ReadDirectoryChangesW
- additionally, introduces FileNotifyChangeFilter to improve use/readability
2024-07-27 11:32:43 -04:00
Jarrod Meyer
9323a00067 windows: add Timeout status result for GetQueuedCompletionStatus 2024-07-27 11:32:43 -04:00
Jarrod Meyer
7434accc3d windows: make the WaitForMultipleObjectsEx assertion inclusive
- additionally, the parameter must be nonzero: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitformultipleobjects
2024-07-27 11:32:43 -04:00
Alex Rønne Petersen
66b71273a2 std.os.linux: Fix default value for perf_event_attr.clockid field.
Closes #20810.
2024-07-26 18:21:10 -07:00
Alex Rønne Petersen
38c492bb53
std.os.linux.start_pie: Add hexagon support. 2024-07-24 20:12:38 +02:00
Alex Rønne Petersen
a0b2b987c8
std.os.linux.start_pie: Add arc support. 2024-07-24 20:12:38 +02:00
Alex Rønne Petersen
bc054a713e
std.os.linux.start_pie: Add csky support. 2024-07-24 20:12:38 +02:00
Alex Rønne Petersen
2dabb7ec77
std.os.linux.start_pie: Handle armeb, thumb, thumbeb, and aarch64_be too. 2024-07-24 20:12:38 +02:00
Andrew Kelley
4de8bba648
Merge pull request #20749 from alexrp/start-pie
`std.os.linux.start_pie`: Implement `getDynamicSymbol()` for loongarch64, m68k, and s390x
2024-07-24 10:27:20 -07:00
Alex Rønne Petersen
1c6bee0834
std.os.linux.start_pie: Add s390x support. 2024-07-24 00:28:08 +02:00
Alex Rønne Petersen
6fac71ec74
std.os.linux.start_pie: Add m68k support. 2024-07-24 00:28:07 +02:00
Alex Rønne Petersen
1fd45766a7
std.os.linux.start_pie: Add loongarch support. 2024-07-24 00:27:46 +02:00
Alex Rønne Petersen
2d4fc1bb7a
std.os.linux.tls: Fix setThreadPointer() for armeb and thumbeb. 2024-07-23 21:17:29 +02:00
Alex Rønne Petersen
0473457b68
std.os.linux.tls: Set some constants correctly for powerpcle. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
c631110f5c
std.os.linux.tls: Set tls_tcb_size correctly for thumbeb. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
d694ddd279
std.os.linux.tls: Set tls_variant correctly for thumbeb. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
d2d325a862
std.os.linux.AUDIT: Fix s390x; add loongarch64 and xtensa. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
93311d6bca
std.os.linux: Also define O for armeb and thumbeb. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
92bc802033
std.os.linux: Also define MAP for armeb and thumbeb. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
fcbb192b49
std.os.linux: Define (MIN)SIGSTKSZ for all supported Linux architectures. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
b21de4de5e
std.os.linux: Define syscalls for armeb and thumbeb too. 2024-07-23 21:14:19 +02:00
Alex Rønne Petersen
b3e82b899f
std.os.linux: Import arch bits for armeb and thumbeb too. 2024-07-23 21:14:19 +02:00
Andrew Kelley
33c7984183 add std.testing.random_seed
closes #17609
2024-07-23 11:43:12 -07:00
Andrew Kelley
bde8c4a46a update start code to use @disableInstrumentation
This prevents it from trying to access thread local storage before it
has set up thread local storage, particularly when code coverage
instrumentation is enabled.
2024-07-22 14:26:17 -07:00
Nguyễn Gia Phong
d6fa71cd67
std: Wrap setpgid on POSIX 2024-07-22 11:49:55 +09:00
Gabor Lekeny
1dbee05609
std.os.linux: sched_setaffinity fix (#20357) 2024-07-21 02:39:28 -07:00
Andrew Kelley
0d1db794d5
Merge pull request #20679 from ziglang/std.c-reorg
std.c reorganization
2024-07-19 16:30:21 -07:00
Andrew Kelley
01337e2093 fix regression of flock being called on wasi targets
* common symbols are now public from std.c even if they live in
  std.posix
* LOCK is now one of the common symbols since it is the same on 100% of
  operating systems.
* flock is now void value on wasi and windows
* std.fs.Dir now uses flock being void as feature detection, avoiding
  trying to call it on wasi and windows
2024-07-19 11:35:22 -07:00
Techatrix
ebd9efa850 fix fanotify_mark on 32-bit 2024-07-19 01:40:16 -07:00
Andrew Kelley
e8c4e79499 std.c reorganization
It is now composed of these main sections:
* Declarations that are shared among all operating systems.
* Declarations that have the same name, but different type signatures
  depending on the operating system. Often multiple operating systems
  share the same type signatures however.
* Declarations that are specific to a single operating system.
  - These are imported one per line so you can see where they come from,
    protected by a comptime block to prevent accessing the wrong one.

Closes #19352 by changing the convention to making types `void` and
functions `{}`, so that it becomes possible to update `@hasDecl` sites
to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up
removing some duplicate logic and update some bitrotted feature
detection checks.

A handful of types have been modified to gain namespacing and type
safety. This is a breaking change.

Oh, and the last usage of `usingnamespace` site is eliminated.
2024-07-19 00:30:32 -07:00
Stephen Gregoratto
3095e83d11 Windows: Rework kernel32 apis
To facilitate #1840, this commit slims `std.windows.kernel32` to only
have the functions needed by the standard library. Since this will break
projects that relied on these, I offer two solutions:

- Make an argument as to why certain functions should be added back in.
  Note that they may just be wrappers around `ntdll` APIs, which would
  go against #1840.
  If necessary I'll add them back in *and* make wrappers in
  `std.windows` for it.
- Maintain your own list of APIs. This is the option taken by bun[1],
  where they wrap functions with tracing.
- Use `zigwin32`.

I've also added TODO comments that specify which functions can be
reimplemented using `ntdll` APIs in the future.

Other changes:
- Group functions into groups (I/O, process management etc.).
- Synchronize definitions against Microsoft documentation to use the
  proper parameter types/names.
- Break all functions with parameters over multiple lines.
2024-07-17 23:11:23 +10:00