Commit Graph

1156 Commits

Author SHA1 Message Date
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
Reuben Dunnington
30427ff794
Fix GetFileInformationByHandle compile error (#14829)
* Fix GetFileInformationByHandle compile error

The wrapper function was mistakenly referencing ntdll.zig when the actual function is declared in kernel32.zig.

* delete GetFileInformationByHandle since it's not used by the stdlib
2023-03-19 23:23:05 +00:00
Ryan Liptak
2fce991d2a Remove std.os.windows.QueryInformationFile (a wrapper of NtQueryInformationFile)
This function is unused, and the current implementation contains a few footguns:

- The current wrapper treats all possible errors as unexpected, even likely ones like BUFFER_OVERFLOW (which is returned if the size of the out_buffer is too small to contain all the variable-length members of the requested info, which the user may not actually care about)
- Each caller may need to handle errors differently, different errors might be possible depending on the FILE_INFORMATION_CLASS, etc, and making a wrapper that handles all of those different use-cases nicely seems like it'd be more trouble than it's worth (FILE_INFORMATION_CLASS has 76 different possible values)

If a wrapper for NtQueryInformationFile is wanted, then it should probably have wrapper functions per-use-case, like how QueryObjectName wraps NtQueryObject for the `ObjectNameInformation` class
2023-03-19 17:33:25 +01:00
Andrew Kelley
68c7261e1d disable bad std lib tests
see tracking issue #14968
2023-03-16 18:25:59 -07: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
cdda395590 std lib tests: avoid cwd races by using std.testing.tmpDir 2023-03-15 10:48:15 -07:00
Andrew Kelley
6d6f6a4ac6 std.os.windows.OpenFile: handle DELETE_PENDING
This error means that there *was* a file in this location on the file
system, but it was deleted. However, the OS is not finished with the
deletion operation, and so this CreateFile call has failed. There is not
really a sane way to handle this other than retrying the creation after
the OS finishes the deletion.
2023-03-15 10:48:15 -07:00
Andrew Kelley
22d94eaf32 disable std lib unit tests that hard code port numbers
See tracking issue #14907
2023-03-15 10:48:15 -07:00
Andrew Kelley
3b29d00c98 add std.process.totalSystemMemory 2023-03-15 10:48:13 -07:00
Andrew Kelley
41a5ad28c9 std: child process API supports rusage data 2023-03-15 10:48:13 -07:00
Andrew Kelley
4f4ddf5ef2 hot code swapping PoC working
- improve fn prototypes of process_vm_writev
 - make the memory writable in the ELF file
 - force the linker to always append the function
 - write updates with process_vm_writev
2023-03-15 10:48:12 -07:00
Andrew Kelley
ee693bfe04 std.os.linux: add ptrace 2023-03-15 10:48:12 -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
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
Gaëtan
bbba701a41 std.os.windows.advapi32: Add RegCloseKey 2023-03-07 18:14:37 -05: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
Binary Craft
a7a709aaa9 Fixes #13893 - some standard library networking tests are failing on Windows 2023-03-01 02:54:43 -05:00
Gaëtan S
5f70c36fa8 fix RegQueryValueExW api 2023-02-24 13:22:12 -05:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Veikka Tuominen
7199d7c777 split @qualCast into @constCast and @volatileCast 2023-02-15 01:43:57 +02:00
Stephen Gregoratto
d4ce0fe7fe Update Linux syscall list for 6.1, support Mips64
Follow up for #14541.
2023-02-05 03:25:21 -05:00
Suirad
7f24993772 Add support for mips64/mips64el 2023-02-04 15:19:53 -05:00
Andrew Kelley
6b7ad22981
Merge pull request #14477 from Vexu/fixes
Improve `@ptrCast` errors, fix some bugs
2023-02-01 23:31:52 -05:00
leap123
ef8f694d77
std.os.uefi: fix shift in pool allocator (again) (#14497) 2023-01-31 13:08:30 -05:00
Veikka Tuominen
f16c10a86b implement @qualCast 2023-01-30 18:55:57 +02:00
Yusuf Bham
9177e0da4f std.os.uefi: fix shift in pool allocator 2023-01-29 15:02:22 -05:00
Andrew Kelley
cb9d00e1af
Merge pull request #14402 from kcbanner/cbe_x86_fixes
CBE: x86 support and MSVC ABI fixes
2023-01-24 17:53:54 -05:00
Isaac Freund
9eeae556cc std: remove meta.assumeSentinel
All but 3 callsites of this function in the standard library and
compiler were unnecessary and were removed in faf2fd18.

In this commit, the remaining 3 callsites are removed. One of them
turned out to also be unnecessary and has been replaced by slicing
directly with the length..

The 2 remaining callsites were in the very pointer-math heavy
std/os/linux/vdso.zig code which should perhaps be refactored to better
utilize slices. These 2 callsites are replaced with a plain
@ptrCast([*:0]u8, ptr) though could likely use std.mem.sliceTo() if the
surrounding code was refactored.
2023-01-24 15:39:52 -05:00
David Gonzalez Martin
59d9afcb5c [UEFI] Delete unnecessary padding and fix number_of_pages type 2023-01-23 21:05:38 -05:00