Commit graph

607 commits

Author SHA1 Message Date
Meghan Denny
a5cfa3db3a std.os: handle ENOENT for fnctl on macos 2025-05-09 11:20:42 +02:00
Alex Rønne Petersen
88e8e9fb91
std: Remove some FreeBSD version checks and resulting dead code.
We now require FreeBSD 13.4+.
2025-04-06 08:05:04 +02:00
Pat Tullmann
14c046fc07 lib/std: PermissionDenied/AccessDenied cleanup and fallout
This PR consistently maps .ACCES into AccessDenied and .PERM into
PermissionDenied.  AccessDenied is returned if the file mode bit
(user/group/other rwx bits) disallow access (errno was `EACCES`).
PermissionDenied is returned if something else denies access (errno was
`EPERM`) (immutable bit, SELinux, capabilities, etc).  This somewhat
subtle distinction is a POSIX thing.

Most of the change is updating std.posix Error Sets to contain both
errors, and then propagating the pair up through caller Error Sets.

Fixes #16782
2025-03-24 16:20:45 +01:00
Linus Groh
f660675467 std: Add support for SerenityOS in various places
Not nearly the entire downstream patchset but these are completely
uncontroversial and known to work.
2025-03-11 14:59:42 +00:00
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05: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
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
Ryan Liptak
76fb2b685b std: Convert deprecated aliases to compile errors and fix usages
Deprecated aliases that are now compile errors:

- `std.fs.MAX_PATH_BYTES` (renamed to `std.fs.max_path_bytes`)
- `std.mem.tokenize` (split into `tokenizeAny`, `tokenizeSequence`, `tokenizeScalar`)
- `std.mem.split` (split into `splitSequence`, `splitAny`, `splitScalar`)
- `std.mem.splitBackwards` (split into `splitBackwardsSequence`, `splitBackwardsAny`, `splitBackwardsScalar`)
- `std.unicode`
  + `utf16leToUtf8Alloc`, `utf16leToUtf8AllocZ`, `utf16leToUtf8`, `fmtUtf16le` (all renamed to have capitalized `Le`)
  + `utf8ToUtf16LeWithNull` (renamed to `utf8ToUtf16LeAllocZ`)
- `std.zig.CrossTarget` (moved to `std.Target.Query`)

Deprecated `lib/std/std.zig` decls were deleted instead of made a `@compileError` because the `refAllDecls` in the test block would trigger the `@compileError`. The deleted top-level `std` namespaces are:

- `std.rand` (renamed to `std.Random`)
- `std.TailQueue` (renamed to `std.DoublyLinkedList`)
- `std.ChildProcess` (renamed/moved to `std.process.Child`)

This is not exhaustive. Deprecated aliases that I didn't touch:
  + `std.io.*`
  + `std.Build.*`
  + `std.builtin.Mode`
  + `std.zig.c_translation.CIntLiteralRadix`
  + anything in `src/`
2024-06-13 10:18:59 -04: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
Andrew Kelley
8c94950c24 fix compilation failures found by CI 2024-03-19 16:18:18 -07:00
Andrew Kelley
cd62005f19 extract std.posix from std.os
closes #5019
2024-03-19 11:45:09 -07:00
Veikka Tuominen
e6f74b78ef std: define error set of toPosixPath 2024-03-17 09:06:54 +02:00
Tristan Ross
6067d39522
std.builtin: make atomic order fields lowercase 2024-03-11 07:09:10 -07:00
Jacob Young
f446d8e8f9 posix: @as and other general cleanup 2024-02-28 04:30:49 +01:00
Jacob Young
17d0bb5bea posix: fix socket fd leaks 2024-02-28 04:09:14 +01:00
Ryan Liptak
ae7f3fc360 Eliminate error.InvalidHandle from OpenError and RealPathError
InvalidHandle in OpenError is no longer a possible error on any platform. In the past it was able to be returned in `openOptionsFromFlagsWasi`, but the implementation was changed in 7680c5330c to make it no longer possible.

InvalidHandle in RealPathError was a holdover from before d5312d53a0, which made realpath a compile error on WASI. However, InvalidHandle was also a possible error in the FreeBSD fallback implementation added in 537624734c. This commit changes the FreeBSD fallback implementation to return FileNotFound instead of InvalidHandle which matches how EBADF is handled in all the other `realpath` implementations (including the FreeBSD non-fallback implementation).

Closes #19084
2024-02-27 15:59:50 -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
Andrew Kelley
6fddc9cd3d
Merge pull request #19064 from ziglang/fix-netname-deleted
std: map NETNAME_DELETED to error.ConnectionResetByPeer
2024-02-24 10:03:40 -08:00
Andrew Kelley
9812bc7b10 std: map NETNAME_DELETED to error.ConnectionResetByPeer
This was observed in writing to a network stream that was closed on the
read end.
2024-02-24 04:16:53 -07:00
Jae B
7f11c19450 use @trap instead of system.abort for emscripten 2024-02-23 22:23:51 -08:00
Andrew Kelley
6129ecd4fe std.net, std.http: simplify 2024-02-23 02:37:11 -07:00
Jae B
241e100827 update root.os.system override to require "system" field, this allows easier overriding of os.heap.page_allocator 2024-02-22 21:33:58 +02:00
Andrew Kelley
0183b44bb1 std.os.windows: add error.UnrecognizedVolume
Thanks to @matklad for finding this additional NTSTATUS possibility when
calling GetFinalPathNameByHandle.
2024-02-16 00:20:57 -08:00
Tim Culverhouse
bec8511728 std.os: export T struct and winsize struct
Export the T struct and winsize struct for targets which have it defined
in std.c. This struct defines libc constants for ioctl syscalls.
2024-02-14 17:53:37 -08:00
Andrew Kelley
07c1dd3d1d std.os.windows.OpenFile: add missing error
Encountered in a recent CI run on an aarch64-windows dev kit.

