214 Commits

Author SHA1 Message Date
Andrew Kelley
974c008a0e convert more {} to {d} and {s} 2021-01-02 19:03:14 -07:00
LemonBoy
dd973fb365 std: Use {s} instead of {} when printing strings 2021-01-02 17:12:57 -07:00
Andrew Kelley
c24540d263 std.debug: adjust panic message
also extern "c" instead of extern "pthread"
2021-01-01 14:56:26 -07:00
LemonBoy
c9756ca0e1 std: Show the panicking thread ID
Annotate the panic message with the thread ID to know who's the culprit.
2021-01-01 14:54:53 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Sébastien Marie
c99c6c0a68 openbsd: add commonly used libc wrappers for pledge(2) and unveil(2) 2020-12-25 16:43:14 +02:00
Sébastien Marie
bc11528b8b openbsd: define sem_t as optional pointer on opaque {} 2020-12-25 16:20:22 +02:00
Andrew Kelley
177377b6e3 rework std.ResetEvent, improve std lib Darwin integration
* split std.ResetEvent into:
   - ResetEvent - requires init() at runtime and it can fail. Also
     requires deinit().
   - StaticResetEvent - can be statically initialized and requires no
     deinitialization. Initialization cannot fail.
 * the POSIX sem_t implementation can in fact fail on initialization
   because it is allowed to be implemented as a file descriptor.
 * Completely define, clarify, and explain in detail the semantics of
   these APIs. Remove the `isSet` function.
 * `ResetEvent.timedWait` returns an enum instead of a possible error.
 * `ResetEvent.init` takes a pointer to the ResetEvent instead of
   returning a copy.
 * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch,
   which is exposed by libSystem.

stage2 changes:
 * ThreadPool: use a single, pre-initialized `ResetEvent` per worker.
 * WaitGroup: now requires init() and deinit() and init() can fail.
   - Add a `reset` function.
   - Compilation initializes one for the work queue in creation and
     re-uses it for every update.
   - Rename `stop` to `finish`.
   - Simplify the implementation based on the usage pattern.
2020-12-23 16:57:18 -08:00
Andrew Kelley
a368c0d099 std: add Darwin and FreeBSD sem_t bits 2020-12-23 13:36:21 -08:00
Andrew Kelley
19459840fe std.ResetEvent: pthreads sem_t cannot be statically initialized
because it is allowed for the implementation to use a file descriptor,
which would require making a syscall at runtime.
2020-12-23 13:36:21 -08:00
Andrew Kelley
028af97df4 std.ResetEvent: use sem_t when linking against pthreads 2020-12-23 13:36:21 -08:00
Evan Haas
ccdb81fb31 Improve handling of C compiler intrinsics in translate-c
C compiler intrinsics can only appear as part of a function call. When called
they are implicitly cast to a function pointer; treat this as a non-null
pointer so that it emits as a regular Zig function call.

Put `pub usingnamespace @import("std").c.builtins;` at the top of translated
C files so that they will have access to builtin functions defined there.

Fixes #6707
2020-12-22 23:59:30 +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
Vexu
7e30e83900
small fixes and zig fmt 2020-12-09 13:54:26 +02:00
Andrew Kelley
50a336fff8 move std.SegmentedList to the std-lib-orphanage
I spent a long time working on this data structure, and I still think
it's a neat idea, but it has no business being in the std lib.

I'm aware of the few remaining references to SegmentedList that exist in
the std lib, but they are dead code, and so I'm leaving the dead
references as a clue that the code is dead. Cleaning up dead code will
be a separate effort that involves code coverage tools to make sure we
find it all.

std-lib-orphanage commit: 2c36a7894c689ecbaf63d5f489bb0c68773410c4

closes #7190
2020-11-30 13:04:26 -07:00
Sébastien Marie
87eb498d89 openbsd: malloc_usable_size is unavailable on OpenBSD 2020-11-20 17:31:29 -08:00
Andrew Kelley
02a4e5a4bf
Merge pull request #6385 from LemonBoy/callocator
std: Make C allocator respect the required alignment
2020-11-18 20:16:57 -08: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
LemonBoy
53433cdea2 Implement a fallback mechanism for posix_memalign
Do the alignment dance by ourselves whenever posix_memalign is not
available.
Don't try to use malloc as it has too many edge cases, figuring out
whether a block of memory is manually aligned by the mechanism above or
is directly coming from malloc becomes too hard to be valuable.
2020-11-05 16:10:15 +01:00
LemonBoy
806097c165 std: Make C allocator respect the required alignment
Use posix_memalign where available and the _aligned_{malloc,free} API on
Windows.

