Commit Graph

1484 Commits

Author SHA1 Message Date
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
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
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
kcbanner
1aa2c32055 cbe: fixes for x86
- Emit calling convention
- Fix .Naked handling for msvc
- Add teb helper for x86
- Fix 128-bit shl implementation when rhs is >= 64
- Add 128-bit shl tests
2023-01-23 13:48:36 -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
Jarred Sumner
a9eb463202 Make res nullable in getaddrinfo 2023-01-19 23:08:15 +02:00
star-tek-mb
116b770809 fix selectSymbol function pointers 2023-01-19 16:34:02 +02:00
fn ⌃ ⌥
2623e1c4d6 Add std.os.darwin.cssm 2023-01-17 09:51:39 -08:00
Andrew Kelley
86308ba1e1 std.net.getAddressList: call WSAStartup on Windows 2023-01-17 00:08:42 -07:00
Andrew Kelley
09560bc69a clean up windows cert scanning
* keep helper functions out of the DLL bindings APIs
 * unify the logic for linux and windows certificate scanning with
   regards to error handling
2023-01-17 00:08:42 -07:00
star-tek-mb
1f9fa82235 windows root certificate scanning 2023-01-17 00:08:42 -07:00
Veikka Tuominen
b2c85464be std.os.linux.io_uring: fix ABI error
`register_files_update` was passing a pointer to a Zig struct to the kernel.
2023-01-16 22:25:34 +02:00
antlilja
4971df8572 UEFI pool allocator changes
* Changed the interface to align with the new allocator interface.
* Fixed bug where not enough memory was allocated for the header or to
  align the pointer.
