Commit graph

504 commits

Author SHA1 Message Date
David Carlier
c66151a226 std.os: sysctl* wrappers, better warning at compile time 2023-04-24 03:59:35 +03:00
David CARLIER
dbdafb6cc5 os: expand sched_getaffinity wrapper and update freebsd's cpuset api flags. 2023-04-22 13:54:57 +03:00
Andrew Kelley
dfe3440540 std.os.sendto: use ws2_32 on Windows
closes #9971
2023-04-09 20:08:18 -04:00
jim price
3487514626 std.os: add mincore syscall
The mincore syscall is available on some UNIX like operating systems
and allows a user to determine if a page is resident in memory.
2023-04-06 00:57:23 -04:00
Jacob Young
83a208c355 x86_64: implement large cmp 2023-04-02 04:49:53 -04:00
Veikka Tuominen
5e161c102d
Merge pull request #14841 from squeek502/is-cygwin-pty-stuff
`os.isCygwinPty`: Fix a bug, replace kernel32 call, and optimize
2023-03-21 15:03:33 +02:00
Jakub Konka
a23ef3783b os.zig: expose ptrace wrapper for darwin and linux 2023-03-18 21:52:40 +01:00
mllken
da0509750a std.os: handle EPERM errno for bind 2023-03-16 17:41:58 +02:00
Jakub Konka
e1e414e62a std: move os/darwin.zig and related to c/darwin.zig
Move to c/darwin.zig as they really are libSystem/libc imports/wrappers.

As an added bonus, get rid of the nasty `usingnamespace`s which are now
unneeded.

Finally, add `os.ptrace` but currently only implemented on darwin.
2023-03-16 11:42:30 +01:00
Andrew Kelley
e098b287e1 std.fs.File.writevAll: fix behavior for 0-length vectors
The OS layer expects pointer addresses to be inside the application's
address space even if the length is zero. Meanwhile, in Zig, slices may
have undefined pointer addresses when the length is zero. So this
function now modifies the iov_base fields when the length is zero.

This is a companion commit to b4893eb05565b2cb033c6ed88617d73faf878455.
2023-03-15 10:48:15 -07:00
Andrew Kelley
25c3878c00 std.fs.File.readvAll: fix behavior for 0-length vectors
The OS layer expects pointer addresses to be inside the application's
address space even if the length is zero. Meanwhile, in Zig, slices may
have undefined pointer addresses when the length is zero. So this
function now modifies the iov_base fields when the length is zero.
2023-03-15 10:48:14 -07:00
Andrew Kelley
41a5ad28c9 std: child process API supports rusage data 2023-03-15 10:48:13 -07:00
Andrew Kelley
3169f0529b eliminate posix_spawn from the standard library
Today I found out that posix_spawn is trash. It's actually implemented
on top of fork/exec inside of libc (or libSystem in the case of macOS).

So, anything posix_spawn can do, we can do better. In particular, what
we can do better is handle spawning of child processes that are
potentially foreign binaries. If you try to spawn a wasm binary, for
example, posix spawn does the following:

 * Goes ahead and creates a child process.
 * The child process writes "foo.wasm: foo.wasm: cannot execute binary file"
   to stderr (yes, it prints the filename twice).
 * The child process then exits with code 126.

This behavior is indistinguishable from the binary being successfully
spawned, and then printing to stderr, and exiting with a failure -
something that is an extremely common occurrence.

Meanwhile, using the lower level fork/exec will simply return ENOEXEC
code from the execve syscall (which is mapped to zig error.InvalidExe).

The posix_spawn behavior means the zig build runner can't tell the
difference between a failure to run a foreign binary, and a binary that
did run, but failed in some other fashion. This is unacceptable, because
attempting to excecve is the proper way to support things like Rosetta.
2023-03-10 15:41:07 -05:00
Jan Philipp Hafer
06b263825a std.os: add missing mmap errors
Man page for posix lists EMFILE, man page for linux ENFILE.
Also posix says "The mmap() function adds an extra reference to the file
associated with the file descriptor fildes which is not removed by a
subsequent close() on that file descriptor. This reference is removed
when there are no more mappings to the file."