Closes #3783
2020-11-05 16:10:15 +01: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
Joran Dirk Greef
888af655e0 Add libc signature 2020-11-01 11:46:08 +02:00
Jakub Konka
4f50958407 Clean up exporting of symbols on Darwin 2020-10-28 10:36:19 +01:00
Frank Denis
6ddb05d996 Darwin has arc4random(), too 2020-10-18 18:24:36 +02:00
Sébastien Marie
f33a610c84 add minimal openbsd support 2020-10-11 08:23:36 +00:00
Andrew Kelley
a4828f6d0f std.c (darwin) update to new opaque syntax
This was an undetected conflict between

76a195473dac059a842fed2a6ba581ca99947d2b and
95a37373e9f576854956c2909cc128b5b6388ec6
2020-10-08 22:45:39 -07:00
Andrew Kelley
76a195473d
Merge pull request #6516 from LemonBoy/fastfilecopy
std: Make file copy ops use zero-copy mechanisms
2020-10-08 20:14:47 -04:00
LemonBoy
03762da2af New review round 2020-10-07 11:13:26 +02:00
xackus
4ec26be424 implement {get, set}rlimit for linux 2020-10-04 23:56:10 +02:00
LemonBoy
0f248e0988 std: Make file copy ops use zero-copy mechanisms
Use copy_file_range on Linux (if available), fcopyfile on Darwin,
sendfile on *BSDs (and on Linux kernels without copy_file_range).
2020-10-03 12:31:17 +02:00
Loris Cro
f841ea77e2 make symlink buffer null-terminated
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-02 19:33:14 +02:00
Jakub Konka
1698e6d7a7 Link against libSystem when generating Mach-O exe
This is required when generating an exe on macOS.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 17:59:44 +02:00
Andrew Kelley
9cfcd0c296
Merge pull request #6103 from Vexu/extern
Disallow extern variables with initializers.
2020-08-20 18:35:31 -04:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Vexu
717e2a365d
correct llvm linkage conversion
when weakly exporting external declaration we need to pass LLVMExternalWeakLinkage
2020-08-20 17:12:26 +03:00
Vexu
d25674a51e
disallow extern variables with initializers 2020-08-20 11:35:33 +03:00
Andrew Kelley
ae2c88754d std: signalfd: fix the types of things; add test 2020-08-17 16:19:57 -07:00
Luna
293b07df12 add signalfd to std.c.linux 2020-08-17 16:05:35 -07:00
Maciej Walczak
6febe7e977
copy_file_range linux syscall (#6010) 2020-08-11 15:49:43 -04:00
Vexu
e7007fa7bd
translate-c: use ArrayList for macro tokens 2020-07-27 15:38:56 +03:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Jakub Konka
c63b23d684 Use fstatat on macOS (otherwise uses 32bit) 2020-06-24 21:00:21 +02:00
Andrew Kelley
da549a72e1 zig fmt 2020-06-20 18:39:15 -04:00
Ryan Liptak
62cfc68d2f Use std.ComptimeStringMap in the C tokenizer 2020-05-26 23:10:08 -07:00
Michael Dusan
e05923f34b macos: use realpath$DARWIN_EXTSN
macOS 10.15 Catalina causes an ancient variant of `realpath` to fail,
likely due to 10.15's evolving security model.

closes #5325
2020-05-16 12:41:53 -04:00
Tadeo Kondrak
6745a6f6f6
zig fmt 2020-05-05 09:38:02 -06:00
nia
14a954f350 Add arc4random_buf() in NetBSD libc, use it to implement getrandom() 2020-05-01 17:22:27 +01:00
LemonBoy
4209ab90a8 std: Use the versioned libc symbols if needed
Many symbols on NetBSD and some on OSX require the definition of an
alias.
2020-04-01 12:23:18 +02:00
LemonBoy
070ace4b22 std: Fix more NetBSD bits
Fix some more libc definitions.
2020-04-01 12:11:19 +02:00
LemonBoy
3ccf99c0bd std: Slim duplicate logic for some calls 2020-03-24 19:47:18 +01:00