119 Commits

Author SHA1 Message Date
daurnimator
e4c4a0a5f6 Improve uring definitions 2021-01-03 19:52:20 -08:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Veikka Tuominen
e79acc24d3
std: clenup, fixes, fmt 2020-12-24 00:23:29 +02:00
Andreas Linz
7e63f7ad03
Truncate user and group ids for 64 bit Linux systems (#7466)
* Truncate user and group ids

Calls to `getuid`, `getgid` and their `eid` variants fail to compile on
64bit Linux systems because the return value of the syscall is of
`usize` and needs to be truncated to fit the size of `uid_t` that is 32
bit.

Thanks to @FireFox317 for figuring this out in Zig's Discord channel!

* Add a regression test for user and group ids

* Replace @truncate with @intCast

This should be safe because `uid_t` will be 32-bit.

* Add missing import for getauxval

* Add missing package names

* Revert "Add missing import for getauxval"

This reverts commit 38f93dc89effdf657f2b81a56b96527ce4083f52.

* Skip user and group test if builtin.link_libc
2020-12-23 11:16:27 +02:00
Andrew Kelley
53987c932c std.crypto.random: introduce fork safety
Everybody gets what they want!

 * AT_RANDOM is completely ignored.
 * On Linux, MADV_WIPEONFORK is used to provide fork safety.
 * On pthread systems, `pthread_atfork` is used to provide fork safety.
 * For systems that do not have the capability to provide fork safety,
   the implementation falls back to calling getrandom() every time.
 * If madvise is unavailable or returns an error, or pthread_atfork
   fails for whatever reason, it falls back to calling getrandom() every
   time.
 * Applications may choose to opt-out of fork safety.
 * Applications may choose to opt-in to unconditionally calling
   getrandom() for every call to std.crypto.random.fillFn.
 * Added `std.meta.globalOption`.
 * Added `std.os.madvise` and related bits.
 * Bumped up the size of the main thread TLS buffer. See the comment
   there for justification.
 * Simpler hot path in TLS initialization.
2020-12-18 15:54:01 -07:00
LemonBoy
ce65533985 std: Properly fix the TLS alignment problem
ad05509 introduced a fix for the wrong problem, the logic to align the
start of main_thread_tls_buffer was already there but was flawed.

Fix it for good and avoid wasting too many bytes for alignment purposes.
2020-12-18 14:22:30 -05:00
Andrew Kelley
ad05509930 std: align(16) main_thread_tls_buffer
Before this change, thread local variables were landmines if LLVM
decided to optimize any writes to them using vector instructions.
2020-12-17 22:58:56 -07:00
Andrew Kelley
5a5389128d
Merge pull request #7369 from jorangreef/io_uring_timeout
Add io_uring TIMEOUT and TIMEOUT_REMOVE operations:
2020-12-10 15:45:38 -05:00
Joran Dirk Greef
b5a9fd9f98 Skip timeout_remove test where not supported by the kernel 2020-12-10 11:34:20 +02:00
Joran Dirk Greef
dd3eac2eb1 Debug CI io_uring unsupported op 2020-12-10 08:36:33 +02:00
Joran Dirk Greef
349d32dc2c Add io_uring TIMEOUT and TIMEOUT_REMOVE operations:
ring.timeout() to queue a IORING_OP_TIMEOUT operation
ring.timeout_remove() to queue a IORING_OP_TIMEOUT_REMOVE operation

io_uring_prep_timeout() to prep a IORING_OP_TIMEOUT sqe
io_uring_prep_timeout_remove() to prep a IORING_OP_TIMEOUT_REMOVE sqe
2020-12-09 19:06:28 +02:00
Vexu
7e30e83900
small fixes and zig fmt 2020-12-09 13:54:26 +02:00
Jonathan Marler
48660371a2 std.meta: add assumeSentinel 2020-11-29 10:36:02 -08:00
Koakuma
f10bff9ffb Add a comment to explain the fork return values on sparc64 2020-11-28 13:24:24 +07:00
Koakuma
41c40f4bbe Fix fork() on Linux/sparc64
fork() on Linux/sparc64 seems to return its result in two registers,
with %o0 always holding the current process' PID, and the parent/child
status returned in %o1. Add some glue code to convert those into
the libc-style return value.
2020-11-27 23:02:22 +07:00
LemonBoy
0a84f85945 Minor code cleanup in start_pie.zig
Thanks @daurnimator for catching this.
2020-11-23 12:36:40 +01:00
Andrew Kelley
abc717f203 modernize the PIE patch for the latest master branch
This is the part of #3960 that has to be rewritten to apply to latest
master branch code.
2020-11-22 17:28:11 -07:00
Andrew Kelley
55ab50efbd Merge branch 'piepiepie' of https://github.com/LemonBoy/zig into pie
Conflicts:
 lib/std/dynamic_library.zig (fixed in this commit)
 src/all_types.hpp
 src/codegen.cpp
 src/link.cpp
 src/main.cpp

Will manually apply the diffs to these deleted files to the new zig
code in a followup commit.
2020-11-22 12:39:44 -07:00
Andrew Kelley
c9551652b0
Merge pull request #6978 from LemonBoy/statshit
Decouple kernel and libc stat definitions
2020-11-05 17:27:22 -05:00
Andrew Kelley
f85d719952
Merge pull request #6895 from jorangreef/fallocate
linux: add fallocate()
2020-11-05 17:23:00 -05:00
LemonBoy
0e95fa455c std: Split kernel&libc definitions of stat struct
There's no guarantee for the kernel definition to be ABI compatible with
the libc one (and vice versa).
There's also no guarantee of ABI compatibility between musl/glibc.

Fun, isn't it?
2020-11-05 09:38:50 +01:00
LemonBoy
f313c88428 std: Fix pipe syscall stub for sparc64 2020-11-04 15:54:38 +01:00
Joran Dirk Greef
8193f55820 Support 32-bit big-endian targets 2020-11-03 06:03:38 +02:00
Joran Dirk Greef
78e9e131e0 Pending #5127 2020-11-02 12:37:55 +02:00
Joran Dirk Greef
067bd7e424 Switch back to writing Zig 2020-11-02 09:55:25 +02:00
Joran Dirk Greef
9dec310826 Debug unhandled errno 2020-11-02 09:52:42 +02:00
Andrew Kelley
909aae8153
Merge pull request #6792 from koachan/sparc64-linux
Initial sparc64-linux bringup
2020-11-01 22:14:56 -05:00
Joran Dirk Greef
a67f140d2f Add test 2020-11-01 11:55:27 +02:00
Andrew Kelley
a41c0b63bb
Merge pull request #6356 from jorangreef/io_uring
std: add io_uring library
2020-10-29 18:20:38 -04:00
Frank Denis
74a1175d9d std/*: add missing MIT license headers 2020-10-26 17:41:29 +01:00
Koakuma
f018201009 Predict error-less path on syscalls 2020-10-25 20:07:18 +07:00
Koakuma
2e7a4758b3 Add back ppc input/output/clobber definitions
Accidentally removed when rebasing, this adds it back.
2020-10-25 13:39:22 +07:00
Koakuma
300cfbf252 Add TLS implementation for sparc64 2020-10-24 20:03:40 +07:00
Koakuma
6146f81c6e Add pipe(2) support 2020-10-24 20:03:37 +07:00
Koakuma
dba009fd21 Account for the delay slot 2020-10-24 20:01:32 +07:00
Koakuma
23433fb317 Fix register naming 2020-10-24 19:59:05 +07:00
Koakuma
e5a11020cc Add sparc64 syscall interface 2020-10-24 19:59:04 +07:00
LemonBoy
0c355bef9e std: Slim down the error code path in initStaticTLS
Calling @panic made the executable ~30x times bigger, use a simple
`abort()` and let the user figure out what went wrong.

Supporting ARMv6 (and earlier?) platforms is not a priority.

Closes #6676
2020-10-21 23:35:06 -04:00
Tadeo Kondrak
2b4b03d301
Update zig files for opaque type syntax 2020-10-06 22:08:25 -06:00
Joran Dirk Greef
e9ba12f456 Test the range of user_data bits 2020-10-05 09:36:07 +02:00
Joran Dirk Greef
9be2941091 Split openat/close test into two separate tests
If an older kernel fails the `openat` test because of `AT_FDCWD`
then we don't want to skip the `close` test.
2020-10-04 17:48:05 +02:00
Joran Dirk Greef
958ff087f2 Use const wherever possible 2020-10-04 16:57:04 +02:00
Joran Dirk Greef
72bdfa5bdd Skip openat test only for older kernels that do not fully support AT_FDCWD 2020-10-04 16:05:52 +02:00
Joran Dirk Greef
9091fcbe9d Improve openat/accept test debugging 2020-10-04 15:11:09 +02:00
Joran Dirk Greef
6a53f4be4b Add openat(), close(), connect(), send(), recv(), as well as tests
Removes non-essential .hardlink_with_next_sqe() and .drain_previous_sqes().
2020-10-04 13:15:39 +02:00
Joran Dirk Greef
3d2de6cfba Use load relaxed semantics when reading the SQPOLL wakeup flag 2020-10-04 13:14:57 +02:00
Joran Dirk Greef
69a55fc560 Allow for advanced non-sequential SQE allocation schemes
Decouples SQE queueing and SQE prepping methods to allow for non-sequential
SQE allocation schemes as suggested by @daurnimator.

Adds essential SQE prepping methods from liburing to reduce boilerplate.

Removes non-essential .link_with_next_sqe() and .use_registered_fd().
2020-10-04 13:01:41 +02:00
Joran Dirk Greef
e32c7d06e5 Limit entries to u12, add errors for invalid entries, use mem.zeroInit 2020-10-04 12:49:48 +02:00
Joran Dirk Greef
61ec6cb6d3 Expose available kernel features 2020-10-04 12:48:08 +02:00
Joran Dirk Greef
a9b107045f Use load acquire semantics when reading the SQPOLL wakeup flag
Ensures that the wakeup flag is read after the tail pointer has been
written. It's important to use memory load acquire semantics for the
flags read, otherwise the application and the kernel might not agree on
the consistency of the wakeup flag, leading to I/O starvation.

Refs: 6768ddcc56
Refs: https://github.com/axboe/liburing/issues/219
2020-10-03 14:34:42 +02:00