Commit graph

537 commits

Author SHA1 Message Date
Andrew Kelley
a92be49851 Revert "Merge pull request #15317 from devnexen/darwin_rand_nativegen"
This reverts commit a111130977, reversing
changes made to 9f3f9fb40f.
2023-07-31 11:13:27 -07:00
Andrew Kelley
182bec8771 Revert "std.os: adding linux's sched_setaffinity and its wrapper"
This reverts commit c7bf8bab38.
2023-07-31 11:01:42 -07:00
Andrew Kelley
86a5edca62 Revert "std.os: implementing sched_setaffinity wrapper for freebsd"
This reverts commit 05268bb967.
2023-07-31 10:58:03 -07:00
Andrew Kelley
aff65e74e1 Revert "std.os: gethostname non libc linking using uname like linux"
This reverts commit f8991ba3d4.
2023-07-31 10:54:51 -07:00
Ryan Liptak
9a3adeea6e windows.OpenFile/DeleteFile: Add NetworkNotFound as a possible error
When calling NtCreateFile with a UNC path, if either `\\server` or `\\server\share` are not found, then the statuses `BAD_NETWORK_PATH` or `BAD_NETWORK_NAME` are returned (respectively).

These statuses are not translated into `error.FileNotFound` because they convey more information than the typical FileNotFound error. For example, if you were trying to call `Dir.makePath` with an absolute UNC path like `\\MyServer\MyShare\a\b\c\d`, then knowing that `\\MyServer\MyShare` was not found allows for returning after trying to create the first directory instead of then trying to create `a\b\c`, `a\b`, etc. when it's already known that they will all fail in the same way.
2023-07-27 09:35:29 -07:00
Ryan Liptak
442933936a os.renameatW: Handle OBJECT_NAME_COLLISION from NtSetInformationFile
Partially addresses #16374
2023-07-23 19:09:36 -07:00
Mathew R Gordon
11695745e5 getenv: remove unnessary small key block
The code removed does unnecessary copying in order to create a null-terminated pointer, just to pass it to libc getenv. It only does this for `small keys`, which are under 64 bytes in size.

Instead of going out of the way to add a null byte to a function that takes normal slices, this should just be handled by the loop below, which scans c.environ to find the value
2023-07-18 11:44:23 +02:00
Mathew R Gordon
bf827d0b55
std: Make getenv return 0-terminated slice 2023-07-17 10:57:41 +00:00
dweiller
a7707d8279 std.os.sigprocmask: @bitCast flags parameter 2023-07-11 23:03:21 -07:00
Robin Voetter
a1b583dc24
std: make panic and abort for amdhsa call trap 2023-07-01 21:23:45 +02:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Andrew Kelley
b20ccff515 std.os: update logic for 64-bit symbol choice
musl v1.2.4 dropped the "64"-suffixed aliases for legacy "LFS64" ("large
file support") interfaces, so this commit changes the corresponding Zig
logic to call the correct names.
2023-06-20 12:55:38 -04:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
r00ster91
6e84f46990 std: replace builtin.Version with SemanticVersion 2023-06-17 13:17:34 -07:00
Andrew Kelley
96acc204b2
Merge pull request #16052 from mikdusan/bsd-getdents
fix bad return types for BSDs getdents and debitrot openbsd
2023-06-17 13:01:52 -07:00
Gregory Mullen
abfa215882 add additional errno (INTR) to tcset,getpgrp calls
Missed this originally because I was only able to trigger it when
SA_RESTART was missing from the sigaction handlers. I'm unconvinced this
is actually a sane way for stdlib to behave (see #15664). But this does
duplicate the existing behavior throughout os.zig which IMO should be
prioritized here.
2023-06-16 22:02:36 -07:00
Jacob G-W
4dac9f54dd plan9: flesh out stdlib enough to allow not using simplified start logic 2023-06-16 08:34:30 -04:00
Michael Dusan
40fc71bf71
openbsd: fix std.c.getdents and debitrot
- fix getdents return type usize → c_int
- special-case process.zig to use sysctl instead of sysctlbyname
- use struct/field pattern for sysctl HW_* constants
2023-06-15 14:48:20 -04:00
Marcos O
ff835cce10
windows.sendto fix (#15831) 2023-06-14 16:24:16 +00:00
Evin Yulo
137b115681 os.connect: mark ECONNABORTED as unreachable
closes #13677
2023-06-13 11:16:09 -07:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
David CARLIER
f8991ba3d4 std.os: gethostname non libc linking using uname like linux 2023-05-22 12:45:18 +03:00
David CARLIER
05268bb967 std.os: implementing sched_setaffinity wrapper for freebsd 2023-05-14 10:21:42 +03:00
Ryan Liptak
815e53b147 Update all std.mem.tokenize calls to their appropriate function
Everywhere that can now use `tokenizeScalar` should get a nice little performance boost.
2023-05-13 13:45:04 -07:00
David CARLIER
c7bf8bab38 std.os: adding linux's sched_setaffinity and its wrapper 2023-05-13 21:18:18 +03:00
Gregory Mullen
aa9ea61216 Add tc{set,get}pgrp to std.os.linux 2023-05-11 19:43:06 +03:00
Veikka Tuominen
a111130977
Merge pull request #15317 from devnexen/darwin_rand_nativegen
std: add CCRandomGenerateBytes macOs native api.
2023-05-05 19:52:05 +03:00
Linus Groh
94e30a756e std: fix a bunch of typos
The majority of these are in comments, some in doc comments which might
affect the generated documentation, and a few in parameter names -
nothing that should be breaking, however.
2023-04-30 18:16:04 -07:00
Andrew Kelley
6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
Andrew Kelley
396bd51c48 enable debugging infrastructure when using C backend
Thanks to @jacobly0's recent enhancements to the C backend, this stuff
works now.
2023-04-26 20:56:21 -07:00
Andrew Kelley
792bbfa301 Sema: fix memcpy alias safety incorrect math
Previously it was not multiplying by the element ABI size. Now, it uses
ptr_add instructions which do math based on the element type.
2023-04-25 11:23:41 -07:00
Andrew Kelley
a5c910adb6 change semantics of @memcpy and @memset
Now they use slices or array pointers with any element type instead of
requiring byte pointers.

This is a breaking enhancement to the language.

The safety check for overlapping pointers will be implemented in a
future commit.

closes #14040
2023-04-25 11:23:40 -07:00
David Carlier
c66151a226 std.os: sysctl* wrappers, better warning at compile time 2023-04-24 03:59:35 +03:00
David CARLIER
6248ac535b os: getrandom wrapper favoring it for macOs/iOs only 2023-04-22 21:01:12 +01: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