Commit Graph

1484 Commits

Author SHA1 Message Date
Vlad Pănăzan
20ea0012f0 linux: add missing io_uring opcodes 2024-02-11 15:43:12 +01: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
Samuel Fiedler
0266017b59 Make EfiPhysicalAddress in std/os/uefi/tables.zig public 2024-02-05 15:31:33 +00:00
mlugg
8944935499 std: eliminate some uses of usingnamespace
This eliminates some simple usages of `usingnamespace` in the standard
library. This construct may in future be removed from the language, and
is generally an inappropriate way to formulate code. It is also
problematic for incremental compilation, which may not initially support
projects using it.

I wasn't entirely sure what the appropriate namespacing for the types in
`std.os.uefi.tables` would be, so I ofted to preserve the current
namespacing, meaning this is not a breaking change. It's possible some
of the moved types should instead be namespaced under `BootServices`
etc, but this can be a future enhancement.
2024-02-01 20:30:42 +00:00
Veikka Tuominen
a4f27e8987 remove std.io.Mode 2024-02-01 15:22:36 +02:00
Constantin Pestka
e460ba66a5
std: add docs about return value of submit() (#18721)
being misleading if used alongside with IORING_SETUP_SQPOLL
2024-01-29 21:26:52 -05:00
Krzysztof Wolicki
190ea02e0d os.windows: Fix missing correction from #18657 2024-01-27 12:38:33 -08:00
Zachary Raineri
b36dd55af5 std.os.wasi | Fix comment links
Branch was renamed: master -> main
Preview 1 was moved to legacy
2024-01-26 15:24:07 +02:00
Krzysztof Wolicki
eff58d6c18 os.windows: Fix error 258 name in Win32Error 2024-01-23 18:06:23 -08:00
xEgoist
194ed30825 child_process: Use security attributes while creating handle.
As suggested by @matu3ba, it can be better to use Security Attributes
directly while creating the handle instead of creating the handle then
setting the handle to inherit. Doing so can prevent potentially leaking
to other parallel spawned processes which would inherit the opened `\Device\Null`
handle.

This change also allows windows.OpenFile to handle when bInheritHandle
is set.

Note that we are using the same `saAttr`, but since it's taken as a
pointer to a const in all calls, it's never mutated, and OpenFile never alters it.

This also saves 1 kernel call for setting the handle to inherit.
2024-01-16 01:25:14 -08:00
Stephen Gregoratto
3200fae9c5 Linux: Add syscall bindings, enhance documentation.
- Add syscall bindings/structures for the `futex2` family.
  The documentation is taken from the syscall definitions.
- Add documnentation for the `cachestat` bindings and structures.
  Taken from work I did in Cosmopolitian libc.
- Add binding for `map_shadow_stack`.
  No documentation for this one, since the kernel devs didn't bother to
  do it ¯\_(ツ)_/¯.
2024-01-15 20:05:03 +11:00
Stephen Gregoratto
cca021c211 Linux: Update syscalls for the 6.7 release
This release adds the rest of the futex2[1] syscalls, along with
shadow stack[2] support for more architectures.

[1]: https://lwn.net/Articles/940944/
[2]: https://lwn.net/Articles/926649/
2024-01-15 20:05:03 +11:00
Andrew Kelley
a5934edd48 std.os.linux.io_uring: fix compilation errors
Commit f0c42fbba1 was created before the
additional compile error for var used instead of const.
2024-01-14 19:20:41 -07:00
Andrew Kelley
f0c42fbba1
Merge pull request #18025 from ianic/io_uring_send_zc
io_uring: add send_zc and *_direct operations
2024-01-14 18:10:51 -08:00
Stephen Gregoratto
01cc904fc7 Rework fchmodat tests
Based on the Linux kernel fchmodat2 test
2024-01-13 23:52:01 -07:00
Stephen Gregoratto
cf6751ae55 Add fchmodat2 bits to os/linux.zig 2024-01-13 23:52:01 -07:00
Stephen Gregoratto
26db31f6f6 Add fchmodat2 to the Linux syscall list
This syscall was added to simplify the the libc implementations of
fchmodat, as the original syscall does not take a `flags` argument.

Another syscall, `map_shadow_stack`, was also added for x86_64.
2024-01-13 23:52:01 -07:00
Matthew Wozniak
aaf1e0b25b
add ability to open dlls with platform-specific flags (#18370) 2024-01-09 20:11:22 -05:00
David Rubin
2f8e4347b1
Optimized std.mem.eql with SIMD (#18389)
* optimized memeql
* add `sched_setaffinity` to `std.os.linux`

Co-authored-by: Protty <45520026+kprotty@users.noreply.github.com>
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2024-01-09 02:50:22 -05:00
Karl Böhlmark
9a56228c2b
doc: Fix typos in bpf docs 2024-01-03 12:34:10 +02:00
Andrew Kelley
96b4eeab55 std: disable failing test on macos
See tracking issue https://github.com/ziglang/zig/issues/18395
2024-01-01 19:49:08 -07:00
Veikka Tuominen
94c63f31f2
Merge pull request #18328 from ExpidusOS/feat/uefi-time
std: add support for getting the time in UEFI
2023-12-26 01:03:10 +02:00
Carl Åstholm
60982ea5bd Correct CreateProcessW parameter types 2023-12-22 12:23:27 +02:00
Tristan Ross
97fd100471
os.uefi: add ns to epoch 2023-12-20 20:05:16 -08:00
Tristan Ross
a86cd91389
os.uefi: add time to epoch conversion 2023-12-19 23:42:47 -08:00
Ryan Liptak
11a398af3e File.stat: Support detection of Kind.sym_link on Windows
Requires an extra NtQueryInformationFile call when FILE_ATTRIBUTE_REPARSE_POINT is set to determine if it's actually a symlink or some other kind of reparse point (https://learn.microsoft.com/en-us/windows/win32/fileio/reparse-point-tags). This is something that `File.Metadata.kind` was already doing, so the same technique is used in `stat`.

Also, replace the std.os.windows.DeviceIoControl call in `metadata` with NtQueryInformationFile (NtQueryInformationFile is what gets called during kernel32.GetFileInformationByHandleEx with FileAttributeTagInfo, verified using NtTrace).
2023-12-19 23:36:23 -08:00
loris
37458cc886 allow sqe entries up to 32768 2023-12-12 06:49:19 +02:00
xdBronch
7a46c20a79 switch to mem.span
Co-authored-by: erikarvstedt <36110478+erikarvstedt@users.noreply.github.com>
2023-12-08 15:58:08 +02:00
xdBronch
e9bd10cfda add getName helper to inotify_event 2023-12-08 15:58:08 +02:00
David Rubin
1e42a3de89
Remove all usages of std.mem.copy and remove std.mem.set (#18143) 2023-11-29 16:03:02 -05:00
Ryan Liptak
0bc4ee1792 Remove std.os.windows.ole32/shell32 2023-11-23 03:06:47 -08:00
Ryan Liptak
2c326d4390 std.os.windows: Add HKEY_CLASSES_ROOT 2023-11-23 01:11:53 -08:00
Andrew Kelley
6fc20b3b09 std.os.windows: remove volatile from inline asm
This inline assembly has no side effects.
2023-11-23 00:52:35 -05:00
Mikko Kaihlavirta
ea4a07701e add missing timeval struct 2023-11-22 01:15:11 +02:00
expikr
40bd93e2a2 replace qpf and qpc
Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update ntdll.zig

Update windows.zig

Update ntdll.zig

Update kernel32.zig
2023-11-21 14:10:25 +02:00
Tw
8ca4a5240e linux/bpf: update helper definitions
Signed-off-by: Tw <tw19881113@gmail.com>
2023-11-19 19:01:18 +02:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
Igor Anić
be4a77d9aa io_uring: fix ci failing test
Getting this error in ci:
run test std-arm-linux-none-generic-Debug: error: 'test.accept/connect/send_zc/recv' failed: /home/ci/actions-runner1/_work/zig/zig/lib/std/os/linux/io_uring.zig:60:23: 0x70b06b in init_params (test)
            .NOSYS => return error.SystemOutdated,
                      ^
/home/ci/actions-runner1/_work/zig/zig/lib/std/os/linux/io_uring.zig:27:16: 0x70b6b7 in init (test)
        return try IO_Uring.init_params(entries, &params);
               ^
/home/ci/actions-runner1/_work/zig/zig/lib/std/os/linux/io_uring.zig:3807:16: 0x72405b in test.accept/connect/send_zc/recv (test)
    var ring = try IO_Uring.init(16, 0);

https://github.com/ziglang/zig/actions/runs/6909813408/job/18801841015?pr=18025
2023-11-18 05:40:24 +01:00
Igor Anić
7eee0d3353 io_uring: try to pass windows/macos tests 2023-11-17 23:39:29 +01:00
Igor Anić
ccf5a6cc5c io_uring: make Linux version check runtime instead od comptime
Reverting previous change.
I'm building test bin and then running it in virtual machines with different
kernels. So Linux kernel checks has to be runtime instead of comptime.
2023-11-17 22:17:00 +01:00
Igor Anić
a7001b86f1 io_uring: include review comments
Thanks @rootbeer for review.
This adds description to send_zc behavior.
Cleans up tests.
2023-11-17 19:58:23 +01:00
Igor Anić
257b8131ec io_uring: use kernel version test in send_zc test 2023-11-17 17:21:54 +01:00
Igor Anić
87dd8d5669 io_uring: simplify tests by checking kernel version
So far we relied on getting EINVAL in CQE for operations that kernel don't
support. The problem with that approach is that there are many other reasons
(like wrong params) to get EINVAL. The other problem is when we have an
operation that existed before and gets new behavior via different attributes,
like accept and accept_direct. Older kernels can fall back to non direct
operation although we set attributes for direct operation. Operation completes
successfully in both cases but with different results.

This commit introduces kernel version check at the start of the test. Making
body of the test free of checking for various kernel version differences.

Feature availability references:
  * https://manpages.debian.org/unstable/liburing-dev/io_uring_enter.2.en.html
  * https://kernel.dk/axboe-kr2022.pdf
  * 5acf7969bc/lib/std/os/linux.zig (L3727)
  * 5acf7969bc/lib/std/os/linux.zig (L3993)
2023-11-17 16:31:57 +01:00
Igor Anić
256384a2ec io_uring: add direct operations
Add operation on direct file descriptors. Also referred to as fixed or
registered files.

References:
https://kernel.dk/axboe-kr2022.pdf
https://lwn.net/Articles/863071/

Added functions:

IO_Uring
  accept_direct
  accept_multishot_direct
  openat_direct
  close_direct
  socket
  socket_direct
  socket_direct_alloc

Raw prepare operations:
  io_uring_prep_accept_direct
  io_uring_prep_multishot_accept_direct
  io_uring_prep_openat_direct
  io_uring_prep_close_direct
  io_uring_prep_socket
  io_uring_prep_socket_direct
  io_uring_prep_socket_direct_alloc

Tested on this kernels:

5.4.0-164-generic
2559 passed; 70 skipped; 0 failed.

5.8.0-63-generic
2573 passed; 56 skipped; 0 failed.

5.11.0-49-generic
2576 passed; 53 skipped; 0 failed.

5.13.0-52-generic
2576 passed; 53 skipped; 0 failed.

5.15.0-87-generic
2579 passed; 50 skipped; 0 failed.

5.19.0-46-geneic
2584 passed; 45 skipped; 0 failed.

6.2.0-35-generic.log
2585 passed; 44 skipped; 0 failed.

6.5.0-9-generic
2585 passed; 44 skipped; 0 failed.
2023-11-17 13:48:17 +01:00
David
941090d94f
Move duplicate field detection for struct init expressions into AstGen
Partially addresses #17916.
2023-11-16 14:38:16 +00:00
Igor Anić
087ee497d4 io_uring: add zero-copy send operation
`send_zc` tries to avoid making intermediate copies of data. Zerocopy execution
is not guaranteed and may fall back to copying.

The flags field of the first struct io_uring_cqe may likely contain
IORING_CQE_F_MORE , which means that there will be a second completion event /
notification for the request, with the user_data field set to the same value.
The user must not modify the data buffer until the notification is posted. The
first cqe follows the usual rules and so its res field will contain the number
of bytes sent or a negative error code. The notification's res field will be set
to zero and the flags field will contain IORING_CQE_F_NOTIF. The two step model
is needed because the kernel may hold on to buffers for a long time, e.g.
waiting for a TCP ACK, and having a separate cqe for request completions allows
userspace to push more data without extra delays. Note, notifications are only
responsible for controlling the lifetime of the buffers, and as such don't mean
anything about whether the data has atually been sent out or received by the
other end. Even errored requests may generate a notification, and the user must
check for IORING_CQE_F_MORE rather than relying on the result.

Available since kernel 6.0.

References:
https://man7.org/linux/man-pages/man3/io_uring_prep_send_zc.3.html
https://man7.org/linux/man-pages/man2/io_uring_enter.2.html
2023-11-10 16:44:18 +01:00
Bogdan Romanyuk
ee8da40769 replace deprecated std.math.absCast 2023-11-09 17:39:27 +02:00
Igor Anić
715e5f757f fix io_uring tests on kernel 5.4
Unsupported tests are now skipped on kernel 5.4:
```
uname -a
Linux d20 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:31:37 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
zig test lib/std/std.zig --zig-lib-dir lib --main-mod-path lib/std 2>&1 | cat
709/2616 test.nop... OK
710/2616 test.readv... OK
711/2616 test.writev/fsync/readv... OK
712/2616 test.write/read... SKIP
713/2616 test.splice/read... SKIP
714/2616 test.write_fixed/read_fixed... OK
715/2616 test.openat... SKIP
716/2616 test.close... SKIP
717/2616 test.accept/connect/send/recv... SKIP
718/2616 test.sendmsg/recvmsg... OK
719/2616 test.timeout (after a relative time)... SKIP
720/2616 test.timeout (after a number of completions)... OK
721/2616 test.timeout_remove... SKIP
722/2616 test.accept/connect/recv/link_timeout... SKIP
723/2616 test.fallocate... SKIP
724/2616 test.statx... SKIP
725/2616 test.accept/connect/recv/cancel... SKIP
726/2616 test.register_files_update... SKIP
727/2616 test.shutdown... SKIP
728/2616 test.renameat... SKIP
729/2616 test.unlinkat... SKIP
730/2616 test.mkdirat... SKIP
731/2616 test.symlinkat... SKIP
732/2616 test.linkat... SKIP
733/2616 test.provide_buffers: read... SKIP
734/2616 test.remove_buffers... SKIP
735/2616 test.provide_buffers: accept/connect/send/recv... SKIP
736/2616 test.accept multishot... SKIP
```
2023-11-08 18:52:03 +01:00
Igor Anić
7a1dbbd4f9 fix io_uring timeout_remove test on kernel 5.4
There is no grantee that `copy_cqes` will return exactly wait_nr number of cqes.
If there are ready cqes it can return > 0 but < wait_nr number of cqes.
2023-11-08 18:25:29 +01:00
Igor Anić
bec36aa7c0 io_uring: add multishot accept operation
Server networking application typically accept multiple connections. Multishot
accept simplifies handling these situations. Applications submits once and
receives CQE whenever a new connection request comes in.

Multishot is active until it is canceled or experience error. While active, and
further notification are expected CQE completion will have IORING_CQE_F_MORE set
in the flags. If this flag isn't set, the application must re-arm this request
by submitting a new one.

Reference: [io_uring and networking in 2023](https://github.com/axboe/liburing/wiki/io_uring-and-networking-in-2023#multi-shot)
2023-11-06 00:12:39 +02:00
Jacob Young
509be7cf1f x86_64: fix std test failures 2023-11-03 23:18:21 -04:00
Ryan Liptak
ae6df9e967 start.zig: Replace kernel32 usage with ntdll
Co-authored-by: e4m2 <git@e4m2.com>
2023-11-03 19:25:46 +02:00
XXIV
c2cf47ab28
std.os.windows: remove unnecessary @ptrCast (#17816) 2023-11-01 18:45:51 -04:00
Kai Jellinghaus
7ee7c90274 Fix regressing #17290 from #17734 2023-11-01 18:30:56 +02:00
Andrew Kelley
3fc6fc6812 std.builtin.Endian: make the tags lower case
Let's take this breaking change opportunity to fix the style of this
enum.
2023-10-31 21:37:35 -04:00
Jacob Young
d890e81761 mem: fix ub in writeInt
Use inline to vastly simplify the exposed API.  This allows a
comptime-known endian parameter to be propogated, making extra functions
for a specific endianness completely unnecessary.
2023-10-31 21:37:35 -04:00
Kamil T
37295696ec std.os.windows additions and fixes 2023-10-29 11:01:54 +02:00
Andrew Kelley
e7ead9c5ea std: delete psapi, gdi32, and winmm
The only remaining Windows APIs now are the ones that the standard
library itself depends on for its cross-platform abstractions.

closes #4426
2023-10-29 00:58:00 -04:00
Andrew Kelley
d817a3c517 delete std.os.windows.user32
This is progress towards #4426
Closes #17417
2023-10-28 13:16:47 -04:00
Jacob Young
3b0dce8ebd
Merge pull request #17716 from jacobly0/x86_64
x86_64: pass more tests
2023-10-27 08:29:24 -04:00
Jacob Young
98cd378208 x86_64: fix behavior of getValue
Old behavior renamed to `getValueIfFree`.
2023-10-26 21:45:58 -04:00
Jacob Young
5e83441096 x86_64: implement @divFloor and @mod for i128 2023-10-26 21:45:57 -04:00
joadnacer
28b848e3f0 std.io_uring: Improve splice implementation 2023-10-27 00:31:55 +01:00
joadnacer
0005e7e70b std.linux: Update io_uring structs and consts for kernel 6.3.8 2023-10-27 00:31:52 +01:00
Jacob Young
b55377a5ab x86_64: pass more tests
* 128-bit integer multiplication with overflow
 * more instruction encodings used by std inline asm
 * implement the `try_ptr` air instruction
 * follow correct stack frame abi
 * enable full panic handler
 * enable stack traces
2023-10-25 04:28:30 -04:00
Jacob Young
8f69e977f1 x86_64: implement 128-bit builtins
* `@clz`
 * `@ctz`
 * `@popCount`
 * `@byteSwap`
 * `@bitReverse`
 * various encodings used by std
2023-10-23 22:42:18 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadb.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab, reversing
changes made to 5f92b070bf.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jacob Young
32e85d44eb x86_64: disable failing tests, enable test-std testing 2023-10-21 10:55:41 -04:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
joadnacer
89aad1b89c linux.io_uring: Implement splice functions 2023-10-21 05:02:17 +03:00
Prokop Randacek
fee09009a8 gettimeofday takes nullable pointers 2023-10-20 00:15:34 -04:00
Ben Crist
6d47198303 return error.AlreadyTerminated from std.ChildProcess.kill when necessary 2023-10-17 16:56:15 -07:00
kcbanner
68ed787751 windows: fix ReadLink not using a synchronous file handle 2023-10-17 14:33:55 -04:00
Andrew Kelley
877393d17a std.fs: fix relative symbolic links on Windows
closes #17564
2023-10-17 06:27:07 -04:00
Ratakor
8ce33795e9 Add pause() to linux.zig 2023-10-06 11:49:31 -07:00
Ratakor
cef90eab57 Add filled_sigset to os.linux
filled_sigset is equivalent to sigfillset() as empty_sigset is
equivalent to sigemptyset().
2023-10-06 11:49:31 -07:00
Jacob Young
2a5335d7b6 x86_64: implement C abi for 128-bit integers 2023-10-04 14:42:35 -04:00
nikneym
9f0d2f9417 linux: add fanotify API 2023-10-04 13:48:22 +03:00
Kai Jellinghaus
11489bb04f
Update IORING_OP to reflect upstream (#17388)
Reference [upstream io_uring.h](cbf3a2cb15/include/uapi/linux/io_uring.h (L234))
2023-10-04 09:18:14 +00:00
Stephen Gregoratto
285970982a Add illumos OS tag
- Adds `illumos` to the `Target.Os.Tag` enum. A new function,
  `isSolarish` has been added that returns true if the tag is either
  Solaris or Illumos. This matches the naming convention found in Rust's
  `libc` crate[1].
- Add the tag wherever `.solaris` is being checked against.
- Check for the C pre-processor macro `__illumos__` in CMake to set the
  proper target tuple. Illumos distros patch their compilers to have
  this in the "built-in" set (verified with `echo | cc -dM -E -`).

  Alternatively you could check the output of `uname -o`.

Right now, both Solaris and Illumos import from `c/solaris.zig`. In the
future it may be worth putting the shared ABI bits in a base file, and
mixing that in with specific `c/solaris.zig`/`c/illumos.zig` files.

[1]: 6e02a329a2/src/unix/solarish
2023-10-02 15:31:49 -06:00
Stephen Gregoratto
bc0bf4e97a Linux: Add cachestat wrapper.
Can be tested using this program I whipped up:
https://gist.github.com/The-King-of-Toasters/aee448f5975c50f735fd1946794574f7
2023-09-28 18:58:05 +10:00
Stephen Gregoratto
5f456b2b97 Update Linux syscalls for kernel 5.5
The latest addition is `cachestat`, which provides more detailed
information for paged files.
2023-09-28 18:58:05 +10:00
Kai Jellinghaus
d1e39b6914 Add new fields to io_sqring_offsets & io_cqring_offsets
`user_addr`s were introduced in `03d89a2` ([github link](03d89a2de2) which was shipped in v6.5
`flags` was introduced even earlier
2023-09-26 18:16:36 -07:00
Aven Bross
6c54ed73f7 Added basic support for wasm32-emscripten target 2023-09-22 12:49:03 -07:00
nikneym
ada02ac6fe wasi: update sock_recv and sock_send according to preview1 2023-09-18 00:27:27 -07:00
bfredl
1a0e6bcdb1 bpf: remove unhelpful "comptime" and fix union order
Insn.st() can be used with dynamic size just like Insn.stx(), which is
relevant in a code generation context.

using ImmOrReg caused an error as its fields were ordered differently than
Source.
2023-09-15 01:05:52 -07:00
Rafael Fernández López
69982339ed std: add compile error when using std.os.getenv on the wasi target
`std.process.getEnvMap` or `std.process.getEnvVarOwned` should be used
instead, requiring allocation.
2023-09-14 20:04:35 +03:00
Jakub Konka
0e8f130aed
Merge pull request #16977 from kcbanner/lib_getauxval_fixup
linux: export getauxval when not compiling with libc
2023-09-04 09:11:15 +02:00
Jim Calabro
ec5a068ac1
Make a Couple Syscall Comments Consistent (#17066)
* Make a Couple Syscall Comments Consistent

* linux.diet.net -> man7.org
2023-09-04 09:09:11 +02:00
Jan Philipp Hafer
1816bb4ab0 std.os+windows: isAtLeast(.win10_rs5) in renameatW(), DeleteFile() for posix semantics
Usage of FILE_RENAME_IGNORE_READONLY_ATTRIBUTE or
FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE for posix semantics require
win10_rs5 instead of win10_rs1 necessary for posix semantics. Keep it as simple
as possible, since it is reasonable to expect users being able to update
win10_rs5 or use non-posix semantics instead.

Closes #17049.
2023-09-03 08:35:26 +02:00
kcbanner
2e2d6d2c3d linux: fixup for platforms that don't support extern functions yet 2023-08-27 19:50:57 -04:00
kcbanner
fb0cef8522 linux: only export getauxval if not linking libc 2023-08-27 16:52:43 -04:00
kcbanner
fba81cd606 linux: instead of export elf_aux_maybe, export getauxval itself 2023-08-27 11:12:31 -04:00
kcbanner
731c6d3fbb linux: export elf_aux_maybe so that libraries can call getauxval 2023-08-26 17:55:12 -04:00
xdBronch
4403008cab
fix compile errors introduced by #16953 (#16955) 2023-08-25 21:07:24 +00:00
Andrew Kelley
a31748b29e std.os.uefi: reorganize namespaces
This is a breaking change.

This commit applies the following rules to std.os.uefi:
* avoid redundant names in the namespace such as "protocol.FooProtocol"
* don't initialize struct field to undefined. do that at the
  initialization site if you want that, or create a named constant that
  sets all the fields to undefined.
* avoid the word "data", "info", "context", "state", "details", or
  "config" in the type name, especially if a word from that category is
  already in the type name.
* embrace tree structure

After following these rules, `usingnamespace` disappeared naturally.
This commit eliminates 26/53 (49%) instances of `usingnamespace` in the
standard library. All these uses were due to not understanding how
to properly use namespaces.

I did not test this commit. The standard library UEFI code is
experimental and pull requests have been accepted with minimal vetting.
Users of std.os.uefi will need to submit follow-up pull requests to fix
up whatever regressions this commit introduces, this time without
abusing namespaces (pun intended).
2023-08-24 22:38:47 -07:00
matu3ba
7a834e2581
std.windows: use atomic rename, if possible (#16717)
Mitigates #14978.

Uses the same strategy as in #16499 suggested by @squeek502
2023-08-23 20:11:01 -04:00
Ryan Liptak
e078324dbe Add NetworkNotFound to ReadLinkError
This matches how other filesystem functions were made to handle BAD_NETWORK_PATH/BAD_NETWORK_NAME in https://github.com/ziglang/zig/pull/16568. ReadLink was the odd one out, but that is no longer the case.
2023-08-18 18:07:16 -07:00
Ryan Liptak
2b44961a20 Fix ntToWin32Namespace and friends on big endian architectures 2023-08-17 00:59:19 -07:00
Ryan Liptak
3819e69376 windows.GetFinalPathNameByHandle: Support UNC paths 2023-08-15 15:52:34 -07:00
Ryan Liptak
19b219bc8a Fix windows.CreateSymbolicLink/ReadLink for non-relative paths
This fixes a few things:
- Previously, CreateSymbolicLink would always create a relative link if a `dir` was provided, but the relative-ness of a link should be determined by the target path, not the null-ness of the `dir`.
- Special handling is now done to symlink to 'rooted' paths correctly (they are treated as a relative link, which is different than how the xToPrefixedFileW functions treat them)
- ReadLink now correctly supports UNC paths via a new `ntToWin32Namespace` function which intends to be an analog of `RtlNtPathNameToDosPathName` (RtlNtPathNameToDosPathName is not used because it seems to heap allocate as it takes an RTL_UNICODE_STRING_BUFFER)
2023-08-15 15:52:33 -07:00
Andrew Kelley
35b85d3ba5
Merge pull request #16783 from squeek502/fs-too-many-parent-dirs
Windows: Fix `TooManyParentDirs` handling for paths that shouldn't be cwd-relative
2023-08-12 10:38:31 -07:00
Ryan Liptak
3f9294c735 Windows: Fix TooManyParentDirs handling for paths that shouldn't be cwd-relative
Previously, a relative path like `..` would:
- Attempt to be normalized (i.e. remove . and .. without any path resolution), but would error with TooManyParentDirs
- This would make wToPrefixedFileW run it through `RtlGetFullPathName_U` to do the necessary path resolution, but `RtlGetFullPathName_U` always resolves relative paths relative to the CWD

Instead, when TooManyParentDirs occurs, we now look up the path of the passed in `dir` (if it's non-null) and append the relative path to it before giving it to `RtlGetFullPathName_U`. If `dir` is null, then we just give it RtlGetFullPathName_U directly and let it resolve it relative to the CWD.

Closes #16779
2023-08-11 18:58:40 -07:00
mllken
9676a43a5d linux: add setsid 2023-08-09 11:33:06 -07:00
Jacob G-W
d0fbfd3c9f Plan 9: add more features to std.os.plan9
* Replaces the exit assembly with the function from std.
* Reads the top-of-stack struct at program startup that can get information
  like the pid.
* Changes the read and write functions to use the Pread and Pwrite syscalls
  instead of the depreciated _READ and _WRITE
* Changes the openat function to use flags instead of perms.
  Plan9 does not support perms when opening, just when creating.
* Adds an errstr function to read the errstr buf created by the kernel
2023-08-02 18:19:07 -04:00
Jacob G-W
841b54f5e3 std: add SbrkAllocator and use it for Plan 9
Implements issue #6451.
This was needed to support allocation on Plan 9 and now other operating
systems like DOS can also use it.

It is a modified version of the WasmAllocator since wasm also uses a
sbrk-esque allocation system.

This commit also adds the necessary system bits for sbrk to work on plan 9.
2023-08-02 17:39:52 -04:00
Jacob G-W
b9aa1dcaf1 plan 9: filesystem support 2023-08-02 17:39:52 -04:00
Andrew Kelley
e84cda0ebf
Merge pull request #16622 from jacobly0/cbe-asm-compat
CBE: fix regressions and get new targets passing behavior tests
2023-07-31 15:34:32 -07:00
Andrew Kelley
8678d445c2 Revert "linux adding some NUMA support"
This reverts commit 6f418c11e1.
2023-07-31 11:02:43 -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
833af381f0 Revert "std.os: add linux timer api"
This reverts commit b9d2e0e308.
2023-07-31 10:56:55 -07:00
Jacob Young
228c956377 std: finish cleanup up asm
This also required implementing the necessary syntax in the x86_64 backend.
2023-07-31 03:49:21 -04:00
Jacob Young
817fa3af86 std: cleanup asm usage
After fixing some issues with inline assembly in the C backend, the std
cleanups have the side effect of making these functions compatible with
the backend, allowing it to be used on linux without linking libc.
2023-07-31 01:58:10 -04:00
Ryan Liptak
8579f720b0 windows_sdk.zig: Reinstate COM ISetupEnumInstances logic
The C++ version of this code used this logic, and it turns out it is able to find some setups that the current registry/Vs7 methods cannot.

For example, if only the "Build Tools for Visual Studio" are installed but not Visual Studio itself, then only the ISetupEnumInstances method seems to find it.

Follow up to #15657, fixes a regression caused by moving from the C++ version to the Zig version
2023-07-28 19:19:32 -07:00
Ryan Liptak
49053cb1b4 Add fs.path.ComponentIterator and use it in Dir.makePath
Before this commit, there were three issues with the makePath implementation:

1. The component iteration did not 'collapse' consecutive path separators; instead, it would treat `a/b//c` as `a/b//c`, `a/b/`, `a/b`, and `a`.
2. Trailing path separators led to redundant `makeDir` calls, e.g. with the path `a/b/` (if `a` doesn't exist), it would try to create `a/b/`, then try `a/b`, then try `a`, then try `a/b`, and finally try `a/b/` again.
3. The iteration did not treat the root of a path specially, so on Windows it could attempt to make a directory with a path like `X:` for something like `X:\a\b\c` if the `X:\` drive doesn't exist. This didn't lead to any problems that I could find, but there's no reason to try to make a drive letter as a directory (or any other root path).

This commit fixes all three issues by introducing a ComponentIterator that is root-aware and handles both sequential path separators and trailing path separators and uses it in `Dir.makePath`. This reduces the number of `makeDir` calls for paths where (1) the root of the path doesn't exist, (2) there are consecutive path separators, or (3) there are trailing path separators

As an example, here are the makeDir calls that would have been made before this commit when calling `makePath` for a relative path like `a/b//c//` (where the full path needs to be created):

a/b//c//
a/b//c/
a/b//c
a/b/
a/b
a
a/b
a/b/
a/b//c
a/b//c/
a/b//c//

And after this commit:

a/b//c
a/b
a
a/b
a/b//c
2023-07-27 10:22:54 -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
Zachary Raineri
dc98b001f3 std.os.linux | Fix sendmmsg function | Issue #16513
Closes #16513
2023-07-25 11:04:10 -07:00
mllken
dc24835168 io_uring: let the OS choose a free local port for all tests
closes #14907
2023-07-24 20:12:41 -07:00
Zachary Raineri
d82b359010 Use builtin inference over @as where possible 2023-07-24 10:23:51 -07:00
Andrew Kelley
77b96231a6
Merge pull request #15657 from BratishkaErik/windows-sdk-finder-port-to-zig
src/windows_sdk.cpp: port to Zig
2023-07-24 09:34:56 -07:00
Ryan Liptak
c57749f5ce Handle INVALID_DEVICE_REQUEST in std.os.windows.DeviceIoControl
This is possible when e.g. calling CreateSymbolicLink on a FAT32 filesystem
2023-07-23 19:10:05 -07:00
Ryan Liptak
3f7166eb8b child_process: Fix regression on Windows for FAT filesystems
This fixes a regression caused by https://github.com/ziglang/zig/pull/13993

As an optimization, the first call to `NtQueryDirectoryFile` would only ask for a single result and assume that if the result returned did not match the app_name exactly, then the unappended app_name did not exist. However, this relied on the assumption that the unappended app_name would always be returned first, but that only seems to be the case on NTFS. On FAT filesystems, the order of returned files can be different, which meant that it could assume the unappended file doesn't exist when it actually does.

This commit fixes that by fully iterating the wildcard matches via `NtQueryDirectoryFile` and taking note of any unappended/PATHEXT-appended filenames it finds. In practice, this strategy does not introduce a speed regression compared to the previous (buggy) implementation.

Benchmark 1 (10 runs): winpathbench-master.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           508ms ± 4.08ms     502ms …  517ms          1 (10%)        0%
  peak_rss           3.62MB ± 2.76KB    3.62MB … 3.63MB          0 ( 0%)        0%
Benchmark 2 (10 runs): winpathbench-fat32-fix.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           500ms ± 21.4ms     480ms …  535ms          0 ( 0%)          -  1.5% ±  2.8%
  peak_rss           3.62MB ± 2.76KB    3.62MB … 3.63MB          0 ( 0%)          -  0.0% ±  0.1%

---

Partially addresses #16374 (it fixes `zig build` on FAT32 when no `zig-cache` is present)
2023-07-23 19:09:20 -07:00
Eric Joldasov
664ecdfb8e
std.os.windows.advapi32: add RegLoadAppKeyW
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-07-23 17:10:57 +06:00
Eric Joldasov
a89b83cc9d
std.os.windows.advapi32: add RegGetValueW
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-07-23 17:10:57 +06:00
Ryan Liptak
1ae378e7a2 windows.DeleteFile: Use FileDispositionInformationEx if possible, but fallback if not
Using FileDispositionInformationEx (and therefore flags like FILE_DISPOSITION_POSIX_SEMANTICS and FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE) is only supported on NTFS, so the comptime Windows version range check is not enough to determine whether or not the NtSetInformationFile will succeed.

This commit makes DeleteFile always try using FileDispositionInformationEx first, but if INVALID_PARAMETER is received (which is the status that occurs when the filesystem doesn't support FileDispositionInformationEx), then it will fallback and try calling NtSetInformationFile with FileDispositionInformation.

This keeps NTFS as fast as it was before, since it will do at most 1 NtSetInformationFile call, but on non-NTFS filesystems (e.g. FAT32), DeleteFile may need to do 2 NtSetInformationFile calls.

Closes #16497
2023-07-23 01:26:26 -07:00
kcbanner
891fa3b8b5 debug: fix initialization of the optional fields on StackIterator
dwarf: documentation fixups
target: enable unwind tables on macho
2023-07-20 22:58:15 -04:00
kcbanner
f991b9dc05 debug: fix reading -gdwarf generated debug sections in COFF files
I had accidentally regressed support for -gdwarf in 461fb499f3 when I changed the logic to
use the already-mapped exe/dll image instead of loading it from disk. The string table is mapped as all zeroes by the loader,
so if a section header's name is longer than 8 bytes (like the ones generated by -gdwarf), then the name can't be read.

Now, if any section headers require the string table, the file is mapped from disk.

windows: Add NtCreateSection/NtMapViewOfSection/NtUnmapViewOfSection
2023-07-20 22:58:14 -04:00
kcbanner
caa334712f linux: rework getcontext to closer match the specification (saved IP/SP match the state after it would return)
debug: fixup ucontext_t check
2023-07-20 22:58:14 -04:00
kcbanner
89ef004646 debug: x86 unwinding support, more unwinding fixes
- Fix unwindFrame using the previous FDE row instead of the current one
- Handle unwinding through noreturn functions
- Add x86-linux getcontext
- Fixup x86_64-linux getcontext not restoring the fp env
- Fix start_addr filtering on x86-windows
2023-07-20 22:58:14 -04:00
kcbanner
41832aa1e6 linux: add getcontext for x86_64 2023-07-20 22:58:14 -04:00
xdBronch
e313584a48 more UEFI alignment fixes 2023-07-20 12:46:33 -07:00
xdBronch
b177e17d15 fix alignment error in uefi FileInfo protocol
previously complained about `[*]const u8` having alignment 1 and `[*:0]const u16` having alignment 2
2023-07-14 00:31:31 -07:00
Andrew Kelley
cc56ab8c68
Merge pull request #16100 from squeek502/windows-path-compare
fs.path: Fix Windows path component comparison being ASCII-only
2023-07-10 11:17:07 -07:00
r00ster91
9be1a3f7ef std.os.uefi: use std.os.uefi.cc instead of .C as calling convention
I tested this and this definitely compiles and these
changes were done programmatically but if there's still anything wrong
it shouldn't be hard to fix.
With this change it's going to be very easy to make further adjustments
to the calling conventions of all these external UEFI functions.

Closes #16309
2023-07-08 17:32:36 -04:00
Jacob Young
78eb3c5617 bootstrap: support aarch64 in 32-bit mode
* `CMakeLists.txt`: support the weird `uname -m` output.
 * `CMakeLists.txt`: detect and use the C compiler's default arm mode.
 * cbe: support gcc with both `f128` and `u128` emulated.
 * std.os.linux.thumb: fix incorrectly passed asm inputs.
2023-07-04 15:47:07 -07:00
Ryan Liptak
cfcf9cd9b7 Add os.windows.nls.upcaseW, a cross-platform implementation of RtlUpcaseUnicodeChar
This allows doing Windows-style case insensitive comparisons from any target, but means that it will need to include its own copy of the uppercase data table (5,088 bytes) to do so.

When targeting Windows, the ntdll functions are used instead to avoid including a redundant copy of the uppercase data in the resulting binary.
2023-06-30 15:29:43 -07: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
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
Christofer Nolander
59a12cd293 windows: detect ANSI support in more terminals 2023-06-17 23:30:17 -07:00
Andrew Kelley
e3736baddb
Merge pull request #15501 from matu3ba/win_rmwithposix
std.windows: use posix semantics to delete files, if available
2023-06-17 14:21:15 -07:00
r00ster91
6e84f46990 std: replace builtin.Version with SemanticVersion 2023-06-17 13:17:34 -07:00
Motiejus Jakštys
d41111d7ef mem: rename align*Generic to mem.align*
Anecdote 1: The generic version is way more popular than the non-generic
one in Zig codebase:

     git grep -w alignForward | wc -l
    56
     git grep -w alignForwardGeneric | wc -l
    149

     git grep -w alignBackward | wc -l
    6
     git grep -w alignBackwardGeneric | wc -l
    15

Anecdote 2: In my project (turbonss) that does much arithmetic and
alignment I exclusively use the Generic functions.

Anecdote 3: we used only the Generic versions in the Macho Man's linker
workshop.
2023-06-17 12:49:13 -07:00
Andrew Kelley
78c8cb4225
Merge pull request #16003 from g-w1/plan9-lazy-syms
Plan9: lots of fixes
2023-06-16 21:57:33 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -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
bfredl
4f914c8414 bpf: expose "syscall" program type and F_SLEEPABLE flag 2023-06-13 10:57:51 -07:00
Jacob G-W
c842deea75 os/plan9: fix order of register setting in syscall1
We need to set rbp last because the arguments are stored on the
stack. If we clobber rbp first, then we will get a segfault when
trying to access the function arguments.

I believe I had already done this with the other syscall* functions,
but not with syscall1, so this allows single argument syscalls like
close to work.
2023-06-10 11:36:32 +03:00
Jakub Konka
76aa1fffb7
Merge pull request #15905 from jacobly0/x86_64-hotfix
x86_64: hotfix for crash during in-memory coercion of large type
2023-05-30 13:22:13 +02:00
Jacob Young
28df1d09dc Revert "Revert "Windows: Support UNC, rooted, drive relative, and namespaced/device paths""
This reverts commit b5fad3a40a.

The latent x86_64 backend bug has been fixed.
2023-05-29 22:09:13 -04:00
mlugg
4976b58ab1
Prevent analysis of functions only referenced at comptime
The idea here is that there are two ways we can reference a function at runtime:

* Through a direct call, i.e. where the function is comptime-known
* Through a function pointer

This means we can easily perform a form of rudimentary escape analysis
on functions. If we ever see a `decl_ref` or `ref` of a function, we
have a function pointer, which could "leak" into runtime code, so we
emit the function; but for a plain `decl_val`, there's no need to.

This change means that `comptime { _ = f; }` no longer forces a function
to be emitted, which was used for some things (mainly tests). These use
sites have been replaced with `_ = &f;`, which still triggers analysis
of the function body, since you're taking a pointer to the function.

Resolves: #6256
Resolves: #15353
2023-05-29 23:06:08 +01:00
Andrew Kelley
b5fad3a40a Revert "Windows: Support UNC, rooted, drive relative, and namespaced/device paths"
This reverts commit 1697d44809.

Master branch started failing after this commit landed.
2023-05-29 15:01:24 -07:00
Ryan Liptak
1697d44809 Windows: Support UNC, rooted, drive relative, and namespaced/device paths
There are many different types of Windows paths, and there are a few different possible namespaces on top of that. Before this commit, NT namespaced paths were somewhat supported, and for Win32 paths (those without a namespace prefix), only relative and drive absolute paths were supported. After this commit, all of the following are supported:

- Device namespaced paths (`\\.\`)
- Verbatim paths (`\\?\`)
- NT-namespaced paths (`\??\`)
- Relative paths (`foo`)
- Drive-absolute paths (`C:\foo`)
- Drive-relative paths (`C:foo`)
- Rooted paths (`\foo`)
- UNC absolute paths (`\\server\share\foo`)
- Root local device paths (`\\.` or `\\?` exactly)

Plus:

- Any of the path types and namespace types can be mixed and matched together as appropriate.
- All of the `std.os.windows.*ToPrefixedFileW` functions will accept any path type, prefixed or not, and do the appropriate thing to convert them to an NT-prefixed path if necessary.

This is achieved by making the `std.os.windows.*ToPrefixedFileW` functions behave like `ntdll.RtlDosPathNameToNtPathName_U`, but with a few differences:

- Does not allocate on the heap (this is why we can't use `ntdll.RtlDosPathNameToNtPathName_U` directly, it does internal heap allocation).
- Relative paths are kept as relative unless they contain too many .. components, in which case they are treated as 'drive relative' and resolved against the CWD (this is how it behaved before this commit as well).
- Special case device names like COM1, NUL, etc are not handled specially (TODO)
- `.` and space are not stripped from the end of relative paths (potential TODO)

Most of the non-trivial conversion of non-relative paths is done via `ntdll.RtlGetFullPathName_U`, which AFAIK is used internally by `ntdll.RtlDosPathNameToNtPathName_U`.

Some relevant reading on Windows paths:

- https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html
- https://chrisdenton.github.io/omnipath/Overview.html

Closes #8205
Might close (untested) #12729

Note:
- This removes checking for illegal characters in `std.os.windows.sliceToPrefixedFileW`, since the previous solution (iterate the whole string and error if any illegal characters were found) was naive and won't work for all path types. This is further complicated by things like file streams (where `:` is used as a delimiter, e.g. `file.ext:stream_name:$DATA`) and things in the device namespace (where a path like `\\.\GLOBALROOT\??\UNC\localhost\C$\foo` is valid despite the `?`s in the path and is effectively equivalent to `C:\foo`). Truly validating paths is complicated and would need to be tailored to each path type. The illegal character checking being removed may open up users to more instances of hitting `OBJECT_NAME_INVALID => unreachable` when using `fs` APIs.
  + This is related to https://github.com/ziglang/zig/issues/15607
2023-05-29 13:08:51 +03:00
Veikka Tuominen
ca16f1e8a7 std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
2023-05-26 21:42:19 -07:00
yujiri8
a1bb9e94d4
fix type errors in os.linux (#15801)
* fix NUMA-related functions in os.linux

* fix os.linux.CPU_ISSET
2023-05-22 13:34:39 +03:00
David CARLIER
b9d2e0e308 std.os: add linux timer api 2023-05-19 03:41:10 +03:00
David CARLIER
c7bf8bab38 std.os: adding linux's sched_setaffinity and its wrapper 2023-05-13 21:18:18 +03:00
Veikka Tuominen
68bacad804
Merge pull request #15643 from Vexu/fixes
make `@call` compile errors match regular calls
2023-05-13 12:52:16 +03:00
David CARLIER
6f418c11e1 linux adding some NUMA support 2023-05-13 12:13:02 +03:00
Gregory Mullen
aa9ea61216 Add tc{set,get}pgrp to std.os.linux 2023-05-11 19:43:06 +03:00
Veikka Tuominen
f0fdaf32d3 fix incorrect use of mutable pointers to temporary values 2023-05-11 17:23:06 +03:00
dweiller
bd3360e03d convert s[start..start+len] to s[start..][0..len] 2023-05-07 15:55:21 +10:00
Tw
855493bb8b bpf: correct return type of ringbuf_output helper
Signed-off-by: Tw <weii.tan>
2023-05-03 08:37:40 +03:00
Jan Philipp Hafer
7594d2c097 address review by user @squeek502 2023-05-01 18:22:28 +02:00
Jan Philipp Hafer
be50dbf1ce apply suggestion by user @xEgoist
FILE_DISPOSITION_ON_CLOSE is used to set/clear the FILE_DELETE_ON_CLOSE,
but we do not use that anymore and FILE_DISPOSITION_POSIX_SEMANTICS
already implies unmapping of the handle and removal fo it on close.
2023-05-01 15:46:58 +02:00
Martin Wickham
0f0f005e92 std.windows: use posix semantics to delete files, if available
Justification: When a file is deleted on Windows, it may not be
immediately removed from the directory. This can cause problems
with future scans of that directory, which will see the partially
deleted file. Under some workloads and system configurations,
Windows files may appear to be deleted immediately.

This is the PR with requested fixup. Thanks to @SpexGuy for the
original PR.
2023-05-01 15:46:58 +02: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
624c3069b4 std.os.windows: fix overlapping copy 2023-04-28 13:24:43 -07:00
Andrew Kelley
125221cce9 std: update to use @memcpy directly 2023-04-28 13:24:43 -07:00
Andrew Kelley
6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
朕与将军解战袍
363269a2a9
fix incorrect struct definition 2023-04-27 11:10:38 +03:00
Andrew Kelley
401b7f6f53 zig fmt 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
Jacob Young
d8bdfd8192 std: fix windows resource leaks 2023-04-24 16:50:44 -07:00
zooster
bc8e1e1de4
Improvements to docs and text
* docs(std.math): elaborate on difference between absCast and absInt

* docs(std.rand.Random.weightedIndex): elaborate on likelihood

I think this makes it easier to understand.

* langref: add small reminder

* docs(std.fs.path.extension): brevity

* docs(std.bit_set.StaticBitSet): mention the specific types

* std.debug.TTY: explain what purpose this struct serves

This should also make it clearer that this struct is not supposed to provide unrelated terminal manipulation functionality such as setting the cursor position or something because terminals are complicated and we should keep this struct simple and focused on debugging.

* langref(package listing): brevity

* langref: explain what exactly `threadlocal` causes to happen

* std.array_list: link between swapRemove and orderedRemove

Maybe this can serve as a TLDR and make it easier to decide.

* PrefetchOptions.locality: clarify docs that this is a range

This confused me previously and I thought I can only use either 0 or 3.

* fix typos and more

* std.builtin.CallingConvention: document some CCs

* langref: explain possibly cryptic names

I think it helps knowing what exactly these acronyms (@clz and @ctz) and
abbreviations (@popCount) mean.

* variadic function error: add missing preposition

* std.fmt.format docs: nicely hyphenate

* help menu: say what to optimize for

I think this is slightly more specific than just calling it
"optimizations". These are speed optimizations. I used the word
"performance" here.
2023-04-23 21:06:21 +03:00
Hubert Jasudowicz
253eb72c14 std.os.linux: Add new CAP constants 2023-04-23 20:58:30 +03:00
Andrew Kelley
21aa55d34e
Merge pull request #15356 from jacobly0/cbe-std-tests
cbe: enable CI for std tests
2023-04-22 11:04:36 -07:00
-k
0282c2a924 doc: fix minor grammar issues 2023-04-22 13:09:15 +03:00
Jacob Young
7ca9b835a1 std: disable failing test
Tracked by #15381
2023-04-21 16:36:31 -04:00
Jacob Young
bf6fd9ae3f cbe: enable CI for std tests 2023-04-21 16:36:10 -04:00
Andrew Kelley
a86759984c
Merge pull request #15316 from xEgoist/fileDisposition
windows: use NtSetInformationFile in DeleteFile.
2023-04-20 16:30:27 -07:00
Andrew Kelley
e102adc863 work around an intermittent io_uring test failure
See #15362
2023-04-19 22:49:51 -07:00
mlugg
77fdd76c16 std: fix uses of comptime blocks in non-inline functions
ccf670c made using `return` from within a comptime block in a non-inline
function illegal, since it is a use of runtime control flow in a
comptime block. It is allowed if the function in question is `inline`,
since no actual control flow occurs in this case. A few functions from
std (notably `std.fmt.comptimePrint`) needed to be marked `inline` to
support this change.
2023-04-18 19:51:18 -07:00
xEgoist
8c79559748 windows: Handle DELETE_PENDING in DeleteFile.
DELETE_PENDING can happen when the file is yet to be closed for deletion
or if it never get closed. In that case, DeleteFile should assume the
file deletion is succeeding (no CloseHandle is required as it's a "failure"). In case of `DELETE_PENDING` failure, the file
may still exist. In which case if it's part of `deleteTree`, it will
eventually fail on `error.DirNotEmpty`.
2023-04-18 19:59:33 -05:00
xEgoist
89334fae20 windows: better error handling for DeleteFile. 2023-04-17 22:35:04 -05:00
xEgoist
911f74e93b windows: use NtSetInformationFile in DeleteFile.
Using `FILE_DELETE_ON_CLOSE` can silently succeed without reporting any error
on non-empty directory. This commit adds usage of NtSetInformationFile
which will report `DIRECTORY_NOT_EMPTY`.
2023-04-16 15:18:15 -05:00
xEgoist
0733c8c5ca windows: replace GetPhysicallyInstalledSystemMemory with ntdll.
`GetPhysicallyInstalledSystemMemory` uses SMBios to grab the physical
memory size which can lead to unecessary allocation and inacurate
representation of the total memory. Using `System_Basic_Information`
help to retrieve the physical memory which is not reserved for the
kernel/tables. This aligns better with the linux side as `/proc/meminfo`
does the same thing.
2023-04-14 13:43:03 -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
fde1ec5d0e x86_64: remove returns from naked functions 2023-04-03 17:45:16 +02:00
Jakub Konka
349349fa01 std: simplify VirtualProtectEx and fix ntdll signature 2023-03-30 21:08:31 +02:00
Jakub Konka
ba5302c4f8 std: move ntdll wrappers to std.os.windows 2023-03-30 21:08:31 +02:00
Jakub Konka
5d387742fd coff: reimplement VirtualProtectEx using our own ntdll wrapper 2023-03-30 21:08:31 +02:00
bing
64214b1ca6
Change ordering of prep provide buffers args 2023-03-30 16:51:57 +00:00
Tw
5d63d1115f bpf: add missing *const for helper functions
Signed-off-by: Tw <tw19881113@gmail.com>
2023-03-28 14:30:12 +03:00
xEgoist
8f4548dd69 fmt: lib/std/os/windows/ntdll.zig 2023-03-23 15:20:03 -05:00
xEgoist
2f5af6c972 Refactored GetProcessMemoryInfo to return VM_COUNTERS
This change allows the function to return the process memory info
directly instead of copying the result of the underlying Nt function.
2023-03-23 06:13:26 -05:00
xEgoist
70469d428d Implemented Zig wrapper for GetProcessMemoryInfo
`GetProcessMemoryInfo` is implemented using `NtQueryInformationProcess`
with `ProcessVmCounters` to obtain `VM_COUNTERS`. The structs, enum
definitions are found in `winternl.h` or `ntddk.h` in the latest WDK.
This should give the same results as using `K32GetProcessMemoryInfo`
2023-03-22 06:13:11 -05: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