Commit graph

109 commits

Author SHA1 Message Date
John Benediktsson
53598e36e8
std.posix: adding getsockopt (#22335) 2025-01-30 16:09:29 +00:00
Michael Dusan
cd365b8b82 std: fix comptime SemanticVersion expr regression
- effects FreeBSD memfd and Windows DeleteFile
- regression: e5d5a8bc4e
2025-01-30 04:35:27 +01:00
Meghan Denny
0bf57b7114 std: mkdir(2) mode uses mode_t 2025-01-29 14:57:07 +01:00
thejohnny5
78b7a446f0 std: add optional times pointer for futimes, futimens, utimes, utimensat 2025-01-29 09:17:20 +01:00
Pierre Tachoire
f3c29dcb24 std.posix.setsockopt: EOPNOTSUPP can be returned
On Linux, set REUSEPORT option on an unix socket returns a EOPNOTSUPP
error.
See 5b0af621c3
2025-01-23 14:35:57 +01:00
Andrew Kelley
1110950528 std.posix.WriteError: update AccessDenied docs
It can happen on POSIX too.
2025-01-20 21:08:44 -08:00
Bryce Vandegrift
e4d5706957 std.posix: Fix errno 13 when writing to file 2025-01-20 21:07:49 -08:00
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
mlugg
d00e05f186
all: update to std.builtin.Type.Pointer.Size field renames
This was done by regex substitution with `sed`. I then manually went
over the entire diff and fixed any incorrect changes.

This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since
my regex happened to also trigger here. I opted to leave these changes
in, since they *are* a correct migration, even if they're not the one I
was trying to do!
2025-01-16 12:46:29 +00:00
Andrew Kelley
7ff42eff91 std.Build.Cache.hit: work around macOS kernel bug
The previous commit cast doubt upon the initial report about macOS
kernel behavior, identifying another reason that ENOENT could be
returned from file creation.

However, it is demonstrable that ENOENT can be returned for both cases:
1. create file race
2. handle refers to deleted directory

This commit re-introduces the workaround for the file creation race on
macOS however it does not unconditionally retry - it first tries again
with O_EXCL to disambiguate the error condition that has occurred.
2024-12-11 11:56:44 -08:00
Andrew Kelley
d37ee79535 std.Build.Cache.hit: more discipline in error handling
Previous commits

2b0929929d
4ea2f441df

had this text:

> There are no dir components, so you would think that this was
> unreachable, however we have observed on macOS two processes racing to
> do openat() with O_CREAT manifest in ENOENT.

This appears to have been a misunderstanding based on the issue
report #12138 and corresponding PR #12139 in which the steps to
reproduce removed the cache directory in a loop which also executed
detached Zig compiler processes.

There is no evidence for the macOS kernel bug however the ENOENT is
easily explained by the removal of the cache directory.

This commit reverts those commits, ultimately reporting the ENOENT as an
error rather than repeating the create file operation. However this
commit also adds an explicit error set to `std.Build.Cache.hit` as well
as changing the `failed_file_index` to a proper diagnostic field that
fully communicates what failed, leading to more informative error
messages on failure to check the cache.

The equivalent failure when occuring for AstGen performs a fatal process
kill, reasoning being that the compiler has an invariant of the cache
directory not being yanked out from underneath it while executing. This
could be made a more granular error in the future but I suspect such
thing is not valuable to pursue.

Related to #18340 but does not solve it.
2024-12-10 18:11:12 -08:00
saurabh
c172877b81
std.posix: map errno 6 (ENXIO) to error.NoDevice in write() (#22113)
Co-authored-by: Saurabh <saurabhm@proton.me>
2024-12-11 00:06:51 +01:00
Justin Braben
d16a9b0acb
std.os.windows: Map PIPE_NOT_AVAILABLE from OpenFile() to error.NoDevice (#21938) 2024-11-27 22:33:29 +01:00
Bruno Reis
c2db5d9cd1 treat errno(6) (NXIO) as expected error in openatZ 2024-11-24 18:17:56 -05:00
Benjamin Hetz
c59aee03c8 Flags for SIOC{G,S}IFFLAGS 2024-11-13 06:11:39 +01:00
PauloCampana
e6989fe637
std: fix compiler errors
See: #20505, #21094
2024-11-12 22:08:27 +01:00
Michael Dusan
e535e65eb3
freebsd posix: add SystemOutdated to MemFdCreateError 2024-10-07 13:19:33 -04:00
Jonathan Marler
73de620ad5 std.os.windows.ReadFile: handle ERROR_LOCK_VIOLATION
fixes #21500
2024-10-05 00:36:49 -07:00
Chris Boesch
e22d79dacb
std.posix: Added error message 'ProcessNotFound' for reading and writing in a Linux process (#21430)
* Added error message 'ProcessNotFound' for reading and writing in a Linux
process.
This error occurs if the process to be read from or written to no longer exists.
Fixes #19875

* Added error message "ProcessNotFound" for error forwarding.

* Add error messgae for forwarding.

* Added message for forwarding.

* Error set completed.

* Fixed format error.

* Changed comments to doc comments.
2024-10-03 01:54:30 +00:00
Andrew Kelley
4442288656 std: fix inappropriate use of unreachable in fanotify_init 2024-09-25 16:07:04 -07:00
Hila Friedman
a76e98e7d5 remove length assertion from mprotect 2024-08-31 20:59:47 -07:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
mlugg
6808ce27bd
compiler,lib,test,langref: migrate @setCold to @branchHint 2024-08-27 00:44:35 +01:00
bilaliscarioth
df6907f601
openbsd: adding EPERM for msync() against hitting a immutable region page (#18701) 2024-08-23 14:28:00 +00:00
Jan Hendrik Farr
ca012e5b69 std.posix: read on timerfd can return error.Canceled 2024-08-08 01:12:26 -07:00
Pat Tullmann
4d6429fc4f POSIX link() syscall only takes two arguments (no flags)
The signature is documented as:

   int link(const char *, const char *);

(see https://man7.org/linux/man-pages/man2/link.2.html or https://man.netbsd.org/link.2)

And its not some Linux extension, the [syscall
implementation](21b136cc63/fs/namei.c (L4794-L4797))
only expects two arguments too.

It probably *should* have a flags parameter, but its too late now.

I am a bit surprised that linking glibc or musl against code that invokes
a 'link' with three parameters doesn't fail (at least, I couldn't get any
local test cases to trigger a compile or link error).

The test case in std/posix/test.zig is currently disabled, but if I
manually enable it, it works with this change.
2024-08-07 13:05:42 -07:00
Andrew Kelley
d36c182748 std.posix: add some more void bits
prevents unnecessary compilation errors on wasm32-freestanding
2024-08-07 00:48:32 -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
Andrew Kelley
390c7d84b2
Merge pull request #19833 from tealsnow/posix-INVAL
std.posix: handle INVAL in openZ, openatZ and openatWasi
2024-07-28 22:29:31 -07:00
Andrew Kelley
08e83fee57
Merge pull request #20297 from sno2/wtf8-conversion-buffer-overflows
std: fix buffer overflows from improper WTF encoding
2024-07-28 20:24:31 -07:00
Ketan Reynolds
0403c4b05c std.posix: handle INVAL in openatWasi
In accordance with https://github.com/ziglang/zig/pull/19833#issuecomment-2089262607
2024-07-28 19:01:55 -07:00
Ketan Reynolds
b4e7b6fdba std.posix: handle INVAL in openZ and openatZ
Contributes to #15607

Although the case is not handled in `openatWasi` (as I could not get a
working wasi environment to test the change) I have added a FIXME
addressing it and linking to the issue.
2024-07-28 19:01:55 -07:00
Andrew Kelley
718f8d5314
Merge pull request #20706 from alexrp/sigaction-nosys
`std.posix`: Make `sigaction()` infallible
2024-07-23 11:49:43 -07:00
Pat Tullmann
e8503ecb65 Default std.posix.system.ucontext_t is void
PR https://github.com/ziglang/zig/pull/20679 ("std.c reorganization")
switched feature-detection code to use "T != void" checks in place of
"@hasDecl".  However, the std.posix.system struct is empty, so
compile-time feature detection against symbols in there (specifically
`std.posix.system.ucontext_t` in this case), fail at compile time on
freestanding targets.

This PR adds a void ucontext_t into the std.posix.system default.

This PR also adds pseudo-"freestanding" variation of the StackIterator
"unwind" test.  It is sort of hacky (its freestanding, but assumes it can
invoke a Linux exit syscall), but it does detect this problem.

Fixes #20710
2024-07-23 11:47:29 -07:00
Nguyễn Gia Phong
d6fa71cd67
std: Wrap setpgid on POSIX 2024-07-22 11:49:55 +09:00
Alex Rønne Petersen
2cced8903e
std.posix: Consider invalid signal numbers to sigaction() to be programmer error.
The set of signals that cannot have their action changed is documented in POSIX,
and any additional, non-standard signals are documented by the specific OS. I
see no valid reason why EINVAL should be considered an unpredictable error here.
2024-07-21 22:38:09 +02:00
Alex Rønne Petersen
4d2868f242
std.posix: Don't consider NOSYS a valid error from sigaction().
I know of no "POSIX" system that does not have a sigaction() syscall.

Closes #20704.
2024-07-21 22:38:09 +02: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
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
Andrew Kelley
6c64090e7a std.os.linux: fanotify_init, fanotify_mark, name_to_handle_at
* Delete existing `FAN` struct in favor of a `fanotify` struct which has
  type-safe bindings (breaking).
* Add name_to_handle_at syscall wrapper.
* Add file_handle
* Add kernel_fsid_t
* Add fsid_t
* Add and update std.posix wrappers.
2024-07-12 00:14:07 -07:00
mochalins
f58ee387c7 fix: Use std.os.windows.poll rather than libc 2024-07-10 01:35:01 -04:00
Jora Troosh
13070448f5
std: fix typos (#20560) 2024-07-09 14:25:42 -07:00
Krzysztof Wolicki
0cc42d090f
std.fs.Dir: Rename OpenDirOptions to OpenOptions (#20542)
* std.fs.Dir: Rename OpenDirOptions to OpenOptions
https://ziglang.org/documentation/master/#Avoid-Redundant-Names-in-Fully-Qualified-Namespaces

* std.fs.Dir: Add deprecated alias `OpenDirOptions`
2024-07-09 13:36:38 -07:00
Isaac Freund
5f2bdafa39 std.posix: remove unchecked std.os.linux usage
Using std.os.linux directly in e.g. std.posix.timerfd_create() causes
the function to compile but silently fail at runtime when targeting any
OS other than Linux.

To catch errors like this at compile time, std.os.linux must only be
directly accessed within std.posix where there has been a comptime check
that the target os is in fact Linux.
2024-06-18 22:35:28 +02:00
Carter Snook
0b3508073c std: fix buffer overflows from improper WTF encoding
Closes #20288
2024-06-14 15:42:17 -05:00
Ryan Liptak
8e155959ca posix.renameW: Handle DIRECTORY_NOT_EMPTY more generally
Before this commit, the DIRECTORY_NOT_EMPTY/FILE_IS_A_DIRECTORY/NOT_A_DIRECTORY statuses were assumed only to be possible when using `FILE_RENAME_INFORMATION_EX` and `FILE_RENAME_POSIX_SEMANTICS`, but that has empirically been shown to be false; a networked samba share can return the DIRECTORY_NOT_EMPTY status from `FILE_RENAME_INFORMATION` (which doesn't support `FILE_RENAME_POSIX_SEMANTICS`).

`FILE_IS_A_DIRECTORY` and `NOT_A_DIRECTORY` were not proven to be possible, but they were also moved to the outer switch just in case.

Fixes #19785
2024-06-13 10:50:46 -04: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
Ekin Dursun
0ba64e9ce3 Add ECONNREFUSED to sendto 2024-06-08 15:35:00 -04:00
Georgijs
084c2cd90f
windows: use permissive file share flags everywhere (#19505)
* use permissive file share flags everywhere

* remove file_share_delete from createnamedpipefile
2024-05-11 23:34:40 +02:00