It sounds counter-intuitive, that a process limit but no system limit can
be exceeeded.

As far as I understand, fildes is only used for file descriptor backed mmaps.
2023-03-08 13:00:06 -05:00
Ryan Liptak
93b35c6999 os.isCygwinPty: Fix a bug, replace kernel32 call, and optimize
- Fixes the first few code units of the name being omitted (it was using `@sizeOf(FILE_NAME_INFO)` as the start of the name bytes, but that includes the length of the dummy [1]u16 field and padding; instead the start should be the offset of the dummy [1]u16 field)
- Replaces kernel32.GetFileInformationByHandleEx call with ntdll.NtQueryInformationFile
  + Contributes towards #1840
- Checks that the handle is a named pipe first before querying and checking the name, which is a much faster call than NtQueryInformationFile (this was about a 10x speedup in my probably-not-so-good/take-it-with-a-grain-of-salt benchmarking)
2023-03-08 04:26:50 -08:00
jim price
6ab04b5941 std.os: Allow write functions to return INVAL errors
In Linux when interacting with the virtual file system when writing
in invalid value to a file the OS will return errno 22 (INVAL).

Instead of triggering an unreachable, this change now returns a
newly introduced error.InvalidArgument.
2023-03-06 15:59:18 -05:00
Andrew Kelley
8558983c86 std.os.abort: take advantage of @trap 2023-03-05 17:29:28 -07:00
jim price
a63134a4a5 std.os: Add DeviceBusy as a possible write error
In Linux when writing to various files in the virtual file system,
for example /sys/fs/cgroup, if you write an invalid value to a file
you'll get errno 16.

This change allows for these specific cases to be caught instead of
being lumped together in UnexpectedError.
2023-03-05 17:56:44 +02:00
Andrew Kelley
bb5006d728 std: add fchmodat
Also add `std.fs.has_executable_bit` for doing conditional compilation.

This adds the linux syscalls for chmod and fchmodat, as well as the
extern libc function declarations.

Only `fchmodat` is added to `std.os`, and it is not yet added to std.fs.
2023-03-03 02:37:45 -05:00
Jonathan Marler
dafefe9c9d use std_options for keep_sigpipe and existence of SIG.PIPE to check for support 2023-02-18 11:49:15 -07:00
Jonathan Marler
0a8fe34b11 add test to ignore sigpipe 2023-02-17 15:25:36 -07:00
Jonathan Marler
c02ced4d34 ignore SIGPIPE by default 2023-02-17 09:08:41 -07:00
Veikka Tuominen
7199d7c777 split @qualCast into @constCast and @volatileCast 2023-02-15 01:43:57 +02:00
Veikka Tuominen
f16c10a86b implement @qualCast 2023-01-30 18:55:57 +02:00
zigster64
2b27bc2c65 On BrokenPipe error during os.sendfile - return error rather than unreachable 2023-01-28 18:27:43 -05:00
Takeshi Yoneda
ce20ebb50c wasi: remove unnecessary breakpoint() in abort
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-26 19:14:36 +01:00
Andrew Kelley
ac28bedbee
Merge pull request #14418 from ifreund/assume-sentinel-sux
std: eliminate pointless meta.assumeSentinel() usage
2023-01-23 21:01:54 -05:00
Isaac Freund
faf2fd18d3
std: eliminate pointless meta.assumeSentinel() usage
This fixes a bug in std.net caused during the introduction of
meta.assumeSentinel due to the unfortunate semantics of mem.span()

