453 Commits

Author SHA1 Message Date
Ali Chraghi
aea617c60b std.os: take advantage of the freebsd's copy_file_range 2022-11-05 15:43:39 -04:00
Nameless
40e84a27d6
change uefi packed structs to new integer backed syntax (#13173)
* std.os.uefi: integer backed structs, add tests to catch regressions

device_path_protocol now uses extern structs with align(1) fields because
the transition to integer backed packed struct broke alignment

added comptime asserts that device_path_protocol structs do not violate
alignment and size specifications
2022-10-30 15:08:32 -04:00
daurnimator
c0c8ee5ae9 Add reboot syscall
Only linux for now
2022-10-27 20:39:35 -04:00
Ali Chraghi
ca27055cda all: rename @maximum to @max and @minimum to @min 2022-10-18 14:15:16 +03:00
Naoki MATSUMOTO
059e397ffc std.os: handle error.UnreachableAddress in send() 2022-10-17 13:10:23 +02:00
Jens Goldberg
1459231624 fix setsockopt returning ENODEV 2022-10-17 12:55:12 +02:00
Ali Chraghi
5127dae7a2 std.os: fix execv* doc comment 2022-10-16 11:38:22 -04:00
Andrew Kelley
c289794f0d nvptx: add TODO comment regarding abuse of llvm builtins 2022-10-15 10:50:02 -07:00
Guillaume Wenzek
24c749473a implement os.abort and panic for cuda 2022-10-15 10:39:19 -07:00
Marijn Stollenga
3a9344d8fc Return invalid argument in sendto instead of unreachable, since this can happen with user-side errors 2022-10-13 13:10:29 +02:00
cod1r
7b32aacbaf fix ChildProcess crash when PATH is empty. 2022-09-15 22:54:17 -04:00
John Schmidt
36f4f32fad
Add AFNOSUPPORT error to bind (#12560) 2022-09-01 15:13:07 -05:00
Motiejus Jakštys
9038528187 copy_file_range: fix zigification of TXTBSY
From `copy_file_range(2)` errors:

    ETXTBSY
           Either fd_in or fd_out refers to an active swap file.

Same error will be used in the upcoming `ioctl_ficlonerange(2)`:

    ETXTBSY
           One of the files is a swap file.  Swap files cannot share storage.
2022-08-26 15:36:40 +03:00
Andrew Kelley
5db80a051f Revert "std.os: add INVALID_SOCKET (#12081)"
This reverts commit 0f01e812ff054ea83661272bf0a96af228f2ffe3.

This does not belong in `std.posix`, and it is already provided at
`std.os.windows.ws2_32.INVALID_SOCKET`.

See related issue #5019.
2022-08-23 21:30:23 -07:00
yyny
0f01e812ff
std.os: add INVALID_SOCKET (#12081)
This constant returns an invalid `socket_t` that can be used as a sentinel
value.
2022-08-23 19:44:42 -05:00
John Schmidt
9cf667a21b Enable unexpectedErrno error tracing for stage2 LLVM
Stage2 seems to be able to handle this now.
2022-08-21 23:41:01 +03:00
Jakub Konka
515ee5b2fa libstd: do not follow symlinks in renameatW
This correctly mimicks POSIX behavior.
2022-08-17 23:13:58 +02:00
Andrew Kelley
e67a43a673
Merge pull request #12410 from ifreund/sig-err-dfl-ign-fix
std: fix definition of SIG_IGN, SIG_DFL, etc.
2022-08-11 15:05:07 -04:00
Andrew Kelley
a82d7c2063 std: add missing error to windows.WriteFile
I encountered this error today when testing the self-hosted compiler on
Windows.
2022-08-11 06:22:05 -04:00
Isaac Freund
b78f3bf1f1
std: fix definition of SIG_IGN, SIG_DFL, etc.
POSIX specifies that the sa_handler field of the sigaction struct may
be set to SIG_IGN or SIG_DFL. However, the current constants in the
standard library use the function pointer signature corresponding to
the sa_sigaction field instead.

This may not cause issues in practice because the fields usually occupy
the same memory in a union, but this isn't required by POSIX and there
may be systems we do not yet support that do this differently.

Fixing this also makes the Zig interface less confusing to use after
reading the man page.
2022-08-11 12:09:34 +02:00
Isaac Freund
7d6a7f513b
std: Don't pass undefined memory to the kernel in os.abort() 2022-08-11 11:05:53 +02:00
Ryan Liptak
1a1b7a3afd Linux: Add IN_MASK_CREATE and corresponding error handling in inotify_add_watch
From https://man7.org/linux/man-pages/man7/inotify.7.html

> **IN_MASK_CREATE** (since Linux 4.18)
>
> Watch pathname only if it does not already have a watch associated with it; the error EEXIST results if pathname is already being watched.
2022-07-31 13:00:16 -07:00
Veikka Tuominen
262f4c7b3a std.fs: remove OpenDirOptions.iterate 2022-07-15 14:39:21 +03:00
Kim SHrier
397e6547a9 add FreeBSD support to std.os.getFdPath
This implementation uses the F_KINFO fcntl command added in FreeBSD
13 release. FreeBSD 12 users get a compile error.

Co-authored-by: Stephen Gregoratto <dev@sgregoratto.me>
2022-07-15 10:16:31 +03:00
Bill Nagel
a455927150 handle HOSTUNREACH for blocking and non-blocking connects 2022-07-14 12:51:40 +03:00
Andrew Kelley
fad95741db AstGen: fix loop control flow applying to wrong loop
In the case of 'continue' or 'break' inside the 'else' block of a
'while' or 'for' loop.

Closes #12109
2022-07-13 16:10:41 -07:00
Veikka Tuominen
ae7b32eb62 Sema: validate deref operator type and value 2022-07-01 10:22:25 +03:00
Jonathan Marler
ca98625789
std.os.execvpe: fix buffer overflow
The NameTooLong check isn't taking the sentinel 0 into account which
would result in a buffer overflow on the stack.
2022-06-21 11:21:45 +02:00
Andrew Kelley
073762395e std.os.abort patch cleanups
* move global into function scope
 * clarify comments
 * avoid unnecessary usage of std.atomic API
 * switch on error instead of `catch unreachable`
 * call linux.gettid() instead of going through higher level API and
   doing unnecessary casting
2022-06-06 15:34:20 -07:00
Jan Philipp Hafer
d1e8b73939 std.os.abort: ported signal handling from musl
* Document deviation from Linux man page, which is identical to musl.
  Man page wants always enabled user-provided abort handlers.
  Worst case logic bug, which this can introduce:
    + user disables SIGABRT handler to prevent tear down to last safe
      state
    + abort() gets called and enables user-provided SIGABRT handler
    + SIGABRT tears down to supposed last safe state instead of crash
    + Application, instead of crashing, continues
* Pid 1 within containers needs special handling.
  - fatal signals are not transmitted without privileges,
    so use exit as fallback
* Fix some signaling bits
* Add checks in Debug and ReleaseSafe for wrong sigprocmask
2022-06-06 15:32:39 -07:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Thiago Teodoro Pereira Silva
7a4758ed78
std.os: add timerfd_create, timerfd_settime and timerfd_gettime 2022-05-17 00:56:33 +02:00
Isaac Freund
1392c24166 std.os: Add memfd_create for FreeBSD
This is minorly breaking as e.g. std.os.linux.MFD_CLOEXEC is now
std.os.linux.MFD.CLOEXEC.
2022-05-16 17:43:44 -04:00
Andrew Kelley
19003de64c
Merge pull request #10595 from squeek502/getenvW-case
os.getenvW: Fix case-insensitivity for Unicode env var names
2022-05-11 15:33:04 -04:00
Isaac Freund
6f4343b61a std: replace usage of std.meta.bitCount() with @bitSizeOf() 2022-04-27 11:10:52 +02:00
Cody Tapscott
7b090df668 stdlib std.os: Improve wasi-libc parity for WASI CWD emulation
Two major changes here:
  1. We store the CWD as a simple `[]const u8` and lookup Preopens for
     every absolute or CWD-referenced file operation, based on the
     Preopen with the longest match (i.e. most specific path)
  2. Preorders are normalized to POSIX absolute paths at init time.
     Behavior depends on the "cwd_root" parameter of `initPreopensWasi`:

	`cwd_root` is used for any Preopens that start with "."

	  For example:
            "./foo/bar" - inits to -> "{cwd_root}/foo/bar"
            "foo/bar"   - inits to -> "/foo/bar"
	    "/foo/bar"  - inits to -> "/foo/bar"

        `cwd_root` must be an absolute path.

	Using "/" as `cwd_root` gives behavior similar to wasi-libc.
2022-04-16 18:08:05 +02:00
Damien Firmenich
5fafcc2b62
zig fmt: remove trailing whitespace on doc comments
Fixes #11353

The renderer treats comments and doc comments differently since doc
comments are parsed into the Ast. This commit adds a check after getting
the text for the doc comment and trims whitespace at the end before
rendering.

The `a = 0,` in the test is here to avoid a ParseError while parsing the
test.
2022-04-05 18:08:33 +03:00
Tom Read Cutting
cdcb34cdf4
Pull elf magic string out to re-used constant 2022-04-04 15:33:24 +03:00
zseri
c6cf40a0c0 fix sigaction double panic
Fixes #8357
2022-03-19 19:13:31 +02:00
Jakub Konka
dd55b72949 std: introduce posix_spawn as an alt to fork-exec
Currently, the new API will only be available on macOS with
the intention of adding more POSIX systems to it incrementally
(such as Linux, etc.).

Changes:
* add `posix_spawn` wrappers in a separate container in
  `os/posix_spawn.zig`
* rewrite `ChildProcess.spawnPosix` using `posix_spawn` targeting macOS
  as `ChildProcess.spawnMacos`
* introduce a `posix_spawn` specific `std.c.waitpid` wrapper which
  does return an error in case the child process failed to exec - this
  is required for any process that was spawned using `posix_spawn`
  mechanism as, by definition, the errors returned by `posix_spawn`
  routine cover only the `fork`-equivalent; `pre-exec()` and `exec()`
  steps are covered by a catch-all error `ECHILD` returned by `waitpid`
  on unsuccessful execution, e.g., no such file error, etc.
2022-03-16 19:40:44 +01:00
Jakub Konka
76bceb240d std+macho: revert and fix exposing Mach wrappers in std.os and std.c 2022-03-13 17:03:04 +01:00
Jakub Konka
1af0c75d71 std: fix imports for darwin specific flags and funcs 2022-03-13 14:59:15 +01:00
Jakub Konka
633c4a2a60 macos: add Mach task abstraction
`std.os.darwin.MachTask` wraps `mach_port_t` and can be used to issue
kernel calls tied to the wrapped Mach kernel port/task.
2022-03-13 13:35:39 +01:00
Cody Tapscott
aafcd8eab3 stdlib std.os: Rename RelativePath to RelativePathWasi 2022-03-03 14:31:49 -07:00
Cody Tapscott
ade2d0c6a2 stdlib WASI: Add realpath() support for non-absolute Preopens 2022-03-03 14:31:49 -07:00
Cody Tapscott
58f961f4cb stdlib: Add emulated CWD to std.os for WASI targets
This adds a special CWD file descriptor, AT.FDCWD (-2), to refer to the
current working directory. The `*at(...)` functions look for this and
resolve relative paths against the stored CWD. Absolute paths are
dynamically matched against the stored Preopens.

"os.initPreopensWasi()" must be called before std.os functions will
resolve relative or absolute paths correctly. This is asserted at
runtime.

Support has been added for: `open`, `rename`, `mkdir`, `rmdir`, `chdir`,
`fchdir`, `link`, `symlink`, `unlink`, `readlink`, `fstatat`, `access`,
and `faccessat`.

This also includes limited support for `getcwd()` and `realpath()`.
These return an error if the CWD does not correspond to a Preopen with
an absolute path. They also do not currently expand symlinks.
2022-03-03 14:31:49 -07:00
David John
139b731d82 std: rename sched_yield to yield and move it to std.Thread 2022-02-27 15:34:02 -05:00
Ryan Liptak
83a486a064 os.getenvW: Fix handling of special =-prefixed env vars 2022-02-19 15:46:23 -08:00
Ryan Liptak
c87f79c957 os.getenvW: Fix case-insensitivity for Unicode env var names
Windows does Unicode-aware case-insensitivity comparisons for environment variable names. Before, os.getenvW was only doing ASCII case-insensitivity. We can take advantage of RtlEqualUnicodeString in NtDll to get the proper Unicode case insensitivity.
2022-02-19 15:46:23 -08:00
Anthony Carrico
078aa5f7b2 Adds Linux support for POSIX file locking with fcntl
On Linux, locking fails with EAGAIN (vs. EACCES on other systems).
This commit also adds FcntlErrors for EDEADLK and ENOLCK.
2022-02-15 13:22:50 +02:00