Pretty sure I disabled the virus scanner but it looks like it turned
itself back on with a Windows Update.

Rather than marking the new error code as unreachable in the places
where it is unexpected, this commit makes it return `error.Unexpected`.
2024-02-14 11:14:43 -08:00
Andrew Kelley
5f92558290 std.posix.termios: bring V back
In d7563a7753, I misunderstood what `cc_t`
was supposed to do. Those V enum values are indices into the array.
2024-02-13 20:10:32 -08:00
Andrew Kelley
ce3bd51597 std.os.termios: move it to be with the group 2024-02-12 21:58:37 -07:00
Andrew Kelley
a280ff2767 std.os.termios: add type safety to lflag field
This creates `tc_cflag_t` even though such a type is not defined by
libc.

I also collected the missing flag bits from all the operating systems.
2024-02-12 21:21:45 -07:00
Andrew Kelley
e97fa8b038 std.os.termios: add type safety to cflag field
This creates `tc_cflag_t` even though such a type is not defined by
libc.

I also collected the missing flag bits from all the operating systems.
2024-02-12 18:24:07 -07:00
Andrew Kelley
20abc0caee std.os.termios: add type safety to oflag field
This creates `tc_oflag_t` even though such a type is not defined by
libc.

I also collected the missing flag bits from all the operating systems.
2024-02-12 17:28:09 -07:00
Andrew Kelley
47643cc5cc std.os.termios: add type safety to iflag field
This creates `tc_iflag_t` even though such a type is not defined by
libc.

I also collected the missing flag bits from all the operating systems.
2024-02-12 16:43:51 -07:00
Andrew Kelley
0c88f927f1 std.os.termios: consolidate and correct 2024-02-12 16:21:21 -07:00
Andrew Kelley
5258c3caad std: add type safety to cc_t 2024-02-12 15:41:38 -07:00
Andrew Kelley
7680c5330c some API work on std.c, std.os, std.os.wasi
* std.c: consolidate some definitions, making them share code. For
  example, freebsd, dragonfly, and openbsd can all share the same
  `pthread_mutex_t` definition.
* add type safety to std.c.O
  - this caught a bug where mode flags were incorrectly passed as the
    open flags.
* 3 fewer uses of usingnamespace keyword
* as per convention, remove purposeless field prefixes from struct field
  names even if they have those prefixes in the corresponding C code.
* fix incorrect wasi libc Stat definition
* remove C definitions from incorrectly being in std.os.wasi
* make std.os.wasi definitions type safe
* go through wasi native APIs even when linking libc because the libc
  APIs are problematic and wasteful
* don't expose WASI definitions in std.posix
* remove std.os.wasi.rights_t.ALL: this is a footgun. should it be all
  future rights too? or only all current rights known? both are
  the wrong answer.
2024-02-11 13:38:55 -07:00
Andrew Kelley
54bbc73f85
Merge pull request #18712 from Vexu/std.options
std: make options a struct instance instead of a namespace
2024-02-09 13:38:42 -08:00
Andrew Kelley
a60f219660 std.c.MAP: use a packed struct
Same as previous commit, but for the libc interface.
2024-02-06 22:06:01 -07: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
Veikka Tuominen
a4f27e8987 remove std.io.Mode 2024-02-01 15:22:36 +02:00
Krzysztof Wolicki
d8981dc493
std.os: fix chdirZ to compile on Windows (#18695) 2024-01-29 21:19:07 -05:00
Andrew Kelley
09074d7cd7 std.os: proper use of inline
Uses `inline` only to forward the comptime-ness of the flags parameter
to function selection.

Also fixes doc comments in std.c.versionCheck.
2024-01-13 23:56:32 -07:00
Stephen Gregoratto
bc69d62669 Linux: Add fchmodat fallback when flags is nonzero
The check for determining whether to use the fallback code has been
moved into an inline function as per Andrew's comments in #17954.
2024-01-13 23:52:01 -07:00
Meghan Denny
f49a8c5431 std: make c.versionCheck() a comptime-known function 2024-01-12 16:17:39 -08:00
xdBronch
a817e27c7d use linux.perf_event_open directly 2023-12-11 17:48:18 +02:00
Carter Snook
d270020114
std.os.dl_iterate_phdr: remove u16 error cast 2023-12-08 16:10:33 +02:00
Lauri Tirkkonen
19af8aac82 os: expect ETIMEDOUT, ECONNRESET, ENOTCONN from recvfrom & read family
reads on eg. connected TCP sockets can fail with ETIMEDOUT, and ENOTCONN
happens eg. if you try to read a TCP socket that has not been connected
yet.

interestingly read() was already handling CONNRESET & TIMEDOUT, but
readv(), pread(), and preadv() were somewhat inconsistent.
2023-11-26 21:35:36 -05:00
Andrew Kelley
2bffd81015
Merge pull request #18085 from ziglang/std-atomics
rework std.atomic
2023-11-23 04:55:28 -05: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
Andrew Kelley
519ba9bb65 Revert "Merge pull request #12060 from Vexu/IterableDir"
This reverts commit da94227f78, reversing
changes made to 8f943b3d33.

I was against this change originally, but decided to approve it to keep
an open mind. After a year of trying it in practice, I firmly believe
that the previous way of doing it was better.
2023-11-22 12:35:33 -07:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
LordMZTE
b3aaf854cd std.os: do nothing when calling fchdir with AT_FDCWD 2023-10-21 05:13:21 -04:00