Commit Graph

1156 Commits

Author SHA1 Message Date
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
HugoFlorentino
806aeab2a7 adding support for UTF-8 output 2021-09-20 02:05:52 -04:00
Jens Goldberg
d2b5105f54
Add Linux ioctl creation utilities (#9748)
* Add Linux ioctl creation utilities

* Apply suggestions from code review

Co-authored-by: Veikka Tuominen <git@vexu.eu>

* Update lib/std/os/linux.zig

Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>

Co-authored-by: Veikka Tuominen <git@vexu.eu>
Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>
2021-09-18 09:56:11 +03:00
Stephen Gregoratto
506f24cac2 Set the Storage socket sizes to be system defined
Some systems (Solaris, OpenBSD, AIX) change their definitions of
sockaddr_storage to be larger than 128 bytes. This comment adds a new
constant in the `sockaddr` that defines the size for every system.

Fixes #9759
2021-09-16 13:32:55 +03:00
Travis Martin
5d14590ed1 Remove WIN16 version of WSAOVERLAPPED. Use LPWSAOVERLAPPED_COMPLETION_ROUTINE 2021-09-14 15:36:08 -04:00
Kenta Iwasaki
c4f97d3365 os: usingnamespace fixes for std.x.os.Socket and std.os.TCP
Extract existing constants to do with TCP socket options into a 'TCP'
namespace.

Export 'MSG' and 'TCP' from std.os.{linux, windows} into std.c.

Fix compile errors to do with std.x.os.Socket methods related to setting
TCP socket options.

Handle errors in the case that an interface could not be resolved in an
IPv6 address on Windows. Tested using Wine with the loopback interface
disabled.

Have all instantiations of std.x.os.Socket on Windows instantiate an
overlapped socket descriptor. Fixes the '1ms read timeout' test in
std.x.net.tcp.Client. The test would previously deadlock, as read
timeouts only apply to overlapped sockets.

Windows documentation by default recommends that most instantiations of
sockets on Windows be overlapped sockets (s.t. they may operate in both
blocking or nonblocking mode when operated with WSA* syscalls). Refer to
the documentation for WSASocketA for more info.
2021-09-12 23:36:44 -04:00
Andrew Kelley
2264fca03e fix regression on linux with kernel_timespec
I incorrectly assumed that __kernel_timespec was used when not linking
libc, however that is not the case. `std.os.timespec` is used both for
libc and non-libc cases. `__kernel_timespec` is a special struct that is
used only for io_uring.
2021-09-01 17:54:07 -07:00
Andrew Kelley
0932b0d9b3 std.os reorg: regression fixes to stack_t, and std.Thread 2021-09-01 17:54:07 -07:00
Andrew Kelley
1a492d5156 re-apply a commit dropped in this branch due to conflicts
This commit reapplies 4f0aa7d639.
2021-09-01 17:54:07 -07:00
Andrew Kelley
057f0fec33 std.os fixes to get the test suite passing again 2021-09-01 17:54:07 -07:00
Andrew Kelley
cca57042df std: fix regressions from this branch
Also move some usingnamespace test cases from compare_output to
behavior.
2021-09-01 17:54:07 -07:00
Andrew Kelley
a2ff3a13fe std, compiler-rt: remove test names where applicable
Tests with no names are executed when using `zig test` regardless of the
`--test-filter` used. Non-named tests should be used when simply
importing unit tests from another file. This allows `zig test` to find
all the appropriate tests, even when using `--test-filter`.
2021-09-01 17:54:06 -07:00
Andrew Kelley
c05a20fc8c std: reorganization that allows new usingnamespace semantics
The proposal #9629 is now accepted, usingnamespace stays but no longer
puts identifiers in scope.
2021-09-01 17:54:06 -07:00
Andrew Kelley
7884d84315 std.os.windows: reorg to avoid usingnamespace
Down to 19 uses of `usingnamespace`.
2021-09-01 17:54:06 -07:00
Andrew Kelley
7f03cfe161 std.os: more reorganization efforts
* std lib tests are passing on x86_64-linux with and without -lc
 * stage2 is building from source on x86_64-linux
 * down to 38 remaining uses of `usingnamespace`
2021-09-01 17:54:06 -07:00
Andrew Kelley
c09ba8796c std.os.linux: remove the "bits" namespace altogether
Now there is only 1 architecture-specific file for Linux kernel bits.
2021-09-01 17:54:06 -07:00
Andrew Kelley
1bbfcb95ab std: reorganize std.c to eliminate usingnamespace
Behavior tests pass on x86_64-linux with -lc
2021-09-01 17:54:06 -07:00
Andrew Kelley
3deda15e21 std.os reorganization, avoiding usingnamespace
The main purpose of this branch is to explore avoiding the
`usingnamespace` feature of the zig language, specifically with regards
to `std.os` and related functionality.

If this experiment is successful, it will provide a data point on
whether or not it would be practical to entirely remove `usingnamespace`
from the language.

In this commit, `usingnamespace` has been completely eliminated from
the Linux x86_64 compilation path, aside from io_uring.

The behavior tests pass, however that's as far as this branch goes. It is
very breaking, and a lot more work is needed before it could be
considered mergeable. I wanted to put a pull requset up early so that
zig programmers have time to provide feedback.

This is progress towards closing #6600 since it clarifies where the
actual "owner" of each declaration is, and reduces the number of
different ways to import the same declarations.

One of the main organizational strategies used here is to do namespacing
with real namespaces (e.g. structs) rather than by having declarations
share a common prefix (the C strategy). It's no coincidence that
`usingnamespace` has similar semantics to `#include` and becomes much
less necessary when using proper namespaces.
2021-09-01 17:54:06 -07:00
Philip Åkesson
4f0aa7d639 std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
The intermediate value can be larger than an u16, so @truncate is needed
to match the behavior of musl.
2021-08-31 22:03:54 -04:00
jdmichaud
49c9975484
zig fmt: respect trailing commas in inline assembly 2021-08-29 11:57:32 +02:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Koakuma
dd75302563 Linux/SPARCv9: use C calling convention for restore_rt
This is needed to prevent infinite loop when calling rt_sigreturn.
2021-08-24 14:08:54 -04:00
Andrew Kelley
a98fa56ae9 std: [breaking] move errno to become an nonexhaustive enum
The primary purpose of this change is to eliminate one usage of
`usingnamespace` in the standard library - specifically the usage for
errno values in `std.os.linux`.

This is accomplished by truncating the `E` prefix from error values, and
making errno a proper enum.

A similar strategy can be used to eliminate some other `usingnamespace`
sites in the std lib.
2021-08-24 01:23:28 -04:00
daurnimator
72c4b80d31
std.os: (p)writev should perform partial writes if iov.len > IOV_MAX
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-08-22 22:22:53 +03:00
Aydin Mercan
e3e6df17ed linux: Add recent clone/clone3 and missing signalfd flags.
The following flags have been introduced:
- CLONE_PIDFD (>=5.2)
- CLONE_INTO_CGROUP (>=5.7)
- SFD_CLOEXEC and SFD_NONBLOCK (>=2.6.27)
2021-08-21 19:41:00 +03:00
Ayende Rahien
65208a7fa2
Expose register_eventfd, register_eventfd_async, unregister_eventfd i… (#9449)
* Expose register_eventfd, register_eventfd_async, unregister_eventfd in the IO URing API

* Fixing formatting

* Fixing typo

* Removing unnecessary casts and adding better comments for a single registration of eventfd

* Update lib/std/os/linux/io_uring.zig

Co-authored-by: Joran Dirk Greef <joran@coil.com>

* Update lib/std/os/linux/io_uring.zig

Co-authored-by: Joran Dirk Greef <joran@coil.com>

* Updating util function name

Co-authored-by: Joran Dirk Greef <joran@coil.com>
2021-08-13 22:41:18 -05:00
Takeshi Yoneda
97560cd915 Merge remote-tracking branch 'origin' into libc-wasi-test 2021-08-09 14:39:26 +09:00
Takeshi Yoneda
7814a2bd4a review: use defined flag for oflags.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-09 14:36:11 +09:00
Klecko
5789036b86 linux: add missing FUTEX definitions 2021-08-07 15:35:27 +03:00
N00byEdge
871f6343f4 Move iovec and log levels to bits/posix.zig
This lets only the OSes that uses them to import them, and removes
dependencies on bits.zig for the os/<os>/<arch>.zig files
2021-08-02 11:05:05 +00:00
N00byEdge
934df5bd44 Make linux syscalls accessible with non-Linux target OS 2021-08-02 11:05:05 +00:00
Vincent Rischmann
accde7fe2d windows: add wrappers for LocalFree, SetThreadDescription and GetThreadDescription 2021-07-29 10:57:08 +02:00
Vincent Rischmann
0be1e74902 windows/kernel32: add LocalFree, SetThreadDescription and GetThreadDescription 2021-07-29 10:57:08 +02:00
Mahdi Khanalizadeh
15bec20b00 linux: add mknod and mknodat syscalls 2021-07-28 18:15:41 -04:00
Takeshi Yoneda
1e20a62126 WASI,libc: enable tests.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-07-27 09:01:00 +09:00
Michal Ziulek
18b8738069
Fixed compile error: 'bMenu' needs to casted. (#9426) 2021-07-22 01:28:21 +02:00
Biolunar
093e10b66e
linux stdlib: fix definition of RW flags (#9428) 2021-07-22 01:27:59 +02:00
Kenta Iwasaki
aa2a31612f io_uring: add sqe prep methods for epoll_ctl, poll_add, and poll_remove
Implement io_uring submission queue entry preparation methods for
epoll_ctl, poll_add and poll_remove.

Poll masks are designated as 32-bit little-endian integers as
specified in liburing's definitions.

Updated io_uring_prep_rw to take in an unsigned 64-bit address instead
of an anytype. io_uring_sqe by default assumes that the address
specified in a submission queue entry is an unsigned 64-bit integer.
2021-07-11 09:15:54 +00:00
Malcolm Still
a3703745eb
Add waitid syscall on linux (#9335) 2021-07-10 16:56:41 -04:00
Carlos Zúñiga
b936bbd2f1 Fixed builtin.Target -> std.Target 2021-07-07 07:54:38 +03:00
Andrew Kelley
b7da1b2d45
Merge pull request #9175 from kprotty/thread
std.Thread enhancements
2021-07-04 22:31:02 -04:00
Andrew Kelley
41336acb0b AstGen: detect redeclaration of function parameters
Also improve redeclaration error message to include the category of
variable.
2021-07-02 13:27:35 -07:00
kprotty
f0fa129e9b std.Thread: more cleanup & testing 2021-06-30 21:49:00 -05:00
kprotty
009c95b8ec std.Thread: more fixes 2021-06-30 21:49:00 -05:00
kprotty
3a276be135 std.Thread.getCpuCount(): fix usages 2021-06-30 21:48:59 -05:00
kprotty
0a1def7833 changes to accomodate std.Thread update 2021-06-30 21:48:59 -05:00
Nameless
908b431abe std/os/uefi: fix packed struct bitfields 2021-06-30 09:28:08 +03:00
Sreehari Sreedev
b8329351b1 boot_services: allow custom MemoryTypes 2021-06-30 09:26:09 +03:00
Andrew Kelley
06129d7e3d std: implement a cross platform file locking abstraction
This modifies the lock semantics from using AccessMode to using
NtLockFile/NtUnlockFile.

This is a breaking change.
2021-06-29 14:25:04 -07:00
Andrew Kelley
488f68069b implement std.fs.File.setLock for Windows 2021-06-29 14:25:04 -07:00
Andrew Kelley
1534cd2f88
Merge pull request #9148 from marler8997/windowsChildOutput
finish ChildProcess collectOutputWindows
2021-06-25 21:42:18 -04:00
Andrew Kelley
d279a23c93 mips: fix syscall_pipe
Previously the fd parameter was ignored and so the result would not get
populated. Now it passes the fd pointer to the inline assembly so that
the results can be observed.
2021-06-21 17:03:04 -07:00
Andrew Kelley
3d8aa97165 std.os.linux.bpf: fix incorrect usage of unexpectedErrno 2021-06-21 17:03:03 -07:00
Andrew Kelley
59d6b7bbb9 std.os.linux: fix splitValueBE64 2021-06-21 17:03:03 -07:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Jacob G-W
641ecc260f std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
LemonBoy
fd6d5f1609 std: Fix PIE startup sequence
* Don't skip the TLS initialization (Fixes #9083)
* Add a test case where a PIE program is built and run
* Refactor the common initialization code in the Linux startup
  sequence.
2021-06-19 18:02:51 +02:00
Jonathan Marler
9e0338b82e finish ChildProcess collectOutputWindows
This finishes LemonBoy's Draft PR ziglang#6750.  It updates ChildProcess to collect the output from stdout/stderr asynchronously using Overlapped IO and named pipes.
2021-06-18 08:26:22 -06:00
LemonBoy
1e0d68e6fb std: Use WINAPI instead of .Stdcall 2021-06-17 17:39:32 -06:00
LemonBoy
34c00ecf57 std: Avoid deadlocking in ChildProcess.exec
Reading stdin&stderr at different times may lead to nasty deadlocks (eg.
when stdout is read before stderr and the child process doesn't write
anything onto stdout).

Implement a polling mechanism to make sure this won't happen: we read
data from stderr/stdout as it becomes ready and then it's copied into an
ArrayList provided by the user, avoiding any kind of blocking read.
2021-06-17 17:39:32 -06:00
Michael Dusan
bfe3558efe netbsd: add more std.os.bits 2021-06-16 14:46:25 -04:00
Veikka Tuominen
4173a2bc24 add a test for dup and dup2 2021-06-14 12:17:12 +03:00
Samadi van Koten
ee048d6569 Add std.os.dup() 2021-06-14 12:17:12 +03:00
viri
b2879825d7 std.windows: fix OVERLAPPED, add OVERLAPPED_ENTRY 2021-06-13 10:26:02 +03:00
Garrett Squire
a6d72fea06 Make std.ChildProcess exit code u8 to match std.process.exit
This patch adjusts the exit code for a child process to be a u8. Since
the WEXITSTATUS macro returns the lower eight bits, it's safe to assume
that we can truncate the returned u32.
2021-06-12 23:13:14 +03:00
Exonorid
f63338195d Renamed @byteOffsetOf to @offsetOf 2021-06-12 19:16:01 +03:00
protty
2ba68f9f4c
std.Thread.Futex addition (#9070)
* std.Thread.Futex: implementation + tests

* std.Thread.Futex: fix darwin compile errors

* std.Thread.Futex: fix wait() documentation typo

* std.Thread.Futex: fix darwin version check

* std.Thread.Futex: remove unnecessary comptime keyword
2021-06-12 08:51:37 -05:00
viri
2ce033f415
std.os.windows: implement <timeapi.h> (#8801) 2021-06-11 12:19:35 +03:00
Jens Goldberg
a3f7a48d9c netlink ifi_change no longer reserved
The documentation (e.g. `man 7 rtnetlink`) states that ifi_change "is reserved for future use and should be always set to 0xFFFFFFFF". This is no longer true, even though the text hasn't been updated.
2021-06-10 22:13:37 +03:00
viri
13dc34f779 std.Progress: use *W functions on windows
Closes #534.
See: https://source.winehq.org/git/wine.git/blob/refs/heads/stable:/dlls/kernelbase/console.c#l520
2021-06-09 19:10:28 +03:00
viri
610ce544d5 windows: remove TCHAR idiom entirely 2021-06-09 19:10:28 +03:00
Vincent Rischmann
c71e8a30cd os/linux: add fadvise 2021-06-09 18:15:50 +03:00
Vincent Rischmann
7f32c799a9 os/bits/linux: add the fadvise advice values 2021-06-09 18:15:50 +03:00
Jens Goldberg
7462b0e5b9
Add Linux XDP bits (#9019) 2021-06-07 21:33:29 -04:00
LemonBoy
e44b55b072 std: Fix some BPF fn definitions
Cros-checked with bpf.h of kernel 5.12.9.
2021-06-06 20:41:14 -04:00
Kenta Iwasaki
4909aa1da4 os/bits: remove duplicate sockaddr_storage for dragonfly 2021-06-01 18:35:13 +09:00
Kenta Iwasaki
aad8491dbd os: make msghdr, msghdr_const, and sockaddr_storage backwards-compatible
`msghdr` and `msghdr_const` definitions have been added back the way
they were in std.os. std.os.sendmsg has also been modified to accept a
msghdr_const again to ensure backwards-compatibility with this PR.
Underneath the hood, std.os.sendmsg will @ptrCast the provided
msghdr_const into a std.x.os.Socket.Message.

`sockaddr_storage` definitions have been added back the way they were in
std.os, except that it now simply aliases
std.x.os.Socket.Address.Native.Storage as all of
std.x.os.Socket.Address.Native.Storage's fields are equivalent to the
fields that were previously defined for std.x.os.bits.sockaddr_storage.

std.x.os.Socket.sendMessage now no longer is a stub that aliases
std.os.sendmsg, but instead calls and handles
errors from std.os.system.sendmsg directly.

Addresses feedback to urge backwards compatibility from @andrewrk.
2021-06-01 18:24:43 +09:00
Kenta Iwasaki
6950e4c294 x/os/net: remove unnecessary comptime prefix in resolveScopeID() 2021-06-01 18:24:43 +09:00
Kenta Iwasaki
278e5d398e x: replace std.builtin with std.Target.current 2021-06-01 18:24:43 +09:00
Kenta Iwasaki
21ec0158a1 os: sockaddr_storage -> std.x.os.Socket.Address.Native.Storage 2021-06-01 18:24:42 +09:00
lithdew
9ba65592d6 os: have sendmsg, recvmsg flags be c_int 2021-06-01 18:22:58 +09:00
lithdew
3600508fe1 x/io, x/os: async i/o reactor, cross-platform socket syscalls and bits
Cross-platform versions of msghdr, sendmsg, recvmsg, linger, and iovec
were provided based on findings from glibc, musl, and Microsoft's
documentation.

Implemented initial Reactor interface for epoll (linux) which wraps
around I/O reactor subsystems such as epoll, kqueue, select, etc. across
different platforms. The Reactor interface allows for driving async I/O
in Zig applications.

A test was added for the Reactor interface to drive a TCP
client/listener socket pair.

A greatest-common-subset of possible socket initialization flags (close
socket on exec syscalls, initialize socket to be non-blocking) were
implemented.

A test was added for using sendmsg/recvmsg syscalls across different
platforms for a TCP client/listener socket pair.
2021-06-01 18:22:57 +09:00
Jens Goldberg
1df993706a Fix socklen_t cast in win32 recvfrom
All other uses of `ws2_32.socklen_t` in windows.zig casts the value to an i32. `recvfrom` should do so as well; it currently errors out with `expected type '?*i32', found '?*u32'`.
2021-05-24 13:46:35 -04:00
Michael Dusan
8cebbc352a housekeeping: builtin.arch → builtin.cpu.arch 2021-05-24 13:38:47 -04:00
Michael Dusan
75cd37b8f7 dragonfly: pass zig build test 2021-05-24 10:24:41 -04:00
Michael Dusan
0f26120377 overhaul elf csu (c-runtime startup) logic
- more support for linux, android, freebsd, netbsd, openbsd, dragonfly
- centralize musl utils; musl logic is no longer intertwined with csu
- fix musl compilation to build crti/crtn for full archs list
- fix openbsd to support `zig build-lib -dynamic`
- initial dragonfly linking success (with a warning)

ancillary:

- fix emutls (openbsd) tests to use `try`
2021-05-23 15:38:57 -04:00
Andrew Kelley
1c636e2564
Merge pull request #8844 from ifreund/inline
Support inline keyword as well as callconv(.Inline)
2021-05-22 20:56:30 -04:00
Sébastien Marie
ceacb7d247 openbsd: complete kqueue(2) constant definitions 2021-05-22 20:52:44 -04:00
Andrew Kelley
7cd9b30e0a
Merge pull request #7664 from marler8997/fixWindowsPaths
implement nt path conversion for windows
2021-05-22 17:58:59 -04:00
Jonathan Marler
b0116afd8a handle relative paths with too many ".." 2021-05-21 01:29:40 -06:00
mason1920
884547f177 Const correct GUID parameter of getInfo and setInfo 2021-05-20 18:53:59 -04:00
Andrew Kelley
495e996169
Merge pull request #8776 from notviri/windows-wm-constants
fix & add some Win32 window message constants
2021-05-20 18:51:45 -04:00
Jonathan Marler
a72ad61cd4 have collapseRepeats return slice intead of just len 2021-05-20 14:00:41 -06:00
Jonathan Marler
666584067a implement nt path conversion for windows 2021-05-20 14:00:40 -06:00
Andrew Kelley
61850f8883 std: Windows: WSASocketW ensures WSAStartup
When WSASocketW gets WSANOTINITIALISED, now it will lock a mutex to
safely call WSAStartup and then try again one time.

This implementation:
 * Does not use recursion
 * Contains a detailed doc comment explaining why things are how they are
 * Is careful about which errors are surfaced in the respective error
   sets. `std.os.socket` intentionally does not have "not initialised"
   as one of the possible errors.
2021-05-20 12:28:30 -07:00
Bxil
85c2ffc9ba std.os: WSAStartup is now called upon socket creation when needed 2021-05-20 11:22:55 -07:00
Isaac Freund
5b850d5c92
Run zig fmt on src/ and lib/std/
This replaces callconv(.Inline) with the more idiomatic inline keyword.
2021-05-20 17:14:18 +02:00
Sébastien Marie
28a89b9ebc openbsd: convert builtin.arch to builtin.target.cpu.arch 2021-05-19 10:55:21 +02:00
Andrew Kelley
4187008b5e std: update freebsd bits to new builtin 2021-05-18 10:49:33 -07:00
Andrew Kelley
83677074f9 std: update regarding std.builtin reorganization
There are also some regressed std.fmt tests here and I haven't figured
out what's wrong yet.
2021-05-17 16:08:09 -07:00
Andrew Kelley
597082adf4 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * src/Compilation.zig
 * src/codegen/spirv/spec.zig
 * src/link/SpirV.zig
 * test/stage2/darwin.zig
   - this one might be problematic; start.zig looks for `main` in the
     root source file, not `_main`. Not sure why there is an underscore
     there in master branch.
2021-05-15 21:44:38 -07:00
viri
a994966870 remove range constants 2021-05-15 10:08:07 -06:00
Andrew Kelley
607abb5b14 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-14 23:16:46 -07:00
viri
ca575f887c std: re-add weird undocumented Win32 constants
Got deleted. Not documented but sure.
2021-05-14 15:15:20 -06:00
viri
150a3ad6ff std: fix & add os.windows.user32 WM constants 2021-05-14 15:06:47 -06:00
Andrew Kelley
826d833416
Merge pull request #8746 from koachan/sparc64-fixes
Various Linux/SPARCv9 fixes
2021-05-14 15:21:17 -04:00
Andrew Kelley
93896ef860 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-13 23:50:39 -07:00
Andrew Kelley
c9cc09a3bf Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux.zig
 * lib/std/os/windows/bits.zig
 * src/Module.zig
 * src/Sema.zig
 * test/stage2/test.zig

Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.

The conflicts were all trivial.
2021-05-12 16:41:20 -07:00
LemonBoy
e260cfae85 stage2: Add CPU feature detection for macos
This is mostly meant to detect the current and future AArch64 core types
as the x86 part is already taken care of with OS-independent machinery.
2021-05-12 09:43:49 +02:00
Koakuma
6e5330ee38 Define ENOTSUP for SPARC 2021-05-12 14:23:08 +07:00
Michael Dusan
30ace64fc4 bsd: detect os version
- netbsd, dragonly: use sysctlbyname
- openbsd: use sysctl
- updated default semver ranges
2021-05-11 22:05:08 -04:00
LemonBoy
8bb58fb428 std: Fix offset param splitting for preadv/pwritev
The kernel interface expects the offset as a low+high pair even on BE
systems.
2021-05-11 15:49:53 +02:00
LemonBoy
780f510ac0 std: Fix fallocate offset type 2021-05-11 12:33:48 +02:00
LemonBoy
31f1cc9a0d std: Harmonize use of off_t between libc and Zig impls
Let's follow the libc/kernel convention and use an i64 for offsets, we
bitcast as needed and avoid the useless conditional casts.
2021-05-11 12:33:48 +02:00
lithdew
0d0edd23a8 std/os: add missing sockaddr_storage defs 2021-05-10 19:22:31 +09:00
lithdew
e652595f2a std/os: fix sockaddr_storage padding size 2021-05-10 19:22:31 +09:00
lithdew
6cb6edb6f6 std/os/windows/ws2_32: add missing FIONBIO constant 2021-05-10 19:22:31 +09:00
lithdew
77f8a9ae22 x/os/socket, std/os/windows: implement loading winsock extensions
Implement loading Winsock extensions.

Add missing Winsock extension GUID's.

Implement readVectorized() for POSIX sockets and
readVectorized() / writeVectorized() for Windows
sockets.

Inverse how mixins are used to implement platform-independent syscalls
for the std.x.os.Socket abstraction. This cleans up the API as suggested
by @komuw.
2021-05-10 19:22:31 +09:00
lithdew
3d946ef5eb x/os, x/net, os:, fix typos/errors, add missing constants/docs
Add missing constants to ws2_32 such as SIO_BASE_HANDLE.

Made all declared constants in ws2_32 comptime_int, and fixed a few
broken constants (i.e. GUID's).

Fixed a few syscalls not having callconv(WINAPI) in ws2_32.

Fixed a typo in std.x.net.tcp.Client.

Removed unnecessary @alignCast's for socket addresses in
std.x.net.Socket.

Added a warning on using timeout methods for std.x.net.Socket.

Fixed compilation error spotted by CI in std.os that references
std.os.windows.ws2_32.SD_RECEIVE.

Renamed std.x.os.Socket.setOption()'s parameter `name: u32` to `code:
u32`.
2021-05-10 19:22:31 +09:00
lithdew
d7b601b35e std/os, x/os/socket: windows support, socket helpers, getpeername()
Socket I/O methods such as read, readv, write, writev, send, recv,
sendmsg, recvmsg have been generalized to read(buf, flags), write(buf,
flags), readVectorized(vectors, flags), and writeVectorized(vectors,
flags). There is still some work left to be done abstracting both
readVectorized and writeVectorized properly across platforms, which is
work to be done in a future PR.

Support for setting the linger timeout of a socket, querying the remote
address of a socket, setting whether or not keep-alive messages are to
be sent through a connection-oriented socket periodically depending on
host operating system settings has been added.

`std.io.Reader` and `std.io.Writer` wrappers around `Socket` has been
implemented, which wrap around Socket.read(buf, flags) and
Socket.write(buf, flags). Both wrappers may be provided flags which are
passed to Socket.read / Socket.write accordingly.

Cross-platform support for `getpeername()` has been implemented.

Windows support for the new `std.x.os.Socket` has been implemented. To
accomplish this, a full refactor of `std.os.windows.ws2_32` has been
done to supply any missing definitions and constants based on
auto-generated Windows syscall bindings by @marler8997.

`std.x.net.TCP.Listener.setQuickACK` has been moved to
`std.x.net.TCP.Client.setQuickACK`.

Windows support for resolving the scope ID of an interface name
specified in an IPv6 address has been provided.

`sockaddr_storage` definitions have been provided for Windows, Linux,
and Darwin. `sockaddr_storage` is used to allocate space before any
socket addresses are queried via. calls such as accept(), getsockname(),
and getpeername().

Zig-friendly wrappers for GetQueuedCompletionStatusEx(), getpeername(),
SetConsoleCtrlHandler(), SetFileCompletionNotificationModes() syscalls
on Windows have been provided.

Socket.setOption() was provided to set the value of a socket option in
place of os.setsockopt. Socket.getOption() will be provided in a future
PR.

There is still further work to be done regarding querying socket option
values on Windows, which is to be done in a subsequent PR.
2021-05-10 19:22:31 +09:00
Frank Denis
4e399ef62c Initialize the Stat structure
The system `stat` structure includes padding, and, on some
operating systems such as all BSDs, "spare" bytes at the end.

We can't reliably compare two `Stat` values if these are
uninitialized, while being later compared.

This is what was causing the `fstatat` test to fail on FreeBSD
since the update to LLVM 12. It was previously only passing by
accident.
2021-05-09 18:15:42 +02:00
Andrew Kelley
5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Andrew Kelley
67154d233e
Merge pull request #8686 from Vexu/try
Allow tests to fail
2021-05-08 17:29:44 -04:00
Andrew Kelley
b6bb0ee1ac Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux/tls.zig
 * test/behavior/align.zig
 * test/behavior/atomics.zig
 * test/behavior/vector.zig
2021-05-08 10:53:22 -07:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Michael Dusan
84d5cc31c5 fix test to restore cwd after chdir
- `../zig-cache/tmp` is no longer created by subsequent test(s)
2021-05-07 01:04:38 -04:00
Andrew Kelley
530e67cb86
Merge pull request #8683 from LemonBoy/thumblinux
Initial bringup for Linux/Thumb2
2021-05-06 12:50:34 -04:00
Andrew Kelley
fc40d23723 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * lib/std/array_list.zig
 * lib/std/c/ast.zig
 * lib/std/c/parse.zig
 * lib/std/os/bits/linux.zig
2021-05-05 10:48:22 -07:00
LemonBoy
afbcb6209d std: Initial bringup for Linux on Thumb2
There are some small problems here and there, mostly due to the pointers
having the lsb set and disrupting the fn alignment tests and the
`@FrameSize` implementation.
2021-05-04 18:52:53 +02:00