80 Commits

Author SHA1 Message Date
Isaac Freund
5f2bdafa39 std.posix: remove unchecked std.os.linux usage
Using std.os.linux directly in e.g. std.posix.timerfd_create() causes
the function to compile but silently fail at runtime when targeting any
OS other than Linux.

To catch errors like this at compile time, std.os.linux must only be
directly accessed within std.posix where there has been a comptime check
that the target os is in fact Linux.
2024-06-18 22:35:28 +02:00
Isaac Freund
a1777cb5cb
std: fix pthread_{get,set}name_np return type ABI
I believe this was accidentally broken when the E enum for errno values
was introduces. These functions are quite the special case in that they
return the error value directly rather than returning -1 and passing the
error value through the errno variable.

In any case, using a u16 as the return type at the ABI boundary where a
c_int is expected is asking for trouble.
2024-06-17 23:26:53 +02:00
Isaac Freund
687a756bf9
std: make all dirent structs extern
Using structs with unspecified layout on the ABI boundry can't end well.
2024-06-17 23:26:53 +02:00
Andrew Kelley
cd62005f19 extract std.posix from std.os
closes #5019
2024-03-19 11:45:09 -07:00
Tim Culverhouse
bec8511728 std.os: export T struct and winsize struct
Export the T struct and winsize struct for targets which have it defined
in std.c. This struct defines libc constants for ioctl syscalls.
2024-02-14 17:53:37 -08:00
Andrew Kelley
0c88f927f1 std.os.termios: consolidate and correct 2024-02-12 16:21:21 -07:00
Andrew Kelley
7680c5330c some API work on std.c, std.os, std.os.wasi
* std.c: consolidate some definitions, making them share code. For
  example, freebsd, dragonfly, and openbsd can all share the same
  `pthread_mutex_t` definition.
* add type safety to std.c.O
  - this caught a bug where mode flags were incorrectly passed as the
    open flags.
* 3 fewer uses of usingnamespace keyword
* as per convention, remove purposeless field prefixes from struct field
  names even if they have those prefixes in the corresponding C code.
* fix incorrect wasi libc Stat definition
* remove C definitions from incorrectly being in std.os.wasi
* make std.os.wasi definitions type safe
* go through wasi native APIs even when linking libc because the libc
  APIs are problematic and wasteful
* don't expose WASI definitions in std.posix
* remove std.os.wasi.rights_t.ALL: this is a footgun. should it be all
  future rights too? or only all current rights known? both are
  the wrong answer.
2024-02-11 13:38:55 -07:00
Andrew Kelley
a60f219660 std.c.MAP: use a packed struct
Same as previous commit, but for the libc interface.
2024-02-06 22:06:01 -07:00
Linus Groh
c097209792 std.c.linux: Add getpw{nam,uid}() 2023-09-08 21:46:05 +03:00
Andrew Kelley
8678d445c2 Revert "linux adding some NUMA support"
This reverts commit 6f418c11e1ad1150fbdb002cfe1be92bda4e93cb.
2023-07-31 11:02:43 -07:00
Andrew Kelley
182bec8771 Revert "std.os: adding linux's sched_setaffinity and its wrapper"
This reverts commit c7bf8bab38f8b89c1371eedb9229e00a29b5ca5b.
2023-07-31 11:01:42 -07:00
Andrew Kelley
1b9ffa0824 Revert "std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791)"
This reverts commit 41502c6aa53a3da31b276c23c4db74db7d04796b.
2023-07-31 10:54:35 -07:00
Andrew Kelley
9f20d01cfb Revert "std.c: exposing timer api"
This reverts commit 54ea0bbcdddc9e13ed98415d8883f03d59392509.
2023-07-31 10:51:44 -07:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
David CARLIER
54ea0bbcdd std.c: exposing timer api 2023-06-18 08:09:42 -07:00
David CARLIER
41502c6aa5
std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791) 2023-05-25 14:32:17 -05:00
David CARLIER
c7bf8bab38 std.os: adding linux's sched_setaffinity and its wrapper 2023-05-13 21:18:18 +03:00
David CARLIER
6f418c11e1 linux adding some NUMA support 2023-05-13 12:13:02 +03: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
Ganesan Rajagopal
06f70c030a Fix missing pthread_key_t definition on linux
* pthread_key_t should also be available for non-android platforms
* Also change the type to c_uint because Linux pthreadtypes.h typedefs it as "unsigned int"

Partially addresses #13950
2022-12-21 17:00:41 -05:00
Andrew Kelley
353121d9d5 std.c.fstatat64: add noalias attributes 2022-12-14 14:26:02 -07: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
Louis Pearson
8d4778b4f9
Support compiling for the android NDK (#13245) 2022-10-21 18:32:56 -04:00
ominitay
295451dfe5
std: Replace use of stage1 function pointers 2022-09-29 21:45:30 +03:00
billzez
dfcadd22bb
fix android definition of pthread_rwlock_t (#12830) 2022-09-16 20:20:24 -05:00
Andrew Kelley
e0a0df5a8a
Merge pull request #11598 from aiotter/master
Add functions from `dirent.h` to std.c
2022-05-26 20:11:54 -04:00
aiotter
552ef5f2e4 std.c: Implement dirent on std/c/linux.zig 2022-05-17 15:23:55 +09: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
Andrew Kelley
6d73f89bf1 stage2: disable default panic handler when linking -lc
It's failing to compile std.os.dl_iterate_phdr correctly.
2022-03-20 00:36:44 -07:00
Koakuma
cb3b1dd6dd c/linux: Fix stat struct definition for SPARCv9
The libc interface uses `stat` instead of `stat64` struct.
This fixes, among other things, `zig fmt` accidentally setting the
formatted file's permission to 000.
2022-03-13 16:48:02 -04:00
m
bd8d6a8342 std: validate frame-pointer address in stack walking 2022-02-11 15:28:36 +01:00
joachimschmidt557
fa84625aeb std: Add some missing termios types to c/linux.zig and os.zig 2022-01-23 17:12:07 +01:00
johnLate
4addb26bba Fix os.rusage when linking with c library on Linux
Fixes ziglang#10543 on Linux.
2022-01-17 16:52:36 +02: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
Felix "xq" Queißner
2fefd4ea8e Fixes invalid errno definition for ***-linux-android 2021-11-18 12:58:28 -05:00
pfg
1de6f9a267
std: add missing termios def to std/c/linux.zig
Fixes #9707
2021-10-30 18:32:26 +02: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
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
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
b781ef464d std.os: fix FILENO constants mapped to wrong values
yikes!
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
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
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
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
Vincent Rischmann
c0f40a5fe6 std/c: add pthread_setname_np and pthread_getname_np 2021-07-29 10:57:08 +02:00
Ryan Liptak
4ea7470417 Add inotify_rm_watch definition to c/linux.zig
Also make inotify_add_watch's pathname marked as nul-terminated
2021-07-15 10:54:05 +03:00
Andrew Kelley
8861ee18f7 std: add android __SIZEOF_PTHREAD_MUTEX_T
closes #8384
2021-05-18 21:08:41 -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