2023-01-12 03:46:15 -05:00
Andrew Kelley
9b807f9c17
Merge pull request #14247 from kcbanner/windows_improve_module_lookup
Windows debug info lookup improvements
2023-01-10 18:08:12 -05:00
kcbanner
bb4cb34204 test: fix "chdir smoke test" comparing paths with potentially different drive letter cases 2023-01-10 18:03:05 -05:00
kcbanner
58e558822a windows: unexpectedStatus/unexpectedError start the stack trace at the caller 2023-01-08 23:51:55 -05:00
kcbanner
461fb499f3 windows: rework DebugInfo to use less file operations and fix some memory management issues 2023-01-08 20:28:42 -05:00
Casey Banner
09ff03a57a
debug: replace RtlCaptureStackBackTrace (which was spuriously failing) with a new implementation which uses RtlVirtualUnwind instead (#12740)
windows: add RtlCaptureContext, RtlLookupFunctionEntry, RtlVirtualUnwind and supporting types
windows: fix alignment of CONTEXT structs to match winnt.h as required by RtlCaptureContext (fxsave instr)
windows aarch64: fix __chkstk being defined twice if libc is not linked on msvc

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2023-01-04 14:54:49 -05: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
7f012eef0b
freebsd: memfd_create: < 13.0 version check
- add conditional compile error
- add conditional skip test
2023-01-02 19:18:33 -05: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
Andrew Kelley
72560b8db5 add some comments to explain workarounds 2023-01-02 14:08:50 -07:00
kcbanner
ccf0ab0ef6 cbe: use callconv(.C) for zig.g stub functions, use zig.h function for windows teb instead of syscall 2023-01-02 13:56:11 -07:00
kcbanner
7fb3683c32 cbe: more msvc compatibility work
- Add .StaticInitializer to ValueRenderLocation to indicate that the emitted values
must be constant expressions (no function calls, struct casting).
- Add new path for special float types (nan, inf) that works in constant expressions
- Implement windows.teb() using a syscall for .stage2_c because x64 MSVC
doesn't support any kind of inline asm
2023-01-01 16:44:28 -05:00
Ganesan Rajagopal
4172c29166
Fix typo (#14149) 2023-01-01 15:57:05 +00:00
Veikka Tuominen
622311fb9a update uses of overflow arithmetic builtins 2022-12-27 15:13:14 +02:00
Andrew Kelley
d93edadead
Merge pull request #13993 from squeek502/windows-childprocess-perf
`spawnWindows`: Improve worst-case performance considerably + tests
2022-12-18 16:22:19 -05:00
Veikka Tuominen
40ed6ae846
Merge pull request #13930 from r00ster91/renamings
std.builtin: renamings
2022-12-18 19:33:15 +02:00
Ryan Liptak
0cbc59f227 standalone tests: Add windows spawn test
Tests a decent amount of edge cases dealing with how PATH and PATHEXT searching is handled.
2022-12-18 03:55:28 -08:00
Ryan Liptak
e9c48e6631 spawnWindows: Improve worst-case performance considerably
The name of the game here is to avoid CreateProcessW calls at all costs,
and only ever try calling it when we have a real candidate for execution.
Secondarily, we want to minimize the number of syscalls used when checking
for each PATHEXT-appended version of the app name.

An overview of the technique used:
- Open the search directory for iteration (either cwd or a path from PATH)
- Use NtQueryDirectoryFile with a wildcard filename of `<app name>*` to
  check if anything that could possibly match either the unappended version
  of the app name or any of the versions with a PATHEXT value appended exists.
- If the wildcard NtQueryDirectoryFile call found nothing, we can exit early
  without needing to use PATHEXT at all.

This allows us to use a <open dir, NtQueryDirectoryFile, close dir> sequence
for any directory that doesn't contain any possible matches, instead of having
to use a separate look up for each individual filename combination (unappended +
each PATHEXT appended). For directories where the wildcard *does* match something,
we only need to do a maximum of <number of supported PATHEXT extensions> more
NtQueryDirectoryFile calls.

---

In addition, we now only evaluate the extensions in PATHEXT that we know we can handle (.COM, .EXE, .BAT, .CMD) and ignore the rest.

---

This commit also makes two edge cases match Windows behavior:

- If an app name has the extension .exe and it is attempted to be executed, that is now treated as unrecoverable and InvalidExe is immediately returned no matter where the .exe is (cwd or in the PATH). This matches the behavior of the Windows cmd.exe.
- If the app name contains more than just a filename (e.g. it has path separators), then it is excluded from PATH searching and only does a cwd search. This matches the behavior of Windows cmd.exe.
2022-12-18 02:48:34 -08:00
Ryan Liptak
3ee8c49582 windows: Map EXE_MACHINE_TYPE_MISMATCH to InvalidExe
Seems to happen if the command trying to be executed has the extension .exe and it's an invalid executable.
2022-12-18 02:31:34 -08:00
Ryan Liptak
6e22b63edb windows: Extract RtlEqualUnicodeString usage into to a helper function 2022-12-17 22:06:47 -08:00
r00ster91
aac2d6b56f std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
Ryan Liptak
5843b7987e Add error.InvalidExe to CreateProcessW error set and handle it in ChildProcess.spawnWindows 2022-12-17 03:36:45 -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
Andrew Kelley
6378644d4e
Merge pull request #13907 from Vexu/call-merge
Remove `stack` option from `@call`
2022-12-13 18:15:18 -05:00
Jakub Konka
ec2697b7ea darwin: add even more wrappers for Mach syscalls
Rename `ThreadId` to `MachThread`.
2022-12-14 00:10:26 +01:00
Jakub Konka
f5336a8fec darwin: add ability to dealloc obtained thread list for a task 2022-12-13 15:29:49 +01:00
Jakub Konka
f505cb96f4 darwin: add thread_act_t wrapper and helpers 2022-12-13 12:53:10 +01:00
Veikka Tuominen
08b2d491bc update usages of @call 2022-12-13 13:14:20 +02:00
Jakub Konka
2efd0eb884 darwin: wrap task_threads mach syscall 2022-12-13 11:36:00 +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
Jakub Konka
6f5eb9927d darwin: add more defs and wrappers 2022-12-12 20:04:46 +01:00
Jan Philipp Hafer
8a27df5355 std.os.linux: fix timerfd test
Remove timerfd timeout and fix timerfd_settime flag.
CI tests should not rely on timings to succeed.

Closes #13721.
2022-12-12 10:58:54 +02:00
Jakub Konka
612b9f4da1 darwin: add defs and funcs for Mach exception handling 2022-12-12 00:13:37 +01:00
Andrew Kelley
dd4ca88ca7 std: fix compile error bitrot
These were revealed in an earlier commit in this branch that removed a
workaround disabling Windows std lib files from being tested.
2022-12-11 12:48:17 -07:00
Jakub Konka
402dfb5fd3 darwin: wrap mach_port_insert_right kernel call 2022-12-11 18:27:10 +01:00
Jakub Konka
2a65971eb0 darwin: wrap allocating and deallocating mach ports for a task 2022-12-11 14:40:27 +01: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
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
c84bc3a06b std.os.test: disable flaky timerfd test
See tracking issue #13721
2022-11-30 15:18:35 -07:00
Andrew Kelley
44ee1c885f std.os.windows.ReadLink: add missing alignment of local data buffer 2022-11-30 12:55:23 -07:00
Jakub Konka
d3b1cdf508
Merge pull request #13659 from ziglang/arm-win-cpu-features
windows: add native CPU and features detection for Armv8 chips
2022-11-28 21:36:56 +01:00
Ryan Liptak
4e078941d0 os.windows.OpenFile: Add USER_MAPPED_FILE as a possible error
Ran into this when using a program that uses CreateFileMapping and then trying to call `std.fs.createFile` on the mapped file. More info can be found here:

https://stackoverflow.com/questions/41844842/when-error-1224-error-user-mapped-file-occurs

Before:

```
error.Unexpected NTSTATUS=0xc0000243
C:\Users\Ryan\Programming\Zig\zig\lib\std\os\windows.zig:138:40: 0x7ff74e957466 in OpenFile (test.exe.obj)
        else => return unexpectedStatus(rc),
                                       ^
```

After:

```
FAIL (AccessDenied)
C:\Users\Ryan\Programming\Zig\zig\lib\std\os\windows.zig:137:30: 0x7ff7f5b776ea in OpenFile (test.exe.obj)
        .USER_MAPPED_FILE => return error.AccessDenied,
                             ^
```
2022-11-28 18:56:11 +01:00
Jakub Konka
2528189101 windows: fix signature of kernel32.RegOpenKeyExW to use *HKEY 2022-11-28 17:09:03 +01:00
Jakub Konka
d64d7aaac7 windows: drive the registry helper with actual value set for reg entries 2022-11-28 17:07:34 +01:00
Jakub Konka
57bda6524b windows: make registry helper generic over value types 2022-11-28 17:07:34 +01:00
Jakub Konka
f348fbc024 windows: revert changes to definition of HKEY 2022-11-28 17:07:34 +01:00
Jakub Konka
7ea2c7fbcd windows: use RtlQueryRegistryValues to query reg in a single syscall 2022-11-28 17:07:34 +01:00
Jakub Konka
153afed877 windows: impl some primitives for getting registry keys 2022-11-28 17:07:34 +01:00
Jakub Konka
e74b6f0a4b windows: detect couple more aarch64 CPU features 2022-11-28 17:07:34 +01:00
Jakub Konka
6edf9127fe windows: add missing enum values for ProcessorFeatures enumeration 2022-11-28 17:07:34 +01:00
Jakub Konka
625415d738 windows: add zig impl of IsProcessorFeaturePresent syscall 2022-11-28 17:07:34 +01:00
Jakub Konka
1eac3c57ec windows: add processor feature enumeration 2022-11-28 17:07:33 +01:00
bfredl
0196010b0c linux.bpf: expose map_get_next_key
Returning a bool allows to conveniently use it as the condition
of a while loop.

Also remove restriction that ST cannot be double-word.
While imm is only 32-bit, this value is extended into a 64-bit
memory location.
2022-11-27 02:07:49 -05:00
Cody Tapscott
a0af3c7a19 std.os: Fix std.os.chdir for WASI
Test coverage was lacking for chdir() on WASI, allowing this to
regress.

This change makes os.chdir() compile again, and improves the test
logic to use our standard CWD support for WASI.
2022-11-26 22:06:15 +02:00
Ali Chraghi
fca776f8f5 os: windows: fix unhandled error 2022-11-19 22:48:32 +02:00
Stevie Hryciw
04f3067a79 run zig fmt on everything checked by CI 2022-11-18 19:22:42 +00:00
Björn Linse
a09a5ad574 stdlib: make linux.PERF.TYPE non-exhaustive
perf_event_attr.type needs to take a runtime defined value to enable
dynamic PMU:s, such as kprobe and uprobe. This value can exceed
predefined values defined in the linux headers.

reference: perf_event_open(2) man page
2022-11-16 19:02:24 -05:00
Hayden Pope
ceb9fedb47 std.os.linux: Add setitimer and getitimer syscalls 2022-11-15 02:38:28 -05:00
Nick Cernis
8a5818535b
Make invalidFmtError public and use in place of compileErrors for bad format strings (#13526)
* Export invalidFmtErr

To allow consistent use of "invalid format string" compile error
response for badly formatted format strings.

See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340.

* Replace format compile errors with invalidFmtErr

- Provides more consistent compile errors.
- Gives user info about the type of the badly formated value.

* Rename invalidFmtErr as invalidFmtError

For consistency. Zig seems to use “Error” more often than “Err”.

* std: add invalid format string checks to remaining custom formatters

* pass reference-trace to comp when building build file; fix checkobjectstep
2022-11-12 21:03:24 +02:00
Veikka Tuominen
41b7e40d75
Merge pull request #13418 from ryanschneider/signal-alignment-13216
std.os: fix alignment of Sigaction.handler_fn
2022-11-09 17:36:40 +02:00
bfredl
95f989a05b Fixes to linux/bpf/btf.zig
- the meaning of packed structs changed in zig 0.10. adjust accordingly.
  Use "extern struct" for the cases that directly map to C structs.

- Add new type info kinds, like enum64 and DeclTag

- change the Type enum to use the canonical names from libbpf.
  This is more predictable when comparing with external BPF
  documentation (than invented synonyms that need to be guessed)
2022-11-09 17:14:22 +02:00
r00ster91
b83e4d9656 std.os.linux.T: translate more MIPS values
This fixes the broken terminal for me and thus fixes #13198.
2022-11-06 16:33:50 +02:00
Ryan Schneider
a68b27c252 std.os: improve sigaction test coverage. 2022-11-04 08:07:44 -07:00
Ryan Schneider
7f1f2e653d std.os: fix alignment of Sigaction.handler_fn
Fixes #13216
2022-11-04 08:00:50 -07:00
Ryan Schneider
64b3ffd8ff std.os: Add IGN coverage to sigaction tests
* Should start failing on aarch64 and other word-aligned CPUs.
2022-11-04 08:00:50 -07:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
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
Andrew Kelley
209a0d2a83
Merge pull request #13153 from squeek502/iterator-filename-limits
Windows: Fix Iterator name buffer size not handling all possible file name components
2022-10-29 23:50:37 -04:00
Ryan Liptak
db80225a97 fs: Some NAME_MAX/MAX_NAME_BYTES improvements 2022-10-29 14:30:46 -07:00
Ryan Liptak
33fdc43714 std.fs: Add MAX_NAME_BYTES
Also add some NAME_MAX or equivalent definitions where necessary
2022-10-29 14:30:43 -07:00
Jacob Young
48a2783969 cbe: implement optional slice representation change 2022-10-29 05:58:41 -04:00
daurnimator
f2401a0756 Add sockaddr_vm for vSocckets on Linux 2022-10-27 20:51:35 -04:00
daurnimator
c0c8ee5ae9 Add reboot syscall
Only linux for now
2022-10-27 20:39:35 -04:00
Jacob Young
15df64ade8 std: add cbe hacks to more targets
These are needed because clang doesn't support anything in naked
functions, not even assembly register inputs.
2022-10-25 05:11:29 -04:00
Jacob Young
4765294ca4 cbe: get enough things working to support basic programs
* Enable advanced start support.
 * Enable advanced test_runner support.
 * Zig Language Reference's Hello World now works.
2022-10-25 05:11:29 -04:00
David Gonzalez Martin
680d3cd1fc UEFI: Querying memory map size with no allocation
This makes possible to query the memory map size from EFI firmware
without making any allocation beforehand. This makes possible to be
precise about the size of the allocation which will own a copy of
the memory map from the UEFI application.
2022-10-21 12:17:41 +02:00
Andrew Kelley
9ee4530b9b std.os.windows.OpenFile: handle INVALID_HANDLE ntstatus 2022-10-18 16:52:43 -07:00
Yujiri
8aa21ade8c add tcdrain on linux 2022-10-17 18:01:05 -04:00
bfredl
c750d95417 os.linux: some fixes to BPF module
- For ALU operations, src should be allowed to be an explicit Reg.
- Expose AluOp and JmpOp as public types.
  This makes code generation using BPF as a backend easier,
  as AluOp and JmpOp can be used directly as part of an IR
2022-10-16 11:36:11 -04:00
Ryan Liptak
8bb2e96ac3 std.os.windows: Change HKEY to *opaque {}
The definition of HKEY__ as a struct with an unused int field is only the case in the Windows headers when `STRICT` is defined. From https://learn.microsoft.com/en-us/windows/win32/winprog/enabling-strict:

> When STRICT is defined, data type definitions change as follows:
>
> -  Specific handle types are defined to be mutually exclusive; for example, you will not be able to pass an HWND where an HDC type argument is required. Without STRICT, all handles are defined as HANDLE, so the compiler does not prevent you from using one type of handle where another type is expected.

Zig's `opaque {}` already gives this benefit to us, so the usage of a struct with an unused field is unnecessary, and it was causing HKEY to have an alignment of 4, which is a problem because there are HKEY constants like HKEY_LOCAL_MACHINE (0x80000002) that are not 4-byte aligned. Without this change, the compiler would not allow something like HKEY_LOCAL_MACHINE to be defined since it enforces pointer alignment.
2022-10-14 15:23:13 -04:00
Jacob Young
f5f28e0d2c io_uring: ignore SOCK_NONEMPTY for reproducible tests
Fixes #12670
2022-10-13 14:58:06 +02:00
Ali Chraghi
fb366f3cd4 std.c: fix incorrect return types
Closes #12964
2022-10-13 13:21:19 +02:00
Andrew Kelley
d08191e146
Merge pull request #12897 from r00ster91/uefi
std.os.uefi: fix some mistakes
2022-10-12 05:28:13 -04:00
mllken
42a3b60c33 io_uring: allow for nullable arguments 2022-10-11 17:49:30 +02:00
Eric Milliken
0b7b4b7e97
std: add linux support for packet sockaddr 2022-10-11 18:46:24 +03:00
r00ster91
47e72132e2 fix: wrong amount of arguments passed to function
I don't know why that one argument was discarded. Is there a reason? It failed to compile.
2022-10-07 19:33:29 +02:00
r00ster91
a56a51e48f fix: wrong return type for _poll
See page 1055 of <https://uefi.org/sites/default/files/resources/UEFI_Spec_2_3_1.pdf>.
2022-10-07 19:33:29 +02:00
r00ster91
4440391d81 fix: wrap function pointers in std.meta.FnPtr 2022-10-07 19:33:29 +02:00
Luuk de Gram
8bbb022500 std: WASI - update to latest snapshot preview 1
This implements the new addition to the API: `sock_accept`.
Reference commit of WASI spec:
0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52

For full details:
0ba0c5e2e3

For entire spec at this commit:
0ba0c5e2e3/phases/snapshot/docs.md
2022-10-03 22:48:57 -04:00
zooster
db5562deb0 std.os.windows: fix HANDLER_ROUTINE callconv 2022-10-03 13:05:38 +03:00
ominitay
295451dfe5
std: Replace use of stage1 function pointers 2022-09-29 21:45:30 +03:00
Andrew Kelley
62ecc154d9
Merge pull request #12904 from Vexu/ptrcast
stage2: pointer casting fixes and improvements
2022-09-20 22:02:36 -04:00
Meghan
521c753fda std: fix os.linux.S function signatures to use mode_t 2022-09-20 17:54:32 -04:00
Veikka Tuominen
541b3e3a31 Sema: check pointer qualifiers before implicit cast
Closes #12881
2022-09-20 00:50:13 +03:00
Yusuf Bham
c9f145a50b std.os.uefi: mark BlockIoProtocol and EfiBlockMedia as public 2022-09-09 16:48:54 +03:00
Jakub Konka
3a4c69c018 x86_64: implement Windows x64 calling convention 2022-09-07 22:42:56 +02:00
Veikka Tuominen
62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
Andrew Kelley
4a27d2aac6 std.os.linux.bpf: fix compile error 2022-08-19 16:45:16 -07:00
Andrew Kelley
445b33cfc0 fix std.os.windows.PathSpace.span
it was returning a pointer to a parameter.
2022-08-19 16:45:16 -07: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
Meghan Denny
0879cbeed2 remove 'builtin.stage2_arch', Sema is smart enough now 2022-08-07 16:07:08 -07:00
Stephen Gregoratto
b3950d4a88 Update Linux syscall list for 5.19
New changes: memfd_secret implemented for RISC-V.
2022-08-05 15:36:32 +03: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
Vincent Rischmann
d99c32c2e1
io_uring: add new flags and opcodes 2022-07-23 17:21:17 +03:00
Andrew Kelley
f550c29c4e LLVM: fix lowering of structs with underaligned fields
When lowering a struct type to an LLVM struct type, keep track of
whether there are any underaligned fields. If so, then make it a packed
llvm struct. This works because we already insert manual padding bytes
regardless.

We could unconditionally use an LLVM packed struct; the reason we bother
checking for underaligned fields is that it is a conservative choice, in
case LLVM handles packed structs less optimally. A future improvement
could simplify this code by unconditionally using packed LLVM structs
and then make sure measure perf is unaffected.

closes #12190
2022-07-21 22:51:17 -07:00
Vincent Rischmann
47c58cba59
Fix io_uring tests (#12134)
* io_uring: fix the timeout_remove test

The test does a IORING_OP_TIMEOUT followed with a IORING_OP_TIMEOUT_REMOVE
and assumed we would get the CQEs in the same order.

Linux v5.18 changed how this works and we now get them in the reverse order.

The documentation doesn't explicitly say which CQE we should get first
so just make the test work with both cases.

* io_uring: fix the remove_buffers test

The original test was buggy but accidentally worked with kernels < 5.18

The test assumed that IORING_OP_REMOVE_BUFFERS removed from the start of
but in fact the documentation doesn't specify which buffer is removed,
only that a certain number of buffers are removed.

Starting with the kernel 5.18 the check for the `used_buffer_id` fails.
Turns out that previous kernels removed buffers in such a way that the
remaining buffer for this read would always be 0, however this isn't
true anymore.

Instead of checking a specific value just check that the `used_buffer_id`
corresponds to a valid ID.
2022-07-16 10:05:11 -05:00
Andrew Kelley
c34392b24e std.os.linux.io_uring: work around LLVM bug
See #12014
2022-07-05 21:54:05 -07:00
Jonathan Marler
93ac87c1bd Mark fstype argument to mount as optional
The fstype argument to the mount system call can be null.  To see an
example run "strace -e trace=mount unshare -m":

```
mount("none", "/", NULL, MS_REC|MS_PRIVATE, NULL) = 0
...
```
2022-07-05 15:04:31 -04:00
Andrew Kelley
314ce5465d std: better definition for std.os.linux.epoll_event
The previous definition depends on a non-lang-spec-compliant memory
layout for packed structs, which happens to trigger #11989 in stage2.

This commit changes the struct to be an extern struct with an
align(4) field. However, stage1 cannot handle this, so conditional
compilation logic is used to select different struct definitions
depending on stage1 vs stage2.

This works around #11989 but does not solve the underlying problem -
putting an extern union inside a packed struct will still trigger the
assert.

After this, both stage1 and stage2 std lib tests run assertion-clean
with a debug LLVM 13.
2022-07-03 22:18:05 -07:00
Philipp Lühmann
bb2929ba08
zig fmt: fix idempotency with newlines surrounding doc comment
Fixes: https://github.com/ziglang/zig/issues/11802
2022-06-28 21:38:28 +02:00
Andrew Kelley
0b8bd9b2b4 std.os.linux.clone: upgrade to stage2 fn ptr semantics 2022-06-27 18:27:06 -07:00
Jonathan Marler
523fae420b add const to msghdr_const iov and control pointers
alongside the typical msghdr struct, Zig has added a msghdr_const
type that can be used with sendmsg which allows const data to
be provided.  I believe that data pointed to by the iov and control
fields in msghdr are also left unmodified, in which case they can
be marked const as well.
2022-06-07 15:23:44 -04:00
Veikka Tuominen
32568dba74 std: handle stage2 function pointer semantics in test 2022-06-06 13:11:50 -07:00
Veikka Tuominen
15ec55406d std: fix ambiguous references 2022-06-06 13:11:50 -07:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
Jonathan Marler
ee1a95b555 fix semantic error with std.os.linux.all_mask
all_mask is a value of type sigset_t, which is defined as an array type
[N]u32.  However, all_mask references sigset_t.len, but, the array type
does not have a len field.  Fix is to use @typeInfo(sigset_t).Array.len
instead.
2022-05-26 19:50:10 -04:00
Vincent Rischmann
3c58d3e281 io_uring: replace the readv method with a read on a new ReadBuffer type
readv() is essentially identical to read() except for the buffer type,
this simplifies the API for the caller at the cost of not clearly mapping to the liburing C API.
2022-05-25 13:53:09 +02:00
Vincent Rischmann
acb8af468f io_uring: add tests for automatic buffer selection 2022-05-25 13:53:09 +02:00
Vincent Rischmann
d8798ef0cd io_uring: use the socket test harness 2022-05-25 13:53:09 +02:00
Vincent Rischmann
456716b30d io_uring: add a test harness for server/client TCP socket tests 2022-05-25 13:53:09 +02:00
Vincent Rischmann
270a5039d4 io_uring: change recv() to use a RecvBuffer instead
RecvBuffer is equivalent to ReadBuffer but tailored for recv only.
2022-05-25 13:53:09 +02:00
Vincent Rischmann
52dd468cc3 io_uring: change read() to use a ReadBuffer instead
Reads can be done in two ways with io_uring:
* using a simple buffer
* using a automatic buffer selection which requires the user to have
provided a number of buffers before

ReadBuffer let's the caller choose where the data should be read.
2022-05-25 13:53:09 +02:00
Vincent Rischmann
7b3e5ce0b3 io_uring: add provide_buffers and remove_buffers
These functions are needed to implement automatic buffer selection.

This maps to the IORING_OP_PROVIDE_BUFFERS and IORING_OP_PROVIDE_BUFFERS ops.
2022-05-25 13:53:09 +02:00
Stephen Gregoratto
a4369918b1 Generate linux syscalls via. the linux source tree
Previously, updating the `SYS` enum for each architecture required
manually looking at the syscall tables and inserting any new additions.

This commit adds a tool, `generate_linux_syscalls.zig`, that automates
this process using the syscall tables in the Linux source tree. On
architectures without a table, it runs `zig cc` as a pre-processor to
extract the system-call numbers from the Linux headers.
2022-05-16 23:55:11 -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
Koakuma
fb0692334e target: Rename sparcv9 -> sparc64
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.

This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-13 16:43:59 -04:00
Jonathan Marler
aceb7e18bd std.os.linux: fix signature of setgroups
the list parameter should be a multi-item pointer rather than a single-item
pointer. see: https://linux.die.net/man/2/setgroups

> setgroups() sets the supplementary group IDs for the calling process...
> the size argument specifies the number of supplementary group IDs in the buffer pointed to by list.
2022-05-13 17:46:56 +02:00
Jonathan Marler
aef642fc07 remove RtlUpcaseUnicodeString, no longer needed 2022-05-11 18:43:41 -06:00
Jonathan Marler
2ddfe16e1e fix ntdll extern casing
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-05-11 18:41:54 -06:00
Jonathan Marler
e65d8f82c5 add unicode support 2022-05-11 18:41:23 -06:00
Ryan Liptak
15d5988e69 Add process.EnvMap, a platform-independent environment variable map
EnvMap provides the same API as the previously used BufMap (besides `putMove` and `getPtr`), so usage sites of `getEnvMap` can usually remain unchanged.

For non-Windows, EnvMap is a wrapper around BufMap. On Windows, it uses a new EnvMapWindows to handle some Windows-specific behavior:

- Lookups use Unicode-aware case insensitivity (but `get` cannot return an error because EnvMapWindows has an internal buffer to use for lookup conversions)
- Canonical names are returned when iterating the EnvMap

Fixes #10561, closes #4603
2022-05-11 18:40:53 -06: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
Brian Gold
52651ae7a0 io_uring cancel test must tolerate CQ reordering
Fixes #11382. Tested on ArchLinux 5.17.5-arch1-1.
2022-05-10 11:49:41 +02:00
Andrew Kelley
413b789e06 std.os.linux.arm-eabi: upgrade to new fn ptr semantics 2022-05-05 22:29:25 -07:00
Andrew Kelley
76b7f56725 std.os.windows: upgrade to new function pointer semantics 2022-05-02 22:14:17 -07:00
r00ster91
bb55276f06 Avoid some unnecessary underscores in constant names 2022-05-02 15:29:04 -04:00
Stephen Gregoratto
2409041e62 Seccomp fixups re: #10717
- Add type annotation for AUDIT.current.
- Make unsupported archs a compile error.
2022-04-28 23:41:25 -04:00
Veikka Tuominen
6d48600ea0
Merge pull request #10717 from gh-fork-dump/seccomp-bits
Add Seccomp bits for linux
2022-04-28 18:54:09 +03:00
protty
963ac60918
std.Thread: Mutex and Condition improvements (#11497)
* Thread: minor cleanups

* Thread: rewrite Mutex

* Thread: introduce Futex.Deadline

* Thread: Condition rewrite + cleanup

* Mutex: optimize lock fast path

* Condition: more docs

* Thread: more mutex + condition docs

* Thread: remove broken Condition test

* Thread: zig fmt

* address review comments + fix Thread.DummyMutex in GPA

* Atomic: disable bitRmw x86 inline asm for stage2

* GPA: typo mutex_init

* Thread: remove noalias on stuff

* Thread: comment typos + clarifications
2022-04-23 19:35:56 -05:00
Morritz
daef82d06f
add GetProcessTimes binding to the kernel32.zig (#11488) 2022-04-23 16:58:27 -05:00
Yusuf Bham
2fa7f6e502 std.os.uefi: Add BlockIoProtocol 2022-04-19 19:51:19 -04:00
Yusuf Bham
2aeaa1cfc4
std.os.uefi: fix GUID formatting (#11452) 2022-04-17 06:15:15 -04: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
Veikka Tuominen
6ad510d832 update self hosted sources to language changes 2022-04-15 11:17:19 +03: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
Andrew Kelley
57539a26b4 std.os: disable failing fnctl file locking test
See #11074
2022-03-23 17:29:39 -07:00
Locria Cyber
eb5e0cba21 Fix ucontext_t 2022-03-22 23:19:02 -04:00
Veikka Tuominen
0577069af5 stage2 llvm: fix lowerDeclRefValue for function aliases 2022-03-21 15:12:32 -04:00
Andrew Kelley
69e6d455ce
Merge pull request #11228 from Vexu/panic
enable default panic handler for stage2 LLVM
2022-03-19 14:32:09 -04:00
zseri
c6cf40a0c0 fix sigaction double panic
Fixes #8357
2022-03-19 19:13:31 +02:00
Veikka Tuominen
c9b6f1bf90 std: enable default panic handler for stage2 LLVM on Linux 2022-03-19 14:05:57 +02:00
Jakub Konka
648afbc839 macos: update Mach routines for accessing page info 2022-03-17 10:42:11 +01: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
Andrew Kelley
86a98b172b std.os: disable failing fnctl file locking test
See #11074
2022-03-11 12:49:53 -07:00
Stephen Gregoratto
ee32d11252 Add bits for the Linux Secure Computing facility 2022-03-09 18:49:36 +11:00
Andrew Kelley
76d810c568 std: disable flaky os.fcntl test
See tracking issue #11074
2022-03-06 20:49: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
Hiroaki Nakamura
3605dd307f
os/linux/io_uring: add recvmsg and sendmsg (#10212)
* os/linux/io_uring: add recvmsg and sendmsg

* Use std.os.iovec and std.os.iovec_const

* Remove msg_ prefix in msghdr and msghdr_const in arm64 etc

* Strip msg_ prefix in msghdr and msghdr_const for linux arm-eabi

* Copy msghdr and msghdr_const from i386 to mips

* Add sockaddr to lib/std/os/linux/mips.zig

* Copy msghdr and msghdr_const from x86_64 to riscv64
2022-03-03 14:13:54 -06:00
Veikka Tuominen
1bbca4f935 stage2: fix bitcast to optional ptr in llvm backend; omit safety check for intToPtr on optional ptr 2022-02-27 12:15:49 +02:00
Veikka Tuominen
950d840be6 stage2: use stage1 test runner for stage2 2022-02-27 11:57:12 +02:00
Isaac Freund
52a2aa11e2 std: work around current packed struct situation
As of 6249a24, align() is not allowed on packed struct fields
and as such the align(4) was removed from the first field of
EdidOverrideProtocolAttributes. The endgame here is packed struct
backed by explicit integers, in this case a u32, but until that
is implemented put the align(4) on the pointer to avoid breaking
someone's UEFI code in a hard to debug way.
2022-02-24 16:08:37 -05:00
Andrew Kelley
6249a24e81 stage2: integer-backed packed structs
This implements #10113 for the self-hosted compiler only. It removes the
ability to override alignment of packed struct fields, and removes the
ability to put pointers and arrays inside packed structs.

After this commit, nearly all the behavior tests pass for the stage2 llvm
backend that involve packed structs.

I didn't implement the compile errors or compile error tests yet. I'm
waiting until we have stage2 building itself and then I want to rework
the compile error test harness with inspiration from Vexu's arocc test
harness. At that point it should be a much nicer dev experience to work
on compile errors.
2022-02-23 23:59:25 -07:00
Felix Queißner
6fdcf1ad2d
std.os.linux.socketpair: fd is an out parameter 2022-02-23 09:32:54 +02: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
Andrew Kelley
2c24bf2f79
Merge pull request #10604 from fifty-six/master
std/os/uefi: additional improvements/fixes
2022-02-18 14:16:30 -05:00
Veikka Tuominen
cf5009f9af
Merge pull request #10003 from viriuwu/nt-thread-name
std.Thread.getName/setName: rework windows implementation
2022-02-15 13:23:09 +02: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
viri
0bde55e881
std.Thread(windows): use NT internals for name fns 2022-02-15 01:20:54 -06:00
Veikka Tuominen
90f2a8d9c5
Merge pull request #10486 from ominitay/metadata
std: Implement cross-platform metadata API
2022-02-14 12:33:49 +02:00
Andrew Kelley
5f50980880
Merge pull request #10863 from m-radomski/fix
std: validate frame-pointer address in stack walking
2022-02-13 16:17:40 -05:00
ominitay
d978fdaa67
std.c.Wasi.Stat: use timespec 2022-02-13 20:40:44 +00:00
Tw
2a73700c0f Fix preadv/pwritev bug on 64bit platform
Signed-off-by: Tw <wei.tan@intel.com>
2022-02-13 18:01:07 +00:00
m
65299c37d1 validate in Windows using VirtualQuery 2022-02-11 22:15:46 +01:00
m
bd8d6a8342 std: validate frame-pointer address in stack walking 2022-02-11 15:28:36 +01:00
Jonathan Marler
ba445013c4
improve comptime windows GUID.parse performance
I found that after switching from my custom Guid parser to the one in std that it increased zigwin32 build times substantially (from 40 seconds to over 10 minutes).  More information can be found in the benchmark PR I created here: https://github.com/ziglang/gotta-go-fast/pull/21 .  This PR ports my GUID parser to std so all projects can leverage the faster comptime performance.
2022-01-29 18:10:22 +02:00
Stephen Gregoratto
a49f2d9f8d Add bits for the Linux Auditing System
Also adds the _CSKY and _FRV ELF machines that are defined in
`<linux/elf-em.h>`
2022-01-29 13:57:14 +11:00
Vesim
8c90b05add fchown: use the 32-bit uid/gid variant of the syscall on 32-bit linux targets 2022-01-27 20:27:16 +02:00
Jonathan Marler
2fc2d88fc6 use explicit integer bit widths for windows GUID
The size of a GUID is not platform-dependent, it's always a fixed number of bits.  So I've updated guid to use fixed bit integer types rather than platform-dependent C integer types.
2022-01-24 17:35:15 +02:00
fifty-six
ff6ece3811 std/os/uefi: Don't treat efi status warnings as errors 2022-01-16 03:50:50 -05:00
fifty-six
03347114c3 std/os/uefi: Add util function for opening protocols 2022-01-16 03:04:37 -05:00
fifty-six
c727bd1bb6 std/os/uefi: Fix parameter type mismatch in edid_override_protocol 2022-01-16 02:52:45 -05:00
fifty-six
628a7f85de std/os/uefi: Add conversion from Status to EfiError
Allows handling uefi function errors in a more zig-style way with try
and catch, using `try f().err()` when a `Status` is returned.
2022-01-16 02:35:22 -05:00
fifty-six
d276a1189d std/os/uefi: Align first field of EdidOverrideProtocolAttributes to 4
This makes the struct align(4), which allows it to be passed as flags
more easily.
2022-01-16 02:05:27 -05:00
fifty-six
4771ac298b std/os/uefi: Simplify packed struct padding and default zero-initialize
Beyond adding default zero-initialization, this commit changes undefined
initialization to zero, as some cases reserved the padding and on other
cases, I've found some systems act strange when giving uninit instead of
zero even when it shouldn't be an issue, one example being
FileProtocol.Open's attributes, which *should* be ignored when not
creating a file, but ended up giving an unrelated error.
2022-01-16 02:04:39 -05:00
viri
12d6bcec02
std.os.windows: add ntdll thread information APIs 2022-01-15 17:46:33 -06:00
viri
3c2eddae5a
std.os.windows: fix casing for ntdll.lib
I've seen having this be wrong break some cross-compilers, and it's
also how it is in other files so it's best to be consistent.

It's also just the actual casing of the file.
2022-01-15 17:27:17 -06:00
fifty-six
dab4c63684 std/os/uefi: Refactor getDevicePath()
Uses comptime loops over the types instead of writing out a large
switch.
2022-01-14 08:58:30 -05:00
fifty-six
a2a2601da5 std/os/uefi: Complete DevicePathProtocol types 2022-01-14 07:02:55 -05:00
fifty-six
ae084c5f59 std/os/uefi: Complete AcpiDevicePath and HardwareDevicePaths 2022-01-13 15:47:14 -05:00
fifty-six
322757c4e1 std/os/uefi: Add parameter names to boot_services 2022-01-13 15:47:14 -05:00
fifty-six
88687645b2 std/os/uefi: Fill out remaining runtime services and add parameter names 2022-01-13 15:47:14 -05:00
fifty-six
fe28cb8261 std/os/uefi: Fill out remaining function signatures and docs on boot_services 2022-01-13 15:47:14 -05:00
fifty-six
ea2df2601e std/os/uefi: Use usingnamespace to re-export symbols
`uefi/protocols.zig` and `uefi/tables.zig` just re-exported all the
public symbols, which is basically the purpose of `usingnamespace`
import-wise.
2022-01-13 15:47:13 -05:00
Andrew Kelley
3d89ff5130 std.fs.path: revert recent public API change
41fd343508 made a breaking change to the
public API; this commit reverts the API changes but keeps the
improved logic.
2022-01-11 11:00:19 -07:00
fifty-six
b65a884169 std/os/uefi: Add pool_allocator and raw_pool_allocator 2022-01-11 10:49:40 -07:00
fifty-six
c78a108d10 std/os/uefi: Add create_file_device_path
This allows users to add file paths to device paths, which is often used
in methods like `boot_services.loadImage` and `boot_services.startImage`,
which take a device path with an additional file path appended to locate
the image.
2022-01-11 10:49:40 -07:00
fifty-six
73e4571b4c std/os/uefi: Add methods next() and size() to DevicePathProtocol
These are used for more easily dealing with a series of Device Path
nodes.
2022-01-11 10:49:40 -07:00
fifty-six
608fceffc4 std/os/uefi: Add FileSystemInfo 2022-01-11 10:49:40 -07:00
fifty-six
b6e1613e58 std/os/uefi: Move FileInfo guid from FileProtocol to FileInfo
The GUID on FileProtocol was for EFI_FILE_INFO, FileProtocol itself doesn't
have a GUID, there are only those for the requested information types.
2022-01-11 10:49:40 -07:00
Ryan Liptak
3c87d4e14e Add CANNOT_DELETE as a possible error in os.windows.DeleteFile
Can happen when e.g. trying to delete a file with the Read Only flag set
2022-01-04 02:15:29 -05:00
Vincent Rischmann
6630a5ede5 io_uring: improve IO_Uring.copy_cqe
copy_cqes() is not guaranteed to return as many CQEs as provided in the
`wait_nr` argument, meaning the assert in `copy_cqe` can trigger.

Instead, loop until we do get at least one CQE returned.

This mimics the behaviour of liburing's _io_uring_get_cqe.
2022-01-04 02:13:41 -05:00
Andrew Kelley
d3f87f8ac0 std.fs.rename: fix Windows implementation
The semantics of this function are that it moves both files and
directories. Previously we had this `is_dir` boolean field of
`std.os.windows.OpenFile` which required the API user to choose: are we
opening a file or directory? And the other kind would either cause
error.IsDir or error.NotDir. But that is not a limitation of the Windows
file system API; it was self-imposed.

On Windows, rename is implemented internally with `NtCreateFile` so we
need to allow it to open either files or directories. This is now done
by `std.os.windows.OpenFile` accepting enum{file_only,dir_only,any}
instead of a boolean.
2022-01-02 16:58:05 -08:00
Vincent Rischmann
0662f1d522 io_uring: fix version check in tests
For renameat, unlinkat, mkdirat, symlinkat and linkat the error code
differs between kernel 5.4 which returns EBADF and kernel 5.10 which returns EINVAL.

Fixes #10466
2022-01-01 15:37:50 -05:00
Isaac Freund
9f9f215305
stage1, stage2: rename c_void to anyopaque (#10316)
zig fmt now replaces c_void with anyopaque to make updating
code easy.
2021-12-19 00:24:45 -05:00
Jens Goldberg
5b29b4ffa6 Fix MIPS inline assembly clobbers 2021-12-18 14:42:01 -08:00
Vincent Rischmann
f9b8808d74 os/linux/io_uring: implement linkat 2021-12-12 18:49:17 +01:00
Vincent Rischmann
5dd53c1986 os/linux/io_uring: implement symlinkat 2021-12-12 18:43:31 +01:00
Vincent Rischmann
1fd0542bee os/linux/io_uring: implement mkdirat 2021-12-12 18:33:17 +01:00
Vincent Rischmann
4e647dee9f os/linux/io_uring: implement unlinkat 2021-12-12 18:32:08 +01:00
Vincent Rischmann
088c1fab4d os/linux/io_uring: implement renameat 2021-12-12 18:12:15 +01:00
Vincent Rischmann
0229fb7c62 os/linux/io_uring: implement shutdown 2021-12-12 18:04:15 +01:00
Vincent Rischmann
331b8e892a os/linux: add more io_uring opcode 2021-12-12 16:55:51 +01:00
Zapolsky Anton
2dae860de3
Added an explicit type for the termios constants (#10266)
Adds the `tcflag_t` type to the termios constants.
This is made to allow bitwise operations on the termios
constants without an integer cast, e.g.:

```zig
var raw = try std.os.tcgetattr(std.os.STDIN_FILENO);
raw.lflag &= std.os.linux.ECHO | std.os.linux.ICANON;
```
instead of

```zig
var raw = try std.os.tcgetattr(std.os.STDIN_FILENO);
raw.lflag &= ~@intCast(u32, std.os.linux.ECHO | std.os.linux.ICANON);
```

Contributes to #10181
2021-12-04 16:24:55 -05:00
Andrew Kelley
36b6e95aa3
Merge pull request #9927 from vrischmann/fix-rlimit-resource
Fix rlimit_resource for MIPS and SPARC
2021-12-03 16:45:55 -08:00
Hiroaki Nakamura
0714832c21 Fix test for io_uring link_timeout
The old test "timeout_link_chain1" was ported from liburing test_timeout_link_chain1
509873c445/test/link-timeout.c (L539-L628)
However it turns out that both fails with EBADF (-9) on Linux kernel 5.4.

The this new test skips properly on Linux kernel 5.4
and passes on Linux kernel 5.11.
2021-12-01 14:30:33 -08:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley
902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00
Andrew Kelley
ec10e63f49 std: add workaround for failing io_uring test
See #10247
2021-11-29 18:04:28 -07:00
Hiroaki Nakamura
f5c0c0803f
Merge pull request #10151 from hnakamur/zig
io_uring: adds link_timeout
2021-11-23 12:32:25 -06:00
Stephen von Takach
ed70f9981c
feat(uefi): add virtual addressing helpers (#10195)
based off definitions in https://uefi.org/sites/default/files/resources/UEFI%20Spec%202_6.pdf
2021-11-22 21:32:16 -05:00
Vincent Rischmann
3d528161c8 io_uring: implement register_files_update 2021-11-16 19:54:19 -05:00
Vincent Rischmann
d7c770fb7f os: fix getrlimit/setrlimit test for MIPS
This test can fail due to a fix in musl for 32 bit MIPS, where musl changes limits greater than -1UL/2 to RLIM_INFINITY.
See http://git.musl-libc.org/cgit/musl/commit/src/misc/getrlimit.c?id=8258014fd1e34e942a549c88c7e022a00445c352

Depending on the system where the test is run getrlimit can return
RLIM_INFINITY for example if RLIMIT_MEMLOCK is bigger than ~2GiB.

If that happens, the setrlimit call will fail with PermissionDenied.
2021-11-16 20:36:50 +01:00
Vincent Rischmann
353c59e6d5 os/linux: fix rlimit_resource for mips/sparcv9
On MIPS and SPARC the RLIMIT kinds have different numbers than the other
architectures.
2021-11-16 20:36:50 +01:00
Ominitay
796687f156 Add chmod and chown 2021-11-15 20:04:55 -05:00
Andrew Kelley
46af3a320c
Merge pull request #10081 from hnakamur/lib_std_os_linux_io_uring_cancel
std.os.linux: Add cancel and io_uring_prep_cancel
2021-11-14 22:51:11 -05:00
Kenta Iwasaki
09c17acf02 io_uring: add poll_update
Add method from liburing to queue (but not submit) a SQE to update the
user data of an existing poll operation.
2021-11-14 13:56:41 -05:00
Hiroaki Nakamura
77d1d5839a Use io_uring_prep_rw in io_uring_prep_cancel
follow liburing's API as closely as possible.

Signed-off-by: Hiroaki Nakamura <hnakamur@gmail.com>
2021-11-12 10:51:49 +09:00
Hiroaki Nakamura
2a54c2ff19 std.os.linux: Add cancel and io_uring_prep_cancel
Signed-off-by: Hiroaki Nakamura <hnakamur@gmail.com>
2021-11-12 10:51:49 +09:00
Jakub Konka
19e5663869
Merge pull request #9935 from g-w1/plan9-std
add plan9 support to std
2021-11-11 10:45:00 -08:00
Andrew Kelley
b521510cd4
Merge pull request #9853 from koachan/sparc64-unittests
SPARCv9: make more tests pass
2021-11-10 11:32:10 -05:00
Andrew Kelley
008b0ec5e5 std.Thread.Mutex: change API to lock() and unlock()
This is a breaking change. Before, usage looked like this:

```zig
const held = mutex.acquire();
defer held.release();
```

Now it looks like this:

```zig
mutex.lock();
defer mutex.unlock();
```

The `Held` type was an idea to make mutexes slightly safer by making it
more difficult to forget to release an aquired lock. However, this
ultimately caused more problems than it solved, when any data structures
needed to store a held mutex. Simplify everything by reducing the API
down to the primitives: lock() and unlock().

Closes #8051
Closes #8246
Closes #10105
2021-11-09 18:31:03 -07:00
Andrew Kelley
65e518e8e8 io_uring: skip statx test failure on older kernels 2021-11-09 18:31:03 -07:00
Vincent Rischmann
082072bd4f os/linux/io_uring: implement statx 2021-11-09 13:35:17 -05:00
Jacob G-W
73be14027d plan9: more syscalls 2021-11-09 07:08:27 -05:00
Jacob G-W
fe314e60bb fix outputs in inline assembly 2021-11-09 07:08:27 -05:00
Jacob G-W
09992f8acc add initial plan9 support to std 2021-11-09 07:08:23 -05:00
Andrew Kelley
a78e61acf9 std: expose rusage constants under rusage namespace 2021-11-01 15:55:22 -07:00
Andrew Kelley
63f4778827 std: add Linux perf syscall bits
Example usage:

```zig
const std = @import("std");
const PERF = std.os.linux.PERF;
const assert = std.debug.assert;

test "perf" {
    var attr: std.os.linux.perf_event_attr = .{
        .type = PERF.TYPE.HARDWARE,
        .config = @enumToInt(PERF.COUNT.HW.INSTRUCTIONS),
        .flags = .{
            .disabled = true,
            .exclude_kernel = true,
            .exclude_hv = true,
        },
    };
    const fd = try std.os.perf_event_open(&attr, 0, -1, -1, PERF.FLAG.FD_CLOEXEC);
    defer std.os.close(fd);

    _ = std.os.linux.ioctl(fd, PERF.EVENT_IOC.RESET, 0);
    _ = std.os.linux.ioctl(fd, PERF.EVENT_IOC.ENABLE, 0);

    long();

    _ = std.os.linux.ioctl(fd, PERF.EVENT_IOC.DISABLE, 0);

    var result: usize = 0;
    assert((try std.os.read(fd, std.mem.asBytes(&result))) == @sizeOf(usize));

    std.debug.print("instruction count: {d}\n", .{result});
}

fn long() void {
    var i: usize = 0;
    while (i < 100000) : (i += 1) {}
}
```
2021-11-01 14:45:05 -07:00
Stephen von Takach
a132190cad fix(uefi MemoryDescriptor): padding after memory type
not 100% certain, just noticed that this is implemented slightly differently in rust
https://docs.rs/uefi/0.11.0/src/uefi/table/boot.rs.html#715
2021-10-25 16:43:23 -04:00
LemonBoy
1690b35770 std: Fix edge case in TLS tp calculation
The TLS area may be located in the upper part of the address space and,
if the platform expects a constant offset to be applied, may make the tp
register calculation overflow.

Use +% instead of +, the overflow is harmless.
2021-10-23 22:48:25 -04:00
Stephen Gregoratto
98a37dfb23 Linux: Update syscall numbers for 5.14 2021-10-17 14:22:47 -04:00
Sizhe Zhao
f3ab092f67
std.os.windows: Fix typo (#9951) 2021-10-15 14:44:05 +02:00
Koakuma
d7a5b12f94 SPARCv9: fix timeval definition 2021-10-10 09:13:18 +07:00
Koakuma
569802160e Linux: fix socket constants for SPARCv9 2021-10-10 09:13:18 +07:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Sreehari Sreedev
598db831f3 FileProtocol: add Reader, Writer, SeekableStream 2021-10-04 22:29:53 -04:00
Stephen Gregoratto
87fd502fb6 Initial bringup of the Solaris/Illumos port 2021-09-24 14:06:16 -04:00
Koakuma
bdbd060cc7 Linux/sparc64 bits: Add missing C type definitions 2021-09-23 13:57:55 -04:00
Vincent Rischmann
01f20c7f48 io_uring: implement read_fixed/write_fixed 2021-09-22 00:47:45 -04:00