This leaves only 3 remaining uses of meta.assumeSentinel() in the
standard library, each of which could be a simple @ptrCast([*:0]T, foo)
instead. I think this function should likely be removed.
2023-01-23 12:19:53 +01:00
Jan Philipp Hafer
55e879d2ed std.os.windows: add possible error NETNAME_DELETED of ReadFile
Closes #13631
2023-01-23 02:07:12 -05:00
mlugg
d3599ec73c std: implement os.mprotect on Windows 2023-01-20 03:33:35 +02:00
Andrew Kelley
f4d6b37068 Package: handle Windows PathAlreadyExists error code
Unfortunately, error.AccessDenied is ambiguous on Windows when it is
returned from fs.rename.
2023-01-11 17:54:34 -08:00
Andrew Kelley
c9ef277fa7
Merge pull request #13980 from ziglang/std.net
networking: delete std.x; add std.crypto.tls and std.http.Client
2023-01-03 02:43:50 -05:00
Michael Dusan
7798af7461
dragonfly: pass test: lib/std/std.zig 2023-01-02 19:18:33 -05:00
Michael Dusan
e752606464
netbsd: getFdPath: F_GETPATH implementation 2023-01-02 19:18:33 -05:00
Michael Dusan
7da9348637
dragonfly: getFdPath: F_GETPATH implementation 2023-01-02 19:18:33 -05:00
Michael Dusan
7f012eef0b
freebsd: memfd_create: < 13.0 version check
- add conditional compile error
- add conditional skip test
2023-01-02 19:18:33 -05:00
Michael Dusan
bd071c98a5
freebsd: getFdPath: handle NameTooLong 2023-01-02 19:18:33 -05:00
Michael Dusan
537624734c
freebsd: getFdPath: < 13.1 fallback impl 2023-01-02 19:18:32 -05:00
Michael Dusan
4cdbde55b4
macos: getFdPath: handle E.NOSPC
- per darwin-xnu source, fcntl F_GETPATH will return ENOSPC when path
  exceeds either user-supplied buffer or system MAXPATHLEN
- macOS does not document this (and other) possible errno values
2023-01-02 19:18:32 -05:00
Andrew Kelley
b3c8c383bb std.os: add missing handling of ECONNRESET in readv 2023-01-02 16:57:16 -07:00
Andrew Kelley
cd0d514643 remove the experimental std.x namespace
Playtime is over. I'm working on networking now.
2023-01-02 16:57:15 -07:00
Ryan Liptak
6e22b63edb windows: Extract RtlEqualUnicodeString usage into to a helper function 2022-12-17 22:06:47 -08:00
Jakub Konka
b27b17e253
Merge pull request #13935 from ziglang/mach-tasks
darwin: expose more Mach primitives, expose wrapped ptrace, and allow starting suspended for posix_spawn
2022-12-14 17:42:02 +01:00
Tom Maenan Read Cutting
d0eef26687 Add 0-length buffer checks to os.read & os.write
This helps prevent errors related to undefined pointers being passed
through to some OS apis when slices have 0 length.

Tests have also been added to catch these cases.
2022-12-12 15:10:59 -05:00
Takeshi Yoneda
78ea270cc6
wasi: fixes os.isatty on type mismatch (#13813) 2022-12-11 03:44:38 -05:00
Jakub Konka
35e3069ab7 darwin: expose ptrace with errno handling 2022-12-10 23:36:36 +01:00
Andrew Kelley
50eb7983cd remove most conditional compilation based on stage1
There are still a few occurrences of "stage1" in the standard library
and self-hosted compiler source, however, these instances need a bit
more careful inspection to ensure no breakage.
2022-12-06 20:38:54 -07:00
Andrew Kelley
b7b905d227 add behavior test for while(true) not needing else unreachable
closes #707
2022-12-06 17:57:27 -07:00
Andrew Kelley
e73170f972 std: fix WASI regressions
This branch largely reverts 58f961f4cb. I
would like to revisit the proposal to modify the standard library in
this way and think more carefully about it before adding isAbsolute()
checks everywhere.
2022-12-06 12:15:05 -07:00
Andrew Kelley
d5312d53a0 WASI: remove absolute path emulation from std lib
Instead of checking for absolute paths and current working directories
in various file system operations, there is one simple solution: allow
overriding `std.fs.cwd` on WASI.

os.realpath is back to causing a compile error when used on WASI. This
caused a compile error in the Sema handling of `@src()`. The compiler
should never call realpath, so the commit that made this change is
reverted (95ab942184). If this breaks
debug info, a different strategy is needed to solve it other than using
realpath.

I also removed the preopens code and replaced it with something much
simpler. There is no longer any global state in the standard library.

Additionally-
 * os.openat no longer does an unnecessary fstat on WASI when O.WRONLY
   is not provided.
 * os.chdir is back to causing a compile error on WASI.
2022-12-06 12:15:04 -07:00