authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-18 23:35:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-19 00:30:32-07:00
loge8c4e79499fbb2a83a0f4fe2cac0d80e5d12a07e
treefa8018ad4597f8f51ce760c34822ad50e9a7157c
parent16604a93b9159fafec3528457366ca146bf29ce5

std.c reorganization

It is now composed of these main sections: * Declarations that are shared among all operating systems. * Declarations that have the same name, but different type signatures depending on the operating system. Often multiple operating systems share the same type signatures however. * Declarations that are specific to a single operating system. - These are imported one per line so you can see where they come from, protected by a comptime block to prevent accessing the wrong one. Closes #19352 by changing the convention to making types `void` and functions `{}`, so that it becomes possible to update `@hasDecl` sites to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up removing some duplicate logic and update some bitrotted feature detection checks. A handful of types have been modified to gain namespacing and type safety. This is a breaking change. Oh, and the last usage of `usingnamespace` site is eliminated.

48 files changed, 9874 insertions(+), 11655 deletions(-)

CMakeLists.txt-1
......@@ -404,7 +404,6 @@ set(ZIG_STAGE2_SOURCES
404404 lib/std/buf_map.zig
405405 lib/std/builtin.zig
406406 lib/std/c.zig
407 lib/std/c/linux.zig
408407 lib/std/coff.zig
409408 lib/std/crypto.zig
410409 lib/std/crypto/blake3.zig
lib/std/Progress.zig+6-6
......@@ -1349,16 +1349,16 @@ fn maybeUpdateSize(resize_flag: bool) void {
13491349 }
13501350 } else {
13511351 var winsize: posix.winsize = .{
1352 .ws_row = 0,
1353 .ws_col = 0,
1354 .ws_xpixel = 0,
1355 .ws_ypixel = 0,
1352 .row = 0,
1353 .col = 0,
1354 .xpixel = 0,
1355 .ypixel = 0,
13561356 };
13571357
13581358 const err = posix.system.ioctl(fd, posix.T.IOCGWINSZ, @intFromPtr(&winsize));
13591359 if (posix.errno(err) == .SUCCESS) {
1360 global_progress.rows = winsize.ws_row;
1361 global_progress.cols = winsize.ws_col;
1360 global_progress.rows = winsize.row;
1361 global_progress.cols = winsize.col;
13621362 } else {
13631363 std.log.debug("failed to determine terminal size; using conservative guess 80x25", .{});
13641364 global_progress.rows = 25;
lib/std/Thread/Futex.zig+28-24
......@@ -196,7 +196,10 @@ const DarwinImpl = struct {
196196 var timeout_overflowed = false;
197197
198198 const addr: *const anyopaque = ptr;
199 const flags = c.UL_COMPARE_AND_WAIT | c.ULF_NO_ERRNO;
199 const flags: c.UL = .{
200 .op = .COMPARE_AND_WAIT,
201 .NO_ERRNO = true,
202 };
200203 const status = blk: {
201204 if (supports_ulock_wait2) {
202205 break :blk c.__ulock_wait2(flags, addr, expect, timeout_ns, 0);
......@@ -228,10 +231,11 @@ const DarwinImpl = struct {
228231 }
229232
230233 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
231 var flags: u32 = c.UL_COMPARE_AND_WAIT | c.ULF_NO_ERRNO;
232 if (max_waiters > 1) {
233 flags |= c.ULF_WAKE_ALL;
234 }
234 const flags: c.UL = .{
235 .op = .COMPARE_AND_WAIT,
236 .NO_ERRNO = true,
237 .WAKE_ALL = max_waiters > 1,
238 };
235239
236240 while (true) {
237241 const addr: *const anyopaque = ptr;
......@@ -242,7 +246,7 @@ const DarwinImpl = struct {
242246 .INTR => continue, // spurious wake()
243247 .FAULT => unreachable, // __ulock_wake doesn't generate EFAULT according to darwin pthread_cond_t
244248 .NOENT => return, // nothing was woken up
245 .ALREADY => unreachable, // only for ULF_WAKE_THREAD
249 .ALREADY => unreachable, // only for UL.Op.WAKE_THREAD
246250 else => unreachable,
247251 }
248252 }
......@@ -254,8 +258,8 @@ const LinuxImpl = struct {
254258 fn wait(ptr: *const atomic.Value(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
255259 var ts: linux.timespec = undefined;
256260 if (timeout) |timeout_ns| {
257 ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
258 ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
261 ts.sec = @as(@TypeOf(ts.sec), @intCast(timeout_ns / std.time.ns_per_s));
262 ts.nsec = @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
259263 }
260264
261265 const rc = linux.futex_wait(
......@@ -306,10 +310,10 @@ const FreebsdImpl = struct {
306310 tm_ptr = &tm;
307311 tm_size = @sizeOf(@TypeOf(tm));
308312
309 tm._flags = 0; // use relative time not UMTX_ABSTIME
310 tm._clockid = c.CLOCK.MONOTONIC;
311 tm._timeout.tv_sec = @as(@TypeOf(tm._timeout.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
312 tm._timeout.tv_nsec = @as(@TypeOf(tm._timeout.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
313 tm.flags = 0; // use relative time not UMTX_ABSTIME
314 tm.clockid = .MONOTONIC;
315 tm.timeout.sec = @as(@TypeOf(tm.timeout.sec), @intCast(timeout_ns / std.time.ns_per_s));
316 tm.timeout.nsec = @as(@TypeOf(tm.timeout.nsec), @intCast(timeout_ns % std.time.ns_per_s));
313317 }
314318
315319 const rc = c._umtx_op(
......@@ -356,16 +360,16 @@ const OpenbsdImpl = struct {
356360 fn wait(ptr: *const atomic.Value(u32), expect: u32, timeout: ?u64) error{Timeout}!void {
357361 var ts: c.timespec = undefined;
358362 if (timeout) |timeout_ns| {
359 ts.tv_sec = @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
360 ts.tv_nsec = @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
363 ts.sec = @as(@TypeOf(ts.sec), @intCast(timeout_ns / std.time.ns_per_s));
364 ts.nsec = @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
361365 }
362366
363367 const rc = c.futex(
364368 @as(*const volatile u32, @ptrCast(&ptr.raw)),
365 c.FUTEX_WAIT | c.FUTEX_PRIVATE_FLAG,
369 c.FUTEX.WAIT | c.FUTEX.PRIVATE_FLAG,
366370 @as(c_int, @bitCast(expect)),
367371 if (timeout != null) &ts else null,
368 null, // FUTEX_WAIT takes no requeue address
372 null, // FUTEX.WAIT takes no requeue address
369373 );
370374
371375 switch (std.posix.errno(rc)) {
......@@ -387,10 +391,10 @@ const OpenbsdImpl = struct {
387391 fn wake(ptr: *const atomic.Value(u32), max_waiters: u32) void {
388392 const rc = c.futex(
389393 @as(*const volatile u32, @ptrCast(&ptr.raw)),
390 c.FUTEX_WAKE | c.FUTEX_PRIVATE_FLAG,
394 c.FUTEX.WAKE | c.FUTEX.PRIVATE_FLAG,
391395 std.math.cast(c_int, max_waiters) orelse std.math.maxInt(c_int),
392 null, // FUTEX_WAKE takes no timeout ptr
393 null, // FUTEX_WAKE takes no requeue address
396 null, // FUTEX.WAKE takes no timeout ptr
397 null, // FUTEX.WAKE takes no requeue address
394398 );
395399
396400 // returns number of threads woken up.
......@@ -540,12 +544,12 @@ const PosixImpl = struct {
540544 var ts: c.timespec = undefined;
541545 if (timeout) |timeout_ns| {
542546 std.posix.clock_gettime(c.CLOCK.REALTIME, &ts) catch unreachable;
543 ts.tv_sec +|= @as(@TypeOf(ts.tv_sec), @intCast(timeout_ns / std.time.ns_per_s));
544 ts.tv_nsec += @as(@TypeOf(ts.tv_nsec), @intCast(timeout_ns % std.time.ns_per_s));
547 ts.sec +|= @as(@TypeOf(ts.sec), @intCast(timeout_ns / std.time.ns_per_s));
548 ts.nsec += @as(@TypeOf(ts.nsec), @intCast(timeout_ns % std.time.ns_per_s));
545549
546 if (ts.tv_nsec >= std.time.ns_per_s) {
547 ts.tv_sec +|= 1;
548 ts.tv_nsec -= std.time.ns_per_s;
550 if (ts.nsec >= std.time.ns_per_s) {
551 ts.sec +|= 1;
552 ts.nsec -= std.time.ns_per_s;
549553 }
550554 }
551555
lib/std/Thread/Mutex.zig+3-3
......@@ -103,8 +103,8 @@ const SingleThreadedImpl = struct {
103103 }
104104};
105105
106// SRWLOCK on windows is almost always faster than Futex solution.
107// It also implements an efficient Condition with requeue support for us.
106/// SRWLOCK on windows is almost always faster than Futex solution.
107/// It also implements an efficient Condition with requeue support for us.
108108const WindowsImpl = struct {
109109 srwlock: windows.SRWLOCK = .{},
110110
......@@ -123,7 +123,7 @@ const WindowsImpl = struct {
123123 const windows = std.os.windows;
124124};
125125
126// os_unfair_lock on darwin supports priority inheritance and is generally faster than Futex solutions.
126/// os_unfair_lock on darwin supports priority inheritance and is generally faster than Futex solutions.
127127const DarwinImpl = struct {
128128 oul: c.os_unfair_lock = .{},
129129
lib/std/c.zig+7957-218
......@@ -1,14 +1,43 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const c = @This();
4const maxInt = std.math.maxInt;
5const assert = std.debug.assert;
46const page_size = std.mem.page_size;
57const iovec = std.posix.iovec;
68const iovec_const = std.posix.iovec_const;
7const wasi = @import("c/wasi.zig");
9const winsize = std.posix.winsize;
810const native_abi = builtin.abi;
911const native_arch = builtin.cpu.arch;
1012const native_os = builtin.os.tag;
1113const linux = std.os.linux;
14const emscripten = std.os.emscripten;
15const wasi = std.os.wasi;
16const windows = std.os.windows;
17const ws2_32 = std.os.windows.ws2_32;
18const darwin = @import("c/darwin.zig");
19const freebsd = @import("c/freebsd.zig");
20const solaris = @import("c/solaris.zig");
21const netbsd = @import("c/netbsd.zig");
22const dragonfly = @import("c/dragonfly.zig");
23const haiku = @import("c/haiku.zig");
24const openbsd = @import("c/openbsd.zig");
25
26/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address
27/// of the mach header in a Mach-O executable file type. It does not appear in
28/// any file type other than a MH_EXECUTE file type. The type of the symbol is
29/// absolute as the header is not part of any section.
30/// This symbol is populated when linking the system's libc, which is guaranteed
31/// on this operating system. However when building object files or libraries,
32/// the system libc won't be linked until the final executable. So we
33/// export a weak symbol here, to be overridden by the real one.
34pub extern var _mh_execute_header: mach_hdr;
35var dummy_execute_header: mach_hdr = undefined;
36comptime {
37 if (native_os.isDarwin()) {
38 @export(dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .weak });
39 }
40}
1241
1342/// If not linking libc, returns false.
1443/// If linking musl libc, returns true.
......@@ -26,25 +55,6572 @@ pub inline fn versionCheck(comptime glibc_version: std.SemanticVersion) bool {
2655 .gt, .eq => true,
2756 .lt => false,
2857 };
29 } else {
30 break :blk false;
58 } else {
59 break :blk false;
60 }
61 };
62}
63
64pub const ino_t = switch (native_os) {
65 .linux => linux.ino_t,
66 .emscripten => emscripten.ino_t,
67 .wasi => wasi.inode_t,
68 .windows => windows.LARGE_INTEGER,
69 .haiku => i64,
70 else => u64,
71};
72
73pub const off_t = switch (native_os) {
74 .linux => linux.off_t,
75 .emscripten => emscripten.off_t,
76 else => i64,
77};
78
79pub const timespec = switch (native_os) {
80 .linux => linux.timespec,
81 .emscripten => emscripten.timespec,
82 .wasi => extern struct {
83 sec: time_t,
84 nsec: isize,
85
86 pub fn fromTimestamp(tm: wasi.timestamp_t) timespec {
87 const sec: wasi.timestamp_t = tm / 1_000_000_000;
88 const nsec = tm - sec * 1_000_000_000;
89 return .{
90 .sec = @as(time_t, @intCast(sec)),
91 .nsec = @as(isize, @intCast(nsec)),
92 };
93 }
94
95 pub fn toTimestamp(ts: timespec) wasi.timestamp_t {
96 return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) +
97 @as(wasi.timestamp_t, @intCast(ts.nsec));
98 }
99 },
100 .windows => extern struct {
101 sec: time_t,
102 nsec: c_long,
103 },
104 .dragonfly, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
105 sec: isize,
106 nsec: isize,
107 },
108 .netbsd, .solaris, .illumos => extern struct {
109 sec: i64,
110 nsec: isize,
111 },
112 .openbsd, .haiku => extern struct {
113 sec: time_t,
114 nsec: isize,
115 },
116 else => void,
117};
118
119pub const dev_t = switch (native_os) {
120 .linux => linux.dev_t,
121 .emscripten => emscripten.dev_t,
122 .wasi => wasi.device_t,
123 .openbsd, .haiku, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => i32,
124 .netbsd, .freebsd, .kfreebsd => u64,
125 else => void,
126};
127
128pub const mode_t = switch (native_os) {
129 .linux => linux.mode_t,
130 .emscripten => emscripten.mode_t,
131 .openbsd, .haiku, .netbsd, .solaris, .illumos, .wasi => u32,
132 .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => u16,
133 else => u0,
134};
135
136pub const nlink_t = switch (native_os) {
137 .linux => linux.nlink_t,
138 .emscripten => emscripten.nlink_t,
139 .wasi => c_ulonglong,
140 .freebsd, .kfreebsd => u64,
141 .openbsd, .netbsd, .solaris, .illumos => u32,
142 .haiku => i32,
143 else => void,
144};
145
146pub const uid_t = switch (native_os) {
147 .linux => linux.uid_t,
148 .emscripten => emscripten.uid_t,
149 else => u32,
150};
151
152pub const gid_t = switch (native_os) {
153 .linux => linux.gid_t,
154 .emscripten => emscripten.gid_t,
155 else => u32,
156};
157
158pub const blksize_t = switch (native_os) {
159 .linux => linux.blksize_t,
160 .emscripten => emscripten.blksize_t,
161 .wasi => c_long,
162 else => i32,
163};
164
165pub const passwd = switch (native_os) {
166 .linux => extern struct {
167 name: ?[*:0]const u8, // username
168 passwd: ?[*:0]const u8, // user password
169 uid: uid_t, // user ID
170 gid: gid_t, // group ID
171 gecos: ?[*:0]const u8, // user information
172 dir: ?[*:0]const u8, // home directory
173 shell: ?[*:0]const u8, // shell program
174 },
175 .openbsd => extern struct {
176 name: ?[*:0]const u8, // user name
177 passwd: ?[*:0]const u8, // encrypted password
178 uid: uid_t, // user uid
179 gid: gid_t, // user gid
180 change: time_t, // password change time
181 class: ?[*:0]const u8, // user access class
182 gecos: ?[*:0]const u8, // Honeywell login info
183 dir: ?[*:0]const u8, // home directory
184 shell: ?[*:0]const u8, // default shell
185 expire: time_t, // account expiration
186 },
187 else => void,
188};
189
190pub const blkcnt_t = switch (native_os) {
191 .linux => linux.blkcnt_t,
192 .emscripten => emscripten.blkcnt_t,
193 .wasi => c_longlong,
194 else => i64,
195};
196
197pub const fd_t = switch (native_os) {
198 .linux => linux.fd_t,
199 .wasi => wasi.fd_t,
200 .windows => windows.HANDLE,
201 else => i32,
202};
203
204pub const ARCH = switch (native_os) {
205 .linux => linux.ARCH,
206 else => void,
207};
208pub const CLOCK = clockid_t;
209pub const clockid_t = switch (native_os) {
210 .linux, .emscripten => linux.clockid_t,
211 .wasi => wasi.clockid_t,
212 .macos, .ios, .tvos, .watchos, .visionos => enum(u32) {
213 REALTIME = 0,
214 MONOTONIC = 6,
215 MONOTONIC_RAW = 4,
216 MONOTONIC_RAW_APPROX = 5,
217 UPTIME_RAW = 8,
218 UPTIME_RAW_APPROX = 9,
219 PROCESS_CPUTIME_ID = 12,
220 THREAD_CPUTIME_ID = 16,
221 _,
222 },
223 .haiku => enum(i32) {
224 /// system-wide monotonic clock (aka system time)
225 MONOTONIC = 0,
226 /// system-wide real time clock
227 REALTIME = -1,
228 /// clock measuring the used CPU time of the current process
229 PROCESS_CPUTIME_ID = -2,
230 /// clock measuring the used CPU time of the current thread
231 THREAD_CPUTIME_ID = -3,
232 },
233 .freebsd, .kfreebsd => enum(u32) {
234 REALTIME = 0,
235 VIRTUAL = 1,
236 PROF = 2,
237 MONOTONIC = 4,
238 UPTIME = 5,
239 UPTIME_PRECISE = 7,
240 UPTIME_FAST = 8,
241 REALTIME_PRECISE = 9,
242 REALTIME_FAST = 10,
243 MONOTONIC_PRECISE = 11,
244 MONOTONIC_FAST = 12,
245 SECOND = 13,
246 THREAD_CPUTIME_ID = 14,
247 PROCESS_CPUTIME_ID = 15,
248 },
249 .solaris, .illumos => enum(u32) {
250 VIRTUAL = 1,
251 THREAD_CPUTIME_ID = 2,
252 REALTIME = 3,
253 MONOTONIC = 4,
254 PROCESS_CPUTIME_ID = 5,
255 },
256 .netbsd => enum(u32) {
257 REALTIME = 0,
258 VIRTUAL = 1,
259 PROF = 2,
260 MONOTONIC = 3,
261 THREAD_CPUTIME_ID = 0x20000000,
262 PROCESS_CPUTIME_ID = 0x40000000,
263 },
264 .dragonfly => enum(u32) {
265 REALTIME = 0,
266 VIRTUAL = 1,
267 PROF = 2,
268 MONOTONIC = 4,
269 UPTIME = 5,
270 UPTIME_PRECISE = 7,
271 UPTIME_FAST = 8,
272 REALTIME_PRECISE = 9,
273 REALTIME_FAST = 10,
274 MONOTONIC_PRECISE = 11,
275 MONOTONIC_FAST = 12,
276 SECOND = 13,
277 THREAD_CPUTIME_ID = 14,
278 PROCESS_CPUTIME_ID = 15,
279 },
280 .openbsd => enum(u32) {
281 REALTIME = 0,
282 PROCESS_CPUTIME_ID = 2,
283 MONOTONIC = 3,
284 THREAD_CPUTIME_ID = 4,
285 },
286 else => void,
287};
288pub const CPU_COUNT = switch (native_os) {
289 .linux => linux.CPU_COUNT,
290 .emscripten => emscripten.CPU_COUNT,
291 else => void,
292};
293pub const E = switch (native_os) {
294 .linux => linux.E,
295 .emscripten => emscripten.E,
296 .wasi => wasi.errno_t,
297 .windows => enum(u16) {
298 /// No error occurred.
299 SUCCESS = 0,
300 PERM = 1,
301 NOENT = 2,
302 SRCH = 3,
303 INTR = 4,
304 IO = 5,
305 NXIO = 6,
306 @"2BIG" = 7,
307 NOEXEC = 8,
308 BADF = 9,
309 CHILD = 10,
310 AGAIN = 11,
311 NOMEM = 12,
312 ACCES = 13,
313 FAULT = 14,
314 BUSY = 16,
315 EXIST = 17,
316 XDEV = 18,
317 NODEV = 19,
318 NOTDIR = 20,
319 ISDIR = 21,
320 NFILE = 23,
321 MFILE = 24,
322 NOTTY = 25,
323 FBIG = 27,
324 NOSPC = 28,
325 SPIPE = 29,
326 ROFS = 30,
327 MLINK = 31,
328 PIPE = 32,
329 DOM = 33,
330 /// Also means `DEADLOCK`.
331 DEADLK = 36,
332 NAMETOOLONG = 38,
333 NOLCK = 39,
334 NOSYS = 40,
335 NOTEMPTY = 41,
336
337 INVAL = 22,
338 RANGE = 34,
339 ILSEQ = 42,
340
341 // POSIX Supplement
342 ADDRINUSE = 100,
343 ADDRNOTAVAIL = 101,
344 AFNOSUPPORT = 102,
345 ALREADY = 103,
346 BADMSG = 104,
347 CANCELED = 105,
348 CONNABORTED = 106,
349 CONNREFUSED = 107,
350 CONNRESET = 108,
351 DESTADDRREQ = 109,
352 HOSTUNREACH = 110,
353 IDRM = 111,
354 INPROGRESS = 112,
355 ISCONN = 113,
356 LOOP = 114,
357 MSGSIZE = 115,
358 NETDOWN = 116,
359 NETRESET = 117,
360 NETUNREACH = 118,
361 NOBUFS = 119,
362 NODATA = 120,
363 NOLINK = 121,
364 NOMSG = 122,
365 NOPROTOOPT = 123,
366 NOSR = 124,
367 NOSTR = 125,
368 NOTCONN = 126,
369 NOTRECOVERABLE = 127,
370 NOTSOCK = 128,
371 NOTSUP = 129,
372 OPNOTSUPP = 130,
373 OTHER = 131,
374 OVERFLOW = 132,
375 OWNERDEAD = 133,
376 PROTO = 134,
377 PROTONOSUPPORT = 135,
378 PROTOTYPE = 136,
379 TIME = 137,
380 TIMEDOUT = 138,
381 TXTBSY = 139,
382 WOULDBLOCK = 140,
383 DQUOT = 10069,
384 _,
385 },
386 .macos, .ios, .tvos, .watchos, .visionos => darwin.E,
387 .freebsd, .kfreebsd => freebsd.E,
388 .solaris, .illumos => enum(u16) {
389 /// No error occurred.
390 SUCCESS = 0,
391 /// Not super-user
392 PERM = 1,
393 /// No such file or directory
394 NOENT = 2,
395 /// No such process
396 SRCH = 3,
397 /// interrupted system call
398 INTR = 4,
399 /// I/O error
400 IO = 5,
401 /// No such device or address
402 NXIO = 6,
403 /// Arg list too long
404 @"2BIG" = 7,
405 /// Exec format error
406 NOEXEC = 8,
407 /// Bad file number
408 BADF = 9,
409 /// No children
410 CHILD = 10,
411 /// Resource temporarily unavailable.
412 /// also: WOULDBLOCK: Operation would block.
413 AGAIN = 11,
414 /// Not enough core
415 NOMEM = 12,
416 /// Permission denied
417 ACCES = 13,
418 /// Bad address
419 FAULT = 14,
420 /// Block device required
421 NOTBLK = 15,
422 /// Mount device busy
423 BUSY = 16,
424 /// File exists
425 EXIST = 17,
426 /// Cross-device link
427 XDEV = 18,
428 /// No such device
429 NODEV = 19,
430 /// Not a directory
431 NOTDIR = 20,
432 /// Is a directory
433 ISDIR = 21,
434 /// Invalid argument
435 INVAL = 22,
436 /// File table overflow
437 NFILE = 23,
438 /// Too many open files
439 MFILE = 24,
440 /// Inappropriate ioctl for device
441 NOTTY = 25,
442 /// Text file busy
443 TXTBSY = 26,
444 /// File too large
445 FBIG = 27,
446 /// No space left on device
447 NOSPC = 28,
448 /// Illegal seek
449 SPIPE = 29,
450 /// Read only file system
451 ROFS = 30,
452 /// Too many links
453 MLINK = 31,
454 /// Broken pipe
455 PIPE = 32,
456 /// Math arg out of domain of func
457 DOM = 33,
458 /// Math result not representable
459 RANGE = 34,
460 /// No message of desired type
461 NOMSG = 35,
462 /// Identifier removed
463 IDRM = 36,
464 /// Channel number out of range
465 CHRNG = 37,
466 /// Level 2 not synchronized
467 L2NSYNC = 38,
468 /// Level 3 halted
469 L3HLT = 39,
470 /// Level 3 reset
471 L3RST = 40,
472 /// Link number out of range
473 LNRNG = 41,
474 /// Protocol driver not attached
475 UNATCH = 42,
476 /// No CSI structure available
477 NOCSI = 43,
478 /// Level 2 halted
479 L2HLT = 44,
480 /// Deadlock condition.
481 DEADLK = 45,
482 /// No record locks available.
483 NOLCK = 46,
484 /// Operation canceled
485 CANCELED = 47,
486 /// Operation not supported
487 NOTSUP = 48,
488
489 // Filesystem Quotas
490 /// Disc quota exceeded
491 DQUOT = 49,
492
493 // Convergent Error Returns
494 /// invalid exchange
495 BADE = 50,
496 /// invalid request descriptor
497 BADR = 51,
498 /// exchange full
499 XFULL = 52,
500 /// no anode
501 NOANO = 53,
502 /// invalid request code
503 BADRQC = 54,
504 /// invalid slot
505 BADSLT = 55,
506 /// file locking deadlock error
507 DEADLOCK = 56,
508 /// bad font file fmt
509 BFONT = 57,
510
511 // Interprocess Robust Locks
512 /// process died with the lock
513 OWNERDEAD = 58,
514 /// lock is not recoverable
515 NOTRECOVERABLE = 59,
516 /// locked lock was unmapped
517 LOCKUNMAPPED = 72,
518 /// Facility is not active
519 NOTACTIVE = 73,
520 /// multihop attempted
521 MULTIHOP = 74,
522 /// trying to read unreadable message
523 BADMSG = 77,
524 /// path name is too long
525 NAMETOOLONG = 78,
526 /// value too large to be stored in data type
527 OVERFLOW = 79,
528 /// given log. name not unique
529 NOTUNIQ = 80,
530 /// f.d. invalid for this operation
531 BADFD = 81,
532 /// Remote address changed
533 REMCHG = 82,
534
535 // Stream Problems
536 /// Device not a stream
537 NOSTR = 60,
538 /// no data (for no delay io)
539 NODATA = 61,
540 /// timer expired
541 TIME = 62,
542 /// out of streams resources
543 NOSR = 63,
544 /// Machine is not on the network
545 NONET = 64,
546 /// Package not installed
547 NOPKG = 65,
548 /// The object is remote
549 REMOTE = 66,
550 /// the link has been severed
551 NOLINK = 67,
552 /// advertise error
553 ADV = 68,
554 /// srmount error
555 SRMNT = 69,
556 /// Communication error on send
557 COMM = 70,
558 /// Protocol error
559 PROTO = 71,
560
561 // Shared Library Problems
562 /// Can't access a needed shared lib.
563 LIBACC = 83,
564 /// Accessing a corrupted shared lib.
565 LIBBAD = 84,
566 /// .lib section in a.out corrupted.
567 LIBSCN = 85,
568 /// Attempting to link in too many libs.
569 LIBMAX = 86,
570 /// Attempting to exec a shared library.
571 LIBEXEC = 87,
572 /// Illegal byte sequence.
573 ILSEQ = 88,
574 /// Unsupported file system operation
575 NOSYS = 89,
576 /// Symbolic link loop
577 LOOP = 90,
578 /// Restartable system call
579 RESTART = 91,
580 /// if pipe/FIFO, don't sleep in stream head
581 STRPIPE = 92,
582 /// directory not empty
583 NOTEMPTY = 93,
584 /// Too many users (for UFS)
585 USERS = 94,
586
587 // BSD Networking Software
588 // Argument Errors
589 /// Socket operation on non-socket
590 NOTSOCK = 95,
591 /// Destination address required
592 DESTADDRREQ = 96,
593 /// Message too long
594 MSGSIZE = 97,
595 /// Protocol wrong type for socket
596 PROTOTYPE = 98,
597 /// Protocol not available
598 NOPROTOOPT = 99,
599 /// Protocol not supported
600 PROTONOSUPPORT = 120,
601 /// Socket type not supported
602 SOCKTNOSUPPORT = 121,
603 /// Operation not supported on socket
604 OPNOTSUPP = 122,
605 /// Protocol family not supported
606 PFNOSUPPORT = 123,
607 /// Address family not supported by
608 AFNOSUPPORT = 124,
609 /// Address already in use
610 ADDRINUSE = 125,
611 /// Can't assign requested address
612 ADDRNOTAVAIL = 126,
613
614 // Operational Errors
615 /// Network is down
616 NETDOWN = 127,
617 /// Network is unreachable
618 NETUNREACH = 128,
619 /// Network dropped connection because
620 NETRESET = 129,
621 /// Software caused connection abort
622 CONNABORTED = 130,
623 /// Connection reset by peer
624 CONNRESET = 131,
625 /// No buffer space available
626 NOBUFS = 132,
627 /// Socket is already connected
628 ISCONN = 133,
629 /// Socket is not connected
630 NOTCONN = 134,
631 /// Can't send after socket shutdown
632 SHUTDOWN = 143,
633 /// Too many references: can't splice
634 TOOMANYREFS = 144,
635 /// Connection timed out
636 TIMEDOUT = 145,
637 /// Connection refused
638 CONNREFUSED = 146,
639 /// Host is down
640 HOSTDOWN = 147,
641 /// No route to host
642 HOSTUNREACH = 148,
643 /// operation already in progress
644 ALREADY = 149,
645 /// operation now in progress
646 INPROGRESS = 150,
647
648 // SUN Network File System
649 /// Stale NFS file handle
650 STALE = 151,
651
652 _,
653 },
654 .netbsd => netbsd.E,
655 .dragonfly => dragonfly.E,
656 .haiku => haiku.E,
657 .openbsd => openbsd.E,
658 else => void,
659};
660pub const Elf_Symndx = switch (native_os) {
661 .linux => linux.Elf_Symndx,
662 else => void,
663};
664/// Command flags for fcntl(2).
665pub const F = switch (native_os) {
666 .linux => linux.F,
667 .emscripten => emscripten.F,
668 .wasi => struct {
669 pub const GETFD = 1;
670 pub const SETFD = 2;
671 pub const GETFL = 3;
672 pub const SETFL = 4;
673 },
674 .macos, .ios, .tvos, .watchos, .visionos => struct {
675 /// duplicate file descriptor
676 pub const DUPFD = 0;
677 /// get file descriptor flags
678 pub const GETFD = 1;
679 /// set file descriptor flags
680 pub const SETFD = 2;
681 /// get file status flags
682 pub const GETFL = 3;
683 /// set file status flags
684 pub const SETFL = 4;
685 /// get SIGIO/SIGURG proc/pgrp
686 pub const GETOWN = 5;
687 /// set SIGIO/SIGURG proc/pgrp
688 pub const SETOWN = 6;
689 /// get record locking information
690 pub const GETLK = 7;
691 /// set record locking information
692 pub const SETLK = 8;
693 /// F.SETLK; wait if blocked
694 pub const SETLKW = 9;
695 /// F.SETLK; wait if blocked, return on timeout
696 pub const SETLKWTIMEOUT = 10;
697 pub const FLUSH_DATA = 40;
698 /// Used for regression test
699 pub const CHKCLEAN = 41;
700 /// Preallocate storage
701 pub const PREALLOCATE = 42;
702 /// Truncate a file without zeroing space
703 pub const SETSIZE = 43;
704 /// Issue an advisory read async with no copy to user
705 pub const RDADVISE = 44;
706 /// turn read ahead off/on for this fd
707 pub const RDAHEAD = 45;
708 /// turn data caching off/on for this fd
709 pub const NOCACHE = 48;
710 /// file offset to device offset
711 pub const LOG2PHYS = 49;
712 /// return the full path of the fd
713 pub const GETPATH = 50;
714 /// fsync + ask the drive to flush to the media
715 pub const FULLFSYNC = 51;
716 /// find which component (if any) is a package
717 pub const PATHPKG_CHECK = 52;
718 /// "freeze" all fs operations
719 pub const FREEZE_FS = 53;
720 /// "thaw" all fs operations
721 pub const THAW_FS = 54;
722 /// turn data caching off/on (globally) for this file
723 pub const GLOBAL_NOCACHE = 55;
724 /// add detached signatures
725 pub const ADDSIGS = 59;
726 /// add signature from same file (used by dyld for shared libs)
727 pub const ADDFILESIGS = 61;
728 /// used in conjunction with F.NOCACHE to indicate that DIRECT, synchronous writes
729 /// should not be used (i.e. its ok to temporarily create cached pages)
730 pub const NODIRECT = 62;
731 ///Get the protection class of a file from the EA, returns int
732 pub const GETPROTECTIONCLASS = 63;
733 ///Set the protection class of a file for the EA, requires int
734 pub const SETPROTECTIONCLASS = 64;
735 ///file offset to device offset, extended
736 pub const LOG2PHYS_EXT = 65;
737 ///get record locking information, per-process
738 pub const GETLKPID = 66;
739 ///Mark the file as being the backing store for another filesystem
740 pub const SETBACKINGSTORE = 70;
741 ///return the full path of the FD, but error in specific mtmd circumstances
742 pub const GETPATH_MTMINFO = 71;
743 ///Returns the code directory, with associated hashes, to the caller
744 pub const GETCODEDIR = 72;
745 ///No SIGPIPE generated on EPIPE
746 pub const SETNOSIGPIPE = 73;
747 ///Status of SIGPIPE for this fd
748 pub const GETNOSIGPIPE = 74;
749 ///For some cases, we need to rewrap the key for AKS/MKB
750 pub const TRANSCODEKEY = 75;
751 ///file being written to a by single writer... if throttling enabled, writes
752 ///may be broken into smaller chunks with throttling in between
753 pub const SINGLE_WRITER = 76;
754 ///Get the protection version number for this filesystem
755 pub const GETPROTECTIONLEVEL = 77;
756 ///Add detached code signatures (used by dyld for shared libs)
757 pub const FINDSIGS = 78;
758 ///Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
759 pub const ADDFILESIGS_FOR_DYLD_SIM = 83;
760 ///fsync + issue barrier to drive
761 pub const BARRIERFSYNC = 85;
762 ///Add signature from same file, return end offset in structure on success
763 pub const ADDFILESIGS_RETURN = 97;
764 ///Check if Library Validation allows this Mach-O file to be mapped into the calling process
765 pub const CHECK_LV = 98;
766 ///Deallocate a range of the file
767 pub const PUNCHHOLE = 99;
768 ///Trim an active file
769 pub const TRIM_ACTIVE_FILE = 100;
770 ///mark the dup with FD_CLOEXEC
771 pub const DUPFD_CLOEXEC = 67;
772 /// shared or read lock
773 pub const RDLCK = 1;
774 /// unlock
775 pub const UNLCK = 2;
776 /// exclusive or write lock
777 pub const WRLCK = 3;
778 },
779 .freebsd, .kfreebsd => struct {
780 /// Duplicate file descriptor.
781 pub const DUPFD = 0;
782 /// Get file descriptor flags.
783 pub const GETFD = 1;
784 /// Set file descriptor flags.
785 pub const SETFD = 2;
786 /// Get file status flags.
787 pub const GETFL = 3;
788 /// Set file status flags.
789 pub const SETFL = 4;
790
791 /// Get SIGIO/SIGURG proc/pgrrp.
792 pub const GETOWN = 5;
793 /// Set SIGIO/SIGURG proc/pgrrp.
794 pub const SETOWN = 6;
795
796 /// Get record locking information.
797 pub const GETLK = 11;
798 /// Set record locking information.
799 pub const SETLK = 12;
800 /// Set record locking information and wait if blocked.
801 pub const SETLKW = 13;
802
803 /// Debugging support for remote locks.
804 pub const SETLK_REMOTE = 14;
805 /// Read ahead.
806 pub const READAHEAD = 15;
807
808 /// DUPFD with FD_CLOEXEC set.
809 pub const DUPFD_CLOEXEC = 17;
810 /// DUP2FD with FD_CLOEXEC set.
811 pub const DUP2FD_CLOEXEC = 18;
812
813 pub const ADD_SEALS = 19;
814 pub const GET_SEALS = 20;
815 /// Return `kinfo_file` for a file descriptor.
816 pub const KINFO = 22;
817
818 // Seals (ADD_SEALS, GET_SEALS)
819 /// Prevent adding sealings.
820 pub const SEAL_SEAL = 0x0001;
821 /// May not shrink
822 pub const SEAL_SHRINK = 0x0002;
823 /// May not grow.
824 pub const SEAL_GROW = 0x0004;
825 /// May not write.
826 pub const SEAL_WRITE = 0x0008;
827
828 // Record locking flags (GETLK, SETLK, SETLKW).
829 /// Shared or read lock.
830 pub const RDLCK = 1;
831 /// Unlock.
832 pub const UNLCK = 2;
833 /// Exclusive or write lock.
834 pub const WRLCK = 3;
835 /// Purge locks for a given system ID.
836 pub const UNLCKSYS = 4;
837 /// Cancel an async lock request.
838 pub const CANCEL = 5;
839
840 pub const SETOWN_EX = 15;
841 pub const GETOWN_EX = 16;
842
843 pub const GETOWNER_UIDS = 17;
844 },
845 .solaris, .illumos => struct {
846 /// Unlock a previously locked region
847 pub const ULOCK = 0;
848 /// Lock a region for exclusive use
849 pub const LOCK = 1;
850 /// Test and lock a region for exclusive use
851 pub const TLOCK = 2;
852 /// Test a region for other processes locks
853 pub const TEST = 3;
854
855 /// Duplicate fildes
856 pub const DUPFD = 0;
857 /// Get fildes flags
858 pub const GETFD = 1;
859 /// Set fildes flags
860 pub const SETFD = 2;
861 /// Get file flags
862 pub const GETFL = 3;
863 /// Get file flags including open-only flags
864 pub const GETXFL = 45;
865 /// Set file flags
866 pub const SETFL = 4;
867
868 /// Unused
869 pub const CHKFL = 8;
870 /// Duplicate fildes at third arg
871 pub const DUP2FD = 9;
872 /// Like DUP2FD with O_CLOEXEC set EINVAL is fildes matches arg1
873 pub const DUP2FD_CLOEXEC = 36;
874 /// Like DUPFD with O_CLOEXEC set
875 pub const DUPFD_CLOEXEC = 37;
876
877 /// Is the file desc. a stream ?
878 pub const ISSTREAM = 13;
879 /// Turn on private access to file
880 pub const PRIV = 15;
881 /// Turn off private access to file
882 pub const NPRIV = 16;
883 /// UFS quota call
884 pub const QUOTACTL = 17;
885 /// Get number of BLKSIZE blocks allocated
886 pub const BLOCKS = 18;
887 /// Get optimal I/O block size
888 pub const BLKSIZE = 19;
889 /// Get owner (socket emulation)
890 pub const GETOWN = 23;
891 /// Set owner (socket emulation)
892 pub const SETOWN = 24;
893 /// Object reuse revoke access to file desc.
894 pub const REVOKE = 25;
895 /// Does vp have NFS locks private to lock manager
896 pub const HASREMOTELOCKS = 26;
897
898 /// Set file lock
899 pub const SETLK = 6;
900 /// Set file lock and wait
901 pub const SETLKW = 7;
902 /// Allocate file space
903 pub const ALLOCSP = 10;
904 /// Free file space
905 pub const FREESP = 11;
906 /// Get file lock
907 pub const GETLK = 14;
908 /// Get file lock owned by file
909 pub const OFD_GETLK = 47;
910 /// Set file lock owned by file
911 pub const OFD_SETLK = 48;
912 /// Set file lock owned by file and wait
913 pub const OFD_SETLKW = 49;
914 /// Set a file share reservation
915 pub const SHARE = 40;
916 /// Remove a file share reservation
917 pub const UNSHARE = 41;
918 /// Create Poison FD
919 pub const BADFD = 46;
920
921 /// Read lock
922 pub const RDLCK = 1;
923 /// Write lock
924 pub const WRLCK = 2;
925 /// Remove lock(s)
926 pub const UNLCK = 3;
927 /// remove remote locks for a given system
928 pub const UNLKSYS = 4;
929
930 // f_access values
931 /// Read-only share access
932 pub const RDACC = 0x1;
933 /// Write-only share access
934 pub const WRACC = 0x2;
935 /// Read-Write share access
936 pub const RWACC = 0x3;
937
938 // f_deny values
939 /// Don't deny others access
940 pub const NODNY = 0x0;
941 /// Deny others read share access
942 pub const RDDNY = 0x1;
943 /// Deny others write share access
944 pub const WRDNY = 0x2;
945 /// Deny others read or write share access
946 pub const RWDNY = 0x3;
947 /// private flag: Deny delete share access
948 pub const RMDNY = 0x4;
949 },
950 .netbsd => struct {
951 pub const DUPFD = 0;
952 pub const GETFD = 1;
953 pub const SETFD = 2;
954 pub const GETFL = 3;
955 pub const SETFL = 4;
956 pub const GETOWN = 5;
957 pub const SETOWN = 6;
958 pub const GETLK = 7;
959 pub const SETLK = 8;
960 pub const SETLKW = 9;
961 pub const CLOSEM = 10;
962 pub const MAXFD = 11;
963 pub const DUPFD_CLOEXEC = 12;
964 pub const GETNOSIGPIPE = 13;
965 pub const SETNOSIGPIPE = 14;
966 pub const GETPATH = 15;
967
968 pub const RDLCK = 1;
969 pub const WRLCK = 3;
970 pub const UNLCK = 2;
971 },
972 .dragonfly => struct {
973 pub const ULOCK = 0;
974 pub const LOCK = 1;
975 pub const TLOCK = 2;
976 pub const TEST = 3;
977
978 pub const DUPFD = 0;
979 pub const GETFD = 1;
980 pub const RDLCK = 1;
981 pub const SETFD = 2;
982 pub const UNLCK = 2;
983 pub const WRLCK = 3;
984 pub const GETFL = 3;
985 pub const SETFL = 4;
986 pub const GETOWN = 5;
987 pub const SETOWN = 6;
988 pub const GETLK = 7;
989 pub const SETLK = 8;
990 pub const SETLKW = 9;
991 pub const DUP2FD = 10;
992 pub const DUPFD_CLOEXEC = 17;
993 pub const DUP2FD_CLOEXEC = 18;
994 pub const GETPATH = 19;
995 },
996 .haiku => struct {
997 pub const DUPFD = 0x0001;
998 pub const GETFD = 0x0002;
999 pub const SETFD = 0x0004;
1000 pub const GETFL = 0x0008;
1001 pub const SETFL = 0x0010;
1002
1003 pub const GETLK = 0x0020;
1004 pub const SETLK = 0x0080;
1005 pub const SETLKW = 0x0100;
1006 pub const DUPFD_CLOEXEC = 0x0200;
1007
1008 pub const RDLCK = 0x0040;
1009 pub const UNLCK = 0x0200;
1010 pub const WRLCK = 0x0400;
1011 },
1012 .openbsd => struct {
1013 pub const DUPFD = 0;
1014 pub const GETFD = 1;
1015 pub const SETFD = 2;
1016 pub const GETFL = 3;
1017 pub const SETFL = 4;
1018
1019 pub const GETOWN = 5;
1020 pub const SETOWN = 6;
1021
1022 pub const GETLK = 7;
1023 pub const SETLK = 8;
1024 pub const SETLKW = 9;
1025
1026 pub const RDLCK = 1;
1027 pub const UNLCK = 2;
1028 pub const WRLCK = 3;
1029 },
1030 else => void,
1031};
1032pub const FD_CLOEXEC = switch (native_os) {
1033 .linux => linux.FD_CLOEXEC,
1034 .emscripten => emscripten.FD_CLOEXEC,
1035 else => 1,
1036};
1037
1038/// Test for existence of file.
1039pub const F_OK = switch (native_os) {
1040 .linux => linux.F_OK,
1041 .emscripten => emscripten.F_OK,
1042 else => 0,
1043};
1044/// Test for execute or search permission.
1045pub const X_OK = switch (native_os) {
1046 .linux => linux.X_OK,
1047 .emscripten => emscripten.X_OK,
1048 else => 1,
1049};
1050/// Test for write permission.
1051pub const W_OK = switch (native_os) {
1052 .linux => linux.W_OK,
1053 .emscripten => emscripten.W_OK,
1054 else => 2,
1055};
1056/// Test for read permission.
1057pub const R_OK = switch (native_os) {
1058 .linux => linux.R_OK,
1059 .emscripten => emscripten.R_OK,
1060 else => 4,
1061};
1062
1063pub const Flock = switch (native_os) {
1064 .linux => linux.Flock,
1065 .emscripten => emscripten.Flock,
1066 .openbsd, .dragonfly, .netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
1067 start: off_t,
1068 len: off_t,
1069 pid: pid_t,
1070 type: i16,
1071 whence: i16,
1072 },
1073 .freebsd, .kfreebsd => extern struct {
1074 /// Starting offset.
1075 start: off_t,
1076 /// Number of consecutive bytes to be locked.
1077 /// A value of 0 means to the end of the file.
1078 len: off_t,
1079 /// Lock owner.
1080 pid: pid_t,
1081 /// Lock type.
1082 type: i16,
1083 /// Type of the start member.
1084 whence: i16,
1085 /// Remote system id or zero for local.
1086 sysid: i32,
1087 },
1088 .solaris, .illumos => extern struct {
1089 type: c_short,
1090 whence: c_short,
1091 start: off_t,
1092 // len == 0 means until end of file.
1093 len: off_t,
1094 sysid: c_int,
1095 pid: pid_t,
1096 __pad: [4]c_long,
1097 },
1098 .haiku => extern struct {
1099 type: i16,
1100 whence: i16,
1101 start: off_t,
1102 len: off_t,
1103 pid: pid_t,
1104 },
1105 else => void,
1106};
1107pub const HOST_NAME_MAX = switch (native_os) {
1108 .linux => linux.HOST_NAME_MAX,
1109 .macos, .ios, .tvos, .watchos, .visionos => 72,
1110 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => 255,
1111 else => {},
1112};
1113pub const IOV_MAX = switch (native_os) {
1114 .linux => linux.IOV_MAX,
1115 .emscripten => emscripten.IOV_MAX,
1116 .openbsd, .haiku, .solaris, .illumos, .wasi => 1024,
1117 .macos, .ios, .tvos, .watchos, .visionos => 16,
1118 .dragonfly, .netbsd, .freebsd, .kfreebsd => KERN.IOV_MAX,
1119 else => {},
1120};
1121pub const CTL = switch (native_os) {
1122 .freebsd, .kfreebsd => struct {
1123 pub const KERN = 1;
1124 pub const DEBUG = 5;
1125 },
1126 .netbsd => struct {
1127 pub const KERN = 1;
1128 pub const DEBUG = 5;
1129 },
1130 .dragonfly => struct {
1131 pub const UNSPEC = 0;
1132 pub const KERN = 1;
1133 pub const VM = 2;
1134 pub const VFS = 3;
1135 pub const NET = 4;
1136 pub const DEBUG = 5;
1137 pub const HW = 6;
1138 pub const MACHDEP = 7;
1139 pub const USER = 8;
1140 pub const LWKT = 10;
1141 pub const MAXID = 11;
1142 pub const MAXNAME = 12;
1143 },
1144 .openbsd => struct {
1145 pub const UNSPEC = 0;
1146 pub const KERN = 1;
1147 pub const VM = 2;
1148 pub const FS = 3;
1149 pub const NET = 4;
1150 pub const DEBUG = 5;
1151 pub const HW = 6;
1152 pub const MACHDEP = 7;
1153
1154 pub const DDB = 9;
1155 pub const VFS = 10;
1156 },
1157 else => void,
1158};
1159pub const KERN = switch (native_os) {
1160 .freebsd, .kfreebsd => struct {
1161 /// struct: process entries
1162 pub const PROC = 14;
1163 /// path to executable
1164 pub const PROC_PATHNAME = 12;
1165 /// file descriptors for process
1166 pub const PROC_FILEDESC = 33;
1167 pub const IOV_MAX = 35;
1168 },
1169 .netbsd => struct {
1170 /// struct: process argv/env
1171 pub const PROC_ARGS = 48;
1172 /// path to executable
1173 pub const PROC_PATHNAME = 5;
1174 pub const IOV_MAX = 38;
1175 },
1176 .dragonfly => struct {
1177 pub const PROC_ALL = 0;
1178 pub const OSTYPE = 1;
1179 pub const PROC_PID = 1;
1180 pub const OSRELEASE = 2;
1181 pub const PROC_PGRP = 2;
1182 pub const OSREV = 3;
1183 pub const PROC_SESSION = 3;
1184 pub const VERSION = 4;
1185 pub const PROC_TTY = 4;
1186 pub const MAXVNODES = 5;
1187 pub const PROC_UID = 5;
1188 pub const MAXPROC = 6;
1189 pub const PROC_RUID = 6;
1190 pub const MAXFILES = 7;
1191 pub const PROC_ARGS = 7;
1192 pub const ARGMAX = 8;
1193 pub const PROC_CWD = 8;
1194 pub const PROC_PATHNAME = 9;
1195 pub const SECURELVL = 9;
1196 pub const PROC_SIGTRAMP = 10;
1197 pub const HOSTNAME = 10;
1198 pub const HOSTID = 11;
1199 pub const CLOCKRATE = 12;
1200 pub const VNODE = 13;
1201 pub const PROC = 14;
1202 pub const FILE = 15;
1203 pub const PROC_FLAGMASK = 16;
1204 pub const PROF = 16;
1205 pub const PROC_FLAG_LWP = 16;
1206 pub const POSIX1 = 17;
1207 pub const NGROUPS = 18;
1208 pub const JOB_CONTROL = 19;
1209 pub const SAVED_IDS = 20;
1210 pub const BOOTTIME = 21;
1211 pub const NISDOMAINNAME = 22;
1212 pub const UPDATEINTERVAL = 23;
1213 pub const OSRELDATE = 24;
1214 pub const NTP_PLL = 25;
1215 pub const BOOTFILE = 26;
1216 pub const MAXFILESPERPROC = 27;
1217 pub const MAXPROCPERUID = 28;
1218 pub const DUMPDEV = 29;
1219 pub const IPC = 30;
1220 pub const DUMMY = 31;
1221 pub const PS_STRINGS = 32;
1222 pub const USRSTACK = 33;
1223 pub const LOGSIGEXIT = 34;
1224 pub const IOV_MAX = 35;
1225 pub const MAXPOSIXLOCKSPERUID = 36;
1226 pub const MAXID = 37;
1227 },
1228 .openbsd => struct {
1229 pub const OSTYPE = 1;
1230 pub const OSRELEASE = 2;
1231 pub const OSREV = 3;
1232 pub const VERSION = 4;
1233 pub const MAXVNODES = 5;
1234 pub const MAXPROC = 6;
1235 pub const MAXFILES = 7;
1236 pub const ARGMAX = 8;
1237 pub const SECURELVL = 9;
1238 pub const HOSTNAME = 10;
1239 pub const HOSTID = 11;
1240 pub const CLOCKRATE = 12;
1241
1242 pub const PROF = 16;
1243 pub const POSIX1 = 17;
1244 pub const NGROUPS = 18;
1245 pub const JOB_CONTROL = 19;
1246 pub const SAVED_IDS = 20;
1247 pub const BOOTTIME = 21;
1248 pub const DOMAINNAME = 22;
1249 pub const MAXPARTITIONS = 23;
1250 pub const RAWPARTITION = 24;
1251 pub const MAXTHREAD = 25;
1252 pub const NTHREADS = 26;
1253 pub const OSVERSION = 27;
1254 pub const SOMAXCONN = 28;
1255 pub const SOMINCONN = 29;
1256
1257 pub const NOSUIDCOREDUMP = 32;
1258 pub const FSYNC = 33;
1259 pub const SYSVMSG = 34;
1260 pub const SYSVSEM = 35;
1261 pub const SYSVSHM = 36;
1262
1263 pub const MSGBUFSIZE = 38;
1264 pub const MALLOCSTATS = 39;
1265 pub const CPTIME = 40;
1266 pub const NCHSTATS = 41;
1267 pub const FORKSTAT = 42;
1268 pub const NSELCOLL = 43;
1269 pub const TTY = 44;
1270 pub const CCPU = 45;
1271 pub const FSCALE = 46;
1272 pub const NPROCS = 47;
1273 pub const MSGBUF = 48;
1274 pub const POOL = 49;
1275 pub const STACKGAPRANDOM = 50;
1276 pub const SYSVIPC_INFO = 51;
1277 pub const ALLOWKMEM = 52;
1278 pub const WITNESSWATCH = 53;
1279 pub const SPLASSERT = 54;
1280 pub const PROC_ARGS = 55;
1281 pub const NFILES = 56;
1282 pub const TTYCOUNT = 57;
1283 pub const NUMVNODES = 58;
1284 pub const MBSTAT = 59;
1285 pub const WITNESS = 60;
1286 pub const SEMINFO = 61;
1287 pub const SHMINFO = 62;
1288 pub const INTRCNT = 63;
1289 pub const WATCHDOG = 64;
1290 pub const ALLOWDT = 65;
1291 pub const PROC = 66;
1292 pub const MAXCLUSTERS = 67;
1293 pub const EVCOUNT = 68;
1294 pub const TIMECOUNTER = 69;
1295 pub const MAXLOCKSPERUID = 70;
1296 pub const CPTIME2 = 71;
1297 pub const CACHEPCT = 72;
1298 pub const FILE = 73;
1299 pub const WXABORT = 74;
1300 pub const CONSDEV = 75;
1301 pub const NETLIVELOCKS = 76;
1302 pub const POOL_DEBUG = 77;
1303 pub const PROC_CWD = 78;
1304 pub const PROC_NOBROADCASTKILL = 79;
1305 pub const PROC_VMMAP = 80;
1306 pub const GLOBAL_PTRACE = 81;
1307 pub const CONSBUFSIZE = 82;
1308 pub const CONSBUF = 83;
1309 pub const AUDIO = 84;
1310 pub const CPUSTATS = 85;
1311 pub const PFSTATUS = 86;
1312 pub const TIMEOUT_STATS = 87;
1313 pub const UTC_OFFSET = 88;
1314 pub const VIDEO = 89;
1315
1316 pub const PROC_ALL = 0;
1317 pub const PROC_PID = 1;
1318 pub const PROC_PGRP = 2;
1319 pub const PROC_SESSION = 3;
1320 pub const PROC_TTY = 4;
1321 pub const PROC_UID = 5;
1322 pub const PROC_RUID = 6;
1323 pub const PROC_KTHREAD = 7;
1324 pub const PROC_SHOW_THREADS = 0x40000000;
1325
1326 pub const PROC_ARGV = 1;
1327 pub const PROC_NARGV = 2;
1328 pub const PROC_ENV = 3;
1329 pub const PROC_NENV = 4;
1330 },
1331 else => void,
1332};
1333pub const LOCK = switch (native_os) {
1334 .linux => linux.LOCK,
1335 .emscripten => emscripten.LOCK,
1336 else => struct {
1337 pub const SH = 1;
1338 pub const EX = 2;
1339 pub const NB = 4;
1340 pub const UN = 8;
1341 },
1342};
1343pub const MADV = switch (native_os) {
1344 .linux => linux.MADV,
1345 .emscripten => emscripten.MADV,
1346 .freebsd, .kfreebsd => struct {
1347 pub const NORMAL = 0;
1348 pub const RANDOM = 1;
1349 pub const SEQUENTIAL = 2;
1350 pub const WILLNEED = 3;
1351 pub const DONTNEED = 4;
1352 pub const FREE = 5;
1353 pub const NOSYNC = 6;
1354 pub const AUTOSYNC = 7;
1355 pub const NOCORE = 8;
1356 pub const CORE = 9;
1357 pub const PROTECT = 10;
1358 },
1359 .solaris, .illumos => struct {
1360 /// no further special treatment
1361 pub const NORMAL = 0;
1362 /// expect random page references
1363 pub const RANDOM = 1;
1364 /// expect sequential page references
1365 pub const SEQUENTIAL = 2;
1366 /// will need these pages
1367 pub const WILLNEED = 3;
1368 /// don't need these pages
1369 pub const DONTNEED = 4;
1370 /// contents can be freed
1371 pub const FREE = 5;
1372 /// default access
1373 pub const ACCESS_DEFAULT = 6;
1374 /// next LWP to access heavily
1375 pub const ACCESS_LWP = 7;
1376 /// many processes to access heavily
1377 pub const ACCESS_MANY = 8;
1378 /// contents will be purged
1379 pub const PURGE = 9;
1380 },
1381 .dragonfly => struct {
1382 pub const SEQUENTIAL = 2;
1383 pub const CONTROL_END = SETMAP;
1384 pub const DONTNEED = 4;
1385 pub const RANDOM = 1;
1386 pub const WILLNEED = 3;
1387 pub const NORMAL = 0;
1388 pub const CONTROL_START = INVAL;
1389 pub const FREE = 5;
1390 pub const NOSYNC = 6;
1391 pub const AUTOSYNC = 7;
1392 pub const NOCORE = 8;
1393 pub const CORE = 9;
1394 pub const INVAL = 10;
1395 pub const SETMAP = 11;
1396 },
1397 else => void,
1398};
1399pub const MSF = switch (native_os) {
1400 .linux => linux.MSF,
1401 .emscripten => emscripten.MSF,
1402 .macos, .ios, .tvos, .watchos, .visionos => struct {
1403 pub const ASYNC = 0x1;
1404 pub const INVALIDATE = 0x2;
1405 /// invalidate, leave mapped
1406 pub const KILLPAGES = 0x4;
1407 /// deactivate, leave mapped
1408 pub const DEACTIVATE = 0x8;
1409 pub const SYNC = 0x10;
1410 },
1411 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => struct {
1412 pub const ASYNC = 1;
1413 pub const INVALIDATE = 2;
1414 pub const SYNC = 4;
1415 },
1416 else => void,
1417};
1418pub const MMAP2_UNIT = switch (native_os) {
1419 .linux => linux.MMAP2_UNIT,
1420 else => void,
1421};
1422pub const NAME_MAX = switch (native_os) {
1423 .linux => linux.NAME_MAX,
1424 .emscripten => emscripten.NAME_MAX,
1425 // Haiku's headers make this 256, to contain room for the terminating null
1426 // character, but POSIX definition says that NAME_MAX does not include the
1427 // terminating null.
1428 .haiku, .openbsd, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => 255,
1429 else => {},
1430};
1431pub const PATH_MAX = switch (native_os) {
1432 .linux => linux.PATH_MAX,
1433 .emscripten => emscripten.PATH_MAX,
1434 .wasi => 4096,
1435 .windows => 260,
1436 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => 1024,
1437 else => {},
1438};
1439
1440pub const POLL = switch (native_os) {
1441 .linux => linux.POLL,
1442 .emscripten => emscripten.POLL,
1443 .wasi => struct {
1444 pub const RDNORM = 0x1;
1445 pub const WRNORM = 0x2;
1446 pub const IN = RDNORM;
1447 pub const OUT = WRNORM;
1448 pub const ERR = 0x1000;
1449 pub const HUP = 0x2000;
1450 pub const NVAL = 0x4000;
1451 },
1452 .windows => ws2_32.POLL,
1453 .macos, .ios, .tvos, .watchos, .visionos => struct {
1454 pub const IN = 0x001;
1455 pub const PRI = 0x002;
1456 pub const OUT = 0x004;
1457 pub const RDNORM = 0x040;
1458 pub const WRNORM = OUT;
1459 pub const RDBAND = 0x080;
1460 pub const WRBAND = 0x100;
1461
1462 pub const EXTEND = 0x0200;
1463 pub const ATTRIB = 0x0400;
1464 pub const NLINK = 0x0800;
1465 pub const WRITE = 0x1000;
1466
1467 pub const ERR = 0x008;
1468 pub const HUP = 0x010;
1469 pub const NVAL = 0x020;
1470
1471 pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
1472 },
1473 .freebsd, .kfreebsd => struct {
1474 /// any readable data available.
1475 pub const IN = 0x0001;
1476 /// OOB/Urgent readable data.
1477 pub const PRI = 0x0002;
1478 /// file descriptor is writeable.
1479 pub const OUT = 0x0004;
1480 /// non-OOB/URG data available.
1481 pub const RDNORM = 0x0040;
1482 /// no write type differentiation.
1483 pub const WRNORM = OUT;
1484 /// OOB/Urgent readable data.
1485 pub const RDBAND = 0x0080;
1486 /// OOB/Urgent data can be written.
1487 pub const WRBAND = 0x0100;
1488 /// like IN, except ignore EOF.
1489 pub const INIGNEOF = 0x2000;
1490 /// some poll error occurred.
1491 pub const ERR = 0x0008;
1492 /// file descriptor was "hung up".
1493 pub const HUP = 0x0010;
1494 /// requested events "invalid".
1495 pub const NVAL = 0x0020;
1496
1497 pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
1498 },
1499 .solaris, .illumos => struct {
1500 pub const IN = 0x0001;
1501 pub const PRI = 0x0002;
1502 pub const OUT = 0x0004;
1503 pub const RDNORM = 0x0040;
1504 pub const WRNORM = .OUT;
1505 pub const RDBAND = 0x0080;
1506 pub const WRBAND = 0x0100;
1507 /// Read-side hangup.
1508 pub const RDHUP = 0x4000;
1509
1510 /// Non-testable events (may not be specified in events).
1511 pub const ERR = 0x0008;
1512 pub const HUP = 0x0010;
1513 pub const NVAL = 0x0020;
1514
1515 /// Events to control `/dev/poll` (not specified in revents)
1516 pub const REMOVE = 0x0800;
1517 pub const ONESHOT = 0x1000;
1518 pub const ET = 0x2000;
1519 },
1520 .dragonfly, .netbsd => struct {
1521 /// Testable events (may be specified in events field).
1522 pub const IN = 0x0001;
1523 pub const PRI = 0x0002;
1524 pub const OUT = 0x0004;
1525 pub const RDNORM = 0x0040;
1526 pub const WRNORM = OUT;
1527 pub const RDBAND = 0x0080;
1528 pub const WRBAND = 0x0100;
1529
1530 /// Non-testable events (may not be specified in events field).
1531 pub const ERR = 0x0008;
1532 pub const HUP = 0x0010;
1533 pub const NVAL = 0x0020;
1534 },
1535 .haiku => struct {
1536 /// any readable data available
1537 pub const IN = 0x0001;
1538 /// file descriptor is writeable
1539 pub const OUT = 0x0002;
1540 pub const RDNORM = IN;
1541 pub const WRNORM = OUT;
1542 /// priority readable data
1543 pub const RDBAND = 0x0008;
1544 /// priority data can be written
1545 pub const WRBAND = 0x0010;
1546 /// high priority readable data
1547 pub const PRI = 0x0020;
1548
1549 /// errors pending
1550 pub const ERR = 0x0004;
1551 /// disconnected
1552 pub const HUP = 0x0080;
1553 /// invalid file descriptor
1554 pub const NVAL = 0x1000;
1555 },
1556 .openbsd => struct {
1557 pub const IN = 0x0001;
1558 pub const PRI = 0x0002;
1559 pub const OUT = 0x0004;
1560 pub const ERR = 0x0008;
1561 pub const HUP = 0x0010;
1562 pub const NVAL = 0x0020;
1563 pub const RDNORM = 0x0040;
1564 pub const NORM = RDNORM;
1565 pub const WRNORM = OUT;
1566 pub const RDBAND = 0x0080;
1567 pub const WRBAND = 0x0100;
1568 },
1569 else => void,
1570};
1571
1572/// Basic memory protection flags
1573pub const PROT = switch (native_os) {
1574 .linux => linux.PROT,
1575 .emscripten => emscripten.PROT,
1576 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd, .windows => struct {
1577 /// page can not be accessed
1578 pub const NONE = 0x0;
1579 /// page can be read
1580 pub const READ = 0x1;
1581 /// page can be written
1582 pub const WRITE = 0x2;
1583 /// page can be executed
1584 pub const EXEC = 0x4;
1585 },
1586 .macos, .ios, .tvos, .watchos, .visionos => struct {
1587 /// [MC2] no permissions
1588 pub const NONE: vm_prot_t = 0x00;
1589 /// [MC2] pages can be read
1590 pub const READ: vm_prot_t = 0x01;
1591 /// [MC2] pages can be written
1592 pub const WRITE: vm_prot_t = 0x02;
1593 /// [MC2] pages can be executed
1594 pub const EXEC: vm_prot_t = 0x04;
1595 /// When a caller finds that they cannot obtain write permission on a
1596 /// mapped entry, the following flag can be used. The entry will be
1597 /// made "needs copy" effectively copying the object (using COW),
1598 /// and write permission will be added to the maximum protections for
1599 /// the associated entry.
1600 pub const COPY: vm_prot_t = 0x10;
1601 },
1602 else => void,
1603};
1604
1605pub const REG = switch (native_os) {
1606 .linux => linux.REG,
1607 .emscripten => emscripten.REG,
1608 .freebsd, .kfreebsd => switch (builtin.cpu.arch) {
1609 .aarch64 => struct {
1610 pub const FP = 29;
1611 pub const SP = 31;
1612 pub const PC = 32;
1613 },
1614 .arm => struct {
1615 pub const FP = 11;
1616 pub const SP = 13;
1617 pub const PC = 15;
1618 },
1619 .x86_64 => struct {
1620 pub const RBP = 12;
1621 pub const RIP = 21;
1622 pub const RSP = 24;
1623 },
1624 else => struct {},
1625 },
1626 .solaris, .illumos => struct {
1627 pub const R15 = 0;
1628 pub const R14 = 1;
1629 pub const R13 = 2;
1630 pub const R12 = 3;
1631 pub const R11 = 4;
1632 pub const R10 = 5;
1633 pub const R9 = 6;
1634 pub const R8 = 7;
1635 pub const RDI = 8;
1636 pub const RSI = 9;
1637 pub const RBP = 10;
1638 pub const RBX = 11;
1639 pub const RDX = 12;
1640 pub const RCX = 13;
1641 pub const RAX = 14;
1642 pub const RIP = 17;
1643 pub const RSP = 20;
1644 },
1645 .netbsd => switch (builtin.cpu.arch) {
1646 .aarch64 => struct {
1647 pub const FP = 29;
1648 pub const SP = 31;
1649 pub const PC = 32;
1650 },
1651 .arm => struct {
1652 pub const FP = 11;
1653 pub const SP = 13;
1654 pub const PC = 15;
1655 },
1656 .x86_64 => struct {
1657 pub const RDI = 0;
1658 pub const RSI = 1;
1659 pub const RDX = 2;
1660 pub const RCX = 3;
1661 pub const R8 = 4;
1662 pub const R9 = 5;
1663 pub const R10 = 6;
1664 pub const R11 = 7;
1665 pub const R12 = 8;
1666 pub const R13 = 9;
1667 pub const R14 = 10;
1668 pub const R15 = 11;
1669 pub const RBP = 12;
1670 pub const RBX = 13;
1671 pub const RAX = 14;
1672 pub const GS = 15;
1673 pub const FS = 16;
1674 pub const ES = 17;
1675 pub const DS = 18;
1676 pub const TRAPNO = 19;
1677 pub const ERR = 20;
1678 pub const RIP = 21;
1679 pub const CS = 22;
1680 pub const RFLAGS = 23;
1681 pub const RSP = 24;
1682 pub const SS = 25;
1683 },
1684 else => struct {},
1685 },
1686 else => struct {},
1687};
1688pub const RLIM = switch (native_os) {
1689 .linux => linux.RLIM,
1690 .emscripten => emscripten.RLIM,
1691 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
1692 /// No limit
1693 pub const INFINITY: rlim_t = (1 << 63) - 1;
1694
1695 pub const SAVED_MAX = INFINITY;
1696 pub const SAVED_CUR = INFINITY;
1697 },
1698 .solaris, .illumos => struct {
1699 /// No limit
1700 pub const INFINITY: rlim_t = (1 << 63) - 3;
1701 pub const SAVED_MAX: rlim_t = (1 << 63) - 2;
1702 pub const SAVED_CUR: rlim_t = (1 << 63) - 1;
1703 },
1704 else => void,
1705};
1706pub const S = switch (native_os) {
1707 .linux => linux.S,
1708 .emscripten => emscripten.S,
1709 .wasi => struct {
1710 pub const IEXEC = @compileError("TODO audit this");
1711 pub const IFBLK = 0x6000;
1712 pub const IFCHR = 0x2000;
1713 pub const IFDIR = 0x4000;
1714 pub const IFIFO = 0xc000;
1715 pub const IFLNK = 0xa000;
1716 pub const IFMT = IFBLK | IFCHR | IFDIR | IFIFO | IFLNK | IFREG | IFSOCK;
1717 pub const IFREG = 0x8000;
1718 /// There's no concept of UNIX domain socket but we define this value here
1719 /// in order to line with other OSes.
1720 pub const IFSOCK = 0x1;
1721 },
1722 .macos, .ios, .tvos, .watchos, .visionos => struct {
1723 pub const IFMT = 0o170000;
1724
1725 pub const IFIFO = 0o010000;
1726 pub const IFCHR = 0o020000;
1727 pub const IFDIR = 0o040000;
1728 pub const IFBLK = 0o060000;
1729 pub const IFREG = 0o100000;
1730 pub const IFLNK = 0o120000;
1731 pub const IFSOCK = 0o140000;
1732 pub const IFWHT = 0o160000;
1733
1734 pub const ISUID = 0o4000;
1735 pub const ISGID = 0o2000;
1736 pub const ISVTX = 0o1000;
1737 pub const IRWXU = 0o700;
1738 pub const IRUSR = 0o400;
1739 pub const IWUSR = 0o200;
1740 pub const IXUSR = 0o100;
1741 pub const IRWXG = 0o070;
1742 pub const IRGRP = 0o040;
1743 pub const IWGRP = 0o020;
1744 pub const IXGRP = 0o010;
1745 pub const IRWXO = 0o007;
1746 pub const IROTH = 0o004;
1747 pub const IWOTH = 0o002;
1748 pub const IXOTH = 0o001;
1749
1750 pub fn ISFIFO(m: u32) bool {
1751 return m & IFMT == IFIFO;
1752 }
1753
1754 pub fn ISCHR(m: u32) bool {
1755 return m & IFMT == IFCHR;
1756 }
1757
1758 pub fn ISDIR(m: u32) bool {
1759 return m & IFMT == IFDIR;
1760 }
1761
1762 pub fn ISBLK(m: u32) bool {
1763 return m & IFMT == IFBLK;
1764 }
1765
1766 pub fn ISREG(m: u32) bool {
1767 return m & IFMT == IFREG;
1768 }
1769
1770 pub fn ISLNK(m: u32) bool {
1771 return m & IFMT == IFLNK;
1772 }
1773
1774 pub fn ISSOCK(m: u32) bool {
1775 return m & IFMT == IFSOCK;
1776 }
1777
1778 pub fn IWHT(m: u32) bool {
1779 return m & IFMT == IFWHT;
1780 }
1781 },
1782 .freebsd, .kfreebsd => struct {
1783 pub const IFMT = 0o170000;
1784
1785 pub const IFIFO = 0o010000;
1786 pub const IFCHR = 0o020000;
1787 pub const IFDIR = 0o040000;
1788 pub const IFBLK = 0o060000;
1789 pub const IFREG = 0o100000;
1790 pub const IFLNK = 0o120000;
1791 pub const IFSOCK = 0o140000;
1792 pub const IFWHT = 0o160000;
1793
1794 pub const ISUID = 0o4000;
1795 pub const ISGID = 0o2000;
1796 pub const ISVTX = 0o1000;
1797 pub const IRWXU = 0o700;
1798 pub const IRUSR = 0o400;
1799 pub const IWUSR = 0o200;
1800 pub const IXUSR = 0o100;
1801 pub const IRWXG = 0o070;
1802 pub const IRGRP = 0o040;
1803 pub const IWGRP = 0o020;
1804 pub const IXGRP = 0o010;
1805 pub const IRWXO = 0o007;
1806 pub const IROTH = 0o004;
1807 pub const IWOTH = 0o002;
1808 pub const IXOTH = 0o001;
1809
1810 pub fn ISFIFO(m: u32) bool {
1811 return m & IFMT == IFIFO;
1812 }
1813
1814 pub fn ISCHR(m: u32) bool {
1815 return m & IFMT == IFCHR;
1816 }
1817
1818 pub fn ISDIR(m: u32) bool {
1819 return m & IFMT == IFDIR;
1820 }
1821
1822 pub fn ISBLK(m: u32) bool {
1823 return m & IFMT == IFBLK;
1824 }
1825
1826 pub fn ISREG(m: u32) bool {
1827 return m & IFMT == IFREG;
1828 }
1829
1830 pub fn ISLNK(m: u32) bool {
1831 return m & IFMT == IFLNK;
1832 }
1833
1834 pub fn ISSOCK(m: u32) bool {
1835 return m & IFMT == IFSOCK;
1836 }
1837
1838 pub fn IWHT(m: u32) bool {
1839 return m & IFMT == IFWHT;
1840 }
1841 },
1842 .solaris, .illumos => struct {
1843 pub const IFMT = 0o170000;
1844
1845 pub const IFIFO = 0o010000;
1846 pub const IFCHR = 0o020000;
1847 pub const IFDIR = 0o040000;
1848 pub const IFBLK = 0o060000;
1849 pub const IFREG = 0o100000;
1850 pub const IFLNK = 0o120000;
1851 pub const IFSOCK = 0o140000;
1852 /// SunOS 2.6 Door
1853 pub const IFDOOR = 0o150000;
1854 /// Solaris 10 Event Port
1855 pub const IFPORT = 0o160000;
1856
1857 pub const ISUID = 0o4000;
1858 pub const ISGID = 0o2000;
1859 pub const ISVTX = 0o1000;
1860 pub const IRWXU = 0o700;
1861 pub const IRUSR = 0o400;
1862 pub const IWUSR = 0o200;
1863 pub const IXUSR = 0o100;
1864 pub const IRWXG = 0o070;
1865 pub const IRGRP = 0o040;
1866 pub const IWGRP = 0o020;
1867 pub const IXGRP = 0o010;
1868 pub const IRWXO = 0o007;
1869 pub const IROTH = 0o004;
1870 pub const IWOTH = 0o002;
1871 pub const IXOTH = 0o001;
1872
1873 pub fn ISFIFO(m: u32) bool {
1874 return m & IFMT == IFIFO;
1875 }
1876
1877 pub fn ISCHR(m: u32) bool {
1878 return m & IFMT == IFCHR;
1879 }
1880
1881 pub fn ISDIR(m: u32) bool {
1882 return m & IFMT == IFDIR;
1883 }
1884
1885 pub fn ISBLK(m: u32) bool {
1886 return m & IFMT == IFBLK;
1887 }
1888
1889 pub fn ISREG(m: u32) bool {
1890 return m & IFMT == IFREG;
1891 }
1892
1893 pub fn ISLNK(m: u32) bool {
1894 return m & IFMT == IFLNK;
1895 }
1896
1897 pub fn ISSOCK(m: u32) bool {
1898 return m & IFMT == IFSOCK;
1899 }
1900
1901 pub fn ISDOOR(m: u32) bool {
1902 return m & IFMT == IFDOOR;
1903 }
1904
1905 pub fn ISPORT(m: u32) bool {
1906 return m & IFMT == IFPORT;
1907 }
1908 },
1909 .netbsd => struct {
1910 pub const IFMT = 0o170000;
1911
1912 pub const IFIFO = 0o010000;
1913 pub const IFCHR = 0o020000;
1914 pub const IFDIR = 0o040000;
1915 pub const IFBLK = 0o060000;
1916 pub const IFREG = 0o100000;
1917 pub const IFLNK = 0o120000;
1918 pub const IFSOCK = 0o140000;
1919 pub const IFWHT = 0o160000;
1920
1921 pub const ISUID = 0o4000;
1922 pub const ISGID = 0o2000;
1923 pub const ISVTX = 0o1000;
1924 pub const IRWXU = 0o700;
1925 pub const IRUSR = 0o400;
1926 pub const IWUSR = 0o200;
1927 pub const IXUSR = 0o100;
1928 pub const IRWXG = 0o070;
1929 pub const IRGRP = 0o040;
1930 pub const IWGRP = 0o020;
1931 pub const IXGRP = 0o010;
1932 pub const IRWXO = 0o007;
1933 pub const IROTH = 0o004;
1934 pub const IWOTH = 0o002;
1935 pub const IXOTH = 0o001;
1936
1937 pub fn ISFIFO(m: u32) bool {
1938 return m & IFMT == IFIFO;
1939 }
1940
1941 pub fn ISCHR(m: u32) bool {
1942 return m & IFMT == IFCHR;
1943 }
1944
1945 pub fn ISDIR(m: u32) bool {
1946 return m & IFMT == IFDIR;
1947 }
1948
1949 pub fn ISBLK(m: u32) bool {
1950 return m & IFMT == IFBLK;
1951 }
1952
1953 pub fn ISREG(m: u32) bool {
1954 return m & IFMT == IFREG;
1955 }
1956
1957 pub fn ISLNK(m: u32) bool {
1958 return m & IFMT == IFLNK;
1959 }
1960
1961 pub fn ISSOCK(m: u32) bool {
1962 return m & IFMT == IFSOCK;
1963 }
1964
1965 pub fn IWHT(m: u32) bool {
1966 return m & IFMT == IFWHT;
1967 }
1968 },
1969 .dragonfly => struct {
1970 pub const IREAD = IRUSR;
1971 pub const IEXEC = IXUSR;
1972 pub const IWRITE = IWUSR;
1973 pub const IXOTH = 1;
1974 pub const IWOTH = 2;
1975 pub const IROTH = 4;
1976 pub const IRWXO = 7;
1977 pub const IXGRP = 8;
1978 pub const IWGRP = 16;
1979 pub const IRGRP = 32;
1980 pub const IRWXG = 56;
1981 pub const IXUSR = 64;
1982 pub const IWUSR = 128;
1983 pub const IRUSR = 256;
1984 pub const IRWXU = 448;
1985 pub const ISTXT = 512;
1986 pub const BLKSIZE = 512;
1987 pub const ISVTX = 512;
1988 pub const ISGID = 1024;
1989 pub const ISUID = 2048;
1990 pub const IFIFO = 4096;
1991 pub const IFCHR = 8192;
1992 pub const IFDIR = 16384;
1993 pub const IFBLK = 24576;
1994 pub const IFREG = 32768;
1995 pub const IFDB = 36864;
1996 pub const IFLNK = 40960;
1997 pub const IFSOCK = 49152;
1998 pub const IFWHT = 57344;
1999 pub const IFMT = 61440;
2000
2001 pub fn ISCHR(m: u32) bool {
2002 return m & IFMT == IFCHR;
2003 }
2004 },
2005 .haiku => struct {
2006 pub const IFMT = 0o170000;
2007 pub const IFSOCK = 0o140000;
2008 pub const IFLNK = 0o120000;
2009 pub const IFREG = 0o100000;
2010 pub const IFBLK = 0o060000;
2011 pub const IFDIR = 0o040000;
2012 pub const IFCHR = 0o020000;
2013 pub const IFIFO = 0o010000;
2014 pub const INDEX_DIR = 0o4000000000;
2015
2016 pub const IUMSK = 0o7777;
2017 pub const ISUID = 0o4000;
2018 pub const ISGID = 0o2000;
2019 pub const ISVTX = 0o1000;
2020 pub const IRWXU = 0o700;
2021 pub const IRUSR = 0o400;
2022 pub const IWUSR = 0o200;
2023 pub const IXUSR = 0o100;
2024 pub const IRWXG = 0o070;
2025 pub const IRGRP = 0o040;
2026 pub const IWGRP = 0o020;
2027 pub const IXGRP = 0o010;
2028 pub const IRWXO = 0o007;
2029 pub const IROTH = 0o004;
2030 pub const IWOTH = 0o002;
2031 pub const IXOTH = 0o001;
2032
2033 pub fn ISREG(m: u32) bool {
2034 return m & IFMT == IFREG;
2035 }
2036
2037 pub fn ISLNK(m: u32) bool {
2038 return m & IFMT == IFLNK;
2039 }
2040
2041 pub fn ISBLK(m: u32) bool {
2042 return m & IFMT == IFBLK;
2043 }
2044
2045 pub fn ISDIR(m: u32) bool {
2046 return m & IFMT == IFDIR;
2047 }
2048
2049 pub fn ISCHR(m: u32) bool {
2050 return m & IFMT == IFCHR;
2051 }
2052
2053 pub fn ISFIFO(m: u32) bool {
2054 return m & IFMT == IFIFO;
2055 }
2056
2057 pub fn ISSOCK(m: u32) bool {
2058 return m & IFMT == IFSOCK;
2059 }
2060
2061 pub fn ISINDEX(m: u32) bool {
2062 return m & INDEX_DIR == INDEX_DIR;
2063 }
2064 },
2065 .openbsd => struct {
2066 pub const IFMT = 0o170000;
2067
2068 pub const IFIFO = 0o010000;
2069 pub const IFCHR = 0o020000;
2070 pub const IFDIR = 0o040000;
2071 pub const IFBLK = 0o060000;
2072 pub const IFREG = 0o100000;
2073 pub const IFLNK = 0o120000;
2074 pub const IFSOCK = 0o140000;
2075
2076 pub const ISUID = 0o4000;
2077 pub const ISGID = 0o2000;
2078 pub const ISVTX = 0o1000;
2079 pub const IRWXU = 0o700;
2080 pub const IRUSR = 0o400;
2081 pub const IWUSR = 0o200;
2082 pub const IXUSR = 0o100;
2083 pub const IRWXG = 0o070;
2084 pub const IRGRP = 0o040;
2085 pub const IWGRP = 0o020;
2086 pub const IXGRP = 0o010;
2087 pub const IRWXO = 0o007;
2088 pub const IROTH = 0o004;
2089 pub const IWOTH = 0o002;
2090 pub const IXOTH = 0o001;
2091
2092 pub fn ISFIFO(m: u32) bool {
2093 return m & IFMT == IFIFO;
2094 }
2095
2096 pub fn ISCHR(m: u32) bool {
2097 return m & IFMT == IFCHR;
2098 }
2099
2100 pub fn ISDIR(m: u32) bool {
2101 return m & IFMT == IFDIR;
2102 }
2103
2104 pub fn ISBLK(m: u32) bool {
2105 return m & IFMT == IFBLK;
2106 }
2107
2108 pub fn ISREG(m: u32) bool {
2109 return m & IFMT == IFREG;
2110 }
2111
2112 pub fn ISLNK(m: u32) bool {
2113 return m & IFMT == IFLNK;
2114 }
2115
2116 pub fn ISSOCK(m: u32) bool {
2117 return m & IFMT == IFSOCK;
2118 }
2119 },
2120 else => void,
2121};
2122pub const SA = switch (native_os) {
2123 .linux => linux.SA,
2124 .emscripten => emscripten.SA,
2125 .macos, .ios, .tvos, .watchos, .visionos => struct {
2126 /// take signal on signal stack
2127 pub const ONSTACK = 0x0001;
2128 /// restart system on signal return
2129 pub const RESTART = 0x0002;
2130 /// reset to SIG.DFL when taking signal
2131 pub const RESETHAND = 0x0004;
2132 /// do not generate SIG.CHLD on child stop
2133 pub const NOCLDSTOP = 0x0008;
2134 /// don't mask the signal we're delivering
2135 pub const NODEFER = 0x0010;
2136 /// don't keep zombies around
2137 pub const NOCLDWAIT = 0x0020;
2138 /// signal handler with SIGINFO args
2139 pub const SIGINFO = 0x0040;
2140 /// do not bounce off kernel's sigtramp
2141 pub const USERTRAMP = 0x0100;
2142 /// signal handler with SIGINFO args with 64bit regs information
2143 pub const @"64REGSET" = 0x0200;
2144 },
2145 .freebsd, .kfreebsd => struct {
2146 pub const ONSTACK = 0x0001;
2147 pub const RESTART = 0x0002;
2148 pub const RESETHAND = 0x0004;
2149 pub const NOCLDSTOP = 0x0008;
2150 pub const NODEFER = 0x0010;
2151 pub const NOCLDWAIT = 0x0020;
2152 pub const SIGINFO = 0x0040;
2153 },
2154 .solaris, .illumos => struct {
2155 pub const ONSTACK = 0x00000001;
2156 pub const RESETHAND = 0x00000002;
2157 pub const RESTART = 0x00000004;
2158 pub const SIGINFO = 0x00000008;
2159 pub const NODEFER = 0x00000010;
2160 pub const NOCLDWAIT = 0x00010000;
2161 },
2162 .netbsd => struct {
2163 pub const ONSTACK = 0x0001;
2164 pub const RESTART = 0x0002;
2165 pub const RESETHAND = 0x0004;
2166 pub const NOCLDSTOP = 0x0008;
2167 pub const NODEFER = 0x0010;
2168 pub const NOCLDWAIT = 0x0020;
2169 pub const SIGINFO = 0x0040;
2170 },
2171 .dragonfly => struct {
2172 pub const ONSTACK = 0x0001;
2173 pub const RESTART = 0x0002;
2174 pub const RESETHAND = 0x0004;
2175 pub const NODEFER = 0x0010;
2176 pub const NOCLDWAIT = 0x0020;
2177 pub const SIGINFO = 0x0040;
2178 },
2179 .haiku => struct {
2180 pub const NOCLDSTOP = 0x01;
2181 pub const NOCLDWAIT = 0x02;
2182 pub const RESETHAND = 0x04;
2183 pub const NODEFER = 0x08;
2184 pub const RESTART = 0x10;
2185 pub const ONSTACK = 0x20;
2186 pub const SIGINFO = 0x40;
2187 pub const NOMASK = NODEFER;
2188 pub const STACK = ONSTACK;
2189 pub const ONESHOT = RESETHAND;
2190 },
2191 .openbsd => struct {
2192 pub const ONSTACK = 0x0001;
2193 pub const RESTART = 0x0002;
2194 pub const RESETHAND = 0x0004;
2195 pub const NOCLDSTOP = 0x0008;
2196 pub const NODEFER = 0x0010;
2197 pub const NOCLDWAIT = 0x0020;
2198 pub const SIGINFO = 0x0040;
2199 },
2200 else => void,
2201};
2202pub const sigval_t = switch (native_os) {
2203 .netbsd, .solaris, .illumos => extern union {
2204 int: i32,
2205 ptr: ?*anyopaque,
2206 },
2207 else => void,
2208};
2209
2210pub const SC = switch (native_os) {
2211 .linux => linux.SC,
2212 else => void,
2213};
2214pub const SEEK = switch (native_os) {
2215 .linux => linux.SEEK,
2216 .emscripten => emscripten.SEEK,
2217 .wasi => struct {
2218 pub const SET: wasi.whence_t = .SET;
2219 pub const CUR: wasi.whence_t = .CUR;
2220 pub const END: wasi.whence_t = .END;
2221 },
2222 .openbsd, .haiku, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos, .windows => struct {
2223 pub const SET = 0;
2224 pub const CUR = 1;
2225 pub const END = 2;
2226 },
2227 .dragonfly, .solaris, .illumos => struct {
2228 pub const SET = 0;
2229 pub const CUR = 1;
2230 pub const END = 2;
2231 pub const DATA = 3;
2232 pub const HOLE = 4;
2233 },
2234 else => void,
2235};
2236pub const SHUT = switch (native_os) {
2237 .linux => linux.SHUT,
2238 .emscripten => emscripten.SHUT,
2239 else => struct {
2240 pub const RD = 0;
2241 pub const WR = 1;
2242 pub const RDWR = 2;
2243 },
2244};
2245
2246/// Signal types
2247pub const SIG = switch (native_os) {
2248 .linux => linux.SIG,
2249 .emscripten => emscripten.SIG,
2250 .windows => struct {
2251 /// interrupt
2252 pub const INT = 2;
2253 /// illegal instruction - invalid function image
2254 pub const ILL = 4;
2255 /// floating point exception
2256 pub const FPE = 8;
2257 /// segment violation
2258 pub const SEGV = 11;
2259 /// Software termination signal from kill
2260 pub const TERM = 15;
2261 /// Ctrl-Break sequence
2262 pub const BREAK = 21;
2263 /// abnormal termination triggered by abort call
2264 pub const ABRT = 22;
2265 /// SIGABRT compatible with other platforms, same as SIGABRT
2266 pub const ABRT_COMPAT = 6;
2267
2268 // Signal action codes
2269 /// default signal action
2270 pub const DFL = 0;
2271 /// ignore signal
2272 pub const IGN = 1;
2273 /// return current value
2274 pub const GET = 2;
2275 /// signal gets error
2276 pub const SGE = 3;
2277 /// acknowledge
2278 pub const ACK = 4;
2279 /// Signal error value (returned by signal call on error)
2280 pub const ERR = -1;
2281 },
2282 .macos, .ios, .tvos, .watchos, .visionos => struct {
2283 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2284 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2285 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2286 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(5);
2287
2288 /// block specified signal set
2289 pub const BLOCK = 1;
2290 /// unblock specified signal set
2291 pub const UNBLOCK = 2;
2292 /// set specified signal set
2293 pub const SETMASK = 3;
2294 /// hangup
2295 pub const HUP = 1;
2296 /// interrupt
2297 pub const INT = 2;
2298 /// quit
2299 pub const QUIT = 3;
2300 /// illegal instruction (not reset when caught)
2301 pub const ILL = 4;
2302 /// trace trap (not reset when caught)
2303 pub const TRAP = 5;
2304 /// abort()
2305 pub const ABRT = 6;
2306 /// pollable event ([XSR] generated, not supported)
2307 pub const POLL = 7;
2308 /// compatibility
2309 pub const IOT = ABRT;
2310 /// EMT instruction
2311 pub const EMT = 7;
2312 /// floating point exception
2313 pub const FPE = 8;
2314 /// kill (cannot be caught or ignored)
2315 pub const KILL = 9;
2316 /// bus error
2317 pub const BUS = 10;
2318 /// segmentation violation
2319 pub const SEGV = 11;
2320 /// bad argument to system call
2321 pub const SYS = 12;
2322 /// write on a pipe with no one to read it
2323 pub const PIPE = 13;
2324 /// alarm clock
2325 pub const ALRM = 14;
2326 /// software termination signal from kill
2327 pub const TERM = 15;
2328 /// urgent condition on IO channel
2329 pub const URG = 16;
2330 /// sendable stop signal not from tty
2331 pub const STOP = 17;
2332 /// stop signal from tty
2333 pub const TSTP = 18;
2334 /// continue a stopped process
2335 pub const CONT = 19;
2336 /// to parent on child stop or exit
2337 pub const CHLD = 20;
2338 /// to readers pgrp upon background tty read
2339 pub const TTIN = 21;
2340 /// like TTIN for output if (tp->t_local&LTOSTOP)
2341 pub const TTOU = 22;
2342 /// input/output possible signal
2343 pub const IO = 23;
2344 /// exceeded CPU time limit
2345 pub const XCPU = 24;
2346 /// exceeded file size limit
2347 pub const XFSZ = 25;
2348 /// virtual time alarm
2349 pub const VTALRM = 26;
2350 /// profiling time alarm
2351 pub const PROF = 27;
2352 /// window size changes
2353 pub const WINCH = 28;
2354 /// information request
2355 pub const INFO = 29;
2356 /// user defined signal 1
2357 pub const USR1 = 30;
2358 /// user defined signal 2
2359 pub const USR2 = 31;
2360 },
2361 .freebsd, .kfreebsd => struct {
2362 pub const HUP = 1;
2363 pub const INT = 2;
2364 pub const QUIT = 3;
2365 pub const ILL = 4;
2366 pub const TRAP = 5;
2367 pub const ABRT = 6;
2368 pub const IOT = ABRT;
2369 pub const EMT = 7;
2370 pub const FPE = 8;
2371 pub const KILL = 9;
2372 pub const BUS = 10;
2373 pub const SEGV = 11;
2374 pub const SYS = 12;
2375 pub const PIPE = 13;
2376 pub const ALRM = 14;
2377 pub const TERM = 15;
2378 pub const URG = 16;
2379 pub const STOP = 17;
2380 pub const TSTP = 18;
2381 pub const CONT = 19;
2382 pub const CHLD = 20;
2383 pub const TTIN = 21;
2384 pub const TTOU = 22;
2385 pub const IO = 23;
2386 pub const XCPU = 24;
2387 pub const XFSZ = 25;
2388 pub const VTALRM = 26;
2389 pub const PROF = 27;
2390 pub const WINCH = 28;
2391 pub const INFO = 29;
2392 pub const USR1 = 30;
2393 pub const USR2 = 31;
2394 pub const THR = 32;
2395 pub const LWP = THR;
2396 pub const LIBRT = 33;
2397
2398 pub const RTMIN = 65;
2399 pub const RTMAX = 126;
2400
2401 pub const BLOCK = 1;
2402 pub const UNBLOCK = 2;
2403 pub const SETMASK = 3;
2404
2405 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2406 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2407 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2408
2409 pub const WORDS = 4;
2410 pub const MAXSIG = 128;
2411
2412 pub inline fn IDX(sig: usize) usize {
2413 return sig - 1;
2414 }
2415 pub inline fn WORD(sig: usize) usize {
2416 return IDX(sig) >> 5;
2417 }
2418 pub inline fn BIT(sig: usize) usize {
2419 return 1 << (IDX(sig) & 31);
2420 }
2421 pub inline fn VALID(sig: usize) usize {
2422 return sig <= MAXSIG and sig > 0;
2423 }
2424 },
2425 .solaris, .illumos => struct {
2426 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2427 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2428 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2429 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(2);
2430
2431 pub const WORDS = 4;
2432 pub const MAXSIG = 75;
2433
2434 pub const SIG_BLOCK = 1;
2435 pub const SIG_UNBLOCK = 2;
2436 pub const SIG_SETMASK = 3;
2437
2438 pub const HUP = 1;
2439 pub const INT = 2;
2440 pub const QUIT = 3;
2441 pub const ILL = 4;
2442 pub const TRAP = 5;
2443 pub const IOT = 6;
2444 pub const ABRT = 6;
2445 pub const EMT = 7;
2446 pub const FPE = 8;
2447 pub const KILL = 9;
2448 pub const BUS = 10;
2449 pub const SEGV = 11;
2450 pub const SYS = 12;
2451 pub const PIPE = 13;
2452 pub const ALRM = 14;
2453 pub const TERM = 15;
2454 pub const USR1 = 16;
2455 pub const USR2 = 17;
2456 pub const CLD = 18;
2457 pub const CHLD = 18;
2458 pub const PWR = 19;
2459 pub const WINCH = 20;
2460 pub const URG = 21;
2461 pub const POLL = 22;
2462 pub const IO = .POLL;
2463 pub const STOP = 23;
2464 pub const TSTP = 24;
2465 pub const CONT = 25;
2466 pub const TTIN = 26;
2467 pub const TTOU = 27;
2468 pub const VTALRM = 28;
2469 pub const PROF = 29;
2470 pub const XCPU = 30;
2471 pub const XFSZ = 31;
2472 pub const WAITING = 32;
2473 pub const LWP = 33;
2474 pub const FREEZE = 34;
2475 pub const THAW = 35;
2476 pub const CANCEL = 36;
2477 pub const LOST = 37;
2478 pub const XRES = 38;
2479 pub const JVM1 = 39;
2480 pub const JVM2 = 40;
2481 pub const INFO = 41;
2482
2483 pub const RTMIN = 42;
2484 pub const RTMAX = 74;
2485
2486 pub inline fn IDX(sig: usize) usize {
2487 return sig - 1;
2488 }
2489 pub inline fn WORD(sig: usize) usize {
2490 return IDX(sig) >> 5;
2491 }
2492 pub inline fn BIT(sig: usize) usize {
2493 return 1 << (IDX(sig) & 31);
2494 }
2495 pub inline fn VALID(sig: usize) usize {
2496 return sig <= MAXSIG and sig > 0;
2497 }
2498 },
2499 .netbsd => struct {
2500 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2501 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2502 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2503
2504 pub const WORDS = 4;
2505 pub const MAXSIG = 128;
2506
2507 pub const BLOCK = 1;
2508 pub const UNBLOCK = 2;
2509 pub const SETMASK = 3;
2510
2511 pub const HUP = 1;
2512 pub const INT = 2;
2513 pub const QUIT = 3;
2514 pub const ILL = 4;
2515 pub const TRAP = 5;
2516 pub const ABRT = 6;
2517 pub const IOT = ABRT;
2518 pub const EMT = 7;
2519 pub const FPE = 8;
2520 pub const KILL = 9;
2521 pub const BUS = 10;
2522 pub const SEGV = 11;
2523 pub const SYS = 12;
2524 pub const PIPE = 13;
2525 pub const ALRM = 14;
2526 pub const TERM = 15;
2527 pub const URG = 16;
2528 pub const STOP = 17;
2529 pub const TSTP = 18;
2530 pub const CONT = 19;
2531 pub const CHLD = 20;
2532 pub const TTIN = 21;
2533 pub const TTOU = 22;
2534 pub const IO = 23;
2535 pub const XCPU = 24;
2536 pub const XFSZ = 25;
2537 pub const VTALRM = 26;
2538 pub const PROF = 27;
2539 pub const WINCH = 28;
2540 pub const INFO = 29;
2541 pub const USR1 = 30;
2542 pub const USR2 = 31;
2543 pub const PWR = 32;
2544
2545 pub const RTMIN = 33;
2546 pub const RTMAX = 63;
2547
2548 pub inline fn IDX(sig: usize) usize {
2549 return sig - 1;
2550 }
2551 pub inline fn WORD(sig: usize) usize {
2552 return IDX(sig) >> 5;
2553 }
2554 pub inline fn BIT(sig: usize) usize {
2555 return 1 << (IDX(sig) & 31);
2556 }
2557 pub inline fn VALID(sig: usize) usize {
2558 return sig <= MAXSIG and sig > 0;
2559 }
2560 },
2561 .dragonfly => struct {
2562 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2563 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2564 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2565
2566 pub const BLOCK = 1;
2567 pub const UNBLOCK = 2;
2568 pub const SETMASK = 3;
2569
2570 pub const IOT = ABRT;
2571 pub const HUP = 1;
2572 pub const INT = 2;
2573 pub const QUIT = 3;
2574 pub const ILL = 4;
2575 pub const TRAP = 5;
2576 pub const ABRT = 6;
2577 pub const EMT = 7;
2578 pub const FPE = 8;
2579 pub const KILL = 9;
2580 pub const BUS = 10;
2581 pub const SEGV = 11;
2582 pub const SYS = 12;
2583 pub const PIPE = 13;
2584 pub const ALRM = 14;
2585 pub const TERM = 15;
2586 pub const URG = 16;
2587 pub const STOP = 17;
2588 pub const TSTP = 18;
2589 pub const CONT = 19;
2590 pub const CHLD = 20;
2591 pub const TTIN = 21;
2592 pub const TTOU = 22;
2593 pub const IO = 23;
2594 pub const XCPU = 24;
2595 pub const XFSZ = 25;
2596 pub const VTALRM = 26;
2597 pub const PROF = 27;
2598 pub const WINCH = 28;
2599 pub const INFO = 29;
2600 pub const USR1 = 30;
2601 pub const USR2 = 31;
2602 pub const THR = 32;
2603 pub const CKPT = 33;
2604 pub const CKPTEXIT = 34;
2605
2606 pub const WORDS = 4;
2607 },
2608 .haiku => struct {
2609 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2610 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2611 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2612
2613 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
2614
2615 pub const HUP = 1;
2616 pub const INT = 2;
2617 pub const QUIT = 3;
2618 pub const ILL = 4;
2619 pub const CHLD = 5;
2620 pub const ABRT = 6;
2621 pub const IOT = ABRT;
2622 pub const PIPE = 7;
2623 pub const FPE = 8;
2624 pub const KILL = 9;
2625 pub const STOP = 10;
2626 pub const SEGV = 11;
2627 pub const CONT = 12;
2628 pub const TSTP = 13;
2629 pub const ALRM = 14;
2630 pub const TERM = 15;
2631 pub const TTIN = 16;
2632 pub const TTOU = 17;
2633 pub const USR1 = 18;
2634 pub const USR2 = 19;
2635 pub const WINCH = 20;
2636 pub const KILLTHR = 21;
2637 pub const TRAP = 22;
2638 pub const POLL = 23;
2639 pub const PROF = 24;
2640 pub const SYS = 25;
2641 pub const URG = 26;
2642 pub const VTALRM = 27;
2643 pub const XCPU = 28;
2644 pub const XFSZ = 29;
2645 pub const BUS = 30;
2646 pub const RESERVED1 = 31;
2647 pub const RESERVED2 = 32;
2648
2649 pub const BLOCK = 1;
2650 pub const UNBLOCK = 2;
2651 pub const SETMASK = 3;
2652 },
2653 .openbsd => struct {
2654 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
2655 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
2656 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
2657 pub const CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);
2658 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
2659
2660 pub const HUP = 1;
2661 pub const INT = 2;
2662 pub const QUIT = 3;
2663 pub const ILL = 4;
2664 pub const TRAP = 5;
2665 pub const ABRT = 6;
2666 pub const IOT = ABRT;
2667 pub const EMT = 7;
2668 pub const FPE = 8;
2669 pub const KILL = 9;
2670 pub const BUS = 10;
2671 pub const SEGV = 11;
2672 pub const SYS = 12;
2673 pub const PIPE = 13;
2674 pub const ALRM = 14;
2675 pub const TERM = 15;
2676 pub const URG = 16;
2677 pub const STOP = 17;
2678 pub const TSTP = 18;
2679 pub const CONT = 19;
2680 pub const CHLD = 20;
2681 pub const TTIN = 21;
2682 pub const TTOU = 22;
2683 pub const IO = 23;
2684 pub const XCPU = 24;
2685 pub const XFSZ = 25;
2686 pub const VTALRM = 26;
2687 pub const PROF = 27;
2688 pub const WINCH = 28;
2689 pub const INFO = 29;
2690 pub const USR1 = 30;
2691 pub const USR2 = 31;
2692 pub const PWR = 32;
2693
2694 pub const BLOCK = 1;
2695 pub const UNBLOCK = 2;
2696 pub const SETMASK = 3;
2697 },
2698 else => void,
2699};
2700
2701pub const SIOCGIFINDEX = switch (native_os) {
2702 .linux => linux.SIOCGIFINDEX,
2703 .emscripten => emscripten.SIOCGIFINDEX,
2704 .solaris, .illumos => solaris.SIOCGLIFINDEX,
2705 else => void,
2706};
2707
2708pub const STDIN_FILENO = switch (native_os) {
2709 .linux => linux.STDIN_FILENO,
2710 .emscripten => emscripten.STDIN_FILENO,
2711 else => 0,
2712};
2713pub const STDOUT_FILENO = switch (native_os) {
2714 .linux => linux.STDOUT_FILENO,
2715 .emscripten => emscripten.STDOUT_FILENO,
2716 else => 1,
2717};
2718pub const STDERR_FILENO = switch (native_os) {
2719 .linux => linux.STDERR_FILENO,
2720 .emscripten => emscripten.STDERR_FILENO,
2721 else => 2,
2722};
2723
2724pub const SYS = switch (native_os) {
2725 .linux => linux.SYS,
2726 else => void,
2727};
2728/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
2729pub const Sigaction = switch (native_os) {
2730 .linux => linux.Sigaction,
2731 .emscripten => emscripten.Sigaction,
2732 .netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
2733 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
2734 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
2735
2736 handler: extern union {
2737 handler: ?handler_fn,
2738 sigaction: ?sigaction_fn,
2739 },
2740 mask: sigset_t,
2741 flags: c_uint,
2742 },
2743 .dragonfly, .freebsd, .kfreebsd => extern struct {
2744 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
2745 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
2746
2747 /// signal handler
2748 handler: extern union {
2749 handler: ?handler_fn,
2750 sigaction: ?sigaction_fn,
2751 },
2752 /// see signal options
2753 flags: c_uint,
2754 /// signal mask to apply
2755 mask: sigset_t,
2756 },
2757 .solaris, .illumos => extern struct {
2758 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
2759 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
2760
2761 /// signal options
2762 flags: c_uint,
2763 /// signal handler
2764 handler: extern union {
2765 handler: ?handler_fn,
2766 sigaction: ?sigaction_fn,
2767 },
2768 /// signal mask to apply
2769 mask: sigset_t,
2770 },
2771 .haiku => extern struct {
2772 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
2773 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
2774
2775 /// signal handler
2776 handler: extern union {
2777 handler: handler_fn,
2778 sigaction: sigaction_fn,
2779 },
2780
2781 /// signal mask to apply
2782 mask: sigset_t,
2783
2784 /// see signal options
2785 flags: i32,
2786
2787 /// will be passed to the signal handler, BeOS extension
2788 userdata: *allowzero anyopaque = undefined,
2789 },
2790 .openbsd => extern struct {
2791 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
2792 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
2793
2794 /// signal handler
2795 handler: extern union {
2796 handler: ?handler_fn,
2797 sigaction: ?sigaction_fn,
2798 },
2799 /// signal mask to apply
2800 mask: sigset_t,
2801 /// signal options
2802 flags: c_uint,
2803 },
2804 else => void,
2805};
2806pub const T = switch (native_os) {
2807 .linux => linux.T,
2808 .macos, .ios, .tvos, .watchos, .visionos => struct {
2809 pub const IOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize));
2810
2811 fn ior(inout: u32, group: usize, num: usize, len: usize) usize {
2812 return (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num));
2813 }
2814 },
2815 .freebsd, .kfreebsd => struct {
2816 pub const IOCEXCL = 0x2000740d;
2817 pub const IOCNXCL = 0x2000740e;
2818 pub const IOCSCTTY = 0x20007461;
2819 pub const IOCGPGRP = 0x40047477;
2820 pub const IOCSPGRP = 0x80047476;
2821 pub const IOCOUTQ = 0x40047473;
2822 pub const IOCSTI = 0x80017472;
2823 pub const IOCGWINSZ = 0x40087468;
2824 pub const IOCSWINSZ = 0x80087467;
2825 pub const IOCMGET = 0x4004746a;
2826 pub const IOCMBIS = 0x8004746c;
2827 pub const IOCMBIC = 0x8004746b;
2828 pub const IOCMSET = 0x8004746d;
2829 pub const FIONREAD = 0x4004667f;
2830 pub const IOCCONS = 0x80047462;
2831 pub const IOCPKT = 0x80047470;
2832 pub const FIONBIO = 0x8004667e;
2833 pub const IOCNOTTY = 0x20007471;
2834 pub const IOCSETD = 0x8004741b;
2835 pub const IOCGETD = 0x4004741a;
2836 pub const IOCSBRK = 0x2000747b;
2837 pub const IOCCBRK = 0x2000747a;
2838 pub const IOCGSID = 0x40047463;
2839 pub const IOCGPTN = 0x4004740f;
2840 pub const IOCSIG = 0x2004745f;
2841 },
2842 .solaris, .illumos => struct {
2843 pub const CGETA = tioc('T', 1);
2844 pub const CSETA = tioc('T', 2);
2845 pub const CSETAW = tioc('T', 3);
2846 pub const CSETAF = tioc('T', 4);
2847 pub const CSBRK = tioc('T', 5);
2848 pub const CXONC = tioc('T', 6);
2849 pub const CFLSH = tioc('T', 7);
2850 pub const IOCGWINSZ = tioc('T', 104);
2851 pub const IOCSWINSZ = tioc('T', 103);
2852 // Softcarrier ioctls
2853 pub const IOCGSOFTCAR = tioc('T', 105);
2854 pub const IOCSSOFTCAR = tioc('T', 106);
2855 // termios ioctls
2856 pub const CGETS = tioc('T', 13);
2857 pub const CSETS = tioc('T', 14);
2858 pub const CSANOW = tioc('T', 14);
2859 pub const CSETSW = tioc('T', 15);
2860 pub const CSADRAIN = tioc('T', 15);
2861 pub const CSETSF = tioc('T', 16);
2862 pub const IOCSETLD = tioc('T', 123);
2863 pub const IOCGETLD = tioc('T', 124);
2864 // NTP PPS ioctls
2865 pub const IOCGPPS = tioc('T', 125);
2866 pub const IOCSPPS = tioc('T', 126);
2867 pub const IOCGPPSEV = tioc('T', 127);
2868
2869 pub const IOCGETD = tioc('t', 0);
2870 pub const IOCSETD = tioc('t', 1);
2871 pub const IOCHPCL = tioc('t', 2);
2872 pub const IOCGETP = tioc('t', 8);
2873 pub const IOCSETP = tioc('t', 9);
2874 pub const IOCSETN = tioc('t', 10);
2875 pub const IOCEXCL = tioc('t', 13);
2876 pub const IOCNXCL = tioc('t', 14);
2877 pub const IOCFLUSH = tioc('t', 16);
2878 pub const IOCSETC = tioc('t', 17);
2879 pub const IOCGETC = tioc('t', 18);
2880 /// bis local mode bits
2881 pub const IOCLBIS = tioc('t', 127);
2882 /// bic local mode bits
2883 pub const IOCLBIC = tioc('t', 126);
2884 /// set entire local mode word
2885 pub const IOCLSET = tioc('t', 125);
2886 /// get local modes
2887 pub const IOCLGET = tioc('t', 124);
2888 /// set break bit
2889 pub const IOCSBRK = tioc('t', 123);
2890 /// clear break bit
2891 pub const IOCCBRK = tioc('t', 122);
2892 /// set data terminal ready
2893 pub const IOCSDTR = tioc('t', 121);
2894 /// clear data terminal ready
2895 pub const IOCCDTR = tioc('t', 120);
2896 /// set local special chars
2897 pub const IOCSLTC = tioc('t', 117);
2898 /// get local special chars
2899 pub const IOCGLTC = tioc('t', 116);
2900 /// driver output queue size
2901 pub const IOCOUTQ = tioc('t', 115);
2902 /// void tty association
2903 pub const IOCNOTTY = tioc('t', 113);
2904 /// get a ctty
2905 pub const IOCSCTTY = tioc('t', 132);
2906 /// stop output, like ^S
2907 pub const IOCSTOP = tioc('t', 111);
2908 /// start output, like ^Q
2909 pub const IOCSTART = tioc('t', 110);
2910 /// get pgrp of tty
2911 pub const IOCGPGRP = tioc('t', 20);
2912 /// set pgrp of tty
2913 pub const IOCSPGRP = tioc('t', 21);
2914 /// get session id on ctty
2915 pub const IOCGSID = tioc('t', 22);
2916 /// simulate terminal input
2917 pub const IOCSTI = tioc('t', 23);
2918 /// set all modem bits
2919 pub const IOCMSET = tioc('t', 26);
2920 /// bis modem bits
2921 pub const IOCMBIS = tioc('t', 27);
2922 /// bic modem bits
2923 pub const IOCMBIC = tioc('t', 28);
2924 /// get all modem bits
2925 pub const IOCMGET = tioc('t', 29);
2926
2927 fn tioc(t: u16, num: u8) u16 {
2928 return (t << 8) | num;
2929 }
2930 },
2931 .netbsd => struct {
2932 pub const IOCCBRK = 0x2000747a;
2933 pub const IOCCDTR = 0x20007478;
2934 pub const IOCCONS = 0x80047462;
2935 pub const IOCDCDTIMESTAMP = 0x40107458;
2936 pub const IOCDRAIN = 0x2000745e;
2937 pub const IOCEXCL = 0x2000740d;
2938 pub const IOCEXT = 0x80047460;
2939 pub const IOCFLAG_CDTRCTS = 0x10;
2940 pub const IOCFLAG_CLOCAL = 0x2;
2941 pub const IOCFLAG_CRTSCTS = 0x4;
2942 pub const IOCFLAG_MDMBUF = 0x8;
2943 pub const IOCFLAG_SOFTCAR = 0x1;
2944 pub const IOCFLUSH = 0x80047410;
2945 pub const IOCGETA = 0x402c7413;
2946 pub const IOCGETD = 0x4004741a;
2947 pub const IOCGFLAGS = 0x4004745d;
2948 pub const IOCGLINED = 0x40207442;
2949 pub const IOCGPGRP = 0x40047477;
2950 pub const IOCGQSIZE = 0x40047481;
2951 pub const IOCGRANTPT = 0x20007447;
2952 pub const IOCGSID = 0x40047463;
2953 pub const IOCGSIZE = 0x40087468;
2954 pub const IOCGWINSZ = 0x40087468;
2955 pub const IOCMBIC = 0x8004746b;
2956 pub const IOCMBIS = 0x8004746c;
2957 pub const IOCMGET = 0x4004746a;
2958 pub const IOCMSET = 0x8004746d;
2959 pub const IOCM_CAR = 0x40;
2960 pub const IOCM_CD = 0x40;
2961 pub const IOCM_CTS = 0x20;
2962 pub const IOCM_DSR = 0x100;
2963 pub const IOCM_DTR = 0x2;
2964 pub const IOCM_LE = 0x1;
2965 pub const IOCM_RI = 0x80;
2966 pub const IOCM_RNG = 0x80;
2967 pub const IOCM_RTS = 0x4;
2968 pub const IOCM_SR = 0x10;
2969 pub const IOCM_ST = 0x8;
2970 pub const IOCNOTTY = 0x20007471;
2971 pub const IOCNXCL = 0x2000740e;
2972 pub const IOCOUTQ = 0x40047473;
2973 pub const IOCPKT = 0x80047470;
2974 pub const IOCPKT_DATA = 0x0;
2975 pub const IOCPKT_DOSTOP = 0x20;
2976 pub const IOCPKT_FLUSHREAD = 0x1;
2977 pub const IOCPKT_FLUSHWRITE = 0x2;
2978 pub const IOCPKT_IOCTL = 0x40;
2979 pub const IOCPKT_NOSTOP = 0x10;
2980 pub const IOCPKT_START = 0x8;
2981 pub const IOCPKT_STOP = 0x4;
2982 pub const IOCPTMGET = 0x40287446;
2983 pub const IOCPTSNAME = 0x40287448;
2984 pub const IOCRCVFRAME = 0x80087445;
2985 pub const IOCREMOTE = 0x80047469;
2986 pub const IOCSBRK = 0x2000747b;
2987 pub const IOCSCTTY = 0x20007461;
2988 pub const IOCSDTR = 0x20007479;
2989 pub const IOCSETA = 0x802c7414;
2990 pub const IOCSETAF = 0x802c7416;
2991 pub const IOCSETAW = 0x802c7415;
2992 pub const IOCSETD = 0x8004741b;
2993 pub const IOCSFLAGS = 0x8004745c;
2994 pub const IOCSIG = 0x2000745f;
2995 pub const IOCSLINED = 0x80207443;
2996 pub const IOCSPGRP = 0x80047476;
2997 pub const IOCSQSIZE = 0x80047480;
2998 pub const IOCSSIZE = 0x80087467;
2999 pub const IOCSTART = 0x2000746e;
3000 pub const IOCSTAT = 0x80047465;
3001 pub const IOCSTI = 0x80017472;
3002 pub const IOCSTOP = 0x2000746f;
3003 pub const IOCSWINSZ = 0x80087467;
3004 pub const IOCUCNTL = 0x80047466;
3005 pub const IOCXMTFRAME = 0x80087444;
3006 },
3007 .haiku => struct {
3008 pub const CGETA = 0x8000;
3009 pub const CSETA = 0x8001;
3010 pub const CSETAF = 0x8002;
3011 pub const CSETAW = 0x8003;
3012 pub const CWAITEVENT = 0x8004;
3013 pub const CSBRK = 0x8005;
3014 pub const CFLSH = 0x8006;
3015 pub const CXONC = 0x8007;
3016 pub const CQUERYCONNECTED = 0x8008;
3017 pub const CGETBITS = 0x8009;
3018 pub const CSETDTR = 0x8010;
3019 pub const CSETRTS = 0x8011;
3020 pub const IOCGWINSZ = 0x8012;
3021 pub const IOCSWINSZ = 0x8013;
3022 pub const CVTIME = 0x8014;
3023 pub const IOCGPGRP = 0x8015;
3024 pub const IOCSPGRP = 0x8016;
3025 pub const IOCSCTTY = 0x8017;
3026 pub const IOCMGET = 0x8018;
3027 pub const IOCMSET = 0x8019;
3028 pub const IOCSBRK = 0x8020;
3029 pub const IOCCBRK = 0x8021;
3030 pub const IOCMBIS = 0x8022;
3031 pub const IOCMBIC = 0x8023;
3032 pub const IOCGSID = 0x8024;
3033
3034 pub const FIONREAD = 0xbe000001;
3035 pub const FIONBIO = 0xbe000000;
3036 },
3037 .openbsd => struct {
3038 pub const IOCCBRK = 0x2000747a;
3039 pub const IOCCDTR = 0x20007478;
3040 pub const IOCCONS = 0x80047462;
3041 pub const IOCDCDTIMESTAMP = 0x40107458;
3042 pub const IOCDRAIN = 0x2000745e;
3043 pub const IOCEXCL = 0x2000740d;
3044 pub const IOCEXT = 0x80047460;
3045 pub const IOCFLAG_CDTRCTS = 0x10;
3046 pub const IOCFLAG_CLOCAL = 0x2;
3047 pub const IOCFLAG_CRTSCTS = 0x4;
3048 pub const IOCFLAG_MDMBUF = 0x8;
3049 pub const IOCFLAG_SOFTCAR = 0x1;
3050 pub const IOCFLUSH = 0x80047410;
3051 pub const IOCGETA = 0x402c7413;
3052 pub const IOCGETD = 0x4004741a;
3053 pub const IOCGFLAGS = 0x4004745d;
3054 pub const IOCGLINED = 0x40207442;
3055 pub const IOCGPGRP = 0x40047477;
3056 pub const IOCGQSIZE = 0x40047481;
3057 pub const IOCGRANTPT = 0x20007447;
3058 pub const IOCGSID = 0x40047463;
3059 pub const IOCGSIZE = 0x40087468;
3060 pub const IOCGWINSZ = 0x40087468;
3061 pub const IOCMBIC = 0x8004746b;
3062 pub const IOCMBIS = 0x8004746c;
3063 pub const IOCMGET = 0x4004746a;
3064 pub const IOCMSET = 0x8004746d;
3065 pub const IOCM_CAR = 0x40;
3066 pub const IOCM_CD = 0x40;
3067 pub const IOCM_CTS = 0x20;
3068 pub const IOCM_DSR = 0x100;
3069 pub const IOCM_DTR = 0x2;
3070 pub const IOCM_LE = 0x1;
3071 pub const IOCM_RI = 0x80;
3072 pub const IOCM_RNG = 0x80;
3073 pub const IOCM_RTS = 0x4;
3074 pub const IOCM_SR = 0x10;
3075 pub const IOCM_ST = 0x8;
3076 pub const IOCNOTTY = 0x20007471;
3077 pub const IOCNXCL = 0x2000740e;
3078 pub const IOCOUTQ = 0x40047473;
3079 pub const IOCPKT = 0x80047470;
3080 pub const IOCPKT_DATA = 0x0;
3081 pub const IOCPKT_DOSTOP = 0x20;
3082 pub const IOCPKT_FLUSHREAD = 0x1;
3083 pub const IOCPKT_FLUSHWRITE = 0x2;
3084 pub const IOCPKT_IOCTL = 0x40;
3085 pub const IOCPKT_NOSTOP = 0x10;
3086 pub const IOCPKT_START = 0x8;
3087 pub const IOCPKT_STOP = 0x4;
3088 pub const IOCPTMGET = 0x40287446;
3089 pub const IOCPTSNAME = 0x40287448;
3090 pub const IOCRCVFRAME = 0x80087445;
3091 pub const IOCREMOTE = 0x80047469;
3092 pub const IOCSBRK = 0x2000747b;
3093 pub const IOCSCTTY = 0x20007461;
3094 pub const IOCSDTR = 0x20007479;
3095 pub const IOCSETA = 0x802c7414;
3096 pub const IOCSETAF = 0x802c7416;
3097 pub const IOCSETAW = 0x802c7415;
3098 pub const IOCSETD = 0x8004741b;
3099 pub const IOCSFLAGS = 0x8004745c;
3100 pub const IOCSIG = 0x2000745f;
3101 pub const IOCSLINED = 0x80207443;
3102 pub const IOCSPGRP = 0x80047476;
3103 pub const IOCSQSIZE = 0x80047480;
3104 pub const IOCSSIZE = 0x80087467;
3105 pub const IOCSTART = 0x2000746e;
3106 pub const IOCSTAT = 0x80047465;
3107 pub const IOCSTI = 0x80017472;
3108 pub const IOCSTOP = 0x2000746f;
3109 pub const IOCSWINSZ = 0x80087467;
3110 pub const IOCUCNTL = 0x80047466;
3111 pub const IOCXMTFRAME = 0x80087444;
3112 },
3113 else => void,
3114};
3115pub const IOCPARM_MASK = switch (native_os) {
3116 .windows => ws2_32.IOCPARM_MASK,
3117 .macos, .ios, .tvos, .watchos, .visionos => 0x1fff,
3118 else => void,
3119};
3120pub const TCSA = std.posix.TCSA;
3121pub const TFD = switch (native_os) {
3122 .linux => linux.TFD,
3123 else => void,
3124};
3125pub const VDSO = switch (native_os) {
3126 .linux => linux.VDSO,
3127 else => void,
3128};
3129pub const W = switch (native_os) {
3130 .linux => linux.W,
3131 .emscripten => emscripten.W,
3132 .macos, .ios, .tvos, .watchos, .visionos => struct {
3133 /// [XSI] no hang in wait/no child to reap
3134 pub const NOHANG = 0x00000001;
3135 /// [XSI] notify on stop, untraced child
3136 pub const UNTRACED = 0x00000002;
3137
3138 pub fn EXITSTATUS(x: u32) u8 {
3139 return @as(u8, @intCast(x >> 8));
3140 }
3141 pub fn TERMSIG(x: u32) u32 {
3142 return status(x);
3143 }
3144 pub fn STOPSIG(x: u32) u32 {
3145 return x >> 8;
3146 }
3147 pub fn IFEXITED(x: u32) bool {
3148 return status(x) == 0;
3149 }
3150 pub fn IFSTOPPED(x: u32) bool {
3151 return status(x) == stopped and STOPSIG(x) != 0x13;
3152 }
3153 pub fn IFSIGNALED(x: u32) bool {
3154 return status(x) != stopped and status(x) != 0;
3155 }
3156
3157 fn status(x: u32) u32 {
3158 return x & 0o177;
3159 }
3160 const stopped = 0o177;
3161 },
3162 .freebsd, .kfreebsd => struct {
3163 pub const NOHANG = 1;
3164 pub const UNTRACED = 2;
3165 pub const STOPPED = UNTRACED;
3166 pub const CONTINUED = 4;
3167 pub const NOWAIT = 8;
3168 pub const EXITED = 16;
3169 pub const TRAPPED = 32;
3170
3171 pub fn EXITSTATUS(s: u32) u8 {
3172 return @as(u8, @intCast((s & 0xff00) >> 8));
3173 }
3174 pub fn TERMSIG(s: u32) u32 {
3175 return s & 0x7f;
3176 }
3177 pub fn STOPSIG(s: u32) u32 {
3178 return EXITSTATUS(s);
3179 }
3180 pub fn IFEXITED(s: u32) bool {
3181 return TERMSIG(s) == 0;
3182 }
3183 pub fn IFSTOPPED(s: u32) bool {
3184 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
3185 }
3186 pub fn IFSIGNALED(s: u32) bool {
3187 return (s & 0xffff) -% 1 < 0xff;
3188 }
3189 },
3190 .solaris, .illumos => struct {
3191 pub const EXITED = 0o001;
3192 pub const TRAPPED = 0o002;
3193 pub const UNTRACED = 0o004;
3194 pub const STOPPED = UNTRACED;
3195 pub const CONTINUED = 0o010;
3196 pub const NOHANG = 0o100;
3197 pub const NOWAIT = 0o200;
3198
3199 pub fn EXITSTATUS(s: u32) u8 {
3200 return @as(u8, @intCast((s >> 8) & 0xff));
3201 }
3202 pub fn TERMSIG(s: u32) u32 {
3203 return s & 0x7f;
3204 }
3205 pub fn STOPSIG(s: u32) u32 {
3206 return EXITSTATUS(s);
3207 }
3208 pub fn IFEXITED(s: u32) bool {
3209 return TERMSIG(s) == 0;
3210 }
3211
3212 pub fn IFCONTINUED(s: u32) bool {
3213 return ((s & 0o177777) == 0o177777);
3214 }
3215
3216 pub fn IFSTOPPED(s: u32) bool {
3217 return (s & 0x00ff != 0o177) and !(s & 0xff00 != 0);
3218 }
3219
3220 pub fn IFSIGNALED(s: u32) bool {
3221 return s & 0x00ff > 0 and s & 0xff00 == 0;
3222 }
3223 },
3224 .netbsd => struct {
3225 pub const NOHANG = 0x00000001;
3226 pub const UNTRACED = 0x00000002;
3227 pub const STOPPED = UNTRACED;
3228 pub const CONTINUED = 0x00000010;
3229 pub const NOWAIT = 0x00010000;
3230 pub const EXITED = 0x00000020;
3231 pub const TRAPPED = 0x00000040;
3232
3233 pub fn EXITSTATUS(s: u32) u8 {
3234 return @as(u8, @intCast((s >> 8) & 0xff));
3235 }
3236 pub fn TERMSIG(s: u32) u32 {
3237 return s & 0x7f;
3238 }
3239 pub fn STOPSIG(s: u32) u32 {
3240 return EXITSTATUS(s);
3241 }
3242 pub fn IFEXITED(s: u32) bool {
3243 return TERMSIG(s) == 0;
3244 }
3245
3246 pub fn IFCONTINUED(s: u32) bool {
3247 return ((s & 0x7f) == 0xffff);
3248 }
3249
3250 pub fn IFSTOPPED(s: u32) bool {
3251 return ((s & 0x7f != 0x7f) and !IFCONTINUED(s));
3252 }
3253
3254 pub fn IFSIGNALED(s: u32) bool {
3255 return !IFSTOPPED(s) and !IFCONTINUED(s) and !IFEXITED(s);
3256 }
3257 },
3258 .dragonfly => struct {
3259 pub const NOHANG = 0x0001;
3260 pub const UNTRACED = 0x0002;
3261 pub const CONTINUED = 0x0004;
3262 pub const STOPPED = UNTRACED;
3263 pub const NOWAIT = 0x0008;
3264 pub const EXITED = 0x0010;
3265 pub const TRAPPED = 0x0020;
3266
3267 pub fn EXITSTATUS(s: u32) u8 {
3268 return @as(u8, @intCast((s & 0xff00) >> 8));
3269 }
3270 pub fn TERMSIG(s: u32) u32 {
3271 return s & 0x7f;
3272 }
3273 pub fn STOPSIG(s: u32) u32 {
3274 return EXITSTATUS(s);
3275 }
3276 pub fn IFEXITED(s: u32) bool {
3277 return TERMSIG(s) == 0;
3278 }
3279 pub fn IFSTOPPED(s: u32) bool {
3280 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
3281 }
3282 pub fn IFSIGNALED(s: u32) bool {
3283 return (s & 0xffff) -% 1 < 0xff;
3284 }
3285 },
3286 .haiku => struct {
3287 pub const NOHANG = 0x1;
3288 pub const UNTRACED = 0x2;
3289 pub const CONTINUED = 0x4;
3290 pub const EXITED = 0x08;
3291 pub const STOPPED = 0x10;
3292 pub const NOWAIT = 0x20;
3293
3294 pub fn EXITSTATUS(s: u32) u8 {
3295 return @as(u8, @intCast(s & 0xff));
3296 }
3297
3298 pub fn TERMSIG(s: u32) u32 {
3299 return (s >> 8) & 0xff;
3300 }
3301
3302 pub fn STOPSIG(s: u32) u32 {
3303 return (s >> 16) & 0xff;
3304 }
3305
3306 pub fn IFEXITED(s: u32) bool {
3307 return (s & ~@as(u32, 0xff)) == 0;
3308 }
3309
3310 pub fn IFSTOPPED(s: u32) bool {
3311 return ((s >> 16) & 0xff) != 0;
3312 }
3313
3314 pub fn IFSIGNALED(s: u32) bool {
3315 return ((s >> 8) & 0xff) != 0;
3316 }
3317 },
3318 .openbsd => struct {
3319 pub const NOHANG = 1;
3320 pub const UNTRACED = 2;
3321 pub const CONTINUED = 8;
3322
3323 pub fn EXITSTATUS(s: u32) u8 {
3324 return @as(u8, @intCast((s >> 8) & 0xff));
3325 }
3326 pub fn TERMSIG(s: u32) u32 {
3327 return (s & 0x7f);
3328 }
3329 pub fn STOPSIG(s: u32) u32 {
3330 return EXITSTATUS(s);
3331 }
3332 pub fn IFEXITED(s: u32) bool {
3333 return TERMSIG(s) == 0;
3334 }
3335
3336 pub fn IFCONTINUED(s: u32) bool {
3337 return ((s & 0o177777) == 0o177777);
3338 }
3339
3340 pub fn IFSTOPPED(s: u32) bool {
3341 return (s & 0xff == 0o177);
3342 }
3343
3344 pub fn IFSIGNALED(s: u32) bool {
3345 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
3346 }
3347 },
3348 else => void,
3349};
3350pub const clock_t = switch (native_os) {
3351 .linux => linux.clock_t,
3352 .emscripten => emscripten.clock_t,
3353 .macos, .ios, .tvos, .watchos, .visionos => c_ulong,
3354 .freebsd, .kfreebsd => isize,
3355 .openbsd, .solaris, .illumos => i64,
3356 .netbsd => u32,
3357 .haiku => i32,
3358 else => void,
3359};
3360pub const cpu_set_t = switch (native_os) {
3361 .linux => linux.cpu_set_t,
3362 .emscripten => emscripten.cpu_set_t,
3363 else => void,
3364};
3365pub const dl_phdr_info = switch (native_os) {
3366 .linux => linux.dl_phdr_info,
3367 .emscripten => emscripten.dl_phdr_info,
3368 .freebsd, .kfreebsd => extern struct {
3369 /// Module relocation base.
3370 addr: if (builtin.target.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,
3371 /// Module name.
3372 name: ?[*:0]const u8,
3373 /// Pointer to module's phdr.
3374 phdr: [*]std.elf.Phdr,
3375 /// Number of entries in phdr.
3376 phnum: u16,
3377 /// Total number of loads.
3378 adds: u64,
3379 /// Total number of unloads.
3380 subs: u64,
3381 tls_modid: usize,
3382 tls_data: ?*anyopaque,
3383 },
3384 .solaris, .illumos => extern struct {
3385 addr: std.elf.Addr,
3386 name: ?[*:0]const u8,
3387 phdr: [*]std.elf.Phdr,
3388 phnum: std.elf.Half,
3389 /// Incremented when a new object is mapped into the process.
3390 adds: u64,
3391 /// Incremented when an object is unmapped from the process.
3392 subs: u64,
3393 },
3394 .openbsd, .haiku, .dragonfly, .netbsd => extern struct {
3395 addr: usize,
3396 name: ?[*:0]const u8,
3397 phdr: [*]std.elf.Phdr,
3398 phnum: u16,
3399 },
3400 else => void,
3401};
3402pub const epoll_event = switch (native_os) {
3403 .linux => linux.epoll_event,
3404 else => void,
3405};
3406pub const ifreq = switch (native_os) {
3407 .linux => linux.ifreq,
3408 .emscripten => emscripten.ifreq,
3409 .solaris, .illumos => lifreq,
3410 else => void,
3411};
3412pub const itimerspec = switch (native_os) {
3413 .linux => linux.itimerspec,
3414 .haiku => extern struct {
3415 interval: timespec,
3416 value: timespec,
3417 },
3418 else => void,
3419};
3420pub const msghdr = switch (native_os) {
3421 .linux => linux.msghdr,
3422 .openbsd, .emscripten, .dragonfly, .freebsd, .kfreebsd, .netbsd, .haiku, .solaris, .illumos => extern struct {
3423 /// optional address
3424 name: ?*sockaddr,
3425 /// size of address
3426 namelen: socklen_t,
3427 /// scatter/gather array
3428 iov: [*]iovec,
3429 /// # elements in iov
3430 iovlen: i32,
3431 /// ancillary data
3432 control: ?*anyopaque,
3433 /// ancillary data buffer len
3434 controllen: socklen_t,
3435 /// flags on received message
3436 flags: i32,
3437 },
3438 else => void,
3439};
3440pub const msghdr_const = switch (native_os) {
3441 .linux => linux.msghdr_const,
3442 .openbsd, .emscripten, .dragonfly, .freebsd, .kfreebsd, .netbsd, .haiku, .solaris, .illumos => extern struct {
3443 /// optional address
3444 name: ?*const sockaddr,
3445 /// size of address
3446 namelen: socklen_t,
3447 /// scatter/gather array
3448 iov: [*]const iovec_const,
3449 /// # elements in iov
3450 iovlen: i32,
3451 /// ancillary data
3452 control: ?*const anyopaque,
3453 /// ancillary data buffer len
3454 controllen: socklen_t,
3455 /// flags on received message
3456 flags: i32,
3457 },
3458 else => void,
3459};
3460pub const nfds_t = switch (native_os) {
3461 .linux => linux.nfds_t,
3462 .emscripten => emscripten.nfds_t,
3463 .haiku, .solaris, .illumos, .wasi => usize,
3464 .windows => c_ulong,
3465 .openbsd, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => u32,
3466 else => void,
3467};
3468pub const perf_event_attr = switch (native_os) {
3469 .linux => linux.perf_event_attr,
3470 else => void,
3471};
3472pub const pid_t = switch (native_os) {
3473 .linux => linux.pid_t,
3474 .emscripten => emscripten.pid_t,
3475 .windows => windows.HANDLE,
3476 else => i32,
3477};
3478pub const pollfd = switch (native_os) {
3479 .linux => linux.pollfd,
3480 .emscripten => emscripten.pollfd,
3481 .windows => ws2_32.pollfd,
3482 else => extern struct {
3483 fd: fd_t,
3484 events: i16,
3485 revents: i16,
3486 },
3487};
3488pub const rlim_t = switch (native_os) {
3489 .linux => linux.rlim_t,
3490 .emscripten => emscripten.rlim_t,
3491 .openbsd, .netbsd, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => u64,
3492 .haiku, .dragonfly, .freebsd, .kfreebsd => i64,
3493 else => void,
3494};
3495pub const rlimit = switch (native_os) {
3496 .linux, .emscripten => linux.rlimit,
3497 .windows => void,
3498 else => extern struct {
3499 /// Soft limit
3500 cur: rlim_t,
3501 /// Hard limit
3502 max: rlim_t,
3503 },
3504};
3505pub const rlimit_resource = switch (native_os) {
3506 .linux => linux.rlimit_resource,
3507 .emscripten => emscripten.rlimit_resource,
3508 .openbsd, .macos, .ios, .tvos, .watchos, .visionos => enum(c_int) {
3509 CPU = 0,
3510 FSIZE = 1,
3511 DATA = 2,
3512 STACK = 3,
3513 CORE = 4,
3514 RSS = 5,
3515 MEMLOCK = 6,
3516 NPROC = 7,
3517 NOFILE = 8,
3518 _,
3519
3520 pub const AS: rlimit_resource = .RSS;
3521 },
3522 .freebsd, .kfreebsd => enum(c_int) {
3523 CPU = 0,
3524 FSIZE = 1,
3525 DATA = 2,
3526 STACK = 3,
3527 CORE = 4,
3528 RSS = 5,
3529 MEMLOCK = 6,
3530 NPROC = 7,
3531 NOFILE = 8,
3532 SBSIZE = 9,
3533 VMEM = 10,
3534 NPTS = 11,
3535 SWAP = 12,
3536 KQUEUES = 13,
3537 UMTXP = 14,
3538 _,
3539
3540 pub const AS: rlimit_resource = .VMEM;
3541 },
3542 .solaris, .illumos => enum(c_int) {
3543 CPU = 0,
3544 FSIZE = 1,
3545 DATA = 2,
3546 STACK = 3,
3547 CORE = 4,
3548 NOFILE = 5,
3549 VMEM = 6,
3550 _,
3551
3552 pub const AS: rlimit_resource = .VMEM;
3553 },
3554 .netbsd => enum(c_int) {
3555 CPU = 0,
3556 FSIZE = 1,
3557 DATA = 2,
3558 STACK = 3,
3559 CORE = 4,
3560 RSS = 5,
3561 MEMLOCK = 6,
3562 NPROC = 7,
3563 NOFILE = 8,
3564 SBSIZE = 9,
3565 VMEM = 10,
3566 NTHR = 11,
3567 _,
3568
3569 pub const AS: rlimit_resource = .VMEM;
3570 },
3571 .dragonfly => enum(c_int) {
3572 CPU = 0,
3573 FSIZE = 1,
3574 DATA = 2,
3575 STACK = 3,
3576 CORE = 4,
3577 RSS = 5,
3578 MEMLOCK = 6,
3579 NPROC = 7,
3580 NOFILE = 8,
3581 SBSIZE = 9,
3582 VMEM = 10,
3583 POSIXLOCKS = 11,
3584 _,
3585
3586 pub const AS: rlimit_resource = .VMEM;
3587 },
3588 .haiku => enum(i32) {
3589 CORE = 0,
3590 CPU = 1,
3591 DATA = 2,
3592 FSIZE = 3,
3593 NOFILE = 4,
3594 STACK = 5,
3595 AS = 6,
3596 NOVMON = 7,
3597 _,
3598 },
3599 else => void,
3600};
3601pub const rusage = switch (native_os) {
3602 .linux => linux.rusage,
3603 .emscripten => emscripten.rusage,
3604 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
3605 utime: timeval,
3606 stime: timeval,
3607 maxrss: isize,
3608 ixrss: isize,
3609 idrss: isize,
3610 isrss: isize,
3611 minflt: isize,
3612 majflt: isize,
3613 nswap: isize,
3614 inblock: isize,
3615 oublock: isize,
3616 msgsnd: isize,
3617 msgrcv: isize,
3618 nsignals: isize,
3619 nvcsw: isize,
3620 nivcsw: isize,
3621
3622 pub const SELF = 0;
3623 pub const CHILDREN = -1;
3624 },
3625 .solaris, .illumos => extern struct {
3626 utime: timeval,
3627 stime: timeval,
3628 maxrss: isize,
3629 ixrss: isize,
3630 idrss: isize,
3631 isrss: isize,
3632 minflt: isize,
3633 majflt: isize,
3634 nswap: isize,
3635 inblock: isize,
3636 oublock: isize,
3637 msgsnd: isize,
3638 msgrcv: isize,
3639 nsignals: isize,
3640 nvcsw: isize,
3641 nivcsw: isize,
3642
3643 pub const SELF = 0;
3644 pub const CHILDREN = -1;
3645 pub const THREAD = 1;
3646 },
3647 else => void,
3648};
3649
3650pub const siginfo_t = switch (native_os) {
3651 .linux => linux.siginfo_t,
3652 .emscripten => emscripten.siginfo_t,
3653 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
3654 signo: c_int,
3655 errno: c_int,
3656 code: c_int,
3657 pid: pid_t,
3658 uid: uid_t,
3659 status: c_int,
3660 addr: *allowzero anyopaque,
3661 value: extern union {
3662 int: c_int,
3663 ptr: *anyopaque,
3664 },
3665 si_band: c_long,
3666 _pad: [7]c_ulong,
3667 },
3668 .freebsd, .kfreebsd => extern struct {
3669 // Signal number.
3670 signo: c_int,
3671 // Errno association.
3672 errno: c_int,
3673 /// Signal code.
3674 ///
3675 /// Cause of signal, one of the SI_ macros or signal-specific values, i.e.
3676 /// one of the FPE_... values for SIGFPE.
3677 /// This value is equivalent to the second argument to an old-style FreeBSD
3678 /// signal handler.
3679 code: c_int,
3680 /// Sending process.
3681 pid: pid_t,
3682 /// Sender's ruid.
3683 uid: uid_t,
3684 /// Exit value.
3685 status: c_int,
3686 /// Faulting instruction.
3687 addr: *allowzero anyopaque,
3688 /// Signal value.
3689 value: sigval,
3690 reason: extern union {
3691 fault: extern struct {
3692 /// Machine specific trap code.
3693 trapno: c_int,
3694 },
3695 timer: extern struct {
3696 timerid: c_int,
3697 overrun: c_int,
3698 },
3699 mesgq: extern struct {
3700 mqd: c_int,
3701 },
3702 poll: extern struct {
3703 /// Band event for SIGPOLL. UNUSED.
3704 band: c_long,
3705 },
3706 spare: extern struct {
3707 spare1: c_long,
3708 spare2: [7]c_int,
3709 },
3710 },
3711 },
3712 .solaris, .illumos => extern struct {
3713 signo: c_int,
3714 code: c_int,
3715 errno: c_int,
3716 // 64bit architectures insert 4bytes of padding here, this is done by
3717 // correctly aligning the reason field
3718 reason: extern union {
3719 proc: extern struct {
3720 pid: pid_t,
3721 pdata: extern union {
3722 kill: extern struct {
3723 uid: uid_t,
3724 value: sigval_t,
3725 },
3726 cld: extern struct {
3727 utime: clock_t,
3728 status: c_int,
3729 stime: clock_t,
3730 },
3731 },
3732 contract: solaris.ctid_t,
3733 zone: solaris.zoneid_t,
3734 },
3735 fault: extern struct {
3736 addr: *allowzero anyopaque,
3737 trapno: c_int,
3738 pc: ?*anyopaque,
3739 },
3740 file: extern struct {
3741 // fd not currently available for SIGPOLL.
3742 fd: c_int,
3743 band: c_long,
3744 },
3745 prof: extern struct {
3746 addr: ?*anyopaque,
3747 timestamp: timespec,
3748 syscall: c_short,
3749 sysarg: u8,
3750 fault: u8,
3751 args: [8]c_long,
3752 state: [10]c_int,
3753 },
3754 rctl: extern struct {
3755 entity: i32,
3756 },
3757 __pad: [256 - 4 * @sizeOf(c_int)]u8,
3758 } align(@sizeOf(usize)),
3759
3760 comptime {
3761 assert(@sizeOf(@This()) == 256);
3762 assert(@alignOf(@This()) == @sizeOf(usize));
3763 }
3764 },
3765 .netbsd => extern union {
3766 pad: [128]u8,
3767 info: netbsd._ksiginfo,
3768 },
3769 .dragonfly => extern struct {
3770 signo: c_int,
3771 errno: c_int,
3772 code: c_int,
3773 pid: c_int,
3774 uid: uid_t,
3775 status: c_int,
3776 addr: *allowzero anyopaque,
3777 value: sigval,
3778 band: c_long,
3779 __spare__: [7]c_int,
3780 },
3781 .haiku => extern struct {
3782 signo: i32,
3783 code: i32,
3784 errno: i32,
3785
3786 pid: pid_t,
3787 uid: uid_t,
3788 addr: *allowzero anyopaque,
3789 },
3790 .openbsd => extern struct {
3791 signo: c_int,
3792 code: c_int,
3793 errno: c_int,
3794 data: extern union {
3795 proc: extern struct {
3796 pid: pid_t,
3797 pdata: extern union {
3798 kill: extern struct {
3799 uid: uid_t,
3800 value: sigval,
3801 },
3802 cld: extern struct {
3803 utime: clock_t,
3804 stime: clock_t,
3805 status: c_int,
3806 },
3807 },
3808 },
3809 fault: extern struct {
3810 addr: *allowzero anyopaque,
3811 trapno: c_int,
3812 },
3813 __pad: [128 - 3 * @sizeOf(c_int)]u8,
3814 },
3815
3816 comptime {
3817 if (@sizeOf(usize) == 4)
3818 assert(@sizeOf(@This()) == 128)
3819 else
3820 // Take into account the padding between errno and data fields.
3821 assert(@sizeOf(@This()) == 136);
3822 }
3823 },
3824 else => void,
3825};
3826pub const sigset_t = switch (native_os) {
3827 .linux => linux.sigset_t,
3828 .emscripten => emscripten.sigset_t,
3829 .openbsd, .macos, .ios, .tvos, .watchos, .visionos => u32,
3830 .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => extern struct {
3831 __bits: [SIG.WORDS]u32,
3832 },
3833 .haiku => u64,
3834 else => u0,
3835};
3836pub const empty_sigset: sigset_t = switch (native_os) {
3837 .linux => linux.empty_sigset,
3838 .emscripten => emscripten.empty_sigset,
3839 .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .kfreebsd => .{ .__bits = [_]u32{0} ** SIG.WORDS },
3840 else => 0,
3841};
3842pub const filled_sigset = switch (native_os) {
3843 .linux => linux.filled_sigset,
3844 .haiku => ~@as(sigset_t, 0),
3845 else => 0,
3846};
3847pub const sigval = switch (native_os) {
3848 .linux => linux.sigval,
3849 .openbsd, .dragonfly, .freebsd, .kfreebsd => extern union {
3850 int: c_int,
3851 ptr: ?*anyopaque,
3852 },
3853 else => void,
3854};
3855
3856pub const addrinfo = switch (native_os) {
3857 .linux, .emscripten => linux.addrinfo,
3858 .windows => ws2_32.addrinfo,
3859 .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
3860 flags: AI,
3861 family: i32,
3862 socktype: i32,
3863 protocol: i32,
3864 addrlen: socklen_t,
3865 canonname: ?[*:0]u8,
3866 addr: ?*sockaddr,
3867 next: ?*addrinfo,
3868 },
3869 .solaris, .illumos => extern struct {
3870 flags: AI,
3871 family: i32,
3872 socktype: i32,
3873 protocol: i32,
3874 addrlen: socklen_t,
3875 canonname: ?[*:0]u8,
3876 addr: ?*sockaddr,
3877 next: ?*addrinfo,
3878 },
3879 .netbsd => extern struct {
3880 flags: AI,
3881 family: i32,
3882 socktype: i32,
3883 protocol: i32,
3884 addrlen: socklen_t,
3885 canonname: ?[*:0]u8,
3886 addr: ?*sockaddr,
3887 next: ?*addrinfo,
3888 },
3889 .dragonfly => extern struct {
3890 flags: AI,
3891 family: i32,
3892 socktype: i32,
3893 protocol: i32,
3894 addrlen: socklen_t,
3895 canonname: ?[*:0]u8,
3896 addr: ?*sockaddr,
3897 next: ?*addrinfo,
3898 },
3899 .haiku => extern struct {
3900 flags: AI,
3901 family: i32,
3902 socktype: i32,
3903 protocol: i32,
3904 addrlen: socklen_t,
3905 canonname: ?[*:0]u8,
3906 addr: ?*sockaddr,
3907 next: ?*addrinfo,
3908 },
3909 .openbsd => extern struct {
3910 flags: AI,
3911 family: c_int,
3912 socktype: c_int,
3913 protocol: c_int,
3914 addrlen: socklen_t,
3915 addr: ?*sockaddr,
3916 canonname: ?[*:0]u8,
3917 next: ?*addrinfo,
3918 },
3919 else => void,
3920};
3921pub const sockaddr = switch (native_os) {
3922 .linux, .emscripten => linux.sockaddr,
3923 .windows => ws2_32.sockaddr,
3924 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
3925 len: u8,
3926 family: sa_family_t,
3927 data: [14]u8,
3928
3929 pub const SS_MAXSIZE = 128;
3930 pub const storage = extern struct {
3931 len: u8 align(8),
3932 family: sa_family_t,
3933 padding: [126]u8 = undefined,
3934
3935 comptime {
3936 assert(@sizeOf(storage) == SS_MAXSIZE);
3937 assert(@alignOf(storage) == 8);
3938 }
3939 };
3940 pub const in = extern struct {
3941 len: u8 = @sizeOf(in),
3942 family: sa_family_t = AF.INET,
3943 port: in_port_t,
3944 addr: u32,
3945 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
3946 };
3947 pub const in6 = extern struct {
3948 len: u8 = @sizeOf(in6),
3949 family: sa_family_t = AF.INET6,
3950 port: in_port_t,
3951 flowinfo: u32,
3952 addr: [16]u8,
3953 scope_id: u32,
3954 };
3955
3956 /// UNIX domain socket
3957 pub const un = extern struct {
3958 len: u8 = @sizeOf(un),
3959 family: sa_family_t = AF.UNIX,
3960 path: [104]u8,
3961 };
3962 },
3963 .freebsd, .kfreebsd => extern struct {
3964 /// total length
3965 len: u8,
3966 /// address family
3967 family: sa_family_t,
3968 /// actually longer; address value
3969 data: [14]u8,
3970
3971 pub const SS_MAXSIZE = 128;
3972 pub const storage = extern struct {
3973 len: u8 align(8),
3974 family: sa_family_t,
3975 padding: [126]u8 = undefined,
3976
3977 comptime {
3978 assert(@sizeOf(storage) == SS_MAXSIZE);
3979 assert(@alignOf(storage) == 8);
3980 }
3981 };
3982
3983 pub const in = extern struct {
3984 len: u8 = @sizeOf(in),
3985 family: sa_family_t = AF.INET,
3986 port: in_port_t,
3987 addr: u32,
3988 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
3989 };
3990
3991 pub const in6 = extern struct {
3992 len: u8 = @sizeOf(in6),
3993 family: sa_family_t = AF.INET6,
3994 port: in_port_t,
3995 flowinfo: u32,
3996 addr: [16]u8,
3997 scope_id: u32,
3998 };
3999
4000 pub const un = extern struct {
4001 len: u8 = @sizeOf(un),
4002 family: sa_family_t = AF.UNIX,
4003 path: [104]u8,
4004 };
4005 },
4006 .solaris, .illumos => extern struct {
4007 /// address family
4008 family: sa_family_t,
4009
4010 /// actually longer; address value
4011 data: [14]u8,
4012
4013 pub const SS_MAXSIZE = 256;
4014 pub const storage = extern struct {
4015 family: sa_family_t align(8),
4016 padding: [254]u8 = undefined,
4017
4018 comptime {
4019 assert(@sizeOf(storage) == SS_MAXSIZE);
4020 assert(@alignOf(storage) == 8);
4021 }
4022 };
4023
4024 pub const in = extern struct {
4025 family: sa_family_t = AF.INET,
4026 port: in_port_t,
4027 addr: u32,
4028 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4029 };
4030
4031 pub const in6 = extern struct {
4032 family: sa_family_t = AF.INET6,
4033 port: in_port_t,
4034 flowinfo: u32,
4035 addr: [16]u8,
4036 scope_id: u32,
4037 __src_id: u32 = 0,
4038 };
4039
4040 /// Definitions for UNIX IPC domain.
4041 pub const un = extern struct {
4042 family: sa_family_t = AF.UNIX,
4043 path: [108]u8,
4044 };
4045 },
4046 .netbsd => extern struct {
4047 /// total length
4048 len: u8,
4049 /// address family
4050 family: sa_family_t,
4051 /// actually longer; address value
4052 data: [14]u8,
4053
4054 pub const SS_MAXSIZE = 128;
4055 pub const storage = extern struct {
4056 len: u8 align(8),
4057 family: sa_family_t,
4058 padding: [126]u8 = undefined,
4059
4060 comptime {
4061 assert(@sizeOf(storage) == SS_MAXSIZE);
4062 assert(@alignOf(storage) == 8);
4063 }
4064 };
4065
4066 pub const in = extern struct {
4067 len: u8 = @sizeOf(in),
4068 family: sa_family_t = AF.INET,
4069 port: in_port_t,
4070 addr: u32,
4071 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4072 };
4073
4074 pub const in6 = extern struct {
4075 len: u8 = @sizeOf(in6),
4076 family: sa_family_t = AF.INET6,
4077 port: in_port_t,
4078 flowinfo: u32,
4079 addr: [16]u8,
4080 scope_id: u32,
4081 };
4082
4083 /// Definitions for UNIX IPC domain.
4084 pub const un = extern struct {
4085 /// total sockaddr length
4086 len: u8 = @sizeOf(un),
4087
4088 family: sa_family_t = AF.LOCAL,
4089
4090 /// path name
4091 path: [104]u8,
4092 };
4093 },
4094 .dragonfly => extern struct {
4095 len: u8,
4096 family: sa_family_t,
4097 data: [14]u8,
4098
4099 pub const SS_MAXSIZE = 128;
4100 pub const storage = extern struct {
4101 len: u8 align(8),
4102 family: sa_family_t,
4103 padding: [126]u8 = undefined,
4104
4105 comptime {
4106 assert(@sizeOf(storage) == SS_MAXSIZE);
4107 assert(@alignOf(storage) == 8);
4108 }
4109 };
4110
4111 pub const in = extern struct {
4112 len: u8 = @sizeOf(in),
4113 family: sa_family_t = AF.INET,
4114 port: in_port_t,
4115 addr: u32,
4116 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4117 };
4118
4119 pub const in6 = extern struct {
4120 len: u8 = @sizeOf(in6),
4121 family: sa_family_t = AF.INET6,
4122 port: in_port_t,
4123 flowinfo: u32,
4124 addr: [16]u8,
4125 scope_id: u32,
4126 };
4127
4128 pub const un = extern struct {
4129 len: u8 = @sizeOf(un),
4130 family: sa_family_t = AF.UNIX,
4131 path: [104]u8,
4132 };
4133 },
4134 .haiku => extern struct {
4135 /// total length
4136 len: u8,
4137 /// address family
4138 family: sa_family_t,
4139 /// actually longer; address value
4140 data: [14]u8,
4141
4142 pub const SS_MAXSIZE = 128;
4143 pub const storage = extern struct {
4144 len: u8 align(8),
4145 family: sa_family_t,
4146 padding: [126]u8 = undefined,
4147
4148 comptime {
4149 assert(@sizeOf(storage) == SS_MAXSIZE);
4150 assert(@alignOf(storage) == 8);
4151 }
4152 };
4153
4154 pub const in = extern struct {
4155 len: u8 = @sizeOf(in),
4156 family: sa_family_t = AF.INET,
4157 port: in_port_t,
4158 addr: u32,
4159 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4160 };
4161
4162 pub const in6 = extern struct {
4163 len: u8 = @sizeOf(in6),
4164 family: sa_family_t = AF.INET6,
4165 port: in_port_t,
4166 flowinfo: u32,
4167 addr: [16]u8,
4168 scope_id: u32,
4169 };
4170
4171 pub const un = extern struct {
4172 len: u8 = @sizeOf(un),
4173 family: sa_family_t = AF.UNIX,
4174 path: [104]u8,
4175 };
4176 },
4177 .openbsd => extern struct {
4178 /// total length
4179 len: u8,
4180 /// address family
4181 family: sa_family_t,
4182 /// actually longer; address value
4183 data: [14]u8,
4184
4185 pub const SS_MAXSIZE = 256;
4186 pub const storage = extern struct {
4187 len: u8 align(8),
4188 family: sa_family_t,
4189 padding: [254]u8 = undefined,
4190
4191 comptime {
4192 assert(@sizeOf(storage) == SS_MAXSIZE);
4193 assert(@alignOf(storage) == 8);
4194 }
4195 };
4196
4197 pub const in = extern struct {
4198 len: u8 = @sizeOf(in),
4199 family: sa_family_t = AF.INET,
4200 port: in_port_t,
4201 addr: u32,
4202 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
4203 };
4204
4205 pub const in6 = extern struct {
4206 len: u8 = @sizeOf(in6),
4207 family: sa_family_t = AF.INET6,
4208 port: in_port_t,
4209 flowinfo: u32,
4210 addr: [16]u8,
4211 scope_id: u32,
4212 };
4213
4214 /// Definitions for UNIX IPC domain.
4215 pub const un = extern struct {
4216 /// total sockaddr length
4217 len: u8 = @sizeOf(un),
4218
4219 family: sa_family_t = AF.LOCAL,
4220
4221 /// path name
4222 path: [104]u8,
4223 };
4224 },
4225 else => void,
4226};
4227pub const socklen_t = switch (native_os) {
4228 .linux, .emscripten => linux.socklen_t,
4229 .windows => ws2_32.socklen_t,
4230 else => u32,
4231};
4232pub const in_port_t = u16;
4233pub const sa_family_t = switch (native_os) {
4234 .linux, .emscripten => linux.sa_family_t,
4235 .windows => ws2_32.ADDRESS_FAMILY,
4236 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => u8,
4237 .solaris, .illumos => u16,
4238 else => void,
4239};
4240pub const AF = switch (native_os) {
4241 .linux, .emscripten => linux.AF,
4242 .windows => ws2_32.AF,
4243 .macos, .ios, .tvos, .watchos, .visionos => struct {
4244 pub const UNSPEC = 0;
4245 pub const LOCAL = 1;
4246 pub const UNIX = LOCAL;
4247 pub const INET = 2;
4248 pub const SYS_CONTROL = 2;
4249 pub const IMPLINK = 3;
4250 pub const PUP = 4;
4251 pub const CHAOS = 5;
4252 pub const NS = 6;
4253 pub const ISO = 7;
4254 pub const OSI = ISO;
4255 pub const ECMA = 8;
4256 pub const DATAKIT = 9;
4257 pub const CCITT = 10;
4258 pub const SNA = 11;
4259 pub const DECnet = 12;
4260 pub const DLI = 13;
4261 pub const LAT = 14;
4262 pub const HYLINK = 15;
4263 pub const APPLETALK = 16;
4264 pub const ROUTE = 17;
4265 pub const LINK = 18;
4266 pub const XTP = 19;
4267 pub const COIP = 20;
4268 pub const CNT = 21;
4269 pub const RTIP = 22;
4270 pub const IPX = 23;
4271 pub const SIP = 24;
4272 pub const PIP = 25;
4273 pub const ISDN = 28;
4274 pub const E164 = ISDN;
4275 pub const KEY = 29;
4276 pub const INET6 = 30;
4277 pub const NATM = 31;
4278 pub const SYSTEM = 32;
4279 pub const NETBIOS = 33;
4280 pub const PPP = 34;
4281 pub const MAX = 40;
4282 },
4283 .freebsd, .kfreebsd => struct {
4284 pub const UNSPEC = 0;
4285 pub const UNIX = 1;
4286 pub const LOCAL = UNIX;
4287 pub const FILE = LOCAL;
4288 pub const INET = 2;
4289 pub const IMPLINK = 3;
4290 pub const PUP = 4;
4291 pub const CHAOS = 5;
4292 pub const NETBIOS = 6;
4293 pub const ISO = 7;
4294 pub const OSI = ISO;
4295 pub const ECMA = 8;
4296 pub const DATAKIT = 9;
4297 pub const CCITT = 10;
4298 pub const SNA = 11;
4299 pub const DECnet = 12;
4300 pub const DLI = 13;
4301 pub const LAT = 14;
4302 pub const HYLINK = 15;
4303 pub const APPLETALK = 16;
4304 pub const ROUTE = 17;
4305 pub const LINK = 18;
4306 pub const pseudo_XTP = 19;
4307 pub const COIP = 20;
4308 pub const CNT = 21;
4309 pub const pseudo_RTIP = 22;
4310 pub const IPX = 23;
4311 pub const SIP = 24;
4312 pub const pseudo_PIP = 25;
4313 pub const ISDN = 26;
4314 pub const E164 = ISDN;
4315 pub const pseudo_KEY = 27;
4316 pub const INET6 = 28;
4317 pub const NATM = 29;
4318 pub const ATM = 30;
4319 pub const pseudo_HDRCMPLT = 31;
4320 pub const NETGRAPH = 32;
4321 pub const SLOW = 33;
4322 pub const SCLUSTER = 34;
4323 pub const ARP = 35;
4324 pub const BLUETOOTH = 36;
4325 pub const IEEE80211 = 37;
4326 pub const INET_SDP = 40;
4327 pub const INET6_SDP = 42;
4328 pub const MAX = 42;
4329 },
4330 .solaris, .illumos => struct {
4331 pub const UNSPEC = 0;
4332 pub const UNIX = 1;
4333 pub const LOCAL = UNIX;
4334 pub const FILE = UNIX;
4335 pub const INET = 2;
4336 pub const IMPLINK = 3;
4337 pub const PUP = 4;
4338 pub const CHAOS = 5;
4339 pub const NS = 6;
4340 pub const NBS = 7;
4341 pub const ECMA = 8;
4342 pub const DATAKIT = 9;
4343 pub const CCITT = 10;
4344 pub const SNA = 11;
4345 pub const DECnet = 12;
4346 pub const DLI = 13;
4347 pub const LAT = 14;
4348 pub const HYLINK = 15;
4349 pub const APPLETALK = 16;
4350 pub const NIT = 17;
4351 pub const @"802" = 18;
4352 pub const OSI = 19;
4353 pub const X25 = 20;
4354 pub const OSINET = 21;
4355 pub const GOSIP = 22;
4356 pub const IPX = 23;
4357 pub const ROUTE = 24;
4358 pub const LINK = 25;
4359 pub const INET6 = 26;
4360 pub const KEY = 27;
4361 pub const NCA = 28;
4362 pub const POLICY = 29;
4363 pub const INET_OFFLOAD = 30;
4364 pub const TRILL = 31;
4365 pub const PACKET = 32;
4366 pub const LX_NETLINK = 33;
4367 pub const MAX = 33;
4368 },
4369 .netbsd => struct {
4370 pub const UNSPEC = 0;
4371 pub const LOCAL = 1;
4372 pub const UNIX = LOCAL;
4373 pub const INET = 2;
4374 pub const IMPLINK = 3;
4375 pub const PUP = 4;
4376 pub const CHAOS = 5;
4377 pub const NS = 6;
4378 pub const ISO = 7;
4379 pub const OSI = ISO;
4380 pub const ECMA = 8;
4381 pub const DATAKIT = 9;
4382 pub const CCITT = 10;
4383 pub const SNA = 11;
4384 pub const DECnet = 12;
4385 pub const DLI = 13;
4386 pub const LAT = 14;
4387 pub const HYLINK = 15;
4388 pub const APPLETALK = 16;
4389 pub const OROUTE = 17;
4390 pub const LINK = 18;
4391 pub const COIP = 20;
4392 pub const CNT = 21;
4393 pub const IPX = 23;
4394 pub const INET6 = 24;
4395 pub const ISDN = 26;
4396 pub const E164 = ISDN;
4397 pub const NATM = 27;
4398 pub const ARP = 28;
4399 pub const BLUETOOTH = 31;
4400 pub const IEEE80211 = 32;
4401 pub const MPLS = 33;
4402 pub const ROUTE = 34;
4403 pub const CAN = 35;
4404 pub const ETHER = 36;
4405 pub const MAX = 37;
4406 },
4407 .dragonfly => struct {
4408 pub const UNSPEC = 0;
4409 pub const OSI = ISO;
4410 pub const UNIX = LOCAL;
4411 pub const LOCAL = 1;
4412 pub const INET = 2;
4413 pub const IMPLINK = 3;
4414 pub const PUP = 4;
4415 pub const CHAOS = 5;
4416 pub const NETBIOS = 6;
4417 pub const ISO = 7;
4418 pub const ECMA = 8;
4419 pub const DATAKIT = 9;
4420 pub const CCITT = 10;
4421 pub const SNA = 11;
4422 pub const DLI = 13;
4423 pub const LAT = 14;
4424 pub const HYLINK = 15;
4425 pub const APPLETALK = 16;
4426 pub const ROUTE = 17;
4427 pub const LINK = 18;
4428 pub const COIP = 20;
4429 pub const CNT = 21;
4430 pub const IPX = 23;
4431 pub const SIP = 24;
4432 pub const ISDN = 26;
4433 pub const INET6 = 28;
4434 pub const NATM = 29;
4435 pub const ATM = 30;
4436 pub const NETGRAPH = 32;
4437 pub const BLUETOOTH = 33;
4438 pub const MPLS = 34;
4439 pub const MAX = 36;
4440 },
4441 .haiku => struct {
4442 pub const UNSPEC = 0;
4443 pub const INET = 1;
4444 pub const APPLETALK = 2;
4445 pub const ROUTE = 3;
4446 pub const LINK = 4;
4447 pub const INET6 = 5;
4448 pub const DLI = 6;
4449 pub const IPX = 7;
4450 pub const NOTIFY = 8;
4451 pub const LOCAL = 9;
4452 pub const UNIX = LOCAL;
4453 pub const BLUETOOTH = 10;
4454 pub const MAX = 11;
4455 },
4456 .openbsd => struct {
4457 pub const UNSPEC = 0;
4458 pub const UNIX = 1;
4459 pub const LOCAL = UNIX;
4460 pub const INET = 2;
4461 pub const APPLETALK = 16;
4462 pub const INET6 = 24;
4463 pub const KEY = 30;
4464 pub const ROUTE = 17;
4465 pub const SNA = 11;
4466 pub const MPLS = 33;
4467 pub const BLUETOOTH = 32;
4468 pub const ISDN = 26;
4469 pub const MAX = 36;
4470 },
4471 else => void,
4472};
4473pub const PF = switch (native_os) {
4474 .linux, .emscripten => linux.PF,
4475 .macos, .ios, .tvos, .watchos, .visionos => struct {
4476 pub const UNSPEC = AF.UNSPEC;
4477 pub const LOCAL = AF.LOCAL;
4478 pub const UNIX = PF.LOCAL;
4479 pub const INET = AF.INET;
4480 pub const IMPLINK = AF.IMPLINK;
4481 pub const PUP = AF.PUP;
4482 pub const CHAOS = AF.CHAOS;
4483 pub const NS = AF.NS;
4484 pub const ISO = AF.ISO;
4485 pub const OSI = AF.ISO;
4486 pub const ECMA = AF.ECMA;
4487 pub const DATAKIT = AF.DATAKIT;
4488 pub const CCITT = AF.CCITT;
4489 pub const SNA = AF.SNA;
4490 pub const DECnet = AF.DECnet;
4491 pub const DLI = AF.DLI;
4492 pub const LAT = AF.LAT;
4493 pub const HYLINK = AF.HYLINK;
4494 pub const APPLETALK = AF.APPLETALK;
4495 pub const ROUTE = AF.ROUTE;
4496 pub const LINK = AF.LINK;
4497 pub const XTP = AF.XTP;
4498 pub const COIP = AF.COIP;
4499 pub const CNT = AF.CNT;
4500 pub const SIP = AF.SIP;
4501 pub const IPX = AF.IPX;
4502 pub const RTIP = AF.RTIP;
4503 pub const PIP = AF.PIP;
4504 pub const ISDN = AF.ISDN;
4505 pub const KEY = AF.KEY;
4506 pub const INET6 = AF.INET6;
4507 pub const NATM = AF.NATM;
4508 pub const SYSTEM = AF.SYSTEM;
4509 pub const NETBIOS = AF.NETBIOS;
4510 pub const PPP = AF.PPP;
4511 pub const MAX = AF.MAX;
4512 },
4513 .freebsd, .kfreebsd => struct {
4514 pub const UNSPEC = AF.UNSPEC;
4515 pub const LOCAL = AF.LOCAL;
4516 pub const UNIX = PF.LOCAL;
4517 pub const INET = AF.INET;
4518 pub const IMPLINK = AF.IMPLINK;
4519 pub const PUP = AF.PUP;
4520 pub const CHAOS = AF.CHAOS;
4521 pub const NETBIOS = AF.NETBIOS;
4522 pub const ISO = AF.ISO;
4523 pub const OSI = AF.ISO;
4524 pub const ECMA = AF.ECMA;
4525 pub const DATAKIT = AF.DATAKIT;
4526 pub const CCITT = AF.CCITT;
4527 pub const DECnet = AF.DECnet;
4528 pub const DLI = AF.DLI;
4529 pub const LAT = AF.LAT;
4530 pub const HYLINK = AF.HYLINK;
4531 pub const APPLETALK = AF.APPLETALK;
4532 pub const ROUTE = AF.ROUTE;
4533 pub const LINK = AF.LINK;
4534 pub const XTP = AF.pseudo_XTP;
4535 pub const COIP = AF.COIP;
4536 pub const CNT = AF.CNT;
4537 pub const SIP = AF.SIP;
4538 pub const IPX = AF.IPX;
4539 pub const RTIP = AF.pseudo_RTIP;
4540 pub const PIP = AF.pseudo_PIP;
4541 pub const ISDN = AF.ISDN;
4542 pub const KEY = AF.pseudo_KEY;
4543 pub const INET6 = AF.pseudo_INET6;
4544 pub const NATM = AF.NATM;
4545 pub const ATM = AF.ATM;
4546 pub const NETGRAPH = AF.NETGRAPH;
4547 pub const SLOW = AF.SLOW;
4548 pub const SCLUSTER = AF.SCLUSTER;
4549 pub const ARP = AF.ARP;
4550 pub const BLUETOOTH = AF.BLUETOOTH;
4551 pub const IEEE80211 = AF.IEEE80211;
4552 pub const INET_SDP = AF.INET_SDP;
4553 pub const INET6_SDP = AF.INET6_SDP;
4554 pub const MAX = AF.MAX;
4555 },
4556 .solaris, .illumos => struct {
4557 pub const UNSPEC = AF.UNSPEC;
4558 pub const UNIX = AF.UNIX;
4559 pub const LOCAL = UNIX;
4560 pub const FILE = UNIX;
4561 pub const INET = AF.INET;
4562 pub const IMPLINK = AF.IMPLINK;
4563 pub const PUP = AF.PUP;
4564 pub const CHAOS = AF.CHAOS;
4565 pub const NS = AF.NS;
4566 pub const NBS = AF.NBS;
4567 pub const ECMA = AF.ECMA;
4568 pub const DATAKIT = AF.DATAKIT;
4569 pub const CCITT = AF.CCITT;
4570 pub const SNA = AF.SNA;
4571 pub const DECnet = AF.DECnet;
4572 pub const DLI = AF.DLI;
4573 pub const LAT = AF.LAT;
4574 pub const HYLINK = AF.HYLINK;
4575 pub const APPLETALK = AF.APPLETALK;
4576 pub const NIT = AF.NIT;
4577 pub const @"802" = AF.@"802";
4578 pub const OSI = AF.OSI;
4579 pub const X25 = AF.X25;
4580 pub const OSINET = AF.OSINET;
4581 pub const GOSIP = AF.GOSIP;
4582 pub const IPX = AF.IPX;
4583 pub const ROUTE = AF.ROUTE;
4584 pub const LINK = AF.LINK;
4585 pub const INET6 = AF.INET6;
4586 pub const KEY = AF.KEY;
4587 pub const NCA = AF.NCA;
4588 pub const POLICY = AF.POLICY;
4589 pub const TRILL = AF.TRILL;
4590 pub const PACKET = AF.PACKET;
4591 pub const LX_NETLINK = AF.LX_NETLINK;
4592 pub const MAX = AF.MAX;
4593 },
4594 .netbsd => struct {
4595 pub const UNSPEC = AF.UNSPEC;
4596 pub const LOCAL = AF.LOCAL;
4597 pub const UNIX = PF.LOCAL;
4598 pub const INET = AF.INET;
4599 pub const IMPLINK = AF.IMPLINK;
4600 pub const PUP = AF.PUP;
4601 pub const CHAOS = AF.CHAOS;
4602 pub const NS = AF.NS;
4603 pub const ISO = AF.ISO;
4604 pub const OSI = AF.ISO;
4605 pub const ECMA = AF.ECMA;
4606 pub const DATAKIT = AF.DATAKIT;
4607 pub const CCITT = AF.CCITT;
4608 pub const SNA = AF.SNA;
4609 pub const DECnet = AF.DECnet;
4610 pub const DLI = AF.DLI;
4611 pub const LAT = AF.LAT;
4612 pub const HYLINK = AF.HYLINK;
4613 pub const APPLETALK = AF.APPLETALK;
4614 pub const OROUTE = AF.OROUTE;
4615 pub const LINK = AF.LINK;
4616 pub const COIP = AF.COIP;
4617 pub const CNT = AF.CNT;
4618 pub const INET6 = AF.INET6;
4619 pub const IPX = AF.IPX;
4620 pub const ISDN = AF.ISDN;
4621 pub const E164 = AF.E164;
4622 pub const NATM = AF.NATM;
4623 pub const ARP = AF.ARP;
4624 pub const BLUETOOTH = AF.BLUETOOTH;
4625 pub const MPLS = AF.MPLS;
4626 pub const ROUTE = AF.ROUTE;
4627 pub const CAN = AF.CAN;
4628 pub const ETHER = AF.ETHER;
4629 pub const MAX = AF.MAX;
4630 },
4631 .dragonfly => struct {
4632 pub const INET6 = AF.INET6;
4633 pub const IMPLINK = AF.IMPLINK;
4634 pub const ROUTE = AF.ROUTE;
4635 pub const ISO = AF.ISO;
4636 pub const PIP = AF.pseudo_PIP;
4637 pub const CHAOS = AF.CHAOS;
4638 pub const DATAKIT = AF.DATAKIT;
4639 pub const INET = AF.INET;
4640 pub const APPLETALK = AF.APPLETALK;
4641 pub const SIP = AF.SIP;
4642 pub const OSI = AF.ISO;
4643 pub const CNT = AF.CNT;
4644 pub const LINK = AF.LINK;
4645 pub const HYLINK = AF.HYLINK;
4646 pub const MAX = AF.MAX;
4647 pub const KEY = AF.pseudo_KEY;
4648 pub const PUP = AF.PUP;
4649 pub const COIP = AF.COIP;
4650 pub const SNA = AF.SNA;
4651 pub const LOCAL = AF.LOCAL;
4652 pub const NETBIOS = AF.NETBIOS;
4653 pub const NATM = AF.NATM;
4654 pub const BLUETOOTH = AF.BLUETOOTH;
4655 pub const UNSPEC = AF.UNSPEC;
4656 pub const NETGRAPH = AF.NETGRAPH;
4657 pub const ECMA = AF.ECMA;
4658 pub const IPX = AF.IPX;
4659 pub const DLI = AF.DLI;
4660 pub const ATM = AF.ATM;
4661 pub const CCITT = AF.CCITT;
4662 pub const ISDN = AF.ISDN;
4663 pub const RTIP = AF.pseudo_RTIP;
4664 pub const LAT = AF.LAT;
4665 pub const UNIX = PF.LOCAL;
4666 pub const XTP = AF.pseudo_XTP;
4667 pub const DECnet = AF.DECnet;
4668 },
4669 .haiku => struct {
4670 pub const UNSPEC = AF.UNSPEC;
4671 pub const INET = AF.INET;
4672 pub const ROUTE = AF.ROUTE;
4673 pub const LINK = AF.LINK;
4674 pub const INET6 = AF.INET6;
4675 pub const LOCAL = AF.LOCAL;
4676 pub const UNIX = AF.UNIX;
4677 pub const BLUETOOTH = AF.BLUETOOTH;
4678 },
4679 .openbsd => struct {
4680 pub const UNSPEC = AF.UNSPEC;
4681 pub const LOCAL = AF.LOCAL;
4682 pub const UNIX = AF.UNIX;
4683 pub const INET = AF.INET;
4684 pub const APPLETALK = AF.APPLETALK;
4685 pub const INET6 = AF.INET6;
4686 pub const DECnet = AF.DECnet;
4687 pub const KEY = AF.KEY;
4688 pub const ROUTE = AF.ROUTE;
4689 pub const SNA = AF.SNA;
4690 pub const MPLS = AF.MPLS;
4691 pub const BLUETOOTH = AF.BLUETOOTH;
4692 pub const ISDN = AF.ISDN;
4693 pub const MAX = AF.MAX;
4694 },
4695 else => void,
4696};
4697pub const DT = switch (native_os) {
4698 .linux => linux.DT,
4699 .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
4700 pub const UNKNOWN = 0;
4701 pub const FIFO = 1;
4702 pub const CHR = 2;
4703 pub const DIR = 4;
4704 pub const BLK = 6;
4705 pub const REG = 8;
4706 pub const LNK = 10;
4707 pub const SOCK = 12;
4708 pub const WHT = 14;
4709 },
4710 .dragonfly => struct {
4711 pub const UNKNOWN = 0;
4712 pub const FIFO = 1;
4713 pub const CHR = 2;
4714 pub const DIR = 4;
4715 pub const BLK = 6;
4716 pub const REG = 8;
4717 pub const LNK = 10;
4718 pub const SOCK = 12;
4719 pub const WHT = 14;
4720 pub const DBF = 15;
4721 },
4722 .openbsd => struct {
4723 pub const UNKNOWN = 0;
4724 pub const FIFO = 1;
4725 pub const CHR = 2;
4726 pub const DIR = 4;
4727 pub const BLK = 6;
4728 pub const REG = 8;
4729 pub const LNK = 10;
4730 pub const SOCK = 12;
4731 pub const WHT = 14; // XXX
4732 },
4733 else => void,
4734};
4735pub const MSG = switch (native_os) {
4736 .linux => linux.MSG,
4737 .emscripten => emscripten.MSG,
4738 .windows => ws2_32.MSG,
4739 .haiku => struct {
4740 pub const OOB = 0x0001;
4741 pub const PEEK = 0x0002;
4742 pub const DONTROUTE = 0x0004;
4743 pub const EOR = 0x0008;
4744 pub const TRUNC = 0x0010;
4745 pub const CTRUNC = 0x0020;
4746 pub const WAITALL = 0x0040;
4747 pub const DONTWAIT = 0x0080;
4748 pub const BCAST = 0x0100;
4749 pub const MCAST = 0x0200;
4750 pub const EOF = 0x0400;
4751 pub const NOSIGNAL = 0x0800;
4752 },
4753 else => void,
4754};
4755pub const SOCK = switch (native_os) {
4756 .linux => linux.SOCK,
4757 .emscripten => emscripten.SOCK,
4758 .windows => ws2_32.SOCK,
4759 .macos, .ios, .tvos, .watchos, .visionos => struct {
4760 pub const STREAM = 1;
4761 pub const DGRAM = 2;
4762 pub const RAW = 3;
4763 pub const RDM = 4;
4764 pub const SEQPACKET = 5;
4765 pub const MAXADDRLEN = 255;
4766
4767 /// Not actually supported by Darwin, but Zig supplies a shim.
4768 /// This numerical value is not ABI-stable. It need only not conflict
4769 /// with any other `SOCK` bits.
4770 pub const CLOEXEC = 1 << 15;
4771 /// Not actually supported by Darwin, but Zig supplies a shim.
4772 /// This numerical value is not ABI-stable. It need only not conflict
4773 /// with any other `SOCK` bits.
4774 pub const NONBLOCK = 1 << 16;
4775 },
4776 .freebsd, .kfreebsd => struct {
4777 pub const STREAM = 1;
4778 pub const DGRAM = 2;
4779 pub const RAW = 3;
4780 pub const RDM = 4;
4781 pub const SEQPACKET = 5;
4782
4783 pub const CLOEXEC = 0x10000000;
4784 pub const NONBLOCK = 0x20000000;
4785 },
4786 .solaris, .illumos => struct {
4787 /// Datagram.
4788 pub const DGRAM = 1;
4789 /// STREAM.
4790 pub const STREAM = 2;
4791 /// Raw-protocol interface.
4792 pub const RAW = 4;
4793 /// Reliably-delivered message.
4794 pub const RDM = 5;
4795 /// Sequenced packed stream.
4796 pub const SEQPACKET = 6;
4797
4798 pub const NONBLOCK = 0x100000;
4799 pub const NDELAY = 0x200000;
4800 pub const CLOEXEC = 0x080000;
4801 },
4802 .netbsd => struct {
4803 pub const STREAM = 1;
4804 pub const DGRAM = 2;
4805 pub const RAW = 3;
4806 pub const RDM = 4;
4807 pub const SEQPACKET = 5;
4808 pub const CONN_DGRAM = 6;
4809 pub const DCCP = CONN_DGRAM;
4810
4811 pub const CLOEXEC = 0x10000000;
4812 pub const NONBLOCK = 0x20000000;
4813 pub const NOSIGPIPE = 0x40000000;
4814 pub const FLAGS_MASK = 0xf0000000;
4815 },
4816 .dragonfly => struct {
4817 pub const STREAM = 1;
4818 pub const DGRAM = 2;
4819 pub const RAW = 3;
4820 pub const RDM = 4;
4821 pub const SEQPACKET = 5;
4822 pub const MAXADDRLEN = 255;
4823 pub const CLOEXEC = 0x10000000;
4824 pub const NONBLOCK = 0x20000000;
4825 },
4826 .haiku => struct {
4827 pub const STREAM = 1;
4828 pub const DGRAM = 2;
4829 pub const RAW = 3;
4830 pub const SEQPACKET = 5;
4831 pub const MISC = 255;
4832 },
4833 .openbsd => struct {
4834 pub const STREAM = 1;
4835 pub const DGRAM = 2;
4836 pub const RAW = 3;
4837 pub const RDM = 4;
4838 pub const SEQPACKET = 5;
4839
4840 pub const CLOEXEC = 0x8000;
4841 pub const NONBLOCK = 0x4000;
4842 },
4843 else => void,
4844};
4845pub const TCP = switch (native_os) {
4846 .linux => linux.TCP,
4847 .emscripten => emscripten.TCP,
4848 .windows => ws2_32.TCP,
4849 else => void,
4850};
4851pub const IPPROTO = switch (native_os) {
4852 .linux, .emscripten => linux.IPPROTO,
4853 .windows => ws2_32.IPPROTO,
4854 .macos, .ios, .tvos, .watchos, .visionos => struct {
4855 pub const ICMP = 1;
4856 pub const ICMPV6 = 58;
4857 pub const TCP = 6;
4858 pub const UDP = 17;
4859 pub const IP = 0;
4860 pub const IPV6 = 41;
4861 },
4862 .freebsd, .kfreebsd => struct {
4863 /// dummy for IP
4864 pub const IP = 0;
4865 /// control message protocol
4866 pub const ICMP = 1;
4867 /// tcp
4868 pub const TCP = 6;
4869 /// user datagram protocol
4870 pub const UDP = 17;
4871 /// IP6 header
4872 pub const IPV6 = 41;
4873 /// raw IP packet
4874 pub const RAW = 255;
4875 /// IP6 hop-by-hop options
4876 pub const HOPOPTS = 0;
4877 /// group mgmt protocol
4878 pub const IGMP = 2;
4879 /// gateway^2 (deprecated)
4880 pub const GGP = 3;
4881 /// IPv4 encapsulation
4882 pub const IPV4 = 4;
4883 /// for compatibility
4884 pub const IPIP = IPV4;
4885 /// Stream protocol II
4886 pub const ST = 7;
4887 /// exterior gateway protocol
4888 pub const EGP = 8;
4889 /// private interior gateway
4890 pub const PIGP = 9;
4891 /// BBN RCC Monitoring
4892 pub const RCCMON = 10;
4893 /// network voice protocol
4894 pub const NVPII = 11;
4895 /// pup
4896 pub const PUP = 12;
4897 /// Argus
4898 pub const ARGUS = 13;
4899 /// EMCON
4900 pub const EMCON = 14;
4901 /// Cross Net Debugger
4902 pub const XNET = 15;
4903 /// Chaos
4904 pub const CHAOS = 16;
4905 /// Multiplexing
4906 pub const MUX = 18;
4907 /// DCN Measurement Subsystems
4908 pub const MEAS = 19;
4909 /// Host Monitoring
4910 pub const HMP = 20;
4911 /// Packet Radio Measurement
4912 pub const PRM = 21;
4913 /// xns idp
4914 pub const IDP = 22;
4915 /// Trunk-1
4916 pub const TRUNK1 = 23;
4917 /// Trunk-2
4918 pub const TRUNK2 = 24;
4919 /// Leaf-1
4920 pub const LEAF1 = 25;
4921 /// Leaf-2
4922 pub const LEAF2 = 26;
4923 /// Reliable Data
4924 pub const RDP = 27;
4925 /// Reliable Transaction
4926 pub const IRTP = 28;
4927 /// tp-4 w/ class negotiation
4928 pub const TP = 29;
4929 /// Bulk Data Transfer
4930 pub const BLT = 30;
4931 /// Network Services
4932 pub const NSP = 31;
4933 /// Merit Internodal
4934 pub const INP = 32;
4935 /// Datagram Congestion Control Protocol
4936 pub const DCCP = 33;
4937 /// Third Party Connect
4938 pub const @"3PC" = 34;
4939 /// InterDomain Policy Routing
4940 pub const IDPR = 35;
4941 /// XTP
4942 pub const XTP = 36;
4943 /// Datagram Delivery
4944 pub const DDP = 37;
4945 /// Control Message Transport
4946 pub const CMTP = 38;
4947 /// TP++ Transport
4948 pub const TPXX = 39;
4949 /// IL transport protocol
4950 pub const IL = 40;
4951 /// Source Demand Routing
4952 pub const SDRP = 42;
4953 /// IP6 routing header
4954 pub const ROUTING = 43;
4955 /// IP6 fragmentation header
4956 pub const FRAGMENT = 44;
4957 /// InterDomain Routing
4958 pub const IDRP = 45;
4959 /// resource reservation
4960 pub const RSVP = 46;
4961 /// General Routing Encap.
4962 pub const GRE = 47;
4963 /// Mobile Host Routing
4964 pub const MHRP = 48;
4965 /// BHA
4966 pub const BHA = 49;
4967 /// IP6 Encap Sec. Payload
4968 pub const ESP = 50;
4969 /// IP6 Auth Header
4970 pub const AH = 51;
4971 /// Integ. Net Layer Security
4972 pub const INLSP = 52;
4973 /// IP with encryption
4974 pub const SWIPE = 53;
4975 /// Next Hop Resolution
4976 pub const NHRP = 54;
4977 /// IP Mobility
4978 pub const MOBILE = 55;
4979 /// Transport Layer Security
4980 pub const TLSP = 56;
4981 /// SKIP
4982 pub const SKIP = 57;
4983 /// ICMP6
4984 pub const ICMPV6 = 58;
4985 /// IP6 no next header
4986 pub const NONE = 59;
4987 /// IP6 destination option
4988 pub const DSTOPTS = 60;
4989 /// any host internal protocol
4990 pub const AHIP = 61;
4991 /// CFTP
4992 pub const CFTP = 62;
4993 /// "hello" routing protocol
4994 pub const HELLO = 63;
4995 /// SATNET/Backroom EXPAK
4996 pub const SATEXPAK = 64;
4997 /// Kryptolan
4998 pub const KRYPTOLAN = 65;
4999 /// Remote Virtual Disk
5000 pub const RVD = 66;
5001 /// Pluribus Packet Core
5002 pub const IPPC = 67;
5003 /// Any distributed FS
5004 pub const ADFS = 68;
5005 /// Satnet Monitoring
5006 pub const SATMON = 69;
5007 /// VISA Protocol
5008 pub const VISA = 70;
5009 /// Packet Core Utility
5010 pub const IPCV = 71;
5011 /// Comp. Prot. Net. Executive
5012 pub const CPNX = 72;
5013 /// Comp. Prot. HeartBeat
5014 pub const CPHB = 73;
5015 /// Wang Span Network
5016 pub const WSN = 74;
5017 /// Packet Video Protocol
5018 pub const PVP = 75;
5019 /// BackRoom SATNET Monitoring
5020 pub const BRSATMON = 76;
5021 /// Sun net disk proto (temp.)
5022 pub const ND = 77;
5023 /// WIDEBAND Monitoring
5024 pub const WBMON = 78;
5025 /// WIDEBAND EXPAK
5026 pub const WBEXPAK = 79;
5027 /// ISO cnlp
5028 pub const EON = 80;
5029 /// VMTP
5030 pub const VMTP = 81;
5031 /// Secure VMTP
5032 pub const SVMTP = 82;
5033 /// Banyon VINES
5034 pub const VINES = 83;
5035 /// TTP
5036 pub const TTP = 84;
5037 /// NSFNET-IGP
5038 pub const IGP = 85;
5039 /// dissimilar gateway prot.
5040 pub const DGP = 86;
5041 /// TCF
5042 pub const TCF = 87;
5043 /// Cisco/GXS IGRP
5044 pub const IGRP = 88;
5045 /// OSPFIGP
5046 pub const OSPFIGP = 89;
5047 /// Strite RPC protocol
5048 pub const SRPC = 90;
5049 /// Locus Address Resoloution
5050 pub const LARP = 91;
5051 /// Multicast Transport
5052 pub const MTP = 92;
5053 /// AX.25 Frames
5054 pub const AX25 = 93;
5055 /// IP encapsulated in IP
5056 pub const IPEIP = 94;
5057 /// Mobile Int.ing control
5058 pub const MICP = 95;
5059 /// Semaphore Comm. security
5060 pub const SCCSP = 96;
5061 /// Ethernet IP encapsulation
5062 pub const ETHERIP = 97;
5063 /// encapsulation header
5064 pub const ENCAP = 98;
5065 /// any private encr. scheme
5066 pub const APES = 99;
5067 /// GMTP
5068 pub const GMTP = 100;
5069 /// payload compression (IPComp)
5070 pub const IPCOMP = 108;
5071 /// SCTP
5072 pub const SCTP = 132;
5073 /// IPv6 Mobility Header
5074 pub const MH = 135;
5075 /// UDP-Lite
5076 pub const UDPLITE = 136;
5077 /// IP6 Host Identity Protocol
5078 pub const HIP = 139;
5079 /// IP6 Shim6 Protocol
5080 pub const SHIM6 = 140;
5081 /// Protocol Independent Mcast
5082 pub const PIM = 103;
5083 /// CARP
5084 pub const CARP = 112;
5085 /// PGM
5086 pub const PGM = 113;
5087 /// MPLS-in-IP
5088 pub const MPLS = 137;
5089 /// PFSYNC
5090 pub const PFSYNC = 240;
5091 /// Reserved
5092 pub const RESERVED_253 = 253;
5093 /// Reserved
5094 pub const RESERVED_254 = 254;
5095 },
5096 .solaris, .illumos => struct {
5097 /// dummy for IP
5098 pub const IP = 0;
5099 /// Hop by hop header for IPv6
5100 pub const HOPOPTS = 0;
5101 /// control message protocol
5102 pub const ICMP = 1;
5103 /// group control protocol
5104 pub const IGMP = 2;
5105 /// gateway^2 (deprecated)
5106 pub const GGP = 3;
5107 /// IP in IP encapsulation
5108 pub const ENCAP = 4;
5109 /// tcp
5110 pub const TCP = 6;
5111 /// exterior gateway protocol
5112 pub const EGP = 8;
5113 /// pup
5114 pub const PUP = 12;
5115 /// user datagram protocol
5116 pub const UDP = 17;
5117 /// xns idp
5118 pub const IDP = 22;
5119 /// IPv6 encapsulated in IP
5120 pub const IPV6 = 41;
5121 /// Routing header for IPv6
5122 pub const ROUTING = 43;
5123 /// Fragment header for IPv6
5124 pub const FRAGMENT = 44;
5125 /// rsvp
5126 pub const RSVP = 46;
5127 /// IPsec Encap. Sec. Payload
5128 pub const ESP = 50;
5129 /// IPsec Authentication Hdr.
5130 pub const AH = 51;
5131 /// ICMP for IPv6
5132 pub const ICMPV6 = 58;
5133 /// No next header for IPv6
5134 pub const NONE = 59;
5135 /// Destination options
5136 pub const DSTOPTS = 60;
5137 /// "hello" routing protocol
5138 pub const HELLO = 63;
5139 /// UNOFFICIAL net disk proto
5140 pub const ND = 77;
5141 /// ISO clnp
5142 pub const EON = 80;
5143 /// OSPF
5144 pub const OSPF = 89;
5145 /// PIM routing protocol
5146 pub const PIM = 103;
5147 /// Stream Control
5148 pub const SCTP = 132;
5149 /// raw IP packet
5150 pub const RAW = 255;
5151 /// Sockets Direct Protocol
5152 pub const PROTO_SDP = 257;
5153 },
5154 .netbsd => struct {
5155 /// dummy for IP
5156 pub const IP = 0;
5157 /// IP6 hop-by-hop options
5158 pub const HOPOPTS = 0;
5159 /// control message protocol
5160 pub const ICMP = 1;
5161 /// group mgmt protocol
5162 pub const IGMP = 2;
5163 /// gateway^2 (deprecated)
5164 pub const GGP = 3;
5165 /// IP header
5166 pub const IPV4 = 4;
5167 /// IP inside IP
5168 pub const IPIP = 4;
5169 /// tcp
5170 pub const TCP = 6;
5171 /// exterior gateway protocol
5172 pub const EGP = 8;
5173 /// pup
5174 pub const PUP = 12;
5175 /// user datagram protocol
5176 pub const UDP = 17;
5177 /// xns idp
5178 pub const IDP = 22;
5179 /// tp-4 w/ class negotiation
5180 pub const TP = 29;
5181 /// DCCP
5182 pub const DCCP = 33;
5183 /// IP6 header
5184 pub const IPV6 = 41;
5185 /// IP6 routing header
5186 pub const ROUTING = 43;
5187 /// IP6 fragmentation header
5188 pub const FRAGMENT = 44;
5189 /// resource reservation
5190 pub const RSVP = 46;
5191 /// GRE encaps RFC 1701
5192 pub const GRE = 47;
5193 /// encap. security payload
5194 pub const ESP = 50;
5195 /// authentication header
5196 pub const AH = 51;
5197 /// IP Mobility RFC 2004
5198 pub const MOBILE = 55;
5199 /// IPv6 ICMP
5200 pub const IPV6_ICMP = 58;
5201 /// ICMP6
5202 pub const ICMPV6 = 58;
5203 /// IP6 no next header
5204 pub const NONE = 59;
5205 /// IP6 destination option
5206 pub const DSTOPTS = 60;
5207 /// ISO cnlp
5208 pub const EON = 80;
5209 /// Ethernet-in-IP
5210 pub const ETHERIP = 97;
5211 /// encapsulation header
5212 pub const ENCAP = 98;
5213 /// Protocol indep. multicast
5214 pub const PIM = 103;
5215 /// IP Payload Comp. Protocol
5216 pub const IPCOMP = 108;
5217 /// VRRP RFC 2338
5218 pub const VRRP = 112;
5219 /// Common Address Resolution Protocol
5220 pub const CARP = 112;
5221 /// L2TPv3
5222 pub const L2TP = 115;
5223 /// SCTP
5224 pub const SCTP = 132;
5225 /// PFSYNC
5226 pub const PFSYNC = 240;
5227 /// raw IP packet
5228 pub const RAW = 255;
5229 },
5230 .dragonfly => struct {
5231 pub const IP = 0;
5232 pub const ICMP = 1;
5233 pub const TCP = 6;
5234 pub const UDP = 17;
5235 pub const IPV6 = 41;
5236 pub const RAW = 255;
5237 pub const HOPOPTS = 0;
5238 pub const IGMP = 2;
5239 pub const GGP = 3;
5240 pub const IPV4 = 4;
5241 pub const IPIP = IPV4;
5242 pub const ST = 7;
5243 pub const EGP = 8;
5244 pub const PIGP = 9;
5245 pub const RCCMON = 10;
5246 pub const NVPII = 11;
5247 pub const PUP = 12;
5248 pub const ARGUS = 13;
5249 pub const EMCON = 14;
5250 pub const XNET = 15;
5251 pub const CHAOS = 16;
5252 pub const MUX = 18;
5253 pub const MEAS = 19;
5254 pub const HMP = 20;
5255 pub const PRM = 21;
5256 pub const IDP = 22;
5257 pub const TRUNK1 = 23;
5258 pub const TRUNK2 = 24;
5259 pub const LEAF1 = 25;
5260 pub const LEAF2 = 26;
5261 pub const RDP = 27;
5262 pub const IRTP = 28;
5263 pub const TP = 29;
5264 pub const BLT = 30;
5265 pub const NSP = 31;
5266 pub const INP = 32;
5267 pub const SEP = 33;
5268 pub const @"3PC" = 34;
5269 pub const IDPR = 35;
5270 pub const XTP = 36;
5271 pub const DDP = 37;
5272 pub const CMTP = 38;
5273 pub const TPXX = 39;
5274 pub const IL = 40;
5275 pub const SDRP = 42;
5276 pub const ROUTING = 43;
5277 pub const FRAGMENT = 44;
5278 pub const IDRP = 45;
5279 pub const RSVP = 46;
5280 pub const GRE = 47;
5281 pub const MHRP = 48;
5282 pub const BHA = 49;
5283 pub const ESP = 50;
5284 pub const AH = 51;
5285 pub const INLSP = 52;
5286 pub const SWIPE = 53;
5287 pub const NHRP = 54;
5288 pub const MOBILE = 55;
5289 pub const TLSP = 56;
5290 pub const SKIP = 57;
5291 pub const ICMPV6 = 58;
5292 pub const NONE = 59;
5293 pub const DSTOPTS = 60;
5294 pub const AHIP = 61;
5295 pub const CFTP = 62;
5296 pub const HELLO = 63;
5297 pub const SATEXPAK = 64;
5298 pub const KRYPTOLAN = 65;
5299 pub const RVD = 66;
5300 pub const IPPC = 67;
5301 pub const ADFS = 68;
5302 pub const SATMON = 69;
5303 pub const VISA = 70;
5304 pub const IPCV = 71;
5305 pub const CPNX = 72;
5306 pub const CPHB = 73;
5307 pub const WSN = 74;
5308 pub const PVP = 75;
5309 pub const BRSATMON = 76;
5310 pub const ND = 77;
5311 pub const WBMON = 78;
5312 pub const WBEXPAK = 79;
5313 pub const EON = 80;
5314 pub const VMTP = 81;
5315 pub const SVMTP = 82;
5316 pub const VINES = 83;
5317 pub const TTP = 84;
5318 pub const IGP = 85;
5319 pub const DGP = 86;
5320 pub const TCF = 87;
5321 pub const IGRP = 88;
5322 pub const OSPFIGP = 89;
5323 pub const SRPC = 90;
5324 pub const LARP = 91;
5325 pub const MTP = 92;
5326 pub const AX25 = 93;
5327 pub const IPEIP = 94;
5328 pub const MICP = 95;
5329 pub const SCCSP = 96;
5330 pub const ETHERIP = 97;
5331 pub const ENCAP = 98;
5332 pub const APES = 99;
5333 pub const GMTP = 100;
5334 pub const IPCOMP = 108;
5335 pub const PIM = 103;
5336 pub const CARP = 112;
5337 pub const PGM = 113;
5338 pub const PFSYNC = 240;
5339 pub const DIVERT = 254;
5340 pub const MAX = 256;
5341 pub const DONE = 257;
5342 pub const UNKNOWN = 258;
5343 },
5344 .haiku => struct {
5345 pub const IP = 0;
5346 pub const HOPOPTS = 0;
5347 pub const ICMP = 1;
5348 pub const IGMP = 2;
5349 pub const TCP = 6;
5350 pub const UDP = 17;
5351 pub const IPV6 = 41;
5352 pub const ROUTING = 43;
5353 pub const FRAGMENT = 44;
5354 pub const ESP = 50;
5355 pub const AH = 51;
5356 pub const ICMPV6 = 58;
5357 pub const NONE = 59;
5358 pub const DSTOPTS = 60;
5359 pub const ETHERIP = 97;
5360 pub const RAW = 255;
5361 pub const MAX = 256;
5362 },
5363 .openbsd => struct {
5364 /// dummy for IP
5365 pub const IP = 0;
5366 /// IP6 hop-by-hop options
5367 pub const HOPOPTS = IP;
5368 /// control message protocol
5369 pub const ICMP = 1;
5370 /// group mgmt protocol
5371 pub const IGMP = 2;
5372 /// gateway^2 (deprecated)
5373 pub const GGP = 3;
5374 /// IP header
5375 pub const IPV4 = IPIP;
5376 /// IP inside IP
5377 pub const IPIP = 4;
5378 /// tcp
5379 pub const TCP = 6;
5380 /// exterior gateway protocol
5381 pub const EGP = 8;
5382 /// pup
5383 pub const PUP = 12;
5384 /// user datagram protocol
5385 pub const UDP = 17;
5386 /// xns idp
5387 pub const IDP = 22;
5388 /// tp-4 w/ class negotiation
5389 pub const TP = 29;
5390 /// IP6 header
5391 pub const IPV6 = 41;
5392 /// IP6 routing header
5393 pub const ROUTING = 43;
5394 /// IP6 fragmentation header
5395 pub const FRAGMENT = 44;
5396 /// resource reservation
5397 pub const RSVP = 46;
5398 /// GRE encaps RFC 1701
5399 pub const GRE = 47;
5400 /// encap. security payload
5401 pub const ESP = 50;
5402 /// authentication header
5403 pub const AH = 51;
5404 /// IP Mobility RFC 2004
5405 pub const MOBILE = 55;
5406 /// IPv6 ICMP
5407 pub const IPV6_ICMP = 58;
5408 /// ICMP6
5409 pub const ICMPV6 = 58;
5410 /// IP6 no next header
5411 pub const NONE = 59;
5412 /// IP6 destination option
5413 pub const DSTOPTS = 60;
5414 /// ISO cnlp
5415 pub const EON = 80;
5416 /// Ethernet-in-IP
5417 pub const ETHERIP = 97;
5418 /// encapsulation header
5419 pub const ENCAP = 98;
5420 /// Protocol indep. multicast
5421 pub const PIM = 103;
5422 /// IP Payload Comp. Protocol
5423 pub const IPCOMP = 108;
5424 /// VRRP RFC 2338
5425 pub const VRRP = 112;
5426 /// Common Address Resolution Protocol
5427 pub const CARP = 112;
5428 /// PFSYNC
5429 pub const PFSYNC = 240;
5430 /// raw IP packet
5431 pub const RAW = 255;
5432 },
5433 else => void,
5434};
5435pub const SOL = switch (native_os) {
5436 .linux => linux.SOL,
5437 .emscripten => emscripten.SOL,
5438 .windows => ws2_32.SOL,
5439 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
5440 pub const SOCKET = 0xffff;
5441 },
5442 .solaris, .illumos => struct {
5443 pub const SOCKET = 0xffff;
5444 pub const ROUTE = 0xfffe;
5445 pub const PACKET = 0xfffd;
5446 pub const FILTER = 0xfffc;
5447 },
5448 else => void,
5449};
5450pub const SO = switch (native_os) {
5451 .linux => linux.SO,
5452 .emscripten => emscripten.SO,
5453 .windows => ws2_32.SO,
5454 .macos, .ios, .tvos, .watchos, .visionos => struct {
5455 pub const DEBUG = 0x0001;
5456 pub const ACCEPTCONN = 0x0002;
5457 pub const REUSEADDR = 0x0004;
5458 pub const KEEPALIVE = 0x0008;
5459 pub const DONTROUTE = 0x0010;
5460 pub const BROADCAST = 0x0020;
5461 pub const USELOOPBACK = 0x0040;
5462 pub const LINGER = 0x1080;
5463 pub const OOBINLINE = 0x0100;
5464 pub const REUSEPORT = 0x0200;
5465 pub const ACCEPTFILTER = 0x1000;
5466 pub const SNDBUF = 0x1001;
5467 pub const RCVBUF = 0x1002;
5468 pub const SNDLOWAT = 0x1003;
5469 pub const RCVLOWAT = 0x1004;
5470 pub const SNDTIMEO = 0x1005;
5471 pub const RCVTIMEO = 0x1006;
5472 pub const ERROR = 0x1007;
5473 pub const TYPE = 0x1008;
5474
5475 pub const NREAD = 0x1020;
5476 pub const NKE = 0x1021;
5477 pub const NOSIGPIPE = 0x1022;
5478 pub const NOADDRERR = 0x1023;
5479 pub const NWRITE = 0x1024;
5480 pub const REUSESHAREUID = 0x1025;
5481 },
5482 .freebsd, .kfreebsd => struct {
5483 pub const DEBUG = 0x00000001;
5484 pub const ACCEPTCONN = 0x00000002;
5485 pub const REUSEADDR = 0x00000004;
5486 pub const KEEPALIVE = 0x00000008;
5487 pub const DONTROUTE = 0x00000010;
5488 pub const BROADCAST = 0x00000020;
5489 pub const USELOOPBACK = 0x00000040;
5490 pub const LINGER = 0x00000080;
5491 pub const OOBINLINE = 0x00000100;
5492 pub const REUSEPORT = 0x00000200;
5493 pub const TIMESTAMP = 0x00000400;
5494 pub const NOSIGPIPE = 0x00000800;
5495 pub const ACCEPTFILTER = 0x00001000;
5496 pub const BINTIME = 0x00002000;
5497 pub const NO_OFFLOAD = 0x00004000;
5498 pub const NO_DDP = 0x00008000;
5499 pub const REUSEPORT_LB = 0x00010000;
5500
5501 pub const SNDBUF = 0x1001;
5502 pub const RCVBUF = 0x1002;
5503 pub const SNDLOWAT = 0x1003;
5504 pub const RCVLOWAT = 0x1004;
5505 pub const SNDTIMEO = 0x1005;
5506 pub const RCVTIMEO = 0x1006;
5507 pub const ERROR = 0x1007;
5508 pub const TYPE = 0x1008;
5509 pub const LABEL = 0x1009;
5510 pub const PEERLABEL = 0x1010;
5511 pub const LISTENQLIMIT = 0x1011;
5512 pub const LISTENQLEN = 0x1012;
5513 pub const LISTENINCQLEN = 0x1013;
5514 pub const SETFIB = 0x1014;
5515 pub const USER_COOKIE = 0x1015;
5516 pub const PROTOCOL = 0x1016;
5517 pub const PROTOTYPE = PROTOCOL;
5518 pub const TS_CLOCK = 0x1017;
5519 pub const MAX_PACING_RATE = 0x1018;
5520 pub const DOMAIN = 0x1019;
5521 },
5522 .solaris, .illumos => struct {
5523 pub const DEBUG = 0x0001;
5524 pub const ACCEPTCONN = 0x0002;
5525 pub const REUSEADDR = 0x0004;
5526 pub const KEEPALIVE = 0x0008;
5527 pub const DONTROUTE = 0x0010;
5528 pub const BROADCAST = 0x0020;
5529 pub const USELOOPBACK = 0x0040;
5530 pub const LINGER = 0x0080;
5531 pub const OOBINLINE = 0x0100;
5532 pub const DGRAM_ERRIND = 0x0200;
5533 pub const RECVUCRED = 0x0400;
5534
5535 pub const SNDBUF = 0x1001;
5536 pub const RCVBUF = 0x1002;
5537 pub const SNDLOWAT = 0x1003;
5538 pub const RCVLOWAT = 0x1004;
5539 pub const SNDTIMEO = 0x1005;
5540 pub const RCVTIMEO = 0x1006;
5541 pub const ERROR = 0x1007;
5542 pub const TYPE = 0x1008;
5543 pub const PROTOTYPE = 0x1009;
5544 pub const ANON_MLP = 0x100a;
5545 pub const MAC_EXEMPT = 0x100b;
5546 pub const DOMAIN = 0x100c;
5547 pub const RCVPSH = 0x100d;
5548
5549 pub const SECATTR = 0x1011;
5550 pub const TIMESTAMP = 0x1013;
5551 pub const ALLZONES = 0x1014;
5552 pub const EXCLBIND = 0x1015;
5553 pub const MAC_IMPLICIT = 0x1016;
5554 pub const VRRP = 0x1017;
5555 },
5556 .netbsd => struct {
5557 pub const DEBUG = 0x0001;
5558 pub const ACCEPTCONN = 0x0002;
5559 pub const REUSEADDR = 0x0004;
5560 pub const KEEPALIVE = 0x0008;
5561 pub const DONTROUTE = 0x0010;
5562 pub const BROADCAST = 0x0020;
5563 pub const USELOOPBACK = 0x0040;
5564 pub const LINGER = 0x0080;
5565 pub const OOBINLINE = 0x0100;
5566 pub const REUSEPORT = 0x0200;
5567 pub const NOSIGPIPE = 0x0800;
5568 pub const ACCEPTFILTER = 0x1000;
5569 pub const TIMESTAMP = 0x2000;
5570 pub const RERROR = 0x4000;
5571
5572 pub const SNDBUF = 0x1001;
5573 pub const RCVBUF = 0x1002;
5574 pub const SNDLOWAT = 0x1003;
5575 pub const RCVLOWAT = 0x1004;
5576 pub const ERROR = 0x1007;
5577 pub const TYPE = 0x1008;
5578 pub const OVERFLOWED = 0x1009;
5579
5580 pub const NOHEADER = 0x100a;
5581 pub const SNDTIMEO = 0x100b;
5582 pub const RCVTIMEO = 0x100c;
5583 },
5584 .dragonfly => struct {
5585 pub const DEBUG = 0x0001;
5586 pub const ACCEPTCONN = 0x0002;
5587 pub const REUSEADDR = 0x0004;
5588 pub const KEEPALIVE = 0x0008;
5589 pub const DONTROUTE = 0x0010;
5590 pub const BROADCAST = 0x0020;
5591 pub const USELOOPBACK = 0x0040;
5592 pub const LINGER = 0x0080;
5593 pub const OOBINLINE = 0x0100;
5594 pub const REUSEPORT = 0x0200;
5595 pub const TIMESTAMP = 0x0400;
5596 pub const NOSIGPIPE = 0x0800;
5597 pub const ACCEPTFILTER = 0x1000;
5598 pub const RERROR = 0x2000;
5599 pub const PASSCRED = 0x4000;
5600
5601 pub const SNDBUF = 0x1001;
5602 pub const RCVBUF = 0x1002;
5603 pub const SNDLOWAT = 0x1003;
5604 pub const RCVLOWAT = 0x1004;
5605 pub const SNDTIMEO = 0x1005;
5606 pub const RCVTIMEO = 0x1006;
5607 pub const ERROR = 0x1007;
5608 pub const TYPE = 0x1008;
5609 pub const SNDSPACE = 0x100a;
5610 pub const CPUHINT = 0x1030;
5611 },
5612 .haiku => struct {
5613 pub const ACCEPTCONN = 0x00000001;
5614 pub const BROADCAST = 0x00000002;
5615 pub const DEBUG = 0x00000004;
5616 pub const DONTROUTE = 0x00000008;
5617 pub const KEEPALIVE = 0x00000010;
5618 pub const OOBINLINE = 0x00000020;
5619 pub const REUSEADDR = 0x00000040;
5620 pub const REUSEPORT = 0x00000080;
5621 pub const USELOOPBACK = 0x00000100;
5622 pub const LINGER = 0x00000200;
5623
5624 pub const SNDBUF = 0x40000001;
5625 pub const SNDLOWAT = 0x40000002;
5626 pub const SNDTIMEO = 0x40000003;
5627 pub const RCVBUF = 0x40000004;
5628 pub const RCVLOWAT = 0x40000005;
5629 pub const RCVTIMEO = 0x40000006;
5630 pub const ERROR = 0x40000007;
5631 pub const TYPE = 0x40000008;
5632 pub const NONBLOCK = 0x40000009;
5633 pub const BINDTODEVICE = 0x4000000a;
5634 pub const PEERCRED = 0x4000000b;
5635 },
5636 .openbsd => struct {
5637 pub const DEBUG = 0x0001;
5638 pub const ACCEPTCONN = 0x0002;
5639 pub const REUSEADDR = 0x0004;
5640 pub const KEEPALIVE = 0x0008;
5641 pub const DONTROUTE = 0x0010;
5642 pub const BROADCAST = 0x0020;
5643 pub const USELOOPBACK = 0x0040;
5644 pub const LINGER = 0x0080;
5645 pub const OOBINLINE = 0x0100;
5646 pub const REUSEPORT = 0x0200;
5647 pub const TIMESTAMP = 0x0800;
5648 pub const BINDANY = 0x1000;
5649 pub const ZEROIZE = 0x2000;
5650 pub const SNDBUF = 0x1001;
5651 pub const RCVBUF = 0x1002;
5652 pub const SNDLOWAT = 0x1003;
5653 pub const RCVLOWAT = 0x1004;
5654 pub const SNDTIMEO = 0x1005;
5655 pub const RCVTIMEO = 0x1006;
5656 pub const ERROR = 0x1007;
5657 pub const TYPE = 0x1008;
5658 pub const NETPROC = 0x1020;
5659 pub const RTABLE = 0x1021;
5660 pub const PEERCRED = 0x1022;
5661 pub const SPLICE = 0x1023;
5662 pub const DOMAIN = 0x1024;
5663 pub const PROTOCOL = 0x1025;
5664 },
5665 else => void,
5666};
5667pub const SOMAXCONN = switch (native_os) {
5668 .linux => linux.SOMAXCONN,
5669 .windows => ws2_32.SOMAXCONN,
5670 .solaris, .illumos => 128,
5671 .openbsd => 28,
5672 else => void,
5673};
5674pub const IFNAMESIZE = switch (native_os) {
5675 .linux => linux.IFNAMESIZE,
5676 .emscripten => emscripten.IFNAMESIZE,
5677 .windows => 30,
5678 .openbsd, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => 16,
5679 .solaris, .illumos => 32,
5680 else => void,
5681};
5682
5683pub const stack_t = switch (native_os) {
5684 .linux => linux.stack_t,
5685 .emscripten => emscripten.stack_t,
5686 .freebsd, .kfreebsd => extern struct {
5687 /// Signal stack base.
5688 sp: *anyopaque,
5689 /// Signal stack length.
5690 size: usize,
5691 /// SS_DISABLE and/or SS_ONSTACK.
5692 flags: i32,
5693 },
5694 else => extern struct {
5695 sp: [*]u8,
5696 size: isize,
5697 flags: i32,
5698 },
5699};
5700pub const time_t = switch (native_os) {
5701 .linux => linux.time_t,
5702 .emscripten => emscripten.time_t,
5703 .haiku, .dragonfly => isize,
5704 else => i64,
5705};
5706pub const suseconds_t = switch (native_os) {
5707 .solaris, .illumos => i64,
5708 .freebsd, .kfreebsd, .dragonfly => c_long,
5709 .netbsd => c_int,
5710 .haiku => i32,
5711 else => void,
5712};
5713
5714pub const timeval = switch (native_os) {
5715 .linux => linux.timeval,
5716 .emscripten => emscripten.timeval,
5717 .windows => extern struct {
5718 sec: c_long,
5719 usec: c_long,
5720 },
5721 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
5722 sec: c_long,
5723 usec: i32,
5724 },
5725 .dragonfly, .netbsd, .freebsd, .kfreebsd, .solaris, .illumos => extern struct {
5726 /// seconds
5727 sec: time_t,
5728 /// microseconds
5729 usec: suseconds_t,
5730 },
5731 .openbsd => extern struct {
5732 sec: time_t,
5733 usec: c_long,
5734 },
5735 else => void,
5736};
5737pub const timezone = switch (native_os) {
5738 .linux => linux.timezone,
5739 .emscripten => emscripten.timezone,
5740 .openbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
5741 minuteswest: i32,
5742 dsttime: i32,
5743 },
5744 else => void,
5745};
5746
5747pub const ucontext_t = switch (native_os) {
5748 .linux => linux.ucontext_t,
5749 .emscripten => emscripten.ucontext_t,
5750 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
5751 onstack: c_int,
5752 sigmask: sigset_t,
5753 stack: stack_t,
5754 link: ?*ucontext_t,
5755 mcsize: u64,
5756 mcontext: *mcontext_t,
5757 __mcontext_data: mcontext_t,
5758 },
5759 .freebsd, .kfreebsd => extern struct {
5760 sigmask: sigset_t,
5761 mcontext: mcontext_t,
5762 link: ?*ucontext_t,
5763 stack: stack_t,
5764 flags: c_int,
5765 __spare__: [4]c_int,
5766 },
5767 .solaris, .illumos => extern struct {
5768 flags: u64,
5769 link: ?*ucontext_t,
5770 sigmask: sigset_t,
5771 stack: stack_t,
5772 mcontext: mcontext_t,
5773 brand_data: [3]?*anyopaque,
5774 filler: [2]i64,
5775 },
5776 .netbsd => extern struct {
5777 flags: u32,
5778 link: ?*ucontext_t,
5779 sigmask: sigset_t,
5780 stack: stack_t,
5781 mcontext: mcontext_t,
5782 __pad: [
5783 switch (builtin.cpu.arch) {
5784 .x86 => 4,
5785 .mips, .mipsel, .mips64, .mips64el => 14,
5786 .arm, .armeb, .thumb, .thumbeb => 1,
5787 .sparc, .sparcel, .sparc64 => if (@sizeOf(usize) == 4) 43 else 8,
5788 else => 0,
5789 }
5790 ]u32,
5791 },
5792 .dragonfly => extern struct {
5793 sigmask: sigset_t,
5794 mcontext: mcontext_t,
5795 link: ?*ucontext_t,
5796 stack: stack_t,
5797 cofunc: ?*fn (?*ucontext_t, ?*anyopaque) void,
5798 arg: ?*void,
5799 _spare: [4]c_int,
5800 },
5801 .haiku => extern struct {
5802 link: ?*ucontext_t,
5803 sigmask: sigset_t,
5804 stack: stack_t,
5805 mcontext: mcontext_t,
5806 },
5807 .openbsd => openbsd.ucontext_t,
5808 else => void,
5809};
5810pub const mcontext_t = switch (native_os) {
5811 .linux => linux.mcontext_t,
5812 .emscripten => emscripten.mcontext_t,
5813 .macos, .ios, .tvos, .watchos, .visionos => darwin.mcontext_t,
5814 .freebsd, .kfreebsd => switch (builtin.cpu.arch) {
5815 .x86_64 => extern struct {
5816 onstack: u64,
5817 rdi: u64,
5818 rsi: u64,
5819 rdx: u64,
5820 rcx: u64,
5821 r8: u64,
5822 r9: u64,
5823 rax: u64,
5824 rbx: u64,
5825 rbp: u64,
5826 r10: u64,
5827 r11: u64,
5828 r12: u64,
5829 r13: u64,
5830 r14: u64,
5831 r15: u64,
5832 trapno: u32,
5833 fs: u16,
5834 gs: u16,
5835 addr: u64,
5836 flags: u32,
5837 es: u16,
5838 ds: u16,
5839 err: u64,
5840 rip: u64,
5841 cs: u64,
5842 rflags: u64,
5843 rsp: u64,
5844 ss: u64,
5845 len: u64,
5846 fpformat: u64,
5847 ownedfp: u64,
5848 fpstate: [64]u64 align(16),
5849 fsbase: u64,
5850 gsbase: u64,
5851 xfpustate: u64,
5852 xfpustate_len: u64,
5853 spare: [4]u64,
5854 },
5855 .aarch64 => extern struct {
5856 gpregs: extern struct {
5857 x: [30]u64,
5858 lr: u64,
5859 sp: u64,
5860 elr: u64,
5861 spsr: u32,
5862 _pad: u32,
5863 },
5864 fpregs: extern struct {
5865 q: [32]u128,
5866 sr: u32,
5867 cr: u32,
5868 flags: u32,
5869 _pad: u32,
5870 },
5871 flags: u32,
5872 _pad: u32,
5873 _spare: [8]u64,
5874 },
5875 else => struct {},
5876 },
5877 .solaris, .illumos => extern struct {
5878 gregs: [28]u64,
5879 fpregs: solaris.fpregset_t,
5880 },
5881 .netbsd => switch (builtin.cpu.arch) {
5882 .aarch64 => extern struct {
5883 gregs: [35]u64,
5884 fregs: [528]u8 align(16),
5885 spare: [8]u64,
5886 },
5887 .x86_64 => extern struct {
5888 gregs: [26]u64,
5889 mc_tlsbase: u64,
5890 fpregs: [512]u8 align(8),
5891 },
5892 else => struct {},
5893 },
5894 .dragonfly => dragonfly.mcontext_t,
5895 .haiku => haiku.mcontext_t,
5896 else => void,
5897};
5898
5899pub const user_desc = switch (native_os) {
5900 .linux => linux.user_desc,
5901 else => void,
5902};
5903pub const utsname = switch (native_os) {
5904 .linux => linux.utsname,
5905 .emscripten => emscripten.utsname,
5906 .solaris, .illumos => extern struct {
5907 sysname: [256:0]u8,
5908 nodename: [256:0]u8,
5909 release: [256:0]u8,
5910 version: [256:0]u8,
5911 machine: [256:0]u8,
5912 domainname: [256:0]u8,
5913 },
5914 else => void,
5915};
5916pub const PR = switch (native_os) {
5917 .linux => linux.PR,
5918 else => void,
5919};
5920pub const _errno = switch (native_os) {
5921 .linux => switch (native_abi) {
5922 .android => private.__errno,
5923 else => private.__errno_location,
5924 },
5925 .emscripten => private.__errno_location,
5926 .wasi, .dragonfly => private.errnoFromThreadLocal,
5927 .windows => private._errno,
5928 .macos, .ios, .tvos, .watchos, .visionos, .freebsd, .kfreebsd => private.__error,
5929 .solaris, .illumos => private.___errno,
5930 .openbsd, .netbsd => private.__errno,
5931 .haiku => haiku._errnop,
5932 else => {},
5933};
5934
5935pub const RTLD = switch (native_os) {
5936 .linux, .emscripten => packed struct(u32) {
5937 LAZY: bool = false,
5938 NOW: bool = false,
5939 NOLOAD: bool = false,
5940 _3: u5 = 0,
5941 GLOBAL: bool = false,
5942 _9: u3 = 0,
5943 NODELETE: bool = false,
5944 _: u19 = 0,
5945 },
5946 .dragonfly, .freebsd, .kfreebsd => packed struct(u32) {
5947 LAZY: bool = false,
5948 NOW: bool = false,
5949 _2: u6 = 0,
5950 GLOBAL: bool = false,
5951 TRACE: bool = false,
5952 _10: u2 = 0,
5953 NODELETE: bool = false,
5954 NOLOAD: bool = false,
5955 _: u18 = 0,
5956 },
5957 .haiku => packed struct(u32) {
5958 NOW: bool = false,
5959 GLOBAL: bool = false,
5960 _: u30 = 0,
5961 },
5962 .netbsd => packed struct(u32) {
5963 LAZY: bool = false,
5964 NOW: bool = false,
5965 _2: u6 = 0,
5966 GLOBAL: bool = false,
5967 LOCAL: bool = false,
5968 _10: u2 = 0,
5969 NODELETE: bool = false,
5970 NOLOAD: bool = false,
5971 _: u18 = 0,
5972 },
5973 .solaris, .illumos => packed struct(u32) {
5974 LAZY: bool = false,
5975 NOW: bool = false,
5976 NOLOAD: bool = false,
5977 _3: u5 = 0,
5978 GLOBAL: bool = false,
5979 PARENT: bool = false,
5980 GROUP: bool = false,
5981 WORLD: bool = false,
5982 NODELETE: bool = false,
5983 FIRST: bool = false,
5984 _14: u2 = 0,
5985 CONFGEN: bool = false,
5986 _: u15 = 0,
5987 },
5988 .openbsd => packed struct(u32) {
5989 LAZY: bool = false,
5990 NOW: bool = false,
5991 _2: u6 = 0,
5992 GLOBAL: bool = false,
5993 TRACE: bool = false,
5994 _: u22 = 0,
5995 },
5996 .macos, .ios, .tvos, .watchos, .visionos => packed struct(u32) {
5997 LAZY: bool = false,
5998 NOW: bool = false,
5999 LOCAL: bool = false,
6000 GLOBAL: bool = false,
6001 NOLOAD: bool = false,
6002 _5: u2 = 0,
6003 NODELETE: bool = false,
6004 FIRST: bool = false,
6005 _: u23 = 0,
6006 },
6007 else => void,
6008};
6009
6010pub const dirent = switch (native_os) {
6011 .linux, .emscripten => extern struct {
6012 ino: c_uint,
6013 off: c_uint,
6014 reclen: c_ushort,
6015 type: u8,
6016 name: [256]u8,
6017 },
6018 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
6019 ino: u64,
6020 seekoff: u64,
6021 reclen: u16,
6022 namlen: u16,
6023 type: u8,
6024 name: [1024]u8,
6025 },
6026 .freebsd, .kfreebsd => extern struct {
6027 /// File number of entry.
6028 fileno: ino_t,
6029 /// Directory offset of entry.
6030 off: off_t,
6031 /// Length of this record.
6032 reclen: u16,
6033 /// File type, one of DT_.
6034 type: u8,
6035 pad0: u8 = 0,
6036 /// Length of the name member.
6037 namlen: u16,
6038 pad1: u16 = 0,
6039 /// Name of entry.
6040 name: [255:0]u8,
6041 },
6042 .solaris, .illumos => extern struct {
6043 /// Inode number of entry.
6044 ino: ino_t,
6045 /// Offset of this entry on disk.
6046 off: off_t,
6047 /// Length of this record.
6048 reclen: u16,
6049 /// File name.
6050 name: [MAXNAMLEN:0]u8,
6051 },
6052 .netbsd => extern struct {
6053 fileno: ino_t,
6054 reclen: u16,
6055 namlen: u16,
6056 type: u8,
6057 name: [MAXNAMLEN:0]u8,
6058 },
6059 .dragonfly => extern struct {
6060 fileno: c_ulong,
6061 namlen: u16,
6062 type: u8,
6063 unused1: u8,
6064 unused2: u32,
6065 name: [256]u8,
6066
6067 pub fn reclen(self: dirent) u16 {
6068 return (@offsetOf(dirent, "name") + self.namlen + 1 + 7) & ~@as(u16, 7);
6069 }
6070 },
6071 .openbsd => extern struct {
6072 fileno: ino_t,
6073 off: off_t,
6074 reclen: u16,
6075 type: u8,
6076 namlen: u8,
6077 _: u32 align(1) = 0,
6078 name: [MAXNAMLEN:0]u8,
6079 },
6080 else => void,
6081};
6082pub const MAXNAMLEN = switch (native_os) {
6083 .netbsd, .solaris, .illumos => 511,
6084 .haiku => NAME_MAX,
6085 .openbsd => 255,
6086 else => {},
6087};
6088pub const dirent64 = switch (native_os) {
6089 .linux => extern struct {
6090 ino: c_ulong,
6091 off: c_ulong,
6092 reclen: c_ushort,
6093 type: u8,
6094 name: [256]u8,
6095 },
6096 else => void,
6097};
6098
6099pub const AI = switch (native_os) {
6100 .linux, .emscripten => linux.AI,
6101 .dragonfly, .haiku, .freebsd, .kfreebsd => packed struct(u32) {
6102 PASSIVE: bool = false,
6103 CANONNAME: bool = false,
6104 NUMERICHOST: bool = false,
6105 NUMERICSERV: bool = false,
6106 _4: u4 = 0,
6107 ALL: bool = false,
6108 V4MAPPED_CFG: bool = false,
6109 ADDRCONFIG: bool = false,
6110 V4MAPPED: bool = false,
6111 _: u20 = 0,
6112 },
6113 .netbsd => packed struct(u32) {
6114 PASSIVE: bool = false,
6115 CANONNAME: bool = false,
6116 NUMERICHOST: bool = false,
6117 NUMERICSERV: bool = false,
6118 _4: u6 = 0,
6119 ADDRCONFIG: bool = false,
6120 _: u21 = 0,
6121 },
6122 .solaris, .illumos => packed struct(u32) {
6123 V4MAPPED: bool = false,
6124 ALL: bool = false,
6125 ADDRCONFIG: bool = false,
6126 PASSIVE: bool = false,
6127 CANONNAME: bool = false,
6128 NUMERICHOST: bool = false,
6129 NUMERICSERV: bool = false,
6130 _: u25 = 0,
6131 },
6132 .openbsd => packed struct(u32) {
6133 PASSIVE: bool = false,
6134 CANONNAME: bool = false,
6135 NUMERICHOST: bool = false,
6136 _3: u1 = 0,
6137 NUMERICSERV: bool = false,
6138 _5: u1 = 0,
6139 ADDRCONFIG: bool = false,
6140 _: u25 = 0,
6141 },
6142 .macos, .ios, .tvos, .watchos, .visionos => packed struct(u32) {
6143 PASSIVE: bool = false,
6144 CANONNAME: bool = false,
6145 NUMERICHOST: bool = false,
6146 _3: u9 = 0,
6147 NUMERICSERV: bool = false,
6148 _: u19 = 0,
6149 },
6150 .windows => ws2_32.AI,
6151 else => void,
6152};
6153
6154pub const NI = switch (native_os) {
6155 .linux, .emscripten => packed struct(u32) {
6156 NUMERICHOST: bool = false,
6157 NUMERICSERV: bool = false,
6158 NOFQDN: bool = false,
6159 NAMEREQD: bool = false,
6160 DGRAM: bool = false,
6161 _5: u3 = 0,
6162 NUMERICSCOPE: bool = false,
6163 _: u23 = 0,
6164 },
6165 .solaris, .illumos => packed struct(u32) {
6166 NOFQDN: bool = false,
6167 NUMERICHOST: bool = false,
6168 NAMEREQD: bool = false,
6169 NUMERICSERV: bool = false,
6170 DGRAM: bool = false,
6171 WITHSCOPEID: bool = false,
6172 NUMERICSCOPE: bool = false,
6173 _: u25 = 0,
6174 },
6175 else => void,
6176};
6177
6178pub const EAI = switch (native_os) {
6179 .linux, .emscripten => enum(c_int) {
6180 BADFLAGS = -1,
6181 NONAME = -2,
6182 AGAIN = -3,
6183 FAIL = -4,
6184 FAMILY = -6,
6185 SOCKTYPE = -7,
6186 SERVICE = -8,
6187 MEMORY = -10,
6188 SYSTEM = -11,
6189 OVERFLOW = -12,
6190
6191 NODATA = -5,
6192 ADDRFAMILY = -9,
6193 INPROGRESS = -100,
6194 CANCELED = -101,
6195 NOTCANCELED = -102,
6196 ALLDONE = -103,
6197 INTR = -104,
6198 IDN_ENCODE = -105,
6199
6200 _,
6201 },
6202 .haiku, .dragonfly, .netbsd, .freebsd, .kfreebsd, .macos, .ios, .tvos, .watchos, .visionos => enum(c_int) {
6203 /// address family for hostname not supported
6204 ADDRFAMILY = 1,
6205 /// temporary failure in name resolution
6206 AGAIN = 2,
6207 /// invalid value for ai_flags
6208 BADFLAGS = 3,
6209 /// non-recoverable failure in name resolution
6210 FAIL = 4,
6211 /// ai_family not supported
6212 FAMILY = 5,
6213 /// memory allocation failure
6214 MEMORY = 6,
6215 /// no address associated with hostname
6216 NODATA = 7,
6217 /// hostname nor servname provided, or not known
6218 NONAME = 8,
6219 /// servname not supported for ai_socktype
6220 SERVICE = 9,
6221 /// ai_socktype not supported
6222 SOCKTYPE = 10,
6223 /// system error returned in errno
6224 SYSTEM = 11,
6225 /// invalid value for hints
6226 BADHINTS = 12,
6227 /// resolved protocol is unknown
6228 PROTOCOL = 13,
6229 /// argument buffer overflow
6230 OVERFLOW = 14,
6231 _,
6232 },
6233 .solaris, .illumos => enum(c_int) {
6234 /// address family for hostname not supported
6235 ADDRFAMILY = 1,
6236 /// name could not be resolved at this time
6237 AGAIN = 2,
6238 /// flags parameter had an invalid value
6239 BADFLAGS = 3,
6240 /// non-recoverable failure in name resolution
6241 FAIL = 4,
6242 /// address family not recognized
6243 FAMILY = 5,
6244 /// memory allocation failure
6245 MEMORY = 6,
6246 /// no address associated with hostname
6247 NODATA = 7,
6248 /// name does not resolve
6249 NONAME = 8,
6250 /// service not recognized for socket type
6251 SERVICE = 9,
6252 /// intended socket type was not recognized
6253 SOCKTYPE = 10,
6254 /// system error returned in errno
6255 SYSTEM = 11,
6256 /// argument buffer overflow
6257 OVERFLOW = 12,
6258 /// resolved protocol is unknown
6259 PROTOCOL = 13,
6260
6261 _,
6262 },
6263 .openbsd => enum(c_int) {
6264 /// address family for hostname not supported
6265 ADDRFAMILY = -9,
6266 /// name could not be resolved at this time
6267 AGAIN = -3,
6268 /// flags parameter had an invalid value
6269 BADFLAGS = -1,
6270 /// non-recoverable failure in name resolution
6271 FAIL = -4,
6272 /// address family not recognized
6273 FAMILY = -6,
6274 /// memory allocation failure
6275 MEMORY = -10,
6276 /// no address associated with hostname
6277 NODATA = -5,
6278 /// name does not resolve
6279 NONAME = -2,
6280 /// service not recognized for socket type
6281 SERVICE = -8,
6282 /// intended socket type was not recognized
6283 SOCKTYPE = -7,
6284 /// system error returned in errno
6285 SYSTEM = -11,
6286 /// invalid value for hints
6287 BADHINTS = -12,
6288 /// resolved protocol is unknown
6289 PROTOCOL = -13,
6290 /// argument buffer overflow
6291 OVERFLOW = -14,
6292 _,
6293 },
6294 else => void,
6295};
6296
6297pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
6298
6299pub const Stat = switch (native_os) {
6300 .linux => switch (native_arch) {
6301 .sparc64 => extern struct {
6302 dev: u64,
6303 __pad1: u16,
6304 ino: ino_t,
6305 mode: u32,
6306 nlink: u32,
6307
6308 uid: u32,
6309 gid: u32,
6310 rdev: u64,
6311 __pad2: u16,
6312
6313 size: off_t,
6314 blksize: isize,
6315 blocks: i64,
6316
6317 atim: timespec,
6318 mtim: timespec,
6319 ctim: timespec,
6320 __reserved: [2]usize,
6321
6322 pub fn atime(self: @This()) timespec {
6323 return self.atim;
6324 }
6325
6326 pub fn mtime(self: @This()) timespec {
6327 return self.mtim;
6328 }
6329
6330 pub fn ctime(self: @This()) timespec {
6331 return self.ctim;
6332 }
6333 },
6334 .mips, .mipsel => extern struct {
6335 dev: dev_t,
6336 __pad0: [2]u32,
6337 ino: ino_t,
6338 mode: mode_t,
6339 nlink: nlink_t,
6340 uid: uid_t,
6341 gid: gid_t,
6342 rdev: dev_t,
6343 __pad1: [2]u32,
6344 size: off_t,
6345 atim: timespec,
6346 mtim: timespec,
6347 ctim: timespec,
6348 blksize: blksize_t,
6349 __pad3: u32,
6350 blocks: blkcnt_t,
6351 __pad4: [14]u32,
6352
6353 pub fn atime(self: @This()) timespec {
6354 return self.atim;
6355 }
6356
6357 pub fn mtime(self: @This()) timespec {
6358 return self.mtim;
6359 }
6360
6361 pub fn ctime(self: @This()) timespec {
6362 return self.ctim;
6363 }
6364 },
6365
6366 else => std.os.linux.Stat, // libc stat is the same as kernel stat.
6367 },
6368 .emscripten => emscripten.Stat,
6369 .wasi => extern struct {
6370 dev: dev_t,
6371 ino: ino_t,
6372 nlink: nlink_t,
6373 mode: mode_t,
6374 uid: uid_t,
6375 gid: gid_t,
6376 __pad0: c_uint = 0,
6377 rdev: dev_t,
6378 size: off_t,
6379 blksize: blksize_t,
6380 blocks: blkcnt_t,
6381 atim: timespec,
6382 mtim: timespec,
6383 ctim: timespec,
6384 __reserved: [3]c_longlong = [3]c_longlong{ 0, 0, 0 },
6385
6386 pub fn atime(self: @This()) timespec {
6387 return self.atim;
6388 }
6389
6390 pub fn mtime(self: @This()) timespec {
6391 return self.mtim;
6392 }
6393
6394 pub fn ctime(self: @This()) timespec {
6395 return self.ctim;
6396 }
6397
6398 pub fn fromFilestat(st: wasi.filestat_t) Stat {
6399 return .{
6400 .dev = st.dev,
6401 .ino = st.ino,
6402 .mode = switch (st.filetype) {
6403 .UNKNOWN => 0,
6404 .BLOCK_DEVICE => S.IFBLK,
6405 .CHARACTER_DEVICE => S.IFCHR,
6406 .DIRECTORY => S.IFDIR,
6407 .REGULAR_FILE => S.IFREG,
6408 .SOCKET_DGRAM => S.IFSOCK,
6409 .SOCKET_STREAM => S.IFIFO,
6410 .SYMBOLIC_LINK => S.IFLNK,
6411 _ => 0,
6412 },
6413 .nlink = st.nlink,
6414 .size = @intCast(st.size),
6415 .atim = timespec.fromTimestamp(st.atim),
6416 .mtim = timespec.fromTimestamp(st.mtim),
6417 .ctim = timespec.fromTimestamp(st.ctim),
6418
6419 .uid = 0,
6420 .gid = 0,
6421 .rdev = 0,
6422 .blksize = 0,
6423 .blocks = 0,
6424 };
316425 }
32 };
33}
6426 },
6427 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
6428 dev: i32,
6429 mode: u16,
6430 nlink: u16,
6431 ino: ino_t,
6432 uid: uid_t,
6433 gid: gid_t,
6434 rdev: i32,
6435 atimespec: timespec,
6436 mtimespec: timespec,
6437 ctimespec: timespec,
6438 birthtimespec: timespec,
6439 size: off_t,
6440 blocks: i64,
6441 blksize: i32,
6442 flags: u32,
6443 gen: u32,
6444 lspare: i32,
6445 qspare: [2]i64,
346446
35pub usingnamespace switch (native_os) {
36 .linux => @import("c/linux.zig"),
37 .windows => @import("c/windows.zig"),
38 .macos, .ios, .tvos, .watchos, .visionos => @import("c/darwin.zig"),
39 .freebsd, .kfreebsd => @import("c/freebsd.zig"),
40 .netbsd => @import("c/netbsd.zig"),
41 .dragonfly => @import("c/dragonfly.zig"),
42 .openbsd => @import("c/openbsd.zig"),
43 .haiku => @import("c/haiku.zig"),
44 .solaris, .illumos => @import("c/solaris.zig"),
45 .emscripten => @import("c/emscripten.zig"),
46 .wasi => wasi,
47 else => struct {},
6447 pub fn atime(self: @This()) timespec {
6448 return self.atimespec;
6449 }
6450
6451 pub fn mtime(self: @This()) timespec {
6452 return self.mtimespec;
6453 }
6454
6455 pub fn ctime(self: @This()) timespec {
6456 return self.ctimespec;
6457 }
6458
6459 pub fn birthtime(self: @This()) timespec {
6460 return self.birthtimespec;
6461 }
6462 },
6463 .freebsd, .kfreebsd => freebsd.Stat,
6464 .solaris, .illumos => extern struct {
6465 dev: dev_t,
6466 ino: ino_t,
6467 mode: mode_t,
6468 nlink: nlink_t,
6469 uid: uid_t,
6470 gid: gid_t,
6471 rdev: dev_t,
6472 size: off_t,
6473 atim: timespec,
6474 mtim: timespec,
6475 ctim: timespec,
6476 blksize: blksize_t,
6477 blocks: blkcnt_t,
6478 fstype: [16]u8,
6479
6480 pub fn atime(self: @This()) timespec {
6481 return self.atim;
6482 }
6483
6484 pub fn mtime(self: @This()) timespec {
6485 return self.mtim;
6486 }
6487
6488 pub fn ctime(self: @This()) timespec {
6489 return self.ctim;
6490 }
6491 },
6492 .netbsd => extern struct {
6493 dev: dev_t,
6494 mode: mode_t,
6495 ino: ino_t,
6496 nlink: nlink_t,
6497 uid: uid_t,
6498 gid: gid_t,
6499 rdev: dev_t,
6500 atim: timespec,
6501 mtim: timespec,
6502 ctim: timespec,
6503 birthtim: timespec,
6504 size: off_t,
6505 blocks: blkcnt_t,
6506 blksize: blksize_t,
6507 flags: u32,
6508 gen: u32,
6509 __spare: [2]u32,
6510
6511 pub fn atime(self: @This()) timespec {
6512 return self.atim;
6513 }
6514
6515 pub fn mtime(self: @This()) timespec {
6516 return self.mtim;
6517 }
6518
6519 pub fn ctime(self: @This()) timespec {
6520 return self.ctim;
6521 }
6522
6523 pub fn birthtime(self: @This()) timespec {
6524 return self.birthtim;
6525 }
6526 },
6527 .dragonfly => extern struct {
6528 ino: ino_t,
6529 nlink: c_uint,
6530 dev: c_uint,
6531 mode: c_ushort,
6532 padding1: u16,
6533 uid: uid_t,
6534 gid: gid_t,
6535 rdev: c_uint,
6536 atim: timespec,
6537 mtim: timespec,
6538 ctim: timespec,
6539 size: c_ulong,
6540 blocks: i64,
6541 blksize: u32,
6542 flags: u32,
6543 gen: u32,
6544 lspare: i32,
6545 qspare1: i64,
6546 qspare2: i64,
6547 pub fn atime(self: @This()) timespec {
6548 return self.atim;
6549 }
6550
6551 pub fn mtime(self: @This()) timespec {
6552 return self.mtim;
6553 }
6554
6555 pub fn ctime(self: @This()) timespec {
6556 return self.ctim;
6557 }
6558 },
6559 .haiku => extern struct {
6560 dev: dev_t,
6561 ino: ino_t,
6562 mode: mode_t,
6563 nlink: nlink_t,
6564 uid: uid_t,
6565 gid: gid_t,
6566 size: off_t,
6567 rdev: dev_t,
6568 blksize: blksize_t,
6569 atim: timespec,
6570 mtim: timespec,
6571 ctim: timespec,
6572 crtim: timespec,
6573 type: u32,
6574 blocks: blkcnt_t,
6575
6576 pub fn atime(self: @This()) timespec {
6577 return self.atim;
6578 }
6579 pub fn mtime(self: @This()) timespec {
6580 return self.mtim;
6581 }
6582 pub fn ctime(self: @This()) timespec {
6583 return self.ctim;
6584 }
6585 pub fn birthtime(self: @This()) timespec {
6586 return self.crtim;
6587 }
6588 },
6589 .openbsd => extern struct {
6590 mode: mode_t,
6591 dev: dev_t,
6592 ino: ino_t,
6593 nlink: nlink_t,
6594 uid: uid_t,
6595 gid: gid_t,
6596 rdev: dev_t,
6597 atim: timespec,
6598 mtim: timespec,
6599 ctim: timespec,
6600 size: off_t,
6601 blocks: blkcnt_t,
6602 blksize: blksize_t,
6603 flags: u32,
6604 gen: u32,
6605 birthtim: timespec,
6606
6607 pub fn atime(self: @This()) timespec {
6608 return self.atim;
6609 }
6610
6611 pub fn mtime(self: @This()) timespec {
6612 return self.mtim;
6613 }
6614
6615 pub fn ctime(self: @This()) timespec {
6616 return self.ctim;
6617 }
6618
6619 pub fn birthtime(self: @This()) timespec {
6620 return self.birthtim;
6621 }
6622 },
6623 else => void,
486624};
496625
506626pub const pthread_mutex_t = switch (native_os) {
......@@ -73,12 +6649,12 @@ pub const pthread_mutex_t = switch (native_os) {
736649 inner: ?*anyopaque = null,
746650 },
756651 .hermit => extern struct {
76 ptr: usize = std.math.maxInt(usize),
6652 ptr: usize = maxInt(usize),
776653 },
786654 .netbsd => extern struct {
796655 magic: u32 = 0x33330003,
80 errorcheck: c.padded_pthread_spin_t = 0,
81 ceiling: c.padded_pthread_spin_t = 0,
6656 errorcheck: padded_pthread_spin_t = 0,
6657 ceiling: padded_pthread_spin_t = 0,
826658 owner: usize = 0,
836659 waiters: ?*u8 = null,
846660 recursed: u32 = 0,
......@@ -106,7 +6682,7 @@ pub const pthread_mutex_t = switch (native_os) {
1066682 .emscripten => extern struct {
1076683 data: [24]u8 align(4) = [_]u8{0} ** 24,
1086684 },
109 else => @compileError("target libc does not have pthread_mutex_t"),
6685 else => void,
1106686};
1116687
1126688pub const pthread_cond_t = switch (native_os) {
......@@ -122,11 +6698,11 @@ pub const pthread_cond_t = switch (native_os) {
1226698 inner: ?*anyopaque = null,
1236699 },
1246700 .hermit => extern struct {
125 ptr: usize = std.math.maxInt(usize),
6701 ptr: usize = maxInt(usize),
1266702 },
1276703 .netbsd => extern struct {
1286704 magic: u32 = 0x55550005,
129 lock: c.pthread_spin_t = 0,
6705 lock: pthread_spin_t = 0,
1306706 waiters_first: ?*u8 = null,
1316707 waiters_last: ?*u8 = null,
1326708 mutex: ?*pthread_mutex_t = null,
......@@ -148,7 +6724,7 @@ pub const pthread_cond_t = switch (native_os) {
1486724 .fuchsia, .minix, .emscripten => extern struct {
1496725 data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48,
1506726 },
151 else => @compileError("target libc does not have pthread_cond_t"),
6727 else => void,
1526728};
1536729
1546730pub const pthread_rwlock_t = switch (native_os) {
......@@ -174,7 +6750,7 @@ pub const pthread_rwlock_t = switch (native_os) {
1746750 ptr: ?*anyopaque = null,
1756751 },
1766752 .hermit => extern struct {
177 ptr: usize = std.math.maxInt(usize),
6753 ptr: usize = maxInt(usize),
1786754 },
1796755 .netbsd => extern struct {
1806756 magic: c_uint = 0x99990009,
......@@ -205,7 +6781,185 @@ pub const pthread_rwlock_t = switch (native_os) {
2056781 .emscripten => extern struct {
2066782 size: [32]u8 align(4) = [_]u8{0} ** 32,
2076783 },
208 else => @compileError("target libc does not have pthread_rwlock_t"),
6784 else => void,
6785};
6786
6787pub const pthread_attr_t = switch (native_os) {
6788 .linux, .emscripten, .dragonfly => extern struct {
6789 __size: [56]u8,
6790 __align: c_long,
6791 },
6792 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
6793 __sig: c_long,
6794 __opaque: [56]u8,
6795 },
6796 .freebsd, .kfreebsd => extern struct {
6797 inner: ?*anyopaque = null,
6798 },
6799 .solaris, .illumos => extern struct {
6800 mutexattr: ?*anyopaque = null,
6801 },
6802 .netbsd => extern struct {
6803 magic: u32,
6804 flags: i32,
6805 private: ?*anyopaque,
6806 },
6807 .haiku => extern struct {
6808 detach_state: i32,
6809 sched_priority: i32,
6810 stack_size: i32,
6811 guard_size: i32,
6812 stack_address: ?*anyopaque,
6813 },
6814 .openbsd => extern struct {
6815 inner: ?*anyopaque = null,
6816 },
6817 else => void,
6818};
6819
6820pub const pthread_key_t = switch (native_os) {
6821 .linux, .emscripten => c_uint,
6822 .openbsd, .solaris, .illumos => c_int,
6823 else => void,
6824};
6825
6826pub const padded_pthread_spin_t = switch (native_os) {
6827 .netbsd => switch (builtin.cpu.arch) {
6828 .x86, .x86_64 => u32,
6829 .sparc, .sparcel, .sparc64 => u32,
6830 else => pthread_spin_t,
6831 },
6832 else => void,
6833};
6834
6835pub const pthread_spin_t = switch (native_os) {
6836 .netbsd => switch (builtin.cpu.arch) {
6837 .aarch64, .aarch64_be, .aarch64_32 => u8,
6838 .mips, .mipsel, .mips64, .mips64el => u32,
6839 .powerpc, .powerpc64, .powerpc64le => i32,
6840 .x86, .x86_64 => u8,
6841 .arm, .armeb, .thumb, .thumbeb => i32,
6842 .sparc, .sparcel, .sparc64 => u8,
6843 .riscv32, .riscv64 => u32,
6844 else => @compileError("undefined pthread_spin_t for this arch"),
6845 },
6846 else => void,
6847};
6848
6849pub const sem_t = switch (native_os) {
6850 .linux, .emscripten => extern struct {
6851 __size: [4 * @sizeOf(usize)]u8 align(@alignOf(usize)),
6852 },
6853 .macos, .ios, .tvos, .watchos, .visionos => c_int,
6854 .freebsd, .kfreebsd => extern struct {
6855 _magic: u32,
6856 _kern: extern struct {
6857 _count: u32,
6858 _flags: u32,
6859 },
6860 _padding: u32,
6861 },
6862 .solaris, .illumos => extern struct {
6863 count: u32 = 0,
6864 type: u16 = 0,
6865 magic: u16 = 0x534d,
6866 __pad1: [3]u64 = [_]u64{0} ** 3,
6867 __pad2: [2]u64 = [_]u64{0} ** 2,
6868 },
6869 .openbsd, .netbsd, .dragonfly => ?*opaque {},
6870 .haiku => extern struct {
6871 type: i32,
6872 u: extern union {
6873 named_sem_id: i32,
6874 unnamed_sem: i32,
6875 },
6876 padding: [2]i32,
6877 },
6878 else => void,
6879};
6880
6881/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
6882pub const Kevent = switch (native_os) {
6883 .netbsd => extern struct {
6884 ident: usize,
6885 filter: i32,
6886 flags: u32,
6887 fflags: u32,
6888 data: i64,
6889 udata: usize,
6890 },
6891 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
6892 ident: usize,
6893 filter: i16,
6894 flags: u16,
6895 fflags: u32,
6896 data: isize,
6897 udata: usize,
6898
6899 // sys/types.h on macos uses #pragma pack(4) so these checks are
6900 // to make sure the struct is laid out the same. These values were
6901 // produced from C code using the offsetof macro.
6902 comptime {
6903 assert(@offsetOf(@This(), "ident") == 0);
6904 assert(@offsetOf(@This(), "filter") == 8);
6905 assert(@offsetOf(@This(), "flags") == 10);
6906 assert(@offsetOf(@This(), "fflags") == 12);
6907 assert(@offsetOf(@This(), "data") == 16);
6908 assert(@offsetOf(@This(), "udata") == 24);
6909 }
6910 },
6911 .freebsd, .kfreebsd => extern struct {
6912 /// Identifier for this event.
6913 ident: usize,
6914 /// Filter for event.
6915 filter: i16,
6916 /// Action flags for kqueue.
6917 flags: u16,
6918 /// Filter flag value.
6919 fflags: u32,
6920 /// Filter data value.
6921 data: i64,
6922 /// Opaque user data identifier.
6923 udata: usize,
6924 /// Future extensions.
6925 _ext: [4]u64 = [_]u64{0} ** 4,
6926 },
6927 .dragonfly => extern struct {
6928 ident: usize,
6929 filter: c_short,
6930 flags: c_ushort,
6931 fflags: c_uint,
6932 data: isize,
6933 udata: usize,
6934 },
6935 .openbsd => extern struct {
6936 ident: usize,
6937 filter: c_short,
6938 flags: u16,
6939 fflags: c_uint,
6940 data: i64,
6941 udata: usize,
6942 },
6943 else => void,
6944};
6945
6946pub const port_t = switch (native_os) {
6947 .solaris, .illumos => c_int,
6948 else => void,
6949};
6950
6951pub const port_event = switch (native_os) {
6952 .solaris, .illumos => extern struct {
6953 events: u32,
6954 /// Event source.
6955 source: u16,
6956 __pad: u16,
6957 /// Source-specific object.
6958 object: ?*anyopaque,
6959 /// User cookie.
6960 cookie: ?*anyopaque,
6961 },
6962 else => void,
2096963};
2106964
2116965pub const AT = switch (native_os) {
......@@ -287,7 +7041,7 @@ pub const AT = switch (native_os) {
2877041 /// Magic value that specify the use of the current working directory
2887042 /// to determine the target of relative file paths in the openat() and
2897043 /// similar syscalls.
290 pub const FDCWD: c.fd_t = @bitCast(@as(u32, 0xffd19553));
7044 pub const FDCWD: fd_t = @bitCast(@as(u32, 0xffd19553));
2917045 /// Do not follow symbolic links
2927046 pub const SYMLINK_NOFOLLOW = 0x1000;
2937047 /// Follow symbolic link
......@@ -320,10 +7074,10 @@ pub const AT = switch (native_os) {
3207074 /// current working directory is the first preopen. This behavior can be
3217075 /// overridden with a public function called `wasi_cwd` in the root source
3227076 /// file.
323 pub const FDCWD: c.fd_t = if (builtin.link_libc) -2 else 3;
7077 pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3;
3247078 },
3257079
326 else => @compileError("target libc does not have AT"),
7080 else => void,
3277081};
3287082
3297083pub const O = switch (native_os) {
......@@ -511,7 +7265,7 @@ pub const O = switch (native_os) {
5117265 DIRECTORY: bool = false,
5127266 _: u4 = 0,
5137267 },
514 .freebsd => packed struct(u32) {
7268 .freebsd, .kfreebsd => packed struct(u32) {
5157269 ACCMODE: std.posix.ACCMODE = .RDONLY,
5167270 NONBLOCK: bool = false,
5177271 APPEND: bool = false,
......@@ -535,7 +7289,7 @@ pub const O = switch (native_os) {
5357289 TMPFILE: bool = false,
5367290 _: u9 = 0,
5377291 },
538 else => @compileError("target libc does not have O"),
7292 else => void,
5397293};
5407294
5417295pub const MAP = switch (native_os) {
......@@ -656,7 +7410,7 @@ pub const MAP = switch (native_os) {
6567410 SIZEALIGN: bool = false,
6577411 _: u13 = 0,
6587412 },
659 .freebsd => packed struct(u32) {
7413 .freebsd, .kfreebsd => packed struct(u32) {
6607414 TYPE: enum(u4) {
6617415 SHARED = 0x01,
6627416 PRIVATE = 0x02,
......@@ -674,11 +7428,11 @@ pub const MAP = switch (native_os) {
6747428 @"32BIT": bool = false,
6757429 _: u12 = 0,
6767430 },
677 else => @compileError("target libc does not have MAP"),
7431 else => void,
6787432};
6797433
6807434/// Used by libc to communicate failure. Not actually part of the underlying syscall.
681pub const MAP_FAILED: *anyopaque = @ptrFromInt(std.math.maxInt(usize));
7435pub const MAP_FAILED: *anyopaque = @ptrFromInt(maxInt(usize));
6827436
6837437pub const cc_t = u8;
6847438
......@@ -779,7 +7533,7 @@ pub const V = switch (native_os) {
7797533 LNEXT,
7807534 EOL2,
7817535 },
782 else => @compileError("target libc does not have cc_t"),
7536 else => void,
7837537};
7847538
7857539pub const NCCS = switch (native_os) {
......@@ -788,7 +7542,7 @@ pub const NCCS = switch (native_os) {
7887542 .haiku => 11,
7897543 .solaris, .illumos => 19,
7907544 .emscripten, .wasi => 32,
791 else => @compileError("target libc does not have NCCS"),
7545 else => void,
7927546};
7937547
7947548pub const termios = switch (native_os) {
......@@ -833,12 +7587,12 @@ pub const termios = switch (native_os) {
8337587 oflag: tc_oflag_t,
8347588 cflag: tc_cflag_t,
8357589 lflag: tc_lflag_t,
836 line: std.c.cc_t,
7590 line: cc_t,
8377591 cc: [NCCS]cc_t,
8387592 ispeed: speed_t,
8397593 ospeed: speed_t,
8407594 },
841 else => @compileError("target libc does not have termios"),
7595 else => void,
8427596};
8437597
8447598pub const tc_iflag_t = switch (native_os) {
......@@ -948,7 +7702,7 @@ pub const tc_iflag_t = switch (native_os) {
9487702 IUTF8: bool = false,
9497703 _: u17 = 0,
9507704 },
951 else => @compileError("target libc does not have tc_iflag_t"),
7705 else => void,
9527706};
9537707
9547708pub const tc_oflag_t = switch (native_os) {
......@@ -1039,7 +7793,7 @@ pub const tc_oflag_t = switch (native_os) {
10397793 FFDLY: u1 = 0,
10407794 _: u16 = 0,
10417795 },
1042 else => @compileError("target libc does not have tc_oflag_t"),
7796 else => void,
10437797};
10447798
10457799pub const CSIZE = switch (native_os) {
......@@ -1181,7 +7935,7 @@ pub const tc_cflag_t = switch (native_os) {
11817935 CLOCAL: bool = false,
11827936 _: u20 = 0,
11837937 },
1184 else => @compileError("target libc does not have tc_cflag_t"),
7938 else => void,
11857939};
11867940
11877941pub const tc_lflag_t = switch (native_os) {
......@@ -1307,7 +8061,7 @@ pub const tc_lflag_t = switch (native_os) {
13078061 IEXTEN: bool = false,
13088062 _: u16 = 0,
13098063 },
1310 else => @compileError("target libc does not have tc_lflag_t"),
8064 else => void,
13118065};
13128066
13138067pub const speed_t = switch (native_os) {
......@@ -1489,11 +8243,543 @@ pub const speed_t = switch (native_os) {
14898243 B3500000 = 0o0010016,
14908244 B4000000 = 0o0010017,
14918245 },
1492 else => @compileError("target libc does not have speed_t"),
8246 else => void,
14938247};
14948248
14958249pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;
14968250
8251pub const sig_atomic_t = c_int;
8252
8253/// maximum signal number + 1
8254pub const NSIG = switch (native_os) {
8255 .linux => linux.NSIG,
8256 .windows => 23,
8257 .haiku => 65,
8258 .netbsd, .freebsd, .kfreebsd => 32,
8259 .solaris, .illumos => 75,
8260 .openbsd => 33,
8261 else => {},
8262};
8263
8264pub const MINSIGSTKSZ = switch (native_os) {
8265 .macos, .ios, .tvos, .watchos, .visionos => 32768,
8266 .freebsd, .kfreebsd => switch (builtin.cpu.arch) {
8267 .x86, .x86_64 => 2048,
8268 .arm, .aarch64 => 4096,
8269 else => @compileError("unsupported arch"),
8270 },
8271 .solaris, .illumos => 2048,
8272 .haiku, .netbsd => 8192,
8273 .openbsd => 1 << openbsd.MAX_PAGE_SHIFT,
8274 else => {},
8275};
8276pub const SIGSTKSZ = switch (native_os) {
8277 .macos, .ios, .tvos, .watchos, .visionos => 131072,
8278 .netbsd, .freebsd, .kfreebsd => MINSIGSTKSZ + 32768,
8279 .solaris, .illumos => 8192,
8280 .haiku => 16384,
8281 .openbsd => MINSIGSTKSZ + (1 << openbsd.MAX_PAGE_SHIFT) * 4,
8282 else => {},
8283};
8284pub const SS = switch (native_os) {
8285 .linux => linux.SS,
8286 .openbsd, .macos, .ios, .tvos, .watchos, .visionos, .netbsd, .freebsd, .kfreebsd => struct {
8287 pub const ONSTACK = 1;
8288 pub const DISABLE = 4;
8289 },
8290 .haiku, .solaris, .illumos => struct {
8291 pub const ONSTACK = 0x1;
8292 pub const DISABLE = 0x2;
8293 },
8294 else => void,
8295};
8296
8297pub const EV = switch (native_os) {
8298 .macos, .ios, .tvos, .watchos, .visionos => struct {
8299 /// add event to kq (implies enable)
8300 pub const ADD = 0x0001;
8301 /// delete event from kq
8302 pub const DELETE = 0x0002;
8303 /// enable event
8304 pub const ENABLE = 0x0004;
8305 /// disable event (not reported)
8306 pub const DISABLE = 0x0008;
8307 /// only report one occurrence
8308 pub const ONESHOT = 0x0010;
8309 /// clear event state after reporting
8310 pub const CLEAR = 0x0020;
8311 /// force immediate event output
8312 /// ... with or without ERROR
8313 /// ... use KEVENT_FLAG_ERROR_EVENTS
8314 /// on syscalls supporting flags
8315 pub const RECEIPT = 0x0040;
8316 /// disable event after reporting
8317 pub const DISPATCH = 0x0080;
8318 /// unique kevent per udata value
8319 pub const UDATA_SPECIFIC = 0x0100;
8320 /// ... in combination with DELETE
8321 /// will defer delete until udata-specific
8322 /// event enabled. EINPROGRESS will be
8323 /// returned to indicate the deferral
8324 pub const DISPATCH2 = DISPATCH | UDATA_SPECIFIC;
8325 /// report that source has vanished
8326 /// ... only valid with DISPATCH2
8327 pub const VANISHED = 0x0200;
8328 /// reserved by system
8329 pub const SYSFLAGS = 0xF000;
8330 /// filter-specific flag
8331 pub const FLAG0 = 0x1000;
8332 /// filter-specific flag
8333 pub const FLAG1 = 0x2000;
8334 /// EOF detected
8335 pub const EOF = 0x8000;
8336 /// error, data contains errno
8337 pub const ERROR = 0x4000;
8338 pub const POLL = FLAG0;
8339 pub const OOBAND = FLAG1;
8340 },
8341 .dragonfly => struct {
8342 pub const ADD = 1;
8343 pub const DELETE = 2;
8344 pub const ENABLE = 4;
8345 pub const DISABLE = 8;
8346 pub const ONESHOT = 16;
8347 pub const CLEAR = 32;
8348 pub const RECEIPT = 64;
8349 pub const DISPATCH = 128;
8350 pub const NODATA = 4096;
8351 pub const FLAG1 = 8192;
8352 pub const ERROR = 16384;
8353 pub const EOF = 32768;
8354 pub const SYSFLAGS = 61440;
8355 },
8356 .netbsd => struct {
8357 /// add event to kq (implies enable)
8358 pub const ADD = 0x0001;
8359 /// delete event from kq
8360 pub const DELETE = 0x0002;
8361 /// enable event
8362 pub const ENABLE = 0x0004;
8363 /// disable event (not reported)
8364 pub const DISABLE = 0x0008;
8365 /// only report one occurrence
8366 pub const ONESHOT = 0x0010;
8367 /// clear event state after reporting
8368 pub const CLEAR = 0x0020;
8369 /// force immediate event output
8370 /// ... with or without ERROR
8371 /// ... use KEVENT_FLAG_ERROR_EVENTS
8372 /// on syscalls supporting flags
8373 pub const RECEIPT = 0x0040;
8374 /// disable event after reporting
8375 pub const DISPATCH = 0x0080;
8376 },
8377 .freebsd => struct {
8378 /// add event to kq (implies enable)
8379 pub const ADD = 0x0001;
8380 /// delete event from kq
8381 pub const DELETE = 0x0002;
8382 /// enable event
8383 pub const ENABLE = 0x0004;
8384 /// disable event (not reported)
8385 pub const DISABLE = 0x0008;
8386 /// only report one occurrence
8387 pub const ONESHOT = 0x0010;
8388 /// clear event state after reporting
8389 pub const CLEAR = 0x0020;
8390 /// error, event data contains errno
8391 pub const ERROR = 0x4000;
8392 /// force immediate event output
8393 /// ... with or without ERROR
8394 /// ... use KEVENT_FLAG_ERROR_EVENTS
8395 /// on syscalls supporting flags
8396 pub const RECEIPT = 0x0040;
8397 /// disable event after reporting
8398 pub const DISPATCH = 0x0080;
8399 },
8400 .openbsd => struct {
8401 pub const ADD = 0x0001;
8402 pub const DELETE = 0x0002;
8403 pub const ENABLE = 0x0004;
8404 pub const DISABLE = 0x0008;
8405 pub const ONESHOT = 0x0010;
8406 pub const CLEAR = 0x0020;
8407 pub const RECEIPT = 0x0040;
8408 pub const DISPATCH = 0x0080;
8409 pub const FLAG1 = 0x2000;
8410 pub const ERROR = 0x4000;
8411 pub const EOF = 0x8000;
8412 },
8413 .haiku => struct {
8414 /// add event to kq (implies enable)
8415 pub const ADD = 0x0001;
8416 /// delete event from kq
8417 pub const DELETE = 0x0002;
8418 /// enable event
8419 pub const ENABLE = 0x0004;
8420 /// disable event (not reported)
8421 pub const DISABLE = 0x0008;
8422 /// only report one occurrence
8423 pub const ONESHOT = 0x0010;
8424 /// clear event state after reporting
8425 pub const CLEAR = 0x0020;
8426 /// force immediate event output
8427 /// ... with or without ERROR
8428 /// ... use KEVENT_FLAG_ERROR_EVENTS
8429 /// on syscalls supporting flags
8430 pub const RECEIPT = 0x0040;
8431 /// disable event after reporting
8432 pub const DISPATCH = 0x0080;
8433 },
8434 else => void,
8435};
8436
8437pub const EVFILT = switch (native_os) {
8438 .macos, .ios, .tvos, .watchos, .visionos => struct {
8439 pub const READ = -1;
8440 pub const WRITE = -2;
8441 /// attached to aio requests
8442 pub const AIO = -3;
8443 /// attached to vnodes
8444 pub const VNODE = -4;
8445 /// attached to struct proc
8446 pub const PROC = -5;
8447 /// attached to struct proc
8448 pub const SIGNAL = -6;
8449 /// timers
8450 pub const TIMER = -7;
8451 /// Mach portsets
8452 pub const MACHPORT = -8;
8453 /// Filesystem events
8454 pub const FS = -9;
8455 /// User events
8456 pub const USER = -10;
8457 /// Virtual memory events
8458 pub const VM = -12;
8459 /// Exception events
8460 pub const EXCEPT = -15;
8461 pub const SYSCOUNT = 17;
8462 },
8463 .haiku => struct {
8464 pub const READ = -1;
8465 pub const WRITE = -2;
8466 /// attached to aio requests
8467 pub const AIO = -3;
8468 /// attached to vnodes
8469 pub const VNODE = -4;
8470 /// attached to struct proc
8471 pub const PROC = -5;
8472 /// attached to struct proc
8473 pub const SIGNAL = -6;
8474 /// timers
8475 pub const TIMER = -7;
8476 /// Process descriptors
8477 pub const PROCDESC = -8;
8478 /// Filesystem events
8479 pub const FS = -9;
8480 pub const LIO = -10;
8481 /// User events
8482 pub const USER = -11;
8483 /// Sendfile events
8484 pub const SENDFILE = -12;
8485 pub const EMPTY = -13;
8486 },
8487 .dragonfly => struct {
8488 pub const FS = -10;
8489 pub const USER = -9;
8490 pub const EXCEPT = -8;
8491 pub const TIMER = -7;
8492 pub const SIGNAL = -6;
8493 pub const PROC = -5;
8494 pub const VNODE = -4;
8495 pub const AIO = -3;
8496 pub const WRITE = -2;
8497 pub const READ = -1;
8498 pub const SYSCOUNT = 10;
8499 pub const MARKER = 15;
8500 },
8501 .netbsd => struct {
8502 pub const READ = 0;
8503 pub const WRITE = 1;
8504 /// attached to aio requests
8505 pub const AIO = 2;
8506 /// attached to vnodes
8507 pub const VNODE = 3;
8508 /// attached to struct proc
8509 pub const PROC = 4;
8510 /// attached to struct proc
8511 pub const SIGNAL = 5;
8512 /// timers
8513 pub const TIMER = 6;
8514 /// Filesystem events
8515 pub const FS = 7;
8516 /// User events
8517 pub const USER = 1;
8518 },
8519 .freebsd => struct {
8520 pub const READ = -1;
8521 pub const WRITE = -2;
8522 /// attached to aio requests
8523 pub const AIO = -3;
8524 /// attached to vnodes
8525 pub const VNODE = -4;
8526 /// attached to struct proc
8527 pub const PROC = -5;
8528 /// attached to struct proc
8529 pub const SIGNAL = -6;
8530 /// timers
8531 pub const TIMER = -7;
8532 /// Process descriptors
8533 pub const PROCDESC = -8;
8534 /// Filesystem events
8535 pub const FS = -9;
8536 pub const LIO = -10;
8537 /// User events
8538 pub const USER = -11;
8539 /// Sendfile events
8540 pub const SENDFILE = -12;
8541 pub const EMPTY = -13;
8542 },
8543 .openbsd => struct {
8544 pub const READ = -1;
8545 pub const WRITE = -2;
8546 pub const AIO = -3;
8547 pub const VNODE = -4;
8548 pub const PROC = -5;
8549 pub const SIGNAL = -6;
8550 pub const TIMER = -7;
8551 pub const EXCEPT = -9;
8552 },
8553 else => void,
8554};
8555
8556pub const NOTE = switch (native_os) {
8557 .macos, .ios, .tvos, .watchos, .visionos => struct {
8558 /// On input, TRIGGER causes the event to be triggered for output.
8559 pub const TRIGGER = 0x01000000;
8560 /// ignore input fflags
8561 pub const FFNOP = 0x00000000;
8562 /// and fflags
8563 pub const FFAND = 0x40000000;
8564 /// or fflags
8565 pub const FFOR = 0x80000000;
8566 /// copy fflags
8567 pub const FFCOPY = 0xc0000000;
8568 /// mask for operations
8569 pub const FFCTRLMASK = 0xc0000000;
8570 pub const FFLAGSMASK = 0x00ffffff;
8571 /// low water mark
8572 pub const LOWAT = 0x00000001;
8573 /// OOB data
8574 pub const OOB = 0x00000002;
8575 /// vnode was removed
8576 pub const DELETE = 0x00000001;
8577 /// data contents changed
8578 pub const WRITE = 0x00000002;
8579 /// size increased
8580 pub const EXTEND = 0x00000004;
8581 /// attributes changed
8582 pub const ATTRIB = 0x00000008;
8583 /// link count changed
8584 pub const LINK = 0x00000010;
8585 /// vnode was renamed
8586 pub const RENAME = 0x00000020;
8587 /// vnode access was revoked
8588 pub const REVOKE = 0x00000040;
8589 /// No specific vnode event: to test for EVFILT_READ activation
8590 pub const NONE = 0x00000080;
8591 /// vnode was unlocked by flock(2)
8592 pub const FUNLOCK = 0x00000100;
8593 /// process exited
8594 pub const EXIT = 0x80000000;
8595 /// process forked
8596 pub const FORK = 0x40000000;
8597 /// process exec'd
8598 pub const EXEC = 0x20000000;
8599 /// shared with EVFILT_SIGNAL
8600 pub const SIGNAL = 0x08000000;
8601 /// exit status to be returned, valid for child process only
8602 pub const EXITSTATUS = 0x04000000;
8603 /// provide details on reasons for exit
8604 pub const EXIT_DETAIL = 0x02000000;
8605 /// mask for signal & exit status
8606 pub const PDATAMASK = 0x000fffff;
8607 pub const PCTRLMASK = (~PDATAMASK);
8608 pub const EXIT_DETAIL_MASK = 0x00070000;
8609 pub const EXIT_DECRYPTFAIL = 0x00010000;
8610 pub const EXIT_MEMORY = 0x00020000;
8611 pub const EXIT_CSERROR = 0x00040000;
8612 /// will react on memory pressure
8613 pub const VM_PRESSURE = 0x80000000;
8614 /// will quit on memory pressure, possibly after cleaning up dirty state
8615 pub const VM_PRESSURE_TERMINATE = 0x40000000;
8616 /// will quit immediately on memory pressure
8617 pub const VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
8618 /// there was an error
8619 pub const VM_ERROR = 0x10000000;
8620 /// data is seconds
8621 pub const SECONDS = 0x00000001;
8622 /// data is microseconds
8623 pub const USECONDS = 0x00000002;
8624 /// data is nanoseconds
8625 pub const NSECONDS = 0x00000004;
8626 /// absolute timeout
8627 pub const ABSOLUTE = 0x00000008;
8628 /// ext[1] holds leeway for power aware timers
8629 pub const LEEWAY = 0x00000010;
8630 /// system does minimal timer coalescing
8631 pub const CRITICAL = 0x00000020;
8632 /// system does maximum timer coalescing
8633 pub const BACKGROUND = 0x00000040;
8634 pub const MACH_CONTINUOUS_TIME = 0x00000080;
8635 /// data is mach absolute time units
8636 pub const MACHTIME = 0x00000100;
8637 },
8638 .dragonfly => struct {
8639 pub const FFNOP = 0;
8640 pub const TRACK = 1;
8641 pub const DELETE = 1;
8642 pub const LOWAT = 1;
8643 pub const TRACKERR = 2;
8644 pub const OOB = 2;
8645 pub const WRITE = 2;
8646 pub const EXTEND = 4;
8647 pub const CHILD = 4;
8648 pub const ATTRIB = 8;
8649 pub const LINK = 16;
8650 pub const RENAME = 32;
8651 pub const REVOKE = 64;
8652 pub const PDATAMASK = 1048575;
8653 pub const FFLAGSMASK = 16777215;
8654 pub const TRIGGER = 16777216;
8655 pub const EXEC = 536870912;
8656 pub const FFAND = 1073741824;
8657 pub const FORK = 1073741824;
8658 pub const EXIT = 2147483648;
8659 pub const FFOR = 2147483648;
8660 pub const FFCTRLMASK = 3221225472;
8661 pub const FFCOPY = 3221225472;
8662 pub const PCTRLMASK = 4026531840;
8663 },
8664 .netbsd => struct {
8665 /// On input, TRIGGER causes the event to be triggered for output.
8666 pub const TRIGGER = 0x08000000;
8667 /// low water mark
8668 pub const LOWAT = 0x00000001;
8669 /// vnode was removed
8670 pub const DELETE = 0x00000001;
8671 /// data contents changed
8672 pub const WRITE = 0x00000002;
8673 /// size increased
8674 pub const EXTEND = 0x00000004;
8675 /// attributes changed
8676 pub const ATTRIB = 0x00000008;
8677 /// link count changed
8678 pub const LINK = 0x00000010;
8679 /// vnode was renamed
8680 pub const RENAME = 0x00000020;
8681 /// vnode access was revoked
8682 pub const REVOKE = 0x00000040;
8683 /// process exited
8684 pub const EXIT = 0x80000000;
8685 /// process forked
8686 pub const FORK = 0x40000000;
8687 /// process exec'd
8688 pub const EXEC = 0x20000000;
8689 /// mask for signal & exit status
8690 pub const PDATAMASK = 0x000fffff;
8691 pub const PCTRLMASK = 0xf0000000;
8692 },
8693 .freebsd => struct {
8694 /// On input, TRIGGER causes the event to be triggered for output.
8695 pub const TRIGGER = 0x01000000;
8696 /// ignore input fflags
8697 pub const FFNOP = 0x00000000;
8698 /// and fflags
8699 pub const FFAND = 0x40000000;
8700 /// or fflags
8701 pub const FFOR = 0x80000000;
8702 /// copy fflags
8703 pub const FFCOPY = 0xc0000000;
8704 /// mask for operations
8705 pub const FFCTRLMASK = 0xc0000000;
8706 pub const FFLAGSMASK = 0x00ffffff;
8707 /// low water mark
8708 pub const LOWAT = 0x00000001;
8709 /// behave like poll()
8710 pub const FILE_POLL = 0x00000002;
8711 /// vnode was removed
8712 pub const DELETE = 0x00000001;
8713 /// data contents changed
8714 pub const WRITE = 0x00000002;
8715 /// size increased
8716 pub const EXTEND = 0x00000004;
8717 /// attributes changed
8718 pub const ATTRIB = 0x00000008;
8719 /// link count changed
8720 pub const LINK = 0x00000010;
8721 /// vnode was renamed
8722 pub const RENAME = 0x00000020;
8723 /// vnode access was revoked
8724 pub const REVOKE = 0x00000040;
8725 /// vnode was opened
8726 pub const OPEN = 0x00000080;
8727 /// file closed, fd did not allow write
8728 pub const CLOSE = 0x00000100;
8729 /// file closed, fd did allow write
8730 pub const CLOSE_WRITE = 0x00000200;
8731 /// file was read
8732 pub const READ = 0x00000400;
8733 /// process exited
8734 pub const EXIT = 0x80000000;
8735 /// process forked
8736 pub const FORK = 0x40000000;
8737 /// process exec'd
8738 pub const EXEC = 0x20000000;
8739 /// mask for signal & exit status
8740 pub const PDATAMASK = 0x000fffff;
8741 pub const PCTRLMASK = (~PDATAMASK);
8742 /// data is seconds
8743 pub const SECONDS = 0x00000001;
8744 /// data is milliseconds
8745 pub const MSECONDS = 0x00000002;
8746 /// data is microseconds
8747 pub const USECONDS = 0x00000004;
8748 /// data is nanoseconds
8749 pub const NSECONDS = 0x00000008;
8750 /// timeout is absolute
8751 pub const ABSTIME = 0x00000010;
8752 },
8753 .openbsd => struct {
8754 // data/hint flags for EVFILT.{READ|WRITE}
8755 pub const LOWAT = 0x0001;
8756 pub const EOF = 0x0002;
8757 // data/hint flags for EVFILT.EXCEPT and EVFILT.{READ|WRITE}
8758 pub const OOB = 0x0004;
8759 // data/hint flags for EVFILT.VNODE
8760 pub const DELETE = 0x0001;
8761 pub const WRITE = 0x0002;
8762 pub const EXTEND = 0x0004;
8763 pub const ATTRIB = 0x0008;
8764 pub const LINK = 0x0010;
8765 pub const RENAME = 0x0020;
8766 pub const REVOKE = 0x0040;
8767 pub const TRUNCATE = 0x0080;
8768 // data/hint flags for EVFILT.PROC
8769 pub const EXIT = 0x80000000;
8770 pub const FORK = 0x40000000;
8771 pub const EXEC = 0x20000000;
8772 pub const PDATAMASK = 0x000fffff;
8773 pub const PCTRLMASK = 0xf0000000;
8774 pub const TRACK = 0x00000001;
8775 pub const TRACKERR = 0x00000002;
8776 pub const CHILD = 0x00000004;
8777 // data/hint flags for EVFILT.DEVICE
8778 pub const CHANGE = 0x00000001;
8779 },
8780 else => void,
8781};
8782
14978783// Unix-like systems
14988784pub const DIR = opaque {};
14998785pub extern "c" fn opendir(pathname: [*:0]const u8) ?*DIR;
......@@ -1503,10 +8789,15 @@ pub extern "c" fn closedir(dp: *DIR) c_int;
15038789pub extern "c" fn telldir(dp: *DIR) c_long;
15048790pub extern "c" fn seekdir(dp: *DIR, loc: c_long) void;
15058791
1506pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
8792pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
15078793
15088794pub extern "c" fn alarm(seconds: c_uint) c_uint;
15098795
8796pub const close = switch (native_os) {
8797 .macos, .ios, .tvos, .watchos, .visionos => darwin.@"close$NOCANCEL",
8798 else => private.close,
8799};
8800
15108801pub const clock_getres = switch (native_os) {
15118802 .netbsd => private.__clock_getres50,
15128803 else => private.clock_getres,
......@@ -1534,11 +8825,117 @@ pub const fstatat = switch (native_os) {
15348825 else => private.fstatat,
15358826};
15368827
8828pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
8829pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
8830pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;
8831pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;
8832pub extern "c" fn mmap64(addr: ?*align(std.mem.page_size) anyopaque, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: i64) *anyopaque;
8833pub extern "c" fn open64(path: [*:0]const u8, oflag: O, ...) c_int;
8834pub extern "c" fn openat64(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int;
8835pub extern "c" fn pread64(fd: fd_t, buf: [*]u8, nbyte: usize, offset: i64) isize;
8836pub extern "c" fn preadv64(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: i64) isize;
8837pub extern "c" fn pwrite64(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: i64) isize;
8838pub extern "c" fn pwritev64(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: i64) isize;
8839pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: usize) isize;
8840pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int;
8841
8842pub const arc4random_buf = switch (native_os) {
8843 .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => private.arc4random_buf,
8844 else => {},
8845};
8846pub const getentropy = switch (native_os) {
8847 .emscripten => private.getentropy,
8848 else => {},
8849};
8850pub const getrandom = switch (native_os) {
8851 .freebsd => private.getrandom,
8852 .linux => if (versionCheck(.{ .major = 2, .minor = 25, .patch = 0 })) private.getrandom else {},
8853 else => {},
8854};
8855
8856pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
8857pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
8858
8859pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
8860pub extern "c" fn epoll_create1(flags: c_uint) c_int;
8861pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int;
8862pub extern "c" fn epoll_pwait(
8863 epfd: fd_t,
8864 events: [*]epoll_event,
8865 maxevents: c_int,
8866 timeout: c_int,
8867 sigmask: *const sigset_t,
8868) c_int;
8869
8870pub extern "c" fn timerfd_create(clockid: clockid_t, flags: c_int) c_int;
8871pub extern "c" fn timerfd_settime(
8872 fd: c_int,
8873 flags: c_int,
8874 new_value: *const itimerspec,
8875 old_value: ?*itimerspec,
8876) c_int;
8877pub extern "c" fn timerfd_gettime(fd: c_int, curr_value: *itimerspec) c_int;
8878
8879pub extern "c" fn inotify_init1(flags: c_uint) c_int;
8880pub extern "c" fn inotify_add_watch(fd: fd_t, pathname: [*:0]const u8, mask: u32) c_int;
8881pub extern "c" fn inotify_rm_watch(fd: fd_t, wd: c_int) c_int;
8882
8883pub extern "c" fn fstat64(fd: fd_t, buf: *Stat) c_int;
8884pub extern "c" fn fstatat64(dirfd: fd_t, noalias path: [*:0]const u8, noalias stat_buf: *Stat, flags: u32) c_int;
8885pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
8886pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
8887pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;
8888pub extern "c" fn fallocate(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
8889pub const sendfile = switch (native_os) {
8890 .freebsd, .kfreebsd => freebsd.sendfile,
8891 .macos, .ios, .tvos, .watchos, .visionos => darwin.sendfile,
8892 .linux => private.sendfile,
8893 else => {},
8894};
8895/// See std.elf for constants for this
8896pub extern "c" fn getauxval(__type: c_ulong) c_ulong;
8897
8898pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
8899
8900pub const sigaltstack = switch (native_os) {
8901 .netbsd => private.__sigaltstack14,
8902 else => private.sigaltstack,
8903};
8904
8905pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
8906pub extern "c" fn pipe2(fds: *[2]fd_t, flags: O) c_int;
8907
8908pub const copy_file_range = switch (native_os) {
8909 .linux => private.copy_file_range,
8910 .freebsd, .kfreebsd => freebsd.copy_file_range,
8911 else => {},
8912};
8913
8914pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;
8915
8916pub extern "c" fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: *const rlimit, old_limit: *rlimit) c_int;
8917pub extern "c" fn mincore(
8918 addr: *align(std.mem.page_size) anyopaque,
8919 length: usize,
8920 vec: [*]u8,
8921) c_int;
8922
8923pub extern "c" fn madvise(
8924 addr: *align(std.mem.page_size) anyopaque,
8925 length: usize,
8926 advice: u32,
8927) c_int;
8928
15378929pub const getdirentries = switch (native_os) {
15388930 .macos, .ios, .tvos, .watchos, .visionos => private.__getdirentries64,
15398931 else => private.getdirentries,
15408932};
15418933
8934pub const getdents = switch (native_os) {
8935 .netbsd => private.__getdents30,
8936 else => private.getdents,
8937};
8938
15428939pub const getrusage = switch (native_os) {
15438940 .netbsd => private.__getrusage50,
15448941 else => private.getrusage,
......@@ -1564,7 +8961,7 @@ pub const readdir = switch (native_os) {
15648961 .x86_64 => private.@"readdir$INODE64",
15658962 else => private.readdir,
15668963 },
1567 .windows => @compileError("not available"),
8964 .windows => {},
15688965 else => private.readdir,
15698966};
15708967
......@@ -1606,6 +9003,33 @@ pub const stat = switch (native_os) {
16069003 else => private.stat,
16079004};
16089005
9006pub const _msize = switch (native_os) {
9007 .windows => private._msize,
9008 else => {},
9009};
9010pub const malloc_size = switch (native_os) {
9011 .macos, .ios, .tvos, .watchos, .visionos => private.malloc_size,
9012 else => {},
9013};
9014pub const malloc_usable_size = switch (native_os) {
9015 .freebsd, .linux => private.malloc_usable_size,
9016 else => {},
9017};
9018pub const posix_memalign = switch (native_os) {
9019 .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos => private.posix_memalign,
9020 else => {},
9021};
9022
9023pub const sf_hdtr = switch (native_os) {
9024 .freebsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
9025 headers: [*]const iovec_const,
9026 hdr_cnt: c_int,
9027 trailers: [*]const iovec_const,
9028 trl_cnt: c_int,
9029 },
9030 else => void,
9031};
9032
16099033pub extern "c" var environ: [*:null]?[*:0]u8;
16109034
16119035pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
......@@ -1617,228 +9041,258 @@ pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
16179041pub extern "c" fn abort() noreturn;
16189042pub extern "c" fn exit(code: c_int) noreturn;
16199043pub extern "c" fn _exit(code: c_int) noreturn;
1620pub extern "c" fn isatty(fd: c.fd_t) c_int;
1621pub extern "c" fn close(fd: c.fd_t) c_int;
1622pub extern "c" fn lseek(fd: c.fd_t, offset: c.off_t, whence: whence_t) c.off_t;
9044pub extern "c" fn isatty(fd: fd_t) c_int;
9045pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: whence_t) off_t;
16239046pub extern "c" fn open(path: [*:0]const u8, oflag: O, ...) c_int;
16249047pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: O, ...) c_int;
1625pub extern "c" fn ftruncate(fd: c_int, length: c.off_t) c_int;
9048pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int;
16269049pub extern "c" fn raise(sig: c_int) c_int;
1627pub extern "c" fn read(fd: c.fd_t, buf: [*]u8, nbyte: usize) isize;
9050pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
16289051pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
1629pub extern "c" fn pread(fd: c.fd_t, buf: [*]u8, nbyte: usize, offset: c.off_t) isize;
1630pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: c.off_t) isize;
9052pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize;
9053pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: off_t) isize;
16319054pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
1632pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: c.off_t) isize;
1633pub extern "c" fn write(fd: c.fd_t, buf: [*]const u8, nbyte: usize) isize;
1634pub extern "c" fn pwrite(fd: c.fd_t, buf: [*]const u8, nbyte: usize, offset: c.off_t) isize;
1635pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: c_uint, flags: MAP, fd: c.fd_t, offset: c.off_t) *anyopaque;
9055pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: off_t) isize;
9056pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
9057pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize;
9058pub extern "c" fn mmap(addr: ?*align(page_size) anyopaque, len: usize, prot: c_uint, flags: MAP, fd: fd_t, offset: off_t) *anyopaque;
16369059pub extern "c" fn munmap(addr: *align(page_size) const anyopaque, len: usize) c_int;
16379060pub extern "c" fn mprotect(addr: *align(page_size) anyopaque, len: usize, prot: c_uint) c_int;
16389061pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: c_int) c_int;
1639pub extern "c" fn linkat(oldfd: c.fd_t, oldpath: [*:0]const u8, newfd: c.fd_t, newpath: [*:0]const u8, flags: c_int) c_int;
9062pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_int) c_int;
16409063pub extern "c" fn unlink(path: [*:0]const u8) c_int;
1641pub extern "c" fn unlinkat(dirfd: c.fd_t, path: [*:0]const u8, flags: c_uint) c_int;
9064pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int;
16429065pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
1643pub extern "c" fn waitpid(pid: c.pid_t, status: ?*c_int, options: c_int) c.pid_t;
1644pub extern "c" fn wait4(pid: c.pid_t, status: ?*c_int, options: c_int, ru: ?*c.rusage) c.pid_t;
1645pub extern "c" fn fork() c_int;
9066pub extern "c" fn waitpid(pid: pid_t, status: ?*c_int, options: c_int) pid_t;
9067pub extern "c" fn wait4(pid: pid_t, status: ?*c_int, options: c_int, ru: ?*rusage) pid_t;
9068pub const fork = switch (native_os) {
9069 .dragonfly,
9070 .freebsd,
9071 .ios,
9072 .kfreebsd,
9073 .linux,
9074 .macos,
9075 .netbsd,
9076 .openbsd,
9077 .solaris,
9078 .illumos,
9079 .tvos,
9080 .watchos,
9081 .visionos,
9082 .haiku,
9083 => private.fork,
9084 else => {},
9085};
16469086pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) c_int;
1647pub extern "c" fn faccessat(dirfd: c.fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int;
1648pub extern "c" fn pipe(fds: *[2]c.fd_t) c_int;
9087pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int;
9088pub extern "c" fn pipe(fds: *[2]fd_t) c_int;
16499089pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int;
1650pub extern "c" fn mkdirat(dirfd: c.fd_t, path: [*:0]const u8, mode: u32) c_int;
9090pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int;
16519091pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;
1652pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: c.fd_t, newpath: [*:0]const u8) c_int;
9092pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: fd_t, newpath: [*:0]const u8) c_int;
16539093pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;
1654pub extern "c" fn renameat(olddirfd: c.fd_t, old: [*:0]const u8, newdirfd: c.fd_t, new: [*:0]const u8) c_int;
9094pub extern "c" fn renameat(olddirfd: fd_t, old: [*:0]const u8, newdirfd: fd_t, new: [*:0]const u8) c_int;
16559095pub extern "c" fn chdir(path: [*:0]const u8) c_int;
1656pub extern "c" fn fchdir(fd: c.fd_t) c_int;
9096pub extern "c" fn fchdir(fd: fd_t) c_int;
16579097pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int;
1658pub extern "c" fn dup(fd: c.fd_t) c_int;
1659pub extern "c" fn dup2(old_fd: c.fd_t, new_fd: c.fd_t) c_int;
9098pub extern "c" fn dup(fd: fd_t) c_int;
9099pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
9100pub extern "c" fn dup3(old: c_int, new: c_int, flags: c_uint) c_int;
16609101pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
1661pub extern "c" fn readlinkat(dirfd: c.fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
1662pub extern "c" fn chmod(path: [*:0]const u8, mode: c.mode_t) c_int;
1663pub extern "c" fn fchmod(fd: c.fd_t, mode: c.mode_t) c_int;
1664pub extern "c" fn fchmodat(fd: c.fd_t, path: [*:0]const u8, mode: c.mode_t, flags: c_uint) c_int;
1665pub extern "c" fn fchown(fd: c.fd_t, owner: c.uid_t, group: c.gid_t) c_int;
1666pub extern "c" fn umask(mode: c.mode_t) c.mode_t;
9102pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
9103pub extern "c" fn chmod(path: [*:0]const u8, mode: mode_t) c_int;
9104pub extern "c" fn fchmod(fd: fd_t, mode: mode_t) c_int;
9105pub extern "c" fn fchmodat(fd: fd_t, path: [*:0]const u8, mode: mode_t, flags: c_uint) c_int;
9106pub extern "c" fn fchown(fd: fd_t, owner: uid_t, group: gid_t) c_int;
9107pub extern "c" fn umask(mode: mode_t) mode_t;
16679108
16689109pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
16699110pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
16709111pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*anyopaque, oldlenp: ?*usize, newp: ?*anyopaque, newlen: usize) c_int;
16719112pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*anyopaque, oldlenp: ?*usize, newp: ?*anyopaque, newlen: usize) c_int;
16729113pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
1673pub extern "c" fn tcgetattr(fd: c.fd_t, termios_p: *c.termios) c_int;
1674pub extern "c" fn tcsetattr(fd: c.fd_t, optional_action: c.TCSA, termios_p: *const c.termios) c_int;
1675pub extern "c" fn fcntl(fd: c.fd_t, cmd: c_int, ...) c_int;
1676pub extern "c" fn flock(fd: c.fd_t, operation: c_int) c_int;
1677pub extern "c" fn ioctl(fd: c.fd_t, request: c_int, ...) c_int;
1678pub extern "c" fn uname(buf: *c.utsname) c_int;
9114pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int;
9115pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int;
9116pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int;
9117pub extern "c" fn flock(fd: fd_t, operation: c_int) c_int;
9118pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;
9119pub extern "c" fn uname(buf: *utsname) c_int;
16799120
16809121pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;
1681pub extern "c" fn shutdown(socket: c.fd_t, how: c_int) c_int;
1682pub extern "c" fn bind(socket: c.fd_t, address: ?*const c.sockaddr, address_len: c.socklen_t) c_int;
1683pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]c.fd_t) c_int;
1684pub extern "c" fn listen(sockfd: c.fd_t, backlog: c_uint) c_int;
1685pub extern "c" fn getsockname(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias addrlen: *c.socklen_t) c_int;
1686pub extern "c" fn getpeername(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias addrlen: *c.socklen_t) c_int;
1687pub extern "c" fn connect(sockfd: c.fd_t, sock_addr: *const c.sockaddr, addrlen: c.socklen_t) c_int;
1688pub extern "c" fn accept(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t) c_int;
1689pub extern "c" fn accept4(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t, flags: c_uint) c_int;
1690pub extern "c" fn getsockopt(sockfd: c.fd_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *c.socklen_t) c_int;
1691pub extern "c" fn setsockopt(sockfd: c.fd_t, level: i32, optname: u32, optval: ?*const anyopaque, optlen: c.socklen_t) c_int;
1692pub extern "c" fn send(sockfd: c.fd_t, buf: *const anyopaque, len: usize, flags: u32) isize;
9122pub extern "c" fn shutdown(socket: fd_t, how: c_int) c_int;
9123pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
9124pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
9125pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;
9126pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
9127pub extern "c" fn getpeername(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
9128pub extern "c" fn connect(sockfd: fd_t, sock_addr: *const sockaddr, addrlen: socklen_t) c_int;
9129pub extern "c" fn accept(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t) c_int;
9130pub extern "c" fn accept4(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t, flags: c_uint) c_int;
9131pub extern "c" fn getsockopt(sockfd: fd_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *socklen_t) c_int;
9132pub extern "c" fn setsockopt(sockfd: fd_t, level: i32, optname: u32, optval: ?*const anyopaque, optlen: socklen_t) c_int;
9133pub extern "c" fn send(sockfd: fd_t, buf: *const anyopaque, len: usize, flags: u32) isize;
16939134pub extern "c" fn sendto(
1694 sockfd: c.fd_t,
9135 sockfd: fd_t,
16959136 buf: *const anyopaque,
16969137 len: usize,
16979138 flags: u32,
1698 dest_addr: ?*const c.sockaddr,
1699 addrlen: c.socklen_t,
9139 dest_addr: ?*const sockaddr,
9140 addrlen: socklen_t,
17009141) isize;
1701pub extern "c" fn sendmsg(sockfd: c.fd_t, msg: *const c.msghdr_const, flags: u32) isize;
9142pub extern "c" fn sendmsg(sockfd: fd_t, msg: *const msghdr_const, flags: u32) isize;
17029143
17039144pub extern "c" fn recv(
1704 sockfd: c.fd_t,
9145 sockfd: fd_t,
17059146 arg1: ?*anyopaque,
17069147 arg2: usize,
17079148 arg3: c_int,
17089149) if (native_os == .windows) c_int else isize;
17099150pub extern "c" fn recvfrom(
1710 sockfd: c.fd_t,
9151 sockfd: fd_t,
17119152 noalias buf: *anyopaque,
17129153 len: usize,
17139154 flags: u32,
1714 noalias src_addr: ?*c.sockaddr,
1715 noalias addrlen: ?*c.socklen_t,
9155 noalias src_addr: ?*sockaddr,
9156 noalias addrlen: ?*socklen_t,
17169157) if (native_os == .windows) c_int else isize;
1717pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *c.msghdr, flags: u32) isize;
9158pub extern "c" fn recvmsg(sockfd: fd_t, msg: *msghdr, flags: u32) isize;
17189159
1719pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int;
9160pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
17209161
1721pub extern "c" fn setuid(uid: c.uid_t) c_int;
1722pub extern "c" fn setgid(gid: c.gid_t) c_int;
1723pub extern "c" fn seteuid(euid: c.uid_t) c_int;
1724pub extern "c" fn setegid(egid: c.gid_t) c_int;
1725pub extern "c" fn setreuid(ruid: c.uid_t, euid: c.uid_t) c_int;
1726pub extern "c" fn setregid(rgid: c.gid_t, egid: c.gid_t) c_int;
1727pub extern "c" fn setresuid(ruid: c.uid_t, euid: c.uid_t, suid: c.uid_t) c_int;
1728pub extern "c" fn setresgid(rgid: c.gid_t, egid: c.gid_t, sgid: c.gid_t) c_int;
9162pub extern "c" fn setuid(uid: uid_t) c_int;
9163pub extern "c" fn setgid(gid: gid_t) c_int;
9164pub extern "c" fn seteuid(euid: uid_t) c_int;
9165pub extern "c" fn setegid(egid: gid_t) c_int;
9166pub extern "c" fn setreuid(ruid: uid_t, euid: uid_t) c_int;
9167pub extern "c" fn setregid(rgid: gid_t, egid: gid_t) c_int;
9168pub extern "c" fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) c_int;
9169pub extern "c" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) c_int;
17299170
17309171pub extern "c" fn malloc(usize) ?*anyopaque;
17319172pub extern "c" fn realloc(?*anyopaque, usize) ?*anyopaque;
17329173pub extern "c" fn free(?*anyopaque) void;
17339174
1734pub extern "c" fn futimes(fd: c.fd_t, times: *[2]c.timeval) c_int;
1735pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]c.timeval) c_int;
9175pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int;
9176pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
17369177
1737pub extern "c" fn utimensat(dirfd: c.fd_t, pathname: [*:0]const u8, times: *[2]c.timespec, flags: u32) c_int;
1738pub extern "c" fn futimens(fd: c.fd_t, times: *const [2]c.timespec) c_int;
9178pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
9179pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
17399180
17409181pub extern "c" fn pthread_create(
17419182 noalias newthread: *pthread_t,
1742 noalias attr: ?*const c.pthread_attr_t,
9183 noalias attr: ?*const pthread_attr_t,
17439184 start_routine: *const fn (?*anyopaque) callconv(.C) ?*anyopaque,
17449185 noalias arg: ?*anyopaque,
1745) c.E;
1746pub extern "c" fn pthread_attr_init(attr: *c.pthread_attr_t) c.E;
1747pub extern "c" fn pthread_attr_setstack(attr: *c.pthread_attr_t, stackaddr: *anyopaque, stacksize: usize) c.E;
1748pub extern "c" fn pthread_attr_setstacksize(attr: *c.pthread_attr_t, stacksize: usize) c.E;
1749pub extern "c" fn pthread_attr_setguardsize(attr: *c.pthread_attr_t, guardsize: usize) c.E;
1750pub extern "c" fn pthread_attr_destroy(attr: *c.pthread_attr_t) c.E;
9186) E;
9187pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
9188pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *anyopaque, stacksize: usize) E;
9189pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) E;
9190pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) E;
9191pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) E;
17519192pub extern "c" fn pthread_self() pthread_t;
1752pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) c.E;
1753pub extern "c" fn pthread_detach(thread: pthread_t) c.E;
9193pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) E;
9194pub extern "c" fn pthread_detach(thread: pthread_t) E;
17549195pub extern "c" fn pthread_atfork(
17559196 prepare: ?*const fn () callconv(.C) void,
17569197 parent: ?*const fn () callconv(.C) void,
17579198 child: ?*const fn () callconv(.C) void,
17589199) c_int;
17599200pub extern "c" fn pthread_key_create(
1760 key: *c.pthread_key_t,
9201 key: *pthread_key_t,
17619202 destructor: ?*const fn (value: *anyopaque) callconv(.C) void,
1762) c.E;
1763pub extern "c" fn pthread_key_delete(key: c.pthread_key_t) c.E;
1764pub extern "c" fn pthread_getspecific(key: c.pthread_key_t) ?*anyopaque;
1765pub extern "c" fn pthread_setspecific(key: c.pthread_key_t, value: ?*anyopaque) c_int;
1766pub extern "c" fn pthread_sigmask(how: c_int, set: *const c.sigset_t, oldset: *c.sigset_t) c_int;
1767pub extern "c" fn sem_init(sem: *c.sem_t, pshared: c_int, value: c_uint) c_int;
1768pub extern "c" fn sem_destroy(sem: *c.sem_t) c_int;
1769pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: c.mode_t, value: c_uint) *c.sem_t;
1770pub extern "c" fn sem_close(sem: *c.sem_t) c_int;
1771pub extern "c" fn sem_post(sem: *c.sem_t) c_int;
1772pub extern "c" fn sem_wait(sem: *c.sem_t) c_int;
1773pub extern "c" fn sem_trywait(sem: *c.sem_t) c_int;
1774pub extern "c" fn sem_timedwait(sem: *c.sem_t, abs_timeout: *const c.timespec) c_int;
1775pub extern "c" fn sem_getvalue(sem: *c.sem_t, sval: *c_int) c_int;
1776
1777pub extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: c.mode_t) c_int;
9203) E;
9204pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
9205pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*anyopaque;
9206pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*anyopaque) c_int;
9207pub extern "c" fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *sigset_t) c_int;
9208pub const pthread_setname_np = switch (native_os) {
9209 .macos, .ios, .tvos, .watchos, .visionos => darwin.pthread_setname_np,
9210 .solaris, .illumos => solaris.pthread_setname_np,
9211 .netbsd => netbsd.pthread_setname_np,
9212 else => private.pthread_setname_np,
9213};
9214
9215pub extern "c" fn pthread_getname_np(thread: pthread_t, name: [*:0]u8, len: usize) c_int;
9216pub const pthread_threadid_np = switch (native_os) {
9217 .macos, .ios, .tvos, .watchos, .visionos => private.pthread_threadid_np,
9218 else => {},
9219};
9220
9221pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;
9222pub extern "c" fn sem_destroy(sem: *sem_t) c_int;
9223pub extern "c" fn sem_open(name: [*:0]const u8, flag: c_int, mode: mode_t, value: c_uint) *sem_t;
9224pub extern "c" fn sem_close(sem: *sem_t) c_int;
9225pub extern "c" fn sem_post(sem: *sem_t) c_int;
9226pub extern "c" fn sem_wait(sem: *sem_t) c_int;
9227pub extern "c" fn sem_trywait(sem: *sem_t) c_int;
9228pub extern "c" fn sem_timedwait(sem: *sem_t, abs_timeout: *const timespec) c_int;
9229pub extern "c" fn sem_getvalue(sem: *sem_t, sval: *c_int) c_int;
9230
9231pub extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, mode: mode_t) c_int;
17789232pub extern "c" fn shm_unlink(name: [*:0]const u8) c_int;
17799233
17809234pub extern "c" fn kqueue() c_int;
17819235pub extern "c" fn kevent(
17829236 kq: c_int,
1783 changelist: [*]const c.Kevent,
9237 changelist: [*]const Kevent,
17849238 nchanges: c_int,
1785 eventlist: [*]c.Kevent,
9239 eventlist: [*]Kevent,
17869240 nevents: c_int,
1787 timeout: ?*const c.timespec,
9241 timeout: ?*const timespec,
17889242) c_int;
17899243
1790pub extern "c" fn port_create() c.port_t;
9244pub extern "c" fn port_create() port_t;
17919245pub extern "c" fn port_associate(
1792 port: c.port_t,
9246 port: port_t,
17939247 source: u32,
17949248 object: usize,
17959249 events: u32,
17969250 user_var: ?*anyopaque,
17979251) c_int;
1798pub extern "c" fn port_dissociate(port: c.port_t, source: u32, object: usize) c_int;
1799pub extern "c" fn port_send(port: c.port_t, events: u32, user_var: ?*anyopaque) c_int;
9252pub extern "c" fn port_dissociate(port: port_t, source: u32, object: usize) c_int;
9253pub extern "c" fn port_send(port: port_t, events: u32, user_var: ?*anyopaque) c_int;
18009254pub extern "c" fn port_sendn(
1801 ports: [*]c.port_t,
9255 ports: [*]port_t,
18029256 errors: []u32,
18039257 num_ports: u32,
18049258 events: u32,
18059259 user_var: ?*anyopaque,
18069260) c_int;
1807pub extern "c" fn port_get(port: c.port_t, event: *c.port_event, timeout: ?*c.timespec) c_int;
9261pub extern "c" fn port_get(port: port_t, event: *port_event, timeout: ?*timespec) c_int;
18089262pub extern "c" fn port_getn(
1809 port: c.port_t,
1810 event_list: []c.port_event,
9263 port: port_t,
9264 event_list: []port_event,
18119265 max_events: u32,
18129266 events_retrieved: *u32,
1813 timeout: ?*c.timespec,
9267 timeout: ?*timespec,
18149268) c_int;
1815pub extern "c" fn port_alert(port: c.port_t, flags: u32, events: u32, user_var: ?*anyopaque) c_int;
9269pub extern "c" fn port_alert(port: port_t, flags: u32, events: u32, user_var: ?*anyopaque) c_int;
18169270
18179271pub extern "c" fn getaddrinfo(
18189272 noalias node: ?[*:0]const u8,
18199273 noalias service: ?[*:0]const u8,
1820 noalias hints: ?*const c.addrinfo,
9274 noalias hints: ?*const addrinfo,
18219275 /// On Linux, `res` will not be modified on error and `freeaddrinfo` will
18229276 /// potentially crash if you pass it an undefined pointer
1823 noalias res: *?*c.addrinfo,
1824) c.EAI;
9277 noalias res: *?*addrinfo,
9278) EAI;
18259279
1826pub extern "c" fn freeaddrinfo(res: *c.addrinfo) void;
9280pub extern "c" fn freeaddrinfo(res: *addrinfo) void;
18279281
18289282pub extern "c" fn getnameinfo(
1829 noalias addr: *const c.sockaddr,
1830 addrlen: c.socklen_t,
9283 noalias addr: *const sockaddr,
9284 addrlen: socklen_t,
18319285 noalias host: [*]u8,
1832 hostlen: c.socklen_t,
9286 hostlen: socklen_t,
18339287 noalias serv: [*]u8,
1834 servlen: c.socklen_t,
9288 servlen: socklen_t,
18359289 flags: u32,
1836) c.EAI;
9290) EAI;
18379291
1838pub extern "c" fn gai_strerror(errcode: c.EAI) [*:0]const u8;
9292pub extern "c" fn gai_strerror(errcode: EAI) [*:0]const u8;
18399293
1840pub extern "c" fn poll(fds: [*]c.pollfd, nfds: c.nfds_t, timeout: c_int) c_int;
1841pub extern "c" fn ppoll(fds: [*]c.pollfd, nfds: c.nfds_t, timeout: ?*const c.timespec, sigmask: ?*const c.sigset_t) c_int;
9294pub extern "c" fn poll(fds: [*]pollfd, nfds: nfds_t, timeout: c_int) c_int;
9295pub extern "c" fn ppoll(fds: [*]pollfd, nfds: nfds_t, timeout: ?*const timespec, sigmask: ?*const sigset_t) c_int;
18429296
18439297pub extern "c" fn dn_expand(
18449298 msg: [*:0]const u8,
......@@ -1849,29 +9303,29 @@ pub extern "c" fn dn_expand(
18499303) c_int;
18509304
18519305pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
1852pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c.E;
1853pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c.E;
1854pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) c.E;
1855pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) c.E;
9306pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) E;
9307pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) E;
9308pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E;
9309pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E;
18569310
18579311pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{};
1858pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) c.E;
1859pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const c.timespec) c.E;
1860pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c.E;
1861pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c.E;
1862pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c.E;
1863
1864pub extern "c" fn pthread_rwlock_destroy(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
1865pub extern "c" fn pthread_rwlock_rdlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
1866pub extern "c" fn pthread_rwlock_wrlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
1867pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
1868pub extern "c" fn pthread_rwlock_trywrlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
1869pub extern "c" fn pthread_rwlock_unlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
9312pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) E;
9313pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) E;
9314pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
9315pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
9316pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
9317
9318pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E;
9319pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
9320pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
9321pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
9322pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
9323pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E;
18709324
18719325pub const pthread_t = *opaque {};
18729326pub const FILE = opaque {};
18739327
1874pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*anyopaque;
9328pub extern "c" fn dlopen(path: [*:0]const u8, mode: RTLD) ?*anyopaque;
18759329pub extern "c" fn dlclose(handle: *anyopaque) c_int;
18769330pub extern "c" fn dlsym(handle: ?*anyopaque, symbol: [*:0]const u8) ?*anyopaque;
18779331pub extern "c" fn dlerror() ?[*:0]u8;
......@@ -1883,8 +9337,8 @@ pub extern "c" fn fdatasync(fd: c_int) c_int;
18839337
18849338pub extern "c" fn prctl(option: c_int, ...) c_int;
18859339
1886pub extern "c" fn getrlimit(resource: c.rlimit_resource, rlim: *c.rlimit) c_int;
1887pub extern "c" fn setrlimit(resource: c.rlimit_resource, rlim: *const c.rlimit) c_int;
9340pub extern "c" fn getrlimit(resource: rlimit_resource, rlim: *rlimit) c_int;
9341pub extern "c" fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) c_int;
18889342
18899343pub extern "c" fn fmemopen(noalias buf: ?*anyopaque, size: usize, noalias mode: [*:0]const u8) ?*FILE;
18909344
......@@ -1895,6 +9349,8 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int;
18959349
18969350pub extern "c" fn if_nametoindex([*:0]const u8) c_int;
18979351
9352pub extern "c" fn getpid() pid_t;
9353
18989354/// These are implementation defined but share identical values in at least musl and glibc:
18999355/// - https://git.musl-libc.org/cgit/musl/tree/include/locale.h?id=ab31e9d6a0fa7c5c408856c89df2dfb12c344039#n18
19009356/// - https://sourceware.org/git/?p=glibc.git;a=blob;f=locale/bits/locale.h;h=0fcbb66114be5fef0577dc9047256eb508c45919;hb=c90cfce849d010474e8cccf3e5bff49a2c8b141f#l26
......@@ -1918,13 +9374,11 @@ pub const LC = enum(c_int) {
19189374pub extern "c" fn setlocale(category: LC, locale: ?[*:0]const u8) ?[*:0]const u8;
19199375
19209376pub const getcontext = if (builtin.target.isAndroid())
1921 @compileError("android bionic libc does not implement getcontext")
9377{} // android bionic libc does not implement getcontext
19229378else if (native_os == .linux and builtin.target.isMusl())
19239379 linux.getcontext
19249380else
1925 struct {
1926 extern fn getcontext(ucp: *std.posix.ucontext_t) c_int;
1927 }.getcontext;
9381 private.getcontext;
19289382
19299383pub const max_align_t = if (native_abi == .msvc)
19309384 f64
......@@ -1936,49 +9390,334 @@ else
19369390 b: c_longdouble,
19379391 };
19389392
9393pub extern "c" fn pthread_getthreadid_np() c_int;
9394pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void;
9395pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void;
9396
9397pub const AF_SUN = solaris.AF_SUN;
9398pub const AT_SUN = solaris.AT_SUN;
9399pub const FILE_EVENT = solaris.FILE_EVENT;
9400pub const GETCONTEXT = solaris.GETCONTEXT;
9401pub const GETUSTACK = solaris.GETUSTACK;
9402pub const PORT_ALERT = solaris.PORT_ALERT;
9403pub const PORT_SOURCE = solaris.PORT_SOURCE;
9404pub const POSIX_FADV = solaris.POSIX_FADV;
9405pub const SCM = solaris.SCM;
9406pub const SETCONTEXT = solaris.SETCONTEXT;
9407pub const SETUSTACK = solaris.GETUSTACK;
9408pub const SFD = solaris.SFD;
9409pub const _SC = solaris._SC;
9410pub const cmsghdr = solaris.cmsghdr;
9411pub const ctid_t = solaris.ctid_t;
9412pub const file_obj = solaris.file_obj;
9413pub const fpregset_t = solaris.fpregset_t;
9414pub const id_t = solaris.id_t;
9415pub const lif_ifinfo_req = solaris.lif_ifinfo_req;
9416pub const lif_nd_req = solaris.lif_nd_req;
9417pub const lifreq = solaris.lifreq;
9418pub const major_t = solaris.major_t;
9419pub const minor_t = solaris.minor_t;
9420pub const poolid_t = solaris.poolid_t;
9421pub const port_notify = solaris.port_notify;
9422pub const priority = solaris.priority;
9423pub const procfs = solaris.procfs;
9424pub const projid_t = solaris.projid_t;
9425pub const signalfd_siginfo = solaris.signalfd_siginfo;
9426pub const sysconf = solaris.sysconf;
9427pub const taskid_t = solaris.taskid_t;
9428pub const zoneid_t = solaris.zoneid_t;
9429
9430pub const DirEnt = haiku.DirEnt;
9431pub const _get_next_area_info = haiku._get_next_area_info;
9432pub const _get_next_image_info = haiku._get_next_image_info;
9433pub const _get_team_info = haiku._get_team_info;
9434pub const _kern_get_current_team = haiku._kern_get_current_team;
9435pub const _kern_open_dir = haiku._kern_open_dir;
9436pub const _kern_read_dir = haiku._kern_read_dir;
9437pub const _kern_read_stat = haiku._kern_read_stat;
9438pub const _kern_rewind_dir = haiku._kern_rewind_dir;
9439pub const area_id = haiku.area_id;
9440pub const area_info = haiku.area_info;
9441pub const directory_which = haiku.directory_which;
9442pub const find_directory = haiku.find_directory;
9443pub const find_thread = haiku.find_thread;
9444pub const get_system_info = haiku.get_system_info;
9445pub const image_info = haiku.image_info;
9446pub const port_id = haiku.port_id;
9447pub const sem_id = haiku.sem_id;
9448pub const status_t = haiku.status_t;
9449pub const system_info = haiku.system_info;
9450pub const team_id = haiku.team_id;
9451pub const team_info = haiku.team_info;
9452pub const thread_id = haiku.thread_id;
9453pub const vregs = haiku.vregs;
9454
9455pub const AUTH = openbsd.AUTH;
9456pub const BI = openbsd.BI;
9457pub const FUTEX = openbsd.FUTEX;
9458pub const HW = openbsd.HW;
9459pub const PTHREAD_STACK_MIN = openbsd.PTHREAD_STACK_MIN;
9460pub const TCFLUSH = openbsd.TCFLUSH;
9461pub const TCIO = openbsd.TCIO;
9462pub const auth_approval = openbsd.auth_approval;
9463pub const auth_call = openbsd.auth_call;
9464pub const auth_cat = openbsd.auth_cat;
9465pub const auth_challenge = openbsd.auth_challenge;
9466pub const auth_check_change = openbsd.auth_check_change;
9467pub const auth_check_expire = openbsd.auth_check_expire;
9468pub const auth_checknologin = openbsd.auth_checknologin;
9469pub const auth_clean = openbsd.auth_clean;
9470pub const auth_close = openbsd.auth_close;
9471pub const auth_clrenv = openbsd.auth_clrenv;
9472pub const auth_clroption = openbsd.auth_clroption;
9473pub const auth_clroptions = openbsd.auth_clroptions;
9474pub const auth_getitem = openbsd.auth_getitem;
9475pub const auth_getpwd = openbsd.auth_getpwd;
9476pub const auth_getstate = openbsd.auth_getstate;
9477pub const auth_getvalue = openbsd.auth_getvalue;
9478pub const auth_item_t = openbsd.auth_item_t;
9479pub const auth_mkvalue = openbsd.auth_mkvalue;
9480pub const auth_open = openbsd.auth_open;
9481pub const auth_session_t = openbsd.auth_session_t;
9482pub const auth_setdata = openbsd.auth_setdata;
9483pub const auth_setenv = openbsd.auth_setenv;
9484pub const auth_setitem = openbsd.auth_setitem;
9485pub const auth_setoption = openbsd.auth_setoption;
9486pub const auth_setpwd = openbsd.auth_setpwd;
9487pub const auth_setstate = openbsd.auth_setstate;
9488pub const auth_userchallenge = openbsd.auth_userchallenge;
9489pub const auth_usercheck = openbsd.auth_usercheck;
9490pub const auth_userokay = openbsd.auth_userokay;
9491pub const auth_userresponse = openbsd.auth_userresponse;
9492pub const auth_verify = openbsd.auth_verify;
9493pub const bcrypt = openbsd.bcrypt;
9494pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;
9495pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;
9496pub const bcrypt_newhash = openbsd.bcrypt_newhash;
9497pub const endpwent = openbsd.endpwent;
9498pub const futex = openbsd.futex;
9499pub const getpwent = openbsd.getpwent;
9500pub const getpwnam_r = openbsd.getpwnam_r;
9501pub const getpwnam_shadow = openbsd.getpwnam_shadow;
9502pub const getpwuid_r = openbsd.getpwuid_r;
9503pub const getpwuid_shadow = openbsd.getpwuid_shadow;
9504pub const getthrid = openbsd.getthrid;
9505pub const login_cap_t = openbsd.login_cap_t;
9506pub const login_close = openbsd.login_close;
9507pub const login_getcapbool = openbsd.login_getcapbool;
9508pub const login_getcapnum = openbsd.login_getcapnum;
9509pub const login_getcapsize = openbsd.login_getcapsize;
9510pub const login_getcapstr = openbsd.login_getcapstr;
9511pub const login_getcaptime = openbsd.login_getcaptime;
9512pub const login_getclass = openbsd.login_getclass;
9513pub const login_getstyle = openbsd.login_getstyle;
9514pub const pledge = openbsd.pledge;
9515pub const pthread_spinlock_t = openbsd.pthread_spinlock_t;
9516pub const pw_dup = openbsd.pw_dup;
9517pub const setclasscontext = openbsd.setclasscontext;
9518pub const setpassent = openbsd.setpassent;
9519pub const setpwent = openbsd.setpwent;
9520pub const setusercontext = openbsd.setusercontext;
9521pub const uid_from_user = openbsd.uid_from_user;
9522pub const unveil = openbsd.unveil;
9523pub const user_from_uid = openbsd.user_from_uid;
9524
9525pub const CAP_RIGHTS_VERSION = freebsd.CAP_RIGHTS_VERSION;
9526pub const KINFO_FILE_SIZE = freebsd.KINFO_FILE_SIZE;
9527pub const MFD = freebsd.MFD;
9528pub const UMTX_ABSTIME = freebsd.UMTX_ABSTIME;
9529pub const UMTX_OP = freebsd.UMTX_OP;
9530pub const _umtx_op = freebsd._umtx_op;
9531pub const _umtx_time = freebsd._umtx_time;
9532pub const cap_rights = freebsd.cap_rights;
9533pub const fflags_t = freebsd.fflags_t;
9534pub const fsblkcnt_t = freebsd.fsblkcnt_t;
9535pub const fsfilcnt_t = freebsd.fsfilcnt_t;
9536pub const kinfo_file = freebsd.kinfo_file;
9537pub const kinfo_getfile = freebsd.kinfo_getfile;
9538
9539pub const COPYFILE = darwin.COPYFILE;
9540pub const CPUFAMILY = darwin.CPUFAMILY;
9541pub const DB_RECORDTYPE = darwin.DB_RECORDTYPE;
9542pub const EXC = darwin.EXC;
9543pub const EXCEPTION = darwin.EXCEPTION;
9544pub const NSVersionOfRunTimeLibrary = darwin.NSVersionOfRunTimeLibrary;
9545pub const OPEN_MAX = darwin.OPEN_MAX;
9546pub const THREAD_STATE_NONE = darwin.THREAD_STATE_NONE;
9547pub const UL = darwin.UL;
9548pub const _NSGetExecutablePath = darwin._NSGetExecutablePath;
9549pub const __getdirentries64 = darwin.__getdirentries64;
9550pub const __ulock_wait = darwin.__ulock_wait;
9551pub const __ulock_wait2 = darwin.__ulock_wait2;
9552pub const __ulock_wake = darwin.__ulock_wake;
9553pub const _dyld_get_image_header = darwin._dyld_get_image_header;
9554pub const _dyld_get_image_name = darwin._dyld_get_image_name;
9555pub const _dyld_get_image_vmaddr_slide = darwin._dyld_get_image_vmaddr_slide;
9556pub const _dyld_image_count = darwin._dyld_image_count;
9557pub const _host_page_size = darwin._host_page_size;
9558pub const clock_get_time = darwin.clock_get_time;
9559pub const dispatch_release = darwin.dispatch_release;
9560pub const dispatch_semaphore_create = darwin.dispatch_semaphore_create;
9561pub const dispatch_semaphore_signal = darwin.dispatch_semaphore_signal;
9562pub const dispatch_semaphore_wait = darwin.dispatch_semaphore_wait;
9563pub const dispatch_time = darwin.dispatch_time;
9564pub const fcopyfile = darwin.fcopyfile;
9565pub const kevent64 = darwin.kevent64;
9566pub const mach_absolute_time = darwin.mach_absolute_time;
9567pub const mach_continuous_time = darwin.mach_continuous_time;
9568pub const mach_hdr = darwin.mach_hdr;
9569pub const mach_host_self = darwin.mach_host_self;
9570pub const mach_msg = darwin.mach_msg;
9571pub const mach_port_allocate = darwin.mach_port_allocate;
9572pub const mach_port_deallocate = darwin.mach_port_deallocate;
9573pub const mach_port_insert_right = darwin.mach_port_insert_right;
9574pub const mach_port_t = darwin.mach_port_t;
9575pub const mach_task_self = darwin.mach_task_self;
9576pub const mach_timebase_info = darwin.mach_timebase_info;
9577pub const mach_vm_protect = darwin.mach_vm_protect;
9578pub const mach_vm_read = darwin.mach_vm_read;
9579pub const mach_vm_region = darwin.mach_vm_region;
9580pub const mach_vm_region_recurse = darwin.mach_vm_region_recurse;
9581pub const mach_vm_write = darwin.mach_vm_write;
9582pub const os_log_create = darwin.os_log_create;
9583pub const os_log_type_enabled = darwin.os_log_type_enabled;
9584pub const os_signpost_enabled = darwin.os_signpost_enabled;
9585pub const os_signpost_id_generate = darwin.os_signpost_id_generate;
9586pub const os_signpost_id_make_with_pointer = darwin.os_signpost_id_make_with_pointer;
9587pub const os_signpost_interval_begin = darwin.os_signpost_interval_begin;
9588pub const os_signpost_interval_end = darwin.os_signpost_interval_end;
9589pub const os_unfair_lock = darwin.os_unfair_lock;
9590pub const os_unfair_lock_assert_not_owner = darwin.os_unfair_lock_assert_not_owner;
9591pub const os_unfair_lock_assert_owner = darwin.os_unfair_lock_assert_owner;
9592pub const os_unfair_lock_lock = darwin.os_unfair_lock_lock;
9593pub const os_unfair_lock_trylock = darwin.os_unfair_lock_trylock;
9594pub const os_unfair_lock_unlock = darwin.os_unfair_lock_unlock;
9595pub const pid_for_task = darwin.pid_for_task;
9596pub const posix_spawn = darwin.posix_spawn;
9597pub const posix_spawn_file_actions_addchdir_np = darwin.posix_spawn_file_actions_addchdir_np;
9598pub const posix_spawn_file_actions_addclose = darwin.posix_spawn_file_actions_addclose;
9599pub const posix_spawn_file_actions_adddup2 = darwin.posix_spawn_file_actions_adddup2;
9600pub const posix_spawn_file_actions_addfchdir_np = darwin.posix_spawn_file_actions_addfchdir_np;
9601pub const posix_spawn_file_actions_addinherit_np = darwin.posix_spawn_file_actions_addinherit_np;
9602pub const posix_spawn_file_actions_addopen = darwin.posix_spawn_file_actions_addopen;
9603pub const posix_spawn_file_actions_destroy = darwin.posix_spawn_file_actions_destroy;
9604pub const posix_spawn_file_actions_init = darwin.posix_spawn_file_actions_init;
9605pub const posix_spawnattr_destroy = darwin.posix_spawnattr_destroy;
9606pub const posix_spawnattr_getflags = darwin.posix_spawnattr_getflags;
9607pub const posix_spawnattr_init = darwin.posix_spawnattr_init;
9608pub const posix_spawnattr_setflags = darwin.posix_spawnattr_setflags;
9609pub const posix_spawnp = darwin.posix_spawnp;
9610pub const pthread_attr_get_qos_class_np = darwin.pthread_attr_get_qos_class_np;
9611pub const pthread_attr_set_qos_class_np = darwin.pthread_attr_set_qos_class_np;
9612pub const pthread_get_qos_class_np = darwin.pthread_get_qos_class_np;
9613pub const pthread_set_qos_class_self_np = darwin.pthread_set_qos_class_self_np;
9614pub const ptrace = darwin.ptrace;
9615pub const sigaddset = darwin.sigaddset;
9616pub const task_for_pid = darwin.task_for_pid;
9617pub const task_get_exception_ports = darwin.task_get_exception_ports;
9618pub const task_info = darwin.task_info;
9619pub const task_resume = darwin.task_resume;
9620pub const task_set_exception_ports = darwin.task_set_exception_ports;
9621pub const task_suspend = darwin.task_suspend;
9622pub const task_threads = darwin.task_threads;
9623pub const thread_get_state = darwin.thread_get_state;
9624pub const thread_info = darwin.thread_info;
9625pub const thread_resume = darwin.thread_resume;
9626pub const thread_set_state = darwin.thread_set_state;
9627pub const vm_deallocate = darwin.vm_deallocate;
9628pub const vm_machine_attribute = darwin.vm_machine_attribute;
9629pub const vm_prot_t = darwin.vm_prot_t;
9630
9631pub const _ksiginfo = netbsd._ksiginfo;
9632pub const _lwp_self = netbsd._lwp_self;
9633pub const lwpid_t = netbsd.lwpid_t;
9634
9635/// External definitions shared by two or more operating systems.
19399636const private = struct {
1940 extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
1941 extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
1942 extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int;
1943 extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int;
1944 extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
1945 extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
1946 extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
9637 extern "c" fn close(fd: fd_t) c_int;
9638 extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int;
9639 extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int;
9640 extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize;
9641 extern "c" fn fork() c_int;
9642 extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
9643 extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
9644 extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
9645 extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) switch (native_os) {
9646 .freebsd, .kfreebsd => isize,
9647 .solaris, .illumos => usize,
9648 else => c_int,
9649 };
9650 extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
9651 extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
19479652 extern "c" fn msync(addr: *align(page_size) const anyopaque, len: usize, flags: c_int) c_int;
1948 extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
1949 extern "c" fn readdir(dir: *c.DIR) ?*c.dirent;
9653 extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
9654 extern "c" fn readdir(dir: *DIR) ?*dirent;
19509655 extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
19519656 extern "c" fn sched_yield() c_int;
1952 extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
1953 extern "c" fn sigfillset(set: ?*c.sigset_t) void;
1954 extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
9657 extern "c" fn sendfile(out_fd: fd_t, in_fd: fd_t, offset: ?*off_t, count: usize) isize;
9658 extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
9659 extern "c" fn sigfillset(set: ?*sigset_t) void;
9660 extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
19559661 extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
1956 extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
9662 extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
9663 extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
9664
9665 extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8) c_int;
9666 extern "c" fn getcontext(ucp: *ucontext_t) c_int;
9667
9668 extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
9669 extern "c" fn getentropy(buffer: [*]u8, size: usize) c_int;
9670 extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
9671
9672 extern "c" fn _msize(memblock: ?*anyopaque) usize;
9673 extern "c" fn malloc_size(?*const anyopaque) usize;
9674 extern "c" fn malloc_usable_size(?*const anyopaque) usize;
9675 extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
19579676
19589677 /// macos modernized symbols.
19599678 /// x86_64 links to $INODE64 suffix for 64-bit support.
19609679 /// Note these are not necessary on aarch64.
1961 extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;
1962 extern "c" fn @"fstatat$INODE64"(dirfd: c.fd_t, path: [*:0]const u8, buf: *c.Stat, flag: u32) c_int;
1963 extern "c" fn @"readdir$INODE64"(dir: *c.DIR) ?*c.dirent;
1964 extern "c" fn @"stat$INODE64"(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
9680 extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int;
9681 extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
9682 extern "c" fn @"readdir$INODE64"(dir: *DIR) ?*dirent;
9683 extern "c" fn @"stat$INODE64"(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
19659684
19669685 /// macos modernized symbols.
19679686 extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
1968 extern "c" fn __getdirentries64(fd: c.fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
9687 extern "c" fn __getdirentries64(fd: fd_t, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
9688
9689 extern "c" fn pthread_threadid_np(thread: ?pthread_t, thread_id: *u64) c_int;
19699690
19709691 /// netbsd modernized symbols.
1971 extern "c" fn __clock_getres50(clk_id: c_int, tp: *c.timespec) c_int;
1972 extern "c" fn __clock_gettime50(clk_id: c_int, tp: *c.timespec) c_int;
1973 extern "c" fn __fstat50(fd: c.fd_t, buf: *c.Stat) c_int;
1974 extern "c" fn __getrusage50(who: c_int, usage: *c.rusage) c_int;
1975 extern "c" fn __gettimeofday50(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
9692 extern "c" fn __clock_getres50(clk_id: clockid_t, tp: *timespec) c_int;
9693 extern "c" fn __clock_gettime50(clk_id: clockid_t, tp: *timespec) c_int;
9694 extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
9695 extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
9696 extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
19769697 extern "c" fn __libc_thr_yield() c_int;
19779698 extern "c" fn __msync13(addr: *align(std.mem.page_size) const anyopaque, len: usize, flags: c_int) c_int;
1978 extern "c" fn __nanosleep50(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
1979 extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
1980 extern "c" fn __sigfillset14(set: ?*c.sigset_t) void;
1981 extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
9699 extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
9700 extern "c" fn __sigaction14(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
9701 extern "c" fn __sigfillset14(set: ?*sigset_t) void;
9702 extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
19829703 extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
1983 extern "c" fn __stat50(path: [*:0]const u8, buf: *c.Stat) c_int;
9704 extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
9705 extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
9706 extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
9707
9708 // Don't forget to add another clown when an OS picks yet another unique
9709 // symbol name for errno location!
9710 // 🤡🤡🤡🤡🤡🤡
9711
9712 extern "c" fn ___errno() *c_int;
9713 extern "c" fn __errno() *c_int;
9714 extern "c" fn __errno_location() *c_int;
9715 extern "c" fn __error() *c_int;
9716 extern "c" fn _errno() *c_int;
9717
9718 extern threadlocal var errno: c_int;
9719
9720 fn errnoFromThreadLocal() *c_int {
9721 return &errno;
9722 }
19849723};
lib/std/c/darwin.zig+1354-2535
......@@ -1,24 +1,30 @@
1const std = @import("../std.zig");
1const std = @import("std");
22const builtin = @import("builtin");
3const assert = std.debug.assert;
4const macho = std.macho;
53const native_arch = builtin.target.cpu.arch;
6const maxInt = std.math.maxInt;
4const assert = std.debug.assert;
5const AF = std.c.AF;
6const PROT = std.c.PROT;
7const fd_t = std.c.fd_t;
78const iovec_const = std.posix.iovec_const;
9const mode_t = std.c.mode_t;
10const off_t = std.c.off_t;
11const pid_t = std.c.pid_t;
12const pthread_attr_t = std.c.pthread_attr_t;
13const sigset_t = std.c.segset_t;
14const timespec = std.c.timespec;
15const sf_hdtr = std.c.sf_hdtr;
16
17comptime {
18 assert(builtin.os.tag.isDarwin()); // Prevent access of std.c symbols on wrong OS.
19}
820
9pub const aarch64 = @import("darwin/aarch64.zig");
10pub const x86_64 = @import("darwin/x86_64.zig");
11pub const cssm = @import("darwin/cssm.zig");
21pub const mach_port_t = c_uint;
1222
13const arch_bits = switch (native_arch) {
14 .aarch64 => @import("darwin/aarch64.zig"),
15 .x86_64 => @import("darwin/x86_64.zig"),
16 else => struct {},
23pub const THREAD_STATE_NONE = switch (native_arch) {
24 .aarch64 => 5,
25 .x86_64 => 13,
1726};
1827
19pub const EXC_TYPES_COUNT = arch_bits.EXC_TYPES_COUNT;
20pub const THREAD_STATE_NONE = arch_bits.THREAD_STATE_NONE;
21
2228pub const EXC = enum(exception_type_t) {
2329 NULL = 0,
2430 /// Could not access memory
......@@ -47,49 +53,61 @@ pub const EXC = enum(exception_type_t) {
4753 GUARD = 12,
4854 /// Abnormal process exited to corpse state
4955 CORPSE_NOTIFY = 13,
56
57 pub const TYPES_COUNT = @typeInfo(EXC).Enum.fields.len;
58 pub const SOFT_SIGNAL = 0x10003;
59
60 pub const MASK = packed struct(u32) {
61 BAD_ACCESS: bool = false,
62 BAD_INSTRUCTION: bool = false,
63 ARITHMETIC: bool = false,
64 EMULATION: bool = false,
65 SOFTWARE: bool = false,
66 BREAKPOINT: bool = false,
67 SYSCALL: bool = false,
68 MACH_SYSCALL: bool = false,
69 RPC_ALERT: bool = false,
70 CRASH: bool = false,
71 RESOURCE: bool = false,
72 GUARD: bool = false,
73 CORPSE_NOTIFY: bool = false,
74
75 pub const MACHINE: MASK = @bitCast(@as(u32, 0));
76
77 pub const ALL: MASK = .{
78 .BAD_ACCESS = true,
79 .BAD_INSTRUCTION = true,
80 .ARITHMETIC = true,
81 .EMULATION = true,
82 .SOFTWARE = true,
83 .BREAKPOINT = true,
84 .SYSCALL = true,
85 .MACH_SYSCALL = true,
86 .RPC_ALERT = true,
87 .CRASH = true,
88 .RESOURCE = true,
89 .GUARD = true,
90 .CORPSE_NOTIFY = true,
91 };
92 };
93};
94
95pub const EXCEPTION = enum(u32) {
96 /// Send a catch_exception_raise message including the identity.
97 DEFAULT = 1,
98 /// Send a catch_exception_raise_state message including the
99 /// thread state.
100 STATE = 2,
101 /// Send a catch_exception_raise_state_identity message including
102 /// the thread identity and state.
103 STATE_IDENTITY = 3,
104 /// Send a catch_exception_raise_identity_protected message including protected task
105 /// and thread identity.
106 IDENTITY_PROTECTED = 4,
107
108 _,
50109};
51110
52pub const EXC_SOFT_SIGNAL = 0x10003;
53
54pub const EXC_MASK_BAD_ACCESS = 1 << @intFromEnum(EXC.BAD_ACCESS);
55pub const EXC_MASK_BAD_INSTRUCTION = 1 << @intFromEnum(EXC.BAD_INSTRUCTION);
56pub const EXC_MASK_ARITHMETIC = 1 << @intFromEnum(EXC.ARITHMETIC);
57pub const EXC_MASK_EMULATION = 1 << @intFromEnum(EXC.EMULATION);
58pub const EXC_MASK_SOFTWARE = 1 << @intFromEnum(EXC.SOFTWARE);
59pub const EXC_MASK_BREAKPOINT = 1 << @intFromEnum(EXC.BREAKPOINT);
60pub const EXC_MASK_SYSCALL = 1 << @intFromEnum(EXC.SYSCALL);
61pub const EXC_MASK_MACH_SYSCALL = 1 << @intFromEnum(EXC.MACH_SYSCALL);
62pub const EXC_MASK_RPC_ALERT = 1 << @intFromEnum(EXC.RPC_ALERT);
63pub const EXC_MASK_CRASH = 1 << @intFromEnum(EXC.CRASH);
64pub const EXC_MASK_RESOURCE = 1 << @intFromEnum(EXC.RESOURCE);
65pub const EXC_MASK_GUARD = 1 << @intFromEnum(EXC.GUARD);
66pub const EXC_MASK_CORPSE_NOTIFY = 1 << @intFromEnum(EXC.CORPSE_NOTIFY);
67pub const EXC_MASK_MACHINE = arch_bits.EXC_MASK_MACHINE;
68
69pub const EXC_MASK_ALL = EXC_MASK_BAD_ACCESS |
70 EXC_MASK_BAD_INSTRUCTION |
71 EXC_MASK_ARITHMETIC |
72 EXC_MASK_EMULATION |
73 EXC_MASK_SOFTWARE |
74 EXC_MASK_BREAKPOINT |
75 EXC_MASK_SYSCALL |
76 EXC_MASK_MACH_SYSCALL |
77 EXC_MASK_RPC_ALERT |
78 EXC_MASK_RESOURCE |
79 EXC_MASK_GUARD |
80 EXC_MASK_MACHINE;
81
82/// Send a catch_exception_raise message including the identity.
83pub const EXCEPTION_DEFAULT = 1;
84/// Send a catch_exception_raise_state message including the
85/// thread state.
86pub const EXCEPTION_STATE = 2;
87/// Send a catch_exception_raise_state_identity message including
88/// the thread identity and state.
89pub const EXCEPTION_STATE_IDENTITY = 3;
90/// Send a catch_exception_raise_identity_protected message including protected task
91/// and thread identity.
92pub const EXCEPTION_IDENTITY_PROTECTED = 4;
93111/// Prefer sending a catch_exception_raice_backtrace message, if applicable.
94112pub const MACH_EXCEPTION_BACKTRACE_PREFERRED = 0x20000000;
95113/// include additional exception specific errors, not used yet.
......@@ -141,19 +159,109 @@ pub const MACH_RCV_SYNC_PEEK = 0x00008000;
141159
142160pub const MACH_MSG_STRICT_REPLY = 0x00000200;
143161
144pub const ucontext_t = extern struct {
145 onstack: c_int,
146 sigmask: sigset_t,
147 stack: stack_t,
148 link: ?*ucontext_t,
149 mcsize: u64,
150 mcontext: *mcontext_t,
151 __mcontext_data: mcontext_t,
162pub const exception_type_t = c_int;
163
164pub const mcontext_t = switch (native_arch) {
165 .aarch64 => extern struct {
166 es: exception_state,
167 ss: thread_state,
168 ns: neon_state,
169 },
170 .x86_64 => extern struct {
171 es: exception_state,
172 ss: thread_state,
173 fs: float_state,
174 },
175 else => @compileError("unsupported arch"),
152176};
153177
154pub const mcontext_t = arch_bits.mcontext_t;
178pub const exception_state = switch (native_arch) {
179 .aarch64 => extern struct {
180 far: u64, // Virtual Fault Address
181 esr: u32, // Exception syndrome
182 exception: u32, // Number of arm exception taken
183 },
184 .x86_64 => extern struct {
185 trapno: u16,
186 cpu: u16,
187 err: u32,
188 faultvaddr: u64,
189 },
190 else => @compileError("unsupported arch"),
191};
192
193pub const thread_state = switch (native_arch) {
194 .aarch64 => extern struct {
195 /// General purpose registers
196 regs: [29]u64,
197 /// Frame pointer x29
198 fp: u64,
199 /// Link register x30
200 lr: u64,
201 /// Stack pointer x31
202 sp: u64,
203 /// Program counter
204 pc: u64,
205 /// Current program status register
206 cpsr: u32,
207 __pad: u32,
208 },
209 .x86_64 => extern struct {
210 rax: u64,
211 rbx: u64,
212 rcx: u64,
213 rdx: u64,
214 rdi: u64,
215 rsi: u64,
216 rbp: u64,
217 rsp: u64,
218 r8: u64,
219 r9: u64,
220 r10: u64,
221 r11: u64,
222 r12: u64,
223 r13: u64,
224 r14: u64,
225 r15: u64,
226 rip: u64,
227 rflags: u64,
228 cs: u64,
229 fs: u64,
230 gs: u64,
231 },
232 else => @compileError("unsupported arch"),
233};
234
235pub const neon_state = extern struct {
236 q: [32]u128,
237 fpsr: u32,
238 fpcr: u32,
239};
240
241pub const float_state = extern struct {
242 reserved: [2]c_int,
243 fcw: u16,
244 fsw: u16,
245 ftw: u8,
246 rsrv1: u8,
247 fop: u16,
248 ip: u32,
249 cs: u16,
250 rsrv2: u16,
251 dp: u32,
252 ds: u16,
253 rsrv3: u16,
254 mxcsr: u32,
255 mxcsrmask: u32,
256 stmm: [8]stmm_reg,
257 xmm: [16]xmm_reg,
258 rsrv4: [96]u8,
259 reserved1: c_int,
260};
261
262pub const stmm_reg = [16]u8;
263pub const xmm_reg = [16]u8;
155264
156extern "c" fn __error() *c_int;
157265pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
158266pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int;
159267pub extern "c" fn _dyld_image_count() u32;
......@@ -161,23 +269,22 @@ pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
161269pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
162270pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;
163271
164pub const COPYFILE_ACL = 1 << 0;
165pub const COPYFILE_STAT = 1 << 1;
166pub const COPYFILE_XATTR = 1 << 2;
167pub const COPYFILE_DATA = 1 << 3;
272pub const COPYFILE = packed struct(u32) {
273 ACL: bool = false,
274 STAT: bool = false,
275 XATTR: bool = false,
276 DATA: bool = false,
277 _: u28 = 0,
278};
168279
169280pub const copyfile_state_t = *opaque {};
170pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: u32) c_int;
171
281pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: COPYFILE) c_int;
172282pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
173283
174284pub extern "c" fn mach_absolute_time() u64;
175285pub extern "c" fn mach_continuous_time() u64;
176286pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) kern_return_t;
177287
178pub extern "c" fn malloc_size(?*const anyopaque) usize;
179pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
180
181288pub extern "c" fn kevent64(
182289 kq: c_int,
183290 changelist: [*]const kevent64_s,
......@@ -188,34 +295,15 @@ pub extern "c" fn kevent64(
188295 timeout: ?*const timespec,
189296) c_int;
190297
191const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
192
193/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address
194/// of the mach header in a Mach-O executable file type. It does not appear in
195/// any file type other than a MH_EXECUTE file type. The type of the symbol is
196/// absolute as the header is not part of any section.
197/// This symbol is populated when linking the system's libc, which is guaranteed
198/// on this operating system. However when building object files or libraries,
199/// the system libc won't be linked until the final executable. So we
200/// export a weak symbol here, to be overridden by the real one.
201var dummy_execute_header: mach_hdr = undefined;
202pub extern var _mh_execute_header: mach_hdr;
203comptime {
204 if (builtin.target.isDarwin()) {
205 @export(dummy_execute_header, .{ .name = "_mh_execute_header", .linkage = .weak });
206 }
207}
208
209pub const mach_header_64 = macho.mach_header_64;
210pub const mach_header = macho.mach_header;
298pub const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;
211299
212pub const _errno = __error;
300pub const mach_header_64 = std.macho.mach_header_64;
301pub const mach_header = std.macho.mach_header;
213302
214303pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
215304pub extern "c" fn mach_host_self() mach_port_t;
216305pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t;
217306
218pub const exception_type_t = c_int;
219307pub const exception_data_type_t = integer_t;
220308pub const exception_data_t = ?*mach_exception_data_type_t;
221309pub const mach_exception_data_type_t = i64;
......@@ -679,6 +767,7 @@ pub const task_vm_info = extern struct {
679767 // added for rev5
680768 decompressions: integer_t,
681769};
770
682771pub const task_vm_info_data_t = task_vm_info;
683772
684773pub const vm_prot_t = c_int;
......@@ -745,13 +834,6 @@ pub extern "c" fn vm_machine_attribute(
745834 value: *vm_machine_attribute_val_t,
746835) kern_return_t;
747836
748pub const sf_hdtr = extern struct {
749 headers: [*]const iovec_const,
750 hdr_cnt: c_int,
751 trailers: [*]const iovec_const,
752 trl_cnt: c_int,
753};
754
755837pub extern "c" fn sendfile(
756838 in_fd: fd_t,
757839 out_fd: fd_t,
......@@ -765,69 +847,6 @@ pub fn sigaddset(set: *sigset_t, signo: u5) void {
765847 set.* |= @as(u32, 1) << (signo - 1);
766848}
767849
768pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
769
770pub const IFNAMESIZE = 16;
771
772pub const AI = struct {
773 /// get address to use bind()
774 pub const PASSIVE = 0x00000001;
775 /// fill ai_canonname
776 pub const CANONNAME = 0x00000002;
777 /// prevent host name resolution
778 pub const NUMERICHOST = 0x00000004;
779 /// prevent service name resolution
780 pub const NUMERICSERV = 0x00001000;
781};
782
783pub const EAI = enum(c_int) {
784 /// address family for hostname not supported
785 ADDRFAMILY = 1,
786
787 /// temporary failure in name resolution
788 AGAIN = 2,
789
790 /// invalid value for ai_flags
791 BADFLAGS = 3,
792
793 /// non-recoverable failure in name resolution
794 FAIL = 4,
795
796 /// ai_family not supported
797 FAMILY = 5,
798
799 /// memory allocation failure
800 MEMORY = 6,
801
802 /// no address associated with hostname
803 NODATA = 7,
804
805 /// hostname nor servname provided, or not known
806 NONAME = 8,
807
808 /// servname not supported for ai_socktype
809 SERVICE = 9,
810
811 /// ai_socktype not supported
812 SOCKTYPE = 10,
813
814 /// system error returned in errno
815 SYSTEM = 11,
816
817 /// invalid value for hints
818 BADHINTS = 12,
819
820 /// resolved protocol is unknown
821 PROTOCOL = 13,
822
823 /// argument buffer overflow
824 OVERFLOW = 14,
825
826 _,
827};
828
829pub const EAI_MAX = 15;
830
831850pub const qos_class_t = enum(c_uint) {
832851 /// highest priority QOS class for critical tasks
833852 QOS_CLASS_USER_INTERACTIVE = 0x21,
......@@ -843,23 +862,6 @@ pub const qos_class_t = enum(c_uint) {
843862 QOS_CLASS_UNSPECIFIED = 0x00,
844863};
845864
846pub const sem_t = c_int;
847
848pub const pthread_attr_t = extern struct {
849 __sig: c_long,
850 __opaque: [56]u8,
851};
852
853pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int;
854pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
855pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
856pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
857pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
858pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
859pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
860
861pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
862
863865// Grand Central Dispatch is exposed by libSystem.
864866pub extern "c" fn dispatch_release(object: *anyopaque) void;
865867
......@@ -881,38 +883,37 @@ pub extern fn dispatch_once_f(
881883 function: dispatch_function_t,
882884) void;
883885
884// Undocumented futex-like API available on darwin 16+
885// (macOS 10.12+, iOS 10.0+, tvOS 10.0+, watchOS 3.0+, catalyst 13.0+).
886//
887// [ulock.h]: https://github.com/apple/darwin-xnu/blob/master/bsd/sys/ulock.h
888// [sys_ulock.c]: https://github.com/apple/darwin-xnu/blob/master/bsd/kern/sys_ulock.c
889
890pub const UL_COMPARE_AND_WAIT = 1;
891pub const UL_UNFAIR_LOCK = 2;
892
893// Obsolete/deprecated
894pub const UL_OSSPINLOCK = UL_COMPARE_AND_WAIT;
895pub const UL_HANDOFFLOCK = UL_UNFAIR_LOCK;
896
897pub const ULF_WAKE_ALL = 0x100;
898pub const ULF_WAKE_THREAD = 0x200;
899pub const ULF_WAIT_WORKQ_DATA_CONTENTION = 0x10000;
900pub const ULF_WAIT_CANCEL_POINT = 0x20000;
901pub const ULF_NO_ERRNO = 0x1000000;
902
903// The following are only supported on darwin 19+
904// (macOS 10.15+, iOS 13.0+)
905pub const UL_COMPARE_AND_WAIT_SHARED = 3;
906pub const UL_UNFAIR_LOCK64_SHARED = 4;
907pub const UL_COMPARE_AND_WAIT64 = 5;
908pub const UL_COMPARE_AND_WAIT64_SHARED = 6;
909pub const ULF_WAIT_ADAPTIVE_SPIN = 0x40000;
910
911pub extern "c" fn __ulock_wait2(op: u32, addr: ?*const anyopaque, val: u64, timeout_ns: u64, val2: u64) c_int;
912pub extern "c" fn __ulock_wait(op: u32, addr: ?*const anyopaque, val: u64, timeout_us: u32) c_int;
913pub extern "c" fn __ulock_wake(op: u32, addr: ?*const anyopaque, val: u64) c_int;
914
915pub const OS_UNFAIR_LOCK_INIT = os_unfair_lock{};
886/// Undocumented futex-like API available on darwin 16+
887/// (macOS 10.12+, iOS 10.0+, tvOS 10.0+, watchOS 3.0+, catalyst 13.0+).
888///
889/// [ulock.h]: https://github.com/apple/darwin-xnu/blob/master/bsd/sys/ulock.h
890/// [sys_ulock.c]: https://github.com/apple/darwin-xnu/blob/master/bsd/kern/sys_ulock.c
891pub const UL = packed struct(u32) {
892 op: Op,
893 WAKE_ALL: bool = false,
894 WAKE_THREAD: bool = false,
895 _10: u6 = 0,
896 WAIT_WORKQ_DATA_CONTENTION: bool = false,
897 WAIT_CANCEL_POINT: bool = false,
898 WAIT_ADAPTIVE_SPIN: bool = false,
899 _19: u5 = 0,
900 NO_ERRNO: bool = false,
901 _: u7 = 0,
902
903 pub const Op = enum(u8) {
904 COMPARE_AND_WAIT = 1,
905 UNFAIR_LOCK = 2,
906 COMPARE_AND_WAIT_SHARED = 3,
907 UNFAIR_LOCK64_SHARED = 4,
908 COMPARE_AND_WAIT64 = 5,
909 COMPARE_AND_WAIT64_SHARED = 6,
910 };
911};
912
913pub extern "c" fn __ulock_wait2(op: UL, addr: ?*const anyopaque, val: u64, timeout_ns: u64, val2: u64) c_int;
914pub extern "c" fn __ulock_wait(op: UL, addr: ?*const anyopaque, val: u64, timeout_us: u32) c_int;
915pub extern "c" fn __ulock_wake(op: UL, addr: ?*const anyopaque, val: u64) c_int;
916
916917pub const os_unfair_lock_t = *os_unfair_lock;
917918pub const os_unfair_lock = extern struct {
918919 _os_unfair_lock_opaque: u32 = 0,
......@@ -924,2416 +925,1234 @@ pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
924925pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
925926pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;
926927
927// See: https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/sys/_types.h.auto.html
928// TODO: audit mode_t/pid_t, should likely be u16/i32
929pub const blkcnt_t = i64;
930pub const blksize_t = i32;
931pub const dev_t = i32;
932pub const fd_t = c_int;
933pub const pid_t = c_int;
934pub const mode_t = c_uint;
935pub const uid_t = u32;
936pub const gid_t = u32;
937
938// machine/_types.h
939pub const clock_t = c_ulong;
940pub const time_t = c_long;
941
942pub const in_port_t = u16;
943pub const sa_family_t = u8;
944pub const socklen_t = u32;
945pub const sockaddr = extern struct {
946 len: u8,
947 family: sa_family_t,
948 data: [14]u8,
949
950 pub const SS_MAXSIZE = 128;
951 pub const storage = extern struct {
952 len: u8 align(8),
953 family: sa_family_t,
954 padding: [126]u8 = undefined,
955
956 comptime {
957 assert(@sizeOf(storage) == SS_MAXSIZE);
958 assert(@alignOf(storage) == 8);
959 }
960 };
961 pub const in = extern struct {
962 len: u8 = @sizeOf(in),
963 family: sa_family_t = AF.INET,
964 port: in_port_t,
965 addr: u32,
966 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
967 };
968 pub const in6 = extern struct {
969 len: u8 = @sizeOf(in6),
970 family: sa_family_t = AF.INET6,
971 port: in_port_t,
972 flowinfo: u32,
973 addr: [16]u8,
974 scope_id: u32,
975 };
976
977 /// UNIX domain socket
978 pub const un = extern struct {
979 len: u8 = @sizeOf(un),
980 family: sa_family_t = AF.UNIX,
981 path: [104]u8,
982 };
983};
984pub const timeval = extern struct {
985 tv_sec: c_long,
986 tv_usec: i32,
987};
988
989pub const timezone = extern struct {
990 tz_minuteswest: i32,
991 tz_dsttime: i32,
992};
993
994pub const mach_timebase_info_data = extern struct {
995 numer: u32,
996 denom: u32,
997};
928pub fn getKernError(err: kern_return_t) KernE {
929 return @as(KernE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
930}
998931
999pub const off_t = i64;
1000pub const ino_t = u64;
932pub fn unexpectedKernError(err: KernE) std.posix.UnexpectedError {
933 if (std.posix.unexpected_error_tracing) {
934 std.debug.print("unexpected error: {d}\n", .{@intFromEnum(err)});
935 std.debug.dumpCurrentStackTrace(null);
936 }
937 return error.Unexpected;
938}
1001939
1002pub const Flock = extern struct {
1003 start: off_t,
1004 len: off_t,
1005 pid: pid_t,
1006 type: i16,
1007 whence: i16,
1008};
940pub const MachError = error{
941 /// Not enough permissions held to perform the requested kernel
942 /// call.
943 PermissionDenied,
944} || std.posix.UnexpectedError;
1009945
1010pub const Stat = extern struct {
1011 dev: i32,
1012 mode: u16,
1013 nlink: u16,
1014 ino: ino_t,
1015 uid: uid_t,
1016 gid: gid_t,
1017 rdev: i32,
1018 atimespec: timespec,
1019 mtimespec: timespec,
1020 ctimespec: timespec,
1021 birthtimespec: timespec,
1022 size: off_t,
1023 blocks: i64,
1024 blksize: i32,
1025 flags: u32,
1026 gen: u32,
1027 lspare: i32,
1028 qspare: [2]i64,
946pub const MachTask = extern struct {
947 port: mach_port_name_t,
1029948
1030 pub fn atime(self: @This()) timespec {
1031 return self.atimespec;
949 pub fn isValid(self: MachTask) bool {
950 return self.port != TASK_NULL;
1032951 }
1033952
1034 pub fn mtime(self: @This()) timespec {
1035 return self.mtimespec;
953 pub fn pidForTask(self: MachTask) MachError!std.c.pid_t {
954 var pid: std.c.pid_t = undefined;
955 switch (getKernError(pid_for_task(self.port, &pid))) {
956 .SUCCESS => return pid,
957 .FAILURE => return error.PermissionDenied,
958 else => |err| return unexpectedKernError(err),
959 }
1036960 }
1037961
1038 pub fn ctime(self: @This()) timespec {
1039 return self.ctimespec;
962 pub fn allocatePort(self: MachTask, right: MACH_PORT_RIGHT) MachError!MachTask {
963 var out_port: mach_port_name_t = undefined;
964 switch (getKernError(mach_port_allocate(
965 self.port,
966 @intFromEnum(right),
967 &out_port,
968 ))) {
969 .SUCCESS => return .{ .port = out_port },
970 .FAILURE => return error.PermissionDenied,
971 else => |err| return unexpectedKernError(err),
972 }
1040973 }
1041974
1042 pub fn birthtime(self: @This()) timespec {
1043 return self.birthtimespec;
975 pub fn deallocatePort(self: MachTask, port: MachTask) void {
976 _ = getKernError(mach_port_deallocate(self.port, port.port));
1044977 }
1045};
1046
1047pub const timespec = extern struct {
1048 tv_sec: isize,
1049 tv_nsec: isize,
1050};
1051
1052pub const sigset_t = u32;
1053pub const empty_sigset: sigset_t = 0;
1054
1055pub const SIG = struct {
1056 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
1057 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
1058 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
1059 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(5);
1060
1061 /// block specified signal set
1062 pub const BLOCK = 1;
1063 /// unblock specified signal set
1064 pub const UNBLOCK = 2;
1065 /// set specified signal set
1066 pub const SETMASK = 3;
1067 /// hangup
1068 pub const HUP = 1;
1069 /// interrupt
1070 pub const INT = 2;
1071 /// quit
1072 pub const QUIT = 3;
1073 /// illegal instruction (not reset when caught)
1074 pub const ILL = 4;
1075 /// trace trap (not reset when caught)
1076 pub const TRAP = 5;
1077 /// abort()
1078 pub const ABRT = 6;
1079 /// pollable event ([XSR] generated, not supported)
1080 pub const POLL = 7;
1081 /// compatibility
1082 pub const IOT = ABRT;
1083 /// EMT instruction
1084 pub const EMT = 7;
1085 /// floating point exception
1086 pub const FPE = 8;
1087 /// kill (cannot be caught or ignored)
1088 pub const KILL = 9;
1089 /// bus error
1090 pub const BUS = 10;
1091 /// segmentation violation
1092 pub const SEGV = 11;
1093 /// bad argument to system call
1094 pub const SYS = 12;
1095 /// write on a pipe with no one to read it
1096 pub const PIPE = 13;
1097 /// alarm clock
1098 pub const ALRM = 14;
1099 /// software termination signal from kill
1100 pub const TERM = 15;
1101 /// urgent condition on IO channel
1102 pub const URG = 16;
1103 /// sendable stop signal not from tty
1104 pub const STOP = 17;
1105 /// stop signal from tty
1106 pub const TSTP = 18;
1107 /// continue a stopped process
1108 pub const CONT = 19;
1109 /// to parent on child stop or exit
1110 pub const CHLD = 20;
1111 /// to readers pgrp upon background tty read
1112 pub const TTIN = 21;
1113 /// like TTIN for output if (tp->t_local&LTOSTOP)
1114 pub const TTOU = 22;
1115 /// input/output possible signal
1116 pub const IO = 23;
1117 /// exceeded CPU time limit
1118 pub const XCPU = 24;
1119 /// exceeded file size limit
1120 pub const XFSZ = 25;
1121 /// virtual time alarm
1122 pub const VTALRM = 26;
1123 /// profiling time alarm
1124 pub const PROF = 27;
1125 /// window size changes
1126 pub const WINCH = 28;
1127 /// information request
1128 pub const INFO = 29;
1129 /// user defined signal 1
1130 pub const USR1 = 30;
1131 /// user defined signal 2
1132 pub const USR2 = 31;
1133};
1134
1135pub const siginfo_t = extern struct {
1136 signo: c_int,
1137 errno: c_int,
1138 code: c_int,
1139 pid: pid_t,
1140 uid: uid_t,
1141 status: c_int,
1142 addr: *allowzero anyopaque,
1143 value: extern union {
1144 int: c_int,
1145 ptr: *anyopaque,
1146 },
1147 si_band: c_long,
1148 _pad: [7]c_ulong,
1149};
1150978
1151/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
1152pub const Sigaction = extern struct {
1153 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
1154 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
1155
1156 handler: extern union {
1157 handler: ?handler_fn,
1158 sigaction: ?sigaction_fn,
1159 },
1160 mask: sigset_t,
1161 flags: c_uint,
1162};
979 pub fn insertRight(self: MachTask, port: MachTask, msg: MACH_MSG_TYPE) !void {
980 switch (getKernError(mach_port_insert_right(
981 self.port,
982 port.port,
983 port.port,
984 @intFromEnum(msg),
985 ))) {
986 .SUCCESS => return,
987 .FAILURE => return error.PermissionDenied,
988 else => |err| return unexpectedKernError(err),
989 }
990 }
1163991
1164pub const dirent = extern struct {
1165 ino: u64,
1166 seekoff: u64,
1167 reclen: u16,
1168 namlen: u16,
1169 type: u8,
1170 name: [1024]u8,
1171};
992 pub const PortInfo = struct {
993 mask: exception_mask_t,
994 masks: [EXC.TYPES_COUNT]exception_mask_t,
995 ports: [EXC.TYPES_COUNT]mach_port_t,
996 behaviors: [EXC.TYPES_COUNT]exception_behavior_t,
997 flavors: [EXC.TYPES_COUNT]thread_state_flavor_t,
998 count: mach_msg_type_number_t,
999 };
11721000
1173/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
1174pub const Kevent = extern struct {
1175 ident: usize,
1176 filter: i16,
1177 flags: u16,
1178 fflags: u32,
1179 data: isize,
1180 udata: usize,
1181};
1001 pub fn getExceptionPorts(self: MachTask, mask: exception_mask_t) !PortInfo {
1002 var info = PortInfo{
1003 .mask = mask,
1004 .masks = undefined,
1005 .ports = undefined,
1006 .behaviors = undefined,
1007 .flavors = undefined,
1008 .count = 0,
1009 };
1010 info.count = info.ports.len / @sizeOf(mach_port_t);
11821011
1183// sys/types.h on macos uses #pragma pack(4) so these checks are
1184// to make sure the struct is laid out the same. These values were
1185// produced from C code using the offsetof macro.
1186comptime {
1187 if (builtin.target.isDarwin()) {
1188 assert(@offsetOf(Kevent, "ident") == 0);
1189 assert(@offsetOf(Kevent, "filter") == 8);
1190 assert(@offsetOf(Kevent, "flags") == 10);
1191 assert(@offsetOf(Kevent, "fflags") == 12);
1192 assert(@offsetOf(Kevent, "data") == 16);
1193 assert(@offsetOf(Kevent, "udata") == 24);
1012 switch (getKernError(task_get_exception_ports(
1013 self.port,
1014 info.mask,
1015 &info.masks,
1016 &info.count,
1017 &info.ports,
1018 &info.behaviors,
1019 &info.flavors,
1020 ))) {
1021 .SUCCESS => return info,
1022 .FAILURE => return error.PermissionDenied,
1023 else => |err| return unexpectedKernError(err),
1024 }
11941025 }
1195}
1196
1197pub const kevent64_s = extern struct {
1198 ident: u64,
1199 filter: i16,
1200 flags: u16,
1201 fflags: u32,
1202 data: i64,
1203 udata: u64,
1204 ext: [2]u64,
1205};
12061026
1207// sys/types.h on macos uses #pragma pack() so these checks are
1208// to make sure the struct is laid out the same. These values were
1209// produced from C code using the offsetof macro.
1210comptime {
1211 if (builtin.target.isDarwin()) {
1212 assert(@offsetOf(kevent64_s, "ident") == 0);
1213 assert(@offsetOf(kevent64_s, "filter") == 8);
1214 assert(@offsetOf(kevent64_s, "flags") == 10);
1215 assert(@offsetOf(kevent64_s, "fflags") == 12);
1216 assert(@offsetOf(kevent64_s, "data") == 16);
1217 assert(@offsetOf(kevent64_s, "udata") == 24);
1218 assert(@offsetOf(kevent64_s, "ext") == 32);
1027 pub fn setExceptionPorts(
1028 self: MachTask,
1029 mask: exception_mask_t,
1030 new_port: MachTask,
1031 behavior: exception_behavior_t,
1032 new_flavor: thread_state_flavor_t,
1033 ) !void {
1034 switch (getKernError(task_set_exception_ports(
1035 self.port,
1036 mask,
1037 new_port.port,
1038 behavior,
1039 new_flavor,
1040 ))) {
1041 .SUCCESS => return,
1042 .FAILURE => return error.PermissionDenied,
1043 else => |err| return unexpectedKernError(err),
1044 }
12191045 }
1220}
1221
1222pub const mach_port_t = c_uint;
1223pub const clock_serv_t = mach_port_t;
1224pub const clock_res_t = c_int;
1225pub const mach_port_name_t = natural_t;
1226pub const natural_t = c_uint;
1227pub const mach_timespec_t = extern struct {
1228 tv_sec: c_uint,
1229 tv_nsec: clock_res_t,
1230};
1231pub const kern_return_t = c_int;
1232pub const host_t = mach_port_t;
1233pub const integer_t = c_int;
1234pub const task_flavor_t = natural_t;
1235pub const task_info_t = *integer_t;
1236pub const task_name_t = mach_port_name_t;
1237pub const vm_address_t = vm_offset_t;
1238pub const vm_size_t = mach_vm_size_t;
1239pub const vm_machine_attribute_t = usize;
1240pub const vm_machine_attribute_val_t = isize;
1241
1242pub const CALENDAR_CLOCK = 1;
12431046
1244pub const PATH_MAX = 1024;
1245pub const NAME_MAX = 255;
1246pub const IOV_MAX = 16;
1247
1248pub const STDIN_FILENO = 0;
1249pub const STDOUT_FILENO = 1;
1250pub const STDERR_FILENO = 2;
1251
1252pub const PROT = struct {
1253 /// [MC2] no permissions
1254 pub const NONE: vm_prot_t = 0x00;
1255 /// [MC2] pages can be read
1256 pub const READ: vm_prot_t = 0x01;
1257 /// [MC2] pages can be written
1258 pub const WRITE: vm_prot_t = 0x02;
1259 /// [MC2] pages can be executed
1260 pub const EXEC: vm_prot_t = 0x04;
1261 /// When a caller finds that they cannot obtain write permission on a
1262 /// mapped entry, the following flag can be used. The entry will be
1263 /// made "needs copy" effectively copying the object (using COW),
1264 /// and write permission will be added to the maximum protections for
1265 /// the associated entry.
1266 pub const COPY: vm_prot_t = 0x10;
1267};
1047 pub const RegionInfo = struct {
1048 pub const Tag = enum {
1049 basic,
1050 extended,
1051 top,
1052 };
12681053
1269pub const MSF = struct {
1270 pub const ASYNC = 0x1;
1271 pub const INVALIDATE = 0x2;
1272 // invalidate, leave mapped
1273 pub const KILLPAGES = 0x4;
1274 // deactivate, leave mapped
1275 pub const DEACTIVATE = 0x8;
1276 pub const SYNC = 0x10;
1277};
1278
1279pub const SA = struct {
1280 /// take signal on signal stack
1281 pub const ONSTACK = 0x0001;
1282 /// restart system on signal return
1283 pub const RESTART = 0x0002;
1284 /// reset to SIG.DFL when taking signal
1285 pub const RESETHAND = 0x0004;
1286 /// do not generate SIG.CHLD on child stop
1287 pub const NOCLDSTOP = 0x0008;
1288 /// don't mask the signal we're delivering
1289 pub const NODEFER = 0x0010;
1290 /// don't keep zombies around
1291 pub const NOCLDWAIT = 0x0020;
1292 /// signal handler with SIGINFO args
1293 pub const SIGINFO = 0x0040;
1294 /// do not bounce off kernel's sigtramp
1295 pub const USERTRAMP = 0x0100;
1296 /// signal handler with SIGINFO args with 64bit regs information
1297 pub const @"64REGSET" = 0x0200;
1298};
1299
1300pub const F_OK = 0;
1301pub const X_OK = 1;
1302pub const W_OK = 2;
1303pub const R_OK = 4;
1304
1305pub const SEEK = struct {
1306 pub const SET = 0x0;
1307 pub const CUR = 0x1;
1308 pub const END = 0x2;
1309};
1054 base_addr: u64,
1055 tag: Tag,
1056 info: union {
1057 basic: vm_region_basic_info_64,
1058 extended: vm_region_extended_info,
1059 top: vm_region_top_info,
1060 },
1061 };
13101062
1311pub const DT = struct {
1312 pub const UNKNOWN = 0;
1313 pub const FIFO = 1;
1314 pub const CHR = 2;
1315 pub const DIR = 4;
1316 pub const BLK = 6;
1317 pub const REG = 8;
1318 pub const LNK = 10;
1319 pub const SOCK = 12;
1320 pub const WHT = 14;
1321};
1063 pub fn getRegionInfo(
1064 task: MachTask,
1065 address: u64,
1066 len: usize,
1067 tag: RegionInfo.Tag,
1068 ) MachError!RegionInfo {
1069 var info: RegionInfo = .{
1070 .base_addr = address,
1071 .tag = tag,
1072 .info = undefined,
1073 };
1074 switch (tag) {
1075 .basic => info.info = .{ .basic = undefined },
1076 .extended => info.info = .{ .extended = undefined },
1077 .top => info.info = .{ .top = undefined },
1078 }
1079 var base_len: mach_vm_size_t = if (len == 1) 2 else len;
1080 var objname: mach_port_t = undefined;
1081 var count: mach_msg_type_number_t = switch (tag) {
1082 .basic => VM_REGION_BASIC_INFO_COUNT,
1083 .extended => VM_REGION_EXTENDED_INFO_COUNT,
1084 .top => VM_REGION_TOP_INFO_COUNT,
1085 };
1086 switch (getKernError(mach_vm_region(
1087 task.port,
1088 &info.base_addr,
1089 &base_len,
1090 switch (tag) {
1091 .basic => VM_REGION_BASIC_INFO_64,
1092 .extended => VM_REGION_EXTENDED_INFO,
1093 .top => VM_REGION_TOP_INFO,
1094 },
1095 switch (tag) {
1096 .basic => @as(vm_region_info_t, @ptrCast(&info.info.basic)),
1097 .extended => @as(vm_region_info_t, @ptrCast(&info.info.extended)),
1098 .top => @as(vm_region_info_t, @ptrCast(&info.info.top)),
1099 },
1100 &count,
1101 &objname,
1102 ))) {
1103 .SUCCESS => return info,
1104 .FAILURE => return error.PermissionDenied,
1105 else => |err| return unexpectedKernError(err),
1106 }
1107 }
13221108
1323/// no flag value
1324pub const KEVENT_FLAG_NONE = 0x000;
1109 pub const RegionSubmapInfo = struct {
1110 pub const Tag = enum {
1111 short,
1112 full,
1113 };
13251114
1326/// immediate timeout
1327pub const KEVENT_FLAG_IMMEDIATE = 0x001;
1115 tag: Tag,
1116 base_addr: u64,
1117 info: union {
1118 short: vm_region_submap_short_info_64,
1119 full: vm_region_submap_info_64,
1120 },
1121 };
13281122
1329/// output events only include change
1330pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
1123 pub fn getRegionSubmapInfo(
1124 task: MachTask,
1125 address: u64,
1126 len: usize,
1127 nesting_depth: u32,
1128 tag: RegionSubmapInfo.Tag,
1129 ) MachError!RegionSubmapInfo {
1130 var info: RegionSubmapInfo = .{
1131 .base_addr = address,
1132 .tag = tag,
1133 .info = undefined,
1134 };
1135 switch (tag) {
1136 .short => info.info = .{ .short = undefined },
1137 .full => info.info = .{ .full = undefined },
1138 }
1139 var nesting = nesting_depth;
1140 var base_len: mach_vm_size_t = if (len == 1) 2 else len;
1141 var count: mach_msg_type_number_t = switch (tag) {
1142 .short => VM_REGION_SUBMAP_SHORT_INFO_COUNT_64,
1143 .full => VM_REGION_SUBMAP_INFO_COUNT_64,
1144 };
1145 switch (getKernError(mach_vm_region_recurse(
1146 task.port,
1147 &info.base_addr,
1148 &base_len,
1149 &nesting,
1150 switch (tag) {
1151 .short => @as(vm_region_recurse_info_t, @ptrCast(&info.info.short)),
1152 .full => @as(vm_region_recurse_info_t, @ptrCast(&info.info.full)),
1153 },
1154 &count,
1155 ))) {
1156 .SUCCESS => return info,
1157 .FAILURE => return error.PermissionDenied,
1158 else => |err| return unexpectedKernError(err),
1159 }
1160 }
13311161
1332/// add event to kq (implies enable)
1333pub const EV_ADD = 0x0001;
1162 pub fn getCurrProtection(task: MachTask, address: u64, len: usize) MachError!vm_prot_t {
1163 const info = try task.getRegionSubmapInfo(address, len, 0, .short);
1164 return info.info.short.protection;
1165 }
13341166
1335/// delete event from kq
1336pub const EV_DELETE = 0x0002;
1167 pub fn setMaxProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
1168 return task.setProtectionImpl(address, len, true, prot);
1169 }
13371170
1338/// enable event
1339pub const EV_ENABLE = 0x0004;
1171 pub fn setCurrProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
1172 return task.setProtectionImpl(address, len, false, prot);
1173 }
13401174
1341/// disable event (not reported)
1342pub const EV_DISABLE = 0x0008;
1175 fn setProtectionImpl(task: MachTask, address: u64, len: usize, set_max: bool, prot: vm_prot_t) MachError!void {
1176 switch (getKernError(mach_vm_protect(task.port, address, len, @intFromBool(set_max), prot))) {
1177 .SUCCESS => return,
1178 .FAILURE => return error.PermissionDenied,
1179 else => |err| return unexpectedKernError(err),
1180 }
1181 }
13431182
1344/// only report one occurrence
1345pub const EV_ONESHOT = 0x0010;
1183 /// Will write to VM even if current protection attributes specifically prohibit
1184 /// us from doing so, by temporarily setting protection level to a level with VM_PROT_COPY
1185 /// variant, and resetting after a successful or unsuccessful write.
1186 pub fn writeMemProtected(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
1187 const curr_prot = try task.getCurrProtection(address, buf.len);
1188 try task.setCurrProtection(
1189 address,
1190 buf.len,
1191 PROT.READ | PROT.WRITE | PROT.COPY,
1192 );
1193 defer {
1194 task.setCurrProtection(address, buf.len, curr_prot) catch {};
1195 }
1196 return task.writeMem(address, buf, arch);
1197 }
13461198
1347/// clear event state after reporting
1348pub const EV_CLEAR = 0x0020;
1199 pub fn writeMem(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
1200 const count = buf.len;
1201 var total_written: usize = 0;
1202 var curr_addr = address;
1203 const page_size = try getPageSize(task); // TODO we probably can assume value here
1204 var out_buf = buf[0..];
13491205
1350/// force immediate event output
1351/// ... with or without EV_ERROR
1352/// ... use KEVENT_FLAG_ERROR_EVENTS
1353/// on syscalls supporting flags
1354pub const EV_RECEIPT = 0x0040;
1206 while (total_written < count) {
1207 const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_written);
1208 switch (getKernError(mach_vm_write(
1209 task.port,
1210 curr_addr,
1211 @intFromPtr(out_buf.ptr),
1212 @as(mach_msg_type_number_t, @intCast(curr_size)),
1213 ))) {
1214 .SUCCESS => {},
1215 .FAILURE => return error.PermissionDenied,
1216 else => |err| return unexpectedKernError(err),
1217 }
13551218
1356/// disable event after reporting
1357pub const EV_DISPATCH = 0x0080;
1219 switch (arch) {
1220 .aarch64 => {
1221 var mattr_value: vm_machine_attribute_val_t = MATTR_VAL_CACHE_FLUSH;
1222 switch (getKernError(vm_machine_attribute(
1223 task.port,
1224 curr_addr,
1225 curr_size,
1226 MATTR_CACHE,
1227 &mattr_value,
1228 ))) {
1229 .SUCCESS => {},
1230 .FAILURE => return error.PermissionDenied,
1231 else => |err| return unexpectedKernError(err),
1232 }
1233 },
1234 .x86_64 => {},
1235 else => unreachable,
1236 }
13581237
1359/// unique kevent per udata value
1360pub const EV_UDATA_SPECIFIC = 0x0100;
1238 out_buf = out_buf[curr_size..];
1239 total_written += curr_size;
1240 curr_addr += curr_size;
1241 }
13611242
1362/// ... in combination with EV_DELETE
1363/// will defer delete until udata-specific
1364/// event enabled. EINPROGRESS will be
1365/// returned to indicate the deferral
1366pub const EV_DISPATCH2 = EV_DISPATCH | EV_UDATA_SPECIFIC;
1243 return total_written;
1244 }
13671245
1368/// report that source has vanished
1369/// ... only valid with EV_DISPATCH2
1370pub const EV_VANISHED = 0x0200;
1246 pub fn readMem(task: MachTask, address: u64, buf: []u8) MachError!usize {
1247 const count = buf.len;
1248 var total_read: usize = 0;
1249 var curr_addr = address;
1250 const page_size = try getPageSize(task); // TODO we probably can assume value here
1251 var out_buf = buf[0..];
13711252
1372/// reserved by system
1373pub const EV_SYSFLAGS = 0xF000;
1253 while (total_read < count) {
1254 const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_read);
1255 var curr_bytes_read: mach_msg_type_number_t = 0;
1256 var vm_memory: vm_offset_t = undefined;
1257 switch (getKernError(mach_vm_read(task.port, curr_addr, curr_size, &vm_memory, &curr_bytes_read))) {
1258 .SUCCESS => {},
1259 .FAILURE => return error.PermissionDenied,
1260 else => |err| return unexpectedKernError(err),
1261 }
13741262
1375/// filter-specific flag
1376pub const EV_FLAG0 = 0x1000;
1263 @memcpy(out_buf[0..curr_bytes_read], @as([*]const u8, @ptrFromInt(vm_memory)));
1264 _ = vm_deallocate(mach_task_self(), vm_memory, curr_bytes_read);
13771265
1378/// filter-specific flag
1379pub const EV_FLAG1 = 0x2000;
1266 out_buf = out_buf[curr_bytes_read..];
1267 curr_addr += curr_bytes_read;
1268 total_read += curr_bytes_read;
1269 }
13801270
1381/// EOF detected
1382pub const EV_EOF = 0x8000;
1271 return total_read;
1272 }
13831273
1384/// error, data contains errno
1385pub const EV_ERROR = 0x4000;
1274 fn maxBytesLeftInPage(page_size: usize, address: u64, count: usize) usize {
1275 var left = count;
1276 if (page_size > 0) {
1277 const page_offset = address % page_size;
1278 const bytes_left_in_page = page_size - page_offset;
1279 if (count > bytes_left_in_page) {
1280 left = bytes_left_in_page;
1281 }
1282 }
1283 return left;
1284 }
13861285
1387pub const EV_POLL = EV_FLAG0;
1388pub const EV_OOBAND = EV_FLAG1;
1286 fn getPageSize(task: MachTask) MachError!usize {
1287 if (task.isValid()) {
1288 var info_count = TASK_VM_INFO_COUNT;
1289 var vm_info: task_vm_info_data_t = undefined;
1290 switch (getKernError(task_info(
1291 task.port,
1292 TASK_VM_INFO,
1293 @as(task_info_t, @ptrCast(&vm_info)),
1294 &info_count,
1295 ))) {
1296 .SUCCESS => return @as(usize, @intCast(vm_info.page_size)),
1297 else => {},
1298 }
1299 }
1300 var page_size: vm_size_t = undefined;
1301 switch (getKernError(_host_page_size(mach_host_self(), &page_size))) {
1302 .SUCCESS => return page_size,
1303 else => |err| return unexpectedKernError(err),
1304 }
1305 }
13891306
1390pub const EVFILT_READ = -1;
1391pub const EVFILT_WRITE = -2;
1307 pub fn basicTaskInfo(task: MachTask) MachError!mach_task_basic_info {
1308 var info: mach_task_basic_info = undefined;
1309 var count = MACH_TASK_BASIC_INFO_COUNT;
1310 switch (getKernError(task_info(
1311 task.port,
1312 MACH_TASK_BASIC_INFO,
1313 @as(task_info_t, @ptrCast(&info)),
1314 &count,
1315 ))) {
1316 .SUCCESS => return info,
1317 else => |err| return unexpectedKernError(err),
1318 }
1319 }
13921320
1393/// attached to aio requests
1394pub const EVFILT_AIO = -3;
1395
1396/// attached to vnodes
1397pub const EVFILT_VNODE = -4;
1398
1399/// attached to struct proc
1400pub const EVFILT_PROC = -5;
1401
1402/// attached to struct proc
1403pub const EVFILT_SIGNAL = -6;
1404
1405/// timers
1406pub const EVFILT_TIMER = -7;
1407
1408/// Mach portsets
1409pub const EVFILT_MACHPORT = -8;
1410
1411/// Filesystem events
1412pub const EVFILT_FS = -9;
1413
1414/// User events
1415pub const EVFILT_USER = -10;
1416
1417/// Virtual memory events
1418pub const EVFILT_VM = -12;
1419
1420/// Exception events
1421pub const EVFILT_EXCEPT = -15;
1422
1423pub const EVFILT_SYSCOUNT = 17;
1424
1425/// On input, NOTE_TRIGGER causes the event to be triggered for output.
1426pub const NOTE_TRIGGER = 0x01000000;
1427
1428/// ignore input fflags
1429pub const NOTE_FFNOP = 0x00000000;
1430
1431/// and fflags
1432pub const NOTE_FFAND = 0x40000000;
1433
1434/// or fflags
1435pub const NOTE_FFOR = 0x80000000;
1436
1437/// copy fflags
1438pub const NOTE_FFCOPY = 0xc0000000;
1439
1440/// mask for operations
1441pub const NOTE_FFCTRLMASK = 0xc0000000;
1442pub const NOTE_FFLAGSMASK = 0x00ffffff;
1443
1444/// low water mark
1445pub const NOTE_LOWAT = 0x00000001;
1446
1447/// OOB data
1448pub const NOTE_OOB = 0x00000002;
1449
1450/// vnode was removed
1451pub const NOTE_DELETE = 0x00000001;
1452
1453/// data contents changed
1454pub const NOTE_WRITE = 0x00000002;
1455
1456/// size increased
1457pub const NOTE_EXTEND = 0x00000004;
1458
1459/// attributes changed
1460pub const NOTE_ATTRIB = 0x00000008;
1461
1462/// link count changed
1463pub const NOTE_LINK = 0x00000010;
1464
1465/// vnode was renamed
1466pub const NOTE_RENAME = 0x00000020;
1467
1468/// vnode access was revoked
1469pub const NOTE_REVOKE = 0x00000040;
1470
1471/// No specific vnode event: to test for EVFILT_READ activation
1472pub const NOTE_NONE = 0x00000080;
1473
1474/// vnode was unlocked by flock(2)
1475pub const NOTE_FUNLOCK = 0x00000100;
1476
1477/// process exited
1478pub const NOTE_EXIT = 0x80000000;
1479
1480/// process forked
1481pub const NOTE_FORK = 0x40000000;
1482
1483/// process exec'd
1484pub const NOTE_EXEC = 0x20000000;
1321 pub fn @"resume"(task: MachTask) MachError!void {
1322 switch (getKernError(task_resume(task.port))) {
1323 .SUCCESS => {},
1324 else => |err| return unexpectedKernError(err),
1325 }
1326 }
14851327
1486/// shared with EVFILT_SIGNAL
1487pub const NOTE_SIGNAL = 0x08000000;
1328 pub fn @"suspend"(task: MachTask) MachError!void {
1329 switch (getKernError(task_suspend(task.port))) {
1330 .SUCCESS => {},
1331 else => |err| return unexpectedKernError(err),
1332 }
1333 }
14881334
1489/// exit status to be returned, valid for child process only
1490pub const NOTE_EXITSTATUS = 0x04000000;
1335 const ThreadList = struct {
1336 buf: []MachThread,
14911337
1492/// provide details on reasons for exit
1493pub const NOTE_EXIT_DETAIL = 0x02000000;
1338 pub fn deinit(list: ThreadList) void {
1339 const self_task = machTaskForSelf();
1340 _ = vm_deallocate(
1341 self_task.port,
1342 @intFromPtr(list.buf.ptr),
1343 @as(vm_size_t, @intCast(list.buf.len * @sizeOf(mach_port_t))),
1344 );
1345 }
1346 };
14941347
1495/// mask for signal & exit status
1496pub const NOTE_PDATAMASK = 0x000fffff;
1497pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
1348 pub fn getThreads(task: MachTask) MachError!ThreadList {
1349 var thread_list: mach_port_array_t = undefined;
1350 var thread_count: mach_msg_type_number_t = undefined;
1351 switch (getKernError(task_threads(task.port, &thread_list, &thread_count))) {
1352 .SUCCESS => return ThreadList{ .buf = @as([*]MachThread, @ptrCast(thread_list))[0..thread_count] },
1353 else => |err| return unexpectedKernError(err),
1354 }
1355 }
1356};
14981357
1499pub const NOTE_EXIT_DETAIL_MASK = 0x00070000;
1500pub const NOTE_EXIT_DECRYPTFAIL = 0x00010000;
1501pub const NOTE_EXIT_MEMORY = 0x00020000;
1502pub const NOTE_EXIT_CSERROR = 0x00040000;
1358pub const MachThread = extern struct {
1359 port: mach_port_t,
15031360
1504/// will react on memory pressure
1505pub const NOTE_VM_PRESSURE = 0x80000000;
1361 pub fn isValid(thread: MachThread) bool {
1362 return thread.port != THREAD_NULL;
1363 }
15061364
1507/// will quit on memory pressure, possibly after cleaning up dirty state
1508pub const NOTE_VM_PRESSURE_TERMINATE = 0x40000000;
1365 pub fn getBasicInfo(thread: MachThread) MachError!thread_basic_info {
1366 var info: thread_basic_info = undefined;
1367 var count = THREAD_BASIC_INFO_COUNT;
1368 switch (getKernError(thread_info(
1369 thread.port,
1370 THREAD_BASIC_INFO,
1371 @as(thread_info_t, @ptrCast(&info)),
1372 &count,
1373 ))) {
1374 .SUCCESS => return info,
1375 else => |err| return unexpectedKernError(err),
1376 }
1377 }
15091378
1510/// will quit immediately on memory pressure
1511pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE = 0x20000000;
1379 pub fn getIdentifierInfo(thread: MachThread) MachError!thread_identifier_info {
1380 var info: thread_identifier_info = undefined;
1381 var count = THREAD_IDENTIFIER_INFO_COUNT;
1382 switch (getKernError(thread_info(
1383 thread.port,
1384 THREAD_IDENTIFIER_INFO,
1385 @as(thread_info_t, @ptrCast(&info)),
1386 &count,
1387 ))) {
1388 .SUCCESS => return info,
1389 else => |err| return unexpectedKernError(err),
1390 }
1391 }
1392};
15121393
1513/// there was an error
1514pub const NOTE_VM_ERROR = 0x10000000;
1394pub fn machTaskForPid(pid: std.c.pid_t) MachError!MachTask {
1395 var port: mach_port_name_t = undefined;
1396 switch (getKernError(task_for_pid(mach_task_self(), pid, &port))) {
1397 .SUCCESS => {},
1398 .FAILURE => return error.PermissionDenied,
1399 else => |err| return unexpectedKernError(err),
1400 }
1401 return MachTask{ .port = port };
1402}
15151403
1516/// data is seconds
1517pub const NOTE_SECONDS = 0x00000001;
1404pub fn machTaskForSelf() MachTask {
1405 return .{ .port = mach_task_self() };
1406}
15181407
1519/// data is microseconds
1520pub const NOTE_USECONDS = 0x00000002;
1408pub const os_signpost_id_t = u64;
15211409
1522/// data is nanoseconds
1523pub const NOTE_NSECONDS = 0x00000004;
1524
1525/// absolute timeout
1526pub const NOTE_ABSOLUTE = 0x00000008;
1527
1528/// ext[1] holds leeway for power aware timers
1529pub const NOTE_LEEWAY = 0x00000010;
1530
1531/// system does minimal timer coalescing
1532pub const NOTE_CRITICAL = 0x00000020;
1533
1534/// system does maximum timer coalescing
1535pub const NOTE_BACKGROUND = 0x00000040;
1536pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
1537
1538/// data is mach absolute time units
1539pub const NOTE_MACHTIME = 0x00000100;
1540
1541pub const AF = struct {
1542 pub const UNSPEC = 0;
1543 pub const LOCAL = 1;
1544 pub const UNIX = LOCAL;
1545 pub const INET = 2;
1546 pub const SYS_CONTROL = 2;
1547 pub const IMPLINK = 3;
1548 pub const PUP = 4;
1549 pub const CHAOS = 5;
1550 pub const NS = 6;
1551 pub const ISO = 7;
1552 pub const OSI = ISO;
1553 pub const ECMA = 8;
1554 pub const DATAKIT = 9;
1555 pub const CCITT = 10;
1556 pub const SNA = 11;
1557 pub const DECnet = 12;
1558 pub const DLI = 13;
1559 pub const LAT = 14;
1560 pub const HYLINK = 15;
1561 pub const APPLETALK = 16;
1562 pub const ROUTE = 17;
1563 pub const LINK = 18;
1564 pub const XTP = 19;
1565 pub const COIP = 20;
1566 pub const CNT = 21;
1567 pub const RTIP = 22;
1568 pub const IPX = 23;
1569 pub const SIP = 24;
1570 pub const PIP = 25;
1571 pub const ISDN = 28;
1572 pub const E164 = ISDN;
1573 pub const KEY = 29;
1574 pub const INET6 = 30;
1575 pub const NATM = 31;
1576 pub const SYSTEM = 32;
1577 pub const NETBIOS = 33;
1578 pub const PPP = 34;
1579 pub const MAX = 40;
1580};
1410pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0;
1411pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0;
1412pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee;
15811413
1582pub const PF = struct {
1583 pub const UNSPEC = AF.UNSPEC;
1584 pub const LOCAL = AF.LOCAL;
1585 pub const UNIX = PF.LOCAL;
1586 pub const INET = AF.INET;
1587 pub const IMPLINK = AF.IMPLINK;
1588 pub const PUP = AF.PUP;
1589 pub const CHAOS = AF.CHAOS;
1590 pub const NS = AF.NS;
1591 pub const ISO = AF.ISO;
1592 pub const OSI = AF.ISO;
1593 pub const ECMA = AF.ECMA;
1594 pub const DATAKIT = AF.DATAKIT;
1595 pub const CCITT = AF.CCITT;
1596 pub const SNA = AF.SNA;
1597 pub const DECnet = AF.DECnet;
1598 pub const DLI = AF.DLI;
1599 pub const LAT = AF.LAT;
1600 pub const HYLINK = AF.HYLINK;
1601 pub const APPLETALK = AF.APPLETALK;
1602 pub const ROUTE = AF.ROUTE;
1603 pub const LINK = AF.LINK;
1604 pub const XTP = AF.XTP;
1605 pub const COIP = AF.COIP;
1606 pub const CNT = AF.CNT;
1607 pub const SIP = AF.SIP;
1608 pub const IPX = AF.IPX;
1609 pub const RTIP = AF.RTIP;
1610 pub const PIP = AF.PIP;
1611 pub const ISDN = AF.ISDN;
1612 pub const KEY = AF.KEY;
1613 pub const INET6 = AF.INET6;
1614 pub const NATM = AF.NATM;
1615 pub const SYSTEM = AF.SYSTEM;
1616 pub const NETBIOS = AF.NETBIOS;
1617 pub const PPP = AF.PPP;
1618 pub const MAX = AF.MAX;
1414pub const os_log_t = opaque {};
1415pub const os_log_type_t = enum(u8) {
1416 /// default messages always captures
1417 OS_LOG_TYPE_DEFAULT = 0x00,
1418 /// messages with additional infos
1419 OS_LOG_TYPE_INFO = 0x01,
1420 /// debug messages
1421 OS_LOG_TYPE_DEBUG = 0x02,
1422 /// error messages
1423 OS_LOG_TYPE_ERROR = 0x10,
1424 /// unexpected conditions messages
1425 OS_LOG_TYPE_FAULT = 0x11,
16191426};
16201427
1621pub const SYSPROTO_EVENT = 1;
1622pub const SYSPROTO_CONTROL = 2;
1428pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
1429pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing";
1430pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
16231431
1624pub const SOCK = struct {
1625 pub const STREAM = 1;
1626 pub const DGRAM = 2;
1627 pub const RAW = 3;
1628 pub const RDM = 4;
1629 pub const SEQPACKET = 5;
1630 pub const MAXADDRLEN = 255;
1631
1632 /// Not actually supported by Darwin, but Zig supplies a shim.
1633 /// This numerical value is not ABI-stable. It need only not conflict
1634 /// with any other `SOCK` bits.
1635 pub const CLOEXEC = 1 << 15;
1636 /// Not actually supported by Darwin, but Zig supplies a shim.
1637 /// This numerical value is not ABI-stable. It need only not conflict
1638 /// with any other `SOCK` bits.
1639 pub const NONBLOCK = 1 << 16;
1640};
1432pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
1433pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
1434pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t;
1435pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
1436pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
1437pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
1438pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
16411439
1642pub const IPPROTO = struct {
1643 pub const ICMP = 1;
1644 pub const ICMPV6 = 58;
1645 pub const TCP = 6;
1646 pub const UDP = 17;
1647 pub const IP = 0;
1648 pub const IPV6 = 41;
1649};
1440pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
1441pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
1442pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
1443pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
1444pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
16501445
1651pub const SOL = struct {
1652 pub const SOCKET = 0xffff;
1446pub const mach_timebase_info_data = extern struct {
1447 numer: u32,
1448 denom: u32,
16531449};
16541450
1655pub const SO = struct {
1656 pub const DEBUG = 0x0001;
1657 pub const ACCEPTCONN = 0x0002;
1658 pub const REUSEADDR = 0x0004;
1659 pub const KEEPALIVE = 0x0008;
1660 pub const DONTROUTE = 0x0010;
1661 pub const BROADCAST = 0x0020;
1662 pub const USELOOPBACK = 0x0040;
1663 pub const LINGER = 0x1080;
1664 pub const OOBINLINE = 0x0100;
1665 pub const REUSEPORT = 0x0200;
1666 pub const ACCEPTFILTER = 0x1000;
1667 pub const SNDBUF = 0x1001;
1668 pub const RCVBUF = 0x1002;
1669 pub const SNDLOWAT = 0x1003;
1670 pub const RCVLOWAT = 0x1004;
1671 pub const SNDTIMEO = 0x1005;
1672 pub const RCVTIMEO = 0x1006;
1673 pub const ERROR = 0x1007;
1674 pub const TYPE = 0x1008;
1675
1676 pub const NREAD = 0x1020;
1677 pub const NKE = 0x1021;
1678 pub const NOSIGPIPE = 0x1022;
1679 pub const NOADDRERR = 0x1023;
1680 pub const NWRITE = 0x1024;
1681 pub const REUSESHAREUID = 0x1025;
1451pub const kevent64_s = extern struct {
1452 ident: u64,
1453 filter: i16,
1454 flags: u16,
1455 fflags: u32,
1456 data: i64,
1457 udata: u64,
1458 ext: [2]u64,
16821459};
16831460
1684pub const W = struct {
1685 /// [XSI] no hang in wait/no child to reap
1686 pub const NOHANG = 0x00000001;
1687 /// [XSI] notify on stop, untraced child
1688 pub const UNTRACED = 0x00000002;
1689
1690 pub fn EXITSTATUS(x: u32) u8 {
1691 return @as(u8, @intCast(x >> 8));
1692 }
1693 pub fn TERMSIG(x: u32) u32 {
1694 return status(x);
1695 }
1696 pub fn STOPSIG(x: u32) u32 {
1697 return x >> 8;
1698 }
1699 pub fn IFEXITED(x: u32) bool {
1700 return status(x) == 0;
1701 }
1702 pub fn IFSTOPPED(x: u32) bool {
1703 return status(x) == stopped and STOPSIG(x) != 0x13;
1704 }
1705 pub fn IFSIGNALED(x: u32) bool {
1706 return status(x) != stopped and status(x) != 0;
1461// sys/types.h on macos uses #pragma pack() so these checks are
1462// to make sure the struct is laid out the same. These values were
1463// produced from C code using the offsetof macro.
1464comptime {
1465 if (builtin.target.isDarwin()) {
1466 assert(@offsetOf(kevent64_s, "ident") == 0);
1467 assert(@offsetOf(kevent64_s, "filter") == 8);
1468 assert(@offsetOf(kevent64_s, "flags") == 10);
1469 assert(@offsetOf(kevent64_s, "fflags") == 12);
1470 assert(@offsetOf(kevent64_s, "data") == 16);
1471 assert(@offsetOf(kevent64_s, "udata") == 24);
1472 assert(@offsetOf(kevent64_s, "ext") == 32);
17071473 }
1474}
17081475
1709 fn status(x: u32) u32 {
1710 return x & 0o177;
1711 }
1712 const stopped = 0o177;
1476pub const clock_serv_t = mach_port_t;
1477pub const clock_res_t = c_int;
1478pub const mach_port_name_t = natural_t;
1479pub const natural_t = c_uint;
1480pub const mach_timespec_t = extern struct {
1481 sec: c_uint,
1482 nsec: clock_res_t,
17131483};
1484pub const kern_return_t = c_int;
1485pub const host_t = mach_port_t;
1486pub const integer_t = c_int;
1487pub const task_flavor_t = natural_t;
1488pub const task_info_t = *integer_t;
1489pub const task_name_t = mach_port_name_t;
1490pub const vm_address_t = vm_offset_t;
1491pub const vm_size_t = mach_vm_size_t;
1492pub const vm_machine_attribute_t = usize;
1493pub const vm_machine_attribute_val_t = isize;
17141494
1715pub const E = enum(u16) {
1716 /// No error occurred.
1717 SUCCESS = 0,
1718
1719 /// Operation not permitted
1720 PERM = 1,
1721
1722 /// No such file or directory
1723 NOENT = 2,
1724
1725 /// No such process
1726 SRCH = 3,
1727
1728 /// Interrupted system call
1729 INTR = 4,
1730
1731 /// Input/output error
1732 IO = 5,
1733
1734 /// Device not configured
1735 NXIO = 6,
1736
1737 /// Argument list too long
1738 @"2BIG" = 7,
1739
1740 /// Exec format error
1741 NOEXEC = 8,
1742
1743 /// Bad file descriptor
1744 BADF = 9,
1745
1746 /// No child processes
1747 CHILD = 10,
1748
1749 /// Resource deadlock avoided
1750 DEADLK = 11,
1751
1752 /// Cannot allocate memory
1753 NOMEM = 12,
1754
1755 /// Permission denied
1756 ACCES = 13,
1757
1758 /// Bad address
1759 FAULT = 14,
1760
1761 /// Block device required
1762 NOTBLK = 15,
1763
1764 /// Device / Resource busy
1765 BUSY = 16,
1766
1767 /// File exists
1768 EXIST = 17,
1769
1770 /// Cross-device link
1771 XDEV = 18,
1495pub const CALENDAR_CLOCK = 1;
17721496
1773 /// Operation not supported by device
1774 NODEV = 19,
1497/// no flag value
1498pub const KEVENT_FLAG_NONE = 0x000;
1499/// immediate timeout
1500pub const KEVENT_FLAG_IMMEDIATE = 0x001;
1501/// output events only include change
1502pub const KEVENT_FLAG_ERROR_EVENTS = 0x002;
17751503
1776 /// Not a directory
1777 NOTDIR = 20,
1778
1779 /// Is a directory
1780 ISDIR = 21,
1781
1782 /// Invalid argument
1783 INVAL = 22,
1784
1785 /// Too many open files in system
1786 NFILE = 23,
1787
1788 /// Too many open files
1789 MFILE = 24,
1790
1791 /// Inappropriate ioctl for device
1792 NOTTY = 25,
1793
1794 /// Text file busy
1795 TXTBSY = 26,
1796
1797 /// File too large
1798 FBIG = 27,
1799
1800 /// No space left on device
1801 NOSPC = 28,
1802
1803 /// Illegal seek
1804 SPIPE = 29,
1805
1806 /// Read-only file system
1807 ROFS = 30,
1808
1809 /// Too many links
1810 MLINK = 31,
1811
1812 /// Broken pipe
1813 PIPE = 32,
1814
1815 // math software
1816
1817 /// Numerical argument out of domain
1818 DOM = 33,
1819
1820 /// Result too large
1821 RANGE = 34,
1822
1823 // non-blocking and interrupt i/o
1824
1825 /// Resource temporarily unavailable
1826 /// This is the same code used for `WOULDBLOCK`.
1827 AGAIN = 35,
1828
1829 /// Operation now in progress
1830 INPROGRESS = 36,
1831
1832 /// Operation already in progress
1833 ALREADY = 37,
1834
1835 // ipc/network software -- argument errors
1836
1837 /// Socket operation on non-socket
1838 NOTSOCK = 38,
1839
1840 /// Destination address required
1841 DESTADDRREQ = 39,
1842
1843 /// Message too long
1844 MSGSIZE = 40,
1845
1846 /// Protocol wrong type for socket
1847 PROTOTYPE = 41,
1848
1849 /// Protocol not available
1850 NOPROTOOPT = 42,
1851
1852 /// Protocol not supported
1853 PROTONOSUPPORT = 43,
1854
1855 /// Socket type not supported
1856 SOCKTNOSUPPORT = 44,
1857
1858 /// Operation not supported
1859 /// The same code is used for `NOTSUP`.
1860 OPNOTSUPP = 45,
1861
1862 /// Protocol family not supported
1863 PFNOSUPPORT = 46,
1864
1865 /// Address family not supported by protocol family
1866 AFNOSUPPORT = 47,
1867
1868 /// Address already in use
1869 ADDRINUSE = 48,
1870 /// Can't assign requested address
1871
1872 // ipc/network software -- operational errors
1873 ADDRNOTAVAIL = 49,
1874
1875 /// Network is down
1876 NETDOWN = 50,
1877
1878 /// Network is unreachable
1879 NETUNREACH = 51,
1880
1881 /// Network dropped connection on reset
1882 NETRESET = 52,
1883
1884 /// Software caused connection abort
1885 CONNABORTED = 53,
1886
1887 /// Connection reset by peer
1888 CONNRESET = 54,
1889
1890 /// No buffer space available
1891 NOBUFS = 55,
1892
1893 /// Socket is already connected
1894 ISCONN = 56,
1895
1896 /// Socket is not connected
1897 NOTCONN = 57,
1898
1899 /// Can't send after socket shutdown
1900 SHUTDOWN = 58,
1901
1902 /// Too many references: can't splice
1903 TOOMANYREFS = 59,
1904
1905 /// Operation timed out
1906 TIMEDOUT = 60,
1907
1908 /// Connection refused
1909 CONNREFUSED = 61,
1910
1911 /// Too many levels of symbolic links
1912 LOOP = 62,
1913
1914 /// File name too long
1915 NAMETOOLONG = 63,
1916
1917 /// Host is down
1918 HOSTDOWN = 64,
1919
1920 /// No route to host
1921 HOSTUNREACH = 65,
1922 /// Directory not empty
1923
1924 // quotas & mush
1925 NOTEMPTY = 66,
1926
1927 /// Too many processes
1928 PROCLIM = 67,
1929
1930 /// Too many users
1931 USERS = 68,
1932 /// Disc quota exceeded
1933
1934 // Network File System
1935 DQUOT = 69,
1936
1937 /// Stale NFS file handle
1938 STALE = 70,
1939
1940 /// Too many levels of remote in path
1941 REMOTE = 71,
1942
1943 /// RPC struct is bad
1944 BADRPC = 72,
1945
1946 /// RPC version wrong
1947 RPCMISMATCH = 73,
1948
1949 /// RPC prog. not avail
1950 PROGUNAVAIL = 74,
1951
1952 /// Program version wrong
1953 PROGMISMATCH = 75,
1954
1955 /// Bad procedure for program
1956 PROCUNAVAIL = 76,
1957
1958 /// No locks available
1959 NOLCK = 77,
1960
1961 /// Function not implemented
1962 NOSYS = 78,
1963
1964 /// Inappropriate file type or format
1965 FTYPE = 79,
1966
1967 /// Authentication error
1968 AUTH = 80,
1969
1970 /// Need authenticator
1971 NEEDAUTH = 81,
1972
1973 // Intelligent device errors
1974
1975 /// Device power is off
1976 PWROFF = 82,
1977
1978 /// Device error, e.g. paper out
1979 DEVERR = 83,
1980
1981 /// Value too large to be stored in data type
1982 OVERFLOW = 84,
1983
1984 // Program loading errors
1985
1986 /// Bad executable
1987 BADEXEC = 85,
1988
1989 /// Bad CPU type in executable
1990 BADARCH = 86,
1991
1992 /// Shared library version mismatch
1993 SHLIBVERS = 87,
1994
1995 /// Malformed Macho file
1996 BADMACHO = 88,
1997
1998 /// Operation canceled
1999 CANCELED = 89,
2000
2001 /// Identifier removed
2002 IDRM = 90,
2003
2004 /// No message of desired type
2005 NOMSG = 91,
2006
2007 /// Illegal byte sequence
2008 ILSEQ = 92,
2009
2010 /// Attribute not found
2011 NOATTR = 93,
2012
2013 /// Bad message
2014 BADMSG = 94,
2015
2016 /// Reserved
2017 MULTIHOP = 95,
2018
2019 /// No message available on STREAM
2020 NODATA = 96,
2021
2022 /// Reserved
2023 NOLINK = 97,
2024
2025 /// No STREAM resources
2026 NOSR = 98,
2027
2028 /// Not a STREAM
2029 NOSTR = 99,
2030
2031 /// Protocol error
2032 PROTO = 100,
2033
2034 /// STREAM ioctl timeout
2035 TIME = 101,
2036
2037 /// No such policy registered
2038 NOPOLICY = 103,
2039
2040 /// State not recoverable
2041 NOTRECOVERABLE = 104,
2042
2043 /// Previous owner died
2044 OWNERDEAD = 105,
2045
2046 /// Interface output queue is full
2047 QFULL = 106,
2048
2049 _,
2050};
2051
2052/// Kernel return values
2053pub const KernE = enum(u32) {
2054 SUCCESS = 0,
2055
2056 /// Specified address is not currently valid
2057 INVALID_ADDRESS = 1,
2058
2059 /// Specified memory is valid, but does not permit the
2060 /// required forms of access.
2061 PROTECTION_FAILURE = 2,
2062
2063 /// The address range specified is already in use, or
2064 /// no address range of the size specified could be
2065 /// found.
2066 NO_SPACE = 3,
2067
2068 /// The function requested was not applicable to this
2069 /// type of argument, or an argument is invalid
2070 INVALID_ARGUMENT = 4,
2071
2072 /// The function could not be performed. A catch-all.
2073 FAILURE = 5,
2074
2075 /// A system resource could not be allocated to fulfill
2076 /// this request. This failure may not be permanent.
2077 RESOURCE_SHORTAGE = 6,
2078
2079 /// The task in question does not hold receive rights
2080 /// for the port argument.
2081 NOT_RECEIVER = 7,
2082
2083 /// Bogus access restriction.
2084 NO_ACCESS = 8,
2085
2086 /// During a page fault, the target address refers to a
2087 /// memory object that has been destroyed. This
2088 /// failure is permanent.
2089 MEMORY_FAILURE = 9,
2090
2091 /// During a page fault, the memory object indicated
2092 /// that the data could not be returned. This failure
2093 /// may be temporary; future attempts to access this
2094 /// same data may succeed, as defined by the memory
2095 /// object.
2096 MEMORY_ERROR = 10,
2097
2098 /// The receive right is already a member of the portset.
2099 ALREADY_IN_SET = 11,
2100
2101 /// The receive right is not a member of a port set.
2102 NOT_IN_SET = 12,
2103
2104 /// The name already denotes a right in the task.
2105 NAME_EXISTS = 13,
2106
2107 /// The operation was aborted. Ipc code will
2108 /// catch this and reflect it as a message error.
2109 ABORTED = 14,
2110
2111 /// The name doesn't denote a right in the task.
2112 INVALID_NAME = 15,
2113
2114 /// Target task isn't an active task.
2115 INVALID_TASK = 16,
2116
2117 /// The name denotes a right, but not an appropriate right.
2118 INVALID_RIGHT = 17,
2119
2120 /// A blatant range error.
2121 INVALID_VALUE = 18,
2122
2123 /// Operation would overflow limit on user-references.
2124 UREFS_OVERFLOW = 19,
2125
2126 /// The supplied (port) capability is improper.
2127 INVALID_CAPABILITY = 20,
2128
2129 /// The task already has send or receive rights
2130 /// for the port under another name.
2131 RIGHT_EXISTS = 21,
2132
2133 /// Target host isn't actually a host.
2134 INVALID_HOST = 22,
2135
2136 /// An attempt was made to supply "precious" data
2137 /// for memory that is already present in a
2138 /// memory object.
2139 MEMORY_PRESENT = 23,
2140
2141 /// A page was requested of a memory manager via
2142 /// memory_object_data_request for an object using
2143 /// a MEMORY_OBJECT_COPY_CALL strategy, with the
2144 /// VM_PROT_WANTS_COPY flag being used to specify
2145 /// that the page desired is for a copy of the
2146 /// object, and the memory manager has detected
2147 /// the page was pushed into a copy of the object
2148 /// while the kernel was walking the shadow chain
2149 /// from the copy to the object. This error code
2150 /// is delivered via memory_object_data_error
2151 /// and is handled by the kernel (it forces the
2152 /// kernel to restart the fault). It will not be
2153 /// seen by users.
2154 MEMORY_DATA_MOVED = 24,
2155
2156 /// A strategic copy was attempted of an object
2157 /// upon which a quicker copy is now possible.
2158 /// The caller should retry the copy using
2159 /// vm_object_copy_quickly. This error code
2160 /// is seen only by the kernel.
2161 MEMORY_RESTART_COPY = 25,
2162
2163 /// An argument applied to assert processor set privilege
2164 /// was not a processor set control port.
2165 INVALID_PROCESSOR_SET = 26,
2166
2167 /// The specified scheduling attributes exceed the thread's
2168 /// limits.
2169 POLICY_LIMIT = 27,
2170
2171 /// The specified scheduling policy is not currently
2172 /// enabled for the processor set.
2173 INVALID_POLICY = 28,
2174
2175 /// The external memory manager failed to initialize the
2176 /// memory object.
2177 INVALID_OBJECT = 29,
2178
2179 /// A thread is attempting to wait for an event for which
2180 /// there is already a waiting thread.
2181 ALREADY_WAITING = 30,
2182
2183 /// An attempt was made to destroy the default processor
2184 /// set.
2185 DEFAULT_SET = 31,
2186
2187 /// An attempt was made to fetch an exception port that is
2188 /// protected, or to abort a thread while processing a
2189 /// protected exception.
2190 EXCEPTION_PROTECTED = 32,
2191
2192 /// A ledger was required but not supplied.
2193 INVALID_LEDGER = 33,
2194
2195 /// The port was not a memory cache control port.
2196 INVALID_MEMORY_CONTROL = 34,
2197
2198 /// An argument supplied to assert security privilege
2199 /// was not a host security port.
2200 INVALID_SECURITY = 35,
2201
2202 /// thread_depress_abort was called on a thread which
2203 /// was not currently depressed.
2204 NOT_DEPRESSED = 36,
2205
2206 /// Object has been terminated and is no longer available
2207 TERMINATED = 37,
2208
2209 /// Lock set has been destroyed and is no longer available.
2210 LOCK_SET_DESTROYED = 38,
2211
2212 /// The thread holding the lock terminated before releasing
2213 /// the lock
2214 LOCK_UNSTABLE = 39,
2215
2216 /// The lock is already owned by another thread
2217 LOCK_OWNED = 40,
2218
2219 /// The lock is already owned by the calling thread
2220 LOCK_OWNED_SELF = 41,
2221
2222 /// Semaphore has been destroyed and is no longer available.
2223 SEMAPHORE_DESTROYED = 42,
2224
2225 /// Return from RPC indicating the target server was
2226 /// terminated before it successfully replied
2227 RPC_SERVER_TERMINATED = 43,
2228
2229 /// Terminate an orphaned activation.
2230 RPC_TERMINATE_ORPHAN = 44,
2231
2232 /// Allow an orphaned activation to continue executing.
2233 RPC_CONTINUE_ORPHAN = 45,
2234
2235 /// Empty thread activation (No thread linked to it)
2236 NOT_SUPPORTED = 46,
2237
2238 /// Remote node down or inaccessible.
2239 NODE_DOWN = 47,
2240
2241 /// A signalled thread was not actually waiting.
2242 NOT_WAITING = 48,
2243
2244 /// Some thread-oriented operation (semaphore_wait) timed out
2245 OPERATION_TIMED_OUT = 49,
2246
2247 /// During a page fault, indicates that the page was rejected
2248 /// as a result of a signature check.
2249 CODESIGN_ERROR = 50,
2250
2251 /// The requested property cannot be changed at this time.
2252 POLICY_STATIC = 51,
2253
2254 /// The provided buffer is of insufficient size for the requested data.
2255 INSUFFICIENT_BUFFER_SIZE = 52,
2256
2257 /// Denied by security policy
2258 DENIED = 53,
2259
2260 /// The KC on which the function is operating is missing
2261 MISSING_KC = 54,
2262
2263 /// The KC on which the function is operating is invalid
2264 INVALID_KC = 55,
2265
2266 /// A search or query operation did not return a result
2267 NOT_FOUND = 56,
2268
2269 _,
2270};
2271
2272pub const mach_msg_return_t = kern_return_t;
2273
2274pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {
2275 return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
2276}
2277
2278/// All special error code bits defined below.
2279pub const MACH_MSG_MASK: u32 = 0x3e00;
2280/// No room in IPC name space for another capability name.
2281pub const MACH_MSG_IPC_SPACE: u32 = 0x2000;
2282/// No room in VM address space for out-of-line memory.
2283pub const MACH_MSG_VM_SPACE: u32 = 0x1000;
2284/// Kernel resource shortage handling out-of-line memory.
2285pub const MACH_MSG_IPC_KERNEL: u32 = 0x800;
2286/// Kernel resource shortage handling an IPC capability.
2287pub const MACH_MSG_VM_KERNEL: u32 = 0x400;
2288
2289/// Mach msg return values
2290pub const MachMsgE = enum(u32) {
2291 SUCCESS = 0x00000000,
2292
2293 /// Thread is waiting to send. (Internal use only.)
2294 SEND_IN_PROGRESS = 0x10000001,
2295 /// Bogus in-line data.
2296 SEND_INVALID_DATA = 0x10000002,
2297 /// Bogus destination port.
2298 SEND_INVALID_DEST = 0x10000003,
2299 /// Message not sent before timeout expired.
2300 SEND_TIMED_OUT = 0x10000004,
2301 /// Bogus voucher port.
2302 SEND_INVALID_VOUCHER = 0x10000005,
2303 /// Software interrupt.
2304 SEND_INTERRUPTED = 0x10000007,
2305 /// Data doesn't contain a complete message.
2306 SEND_MSG_TOO_SMALL = 0x10000008,
2307 /// Bogus reply port.
2308 SEND_INVALID_REPLY = 0x10000009,
2309 /// Bogus port rights in the message body.
2310 SEND_INVALID_RIGHT = 0x1000000a,
2311 /// Bogus notify port argument.
2312 SEND_INVALID_NOTIFY = 0x1000000b,
2313 /// Invalid out-of-line memory pointer.
2314 SEND_INVALID_MEMORY = 0x1000000c,
2315 /// No message buffer is available.
2316 SEND_NO_BUFFER = 0x1000000d,
2317 /// Send is too large for port
2318 SEND_TOO_LARGE = 0x1000000e,
2319 /// Invalid msg-type specification.
2320 SEND_INVALID_TYPE = 0x1000000f,
2321 /// A field in the header had a bad value.
2322 SEND_INVALID_HEADER = 0x10000010,
2323 /// The trailer to be sent does not match kernel format.
2324 SEND_INVALID_TRAILER = 0x10000011,
2325 /// The sending thread context did not match the context on the dest port
2326 SEND_INVALID_CONTEXT = 0x10000012,
2327 /// compatibility: no longer a returned error
2328 SEND_INVALID_RT_OOL_SIZE = 0x10000015,
2329 /// The destination port doesn't accept ports in body
2330 SEND_NO_GRANT_DEST = 0x10000016,
2331 /// Message send was rejected by message filter
2332 SEND_MSG_FILTERED = 0x10000017,
2333
2334 /// Thread is waiting for receive. (Internal use only.)
2335 RCV_IN_PROGRESS = 0x10004001,
2336 /// Bogus name for receive port/port-set.
2337 RCV_INVALID_NAME = 0x10004002,
2338 /// Didn't get a message within the timeout value.
2339 RCV_TIMED_OUT = 0x10004003,
2340 /// Message buffer is not large enough for inline data.
2341 RCV_TOO_LARGE = 0x10004004,
2342 /// Software interrupt.
2343 RCV_INTERRUPTED = 0x10004005,
2344 /// compatibility: no longer a returned error
2345 RCV_PORT_CHANGED = 0x10004006,
2346 /// Bogus notify port argument.
2347 RCV_INVALID_NOTIFY = 0x10004007,
2348 /// Bogus message buffer for inline data.
2349 RCV_INVALID_DATA = 0x10004008,
2350 /// Port/set was sent away/died during receive.
2351 RCV_PORT_DIED = 0x10004009,
2352 /// compatibility: no longer a returned error
2353 RCV_IN_SET = 0x1000400a,
2354 /// Error receiving message header. See special bits.
2355 RCV_HEADER_ERROR = 0x1000400b,
2356 /// Error receiving message body. See special bits.
2357 RCV_BODY_ERROR = 0x1000400c,
2358 /// Invalid msg-type specification in scatter list.
2359 RCV_INVALID_TYPE = 0x1000400d,
2360 /// Out-of-line overwrite region is not large enough
2361 RCV_SCATTER_SMALL = 0x1000400e,
2362 /// trailer type or number of trailer elements not supported
2363 RCV_INVALID_TRAILER = 0x1000400f,
2364 /// Waiting for receive with timeout. (Internal use only.)
2365 RCV_IN_PROGRESS_TIMED = 0x10004011,
2366 /// invalid reply port used in a STRICT_REPLY message
2367 RCV_INVALID_REPLY = 0x10004012,
2368};
2369
2370pub const SIGSTKSZ = 131072;
2371pub const MINSIGSTKSZ = 32768;
2372
2373pub const SS_ONSTACK = 1;
2374pub const SS_DISABLE = 4;
2375
2376pub const stack_t = extern struct {
2377 sp: [*]u8,
2378 size: isize,
2379 flags: i32,
2380};
2381
2382pub const S = struct {
2383 pub const IFMT = 0o170000;
2384
2385 pub const IFIFO = 0o010000;
2386 pub const IFCHR = 0o020000;
2387 pub const IFDIR = 0o040000;
2388 pub const IFBLK = 0o060000;
2389 pub const IFREG = 0o100000;
2390 pub const IFLNK = 0o120000;
2391 pub const IFSOCK = 0o140000;
2392 pub const IFWHT = 0o160000;
2393
2394 pub const ISUID = 0o4000;
2395 pub const ISGID = 0o2000;
2396 pub const ISVTX = 0o1000;
2397 pub const IRWXU = 0o700;
2398 pub const IRUSR = 0o400;
2399 pub const IWUSR = 0o200;
2400 pub const IXUSR = 0o100;
2401 pub const IRWXG = 0o070;
2402 pub const IRGRP = 0o040;
2403 pub const IWGRP = 0o020;
2404 pub const IXGRP = 0o010;
2405 pub const IRWXO = 0o007;
2406 pub const IROTH = 0o004;
2407 pub const IWOTH = 0o002;
2408 pub const IXOTH = 0o001;
2409
2410 pub fn ISFIFO(m: u32) bool {
2411 return m & IFMT == IFIFO;
2412 }
2413
2414 pub fn ISCHR(m: u32) bool {
2415 return m & IFMT == IFCHR;
2416 }
2417
2418 pub fn ISDIR(m: u32) bool {
2419 return m & IFMT == IFDIR;
2420 }
2421
2422 pub fn ISBLK(m: u32) bool {
2423 return m & IFMT == IFBLK;
2424 }
2425
2426 pub fn ISREG(m: u32) bool {
2427 return m & IFMT == IFREG;
2428 }
2429
2430 pub fn ISLNK(m: u32) bool {
2431 return m & IFMT == IFLNK;
2432 }
2433
2434 pub fn ISSOCK(m: u32) bool {
2435 return m & IFMT == IFSOCK;
2436 }
2437
2438 pub fn IWHT(m: u32) bool {
2439 return m & IFMT == IFWHT;
2440 }
2441};
2442
2443pub const HOST_NAME_MAX = 72;
2444
2445pub const addrinfo = extern struct {
2446 flags: i32,
2447 family: i32,
2448 socktype: i32,
2449 protocol: i32,
2450 addrlen: socklen_t,
2451 canonname: ?[*:0]u8,
2452 addr: ?*sockaddr,
2453 next: ?*addrinfo,
2454};
2455
2456pub const RTLD = struct {
2457 pub const LAZY = 0x1;
2458 pub const NOW = 0x2;
2459 pub const LOCAL = 0x4;
2460 pub const GLOBAL = 0x8;
2461 pub const NOLOAD = 0x10;
2462 pub const NODELETE = 0x80;
2463 pub const FIRST = 0x100;
2464
2465 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
2466 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
2467 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
2468 pub const MAIN_ONLY = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -5)))));
2469};
2470
2471pub const F = struct {
2472 /// duplicate file descriptor
2473 pub const DUPFD = 0;
2474 /// get file descriptor flags
2475 pub const GETFD = 1;
2476 /// set file descriptor flags
2477 pub const SETFD = 2;
2478 /// get file status flags
2479 pub const GETFL = 3;
2480 /// set file status flags
2481 pub const SETFL = 4;
2482 /// get SIGIO/SIGURG proc/pgrp
2483 pub const GETOWN = 5;
2484 /// set SIGIO/SIGURG proc/pgrp
2485 pub const SETOWN = 6;
2486 /// get record locking information
2487 pub const GETLK = 7;
2488 /// set record locking information
2489 pub const SETLK = 8;
2490 /// F.SETLK; wait if blocked
2491 pub const SETLKW = 9;
2492 /// F.SETLK; wait if blocked, return on timeout
2493 pub const SETLKWTIMEOUT = 10;
2494 pub const FLUSH_DATA = 40;
2495 /// Used for regression test
2496 pub const CHKCLEAN = 41;
2497 /// Preallocate storage
2498 pub const PREALLOCATE = 42;
2499 /// Truncate a file without zeroing space
2500 pub const SETSIZE = 43;
2501 /// Issue an advisory read async with no copy to user
2502 pub const RDADVISE = 44;
2503 /// turn read ahead off/on for this fd
2504 pub const RDAHEAD = 45;
2505 /// turn data caching off/on for this fd
2506 pub const NOCACHE = 48;
2507 /// file offset to device offset
2508 pub const LOG2PHYS = 49;
2509 /// return the full path of the fd
2510 pub const GETPATH = 50;
2511 /// fsync + ask the drive to flush to the media
2512 pub const FULLFSYNC = 51;
2513 /// find which component (if any) is a package
2514 pub const PATHPKG_CHECK = 52;
2515 /// "freeze" all fs operations
2516 pub const FREEZE_FS = 53;
2517 /// "thaw" all fs operations
2518 pub const THAW_FS = 54;
2519 /// turn data caching off/on (globally) for this file
2520 pub const GLOBAL_NOCACHE = 55;
2521 /// add detached signatures
2522 pub const ADDSIGS = 59;
2523 /// add signature from same file (used by dyld for shared libs)
2524 pub const ADDFILESIGS = 61;
2525 /// used in conjunction with F.NOCACHE to indicate that DIRECT, synchronous writes
2526 /// should not be used (i.e. its ok to temporarily create cached pages)
2527 pub const NODIRECT = 62;
2528 ///Get the protection class of a file from the EA, returns int
2529 pub const GETPROTECTIONCLASS = 63;
2530 ///Set the protection class of a file for the EA, requires int
2531 pub const SETPROTECTIONCLASS = 64;
2532 ///file offset to device offset, extended
2533 pub const LOG2PHYS_EXT = 65;
2534 ///get record locking information, per-process
2535 pub const GETLKPID = 66;
2536 ///Mark the file as being the backing store for another filesystem
2537 pub const SETBACKINGSTORE = 70;
2538 ///return the full path of the FD, but error in specific mtmd circumstances
2539 pub const GETPATH_MTMINFO = 71;
2540 ///Returns the code directory, with associated hashes, to the caller
2541 pub const GETCODEDIR = 72;
2542 ///No SIGPIPE generated on EPIPE
2543 pub const SETNOSIGPIPE = 73;
2544 ///Status of SIGPIPE for this fd
2545 pub const GETNOSIGPIPE = 74;
2546 ///For some cases, we need to rewrap the key for AKS/MKB
2547 pub const TRANSCODEKEY = 75;
2548 ///file being written to a by single writer... if throttling enabled, writes
2549 ///may be broken into smaller chunks with throttling in between
2550 pub const SINGLE_WRITER = 76;
2551 ///Get the protection version number for this filesystem
2552 pub const GETPROTECTIONLEVEL = 77;
2553 ///Add detached code signatures (used by dyld for shared libs)
2554 pub const FINDSIGS = 78;
2555 ///Add signature from same file, only if it is signed by Apple (used by dyld for simulator)
2556 pub const ADDFILESIGS_FOR_DYLD_SIM = 83;
2557 ///fsync + issue barrier to drive
2558 pub const BARRIERFSYNC = 85;
2559 ///Add signature from same file, return end offset in structure on success
2560 pub const ADDFILESIGS_RETURN = 97;
2561 ///Check if Library Validation allows this Mach-O file to be mapped into the calling process
2562 pub const CHECK_LV = 98;
2563 ///Deallocate a range of the file
2564 pub const PUNCHHOLE = 99;
2565 ///Trim an active file
2566 pub const TRIM_ACTIVE_FILE = 100;
2567 ///mark the dup with FD_CLOEXEC
2568 pub const DUPFD_CLOEXEC = 67;
2569 /// shared or read lock
2570 pub const RDLCK = 1;
2571 /// unlock
2572 pub const UNLCK = 2;
2573 /// exclusive or write lock
2574 pub const WRLCK = 3;
2575};
2576
2577pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
2578
2579///close-on-exec flag
2580pub const FD_CLOEXEC = 1;
2581
2582pub const LOCK = struct {
2583 pub const SH = 1;
2584 pub const EX = 2;
2585 pub const UN = 8;
2586 pub const NB = 4;
2587};
2588
2589pub const nfds_t = u32;
2590pub const pollfd = extern struct {
2591 fd: fd_t,
2592 events: i16,
2593 revents: i16,
2594};
2595
2596pub const POLL = struct {
2597 pub const IN = 0x001;
2598 pub const PRI = 0x002;
2599 pub const OUT = 0x004;
2600 pub const RDNORM = 0x040;
2601 pub const WRNORM = OUT;
2602 pub const RDBAND = 0x080;
2603 pub const WRBAND = 0x100;
2604
2605 pub const EXTEND = 0x0200;
2606 pub const ATTRIB = 0x0400;
2607 pub const NLINK = 0x0800;
2608 pub const WRITE = 0x1000;
2609
2610 pub const ERR = 0x008;
2611 pub const HUP = 0x010;
2612 pub const NVAL = 0x020;
2613
2614 pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
2615};
2616
2617pub const CLOCK = struct {
2618 pub const REALTIME = 0;
2619 pub const MONOTONIC = 6;
2620 pub const MONOTONIC_RAW = 4;
2621 pub const MONOTONIC_RAW_APPROX = 5;
2622 pub const UPTIME_RAW = 8;
2623 pub const UPTIME_RAW_APPROX = 9;
2624 pub const PROCESS_CPUTIME_ID = 12;
2625 pub const THREAD_CPUTIME_ID = 16;
2626};
2627
2628/// Max open files per process
2629/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
2630pub const OPEN_MAX = 10240;
2631
2632pub const rusage = extern struct {
2633 utime: timeval,
2634 stime: timeval,
2635 maxrss: isize,
2636 ixrss: isize,
2637 idrss: isize,
2638 isrss: isize,
2639 minflt: isize,
2640 majflt: isize,
2641 nswap: isize,
2642 inblock: isize,
2643 oublock: isize,
2644 msgsnd: isize,
2645 msgrcv: isize,
2646 nsignals: isize,
2647 nvcsw: isize,
2648 nivcsw: isize,
2649
2650 pub const SELF = 0;
2651 pub const CHILDREN = -1;
2652};
2653
2654pub const rlimit_resource = enum(c_int) {
2655 CPU = 0,
2656 FSIZE = 1,
2657 DATA = 2,
2658 STACK = 3,
2659 CORE = 4,
2660 RSS = 5,
2661 MEMLOCK = 6,
2662 NPROC = 7,
2663 NOFILE = 8,
2664 _,
2665
2666 pub const AS: rlimit_resource = .RSS;
2667};
2668
2669pub const rlim_t = u64;
2670
2671pub const RLIM = struct {
2672 /// No limit
2673 pub const INFINITY: rlim_t = (1 << 63) - 1;
2674
2675 pub const SAVED_MAX = INFINITY;
2676 pub const SAVED_CUR = INFINITY;
2677};
2678
2679pub const rlimit = extern struct {
2680 /// Soft limit
2681 cur: rlim_t,
2682 /// Hard limit
2683 max: rlim_t,
2684};
2685
2686pub const SHUT = struct {
2687 pub const RD = 0;
2688 pub const WR = 1;
2689 pub const RDWR = 2;
2690};
2691
2692pub const TCSA = enum(c_uint) {
2693 NOW,
2694 DRAIN,
2695 FLUSH,
2696 _,
2697};
2698
2699pub const winsize = extern struct {
2700 ws_row: u16,
2701 ws_col: u16,
2702 ws_xpixel: u16,
2703 ws_ypixel: u16,
2704};
2705
2706pub const T = struct {
2707 pub const IOCGWINSZ = ior(0x40000000, 't', 104, @sizeOf(winsize));
2708};
2709pub const IOCPARM_MASK = 0x1fff;
2710
2711fn ior(inout: u32, group: usize, num: usize, len: usize) usize {
2712 return (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num));
2713}
2714
2715// CPU families mapping
2716pub const CPUFAMILY = enum(u32) {
2717 UNKNOWN = 0,
2718 POWERPC_G3 = 0xcee41549,
2719 POWERPC_G4 = 0x77c184ae,
2720 POWERPC_G5 = 0xed76d8aa,
2721 INTEL_6_13 = 0xaa33392b,
2722 INTEL_PENRYN = 0x78ea4fbc,
2723 INTEL_NEHALEM = 0x6b5a4cd2,
2724 INTEL_WESTMERE = 0x573b5eec,
2725 INTEL_SANDYBRIDGE = 0x5490b78c,
2726 INTEL_IVYBRIDGE = 0x1f65e835,
2727 INTEL_HASWELL = 0x10b282dc,
2728 INTEL_BROADWELL = 0x582ed09c,
2729 INTEL_SKYLAKE = 0x37fc219f,
2730 INTEL_KABYLAKE = 0x0f817246,
2731 ARM_9 = 0xe73283ae,
2732 ARM_11 = 0x8ff620d8,
2733 ARM_XSCALE = 0x53b005f5,
2734 ARM_12 = 0xbd1b0ae9,
2735 ARM_13 = 0x0cc90e64,
2736 ARM_14 = 0x96077ef1,
2737 ARM_15 = 0xa8511bca,
2738 ARM_SWIFT = 0x1e2d6381,
2739 ARM_CYCLONE = 0x37a09642,
2740 ARM_TYPHOON = 0x2c91a47e,
2741 ARM_TWISTER = 0x92fb37c8,
2742 ARM_HURRICANE = 0x67ceee93,
2743 ARM_MONSOON_MISTRAL = 0xe81e7ef6,
2744 ARM_VORTEX_TEMPEST = 0x07d34b9f,
2745 ARM_LIGHTNING_THUNDER = 0x462504d2,
2746 ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
2747 ARM_BLIZZARD_AVALANCHE = 0xda33d83d,
2748 ARM_EVEREST_SAWTOOTH = 0x8765edea,
2749 _,
2750};
2751
2752pub const PT = struct {
2753 pub const TRACE_ME = 0;
2754 pub const READ_I = 1;
2755 pub const READ_D = 2;
2756 pub const READ_U = 3;
2757 pub const WRITE_I = 4;
2758 pub const WRITE_D = 5;
2759 pub const WRITE_U = 6;
2760 pub const CONTINUE = 7;
2761 pub const KILL = 8;
2762 pub const STEP = 9;
2763 pub const DETACH = 11;
2764 pub const SIGEXC = 12;
2765 pub const THUPDATE = 13;
2766 pub const ATTACHEXC = 14;
2767 pub const FORCEQUOTA = 30;
2768 pub const DENY_ATTACH = 31;
2769};
2770
2771pub const caddr_t = ?[*]u8;
2772
2773pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int;
2774
2775pub const POSIX_SPAWN = struct {
2776 pub const RESETIDS = 0x0001;
2777 pub const SETPGROUP = 0x0002;
2778 pub const SETSIGDEF = 0x0004;
2779 pub const SETSIGMASK = 0x0008;
2780 pub const SETEXEC = 0x0040;
2781 pub const START_SUSPENDED = 0x0080;
2782 pub const DISABLE_ASLR = 0x0100;
2783 pub const SETSID = 0x0400;
2784 pub const RESLIDE = 0x0800;
2785 pub const CLOEXEC_DEFAULT = 0x4000;
2786};
2787
2788pub const posix_spawnattr_t = *opaque {};
2789pub const posix_spawn_file_actions_t = *opaque {};
2790pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
2791pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
2792pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int;
2793pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;
2794pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
2795pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
2796pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
2797pub extern "c" fn posix_spawn_file_actions_addopen(
2798 actions: *posix_spawn_file_actions_t,
2799 filedes: fd_t,
2800 path: [*:0]const u8,
2801 oflag: c_int,
2802 mode: mode_t,
2803) c_int;
2804pub extern "c" fn posix_spawn_file_actions_adddup2(
2805 actions: *posix_spawn_file_actions_t,
2806 filedes: fd_t,
2807 newfiledes: fd_t,
2808) c_int;
2809pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
2810pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;
2811pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
2812pub extern "c" fn posix_spawn(
2813 pid: *pid_t,
2814 path: [*:0]const u8,
2815 actions: ?*const posix_spawn_file_actions_t,
2816 attr: ?*const posix_spawnattr_t,
2817 argv: [*:null]?[*:0]const u8,
2818 env: [*:null]?[*:0]const u8,
2819) c_int;
2820pub extern "c" fn posix_spawnp(
2821 pid: *pid_t,
2822 path: [*:0]const u8,
2823 actions: ?*const posix_spawn_file_actions_t,
2824 attr: ?*const posix_spawnattr_t,
2825 argv: [*:null]?[*:0]const u8,
2826 env: [*:null]?[*:0]const u8,
2827) c_int;
2828
2829pub fn getKernError(err: kern_return_t) KernE {
2830 return @as(KernE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
2831}
2832
2833pub fn unexpectedKernError(err: KernE) std.posix.UnexpectedError {
2834 if (std.posix.unexpected_error_tracing) {
2835 std.debug.print("unexpected error: {d}\n", .{@intFromEnum(err)});
2836 std.debug.dumpCurrentStackTrace(null);
2837 }
2838 return error.Unexpected;
2839}
2840
2841pub const MachError = error{
2842 /// Not enough permissions held to perform the requested kernel
2843 /// call.
2844 PermissionDenied,
2845} || std.posix.UnexpectedError;
2846
2847pub const MachTask = extern struct {
2848 port: mach_port_name_t,
2849
2850 pub fn isValid(self: MachTask) bool {
2851 return self.port != TASK_NULL;
2852 }
2853
2854 pub fn pidForTask(self: MachTask) MachError!std.c.pid_t {
2855 var pid: std.c.pid_t = undefined;
2856 switch (getKernError(pid_for_task(self.port, &pid))) {
2857 .SUCCESS => return pid,
2858 .FAILURE => return error.PermissionDenied,
2859 else => |err| return unexpectedKernError(err),
2860 }
2861 }
2862
2863 pub fn allocatePort(self: MachTask, right: MACH_PORT_RIGHT) MachError!MachTask {
2864 var out_port: mach_port_name_t = undefined;
2865 switch (getKernError(mach_port_allocate(
2866 self.port,
2867 @intFromEnum(right),
2868 &out_port,
2869 ))) {
2870 .SUCCESS => return .{ .port = out_port },
2871 .FAILURE => return error.PermissionDenied,
2872 else => |err| return unexpectedKernError(err),
2873 }
2874 }
2875
2876 pub fn deallocatePort(self: MachTask, port: MachTask) void {
2877 _ = getKernError(mach_port_deallocate(self.port, port.port));
2878 }
2879
2880 pub fn insertRight(self: MachTask, port: MachTask, msg: MACH_MSG_TYPE) !void {
2881 switch (getKernError(mach_port_insert_right(
2882 self.port,
2883 port.port,
2884 port.port,
2885 @intFromEnum(msg),
2886 ))) {
2887 .SUCCESS => return,
2888 .FAILURE => return error.PermissionDenied,
2889 else => |err| return unexpectedKernError(err),
2890 }
2891 }
2892
2893 pub const PortInfo = struct {
2894 mask: exception_mask_t,
2895 masks: [EXC_TYPES_COUNT]exception_mask_t,
2896 ports: [EXC_TYPES_COUNT]mach_port_t,
2897 behaviors: [EXC_TYPES_COUNT]exception_behavior_t,
2898 flavors: [EXC_TYPES_COUNT]thread_state_flavor_t,
2899 count: mach_msg_type_number_t,
2900 };
2901
2902 pub fn getExceptionPorts(self: MachTask, mask: exception_mask_t) !PortInfo {
2903 var info = PortInfo{
2904 .mask = mask,
2905 .masks = undefined,
2906 .ports = undefined,
2907 .behaviors = undefined,
2908 .flavors = undefined,
2909 .count = 0,
2910 };
2911 info.count = info.ports.len / @sizeOf(mach_port_t);
2912
2913 switch (getKernError(task_get_exception_ports(
2914 self.port,
2915 info.mask,
2916 &info.masks,
2917 &info.count,
2918 &info.ports,
2919 &info.behaviors,
2920 &info.flavors,
2921 ))) {
2922 .SUCCESS => return info,
2923 .FAILURE => return error.PermissionDenied,
2924 else => |err| return unexpectedKernError(err),
2925 }
2926 }
2927
2928 pub fn setExceptionPorts(
2929 self: MachTask,
2930 mask: exception_mask_t,
2931 new_port: MachTask,
2932 behavior: exception_behavior_t,
2933 new_flavor: thread_state_flavor_t,
2934 ) !void {
2935 switch (getKernError(task_set_exception_ports(
2936 self.port,
2937 mask,
2938 new_port.port,
2939 behavior,
2940 new_flavor,
2941 ))) {
2942 .SUCCESS => return,
2943 .FAILURE => return error.PermissionDenied,
2944 else => |err| return unexpectedKernError(err),
2945 }
2946 }
2947
2948 pub const RegionInfo = struct {
2949 pub const Tag = enum {
2950 basic,
2951 extended,
2952 top,
2953 };
2954
2955 base_addr: u64,
2956 tag: Tag,
2957 info: union {
2958 basic: vm_region_basic_info_64,
2959 extended: vm_region_extended_info,
2960 top: vm_region_top_info,
2961 },
2962 };
2963
2964 pub fn getRegionInfo(
2965 task: MachTask,
2966 address: u64,
2967 len: usize,
2968 tag: RegionInfo.Tag,
2969 ) MachError!RegionInfo {
2970 var info: RegionInfo = .{
2971 .base_addr = address,
2972 .tag = tag,
2973 .info = undefined,
2974 };
2975 switch (tag) {
2976 .basic => info.info = .{ .basic = undefined },
2977 .extended => info.info = .{ .extended = undefined },
2978 .top => info.info = .{ .top = undefined },
2979 }
2980 var base_len: mach_vm_size_t = if (len == 1) 2 else len;
2981 var objname: mach_port_t = undefined;
2982 var count: mach_msg_type_number_t = switch (tag) {
2983 .basic => VM_REGION_BASIC_INFO_COUNT,
2984 .extended => VM_REGION_EXTENDED_INFO_COUNT,
2985 .top => VM_REGION_TOP_INFO_COUNT,
2986 };
2987 switch (getKernError(mach_vm_region(
2988 task.port,
2989 &info.base_addr,
2990 &base_len,
2991 switch (tag) {
2992 .basic => VM_REGION_BASIC_INFO_64,
2993 .extended => VM_REGION_EXTENDED_INFO,
2994 .top => VM_REGION_TOP_INFO,
2995 },
2996 switch (tag) {
2997 .basic => @as(vm_region_info_t, @ptrCast(&info.info.basic)),
2998 .extended => @as(vm_region_info_t, @ptrCast(&info.info.extended)),
2999 .top => @as(vm_region_info_t, @ptrCast(&info.info.top)),
3000 },
3001 &count,
3002 &objname,
3003 ))) {
3004 .SUCCESS => return info,
3005 .FAILURE => return error.PermissionDenied,
3006 else => |err| return unexpectedKernError(err),
3007 }
3008 }
3009
3010 pub const RegionSubmapInfo = struct {
3011 pub const Tag = enum {
3012 short,
3013 full,
3014 };
3015
3016 tag: Tag,
3017 base_addr: u64,
3018 info: union {
3019 short: vm_region_submap_short_info_64,
3020 full: vm_region_submap_info_64,
3021 },
3022 };
3023
3024 pub fn getRegionSubmapInfo(
3025 task: MachTask,
3026 address: u64,
3027 len: usize,
3028 nesting_depth: u32,
3029 tag: RegionSubmapInfo.Tag,
3030 ) MachError!RegionSubmapInfo {
3031 var info: RegionSubmapInfo = .{
3032 .base_addr = address,
3033 .tag = tag,
3034 .info = undefined,
3035 };
3036 switch (tag) {
3037 .short => info.info = .{ .short = undefined },
3038 .full => info.info = .{ .full = undefined },
3039 }
3040 var nesting = nesting_depth;
3041 var base_len: mach_vm_size_t = if (len == 1) 2 else len;
3042 var count: mach_msg_type_number_t = switch (tag) {
3043 .short => VM_REGION_SUBMAP_SHORT_INFO_COUNT_64,
3044 .full => VM_REGION_SUBMAP_INFO_COUNT_64,
3045 };
3046 switch (getKernError(mach_vm_region_recurse(
3047 task.port,
3048 &info.base_addr,
3049 &base_len,
3050 &nesting,
3051 switch (tag) {
3052 .short => @as(vm_region_recurse_info_t, @ptrCast(&info.info.short)),
3053 .full => @as(vm_region_recurse_info_t, @ptrCast(&info.info.full)),
3054 },
3055 &count,
3056 ))) {
3057 .SUCCESS => return info,
3058 .FAILURE => return error.PermissionDenied,
3059 else => |err| return unexpectedKernError(err),
3060 }
3061 }
3062
3063 pub fn getCurrProtection(task: MachTask, address: u64, len: usize) MachError!vm_prot_t {
3064 const info = try task.getRegionSubmapInfo(address, len, 0, .short);
3065 return info.info.short.protection;
3066 }
3067
3068 pub fn setMaxProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
3069 return task.setProtectionImpl(address, len, true, prot);
3070 }
3071
3072 pub fn setCurrProtection(task: MachTask, address: u64, len: usize, prot: vm_prot_t) MachError!void {
3073 return task.setProtectionImpl(address, len, false, prot);
3074 }
3075
3076 fn setProtectionImpl(task: MachTask, address: u64, len: usize, set_max: bool, prot: vm_prot_t) MachError!void {
3077 switch (getKernError(mach_vm_protect(task.port, address, len, @intFromBool(set_max), prot))) {
3078 .SUCCESS => return,
3079 .FAILURE => return error.PermissionDenied,
3080 else => |err| return unexpectedKernError(err),
3081 }
3082 }
3083
3084 /// Will write to VM even if current protection attributes specifically prohibit
3085 /// us from doing so, by temporarily setting protection level to a level with VM_PROT_COPY
3086 /// variant, and resetting after a successful or unsuccessful write.
3087 pub fn writeMemProtected(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
3088 const curr_prot = try task.getCurrProtection(address, buf.len);
3089 try task.setCurrProtection(
3090 address,
3091 buf.len,
3092 PROT.READ | PROT.WRITE | PROT.COPY,
3093 );
3094 defer {
3095 task.setCurrProtection(address, buf.len, curr_prot) catch {};
3096 }
3097 return task.writeMem(address, buf, arch);
3098 }
3099
3100 pub fn writeMem(task: MachTask, address: u64, buf: []const u8, arch: std.Target.Cpu.Arch) MachError!usize {
3101 const count = buf.len;
3102 var total_written: usize = 0;
3103 var curr_addr = address;
3104 const page_size = try getPageSize(task); // TODO we probably can assume value here
3105 var out_buf = buf[0..];
3106
3107 while (total_written < count) {
3108 const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_written);
3109 switch (getKernError(mach_vm_write(
3110 task.port,
3111 curr_addr,
3112 @intFromPtr(out_buf.ptr),
3113 @as(mach_msg_type_number_t, @intCast(curr_size)),
3114 ))) {
3115 .SUCCESS => {},
3116 .FAILURE => return error.PermissionDenied,
3117 else => |err| return unexpectedKernError(err),
3118 }
3119
3120 switch (arch) {
3121 .aarch64 => {
3122 var mattr_value: vm_machine_attribute_val_t = MATTR_VAL_CACHE_FLUSH;
3123 switch (getKernError(vm_machine_attribute(
3124 task.port,
3125 curr_addr,
3126 curr_size,
3127 MATTR_CACHE,
3128 &mattr_value,
3129 ))) {
3130 .SUCCESS => {},
3131 .FAILURE => return error.PermissionDenied,
3132 else => |err| return unexpectedKernError(err),
3133 }
3134 },
3135 .x86_64 => {},
3136 else => unreachable,
3137 }
3138
3139 out_buf = out_buf[curr_size..];
3140 total_written += curr_size;
3141 curr_addr += curr_size;
3142 }
3143
3144 return total_written;
3145 }
3146
3147 pub fn readMem(task: MachTask, address: u64, buf: []u8) MachError!usize {
3148 const count = buf.len;
3149 var total_read: usize = 0;
3150 var curr_addr = address;
3151 const page_size = try getPageSize(task); // TODO we probably can assume value here
3152 var out_buf = buf[0..];
3153
3154 while (total_read < count) {
3155 const curr_size = maxBytesLeftInPage(page_size, curr_addr, count - total_read);
3156 var curr_bytes_read: mach_msg_type_number_t = 0;
3157 var vm_memory: vm_offset_t = undefined;
3158 switch (getKernError(mach_vm_read(task.port, curr_addr, curr_size, &vm_memory, &curr_bytes_read))) {
3159 .SUCCESS => {},
3160 .FAILURE => return error.PermissionDenied,
3161 else => |err| return unexpectedKernError(err),
3162 }
3163
3164 @memcpy(out_buf[0..curr_bytes_read], @as([*]const u8, @ptrFromInt(vm_memory)));
3165 _ = vm_deallocate(mach_task_self(), vm_memory, curr_bytes_read);
1504pub const SYSPROTO_EVENT = 1;
1505pub const SYSPROTO_CONTROL = 2;
1506/// Kernel return values
1507pub const KernE = enum(u32) {
1508 SUCCESS = 0,
1509 /// Specified address is not currently valid
1510 INVALID_ADDRESS = 1,
1511 /// Specified memory is valid, but does not permit the
1512 /// required forms of access.
1513 PROTECTION_FAILURE = 2,
1514 /// The address range specified is already in use, or
1515 /// no address range of the size specified could be
1516 /// found.
1517 NO_SPACE = 3,
1518 /// The function requested was not applicable to this
1519 /// type of argument, or an argument is invalid
1520 INVALID_ARGUMENT = 4,
1521 /// The function could not be performed. A catch-all.
1522 FAILURE = 5,
1523 /// A system resource could not be allocated to fulfill
1524 /// this request. This failure may not be permanent.
1525 RESOURCE_SHORTAGE = 6,
1526 /// The task in question does not hold receive rights
1527 /// for the port argument.
1528 NOT_RECEIVER = 7,
1529 /// Bogus access restriction.
1530 NO_ACCESS = 8,
1531 /// During a page fault, the target address refers to a
1532 /// memory object that has been destroyed. This
1533 /// failure is permanent.
1534 MEMORY_FAILURE = 9,
1535 /// During a page fault, the memory object indicated
1536 /// that the data could not be returned. This failure
1537 /// may be temporary; future attempts to access this
1538 /// same data may succeed, as defined by the memory
1539 /// object.
1540 MEMORY_ERROR = 10,
1541 /// The receive right is already a member of the portset.
1542 ALREADY_IN_SET = 11,
1543 /// The receive right is not a member of a port set.
1544 NOT_IN_SET = 12,
1545 /// The name already denotes a right in the task.
1546 NAME_EXISTS = 13,
1547 /// The operation was aborted. Ipc code will
1548 /// catch this and reflect it as a message error.
1549 ABORTED = 14,
1550 /// The name doesn't denote a right in the task.
1551 INVALID_NAME = 15,
1552 /// Target task isn't an active task.
1553 INVALID_TASK = 16,
1554 /// The name denotes a right, but not an appropriate right.
1555 INVALID_RIGHT = 17,
1556 /// A blatant range error.
1557 INVALID_VALUE = 18,
1558 /// Operation would overflow limit on user-references.
1559 UREFS_OVERFLOW = 19,
1560 /// The supplied (port) capability is improper.
1561 INVALID_CAPABILITY = 20,
1562 /// The task already has send or receive rights
1563 /// for the port under another name.
1564 RIGHT_EXISTS = 21,
1565 /// Target host isn't actually a host.
1566 INVALID_HOST = 22,
1567 /// An attempt was made to supply "precious" data
1568 /// for memory that is already present in a
1569 /// memory object.
1570 MEMORY_PRESENT = 23,
1571 /// A page was requested of a memory manager via
1572 /// memory_object_data_request for an object using
1573 /// a MEMORY_OBJECT_COPY_CALL strategy, with the
1574 /// VM_PROT_WANTS_COPY flag being used to specify
1575 /// that the page desired is for a copy of the
1576 /// object, and the memory manager has detected
1577 /// the page was pushed into a copy of the object
1578 /// while the kernel was walking the shadow chain
1579 /// from the copy to the object. This error code
1580 /// is delivered via memory_object_data_error
1581 /// and is handled by the kernel (it forces the
1582 /// kernel to restart the fault). It will not be
1583 /// seen by users.
1584 MEMORY_DATA_MOVED = 24,
1585 /// A strategic copy was attempted of an object
1586 /// upon which a quicker copy is now possible.
1587 /// The caller should retry the copy using
1588 /// vm_object_copy_quickly. This error code
1589 /// is seen only by the kernel.
1590 MEMORY_RESTART_COPY = 25,
1591 /// An argument applied to assert processor set privilege
1592 /// was not a processor set control port.
1593 INVALID_PROCESSOR_SET = 26,
1594 /// The specified scheduling attributes exceed the thread's
1595 /// limits.
1596 POLICY_LIMIT = 27,
1597 /// The specified scheduling policy is not currently
1598 /// enabled for the processor set.
1599 INVALID_POLICY = 28,
1600 /// The external memory manager failed to initialize the
1601 /// memory object.
1602 INVALID_OBJECT = 29,
1603 /// A thread is attempting to wait for an event for which
1604 /// there is already a waiting thread.
1605 ALREADY_WAITING = 30,
1606 /// An attempt was made to destroy the default processor
1607 /// set.
1608 DEFAULT_SET = 31,
1609 /// An attempt was made to fetch an exception port that is
1610 /// protected, or to abort a thread while processing a
1611 /// protected exception.
1612 EXCEPTION_PROTECTED = 32,
1613 /// A ledger was required but not supplied.
1614 INVALID_LEDGER = 33,
1615 /// The port was not a memory cache control port.
1616 INVALID_MEMORY_CONTROL = 34,
1617 /// An argument supplied to assert security privilege
1618 /// was not a host security port.
1619 INVALID_SECURITY = 35,
1620 /// thread_depress_abort was called on a thread which
1621 /// was not currently depressed.
1622 NOT_DEPRESSED = 36,
1623 /// Object has been terminated and is no longer available
1624 TERMINATED = 37,
1625 /// Lock set has been destroyed and is no longer available.
1626 LOCK_SET_DESTROYED = 38,
1627 /// The thread holding the lock terminated before releasing
1628 /// the lock
1629 LOCK_UNSTABLE = 39,
1630 /// The lock is already owned by another thread
1631 LOCK_OWNED = 40,
1632 /// The lock is already owned by the calling thread
1633 LOCK_OWNED_SELF = 41,
1634 /// Semaphore has been destroyed and is no longer available.
1635 SEMAPHORE_DESTROYED = 42,
1636 /// Return from RPC indicating the target server was
1637 /// terminated before it successfully replied
1638 RPC_SERVER_TERMINATED = 43,
1639 /// Terminate an orphaned activation.
1640 RPC_TERMINATE_ORPHAN = 44,
1641 /// Allow an orphaned activation to continue executing.
1642 RPC_CONTINUE_ORPHAN = 45,
1643 /// Empty thread activation (No thread linked to it)
1644 NOT_SUPPORTED = 46,
1645 /// Remote node down or inaccessible.
1646 NODE_DOWN = 47,
1647 /// A signalled thread was not actually waiting.
1648 NOT_WAITING = 48,
1649 /// Some thread-oriented operation (semaphore_wait) timed out
1650 OPERATION_TIMED_OUT = 49,
1651 /// During a page fault, indicates that the page was rejected
1652 /// as a result of a signature check.
1653 CODESIGN_ERROR = 50,
1654 /// The requested property cannot be changed at this time.
1655 POLICY_STATIC = 51,
1656 /// The provided buffer is of insufficient size for the requested data.
1657 INSUFFICIENT_BUFFER_SIZE = 52,
1658 /// Denied by security policy
1659 DENIED = 53,
1660 /// The KC on which the function is operating is missing
1661 MISSING_KC = 54,
1662 /// The KC on which the function is operating is invalid
1663 INVALID_KC = 55,
1664 /// A search or query operation did not return a result
1665 NOT_FOUND = 56,
1666 _,
1667};
31661668
3167 out_buf = out_buf[curr_bytes_read..];
3168 curr_addr += curr_bytes_read;
3169 total_read += curr_bytes_read;
3170 }
1669pub const mach_msg_return_t = kern_return_t;
31711670
3172 return total_read;
3173 }
1671pub fn getMachMsgError(err: mach_msg_return_t) MachMsgE {
1672 return @as(MachMsgE, @enumFromInt(@as(u32, @truncate(@as(usize, @intCast(err))))));
1673}
31741674
3175 fn maxBytesLeftInPage(page_size: usize, address: u64, count: usize) usize {
3176 var left = count;
3177 if (page_size > 0) {
3178 const page_offset = address % page_size;
3179 const bytes_left_in_page = page_size - page_offset;
3180 if (count > bytes_left_in_page) {
3181 left = bytes_left_in_page;
3182 }
3183 }
3184 return left;
3185 }
1675/// All special error code bits defined below.
1676pub const MACH_MSG_MASK: u32 = 0x3e00;
1677/// No room in IPC name space for another capability name.
1678pub const MACH_MSG_IPC_SPACE: u32 = 0x2000;
1679/// No room in VM address space for out-of-line memory.
1680pub const MACH_MSG_VM_SPACE: u32 = 0x1000;
1681/// Kernel resource shortage handling out-of-line memory.
1682pub const MACH_MSG_IPC_KERNEL: u32 = 0x800;
1683/// Kernel resource shortage handling an IPC capability.
1684pub const MACH_MSG_VM_KERNEL: u32 = 0x400;
31861685
3187 fn getPageSize(task: MachTask) MachError!usize {
3188 if (task.isValid()) {
3189 var info_count = TASK_VM_INFO_COUNT;
3190 var vm_info: task_vm_info_data_t = undefined;
3191 switch (getKernError(task_info(
3192 task.port,
3193 TASK_VM_INFO,
3194 @as(task_info_t, @ptrCast(&vm_info)),
3195 &info_count,
3196 ))) {
3197 .SUCCESS => return @as(usize, @intCast(vm_info.page_size)),
3198 else => {},
3199 }
3200 }
3201 var page_size: vm_size_t = undefined;
3202 switch (getKernError(_host_page_size(mach_host_self(), &page_size))) {
3203 .SUCCESS => return page_size,
3204 else => |err| return unexpectedKernError(err),
3205 }
3206 }
1686/// Mach msg return values
1687pub const MachMsgE = enum(u32) {
1688 SUCCESS = 0x00000000,
32071689
3208 pub fn basicTaskInfo(task: MachTask) MachError!mach_task_basic_info {
3209 var info: mach_task_basic_info = undefined;
3210 var count = MACH_TASK_BASIC_INFO_COUNT;
3211 switch (getKernError(task_info(
3212 task.port,
3213 MACH_TASK_BASIC_INFO,
3214 @as(task_info_t, @ptrCast(&info)),
3215 &count,
3216 ))) {
3217 .SUCCESS => return info,
3218 else => |err| return unexpectedKernError(err),
3219 }
3220 }
1690 /// Thread is waiting to send. (Internal use only.)
1691 SEND_IN_PROGRESS = 0x10000001,
1692 /// Bogus in-line data.
1693 SEND_INVALID_DATA = 0x10000002,
1694 /// Bogus destination port.
1695 SEND_INVALID_DEST = 0x10000003,
1696 /// Message not sent before timeout expired.
1697 SEND_TIMED_OUT = 0x10000004,
1698 /// Bogus voucher port.
1699 SEND_INVALID_VOUCHER = 0x10000005,
1700 /// Software interrupt.
1701 SEND_INTERRUPTED = 0x10000007,
1702 /// Data doesn't contain a complete message.
1703 SEND_MSG_TOO_SMALL = 0x10000008,
1704 /// Bogus reply port.
1705 SEND_INVALID_REPLY = 0x10000009,
1706 /// Bogus port rights in the message body.
1707 SEND_INVALID_RIGHT = 0x1000000a,
1708 /// Bogus notify port argument.
1709 SEND_INVALID_NOTIFY = 0x1000000b,
1710 /// Invalid out-of-line memory pointer.
1711 SEND_INVALID_MEMORY = 0x1000000c,
1712 /// No message buffer is available.
1713 SEND_NO_BUFFER = 0x1000000d,
1714 /// Send is too large for port
1715 SEND_TOO_LARGE = 0x1000000e,
1716 /// Invalid msg-type specification.
1717 SEND_INVALID_TYPE = 0x1000000f,
1718 /// A field in the header had a bad value.
1719 SEND_INVALID_HEADER = 0x10000010,
1720 /// The trailer to be sent does not match kernel format.
1721 SEND_INVALID_TRAILER = 0x10000011,
1722 /// The sending thread context did not match the context on the dest port
1723 SEND_INVALID_CONTEXT = 0x10000012,
1724 /// compatibility: no longer a returned error
1725 SEND_INVALID_RT_OOL_SIZE = 0x10000015,
1726 /// The destination port doesn't accept ports in body
1727 SEND_NO_GRANT_DEST = 0x10000016,
1728 /// Message send was rejected by message filter
1729 SEND_MSG_FILTERED = 0x10000017,
32211730
3222 pub fn @"resume"(task: MachTask) MachError!void {
3223 switch (getKernError(task_resume(task.port))) {
3224 .SUCCESS => {},
3225 else => |err| return unexpectedKernError(err),
3226 }
3227 }
1731 /// Thread is waiting for receive. (Internal use only.)
1732 RCV_IN_PROGRESS = 0x10004001,
1733 /// Bogus name for receive port/port-set.
1734 RCV_INVALID_NAME = 0x10004002,
1735 /// Didn't get a message within the timeout value.
1736 RCV_TIMED_OUT = 0x10004003,
1737 /// Message buffer is not large enough for inline data.
1738 RCV_TOO_LARGE = 0x10004004,
1739 /// Software interrupt.
1740 RCV_INTERRUPTED = 0x10004005,
1741 /// compatibility: no longer a returned error
1742 RCV_PORT_CHANGED = 0x10004006,
1743 /// Bogus notify port argument.
1744 RCV_INVALID_NOTIFY = 0x10004007,
1745 /// Bogus message buffer for inline data.
1746 RCV_INVALID_DATA = 0x10004008,
1747 /// Port/set was sent away/died during receive.
1748 RCV_PORT_DIED = 0x10004009,
1749 /// compatibility: no longer a returned error
1750 RCV_IN_SET = 0x1000400a,
1751 /// Error receiving message header. See special bits.
1752 RCV_HEADER_ERROR = 0x1000400b,
1753 /// Error receiving message body. See special bits.
1754 RCV_BODY_ERROR = 0x1000400c,
1755 /// Invalid msg-type specification in scatter list.
1756 RCV_INVALID_TYPE = 0x1000400d,
1757 /// Out-of-line overwrite region is not large enough
1758 RCV_SCATTER_SMALL = 0x1000400e,
1759 /// trailer type or number of trailer elements not supported
1760 RCV_INVALID_TRAILER = 0x1000400f,
1761 /// Waiting for receive with timeout. (Internal use only.)
1762 RCV_IN_PROGRESS_TIMED = 0x10004011,
1763 /// invalid reply port used in a STRICT_REPLY message
1764 RCV_INVALID_REPLY = 0x10004012,
1765};
32281766
3229 pub fn @"suspend"(task: MachTask) MachError!void {
3230 switch (getKernError(task_suspend(task.port))) {
3231 .SUCCESS => {},
3232 else => |err| return unexpectedKernError(err),
3233 }
3234 }
1767pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;
32351768
3236 const ThreadList = struct {
3237 buf: []MachThread,
1769/// Max open files per process
1770/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
1771pub const OPEN_MAX = 10240;
32381772
3239 pub fn deinit(list: ThreadList) void {
3240 const self_task = machTaskForSelf();
3241 _ = vm_deallocate(
3242 self_task.port,
3243 @intFromPtr(list.buf.ptr),
3244 @as(vm_size_t, @intCast(list.buf.len * @sizeOf(mach_port_t))),
3245 );
3246 }
3247 };
1773// CPU families mapping
1774pub const CPUFAMILY = enum(u32) {
1775 UNKNOWN = 0,
1776 POWERPC_G3 = 0xcee41549,
1777 POWERPC_G4 = 0x77c184ae,
1778 POWERPC_G5 = 0xed76d8aa,
1779 INTEL_6_13 = 0xaa33392b,
1780 INTEL_PENRYN = 0x78ea4fbc,
1781 INTEL_NEHALEM = 0x6b5a4cd2,
1782 INTEL_WESTMERE = 0x573b5eec,
1783 INTEL_SANDYBRIDGE = 0x5490b78c,
1784 INTEL_IVYBRIDGE = 0x1f65e835,
1785 INTEL_HASWELL = 0x10b282dc,
1786 INTEL_BROADWELL = 0x582ed09c,
1787 INTEL_SKYLAKE = 0x37fc219f,
1788 INTEL_KABYLAKE = 0x0f817246,
1789 ARM_9 = 0xe73283ae,
1790 ARM_11 = 0x8ff620d8,
1791 ARM_XSCALE = 0x53b005f5,
1792 ARM_12 = 0xbd1b0ae9,
1793 ARM_13 = 0x0cc90e64,
1794 ARM_14 = 0x96077ef1,
1795 ARM_15 = 0xa8511bca,
1796 ARM_SWIFT = 0x1e2d6381,
1797 ARM_CYCLONE = 0x37a09642,
1798 ARM_TYPHOON = 0x2c91a47e,
1799 ARM_TWISTER = 0x92fb37c8,
1800 ARM_HURRICANE = 0x67ceee93,
1801 ARM_MONSOON_MISTRAL = 0xe81e7ef6,
1802 ARM_VORTEX_TEMPEST = 0x07d34b9f,
1803 ARM_LIGHTNING_THUNDER = 0x462504d2,
1804 ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
1805 ARM_BLIZZARD_AVALANCHE = 0xda33d83d,
1806 ARM_EVEREST_SAWTOOTH = 0x8765edea,
1807 _,
1808};
32481809
3249 pub fn getThreads(task: MachTask) MachError!ThreadList {
3250 var thread_list: mach_port_array_t = undefined;
3251 var thread_count: mach_msg_type_number_t = undefined;
3252 switch (getKernError(task_threads(task.port, &thread_list, &thread_count))) {
3253 .SUCCESS => return ThreadList{ .buf = @as([*]MachThread, @ptrCast(thread_list))[0..thread_count] },
3254 else => |err| return unexpectedKernError(err),
3255 }
3256 }
1810pub const PT = struct {
1811 pub const TRACE_ME = 0;
1812 pub const READ_I = 1;
1813 pub const READ_D = 2;
1814 pub const READ_U = 3;
1815 pub const WRITE_I = 4;
1816 pub const WRITE_D = 5;
1817 pub const WRITE_U = 6;
1818 pub const CONTINUE = 7;
1819 pub const KILL = 8;
1820 pub const STEP = 9;
1821 pub const DETACH = 11;
1822 pub const SIGEXC = 12;
1823 pub const THUPDATE = 13;
1824 pub const ATTACHEXC = 14;
1825 pub const FORCEQUOTA = 30;
1826 pub const DENY_ATTACH = 31;
32571827};
32581828
3259pub const MachThread = extern struct {
3260 port: mach_port_t,
1829pub const caddr_t = ?[*]u8;
32611830
3262 pub fn isValid(thread: MachThread) bool {
3263 return thread.port != THREAD_NULL;
3264 }
1831pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: caddr_t, data: c_int) c_int;
32651832
3266 pub fn getBasicInfo(thread: MachThread) MachError!thread_basic_info {
3267 var info: thread_basic_info = undefined;
3268 var count = THREAD_BASIC_INFO_COUNT;
3269 switch (getKernError(thread_info(
3270 thread.port,
3271 THREAD_BASIC_INFO,
3272 @as(thread_info_t, @ptrCast(&info)),
3273 &count,
3274 ))) {
3275 .SUCCESS => return info,
3276 else => |err| return unexpectedKernError(err),
3277 }
3278 }
1833pub const POSIX_SPAWN = struct {
1834 pub const RESETIDS = 0x0001;
1835 pub const SETPGROUP = 0x0002;
1836 pub const SETSIGDEF = 0x0004;
1837 pub const SETSIGMASK = 0x0008;
1838 pub const SETEXEC = 0x0040;
1839 pub const START_SUSPENDED = 0x0080;
1840 pub const DISABLE_ASLR = 0x0100;
1841 pub const SETSID = 0x0400;
1842 pub const RESLIDE = 0x0800;
1843 pub const CLOEXEC_DEFAULT = 0x4000;
1844};
32791845
3280 pub fn getIdentifierInfo(thread: MachThread) MachError!thread_identifier_info {
3281 var info: thread_identifier_info = undefined;
3282 var count = THREAD_IDENTIFIER_INFO_COUNT;
3283 switch (getKernError(thread_info(
3284 thread.port,
3285 THREAD_IDENTIFIER_INFO,
3286 @as(thread_info_t, @ptrCast(&info)),
3287 &count,
3288 ))) {
3289 .SUCCESS => return info,
3290 else => |err| return unexpectedKernError(err),
3291 }
3292 }
1846pub const posix_spawnattr_t = *opaque {};
1847pub const posix_spawn_file_actions_t = *opaque {};
1848pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
1849pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
1850pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: c_short) c_int;
1851pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *c_short) c_int;
1852pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
1853pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
1854pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
1855pub extern "c" fn posix_spawn_file_actions_addopen(
1856 actions: *posix_spawn_file_actions_t,
1857 filedes: fd_t,
1858 path: [*:0]const u8,
1859 oflag: c_int,
1860 mode: mode_t,
1861) c_int;
1862pub extern "c" fn posix_spawn_file_actions_adddup2(
1863 actions: *posix_spawn_file_actions_t,
1864 filedes: fd_t,
1865 newfiledes: fd_t,
1866) c_int;
1867pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
1868pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;
1869pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
1870pub extern "c" fn posix_spawn(
1871 pid: *pid_t,
1872 path: [*:0]const u8,
1873 actions: ?*const posix_spawn_file_actions_t,
1874 attr: ?*const posix_spawnattr_t,
1875 argv: [*:null]?[*:0]const u8,
1876 env: [*:null]?[*:0]const u8,
1877) c_int;
1878pub extern "c" fn posix_spawnp(
1879 pid: *pid_t,
1880 path: [*:0]const u8,
1881 actions: ?*const posix_spawn_file_actions_t,
1882 attr: ?*const posix_spawnattr_t,
1883 argv: [*:null]?[*:0]const u8,
1884 env: [*:null]?[*:0]const u8,
1885) c_int;
1886
1887pub const E = enum(u16) {
1888 /// No error occurred.
1889 SUCCESS = 0,
1890 /// Operation not permitted
1891 PERM = 1,
1892 /// No such file or directory
1893 NOENT = 2,
1894 /// No such process
1895 SRCH = 3,
1896 /// Interrupted system call
1897 INTR = 4,
1898 /// Input/output error
1899 IO = 5,
1900 /// Device not configured
1901 NXIO = 6,
1902 /// Argument list too long
1903 @"2BIG" = 7,
1904 /// Exec format error
1905 NOEXEC = 8,
1906 /// Bad file descriptor
1907 BADF = 9,
1908 /// No child processes
1909 CHILD = 10,
1910 /// Resource deadlock avoided
1911 DEADLK = 11,
1912 /// Cannot allocate memory
1913 NOMEM = 12,
1914 /// Permission denied
1915 ACCES = 13,
1916 /// Bad address
1917 FAULT = 14,
1918 /// Block device required
1919 NOTBLK = 15,
1920 /// Device / Resource busy
1921 BUSY = 16,
1922 /// File exists
1923 EXIST = 17,
1924 /// Cross-device link
1925 XDEV = 18,
1926 /// Operation not supported by device
1927 NODEV = 19,
1928 /// Not a directory
1929 NOTDIR = 20,
1930 /// Is a directory
1931 ISDIR = 21,
1932 /// Invalid argument
1933 INVAL = 22,
1934 /// Too many open files in system
1935 NFILE = 23,
1936 /// Too many open files
1937 MFILE = 24,
1938 /// Inappropriate ioctl for device
1939 NOTTY = 25,
1940 /// Text file busy
1941 TXTBSY = 26,
1942 /// File too large
1943 FBIG = 27,
1944 /// No space left on device
1945 NOSPC = 28,
1946 /// Illegal seek
1947 SPIPE = 29,
1948 /// Read-only file system
1949 ROFS = 30,
1950 /// Too many links
1951 MLINK = 31,
1952 /// Broken pipe
1953 PIPE = 32,
1954 // math software
1955 /// Numerical argument out of domain
1956 DOM = 33,
1957 /// Result too large
1958 RANGE = 34,
1959 // non-blocking and interrupt i/o
1960 /// Resource temporarily unavailable
1961 /// This is the same code used for `WOULDBLOCK`.
1962 AGAIN = 35,
1963 /// Operation now in progress
1964 INPROGRESS = 36,
1965 /// Operation already in progress
1966 ALREADY = 37,
1967 // ipc/network software -- argument errors
1968 /// Socket operation on non-socket
1969 NOTSOCK = 38,
1970 /// Destination address required
1971 DESTADDRREQ = 39,
1972 /// Message too long
1973 MSGSIZE = 40,
1974 /// Protocol wrong type for socket
1975 PROTOTYPE = 41,
1976 /// Protocol not available
1977 NOPROTOOPT = 42,
1978 /// Protocol not supported
1979 PROTONOSUPPORT = 43,
1980 /// Socket type not supported
1981 SOCKTNOSUPPORT = 44,
1982 /// Operation not supported
1983 /// The same code is used for `NOTSUP`.
1984 OPNOTSUPP = 45,
1985 /// Protocol family not supported
1986 PFNOSUPPORT = 46,
1987 /// Address family not supported by protocol family
1988 AFNOSUPPORT = 47,
1989 /// Address already in use
1990 ADDRINUSE = 48,
1991 /// Can't assign requested address
1992 // ipc/network software -- operational errors
1993 ADDRNOTAVAIL = 49,
1994 /// Network is down
1995 NETDOWN = 50,
1996 /// Network is unreachable
1997 NETUNREACH = 51,
1998 /// Network dropped connection on reset
1999 NETRESET = 52,
2000 /// Software caused connection abort
2001 CONNABORTED = 53,
2002 /// Connection reset by peer
2003 CONNRESET = 54,
2004 /// No buffer space available
2005 NOBUFS = 55,
2006 /// Socket is already connected
2007 ISCONN = 56,
2008 /// Socket is not connected
2009 NOTCONN = 57,
2010 /// Can't send after socket shutdown
2011 SHUTDOWN = 58,
2012 /// Too many references: can't splice
2013 TOOMANYREFS = 59,
2014 /// Operation timed out
2015 TIMEDOUT = 60,
2016 /// Connection refused
2017 CONNREFUSED = 61,
2018 /// Too many levels of symbolic links
2019 LOOP = 62,
2020 /// File name too long
2021 NAMETOOLONG = 63,
2022 /// Host is down
2023 HOSTDOWN = 64,
2024 /// No route to host
2025 HOSTUNREACH = 65,
2026 /// Directory not empty
2027 // quotas & mush
2028 NOTEMPTY = 66,
2029 /// Too many processes
2030 PROCLIM = 67,
2031 /// Too many users
2032 USERS = 68,
2033 /// Disc quota exceeded
2034 // Network File System
2035 DQUOT = 69,
2036 /// Stale NFS file handle
2037 STALE = 70,
2038 /// Too many levels of remote in path
2039 REMOTE = 71,
2040 /// RPC struct is bad
2041 BADRPC = 72,
2042 /// RPC version wrong
2043 RPCMISMATCH = 73,
2044 /// RPC prog. not avail
2045 PROGUNAVAIL = 74,
2046 /// Program version wrong
2047 PROGMISMATCH = 75,
2048 /// Bad procedure for program
2049 PROCUNAVAIL = 76,
2050 /// No locks available
2051 NOLCK = 77,
2052 /// Function not implemented
2053 NOSYS = 78,
2054 /// Inappropriate file type or format
2055 FTYPE = 79,
2056 /// Authentication error
2057 AUTH = 80,
2058 /// Need authenticator
2059 NEEDAUTH = 81,
2060 // Intelligent device errors
2061 /// Device power is off
2062 PWROFF = 82,
2063 /// Device error, e.g. paper out
2064 DEVERR = 83,
2065 /// Value too large to be stored in data type
2066 OVERFLOW = 84,
2067 // Program loading errors
2068 /// Bad executable
2069 BADEXEC = 85,
2070 /// Bad CPU type in executable
2071 BADARCH = 86,
2072 /// Shared library version mismatch
2073 SHLIBVERS = 87,
2074 /// Malformed Macho file
2075 BADMACHO = 88,
2076 /// Operation canceled
2077 CANCELED = 89,
2078 /// Identifier removed
2079 IDRM = 90,
2080 /// No message of desired type
2081 NOMSG = 91,
2082 /// Illegal byte sequence
2083 ILSEQ = 92,
2084 /// Attribute not found
2085 NOATTR = 93,
2086 /// Bad message
2087 BADMSG = 94,
2088 /// Reserved
2089 MULTIHOP = 95,
2090 /// No message available on STREAM
2091 NODATA = 96,
2092 /// Reserved
2093 NOLINK = 97,
2094 /// No STREAM resources
2095 NOSR = 98,
2096 /// Not a STREAM
2097 NOSTR = 99,
2098 /// Protocol error
2099 PROTO = 100,
2100 /// STREAM ioctl timeout
2101 TIME = 101,
2102 /// No such policy registered
2103 NOPOLICY = 103,
2104 /// State not recoverable
2105 NOTRECOVERABLE = 104,
2106 /// Previous owner died
2107 OWNERDEAD = 105,
2108 /// Interface output queue is full
2109 QFULL = 106,
2110 _,
32932111};
32942112
3295pub fn machTaskForPid(pid: std.c.pid_t) MachError!MachTask {
3296 var port: mach_port_name_t = undefined;
3297 switch (getKernError(task_for_pid(mach_task_self(), pid, &port))) {
3298 .SUCCESS => {},
3299 .FAILURE => return error.PermissionDenied,
3300 else => |err| return unexpectedKernError(err),
3301 }
3302 return MachTask{ .port = port };
3303}
2113/// From Common Security Services Manager
2114/// Security.framework/Headers/cssm*.h
2115pub const DB_RECORDTYPE = enum(u32) {
2116 // Record Types defined in the Schema Management Name Space
2117 SCHEMA_INFO = SCHEMA_START + 0,
2118 SCHEMA_INDEXES = SCHEMA_START + 1,
2119 SCHEMA_ATTRIBUTES = SCHEMA_START + 2,
2120 SCHEMA_PARSING_MODULE = SCHEMA_START + 3,
2121
2122 // Record Types defined in the Open Group Application Name Space
2123 ANY = OPEN_GROUP_START + 0,
2124 CERT = OPEN_GROUP_START + 1,
2125 CRL = OPEN_GROUP_START + 2,
2126 POLICY = OPEN_GROUP_START + 3,
2127 GENERIC = OPEN_GROUP_START + 4,
2128 PUBLIC_KEY = OPEN_GROUP_START + 5,
2129 PRIVATE_KEY = OPEN_GROUP_START + 6,
2130 SYMMETRIC_KEY = OPEN_GROUP_START + 7,
2131 ALL_KEYS = OPEN_GROUP_START + 8,
2132
2133 // AppleFileDL record types
2134 GENERIC_PASSWORD = APP_DEFINED_START + 0,
2135 INTERNET_PASSWORD = APP_DEFINED_START + 1,
2136 APPLESHARE_PASSWORD = APP_DEFINED_START + 2,
2137
2138 X509_CERTIFICATE = APP_DEFINED_START + 0x1000,
2139 USER_TRUST,
2140 X509_CRL,
2141 UNLOCK_REFERRAL,
2142 EXTENDED_ATTRIBUTE,
2143 METADATA = APP_DEFINED_START + 0x8000,
33042144
3305pub fn machTaskForSelf() MachTask {
3306 return .{ .port = mach_task_self() };
3307}
2145 _,
33082146
3309pub const os_signpost_id_t = u64;
2147 // Schema Management Name Space Range Definition
2148 pub const SCHEMA_START = 0x00000000;
2149 pub const SCHEMA_END = SCHEMA_START + 4;
33102150
3311pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0;
3312pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0;
3313pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee;
2151 // Open Group Application Name Space Range Definition
2152 pub const OPEN_GROUP_START = 0x0000000A;
2153 pub const OPEN_GROUP_END = OPEN_GROUP_START + 8;
33142154
3315pub const os_log_t = opaque {};
3316pub const os_log_type_t = enum(u8) {
3317 /// default messages always captures
3318 OS_LOG_TYPE_DEFAULT = 0x00,
3319 /// messages with additional infos
3320 OS_LOG_TYPE_INFO = 0x01,
3321 /// debug messages
3322 OS_LOG_TYPE_DEBUG = 0x02,
3323 /// error messages
3324 OS_LOG_TYPE_ERROR = 0x10,
3325 /// unexpected conditions messages
3326 OS_LOG_TYPE_FAULT = 0x11,
2155 // Industry At Large Application Name Space Range Definition
2156 pub const APP_DEFINED_START = 0x80000000;
2157 pub const APP_DEFINED_END = 0xffffffff;
33272158};
3328
3329pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
3330pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing";
3331pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
3332
3333pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
3334pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
3335pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t;
3336pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
3337pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
3338pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
3339pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
lib/std/c/darwin/aarch64.zig deleted-51
......@@ -1,51 +0,0 @@
1// See C headers in
2// lib/libc/include/aarch64-macos.12-gnu/mach/arm/_structs.h
3// lib/libc/include/aarch64-macos.13-none/arm/_mcontext.h
4
5pub const mcontext_t = extern struct {
6 es: exception_state,
7 ss: thread_state,
8 ns: neon_state,
9};
10
11pub const exception_state = extern struct {
12 far: u64, // Virtual Fault Address
13 esr: u32, // Exception syndrome
14 exception: u32, // Number of arm exception taken
15};
16
17pub const thread_state = extern struct {
18 regs: [29]u64, // General purpose registers
19 fp: u64, // Frame pointer x29
20 lr: u64, // Link register x30
21 sp: u64, // Stack pointer x31
22 pc: u64, // Program counter
23 cpsr: u32, // Current program status register
24 __pad: u32,
25};
26
27pub const neon_state = extern struct {
28 q: [32]u128,
29 fpsr: u32,
30 fpcr: u32,
31};
32
33pub const EXC_TYPES_COUNT = 14;
34pub const EXC_MASK_MACHINE = 0;
35
36pub const ARM_THREAD_STATE = 1;
37pub const ARM_UNIFIED_THREAD_STATE = ARM_THREAD_STATE;
38pub const ARM_VFP_STATE = 2;
39pub const ARM_EXCEPTION_STATE = 3;
40pub const ARM_DEBUG_STATE = 4;
41pub const THREAD_STATE_NONE = 5;
42pub const ARM_THREAD_STATE64 = 6;
43pub const ARM_EXCEPTION_STATE64 = 7;
44pub const ARM_THREAD_STATE_LAST = 8;
45pub const ARM_THREAD_STATE32 = 9;
46pub const ARM_DEBUG_STATE32 = 14;
47pub const ARM_DEBUG_STATE64 = 15;
48pub const ARM_NEON_STATE = 16;
49pub const ARM_NEON_STATE64 = 17;
50pub const ARM_CPMU_STATE64 = 18;
51pub const ARM_PAGEIN_STATE = 27;
lib/std/c/darwin/cssm.zig deleted-47
......@@ -1,47 +0,0 @@
1// Common Security Services Manager
2// Security.framework/Headers/cssm*.h
3
4// Schema Management Name Space Range Definition
5pub const DB_RECORDTYPE_SCHEMA_START = 0x00000000;
6pub const DB_RECORDTYPE_SCHEMA_END = DB_RECORDTYPE_SCHEMA_START + 4;
7
8// Open Group Application Name Space Range Definition
9pub const DB_RECORDTYPE_OPEN_GROUP_START = 0x0000000A;
10pub const DB_RECORDTYPE_OPEN_GROUP_END = DB_RECORDTYPE_OPEN_GROUP_START + 8;
11
12// Industry At Large Application Name Space Range Definition
13pub const DB_RECORDTYPE_APP_DEFINED_START = 0x80000000;
14pub const DB_RECORDTYPE_APP_DEFINED_END = 0xffffffff;
15
16pub const DB_RECORDTYPE = enum(u32) {
17 // Record Types defined in the Schema Management Name Space
18 SCHEMA_INFO = DB_RECORDTYPE_SCHEMA_START + 0,
19 SCHEMA_INDEXES = DB_RECORDTYPE_SCHEMA_START + 1,
20 SCHEMA_ATTRIBUTES = DB_RECORDTYPE_SCHEMA_START + 2,
21 SCHEMA_PARSING_MODULE = DB_RECORDTYPE_SCHEMA_START + 3,
22
23 // Record Types defined in the Open Group Application Name Space
24 ANY = DB_RECORDTYPE_OPEN_GROUP_START + 0,
25 CERT = DB_RECORDTYPE_OPEN_GROUP_START + 1,
26 CRL = DB_RECORDTYPE_OPEN_GROUP_START + 2,
27 POLICY = DB_RECORDTYPE_OPEN_GROUP_START + 3,
28 GENERIC = DB_RECORDTYPE_OPEN_GROUP_START + 4,
29 PUBLIC_KEY = DB_RECORDTYPE_OPEN_GROUP_START + 5,
30 PRIVATE_KEY = DB_RECORDTYPE_OPEN_GROUP_START + 6,
31 SYMMETRIC_KEY = DB_RECORDTYPE_OPEN_GROUP_START + 7,
32 ALL_KEYS = DB_RECORDTYPE_OPEN_GROUP_START + 8,
33
34 // AppleFileDL record types
35 GENERIC_PASSWORD = DB_RECORDTYPE_APP_DEFINED_START + 0,
36 INTERNET_PASSWORD = DB_RECORDTYPE_APP_DEFINED_START + 1,
37 APPLESHARE_PASSWORD = DB_RECORDTYPE_APP_DEFINED_START + 2,
38
39 X509_CERTIFICATE = DB_RECORDTYPE_APP_DEFINED_START + 0x1000,
40 USER_TRUST,
41 X509_CRL,
42 UNLOCK_REFERRAL,
43 EXTENDED_ATTRIBUTE,
44 METADATA = DB_RECORDTYPE_APP_DEFINED_START + 0x8000,
45
46 _,
47};
lib/std/c/darwin/x86_64.zig deleted-91
......@@ -1,91 +0,0 @@
1const c = @import("../darwin.zig");
2
3pub const mcontext_t = extern struct {
4 es: exception_state,
5 ss: thread_state,
6 fs: float_state,
7};
8
9pub const exception_state = extern struct {
10 trapno: u16,
11 cpu: u16,
12 err: u32,
13 faultvaddr: u64,
14};
15
16pub const thread_state = extern struct {
17 rax: u64,
18 rbx: u64,
19 rcx: u64,
20 rdx: u64,
21 rdi: u64,
22 rsi: u64,
23 rbp: u64,
24 rsp: u64,
25 r8: u64,
26 r9: u64,
27 r10: u64,
28 r11: u64,
29 r12: u64,
30 r13: u64,
31 r14: u64,
32 r15: u64,
33 rip: u64,
34 rflags: u64,
35 cs: u64,
36 fs: u64,
37 gs: u64,
38};
39
40const stmm_reg = [16]u8;
41const xmm_reg = [16]u8;
42pub const float_state = extern struct {
43 reserved: [2]c_int,
44 fcw: u16,
45 fsw: u16,
46 ftw: u8,
47 rsrv1: u8,
48 fop: u16,
49 ip: u32,
50 cs: u16,
51 rsrv2: u16,
52 dp: u32,
53 ds: u16,
54 rsrv3: u16,
55 mxcsr: u32,
56 mxcsrmask: u32,
57 stmm: [8]stmm_reg,
58 xmm: [16]xmm_reg,
59 rsrv4: [96]u8,
60 reserved1: c_int,
61};
62
63pub const THREAD_STATE = 4;
64pub const THREAD_STATE_COUNT: c.mach_msg_type_number_t = @sizeOf(thread_state) / @sizeOf(c_int);
65
66pub const EXC_TYPES_COUNT = 14;
67pub const EXC_MASK_MACHINE = 0;
68
69pub const x86_THREAD_STATE32 = 1;
70pub const x86_FLOAT_STATE32 = 2;
71pub const x86_EXCEPTION_STATE32 = 3;
72pub const x86_THREAD_STATE64 = 4;
73pub const x86_FLOAT_STATE64 = 5;
74pub const x86_EXCEPTION_STATE64 = 6;
75pub const x86_THREAD_STATE = 7;
76pub const x86_FLOAT_STATE = 8;
77pub const x86_EXCEPTION_STATE = 9;
78pub const x86_DEBUG_STATE32 = 10;
79pub const x86_DEBUG_STATE64 = 11;
80pub const x86_DEBUG_STATE = 12;
81pub const THREAD_STATE_NONE = 13;
82pub const x86_AVX_STATE32 = 16;
83pub const x86_AVX_STATE64 = (x86_AVX_STATE32 + 1);
84pub const x86_AVX_STATE = (x86_AVX_STATE32 + 2);
85pub const x86_AVX512_STATE32 = 19;
86pub const x86_AVX512_STATE64 = (x86_AVX512_STATE32 + 1);
87pub const x86_AVX512_STATE = (x86_AVX512_STATE32 + 2);
88pub const x86_PAGEIN_STATE = 22;
89pub const x86_THREAD_FULL_STATE64 = 23;
90pub const x86_INSTRUCTION_STATE = 24;
91pub const x86_LAST_BRANCH_STATE = 25;
lib/std/c/dragonfly.zig+16-970
......@@ -1,63 +1,16 @@
1const builtin = @import("builtin");
21const std = @import("../std.zig");
3const assert = std.debug.assert;
4const maxInt = std.math.maxInt;
5const iovec = std.posix.iovec;
62
7extern "c" threadlocal var errno: c_int;
8pub fn _errno() *c_int {
9 return &errno;
10}
11
12pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
13pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
14pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
15pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
16pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
17
18pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
19pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
3const SIG = std.c.SIG;
4const gid_t = std.c.gid_t;
5const iovec = std.c.iovec;
6const pid_t = std.c.pid_t;
7const socklen_t = std.c.socklen_t;
8const uid_t = std.c.uid_t;
209
2110pub extern "c" fn lwp_gettid() c_int;
22
23pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
24
25pub const pthread_attr_t = extern struct { // copied from freebsd
26 __size: [56]u8,
27 __align: c_long,
28};
29
30pub const sem_t = ?*opaque {};
31
32pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
33pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
34
3511pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int;
3612pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int;
3713
38// See:
39// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h
40// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h
41// TODO: mode_t should probably be changed to a u16, audit pid_t/off_t as well
42pub const fd_t = c_int;
43pub const pid_t = c_int;
44pub const off_t = c_long;
45pub const mode_t = c_uint;
46pub const uid_t = u32;
47pub const gid_t = u32;
48pub const time_t = isize;
49pub const suseconds_t = c_long;
50
51pub const ucontext_t = extern struct {
52 sigmask: sigset_t,
53 mcontext: mcontext_t,
54 link: ?*ucontext_t,
55 stack: stack_t,
56 cofunc: ?*fn (?*ucontext_t, ?*anyopaque) void,
57 arg: ?*void,
58 _spare: [4]c_int,
59};
60
6114pub const mcontext_t = extern struct {
6215 onstack: register_t, // XXX - sigcontext compat.
6316 rdi: register_t,
......@@ -201,707 +154,23 @@ pub const E = enum(u16) {
201154 _,
202155};
203156
204pub const STDIN_FILENO = 0;
205pub const STDOUT_FILENO = 1;
206pub const STDERR_FILENO = 2;
207
208pub const PROT = struct {
209 pub const NONE = 0;
210 pub const READ = 1;
211 pub const WRITE = 2;
212 pub const EXEC = 4;
213};
214
215pub const MSF = struct {
216 pub const ASYNC = 1;
217 pub const INVALIDATE = 2;
218 pub const SYNC = 4;
219};
220
221pub const W = struct {
222 pub const NOHANG = 0x0001;
223 pub const UNTRACED = 0x0002;
224 pub const CONTINUED = 0x0004;
225 pub const STOPPED = UNTRACED;
226 pub const NOWAIT = 0x0008;
227 pub const EXITED = 0x0010;
228 pub const TRAPPED = 0x0020;
229
230 pub fn EXITSTATUS(s: u32) u8 {
231 return @as(u8, @intCast((s & 0xff00) >> 8));
232 }
233 pub fn TERMSIG(s: u32) u32 {
234 return s & 0x7f;
235 }
236 pub fn STOPSIG(s: u32) u32 {
237 return EXITSTATUS(s);
238 }
239 pub fn IFEXITED(s: u32) bool {
240 return TERMSIG(s) == 0;
241 }
242 pub fn IFSTOPPED(s: u32) bool {
243 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
244 }
245 pub fn IFSIGNALED(s: u32) bool {
246 return (s & 0xffff) -% 1 < 0xff;
247 }
248};
249
250pub const SA = struct {
251 pub const ONSTACK = 0x0001;
252 pub const RESTART = 0x0002;
253 pub const RESETHAND = 0x0004;
254 pub const NODEFER = 0x0010;
255 pub const NOCLDWAIT = 0x0020;
256 pub const SIGINFO = 0x0040;
257};
258
259pub const PATH_MAX = 1024;
260pub const NAME_MAX = 255;
261pub const IOV_MAX = KERN.IOV_MAX;
262
263pub const ino_t = c_ulong;
264
265pub const Stat = extern struct {
266 ino: ino_t,
267 nlink: c_uint,
268 dev: c_uint,
269 mode: c_ushort,
270 padding1: u16,
271 uid: uid_t,
272 gid: gid_t,
273 rdev: c_uint,
274 atim: timespec,
275 mtim: timespec,
276 ctim: timespec,
277 size: c_ulong,
278 blocks: i64,
279 blksize: u32,
280 flags: u32,
281 gen: u32,
282 lspare: i32,
283 qspare1: i64,
284 qspare2: i64,
285 pub fn atime(self: @This()) timespec {
286 return self.atim;
287 }
288
289 pub fn mtime(self: @This()) timespec {
290 return self.mtim;
291 }
292
293 pub fn ctime(self: @This()) timespec {
294 return self.ctim;
295 }
296};
297
298pub const timespec = extern struct {
299 tv_sec: c_long,
300 tv_nsec: c_long,
301};
302
303pub const timeval = extern struct {
304 /// seconds
305 tv_sec: time_t,
306 /// microseconds
307 tv_usec: suseconds_t,
308};
309
310pub const CTL = struct {
311 pub const UNSPEC = 0;
312 pub const KERN = 1;
313 pub const VM = 2;
314 pub const VFS = 3;
315 pub const NET = 4;
316 pub const DEBUG = 5;
317 pub const HW = 6;
318 pub const MACHDEP = 7;
319 pub const USER = 8;
320 pub const LWKT = 10;
321 pub const MAXID = 11;
322 pub const MAXNAME = 12;
323};
324
325pub const KERN = struct {
326 pub const PROC_ALL = 0;
327 pub const OSTYPE = 1;
328 pub const PROC_PID = 1;
329 pub const OSRELEASE = 2;
330 pub const PROC_PGRP = 2;
331 pub const OSREV = 3;
332 pub const PROC_SESSION = 3;
333 pub const VERSION = 4;
334 pub const PROC_TTY = 4;
335 pub const MAXVNODES = 5;
336 pub const PROC_UID = 5;
337 pub const MAXPROC = 6;
338 pub const PROC_RUID = 6;
339 pub const MAXFILES = 7;
340 pub const PROC_ARGS = 7;
341 pub const ARGMAX = 8;
342 pub const PROC_CWD = 8;
343 pub const PROC_PATHNAME = 9;
344 pub const SECURELVL = 9;
345 pub const PROC_SIGTRAMP = 10;
346 pub const HOSTNAME = 10;
347 pub const HOSTID = 11;
348 pub const CLOCKRATE = 12;
349 pub const VNODE = 13;
350 pub const PROC = 14;
351 pub const FILE = 15;
352 pub const PROC_FLAGMASK = 16;
353 pub const PROF = 16;
354 pub const PROC_FLAG_LWP = 16;
355 pub const POSIX1 = 17;
356 pub const NGROUPS = 18;
357 pub const JOB_CONTROL = 19;
358 pub const SAVED_IDS = 20;
359 pub const BOOTTIME = 21;
360 pub const NISDOMAINNAME = 22;
361 pub const UPDATEINTERVAL = 23;
362 pub const OSRELDATE = 24;
363 pub const NTP_PLL = 25;
364 pub const BOOTFILE = 26;
365 pub const MAXFILESPERPROC = 27;
366 pub const MAXPROCPERUID = 28;
367 pub const DUMPDEV = 29;
368 pub const IPC = 30;
369 pub const DUMMY = 31;
370 pub const PS_STRINGS = 32;
371 pub const USRSTACK = 33;
372 pub const LOGSIGEXIT = 34;
373 pub const IOV_MAX = 35;
374 pub const MAXPOSIXLOCKSPERUID = 36;
375 pub const MAXID = 37;
376};
377
378pub const HOST_NAME_MAX = 255;
379
380// access function
381pub const F_OK = 0; // test for existence of file
382pub const X_OK = 1; // test for execute or search permission
383pub const W_OK = 2; // test for write permission
384pub const R_OK = 4; // test for read permission
385
386pub const SEEK = struct {
387 pub const SET = 0;
388 pub const CUR = 1;
389 pub const END = 2;
390 pub const DATA = 3;
391 pub const HOLE = 4;
392};
393
394pub const F = struct {
395 pub const ULOCK = 0;
396 pub const LOCK = 1;
397 pub const TLOCK = 2;
398 pub const TEST = 3;
399
400 pub const DUPFD = 0;
401 pub const GETFD = 1;
402 pub const RDLCK = 1;
403 pub const SETFD = 2;
404 pub const UNLCK = 2;
405 pub const WRLCK = 3;
406 pub const GETFL = 3;
407 pub const SETFL = 4;
408 pub const GETOWN = 5;
409 pub const SETOWN = 6;
410 pub const GETLK = 7;
411 pub const SETLK = 8;
412 pub const SETLKW = 9;
413 pub const DUP2FD = 10;
414 pub const DUPFD_CLOEXEC = 17;
415 pub const DUP2FD_CLOEXEC = 18;
416 pub const GETPATH = 19;
417};
418
419pub const FD_CLOEXEC = 1;
420
421pub const dirent = extern struct {
422 fileno: c_ulong,
423 namlen: u16,
424 type: u8,
425 unused1: u8,
426 unused2: u32,
427 name: [256]u8,
428
429 pub fn reclen(self: dirent) u16 {
430 return (@offsetOf(dirent, "name") + self.namlen + 1 + 7) & ~@as(u16, 7);
431 }
432};
433
434pub const DT = struct {
435 pub const UNKNOWN = 0;
436 pub const FIFO = 1;
437 pub const CHR = 2;
438 pub const DIR = 4;
439 pub const BLK = 6;
440 pub const REG = 8;
441 pub const LNK = 10;
442 pub const SOCK = 12;
443 pub const WHT = 14;
444 pub const DBF = 15;
445};
446
447pub const CLOCK = struct {
448 pub const REALTIME = 0;
449 pub const VIRTUAL = 1;
450 pub const PROF = 2;
451 pub const MONOTONIC = 4;
452 pub const UPTIME = 5;
453 pub const UPTIME_PRECISE = 7;
454 pub const UPTIME_FAST = 8;
455 pub const REALTIME_PRECISE = 9;
456 pub const REALTIME_FAST = 10;
457 pub const MONOTONIC_PRECISE = 11;
458 pub const MONOTONIC_FAST = 12;
459 pub const SECOND = 13;
460 pub const THREAD_CPUTIME_ID = 14;
461 pub const PROCESS_CPUTIME_ID = 15;
462};
463
464pub const sockaddr = extern struct {
465 len: u8,
466 family: sa_family_t,
467 data: [14]u8,
468
469 pub const SS_MAXSIZE = 128;
470 pub const storage = extern struct {
471 len: u8 align(8),
472 family: sa_family_t,
473 padding: [126]u8 = undefined,
474
475 comptime {
476 assert(@sizeOf(storage) == SS_MAXSIZE);
477 assert(@alignOf(storage) == 8);
478 }
479 };
480
481 pub const in = extern struct {
482 len: u8 = @sizeOf(in),
483 family: sa_family_t = AF.INET,
484 port: in_port_t,
485 addr: u32,
486 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
487 };
488
489 pub const in6 = extern struct {
490 len: u8 = @sizeOf(in6),
491 family: sa_family_t = AF.INET6,
492 port: in_port_t,
493 flowinfo: u32,
494 addr: [16]u8,
495 scope_id: u32,
496 };
497
498 pub const un = extern struct {
499 len: u8 = @sizeOf(un),
500 family: sa_family_t = AF.UNIX,
501 path: [104]u8,
502 };
503};
504
505pub const Kevent = extern struct {
506 ident: usize,
507 filter: c_short,
508 flags: c_ushort,
509 fflags: c_uint,
510 data: isize,
511 udata: usize,
512};
513
514pub const EVFILT_FS = -10;
515pub const EVFILT_USER = -9;
516pub const EVFILT_EXCEPT = -8;
517pub const EVFILT_TIMER = -7;
518pub const EVFILT_SIGNAL = -6;
519pub const EVFILT_PROC = -5;
520pub const EVFILT_VNODE = -4;
521pub const EVFILT_AIO = -3;
522pub const EVFILT_WRITE = -2;
523pub const EVFILT_READ = -1;
524pub const EVFILT_SYSCOUNT = 10;
525pub const EVFILT_MARKER = 15;
526
527pub const EV_ADD = 1;
528pub const EV_DELETE = 2;
529pub const EV_ENABLE = 4;
530pub const EV_DISABLE = 8;
531pub const EV_ONESHOT = 16;
532pub const EV_CLEAR = 32;
533pub const EV_RECEIPT = 64;
534pub const EV_DISPATCH = 128;
535pub const EV_NODATA = 4096;
536pub const EV_FLAG1 = 8192;
537pub const EV_ERROR = 16384;
538pub const EV_EOF = 32768;
539pub const EV_SYSFLAGS = 61440;
540
541pub const NOTE_FFNOP = 0;
542pub const NOTE_TRACK = 1;
543pub const NOTE_DELETE = 1;
544pub const NOTE_LOWAT = 1;
545pub const NOTE_TRACKERR = 2;
546pub const NOTE_OOB = 2;
547pub const NOTE_WRITE = 2;
548pub const NOTE_EXTEND = 4;
549pub const NOTE_CHILD = 4;
550pub const NOTE_ATTRIB = 8;
551pub const NOTE_LINK = 16;
552pub const NOTE_RENAME = 32;
553pub const NOTE_REVOKE = 64;
554pub const NOTE_PDATAMASK = 1048575;
555pub const NOTE_FFLAGSMASK = 16777215;
556pub const NOTE_TRIGGER = 16777216;
557pub const NOTE_EXEC = 536870912;
558pub const NOTE_FFAND = 1073741824;
559pub const NOTE_FORK = 1073741824;
560pub const NOTE_EXIT = 2147483648;
561pub const NOTE_FFOR = 2147483648;
562pub const NOTE_FFCTRLMASK = 3221225472;
563pub const NOTE_FFCOPY = 3221225472;
564pub const NOTE_PCTRLMASK = 4026531840;
565
566pub const TCSA = enum(c_uint) {
567 NOW,
568 DRAIN,
569 FLUSH,
570 _,
571};
572
573pub const stack_t = extern struct {
574 sp: [*]u8,
575 size: isize,
576 flags: i32,
577};
578
579pub const S = struct {
580 pub const IREAD = IRUSR;
581 pub const IEXEC = IXUSR;
582 pub const IWRITE = IWUSR;
583 pub const IXOTH = 1;
584 pub const IWOTH = 2;
585 pub const IROTH = 4;
586 pub const IRWXO = 7;
587 pub const IXGRP = 8;
588 pub const IWGRP = 16;
589 pub const IRGRP = 32;
590 pub const IRWXG = 56;
591 pub const IXUSR = 64;
592 pub const IWUSR = 128;
593 pub const IRUSR = 256;
594 pub const IRWXU = 448;
595 pub const ISTXT = 512;
596 pub const BLKSIZE = 512;
597 pub const ISVTX = 512;
598 pub const ISGID = 1024;
599 pub const ISUID = 2048;
600 pub const IFIFO = 4096;
601 pub const IFCHR = 8192;
602 pub const IFDIR = 16384;
603 pub const IFBLK = 24576;
604 pub const IFREG = 32768;
605 pub const IFDB = 36864;
606 pub const IFLNK = 40960;
607 pub const IFSOCK = 49152;
608 pub const IFWHT = 57344;
609 pub const IFMT = 61440;
610
611 pub fn ISCHR(m: u32) bool {
612 return m & IFMT == IFCHR;
613 }
614};
615
616157pub const BADSIG = SIG.ERR;
617158
618pub const SIG = struct {
619 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
620 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
621 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
622
623 pub const BLOCK = 1;
624 pub const UNBLOCK = 2;
625 pub const SETMASK = 3;
626
627 pub const IOT = ABRT;
628 pub const HUP = 1;
629 pub const INT = 2;
630 pub const QUIT = 3;
631 pub const ILL = 4;
632 pub const TRAP = 5;
633 pub const ABRT = 6;
634 pub const EMT = 7;
635 pub const FPE = 8;
636 pub const KILL = 9;
637 pub const BUS = 10;
638 pub const SEGV = 11;
639 pub const SYS = 12;
640 pub const PIPE = 13;
641 pub const ALRM = 14;
642 pub const TERM = 15;
643 pub const URG = 16;
644 pub const STOP = 17;
645 pub const TSTP = 18;
646 pub const CONT = 19;
647 pub const CHLD = 20;
648 pub const TTIN = 21;
649 pub const TTOU = 22;
650 pub const IO = 23;
651 pub const XCPU = 24;
652 pub const XFSZ = 25;
653 pub const VTALRM = 26;
654 pub const PROF = 27;
655 pub const WINCH = 28;
656 pub const INFO = 29;
657 pub const USR1 = 30;
658 pub const USR2 = 31;
659 pub const THR = 32;
660 pub const CKPT = 33;
661 pub const CKPTEXIT = 34;
662};
663
664pub const siginfo_t = extern struct {
665 signo: c_int,
666 errno: c_int,
667 code: c_int,
668 pid: c_int,
669 uid: uid_t,
670 status: c_int,
671 addr: *allowzero anyopaque,
672 value: sigval,
673 band: c_long,
674 __spare__: [7]c_int,
675};
676
677pub const sigval = extern union {
678 sival_int: c_int,
679 sival_ptr: ?*anyopaque,
680};
681
682pub const _SIG_WORDS = 4;
683
684pub const sigset_t = extern struct {
685 __bits: [_SIG_WORDS]c_uint,
686};
687
688pub const empty_sigset = sigset_t{ .__bits = [_]c_uint{0} ** _SIG_WORDS };
689
690pub const sig_atomic_t = c_int;
691
692pub const Sigaction = extern struct {
693 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
694 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
695
696 /// signal handler
697 handler: extern union {
698 handler: ?handler_fn,
699 sigaction: ?sigaction_fn,
700 },
701 flags: c_uint,
702 mask: sigset_t,
703};
704
705159pub const sig_t = *const fn (i32) callconv(.C) void;
706160
707pub const SOCK = struct {
708 pub const STREAM = 1;
709 pub const DGRAM = 2;
710 pub const RAW = 3;
711 pub const RDM = 4;
712 pub const SEQPACKET = 5;
713 pub const MAXADDRLEN = 255;
714 pub const CLOEXEC = 0x10000000;
715 pub const NONBLOCK = 0x20000000;
716};
717
718pub const SO = struct {
719 pub const DEBUG = 0x0001;
720 pub const ACCEPTCONN = 0x0002;
721 pub const REUSEADDR = 0x0004;
722 pub const KEEPALIVE = 0x0008;
723 pub const DONTROUTE = 0x0010;
724 pub const BROADCAST = 0x0020;
725 pub const USELOOPBACK = 0x0040;
726 pub const LINGER = 0x0080;
727 pub const OOBINLINE = 0x0100;
728 pub const REUSEPORT = 0x0200;
729 pub const TIMESTAMP = 0x0400;
730 pub const NOSIGPIPE = 0x0800;
731 pub const ACCEPTFILTER = 0x1000;
732 pub const RERROR = 0x2000;
733 pub const PASSCRED = 0x4000;
734
735 pub const SNDBUF = 0x1001;
736 pub const RCVBUF = 0x1002;
737 pub const SNDLOWAT = 0x1003;
738 pub const RCVLOWAT = 0x1004;
739 pub const SNDTIMEO = 0x1005;
740 pub const RCVTIMEO = 0x1006;
741 pub const ERROR = 0x1007;
742 pub const TYPE = 0x1008;
743 pub const SNDSPACE = 0x100a;
744 pub const CPUHINT = 0x1030;
745};
746
747pub const SOL = struct {
748 pub const SOCKET = 0xffff;
749};
750
751pub const PF = struct {
752 pub const INET6 = AF.INET6;
753 pub const IMPLINK = AF.IMPLINK;
754 pub const ROUTE = AF.ROUTE;
755 pub const ISO = AF.ISO;
756 pub const PIP = AF.pseudo_PIP;
757 pub const CHAOS = AF.CHAOS;
758 pub const DATAKIT = AF.DATAKIT;
759 pub const INET = AF.INET;
760 pub const APPLETALK = AF.APPLETALK;
761 pub const SIP = AF.SIP;
762 pub const OSI = AF.ISO;
763 pub const CNT = AF.CNT;
764 pub const LINK = AF.LINK;
765 pub const HYLINK = AF.HYLINK;
766 pub const MAX = AF.MAX;
767 pub const KEY = AF.pseudo_KEY;
768 pub const PUP = AF.PUP;
769 pub const COIP = AF.COIP;
770 pub const SNA = AF.SNA;
771 pub const LOCAL = AF.LOCAL;
772 pub const NETBIOS = AF.NETBIOS;
773 pub const NATM = AF.NATM;
774 pub const BLUETOOTH = AF.BLUETOOTH;
775 pub const UNSPEC = AF.UNSPEC;
776 pub const NETGRAPH = AF.NETGRAPH;
777 pub const ECMA = AF.ECMA;
778 pub const IPX = AF.IPX;
779 pub const DLI = AF.DLI;
780 pub const ATM = AF.ATM;
781 pub const CCITT = AF.CCITT;
782 pub const ISDN = AF.ISDN;
783 pub const RTIP = AF.pseudo_RTIP;
784 pub const LAT = AF.LAT;
785 pub const UNIX = PF.LOCAL;
786 pub const XTP = AF.pseudo_XTP;
787 pub const DECnet = AF.DECnet;
788};
789
790pub const AF = struct {
791 pub const UNSPEC = 0;
792 pub const OSI = ISO;
793 pub const UNIX = LOCAL;
794 pub const LOCAL = 1;
795 pub const INET = 2;
796 pub const IMPLINK = 3;
797 pub const PUP = 4;
798 pub const CHAOS = 5;
799 pub const NETBIOS = 6;
800 pub const ISO = 7;
801 pub const ECMA = 8;
802 pub const DATAKIT = 9;
803 pub const CCITT = 10;
804 pub const SNA = 11;
805 pub const DLI = 13;
806 pub const LAT = 14;
807 pub const HYLINK = 15;
808 pub const APPLETALK = 16;
809 pub const ROUTE = 17;
810 pub const LINK = 18;
811 pub const COIP = 20;
812 pub const CNT = 21;
813 pub const IPX = 23;
814 pub const SIP = 24;
815 pub const ISDN = 26;
816 pub const INET6 = 28;
817 pub const NATM = 29;
818 pub const ATM = 30;
819 pub const NETGRAPH = 32;
820 pub const BLUETOOTH = 33;
821 pub const MPLS = 34;
822 pub const MAX = 36;
823};
824
825pub const in_port_t = u16;
826pub const sa_family_t = u8;
827pub const socklen_t = u32;
828
829pub const EAI = enum(c_int) {
830 ADDRFAMILY = 1,
831 AGAIN = 2,
832 BADFLAGS = 3,
833 FAIL = 4,
834 FAMILY = 5,
835 MEMORY = 6,
836 NODATA = 7,
837 NONAME = 8,
838 SERVICE = 9,
839 SOCKTYPE = 10,
840 SYSTEM = 11,
841 BADHINTS = 12,
842 PROTOCOL = 13,
843 OVERFLOW = 14,
844 _,
845};
846
847pub const IFNAMESIZE = 16;
848
849pub const AI = struct {
850 pub const PASSIVE = 0x00000001;
851 pub const CANONNAME = 0x00000002;
852 pub const NUMERICHOST = 0x00000004;
853 pub const NUMERICSERV = 0x00000008;
854 pub const MASK = PASSIVE | CANONNAME | NUMERICHOST | NUMERICSERV | ADDRCONFIG;
855 pub const ALL = 0x00000100;
856 pub const V4MAPPED_CFG = 0x00000200;
857 pub const ADDRCONFIG = 0x00000400;
858 pub const V4MAPPED = 0x00000800;
859 pub const DEFAULT = V4MAPPED_CFG | ADDRCONFIG;
860};
861
862pub const RTLD = struct {
863 pub const LAZY = 1;
864 pub const NOW = 2;
865 pub const MODEMASK = 0x3;
866 pub const GLOBAL = 0x100;
867 pub const LOCAL = 0;
868 pub const TRACE = 0x200;
869 pub const NODELETE = 0x01000;
870 pub const NOLOAD = 0x02000;
871
872 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
873 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
874 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
875 pub const ALL = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
876};
877
878pub const dl_phdr_info = extern struct {
879 dlpi_addr: usize,
880 dlpi_name: ?[*:0]const u8,
881 dlpi_phdr: [*]std.elf.Phdr,
882 dlpi_phnum: u16,
883};
884161pub const cmsghdr = extern struct {
885 cmsg_len: socklen_t,
886 cmsg_level: c_int,
887 cmsg_type: c_int,
888};
889pub const msghdr = extern struct {
890 msg_name: ?*anyopaque,
891 msg_namelen: socklen_t,
892 msg_iov: [*]iovec,
893 msg_iovlen: c_int,
894 msg_control: ?*anyopaque,
895 msg_controllen: socklen_t,
896 msg_flags: c_int,
162 len: socklen_t,
163 level: c_int,
164 type: c_int,
897165};
166
898167pub const cmsgcred = extern struct {
899 cmcred_pid: pid_t,
900 cmcred_uid: uid_t,
901 cmcred_euid: uid_t,
902 cmcred_gid: gid_t,
903 cmcred_ngroups: c_short,
904 cmcred_groups: [16]gid_t,
168 pid: pid_t,
169 uid: uid_t,
170 euid: uid_t,
171 gid: gid_t,
172 ngroups: c_short,
173 groups: [16]gid_t,
905174};
906175pub const sf_hdtr = extern struct {
907176 headers: [*]iovec,
......@@ -919,226 +188,3 @@ pub const POSIX_MADV_RANDOM = 1;
919188pub const POSIX_MADV_DONTNEED = 4;
920189pub const POSIX_MADV_NORMAL = 0;
921190pub const POSIX_MADV_WILLNEED = 3;
922
923pub const MADV = struct {
924 pub const SEQUENTIAL = 2;
925 pub const CONTROL_END = SETMAP;
926 pub const DONTNEED = 4;
927 pub const RANDOM = 1;
928 pub const WILLNEED = 3;
929 pub const NORMAL = 0;
930 pub const CONTROL_START = INVAL;
931 pub const FREE = 5;
932 pub const NOSYNC = 6;
933 pub const AUTOSYNC = 7;
934 pub const NOCORE = 8;
935 pub const CORE = 9;
936 pub const INVAL = 10;
937 pub const SETMAP = 11;
938};
939
940pub const LOCK = struct {
941 pub const SH = 1;
942 pub const EX = 2;
943 pub const UN = 8;
944 pub const NB = 4;
945};
946
947pub const Flock = extern struct {
948 start: off_t,
949 len: off_t,
950 pid: pid_t,
951 type: c_short,
952 whence: c_short,
953};
954
955pub const addrinfo = extern struct {
956 flags: i32,
957 family: i32,
958 socktype: i32,
959 protocol: i32,
960 addrlen: socklen_t,
961 canonname: ?[*:0]u8,
962 addr: ?*sockaddr,
963 next: ?*addrinfo,
964};
965
966pub const IPPROTO = struct {
967 pub const IP = 0;
968 pub const ICMP = 1;
969 pub const TCP = 6;
970 pub const UDP = 17;
971 pub const IPV6 = 41;
972 pub const RAW = 255;
973 pub const HOPOPTS = 0;
974 pub const IGMP = 2;
975 pub const GGP = 3;
976 pub const IPV4 = 4;
977 pub const IPIP = IPV4;
978 pub const ST = 7;
979 pub const EGP = 8;
980 pub const PIGP = 9;
981 pub const RCCMON = 10;
982 pub const NVPII = 11;
983 pub const PUP = 12;
984 pub const ARGUS = 13;
985 pub const EMCON = 14;
986 pub const XNET = 15;
987 pub const CHAOS = 16;
988 pub const MUX = 18;
989 pub const MEAS = 19;
990 pub const HMP = 20;
991 pub const PRM = 21;
992 pub const IDP = 22;
993 pub const TRUNK1 = 23;
994 pub const TRUNK2 = 24;
995 pub const LEAF1 = 25;
996 pub const LEAF2 = 26;
997 pub const RDP = 27;
998 pub const IRTP = 28;
999 pub const TP = 29;
1000 pub const BLT = 30;
1001 pub const NSP = 31;
1002 pub const INP = 32;
1003 pub const SEP = 33;
1004 pub const @"3PC" = 34;
1005 pub const IDPR = 35;
1006 pub const XTP = 36;
1007 pub const DDP = 37;
1008 pub const CMTP = 38;
1009 pub const TPXX = 39;
1010 pub const IL = 40;
1011 pub const SDRP = 42;
1012 pub const ROUTING = 43;
1013 pub const FRAGMENT = 44;
1014 pub const IDRP = 45;
1015 pub const RSVP = 46;
1016 pub const GRE = 47;
1017 pub const MHRP = 48;
1018 pub const BHA = 49;
1019 pub const ESP = 50;
1020 pub const AH = 51;
1021 pub const INLSP = 52;
1022 pub const SWIPE = 53;
1023 pub const NHRP = 54;
1024 pub const MOBILE = 55;
1025 pub const TLSP = 56;
1026 pub const SKIP = 57;
1027 pub const ICMPV6 = 58;
1028 pub const NONE = 59;
1029 pub const DSTOPTS = 60;
1030 pub const AHIP = 61;
1031 pub const CFTP = 62;
1032 pub const HELLO = 63;
1033 pub const SATEXPAK = 64;
1034 pub const KRYPTOLAN = 65;
1035 pub const RVD = 66;
1036 pub const IPPC = 67;
1037 pub const ADFS = 68;
1038 pub const SATMON = 69;
1039 pub const VISA = 70;
1040 pub const IPCV = 71;
1041 pub const CPNX = 72;
1042 pub const CPHB = 73;
1043 pub const WSN = 74;
1044 pub const PVP = 75;
1045 pub const BRSATMON = 76;
1046 pub const ND = 77;
1047 pub const WBMON = 78;
1048 pub const WBEXPAK = 79;
1049 pub const EON = 80;
1050 pub const VMTP = 81;
1051 pub const SVMTP = 82;
1052 pub const VINES = 83;
1053 pub const TTP = 84;
1054 pub const IGP = 85;
1055 pub const DGP = 86;
1056 pub const TCF = 87;
1057 pub const IGRP = 88;
1058 pub const OSPFIGP = 89;
1059 pub const SRPC = 90;
1060 pub const LARP = 91;
1061 pub const MTP = 92;
1062 pub const AX25 = 93;
1063 pub const IPEIP = 94;
1064 pub const MICP = 95;
1065 pub const SCCSP = 96;
1066 pub const ETHERIP = 97;
1067 pub const ENCAP = 98;
1068 pub const APES = 99;
1069 pub const GMTP = 100;
1070 pub const IPCOMP = 108;
1071 pub const PIM = 103;
1072 pub const CARP = 112;
1073 pub const PGM = 113;
1074 pub const PFSYNC = 240;
1075 pub const DIVERT = 254;
1076 pub const MAX = 256;
1077 pub const DONE = 257;
1078 pub const UNKNOWN = 258;
1079};
1080
1081pub const rlimit_resource = enum(c_int) {
1082 CPU = 0,
1083 FSIZE = 1,
1084 DATA = 2,
1085 STACK = 3,
1086 CORE = 4,
1087 RSS = 5,
1088 MEMLOCK = 6,
1089 NPROC = 7,
1090 NOFILE = 8,
1091 SBSIZE = 9,
1092 VMEM = 10,
1093 POSIXLOCKS = 11,
1094 _,
1095
1096 pub const AS: rlimit_resource = .VMEM;
1097};
1098
1099pub const rlim_t = i64;
1100
1101pub const RLIM = struct {
1102 /// No limit
1103 pub const INFINITY: rlim_t = (1 << 63) - 1;
1104
1105 pub const SAVED_MAX = INFINITY;
1106 pub const SAVED_CUR = INFINITY;
1107};
1108
1109pub const rlimit = extern struct {
1110 /// Soft limit
1111 cur: rlim_t,
1112 /// Hard limit
1113 max: rlim_t,
1114};
1115
1116pub const SHUT = struct {
1117 pub const RD = 0;
1118 pub const WR = 1;
1119 pub const RDWR = 2;
1120};
1121
1122pub const nfds_t = u32;
1123
1124pub const pollfd = extern struct {
1125 fd: fd_t,
1126 events: i16,
1127 revents: i16,
1128};
1129
1130pub const POLL = struct {
1131 /// Requestable events.
1132 pub const IN = 0x0001;
1133 pub const PRI = 0x0002;
1134 pub const OUT = 0x0004;
1135 pub const RDNORM = 0x0040;
1136 pub const WRNORM = OUT;
1137 pub const RDBAND = 0x0080;
1138 pub const WRBAND = 0x0100;
1139
1140 /// These events are set if they occur regardless of whether they were requested.
1141 pub const ERR = 0x0008;
1142 pub const HUP = 0x0010;
1143 pub const NVAL = 0x0020;
1144};
lib/std/c/emscripten.zig deleted-180
......@@ -1,180 +0,0 @@
1const std = @import("../std.zig");
2const maxInt = std.math.maxInt;
3const emscripten = std.os.emscripten;
4
5pub const AF = emscripten.AF;
6pub const CLOCK = emscripten.CLOCK;
7pub const CPU_COUNT = emscripten.CPU_COUNT;
8pub const E = emscripten.E;
9pub const F = emscripten.F;
10pub const FD_CLOEXEC = emscripten.FD_CLOEXEC;
11pub const F_OK = emscripten.F_OK;
12pub const Flock = emscripten.Flock;
13pub const IFNAMESIZE = emscripten.IFNAMESIZE;
14pub const IOV_MAX = emscripten.IOV_MAX;
15pub const IPPROTO = emscripten.IPPROTO;
16pub const LOCK = emscripten.LOCK;
17pub const MADV = emscripten.MADV;
18pub const MSF = emscripten.MSF;
19pub const MSG = emscripten.MSG;
20pub const NAME_MAX = emscripten.NAME_MAX;
21pub const PATH_MAX = emscripten.PATH_MAX;
22pub const POLL = emscripten.POLL;
23pub const PROT = emscripten.PROT;
24pub const REG = emscripten.REG;
25pub const RLIM = emscripten.RLIM;
26pub const R_OK = emscripten.R_OK;
27pub const S = emscripten.S;
28pub const SA = emscripten.SA;
29pub const SEEK = emscripten.SEEK;
30pub const SHUT = emscripten.SHUT;
31pub const SIG = emscripten.SIG;
32pub const SIOCGIFINDEX = emscripten.SIOCGIFINDEX;
33pub const SO = emscripten.SO;
34pub const SOCK = emscripten.SOCK;
35pub const SOL = emscripten.SOL;
36pub const STDERR_FILENO = emscripten.STDERR_FILENO;
37pub const STDIN_FILENO = emscripten.STDIN_FILENO;
38pub const STDOUT_FILENO = emscripten.STDOUT_FILENO;
39pub const Sigaction = emscripten.Sigaction;
40pub const TCP = emscripten.TCP;
41pub const TCSA = emscripten.TCSA;
42pub const W = emscripten.W;
43pub const W_OK = emscripten.W_OK;
44pub const X_OK = emscripten.X_OK;
45pub const addrinfo = emscripten.addrinfo;
46pub const blkcnt_t = emscripten.blkcnt_t;
47pub const blksize_t = emscripten.blksize_t;
48pub const clock_t = emscripten.clock_t;
49pub const cpu_set_t = emscripten.cpu_set_t;
50pub const dev_t = emscripten.dev_t;
51pub const dl_phdr_info = emscripten.dl_phdr_info;
52pub const empty_sigset = emscripten.empty_sigset;
53pub const fd_t = emscripten.fd_t;
54pub const gid_t = emscripten.gid_t;
55pub const ifreq = emscripten.ifreq;
56pub const ino_t = emscripten.ino_t;
57pub const mcontext_t = emscripten.mcontext_t;
58pub const mode_t = emscripten.mode_t;
59pub const msghdr = emscripten.msghdr;
60pub const msghdr_const = emscripten.msghdr_const;
61pub const nfds_t = emscripten.nfds_t;
62pub const nlink_t = emscripten.nlink_t;
63pub const off_t = emscripten.off_t;
64pub const pid_t = emscripten.pid_t;
65pub const pollfd = emscripten.pollfd;
66pub const rlim_t = emscripten.rlim_t;
67pub const rlimit = emscripten.rlimit;
68pub const rlimit_resource = emscripten.rlimit_resource;
69pub const rusage = emscripten.rusage;
70pub const siginfo_t = emscripten.siginfo_t;
71pub const sigset_t = emscripten.sigset_t;
72pub const sockaddr = emscripten.sockaddr;
73pub const socklen_t = emscripten.socklen_t;
74pub const stack_t = emscripten.stack_t;
75pub const time_t = emscripten.time_t;
76pub const timespec = emscripten.timespec;
77pub const timeval = emscripten.timeval;
78pub const timezone = emscripten.timezone;
79pub const ucontext_t = emscripten.ucontext_t;
80pub const uid_t = emscripten.uid_t;
81pub const utsname = emscripten.utsname;
82
83pub const _errno = struct {
84 extern "c" fn __errno_location() *c_int;
85}.__errno_location;
86
87pub const Stat = emscripten.Stat;
88
89pub const AI = struct {
90 pub const PASSIVE = 0x01;
91 pub const CANONNAME = 0x02;
92 pub const NUMERICHOST = 0x04;
93 pub const V4MAPPED = 0x08;
94 pub const ALL = 0x10;
95 pub const ADDRCONFIG = 0x20;
96 pub const NUMERICSERV = 0x400;
97};
98
99pub const NI = struct {
100 pub const NUMERICHOST = 0x01;
101 pub const NUMERICSERV = 0x02;
102 pub const NOFQDN = 0x04;
103 pub const NAMEREQD = 0x08;
104 pub const DGRAM = 0x10;
105 pub const NUMERICSCOPE = 0x100;
106 pub const MAXHOST = 255;
107 pub const MAXSERV = 32;
108};
109
110pub const EAI = enum(c_int) {
111 BADFLAGS = -1,
112 NONAME = -2,
113 AGAIN = -3,
114 FAIL = -4,
115 FAMILY = -6,
116 SOCKTYPE = -7,
117 SERVICE = -8,
118 MEMORY = -10,
119 SYSTEM = -11,
120 OVERFLOW = -12,
121
122 NODATA = -5,
123 ADDRFAMILY = -9,
124 INPROGRESS = -100,
125 CANCELED = -101,
126 NOTCANCELED = -102,
127 ALLDONE = -103,
128 INTR = -104,
129 IDN_ENCODE = -105,
130
131 _,
132};
133
134pub const fopen64 = std.c.fopen;
135pub const fstat64 = std.c.fstat;
136pub const fstatat64 = std.c.fstatat;
137pub const ftruncate64 = std.c.ftruncate;
138pub const getrlimit64 = std.c.getrlimit;
139pub const lseek64 = std.c.lseek;
140pub const mmap64 = std.c.mmap;
141pub const open64 = std.c.open;
142pub const openat64 = std.c.openat;
143pub const pread64 = std.c.pread;
144pub const preadv64 = std.c.preadv;
145pub const pwrite64 = std.c.pwrite;
146pub const pwritev64 = std.c.pwritev;
147pub const setrlimit64 = std.c.setrlimit;
148
149pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
150pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
151pub extern "c" fn getentropy(buffer: [*]u8, size: usize) c_int;
152
153pub const pthread_attr_t = extern struct {
154 __size: [56]u8,
155 __align: c_long,
156};
157
158pub const pthread_key_t = c_uint;
159pub const sem_t = extern struct {
160 __size: [__SIZEOF_SEM_T]u8 align(@alignOf(usize)),
161};
162
163const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
164
165pub const RTLD = struct {
166 pub const LAZY = 1;
167 pub const NOW = 2;
168 pub const NOLOAD = 4;
169 pub const NODELETE = 4096;
170 pub const GLOBAL = 256;
171 pub const LOCAL = 0;
172};
173
174pub const dirent = extern struct {
175 ino: c_uint,
176 off: c_uint,
177 reclen: c_ushort,
178 type: u8,
179 name: [256]u8,
180};
lib/std/c/freebsd.zig+35-1516
......@@ -1,36 +1,33 @@
1const builtin = @import("builtin");
12const std = @import("../std.zig");
23const assert = std.debug.assert;
3const builtin = @import("builtin");
4const maxInt = std.math.maxInt;
5const iovec = std.posix.iovec;
6const iovec_const = std.posix.iovec_const;
7
8extern "c" fn __error() *c_int;
9pub const _errno = __error;
10
11pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize;
12pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
13pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
144
15pub extern "c" fn pthread_getthreadid_np() c_int;
16pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
17pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
18pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
19pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
20
21pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
22pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
5const PATH_MAX = std.c.PATH_MAX;
6const blkcnt_t = std.c.blkcnt_t;
7const blksize_t = std.c.blksize_t;
8const dev_t = std.c.dev_t;
9const fd_t = std.c.fd_t;
10const gid_t = std.c.gid_t;
11const ino_t = std.c.ino_t;
12const iovec_const = std.posix.iovec_const;
13const mode_t = std.c.mode_t;
14const nlink_t = std.c.nlink_t;
15const off_t = std.c.off_t;
16const pid_t = std.c.pid_t;
17const sockaddr = std.c.sockaddr;
18const time_t = std.c.time_t;
19const timespec = std.c.timespec;
20const uid_t = std.c.uid_t;
21const sf_hdtr = std.c.sf_hdtr;
22const clockid_t = std.c.clockid_t;
2323
24pub extern "c" fn getpid() pid_t;
24comptime {
25 assert(builtin.os.tag == .freebsd or builtin.os.tag == .kfreebsd); // Prevent access of std.c symbols on wrong OS.
26}
2527
2628pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file;
29pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize;
2730
28pub const sf_hdtr = extern struct {
29 headers: [*]const iovec_const,
30 hdr_cnt: c_int,
31 trailers: [*]const iovec_const,
32 trl_cnt: c_int,
33};
3431pub extern "c" fn sendfile(
3532 in_fd: fd_t,
3633 out_fd: fd_t,
......@@ -41,23 +38,6 @@ pub extern "c" fn sendfile(
4138 flags: u32,
4239) c_int;
4340
44pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
45pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
46
47pub const pthread_attr_t = extern struct {
48 inner: ?*anyopaque = null,
49};
50
51pub const sem_t = extern struct {
52 _magic: u32,
53 _kern: extern struct {
54 _count: u32,
55 _flags: u32,
56 },
57 _padding: u32,
58};
59
60// https://github.com/freebsd/freebsd-src/blob/main/sys/sys/umtx.h
6141pub const UMTX_OP = enum(c_int) {
6242 LOCK = 0,
6343 UNLOCK = 1,
......@@ -90,213 +70,14 @@ pub const UMTX_OP = enum(c_int) {
9070
9171pub const UMTX_ABSTIME = 0x01;
9272pub const _umtx_time = extern struct {
93 _timeout: timespec,
94 _flags: u32,
95 _clockid: u32,
73 timeout: timespec,
74 flags: u32,
75 clockid: clockid_t,
9676};
9777
9878pub extern "c" fn _umtx_op(obj: usize, op: c_int, val: c_ulong, uaddr: usize, uaddr2: usize) c_int;
9979
100pub const EAI = enum(c_int) {
101 /// address family for hostname not supported
102 ADDRFAMILY = 1,
103
104 /// name could not be resolved at this time
105 AGAIN = 2,
106
107 /// flags parameter had an invalid value
108 BADFLAGS = 3,
109
110 /// non-recoverable failure in name resolution
111 FAIL = 4,
112
113 /// address family not recognized
114 FAMILY = 5,
115
116 /// memory allocation failure
117 MEMORY = 6,
118
119 /// no address associated with hostname
120 NODATA = 7,
121
122 /// name does not resolve
123 NONAME = 8,
124
125 /// service not recognized for socket type
126 SERVICE = 9,
127
128 /// intended socket type was not recognized
129 SOCKTYPE = 10,
130
131 /// system error returned in errno
132 SYSTEM = 11,
133
134 /// invalid value for hints
135 BADHINTS = 12,
136
137 /// resolved protocol is unknown
138 PROTOCOL = 13,
139
140 /// argument buffer overflow
141 OVERFLOW = 14,
142
143 _,
144};
145
146pub const EAI_MAX = 15;
147
148pub const IFNAMESIZE = 16;
149
150pub const AI = struct {
151 /// get address to use bind()
152 pub const PASSIVE = 0x00000001;
153 /// fill ai_canonname
154 pub const CANONNAME = 0x00000002;
155 /// prevent host name resolution
156 pub const NUMERICHOST = 0x00000004;
157 /// prevent service name resolution
158 pub const NUMERICSERV = 0x00000008;
159 /// valid flags for addrinfo (not a standard def, apps should not use it)
160 pub const MASK = (PASSIVE | CANONNAME | NUMERICHOST | NUMERICSERV | ADDRCONFIG | ALL | V4MAPPED);
161 /// IPv6 and IPv4-mapped (with V4MAPPED)
162 pub const ALL = 0x00000100;
163 /// accept IPv4-mapped if kernel supports
164 pub const V4MAPPED_CFG = 0x00000200;
165 /// only if any address is assigned
166 pub const ADDRCONFIG = 0x00000400;
167 /// accept IPv4-mapped IPv6 address
168 pub const V4MAPPED = 0x00000800;
169 /// special recommended flags for getipnodebyname
170 pub const DEFAULT = (V4MAPPED_CFG | ADDRCONFIG);
171};
172
173pub const blksize_t = i32;
174pub const blkcnt_t = i64;
175pub const clockid_t = i32;
17680pub const fflags_t = u32;
177pub const fsblkcnt_t = u64;
178pub const fsfilcnt_t = u64;
179pub const nlink_t = u64;
180pub const fd_t = i32;
181pub const pid_t = i32;
182pub const uid_t = u32;
183pub const gid_t = u32;
184pub const mode_t = u16;
185pub const off_t = i64;
186pub const ino_t = u64;
187pub const dev_t = u64;
188pub const time_t = i64;
189// The signedness is not constant across different architectures.
190pub const clock_t = isize;
191
192pub const socklen_t = u32;
193pub const suseconds_t = c_long;
194
195/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
196pub const Kevent = extern struct {
197 /// Identifier for this event.
198 ident: usize,
199 /// Filter for event.
200 filter: i16,
201 /// Action flags for kqueue.
202 flags: u16,
203 /// Filter flag value.
204 fflags: u32,
205 /// Filter data value.
206 data: i64,
207 /// Opaque user data identifier.
208 udata: usize,
209 /// Future extensions.
210 _ext: [4]u64 = [_]u64{0} ** 4,
211};
212
213// Modes and flags for dlopen()
214// include/dlfcn.h
215
216pub const RTLD = struct {
217 /// Bind function calls lazily.
218 pub const LAZY = 1;
219 /// Bind function calls immediately.
220 pub const NOW = 2;
221 pub const MODEMASK = 0x3;
222 /// Make symbols globally available.
223 pub const GLOBAL = 0x100;
224 /// Opposite of GLOBAL, and the default.
225 pub const LOCAL = 0;
226 /// Trace loaded objects and exit.
227 pub const TRACE = 0x200;
228 /// Do not remove members.
229 pub const NODELETE = 0x01000;
230 /// Do not load if not already loaded.
231 pub const NOLOAD = 0x02000;
232};
233
234pub const dl_phdr_info = extern struct {
235 /// Module relocation base.
236 dlpi_addr: if (builtin.target.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,
237 /// Module name.
238 dlpi_name: ?[*:0]const u8,
239 /// Pointer to module's phdr.
240 dlpi_phdr: [*]std.elf.Phdr,
241 /// Number of entries in phdr.
242 dlpi_phnum: u16,
243 /// Total number of loads.
244 dlpi_adds: u64,
245 /// Total number of unloads.
246 dlpi_subs: u64,
247 dlpi_tls_modid: usize,
248 dlpi_tls_data: ?*anyopaque,
249};
250
251pub const Flock = extern struct {
252 /// Starting offset.
253 start: off_t,
254 /// Number of consecutive bytes to be locked.
255 /// A value of 0 means to the end of the file.
256 len: off_t,
257 /// Lock owner.
258 pid: pid_t,
259 /// Lock type.
260 type: i16,
261 /// Type of the start member.
262 whence: i16,
263 /// Remote system id or zero for local.
264 sysid: i32,
265};
266
267pub const msghdr = extern struct {
268 /// Optional address.
269 msg_name: ?*sockaddr,
270 /// Size of address.
271 msg_namelen: socklen_t,
272 /// Scatter/gather array.
273 msg_iov: [*]iovec,
274 /// Number of elements in msg_iov.
275 msg_iovlen: i32,
276 /// Ancillary data.
277 msg_control: ?*anyopaque,
278 /// Ancillary data buffer length.
279 msg_controllen: socklen_t,
280 /// Flags on received message.
281 msg_flags: i32,
282};
283
284pub const msghdr_const = extern struct {
285 /// Optional address.
286 msg_name: ?*const sockaddr,
287 /// Size of address.
288 msg_namelen: socklen_t,
289 /// Scatter/gather array.
290 msg_iov: [*]iovec_const,
291 /// Number of elements in msg_iov.
292 msg_iovlen: i32,
293 /// Ancillary data.
294 msg_control: ?*anyopaque,
295 /// Ancillary data buffer length.
296 msg_controllen: socklen_t,
297 /// Flags on received message.
298 msg_flags: i32,
299};
30081
30182pub const Stat = extern struct {
30283 /// The inode's device.
......@@ -352,81 +133,8 @@ pub const Stat = extern struct {
352133 }
353134};
354135
355pub const timespec = extern struct {
356 tv_sec: isize,
357 tv_nsec: isize,
358};
359
360pub const timeval = extern struct {
361 /// seconds
362 tv_sec: time_t,
363 /// microseconds
364 tv_usec: suseconds_t,
365};
366
367pub const dirent = extern struct {
368 /// File number of entry.
369 fileno: ino_t,
370 /// Directory offset of entry.
371 off: off_t,
372 /// Length of this record.
373 reclen: u16,
374 /// File type, one of DT_.
375 type: u8,
376 pad0: u8 = 0,
377 /// Length of the name member.
378 namlen: u16,
379 pad1: u16 = 0,
380 /// Name of entry.
381 name: [255:0]u8,
382};
383
384pub const in_port_t = u16;
385pub const sa_family_t = u8;
386
387pub const sockaddr = extern struct {
388 /// total length
389 len: u8,
390 /// address family
391 family: sa_family_t,
392 /// actually longer; address value
393 data: [14]u8,
394
395 pub const SS_MAXSIZE = 128;
396 pub const storage = extern struct {
397 len: u8 align(8),
398 family: sa_family_t,
399 padding: [126]u8 = undefined,
400
401 comptime {
402 assert(@sizeOf(storage) == SS_MAXSIZE);
403 assert(@alignOf(storage) == 8);
404 }
405 };
406
407 pub const in = extern struct {
408 len: u8 = @sizeOf(in),
409 family: sa_family_t = AF.INET,
410 port: in_port_t,
411 addr: u32,
412 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
413 };
414
415 pub const in6 = extern struct {
416 len: u8 = @sizeOf(in6),
417 family: sa_family_t = AF.INET6,
418 port: in_port_t,
419 flowinfo: u32,
420 addr: [16]u8,
421 scope_id: u32,
422 };
423
424 pub const un = extern struct {
425 len: u8 = @sizeOf(un),
426 family: sa_family_t = AF.UNIX,
427 path: [104]u8,
428 };
429};
136pub const fsblkcnt_t = u64;
137pub const fsfilcnt_t = u64;
430138
431139pub const CAP_RIGHTS_VERSION = 0;
432140
......@@ -540,788 +248,18 @@ pub const kinfo_file = extern struct {
540248 _cap_spare: u64,
541249 /// Path to file, if any.
542250 path: [PATH_MAX - 1:0]u8,
543};
544
545pub const KINFO_FILE_SIZE = 1392;
546251
547comptime {
548 std.debug.assert(@sizeOf(kinfo_file) == KINFO_FILE_SIZE);
549 std.debug.assert(@alignOf(kinfo_file) == @sizeOf(u64));
550}
551
552pub const CTL = struct {
553 pub const KERN = 1;
554 pub const DEBUG = 5;
555};
556
557pub const KERN = struct {
558 pub const PROC = 14; // struct: process entries
559 pub const PROC_PATHNAME = 12; // path to executable
560 pub const PROC_FILEDESC = 33; // file descriptors for process
561 pub const IOV_MAX = 35;
562};
563
564pub const PATH_MAX = 1024;
565pub const IOV_MAX = KERN.IOV_MAX;
566
567pub const STDIN_FILENO = 0;
568pub const STDOUT_FILENO = 1;
569pub const STDERR_FILENO = 2;
570
571pub const PROT = struct {
572 pub const NONE = 0;
573 pub const READ = 1;
574 pub const WRITE = 2;
575 pub const EXEC = 4;
576};
577
578pub const CLOCK = struct {
579 pub const REALTIME = 0;
580 pub const VIRTUAL = 1;
581 pub const PROF = 2;
582 pub const MONOTONIC = 4;
583 pub const UPTIME = 5;
584 pub const UPTIME_PRECISE = 7;
585 pub const UPTIME_FAST = 8;
586 pub const REALTIME_PRECISE = 9;
587 pub const REALTIME_FAST = 10;
588 pub const MONOTONIC_PRECISE = 11;
589 pub const MONOTONIC_FAST = 12;
590 pub const SECOND = 13;
591 pub const THREAD_CPUTIME_ID = 14;
592 pub const PROCESS_CPUTIME_ID = 15;
593};
594
595pub const MADV = struct {
596 pub const NORMAL = 0;
597 pub const RANDOM = 1;
598 pub const SEQUENTIAL = 2;
599 pub const WILLNEED = 3;
600 pub const DONTNEED = 4;
601 pub const FREE = 5;
602 pub const NOSYNC = 6;
603 pub const AUTOSYNC = 7;
604 pub const NOCORE = 8;
605 pub const CORE = 9;
606 pub const PROTECT = 10;
607};
608
609pub const MSF = struct {
610 pub const ASYNC = 1;
611 pub const INVALIDATE = 2;
612 pub const SYNC = 4;
613};
614
615pub const W = struct {
616 pub const NOHANG = 1;
617 pub const UNTRACED = 2;
618 pub const STOPPED = UNTRACED;
619 pub const CONTINUED = 4;
620 pub const NOWAIT = 8;
621 pub const EXITED = 16;
622 pub const TRAPPED = 32;
623
624 pub fn EXITSTATUS(s: u32) u8 {
625 return @as(u8, @intCast((s & 0xff00) >> 8));
626 }
627 pub fn TERMSIG(s: u32) u32 {
628 return s & 0x7f;
629 }
630 pub fn STOPSIG(s: u32) u32 {
631 return EXITSTATUS(s);
632 }
633 pub fn IFEXITED(s: u32) bool {
634 return TERMSIG(s) == 0;
635 }
636 pub fn IFSTOPPED(s: u32) bool {
637 return @as(u16, @truncate((((s & 0xffff) *% 0x10001) >> 8))) > 0x7f00;
638 }
639 pub fn IFSIGNALED(s: u32) bool {
640 return (s & 0xffff) -% 1 < 0xff;
641 }
642};
643
644pub const SA = struct {
645 pub const ONSTACK = 0x0001;
646 pub const RESTART = 0x0002;
647 pub const RESETHAND = 0x0004;
648 pub const NOCLDSTOP = 0x0008;
649 pub const NODEFER = 0x0010;
650 pub const NOCLDWAIT = 0x0020;
651 pub const SIGINFO = 0x0040;
652};
653
654pub const SIG = struct {
655 pub const HUP = 1;
656 pub const INT = 2;
657 pub const QUIT = 3;
658 pub const ILL = 4;
659 pub const TRAP = 5;
660 pub const ABRT = 6;
661 pub const IOT = ABRT;
662 pub const EMT = 7;
663 pub const FPE = 8;
664 pub const KILL = 9;
665 pub const BUS = 10;
666 pub const SEGV = 11;
667 pub const SYS = 12;
668 pub const PIPE = 13;
669 pub const ALRM = 14;
670 pub const TERM = 15;
671 pub const URG = 16;
672 pub const STOP = 17;
673 pub const TSTP = 18;
674 pub const CONT = 19;
675 pub const CHLD = 20;
676 pub const TTIN = 21;
677 pub const TTOU = 22;
678 pub const IO = 23;
679 pub const XCPU = 24;
680 pub const XFSZ = 25;
681 pub const VTALRM = 26;
682 pub const PROF = 27;
683 pub const WINCH = 28;
684 pub const INFO = 29;
685 pub const USR1 = 30;
686 pub const USR2 = 31;
687 pub const THR = 32;
688 pub const LWP = THR;
689 pub const LIBRT = 33;
690
691 pub const RTMIN = 65;
692 pub const RTMAX = 126;
693
694 pub const BLOCK = 1;
695 pub const UNBLOCK = 2;
696 pub const SETMASK = 3;
697
698 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
699 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
700 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
701
702 pub const WORDS = 4;
703 pub const MAXSIG = 128;
704
705 pub inline fn IDX(sig: usize) usize {
706 return sig - 1;
707 }
708 pub inline fn WORD(sig: usize) usize {
709 return IDX(sig) >> 5;
710 }
711 pub inline fn BIT(sig: usize) usize {
712 return 1 << (IDX(sig) & 31);
713 }
714 pub inline fn VALID(sig: usize) usize {
715 return sig <= MAXSIG and sig > 0;
252 comptime {
253 assert(@sizeOf(@This()) == KINFO_FILE_SIZE);
254 assert(@alignOf(@This()) == @sizeOf(u64));
716255 }
717256};
718pub const sigval = extern union {
719 int: c_int,
720 ptr: ?*anyopaque,
721};
722
723pub const sigset_t = extern struct {
724 __bits: [SIG.WORDS]u32,
725};
726
727pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
728
729// access function
730pub const F_OK = 0; // test for existence of file
731pub const X_OK = 1; // test for execute or search permission
732pub const W_OK = 2; // test for write permission
733pub const R_OK = 4; // test for read permission
734
735/// Command flags for fcntl(2).
736pub const F = struct {
737 /// Duplicate file descriptor.
738 pub const DUPFD = 0;
739 /// Get file descriptor flags.
740 pub const GETFD = 1;
741 /// Set file descriptor flags.
742 pub const SETFD = 2;
743 /// Get file status flags.
744 pub const GETFL = 3;
745 /// Set file status flags.
746 pub const SETFL = 4;
747
748 /// Get SIGIO/SIGURG proc/pgrrp.
749 pub const GETOWN = 5;
750 /// Set SIGIO/SIGURG proc/pgrrp.
751 pub const SETOWN = 6;
752
753 /// Get record locking information.
754 pub const GETLK = 11;
755 /// Set record locking information.
756 pub const SETLK = 12;
757 /// Set record locking information and wait if blocked.
758 pub const SETLKW = 13;
759
760 /// Debugging support for remote locks.
761 pub const SETLK_REMOTE = 14;
762 /// Read ahead.
763 pub const READAHEAD = 15;
764
765 /// DUPFD with FD_CLOEXEC set.
766 pub const DUPFD_CLOEXEC = 17;
767 /// DUP2FD with FD_CLOEXEC set.
768 pub const DUP2FD_CLOEXEC = 18;
769
770 pub const ADD_SEALS = 19;
771 pub const GET_SEALS = 20;
772 /// Return `kinfo_file` for a file descriptor.
773 pub const KINFO = 22;
774
775 // Seals (ADD_SEALS, GET_SEALS)
776 /// Prevent adding sealings.
777 pub const SEAL_SEAL = 0x0001;
778 /// May not shrink
779 pub const SEAL_SHRINK = 0x0002;
780 /// May not grow.
781 pub const SEAL_GROW = 0x0004;
782 /// May not write.
783 pub const SEAL_WRITE = 0x0008;
784
785 // Record locking flags (GETLK, SETLK, SETLKW).
786 /// Shared or read lock.
787 pub const RDLCK = 1;
788 /// Unlock.
789 pub const UNLCK = 2;
790 /// Exclusive or write lock.
791 pub const WRLCK = 3;
792 /// Purge locks for a given system ID.
793 pub const UNLCKSYS = 4;
794 /// Cancel an async lock request.
795 pub const CANCEL = 5;
796
797 pub const SETOWN_EX = 15;
798 pub const GETOWN_EX = 16;
799
800 pub const GETOWNER_UIDS = 17;
801};
802
803pub const LOCK = struct {
804 pub const SH = 1;
805 pub const EX = 2;
806 pub const UN = 8;
807 pub const NB = 4;
808};
809
810pub const FD_CLOEXEC = 1;
811
812pub const SEEK = struct {
813 pub const SET = 0;
814 pub const CUR = 1;
815 pub const END = 2;
816};
817
818pub const SOCK = struct {
819 pub const STREAM = 1;
820 pub const DGRAM = 2;
821 pub const RAW = 3;
822 pub const RDM = 4;
823 pub const SEQPACKET = 5;
824
825 pub const CLOEXEC = 0x10000000;
826 pub const NONBLOCK = 0x20000000;
827};
828
829pub const SO = struct {
830 pub const DEBUG = 0x00000001;
831 pub const ACCEPTCONN = 0x00000002;
832 pub const REUSEADDR = 0x00000004;
833 pub const KEEPALIVE = 0x00000008;
834 pub const DONTROUTE = 0x00000010;
835 pub const BROADCAST = 0x00000020;
836 pub const USELOOPBACK = 0x00000040;
837 pub const LINGER = 0x00000080;
838 pub const OOBINLINE = 0x00000100;
839 pub const REUSEPORT = 0x00000200;
840 pub const TIMESTAMP = 0x00000400;
841 pub const NOSIGPIPE = 0x00000800;
842 pub const ACCEPTFILTER = 0x00001000;
843 pub const BINTIME = 0x00002000;
844 pub const NO_OFFLOAD = 0x00004000;
845 pub const NO_DDP = 0x00008000;
846 pub const REUSEPORT_LB = 0x00010000;
847
848 pub const SNDBUF = 0x1001;
849 pub const RCVBUF = 0x1002;
850 pub const SNDLOWAT = 0x1003;
851 pub const RCVLOWAT = 0x1004;
852 pub const SNDTIMEO = 0x1005;
853 pub const RCVTIMEO = 0x1006;
854 pub const ERROR = 0x1007;
855 pub const TYPE = 0x1008;
856 pub const LABEL = 0x1009;
857 pub const PEERLABEL = 0x1010;
858 pub const LISTENQLIMIT = 0x1011;
859 pub const LISTENQLEN = 0x1012;
860 pub const LISTENINCQLEN = 0x1013;
861 pub const SETFIB = 0x1014;
862 pub const USER_COOKIE = 0x1015;
863 pub const PROTOCOL = 0x1016;
864 pub const PROTOTYPE = PROTOCOL;
865 pub const TS_CLOCK = 0x1017;
866 pub const MAX_PACING_RATE = 0x1018;
867 pub const DOMAIN = 0x1019;
868};
869
870pub const SOL = struct {
871 pub const SOCKET = 0xffff;
872};
873
874pub const PF = struct {
875 pub const UNSPEC = AF.UNSPEC;
876 pub const LOCAL = AF.LOCAL;
877 pub const UNIX = PF.LOCAL;
878 pub const INET = AF.INET;
879 pub const IMPLINK = AF.IMPLINK;
880 pub const PUP = AF.PUP;
881 pub const CHAOS = AF.CHAOS;
882 pub const NETBIOS = AF.NETBIOS;
883 pub const ISO = AF.ISO;
884 pub const OSI = AF.ISO;
885 pub const ECMA = AF.ECMA;
886 pub const DATAKIT = AF.DATAKIT;
887 pub const CCITT = AF.CCITT;
888 pub const DECnet = AF.DECnet;
889 pub const DLI = AF.DLI;
890 pub const LAT = AF.LAT;
891 pub const HYLINK = AF.HYLINK;
892 pub const APPLETALK = AF.APPLETALK;
893 pub const ROUTE = AF.ROUTE;
894 pub const LINK = AF.LINK;
895 pub const XTP = AF.pseudo_XTP;
896 pub const COIP = AF.COIP;
897 pub const CNT = AF.CNT;
898 pub const SIP = AF.SIP;
899 pub const IPX = AF.IPX;
900 pub const RTIP = AF.pseudo_RTIP;
901 pub const PIP = AF.pseudo_PIP;
902 pub const ISDN = AF.ISDN;
903 pub const KEY = AF.pseudo_KEY;
904 pub const INET6 = AF.pseudo_INET6;
905 pub const NATM = AF.NATM;
906 pub const ATM = AF.ATM;
907 pub const NETGRAPH = AF.NETGRAPH;
908 pub const SLOW = AF.SLOW;
909 pub const SCLUSTER = AF.SCLUSTER;
910 pub const ARP = AF.ARP;
911 pub const BLUETOOTH = AF.BLUETOOTH;
912 pub const IEEE80211 = AF.IEEE80211;
913 pub const INET_SDP = AF.INET_SDP;
914 pub const INET6_SDP = AF.INET6_SDP;
915 pub const MAX = AF.MAX;
916};
917
918pub const AF = struct {
919 pub const UNSPEC = 0;
920 pub const UNIX = 1;
921 pub const LOCAL = UNIX;
922 pub const FILE = LOCAL;
923 pub const INET = 2;
924 pub const IMPLINK = 3;
925 pub const PUP = 4;
926 pub const CHAOS = 5;
927 pub const NETBIOS = 6;
928 pub const ISO = 7;
929 pub const OSI = ISO;
930 pub const ECMA = 8;
931 pub const DATAKIT = 9;
932 pub const CCITT = 10;
933 pub const SNA = 11;
934 pub const DECnet = 12;
935 pub const DLI = 13;
936 pub const LAT = 14;
937 pub const HYLINK = 15;
938 pub const APPLETALK = 16;
939 pub const ROUTE = 17;
940 pub const LINK = 18;
941 pub const pseudo_XTP = 19;
942 pub const COIP = 20;
943 pub const CNT = 21;
944 pub const pseudo_RTIP = 22;
945 pub const IPX = 23;
946 pub const SIP = 24;
947 pub const pseudo_PIP = 25;
948 pub const ISDN = 26;
949 pub const E164 = ISDN;
950 pub const pseudo_KEY = 27;
951 pub const INET6 = 28;
952 pub const NATM = 29;
953 pub const ATM = 30;
954 pub const pseudo_HDRCMPLT = 31;
955 pub const NETGRAPH = 32;
956 pub const SLOW = 33;
957 pub const SCLUSTER = 34;
958 pub const ARP = 35;
959 pub const BLUETOOTH = 36;
960 pub const IEEE80211 = 37;
961 pub const INET_SDP = 40;
962 pub const INET6_SDP = 42;
963 pub const MAX = 42;
964};
965
966pub const DT = struct {
967 pub const UNKNOWN = 0;
968 pub const FIFO = 1;
969 pub const CHR = 2;
970 pub const DIR = 4;
971 pub const BLK = 6;
972 pub const REG = 8;
973 pub const LNK = 10;
974 pub const SOCK = 12;
975 pub const WHT = 14;
976};
977
978/// add event to kq (implies enable)
979pub const EV_ADD = 0x0001;
980257
981/// delete event from kq
982pub const EV_DELETE = 0x0002;
983
984/// enable event
985pub const EV_ENABLE = 0x0004;
986
987/// disable event (not reported)
988pub const EV_DISABLE = 0x0008;
989
990/// only report one occurrence
991pub const EV_ONESHOT = 0x0010;
992
993/// clear event state after reporting
994pub const EV_CLEAR = 0x0020;
995
996/// error, event data contains errno
997pub const EV_ERROR = 0x4000;
998
999/// force immediate event output
1000/// ... with or without EV_ERROR
1001/// ... use KEVENT_FLAG_ERROR_EVENTS
1002/// on syscalls supporting flags
1003pub const EV_RECEIPT = 0x0040;
1004
1005/// disable event after reporting
1006pub const EV_DISPATCH = 0x0080;
1007
1008pub const EVFILT_READ = -1;
1009pub const EVFILT_WRITE = -2;
1010
1011/// attached to aio requests
1012pub const EVFILT_AIO = -3;
1013
1014/// attached to vnodes
1015pub const EVFILT_VNODE = -4;
1016
1017/// attached to struct proc
1018pub const EVFILT_PROC = -5;
1019
1020/// attached to struct proc
1021pub const EVFILT_SIGNAL = -6;
1022
1023/// timers
1024pub const EVFILT_TIMER = -7;
1025
1026/// Process descriptors
1027pub const EVFILT_PROCDESC = -8;
1028
1029/// Filesystem events
1030pub const EVFILT_FS = -9;
1031
1032pub const EVFILT_LIO = -10;
1033
1034/// User events
1035pub const EVFILT_USER = -11;
1036
1037/// Sendfile events
1038pub const EVFILT_SENDFILE = -12;
1039
1040pub const EVFILT_EMPTY = -13;
1041
1042/// On input, NOTE_TRIGGER causes the event to be triggered for output.
1043pub const NOTE_TRIGGER = 0x01000000;
1044
1045/// ignore input fflags
1046pub const NOTE_FFNOP = 0x00000000;
1047
1048/// and fflags
1049pub const NOTE_FFAND = 0x40000000;
1050
1051/// or fflags
1052pub const NOTE_FFOR = 0x80000000;
1053
1054/// copy fflags
1055pub const NOTE_FFCOPY = 0xc0000000;
1056
1057/// mask for operations
1058pub const NOTE_FFCTRLMASK = 0xc0000000;
1059pub const NOTE_FFLAGSMASK = 0x00ffffff;
1060
1061/// low water mark
1062pub const NOTE_LOWAT = 0x00000001;
1063
1064/// behave like poll()
1065pub const NOTE_FILE_POLL = 0x00000002;
1066
1067/// vnode was removed
1068pub const NOTE_DELETE = 0x00000001;
1069
1070/// data contents changed
1071pub const NOTE_WRITE = 0x00000002;
1072
1073/// size increased
1074pub const NOTE_EXTEND = 0x00000004;
1075
1076/// attributes changed
1077pub const NOTE_ATTRIB = 0x00000008;
1078
1079/// link count changed
1080pub const NOTE_LINK = 0x00000010;
1081
1082/// vnode was renamed
1083pub const NOTE_RENAME = 0x00000020;
1084
1085/// vnode access was revoked
1086pub const NOTE_REVOKE = 0x00000040;
1087
1088/// vnode was opened
1089pub const NOTE_OPEN = 0x00000080;
1090
1091/// file closed, fd did not allow write
1092pub const NOTE_CLOSE = 0x00000100;
1093
1094/// file closed, fd did allow write
1095pub const NOTE_CLOSE_WRITE = 0x00000200;
1096
1097/// file was read
1098pub const NOTE_READ = 0x00000400;
1099
1100/// process exited
1101pub const NOTE_EXIT = 0x80000000;
1102
1103/// process forked
1104pub const NOTE_FORK = 0x40000000;
1105
1106/// process exec'd
1107pub const NOTE_EXEC = 0x20000000;
1108
1109/// mask for signal & exit status
1110pub const NOTE_PDATAMASK = 0x000fffff;
1111pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
1112
1113/// data is seconds
1114pub const NOTE_SECONDS = 0x00000001;
1115
1116/// data is milliseconds
1117pub const NOTE_MSECONDS = 0x00000002;
1118
1119/// data is microseconds
1120pub const NOTE_USECONDS = 0x00000004;
1121
1122/// data is nanoseconds
1123pub const NOTE_NSECONDS = 0x00000008;
1124
1125/// timeout is absolute
1126pub const NOTE_ABSTIME = 0x00000010;
1127
1128pub const T = struct {
1129 pub const IOCEXCL = 0x2000740d;
1130 pub const IOCNXCL = 0x2000740e;
1131 pub const IOCSCTTY = 0x20007461;
1132 pub const IOCGPGRP = 0x40047477;
1133 pub const IOCSPGRP = 0x80047476;
1134 pub const IOCOUTQ = 0x40047473;
1135 pub const IOCSTI = 0x80017472;
1136 pub const IOCGWINSZ = 0x40087468;
1137 pub const IOCSWINSZ = 0x80087467;
1138 pub const IOCMGET = 0x4004746a;
1139 pub const IOCMBIS = 0x8004746c;
1140 pub const IOCMBIC = 0x8004746b;
1141 pub const IOCMSET = 0x8004746d;
1142 pub const FIONREAD = 0x4004667f;
1143 pub const IOCCONS = 0x80047462;
1144 pub const IOCPKT = 0x80047470;
1145 pub const FIONBIO = 0x8004667e;
1146 pub const IOCNOTTY = 0x20007471;
1147 pub const IOCSETD = 0x8004741b;
1148 pub const IOCGETD = 0x4004741a;
1149 pub const IOCSBRK = 0x2000747b;
1150 pub const IOCCBRK = 0x2000747a;
1151 pub const IOCGSID = 0x40047463;
1152 pub const IOCGPTN = 0x4004740f;
1153 pub const IOCSIG = 0x2004745f;
1154};
1155
1156pub const TCSA = enum(c_uint) {
1157 NOW,
1158 DRAIN,
1159 FLUSH,
1160 _,
1161};
1162
1163pub const winsize = extern struct {
1164 ws_row: u16,
1165 ws_col: u16,
1166 ws_xpixel: u16,
1167 ws_ypixel: u16,
1168};
1169
1170const NSIG = 32;
1171
1172/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
1173pub const Sigaction = extern struct {
1174 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
1175 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
1176
1177 /// signal handler
1178 handler: extern union {
1179 handler: ?handler_fn,
1180 sigaction: ?sigaction_fn,
1181 },
1182
1183 /// see signal options
1184 flags: c_uint,
1185
1186 /// signal mask to apply
1187 mask: sigset_t,
1188};
1189
1190pub const siginfo_t = extern struct {
1191 // Signal number.
1192 signo: c_int,
1193 // Errno association.
1194 errno: c_int,
1195 /// Signal code.
1196 ///
1197 /// Cause of signal, one of the SI_ macros or signal-specific values, i.e.
1198 /// one of the FPE_... values for SIGFPE.
1199 /// This value is equivalent to the second argument to an old-style FreeBSD
1200 /// signal handler.
1201 code: c_int,
1202 /// Sending process.
1203 pid: pid_t,
1204 /// Sender's ruid.
1205 uid: uid_t,
1206 /// Exit value.
1207 status: c_int,
1208 /// Faulting instruction.
1209 addr: *allowzero anyopaque,
1210 /// Signal value.
1211 value: sigval,
1212 reason: extern union {
1213 fault: extern struct {
1214 /// Machine specific trap code.
1215 trapno: c_int,
1216 },
1217 timer: extern struct {
1218 timerid: c_int,
1219 overrun: c_int,
1220 },
1221 mesgq: extern struct {
1222 mqd: c_int,
1223 },
1224 poll: extern struct {
1225 /// Band event for SIGPOLL. UNUSED.
1226 band: c_long,
1227 },
1228 spare: extern struct {
1229 spare1: c_long,
1230 spare2: [7]c_int,
1231 },
1232 },
1233};
1234
1235pub const mcontext_t = switch (builtin.cpu.arch) {
1236 .x86_64 => extern struct {
1237 onstack: u64,
1238 rdi: u64,
1239 rsi: u64,
1240 rdx: u64,
1241 rcx: u64,
1242 r8: u64,
1243 r9: u64,
1244 rax: u64,
1245 rbx: u64,
1246 rbp: u64,
1247 r10: u64,
1248 r11: u64,
1249 r12: u64,
1250 r13: u64,
1251 r14: u64,
1252 r15: u64,
1253 trapno: u32,
1254 fs: u16,
1255 gs: u16,
1256 addr: u64,
1257 flags: u32,
1258 es: u16,
1259 ds: u16,
1260 err: u64,
1261 rip: u64,
1262 cs: u64,
1263 rflags: u64,
1264 rsp: u64,
1265 ss: u64,
1266 len: u64,
1267 fpformat: u64,
1268 ownedfp: u64,
1269 fpstate: [64]u64 align(16),
1270 fsbase: u64,
1271 gsbase: u64,
1272 xfpustate: u64,
1273 xfpustate_len: u64,
1274 spare: [4]u64,
1275 },
1276 .aarch64 => extern struct {
1277 gpregs: extern struct {
1278 x: [30]u64,
1279 lr: u64,
1280 sp: u64,
1281 elr: u64,
1282 spsr: u32,
1283 _pad: u32,
1284 },
1285 fpregs: extern struct {
1286 q: [32]u128,
1287 sr: u32,
1288 cr: u32,
1289 flags: u32,
1290 _pad: u32,
1291 },
1292 flags: u32,
1293 _pad: u32,
1294 _spare: [8]u64,
1295 },
1296 else => struct {},
1297};
1298
1299pub const REG = switch (builtin.cpu.arch) {
1300 .aarch64 => struct {
1301 pub const FP = 29;
1302 pub const SP = 31;
1303 pub const PC = 32;
1304 },
1305 .arm => struct {
1306 pub const FP = 11;
1307 pub const SP = 13;
1308 pub const PC = 15;
1309 },
1310 .x86_64 => struct {
1311 pub const RBP = 12;
1312 pub const RIP = 21;
1313 pub const RSP = 24;
1314 },
1315 else => struct {},
1316};
258pub const KINFO_FILE_SIZE = 1392;
1317259
1318pub const ucontext_t = extern struct {
1319 sigmask: sigset_t,
1320 mcontext: mcontext_t,
1321 link: ?*ucontext_t,
1322 stack: stack_t,
1323 flags: c_int,
1324 __spare__: [4]c_int,
260pub const MFD = struct {
261 pub const CLOEXEC = 0x0001;
262 pub const ALLOW_SEALING = 0x0002;
1325263};
1326264
1327265pub const E = enum(u16) {
......@@ -1453,422 +391,3 @@ pub const E = enum(u16) {
1453391 INTEGRITY = 97, // Integrity check failed
1454392 _,
1455393};
1456
1457pub const MINSIGSTKSZ = switch (builtin.cpu.arch) {
1458 .x86, .x86_64 => 2048,
1459 .arm, .aarch64 => 4096,
1460 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
1461};
1462pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
1463
1464pub const SS_ONSTACK = 1;
1465pub const SS_DISABLE = 4;
1466
1467pub const stack_t = extern struct {
1468 /// Signal stack base.
1469 sp: *anyopaque,
1470 /// Signal stack length.
1471 size: usize,
1472 /// SS_DISABLE and/or SS_ONSTACK.
1473 flags: i32,
1474};
1475
1476pub const S = struct {
1477 pub const IFMT = 0o170000;
1478
1479 pub const IFIFO = 0o010000;
1480 pub const IFCHR = 0o020000;
1481 pub const IFDIR = 0o040000;
1482 pub const IFBLK = 0o060000;
1483 pub const IFREG = 0o100000;
1484 pub const IFLNK = 0o120000;
1485 pub const IFSOCK = 0o140000;
1486 pub const IFWHT = 0o160000;
1487
1488 pub const ISUID = 0o4000;
1489 pub const ISGID = 0o2000;
1490 pub const ISVTX = 0o1000;
1491 pub const IRWXU = 0o700;
1492 pub const IRUSR = 0o400;
1493 pub const IWUSR = 0o200;
1494 pub const IXUSR = 0o100;
1495 pub const IRWXG = 0o070;
1496 pub const IRGRP = 0o040;
1497 pub const IWGRP = 0o020;
1498 pub const IXGRP = 0o010;
1499 pub const IRWXO = 0o007;
1500 pub const IROTH = 0o004;
1501 pub const IWOTH = 0o002;
1502 pub const IXOTH = 0o001;
1503
1504 pub fn ISFIFO(m: u32) bool {
1505 return m & IFMT == IFIFO;
1506 }
1507
1508 pub fn ISCHR(m: u32) bool {
1509 return m & IFMT == IFCHR;
1510 }
1511
1512 pub fn ISDIR(m: u32) bool {
1513 return m & IFMT == IFDIR;
1514 }
1515
1516 pub fn ISBLK(m: u32) bool {
1517 return m & IFMT == IFBLK;
1518 }
1519
1520 pub fn ISREG(m: u32) bool {
1521 return m & IFMT == IFREG;
1522 }
1523
1524 pub fn ISLNK(m: u32) bool {
1525 return m & IFMT == IFLNK;
1526 }
1527
1528 pub fn ISSOCK(m: u32) bool {
1529 return m & IFMT == IFSOCK;
1530 }
1531
1532 pub fn IWHT(m: u32) bool {
1533 return m & IFMT == IFWHT;
1534 }
1535};
1536
1537pub const HOST_NAME_MAX = 255;
1538
1539pub const addrinfo = extern struct {
1540 flags: i32,
1541 family: i32,
1542 socktype: i32,
1543 protocol: i32,
1544 addrlen: socklen_t,
1545 canonname: ?[*:0]u8,
1546 addr: ?*sockaddr,
1547 next: ?*addrinfo,
1548};
1549
1550pub const IPPROTO = struct {
1551 /// dummy for IP
1552 pub const IP = 0;
1553 /// control message protocol
1554 pub const ICMP = 1;
1555 /// tcp
1556 pub const TCP = 6;
1557 /// user datagram protocol
1558 pub const UDP = 17;
1559 /// IP6 header
1560 pub const IPV6 = 41;
1561 /// raw IP packet
1562 pub const RAW = 255;
1563 /// IP6 hop-by-hop options
1564 pub const HOPOPTS = 0;
1565 /// group mgmt protocol
1566 pub const IGMP = 2;
1567 /// gateway^2 (deprecated)
1568 pub const GGP = 3;
1569 /// IPv4 encapsulation
1570 pub const IPV4 = 4;
1571 /// for compatibility
1572 pub const IPIP = IPV4;
1573 /// Stream protocol II
1574 pub const ST = 7;
1575 /// exterior gateway protocol
1576 pub const EGP = 8;
1577 /// private interior gateway
1578 pub const PIGP = 9;
1579 /// BBN RCC Monitoring
1580 pub const RCCMON = 10;
1581 /// network voice protocol
1582 pub const NVPII = 11;
1583 /// pup
1584 pub const PUP = 12;
1585 /// Argus
1586 pub const ARGUS = 13;
1587 /// EMCON
1588 pub const EMCON = 14;
1589 /// Cross Net Debugger
1590 pub const XNET = 15;
1591 /// Chaos
1592 pub const CHAOS = 16;
1593 /// Multiplexing
1594 pub const MUX = 18;
1595 /// DCN Measurement Subsystems
1596 pub const MEAS = 19;
1597 /// Host Monitoring
1598 pub const HMP = 20;
1599 /// Packet Radio Measurement
1600 pub const PRM = 21;
1601 /// xns idp
1602 pub const IDP = 22;
1603 /// Trunk-1
1604 pub const TRUNK1 = 23;
1605 /// Trunk-2
1606 pub const TRUNK2 = 24;
1607 /// Leaf-1
1608 pub const LEAF1 = 25;
1609 /// Leaf-2
1610 pub const LEAF2 = 26;
1611 /// Reliable Data
1612 pub const RDP = 27;
1613 /// Reliable Transaction
1614 pub const IRTP = 28;
1615 /// tp-4 w/ class negotiation
1616 pub const TP = 29;
1617 /// Bulk Data Transfer
1618 pub const BLT = 30;
1619 /// Network Services
1620 pub const NSP = 31;
1621 /// Merit Internodal
1622 pub const INP = 32;
1623 /// Datagram Congestion Control Protocol
1624 pub const DCCP = 33;
1625 /// Third Party Connect
1626 pub const @"3PC" = 34;
1627 /// InterDomain Policy Routing
1628 pub const IDPR = 35;
1629 /// XTP
1630 pub const XTP = 36;
1631 /// Datagram Delivery
1632 pub const DDP = 37;
1633 /// Control Message Transport
1634 pub const CMTP = 38;
1635 /// TP++ Transport
1636 pub const TPXX = 39;
1637 /// IL transport protocol
1638 pub const IL = 40;
1639 /// Source Demand Routing
1640 pub const SDRP = 42;
1641 /// IP6 routing header
1642 pub const ROUTING = 43;
1643 /// IP6 fragmentation header
1644 pub const FRAGMENT = 44;
1645 /// InterDomain Routing
1646 pub const IDRP = 45;
1647 /// resource reservation
1648 pub const RSVP = 46;
1649 /// General Routing Encap.
1650 pub const GRE = 47;
1651 /// Mobile Host Routing
1652 pub const MHRP = 48;
1653 /// BHA
1654 pub const BHA = 49;
1655 /// IP6 Encap Sec. Payload
1656 pub const ESP = 50;
1657 /// IP6 Auth Header
1658 pub const AH = 51;
1659 /// Integ. Net Layer Security
1660 pub const INLSP = 52;
1661 /// IP with encryption
1662 pub const SWIPE = 53;
1663 /// Next Hop Resolution
1664 pub const NHRP = 54;
1665 /// IP Mobility
1666 pub const MOBILE = 55;
1667 /// Transport Layer Security
1668 pub const TLSP = 56;
1669 /// SKIP
1670 pub const SKIP = 57;
1671 /// ICMP6
1672 pub const ICMPV6 = 58;
1673 /// IP6 no next header
1674 pub const NONE = 59;
1675 /// IP6 destination option
1676 pub const DSTOPTS = 60;
1677 /// any host internal protocol
1678 pub const AHIP = 61;
1679 /// CFTP
1680 pub const CFTP = 62;
1681 /// "hello" routing protocol
1682 pub const HELLO = 63;
1683 /// SATNET/Backroom EXPAK
1684 pub const SATEXPAK = 64;
1685 /// Kryptolan
1686 pub const KRYPTOLAN = 65;
1687 /// Remote Virtual Disk
1688 pub const RVD = 66;
1689 /// Pluribus Packet Core
1690 pub const IPPC = 67;
1691 /// Any distributed FS
1692 pub const ADFS = 68;
1693 /// Satnet Monitoring
1694 pub const SATMON = 69;
1695 /// VISA Protocol
1696 pub const VISA = 70;
1697 /// Packet Core Utility
1698 pub const IPCV = 71;
1699 /// Comp. Prot. Net. Executive
1700 pub const CPNX = 72;
1701 /// Comp. Prot. HeartBeat
1702 pub const CPHB = 73;
1703 /// Wang Span Network
1704 pub const WSN = 74;
1705 /// Packet Video Protocol
1706 pub const PVP = 75;
1707 /// BackRoom SATNET Monitoring
1708 pub const BRSATMON = 76;
1709 /// Sun net disk proto (temp.)
1710 pub const ND = 77;
1711 /// WIDEBAND Monitoring
1712 pub const WBMON = 78;
1713 /// WIDEBAND EXPAK
1714 pub const WBEXPAK = 79;
1715 /// ISO cnlp
1716 pub const EON = 80;
1717 /// VMTP
1718 pub const VMTP = 81;
1719 /// Secure VMTP
1720 pub const SVMTP = 82;
1721 /// Banyon VINES
1722 pub const VINES = 83;
1723 /// TTP
1724 pub const TTP = 84;
1725 /// NSFNET-IGP
1726 pub const IGP = 85;
1727 /// dissimilar gateway prot.
1728 pub const DGP = 86;
1729 /// TCF
1730 pub const TCF = 87;
1731 /// Cisco/GXS IGRP
1732 pub const IGRP = 88;
1733 /// OSPFIGP
1734 pub const OSPFIGP = 89;
1735 /// Strite RPC protocol
1736 pub const SRPC = 90;
1737 /// Locus Address Resoloution
1738 pub const LARP = 91;
1739 /// Multicast Transport
1740 pub const MTP = 92;
1741 /// AX.25 Frames
1742 pub const AX25 = 93;
1743 /// IP encapsulated in IP
1744 pub const IPEIP = 94;
1745 /// Mobile Int.ing control
1746 pub const MICP = 95;
1747 /// Semaphore Comm. security
1748 pub const SCCSP = 96;
1749 /// Ethernet IP encapsulation
1750 pub const ETHERIP = 97;
1751 /// encapsulation header
1752 pub const ENCAP = 98;
1753 /// any private encr. scheme
1754 pub const APES = 99;
1755 /// GMTP
1756 pub const GMTP = 100;
1757 /// payload compression (IPComp)
1758 pub const IPCOMP = 108;
1759 /// SCTP
1760 pub const SCTP = 132;
1761 /// IPv6 Mobility Header
1762 pub const MH = 135;
1763 /// UDP-Lite
1764 pub const UDPLITE = 136;
1765 /// IP6 Host Identity Protocol
1766 pub const HIP = 139;
1767 /// IP6 Shim6 Protocol
1768 pub const SHIM6 = 140;
1769 /// Protocol Independent Mcast
1770 pub const PIM = 103;
1771 /// CARP
1772 pub const CARP = 112;
1773 /// PGM
1774 pub const PGM = 113;
1775 /// MPLS-in-IP
1776 pub const MPLS = 137;
1777 /// PFSYNC
1778 pub const PFSYNC = 240;
1779 /// Reserved
1780 pub const RESERVED_253 = 253;
1781 /// Reserved
1782 pub const RESERVED_254 = 254;
1783};
1784
1785pub const rlimit_resource = enum(c_int) {
1786 CPU = 0,
1787 FSIZE = 1,
1788 DATA = 2,
1789 STACK = 3,
1790 CORE = 4,
1791 RSS = 5,
1792 MEMLOCK = 6,
1793 NPROC = 7,
1794 NOFILE = 8,
1795 SBSIZE = 9,
1796 VMEM = 10,
1797 NPTS = 11,
1798 SWAP = 12,
1799 KQUEUES = 13,
1800 UMTXP = 14,
1801 _,
1802
1803 pub const AS: rlimit_resource = .VMEM;
1804};
1805
1806pub const rlim_t = i64;
1807
1808pub const RLIM = struct {
1809 /// No limit
1810 pub const INFINITY: rlim_t = (1 << 63) - 1;
1811
1812 pub const SAVED_MAX = INFINITY;
1813 pub const SAVED_CUR = INFINITY;
1814};
1815
1816pub const rlimit = extern struct {
1817 /// Soft limit
1818 cur: rlim_t,
1819 /// Hard limit
1820 max: rlim_t,
1821};
1822
1823pub const SHUT = struct {
1824 pub const RD = 0;
1825 pub const WR = 1;
1826 pub const RDWR = 2;
1827};
1828
1829pub const nfds_t = u32;
1830
1831pub const pollfd = extern struct {
1832 fd: fd_t,
1833 events: i16,
1834 revents: i16,
1835};
1836
1837pub const POLL = struct {
1838 /// any readable data available.
1839 pub const IN = 0x0001;
1840 /// OOB/Urgent readable data.
1841 pub const PRI = 0x0002;
1842 /// file descriptor is writeable.
1843 pub const OUT = 0x0004;
1844 /// non-OOB/URG data available.
1845 pub const RDNORM = 0x0040;
1846 /// no write type differentiation.
1847 pub const WRNORM = OUT;
1848 /// OOB/Urgent readable data.
1849 pub const RDBAND = 0x0080;
1850 /// OOB/Urgent data can be written.
1851 pub const WRBAND = 0x0100;
1852 /// like IN, except ignore EOF.
1853 pub const INIGNEOF = 0x2000;
1854 /// some poll error occurred.
1855 pub const ERR = 0x0008;
1856 /// file descriptor was "hung up".
1857 pub const HUP = 0x0010;
1858 /// requested events "invalid".
1859 pub const NVAL = 0x0020;
1860
1861 pub const STANDARD = IN | PRI | OUT | RDNORM | RDBAND | WRBAND | ERR | HUP | NVAL;
1862};
1863
1864pub const NAME_MAX = 255;
1865
1866pub const MFD = struct {
1867 pub const CLOEXEC = 0x0001;
1868 pub const ALLOW_SEALING = 0x0002;
1869};
1870
1871pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
1872pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize;
1873pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
1874pub extern "c" fn dup3(old: c_int, new: c_int, flags: c_uint) c_int;
lib/std/c/haiku.zig+16-859
......@@ -4,152 +4,29 @@ const builtin = @import("builtin");
44const maxInt = std.math.maxInt;
55const iovec = std.posix.iovec;
66const iovec_const = std.posix.iovec_const;
7
7const socklen_t = std.c.socklen_t;
8const fd_t = std.c.fd_t;
9const PATH_MAX = std.c.PATH_MAX;
10const uid_t = std.c.uid_t;
11const gid_t = std.c.gid_t;
12const dev_t = std.c.dev_t;
13const ino_t = std.c.ino_t;
14
15comptime {
16 assert(builtin.os.tag == .haiku); // Prevent access of std.c symbols on wrong OS.
17}
18
19pub extern "root" fn _errnop() *i32;
820pub extern "root" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
9
1021pub extern "root" fn find_thread(thread_name: ?*anyopaque) i32;
11
1222pub extern "root" fn get_system_info(system_info: *system_info) usize;
13
1423pub extern "root" fn _get_team_info(team: i32, team_info: *team_info, size: usize) i32;
15
1624pub extern "root" fn _get_next_area_info(team: i32, cookie: *i64, area_info: *area_info, size: usize) i32;
17
18// TODO revisit if abi changes or better option becomes apparent
1925pub extern "root" fn _get_next_image_info(team: i32, cookie: *i32, image_info: *image_info, size: usize) i32;
2026
21pub const sem_t = extern struct {
22 type: i32,
23 u: extern union {
24 named_sem_id: i32,
25 unnamed_sem: i32,
26 },
27 padding: [2]i32,
28};
29
30pub const pthread_attr_t = extern struct {
31 __detach_state: i32,
32 __sched_priority: i32,
33 __stack_size: i32,
34 __guard_size: i32,
35 __stack_address: ?*anyopaque,
36};
37
38pub const EAI = enum(i32) {
39 /// address family for hostname not supported
40 ADDRFAMILY = 1,
41
42 /// name could not be resolved at this time
43 AGAIN = 2,
44
45 /// flags parameter had an invalid value
46 BADFLAGS = 3,
47
48 /// non-recoverable failure in name resolution
49 FAIL = 4,
50
51 /// address family not recognized
52 FAMILY = 5,
53
54 /// memory allocation failure
55 MEMORY = 6,
56
57 /// no address associated with hostname
58 NODATA = 7,
59
60 /// name does not resolve
61 NONAME = 8,
62
63 /// service not recognized for socket type
64 SERVICE = 9,
65
66 /// intended socket type was not recognized
67 SOCKTYPE = 10,
68
69 /// system error returned in errno
70 SYSTEM = 11,
71
72 /// invalid value for hints
73 BADHINTS = 12,
74
75 /// resolved protocol is unknown
76 PROTOCOL = 13,
77
78 /// argument buffer overflow
79 OVERFLOW = 14,
80
81 _,
82};
83
84pub const EAI_MAX = 15;
85
86pub const AI = struct {
87 pub const NUMERICSERV = 0x00000008;
88};
89
90pub const AI_NUMERICSERV = AI.NUMERICSERV;
91
92pub const fd_t = i32;
93
94pub const socklen_t = u32;
95
96// Modes and flags for dlopen()
97// include/dlfcn.h
98
99pub const RTLD = struct {
100 /// relocations are performed as needed
101 pub const LAZY = 0;
102 /// the file gets relocated at load time
103 pub const NOW = 1;
104 /// all symbols are available
105 pub const GLOBAL = 2;
106 /// symbols are not available for relocating any other object
107 pub const LOCAL = 0;
108};
109
110pub const dl_phdr_info = extern struct {
111 dlpi_addr: usize,
112 dlpi_name: ?[*:0]const u8,
113 dlpi_phdr: [*]std.elf.Phdr,
114 dlpi_phnum: u16,
115};
116
117pub const Flock = extern struct {
118 type: i16,
119 whence: i16,
120 start: off_t,
121 len: off_t,
122 pid: pid_t,
123};
124
125pub const msghdr = extern struct {
126 /// optional address
127 msg_name: ?*sockaddr,
128
129 /// size of address
130 msg_namelen: socklen_t,
131
132 /// scatter/gather array
133 msg_iov: [*]iovec,
134
135 /// # elements in msg_iov
136 msg_iovlen: i32,
137
138 /// ancillary data
139 msg_control: ?*anyopaque,
140
141 /// ancillary data buffer len
142 msg_controllen: socklen_t,
143
144 /// flags on received message
145 msg_flags: i32,
146};
147
148pub const B_OS_NAME_LENGTH = 32; // OS.h
149
15027pub const area_info = extern struct {
15128 area: u32,
152 name: [B_OS_NAME_LENGTH]u8,
29 name: [32]u8,
15330 size: usize,
15431 lock: u32,
15532 protection: u32,
......@@ -161,9 +38,6 @@ pub const area_info = extern struct {
16138 address: *anyopaque,
16239};
16340
164pub const MAXPATHLEN = PATH_MAX;
165pub const MAXNAMLEN = NAME_MAX;
166
16741pub const image_info = extern struct {
16842 id: u32,
16943 image_type: u32,
......@@ -173,7 +47,7 @@ pub const image_info = extern struct {
17347 term_routine: *anyopaque,
17448 device: i32,
17549 node: i64,
176 name: [MAXPATHLEN]u8,
50 name: [PATH_MAX]u8,
17751 text: *anyopaque,
17852 data: *anyopaque,
17953 text_size: i32,
......@@ -223,473 +97,18 @@ pub const team_info = extern struct {
22397 gid: gid_t,
22498};
22599
226pub const in_port_t = u16;
227pub const sa_family_t = u8;
228
229pub const sockaddr = extern struct {
230 /// total length
231 len: u8,
232 /// address family
233 family: sa_family_t,
234 /// actually longer; address value
235 data: [14]u8,
236
237 pub const SS_MAXSIZE = 128;
238 pub const storage = extern struct {
239 len: u8 align(8),
240 family: sa_family_t,
241 padding: [126]u8 = undefined,
242
243 comptime {
244 assert(@sizeOf(storage) == SS_MAXSIZE);
245 assert(@alignOf(storage) == 8);
246 }
247 };
248
249 pub const in = extern struct {
250 len: u8 = @sizeOf(in),
251 family: sa_family_t = AF.INET,
252 port: in_port_t,
253 addr: u32,
254 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
255 };
256
257 pub const in6 = extern struct {
258 len: u8 = @sizeOf(in6),
259 family: sa_family_t = AF.INET6,
260 port: in_port_t,
261 flowinfo: u32,
262 addr: [16]u8,
263 scope_id: u32,
264 };
265
266 pub const un = extern struct {
267 len: u8 = @sizeOf(un),
268 family: sa_family_t = AF.UNIX,
269 path: [104]u8,
270 };
271};
272
273pub const CTL = struct {};
274
275pub const KERN = struct {};
276
277pub const IOV_MAX = 1024;
278
279pub const PATH_MAX = 1024;
280/// NOTE: Contains room for the terminating null character (despite the POSIX
281/// definition saying that NAME_MAX does not include the terminating null).
282pub const NAME_MAX = 256; // limits.h
283
284pub const STDIN_FILENO = 0;
285pub const STDOUT_FILENO = 1;
286pub const STDERR_FILENO = 2;
287
288pub const PROT = struct {
289 pub const READ = 0x01;
290 pub const WRITE = 0x02;
291 pub const EXEC = 0x04;
292 pub const NONE = 0x00;
293};
294
295pub const MSF = struct {
296 pub const ASYNC = 1;
297 pub const INVALIDATE = 2;
298 pub const SYNC = 4;
299};
300
301pub const W = struct {
302 pub const NOHANG = 0x1;
303 pub const UNTRACED = 0x2;
304 pub const CONTINUED = 0x4;
305 pub const EXITED = 0x08;
306 pub const STOPPED = 0x10;
307 pub const NOWAIT = 0x20;
308
309 pub fn EXITSTATUS(s: u32) u8 {
310 return @as(u8, @intCast(s & 0xff));
311 }
312
313 pub fn TERMSIG(s: u32) u32 {
314 return (s >> 8) & 0xff;
315 }
316
317 pub fn STOPSIG(s: u32) u32 {
318 return (s >> 16) & 0xff;
319 }
320
321 pub fn IFEXITED(s: u32) bool {
322 return (s & ~@as(u32, 0xff)) == 0;
323 }
324
325 pub fn IFSTOPPED(s: u32) bool {
326 return ((s >> 16) & 0xff) != 0;
327 }
328
329 pub fn IFSIGNALED(s: u32) bool {
330 return ((s >> 8) & 0xff) != 0;
331 }
332};
333
334// access function
335pub const F_OK = 0; // test for existence of file
336pub const X_OK = 1; // test for execute or search permission
337pub const W_OK = 2; // test for write permission
338pub const R_OK = 4; // test for read permission
339
340pub const F = struct {
341 pub const DUPFD = 0x0001;
342 pub const GETFD = 0x0002;
343 pub const SETFD = 0x0004;
344 pub const GETFL = 0x0008;
345 pub const SETFL = 0x0010;
346
347 pub const GETLK = 0x0020;
348 pub const SETLK = 0x0080;
349 pub const SETLKW = 0x0100;
350 pub const DUPFD_CLOEXEC = 0x0200;
351
352 pub const RDLCK = 0x0040;
353 pub const UNLCK = 0x0200;
354 pub const WRLCK = 0x0400;
355};
356
357pub const LOCK = struct {
358 pub const SH = 0x01;
359 pub const EX = 0x02;
360 pub const NB = 0x04;
361 pub const UN = 0x08;
362};
363
364pub const FD_CLOEXEC = 1;
365
366pub const SEEK = struct {
367 pub const SET = 0;
368 pub const CUR = 1;
369 pub const END = 2;
370};
371
372pub const SOCK = struct {
373 pub const STREAM = 1;
374 pub const DGRAM = 2;
375 pub const RAW = 3;
376 pub const SEQPACKET = 5;
377
378 /// WARNING: this flag is not supported by windows socket functions directly,
379 /// it is only supported by std.os.socket. Be sure that this value does
380 /// not share any bits with any of the `SOCK` values.
381 pub const CLOEXEC = 0x10000;
382 /// WARNING: this flag is not supported by windows socket functions directly,
383 /// it is only supported by std.os.socket. Be sure that this value does
384 /// not share any bits with any of the `SOCK` values.
385 pub const NONBLOCK = 0x20000;
386};
387
388pub const SO = struct {
389 pub const ACCEPTCONN = 0x00000001;
390 pub const BROADCAST = 0x00000002;
391 pub const DEBUG = 0x00000004;
392 pub const DONTROUTE = 0x00000008;
393 pub const KEEPALIVE = 0x00000010;
394 pub const OOBINLINE = 0x00000020;
395 pub const REUSEADDR = 0x00000040;
396 pub const REUSEPORT = 0x00000080;
397 pub const USELOOPBACK = 0x00000100;
398 pub const LINGER = 0x00000200;
399
400 pub const SNDBUF = 0x40000001;
401 pub const SNDLOWAT = 0x40000002;
402 pub const SNDTIMEO = 0x40000003;
403 pub const RCVBUF = 0x40000004;
404 pub const RCVLOWAT = 0x40000005;
405 pub const RCVTIMEO = 0x40000006;
406 pub const ERROR = 0x40000007;
407 pub const TYPE = 0x40000008;
408 pub const NONBLOCK = 0x40000009;
409 pub const BINDTODEVICE = 0x4000000a;
410 pub const PEERCRED = 0x4000000b;
411};
412
413pub const SOL = struct {
414 pub const SOCKET = -1;
415};
416
417pub const PF = struct {
418 pub const UNSPEC = AF.UNSPEC;
419 pub const INET = AF.INET;
420 pub const ROUTE = AF.ROUTE;
421 pub const LINK = AF.LINK;
422 pub const INET6 = AF.INET6;
423 pub const LOCAL = AF.LOCAL;
424 pub const UNIX = AF.UNIX;
425 pub const BLUETOOTH = AF.BLUETOOTH;
426};
427
428pub const AF = struct {
429 pub const UNSPEC = 0;
430 pub const INET = 1;
431 pub const APPLETALK = 2;
432 pub const ROUTE = 3;
433 pub const LINK = 4;
434 pub const INET6 = 5;
435 pub const DLI = 6;
436 pub const IPX = 7;
437 pub const NOTIFY = 8;
438 pub const LOCAL = 9;
439 pub const UNIX = LOCAL;
440 pub const BLUETOOTH = 10;
441 pub const MAX = 11;
442};
443
444pub const DT = struct {};
445
446/// add event to kq (implies enable)
447pub const EV_ADD = 0x0001;
448
449/// delete event from kq
450pub const EV_DELETE = 0x0002;
451
452/// enable event
453pub const EV_ENABLE = 0x0004;
454
455/// disable event (not reported)
456pub const EV_DISABLE = 0x0008;
457
458/// only report one occurrence
459pub const EV_ONESHOT = 0x0010;
460
461/// clear event state after reporting
462pub const EV_CLEAR = 0x0020;
463
464/// force immediate event output
465/// ... with or without EV_ERROR
466/// ... use KEVENT_FLAG_ERROR_EVENTS
467/// on syscalls supporting flags
468pub const EV_RECEIPT = 0x0040;
469
470/// disable event after reporting
471pub const EV_DISPATCH = 0x0080;
472
473pub const EVFILT_READ = -1;
474pub const EVFILT_WRITE = -2;
475
476/// attached to aio requests
477pub const EVFILT_AIO = -3;
478
479/// attached to vnodes
480pub const EVFILT_VNODE = -4;
481
482/// attached to struct proc
483pub const EVFILT_PROC = -5;
484
485/// attached to struct proc
486pub const EVFILT_SIGNAL = -6;
487
488/// timers
489pub const EVFILT_TIMER = -7;
490
491/// Process descriptors
492pub const EVFILT_PROCDESC = -8;
493
494/// Filesystem events
495pub const EVFILT_FS = -9;
496
497pub const EVFILT_LIO = -10;
498
499/// User events
500pub const EVFILT_USER = -11;
501
502/// Sendfile events
503pub const EVFILT_SENDFILE = -12;
504
505pub const EVFILT_EMPTY = -13;
506
507pub const T = struct {
508 pub const CGETA = 0x8000;
509 pub const CSETA = 0x8001;
510 pub const CSETAF = 0x8002;
511 pub const CSETAW = 0x8003;
512 pub const CWAITEVENT = 0x8004;
513 pub const CSBRK = 0x8005;
514 pub const CFLSH = 0x8006;
515 pub const CXONC = 0x8007;
516 pub const CQUERYCONNECTED = 0x8008;
517 pub const CGETBITS = 0x8009;
518 pub const CSETDTR = 0x8010;
519 pub const CSETRTS = 0x8011;
520 pub const IOCGWINSZ = 0x8012;
521 pub const IOCSWINSZ = 0x8013;
522 pub const CVTIME = 0x8014;
523 pub const IOCGPGRP = 0x8015;
524 pub const IOCSPGRP = 0x8016;
525 pub const IOCSCTTY = 0x8017;
526 pub const IOCMGET = 0x8018;
527 pub const IOCMSET = 0x8019;
528 pub const IOCSBRK = 0x8020;
529 pub const IOCCBRK = 0x8021;
530 pub const IOCMBIS = 0x8022;
531 pub const IOCMBIC = 0x8023;
532 pub const IOCGSID = 0x8024;
533
534 pub const FIONREAD = 0xbe000001;
535 pub const FIONBIO = 0xbe000000;
536};
537
538pub const winsize = extern struct {
539 ws_row: u16,
540 ws_col: u16,
541 ws_xpixel: u16,
542 ws_ypixel: u16,
543};
544
545pub const S = struct {
546 pub const IFMT = 0o170000;
547 pub const IFSOCK = 0o140000;
548 pub const IFLNK = 0o120000;
549 pub const IFREG = 0o100000;
550 pub const IFBLK = 0o060000;
551 pub const IFDIR = 0o040000;
552 pub const IFCHR = 0o020000;
553 pub const IFIFO = 0o010000;
554 pub const INDEX_DIR = 0o4000000000;
555
556 pub const IUMSK = 0o7777;
557 pub const ISUID = 0o4000;
558 pub const ISGID = 0o2000;
559 pub const ISVTX = 0o1000;
560 pub const IRWXU = 0o700;
561 pub const IRUSR = 0o400;
562 pub const IWUSR = 0o200;
563 pub const IXUSR = 0o100;
564 pub const IRWXG = 0o070;
565 pub const IRGRP = 0o040;
566 pub const IWGRP = 0o020;
567 pub const IXGRP = 0o010;
568 pub const IRWXO = 0o007;
569 pub const IROTH = 0o004;
570 pub const IWOTH = 0o002;
571 pub const IXOTH = 0o001;
572
573 pub fn ISREG(m: u32) bool {
574 return m & IFMT == IFREG;
575 }
576
577 pub fn ISLNK(m: u32) bool {
578 return m & IFMT == IFLNK;
579 }
580
581 pub fn ISBLK(m: u32) bool {
582 return m & IFMT == IFBLK;
583 }
584
585 pub fn ISDIR(m: u32) bool {
586 return m & IFMT == IFDIR;
587 }
588
589 pub fn ISCHR(m: u32) bool {
590 return m & IFMT == IFCHR;
591 }
592
593 pub fn ISFIFO(m: u32) bool {
594 return m & IFMT == IFIFO;
595 }
596
597 pub fn ISSOCK(m: u32) bool {
598 return m & IFMT == IFSOCK;
599 }
600
601 pub fn ISINDEX(m: u32) bool {
602 return m & INDEX_DIR == INDEX_DIR;
603 }
604};
605
606pub const HOST_NAME_MAX = 255;
607
608pub const addrinfo = extern struct {
609 flags: i32,
610 family: i32,
611 socktype: i32,
612 protocol: i32,
613 addrlen: socklen_t,
614 canonname: ?[*:0]u8,
615 addr: ?*sockaddr,
616 next: ?*addrinfo,
617};
618
619pub const IPPROTO = struct {
620 pub const IP = 0;
621 pub const HOPOPTS = 0;
622 pub const ICMP = 1;
623 pub const IGMP = 2;
624 pub const TCP = 6;
625 pub const UDP = 17;
626 pub const IPV6 = 41;
627 pub const ROUTING = 43;
628 pub const FRAGMENT = 44;
629 pub const ESP = 50;
630 pub const AH = 51;
631 pub const ICMPV6 = 58;
632 pub const NONE = 59;
633 pub const DSTOPTS = 60;
634 pub const ETHERIP = 97;
635 pub const RAW = 255;
636 pub const MAX = 256;
637};
638
639pub const rlimit_resource = enum(i32) {
640 CORE = 0,
641 CPU = 1,
642 DATA = 2,
643 FSIZE = 3,
644 NOFILE = 4,
645 STACK = 5,
646 AS = 6,
647 NOVMON = 7,
648 _,
649};
650
651pub const rlim_t = i64;
652
653pub const RLIM = struct {
654 /// No limit
655 pub const INFINITY: rlim_t = (1 << 63) - 1;
656
657 pub const SAVED_MAX = INFINITY;
658 pub const SAVED_CUR = INFINITY;
659};
660
661pub const rlimit = extern struct {
662 /// Soft limit
663 cur: rlim_t,
664 /// Hard limit
665 max: rlim_t,
666};
667
668pub const SHUT = struct {
669 pub const RD = 0;
670 pub const WR = 1;
671 pub const RDWR = 2;
672};
673
674// TODO fill out if needed
675100pub const directory_which = enum(i32) {
676101 B_USER_SETTINGS_DIRECTORY = 0xbbe,
677102
678103 _,
679104};
680105
681pub const MSG_NOSIGNAL = 0x0800;
682
683// /system/develop/headers/os/kernel/OS.h
684
685106pub const area_id = i32;
686107pub const port_id = i32;
687108pub const sem_id = i32;
688109pub const team_id = i32;
689110pub const thread_id = i32;
690111
691// /system/develop/headers/os/support/Errors.h
692
693112pub const E = enum(i32) {
694113 pub const B_GENERAL_ERROR_BASE: i32 = std.math.minInt(i32);
695114 pub const B_OS_ERROR_BASE = B_GENERAL_ERROR_BASE + 0x1000;
......@@ -847,13 +266,9 @@ pub const E = enum(i32) {
847266 _,
848267};
849268
850// /system/develop/headers/os/support/SupportDefs.h
851
852269pub const status_t = i32;
853270
854// /system/develop/headers/posix/arch/*/signal.h
855
856pub const vregs = switch (builtin.cpu.arch) {
271pub const mcontext_t = switch (builtin.cpu.arch) {
857272 .arm, .thumb => extern struct {
858273 r0: u32,
859274 r1: u32,
......@@ -1116,8 +531,6 @@ pub const vregs = switch (builtin.cpu.arch) {
1116531 else => void,
1117532};
1118533
1119// /system/develop/headers/posix/dirent.h
1120
1121534pub const DirEnt = extern struct {
1122535 /// device
1123536 dev: dev_t,
......@@ -1135,259 +548,3 @@ pub const DirEnt = extern struct {
1135548 return @ptrCast(&dirent.name);
1136549 }
1137550};
1138
1139// /system/develop/headers/posix/errno.h
1140
1141extern "root" fn _errnop() *i32;
1142pub const _errno = _errnop;
1143
1144// /system/develop/headers/posix/poll.h
1145
1146pub const nfds_t = usize;
1147
1148pub const pollfd = extern struct {
1149 fd: i32,
1150 events: i16,
1151 revents: i16,
1152};
1153
1154pub const POLL = struct {
1155 /// any readable data available
1156 pub const IN = 0x0001;
1157 /// file descriptor is writeable
1158 pub const OUT = 0x0002;
1159 pub const RDNORM = IN;
1160 pub const WRNORM = OUT;
1161 /// priority readable data
1162 pub const RDBAND = 0x0008;
1163 /// priority data can be written
1164 pub const WRBAND = 0x0010;
1165 /// high priority readable data
1166 pub const PRI = 0x0020;
1167
1168 /// errors pending
1169 pub const ERR = 0x0004;
1170 /// disconnected
1171 pub const HUP = 0x0080;
1172 /// invalid file descriptor
1173 pub const NVAL = 0x1000;
1174};
1175
1176// /system/develop/headers/posix/signal.h
1177
1178pub const sigset_t = u64;
1179pub const empty_sigset: sigset_t = 0;
1180pub const filled_sigset = ~@as(sigset_t, 0);
1181
1182pub const SIG = struct {
1183 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
1184 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
1185 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
1186
1187 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
1188
1189 pub const HUP = 1;
1190 pub const INT = 2;
1191 pub const QUIT = 3;
1192 pub const ILL = 4;
1193 pub const CHLD = 5;
1194 pub const ABRT = 6;
1195 pub const IOT = ABRT;
1196 pub const PIPE = 7;
1197 pub const FPE = 8;
1198 pub const KILL = 9;
1199 pub const STOP = 10;
1200 pub const SEGV = 11;
1201 pub const CONT = 12;
1202 pub const TSTP = 13;
1203 pub const ALRM = 14;
1204 pub const TERM = 15;
1205 pub const TTIN = 16;
1206 pub const TTOU = 17;
1207 pub const USR1 = 18;
1208 pub const USR2 = 19;
1209 pub const WINCH = 20;
1210 pub const KILLTHR = 21;
1211 pub const TRAP = 22;
1212 pub const POLL = 23;
1213 pub const PROF = 24;
1214 pub const SYS = 25;
1215 pub const URG = 26;
1216 pub const VTALRM = 27;
1217 pub const XCPU = 28;
1218 pub const XFSZ = 29;
1219 pub const BUS = 30;
1220 pub const RESERVED1 = 31;
1221 pub const RESERVED2 = 32;
1222
1223 pub const BLOCK = 1;
1224 pub const UNBLOCK = 2;
1225 pub const SETMASK = 3;
1226};
1227
1228pub const siginfo_t = extern struct {
1229 signo: i32,
1230 code: i32,
1231 errno: i32,
1232
1233 pid: pid_t,
1234 uid: uid_t,
1235 addr: *allowzero anyopaque,
1236};
1237
1238/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
1239pub const Sigaction = extern struct {
1240 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
1241 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
1242
1243 /// signal handler
1244 handler: extern union {
1245 handler: handler_fn,
1246 sigaction: sigaction_fn,
1247 },
1248
1249 /// signal mask to apply
1250 mask: sigset_t,
1251
1252 /// see signal options
1253 flags: i32,
1254
1255 /// will be passed to the signal handler, BeOS extension
1256 userdata: *allowzero anyopaque = undefined,
1257};
1258
1259pub const SA = struct {
1260 pub const NOCLDSTOP = 0x01;
1261 pub const NOCLDWAIT = 0x02;
1262 pub const RESETHAND = 0x04;
1263 pub const NODEFER = 0x08;
1264 pub const RESTART = 0x10;
1265 pub const ONSTACK = 0x20;
1266 pub const SIGINFO = 0x40;
1267 pub const NOMASK = NODEFER;
1268 pub const STACK = ONSTACK;
1269 pub const ONESHOT = RESETHAND;
1270};
1271
1272pub const SS = struct {
1273 pub const ONSTACK = 0x1;
1274 pub const DISABLE = 0x2;
1275};
1276
1277pub const MINSIGSTKSZ = 8192;
1278pub const SIGSTKSZ = 16384;
1279
1280pub const stack_t = extern struct {
1281 sp: [*]u8,
1282 size: isize,
1283 flags: i32,
1284};
1285
1286pub const NSIG = 65;
1287
1288pub const mcontext_t = vregs;
1289
1290pub const ucontext_t = extern struct {
1291 link: ?*ucontext_t,
1292 sigmask: sigset_t,
1293 stack: stack_t,
1294 mcontext: mcontext_t,
1295};
1296
1297// /system/develop/headers/posix/sys/stat.h
1298
1299pub const Stat = extern struct {
1300 dev: dev_t,
1301 ino: ino_t,
1302 mode: mode_t,
1303 nlink: nlink_t,
1304 uid: uid_t,
1305 gid: gid_t,
1306 size: off_t,
1307 rdev: dev_t,
1308 blksize: blksize_t,
1309 atim: timespec,
1310 mtim: timespec,
1311 ctim: timespec,
1312 crtim: timespec,
1313 type: u32,
1314 blocks: blkcnt_t,
1315
1316 pub fn atime(self: @This()) timespec {
1317 return self.atim;
1318 }
1319 pub fn mtime(self: @This()) timespec {
1320 return self.mtim;
1321 }
1322 pub fn ctime(self: @This()) timespec {
1323 return self.ctim;
1324 }
1325 pub fn birthtime(self: @This()) timespec {
1326 return self.crtim;
1327 }
1328};
1329
1330// /system/develop/headers/posix/sys/types.h
1331
1332pub const blkcnt_t = i64;
1333pub const blksize_t = i32;
1334pub const fsblkcnt_t = i64;
1335pub const fsfilcnt_t = i64;
1336pub const off_t = i64;
1337pub const ino_t = i64;
1338pub const cnt_t = i32;
1339pub const dev_t = i32;
1340pub const pid_t = i32;
1341pub const id_t = i32;
1342
1343pub const uid_t = u32;
1344pub const gid_t = u32;
1345pub const mode_t = u32;
1346pub const umode_t = u32;
1347pub const nlink_t = i32;
1348
1349pub const clockid_t = i32;
1350pub const timer_t = *opaque {};
1351
1352// /system/develop/headers/posix/time.h
1353
1354pub const clock_t = i32;
1355pub const suseconds_t = i32;
1356pub const useconds_t = u32;
1357
1358pub const time_t = isize;
1359
1360pub const CLOCKS_PER_SEC = 1_000_000;
1361pub const CLK_TCK = CLOCKS_PER_SEC;
1362pub const TIME_UTC = 1;
1363
1364pub const CLOCK = struct {
1365 /// system-wide monotonic clock (aka system time)
1366 pub const MONOTONIC: clockid_t = 0;
1367 /// system-wide real time clock
1368 pub const REALTIME: clockid_t = -1;
1369 /// clock measuring the used CPU time of the current process
1370 pub const PROCESS_CPUTIME_ID: clockid_t = -2;
1371 /// clock measuring the used CPU time of the current thread
1372 pub const THREAD_CPUTIME_ID: clockid_t = -3;
1373};
1374
1375pub const timespec = extern struct {
1376 /// seconds
1377 tv_sec: time_t,
1378 /// and nanoseconds
1379 tv_nsec: isize,
1380};
1381
1382pub const itimerspec = extern struct {
1383 interval: timespec,
1384 value: timespec,
1385};
1386
1387// /system/develop/headers/private/system/syscalls.h
1388
1389pub extern "root" fn _kern_get_current_team() team_id;
1390pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t;
1391pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize;
1392pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t;
1393pub extern "root" fn _kern_read_stat(fd: fd_t, path: [*:0]const u8, traverseLink: bool, stat: *Stat, statSize: usize) status_t;
lib/std/c/linux.zig deleted-358
......@@ -1,358 +0,0 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");
3const native_abi = builtin.abi;
4const native_arch = builtin.cpu.arch;
5const linux = std.os.linux;
6const iovec = std.posix.iovec;
7const iovec_const = std.posix.iovec_const;
8const FILE = std.c.FILE;
9
10pub const AF = linux.AF;
11pub const ARCH = linux.ARCH;
12pub const CLOCK = linux.CLOCK;
13pub const CPU_COUNT = linux.CPU_COUNT;
14pub const E = linux.E;
15pub const Elf_Symndx = linux.Elf_Symndx;
16pub const F = linux.F;
17pub const FD_CLOEXEC = linux.FD_CLOEXEC;
18pub const F_OK = linux.F_OK;
19pub const Flock = linux.Flock;
20pub const HOST_NAME_MAX = linux.HOST_NAME_MAX;
21pub const IFNAMESIZE = linux.IFNAMESIZE;
22pub const IOV_MAX = linux.IOV_MAX;
23pub const IPPROTO = linux.IPPROTO;
24pub const LOCK = linux.LOCK;
25pub const MADV = linux.MADV;
26pub const MSF = linux.MSF;
27pub const MMAP2_UNIT = linux.MMAP2_UNIT;
28pub const MSG = linux.MSG;
29pub const NAME_MAX = linux.NAME_MAX;
30pub const PATH_MAX = linux.PATH_MAX;
31pub const POLL = linux.POLL;
32pub const PROT = linux.PROT;
33pub const REG = linux.REG;
34pub const RLIM = linux.RLIM;
35pub const R_OK = linux.R_OK;
36pub const S = linux.S;
37pub const SA = linux.SA;
38pub const SC = linux.SC;
39pub const SEEK = linux.SEEK;
40pub const SHUT = linux.SHUT;
41pub const SIG = linux.SIG;
42pub const SIOCGIFINDEX = linux.SIOCGIFINDEX;
43pub const SO = linux.SO;
44pub const SOCK = linux.SOCK;
45pub const SOL = linux.SOL;
46pub const STDERR_FILENO = linux.STDERR_FILENO;
47pub const STDIN_FILENO = linux.STDIN_FILENO;
48pub const STDOUT_FILENO = linux.STDOUT_FILENO;
49pub const SYS = linux.SYS;
50pub const Sigaction = linux.Sigaction;
51pub const T = linux.T;
52pub const TCP = linux.TCP;
53pub const TCSA = linux.TCSA;
54pub const TFD = linux.TFD;
55pub const VDSO = linux.VDSO;
56pub const W = linux.W;
57pub const W_OK = linux.W_OK;
58pub const X_OK = linux.X_OK;
59pub const addrinfo = linux.addrinfo;
60pub const blkcnt_t = linux.blkcnt_t;
61pub const blksize_t = linux.blksize_t;
62pub const clock_t = linux.clock_t;
63pub const cpu_set_t = linux.cpu_set_t;
64pub const dev_t = linux.dev_t;
65pub const dl_phdr_info = linux.dl_phdr_info;
66pub const empty_sigset = linux.empty_sigset;
67pub const epoll_event = linux.epoll_event;
68pub const fd_t = linux.fd_t;
69pub const gid_t = linux.gid_t;
70pub const ifreq = linux.ifreq;
71pub const ino_t = linux.ino_t;
72pub const itimerspec = linux.itimerspec;
73pub const mcontext_t = linux.mcontext_t;
74pub const mode_t = linux.mode_t;
75pub const msghdr = linux.msghdr;
76pub const msghdr_const = linux.msghdr_const;
77pub const nfds_t = linux.nfds_t;
78pub const nlink_t = linux.nlink_t;
79pub const off_t = linux.off_t;
80pub const perf_event_attr = linux.perf_event_attr;
81pub const pid_t = linux.pid_t;
82pub const pollfd = linux.pollfd;
83pub const rlim_t = linux.rlim_t;
84pub const rlimit = linux.rlimit;
85pub const rlimit_resource = linux.rlimit_resource;
86pub const rusage = linux.rusage;
87pub const siginfo_t = linux.siginfo_t;
88pub const sigset_t = linux.sigset_t;
89pub const sockaddr = linux.sockaddr;
90pub const socklen_t = linux.socklen_t;
91pub const stack_t = linux.stack_t;
92pub const time_t = linux.time_t;
93pub const timespec = linux.timespec;
94pub const timeval = linux.timeval;
95pub const timezone = linux.timezone;
96pub const ucontext_t = linux.ucontext_t;
97pub const uid_t = linux.uid_t;
98pub const user_desc = linux.user_desc;
99pub const utsname = linux.utsname;
100pub const winsize = linux.winsize;
101pub const PR = linux.PR;
102
103pub const _errno = switch (native_abi) {
104 .android => struct {
105 extern fn __errno() *c_int;
106 }.__errno,
107 else => struct {
108 extern "c" fn __errno_location() *c_int;
109 }.__errno_location,
110};
111
112pub const Stat = switch (native_arch) {
113 .sparc64 => extern struct {
114 dev: u64,
115 __pad1: u16,
116 ino: ino_t,
117 mode: u32,
118 nlink: u32,
119
120 uid: u32,
121 gid: u32,
122 rdev: u64,
123 __pad2: u16,
124
125 size: off_t,
126 blksize: isize,
127 blocks: i64,
128
129 atim: timespec,
130 mtim: timespec,
131 ctim: timespec,
132 __reserved: [2]usize,
133
134 pub fn atime(self: @This()) timespec {
135 return self.atim;
136 }
137
138 pub fn mtime(self: @This()) timespec {
139 return self.mtim;
140 }
141
142 pub fn ctime(self: @This()) timespec {
143 return self.ctim;
144 }
145 },
146 .mips, .mipsel => extern struct {
147 dev: dev_t,
148 __pad0: [2]u32,
149 ino: ino_t,
150 mode: mode_t,
151 nlink: nlink_t,
152 uid: uid_t,
153 gid: gid_t,
154 rdev: dev_t,
155 __pad1: [2]u32,
156 size: off_t,
157 atim: timespec,
158 mtim: timespec,
159 ctim: timespec,
160 blksize: blksize_t,
161 __pad3: u32,
162 blocks: blkcnt_t,
163 __pad4: [14]u32,
164
165 pub fn atime(self: @This()) timespec {
166 return self.atim;
167 }
168
169 pub fn mtime(self: @This()) timespec {
170 return self.mtim;
171 }
172
173 pub fn ctime(self: @This()) timespec {
174 return self.ctim;
175 }
176 },
177
178 else => std.os.linux.Stat, // libc stat is the same as kernel stat.
179};
180
181pub const AI = struct {
182 pub const PASSIVE = 0x01;
183 pub const CANONNAME = 0x02;
184 pub const NUMERICHOST = 0x04;
185 pub const V4MAPPED = 0x08;
186 pub const ALL = 0x10;
187 pub const ADDRCONFIG = 0x20;
188 pub const NUMERICSERV = 0x400;
189};
190
191pub const NI = struct {
192 pub const NUMERICHOST = 0x01;
193 pub const NUMERICSERV = 0x02;
194 pub const NOFQDN = 0x04;
195 pub const NAMEREQD = 0x08;
196 pub const DGRAM = 0x10;
197 pub const NUMERICSCOPE = 0x100;
198};
199
200pub const EAI = enum(c_int) {
201 BADFLAGS = -1,
202 NONAME = -2,
203 AGAIN = -3,
204 FAIL = -4,
205 FAMILY = -6,
206 SOCKTYPE = -7,
207 SERVICE = -8,
208 MEMORY = -10,
209 SYSTEM = -11,
210 OVERFLOW = -12,
211
212 NODATA = -5,
213 ADDRFAMILY = -9,
214 INPROGRESS = -100,
215 CANCELED = -101,
216 NOTCANCELED = -102,
217 ALLDONE = -103,
218 INTR = -104,
219 IDN_ENCODE = -105,
220
221 _,
222};
223
224pub const passwd = extern struct {
225 pw_name: ?[*:0]const u8, // username
226 pw_passwd: ?[*:0]const u8, // user password
227 pw_uid: uid_t, // user ID
228 pw_gid: gid_t, // group ID
229 pw_gecos: ?[*:0]const u8, // user information
230 pw_dir: ?[*:0]const u8, // home directory
231 pw_shell: ?[*:0]const u8, // shell program
232};
233
234pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
235pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
236
237pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
238pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
239pub extern "c" fn fstat64(fd: fd_t, buf: *Stat) c_int;
240pub extern "c" fn fstatat64(dirfd: fd_t, noalias path: [*:0]const u8, noalias stat_buf: *Stat, flags: u32) c_int;
241pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;
242pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;
243pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;
244pub extern "c" fn mmap64(addr: ?*align(std.mem.page_size) anyopaque, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: i64) *anyopaque;
245pub extern "c" fn open64(path: [*:0]const u8, oflag: linux.O, ...) c_int;
246pub extern "c" fn openat64(fd: c_int, path: [*:0]const u8, oflag: linux.O, ...) c_int;
247pub extern "c" fn pread64(fd: fd_t, buf: [*]u8, nbyte: usize, offset: i64) isize;
248pub extern "c" fn preadv64(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: i64) isize;
249pub extern "c" fn pwrite64(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: i64) isize;
250pub extern "c" fn pwritev64(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: i64) isize;
251pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: usize) isize;
252pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int;
253
254pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
255pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
256pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
257pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
258pub extern "c" fn epoll_create1(flags: c_uint) c_int;
259pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int;
260pub extern "c" fn epoll_pwait(
261 epfd: fd_t,
262 events: [*]epoll_event,
263 maxevents: c_int,
264 timeout: c_int,
265 sigmask: *const sigset_t,
266) c_int;
267pub extern "c" fn inotify_init1(flags: c_uint) c_int;
268pub extern "c" fn inotify_add_watch(fd: fd_t, pathname: [*:0]const u8, mask: u32) c_int;
269pub extern "c" fn inotify_rm_watch(fd: fd_t, wd: c_int) c_int;
270
271/// See std.elf for constants for this
272pub extern "c" fn getauxval(__type: c_ulong) c_ulong;
273
274pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
275
276pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
277
278pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
279
280pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
281pub extern "c" fn pipe2(fds: *[2]fd_t, flags: linux.O) c_int;
282
283pub extern "c" fn fallocate(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
284
285pub extern "c" fn sendfile(
286 out_fd: fd_t,
287 in_fd: fd_t,
288 offset: ?*off_t,
289 count: usize,
290) isize;
291
292pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize;
293
294pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: c_uint) c_int;
295
296pub extern "c" fn prlimit(pid: pid_t, resource: rlimit_resource, new_limit: *const rlimit, old_limit: *rlimit) c_int;
297pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
298pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
299
300pub extern "c" fn mincore(
301 addr: *align(std.mem.page_size) anyopaque,
302 length: usize,
303 vec: [*]u8,
304) c_int;
305
306pub extern "c" fn madvise(
307 addr: *align(std.mem.page_size) anyopaque,
308 length: usize,
309 advice: c_uint,
310) c_int;
311
312pub const pthread_attr_t = extern struct {
313 __size: [56]u8,
314 __align: c_long,
315};
316
317pub const pthread_key_t = c_uint;
318pub const sem_t = extern struct {
319 __size: [__SIZEOF_SEM_T]u8 align(@alignOf(usize)),
320};
321
322const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
323
324pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
325pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
326
327pub const RTLD = struct {
328 pub const LAZY = 1;
329 pub const NOW = 2;
330 pub const NOLOAD = 4;
331 pub const NODELETE = 4096;
332 pub const GLOBAL = 256;
333 pub const LOCAL = 0;
334};
335
336pub const dirent = extern struct {
337 ino: c_uint,
338 off: c_uint,
339 reclen: c_ushort,
340 type: u8,
341 name: [256]u8,
342};
343pub const dirent64 = extern struct {
344 ino: c_ulong,
345 off: c_ulong,
346 reclen: c_ushort,
347 type: u8,
348 name: [256]u8,
349};
350
351pub extern "c" fn timerfd_create(clockid: c_int, flags: c_int) c_int;
352pub extern "c" fn timerfd_settime(
353 fd: c_int,
354 flags: c_int,
355 new_value: *const itimerspec,
356 old_value: ?*itimerspec,
357) c_int;
358pub extern "c" fn timerfd_gettime(fd: c_int, curr_value: *itimerspec) c_int;
lib/std/c/netbsd.zig+7-1173
......@@ -1,786 +1,14 @@
11const std = @import("../std.zig");
2const assert = std.debug.assert;
3const builtin = @import("builtin");
4const maxInt = std.math.maxInt;
5const iovec = std.posix.iovec;
6const iovec_const = std.posix.iovec_const;
7const timezone = std.c.timezone;
8const rusage = std.c.rusage;
2const clock_t = std.c.clock_t;
3const pid_t = std.c.pid_t;
4const pthread_t = std.c.pthread_t;
5const sigval_t = std.c.sigval_t;
6const uid_t = std.c.uid_t;
97
10extern "c" fn __errno() *c_int;
11pub const _errno = __errno;
12
13pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
14pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
15
16pub extern "c" fn _lwp_self() lwpid_t;
17
18pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
19pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
20
21pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
22pub const getdents = __getdents30;
23
24pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
25pub const sigaltstack = __sigaltstack14;
26
27pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
28
29pub const pthread_spin_t = switch (builtin.cpu.arch) {
30 .aarch64, .aarch64_be, .aarch64_32 => u8,
31 .mips, .mipsel, .mips64, .mips64el => u32,
32 .powerpc, .powerpc64, .powerpc64le => i32,
33 .x86, .x86_64 => u8,
34 .arm, .armeb, .thumb, .thumbeb => i32,
35 .sparc, .sparcel, .sparc64 => u8,
36 .riscv32, .riscv64 => u32,
37 else => @compileError("undefined pthread_spin_t for this arch"),
38};
39
40pub const padded_pthread_spin_t = switch (builtin.cpu.arch) {
41 .x86, .x86_64 => u32,
42 .sparc, .sparcel, .sparc64 => u32,
43 else => pthread_spin_t,
44};
45
46pub const pthread_attr_t = extern struct {
47 pta_magic: u32,
48 pta_flags: i32,
49 pta_private: ?*anyopaque,
50};
51
52pub const sem_t = ?*opaque {};
53
54pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
55pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
56
57pub const blkcnt_t = i64;
58pub const blksize_t = i32;
59pub const clock_t = u32;
60pub const dev_t = u64;
61pub const fd_t = i32;
62pub const gid_t = u32;
63pub const ino_t = u64;
64pub const mode_t = u32;
65pub const nlink_t = u32;
66pub const off_t = i64;
67pub const pid_t = i32;
68pub const socklen_t = u32;
69pub const time_t = i64;
70pub const uid_t = u32;
718pub const lwpid_t = i32;
72pub const suseconds_t = c_int;
73
74/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
75pub const Kevent = extern struct {
76 ident: usize,
77 filter: i32,
78 flags: u32,
79 fflags: u32,
80 data: i64,
81 udata: usize,
82};
83
84pub const RTLD = struct {
85 pub const LAZY = 1;
86 pub const NOW = 2;
87 pub const GLOBAL = 0x100;
88 pub const LOCAL = 0x200;
89 pub const NODELETE = 0x01000;
90 pub const NOLOAD = 0x02000;
91
92 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
93 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
94 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
95};
96
97pub const dl_phdr_info = extern struct {
98 dlpi_addr: usize,
99 dlpi_name: ?[*:0]const u8,
100 dlpi_phdr: [*]std.elf.Phdr,
101 dlpi_phnum: u16,
102};
103
104pub const Flock = extern struct {
105 start: off_t,
106 len: off_t,
107 pid: pid_t,
108 type: i16,
109 whence: i16,
110};
111
112pub const addrinfo = extern struct {
113 flags: i32,
114 family: i32,
115 socktype: i32,
116 protocol: i32,
117 addrlen: socklen_t,
118 canonname: ?[*:0]u8,
119 addr: ?*sockaddr,
120 next: ?*addrinfo,
121};
122
123pub const EAI = enum(c_int) {
124 /// address family for hostname not supported
125 ADDRFAMILY = 1,
126
127 /// name could not be resolved at this time
128 AGAIN = 2,
129
130 /// flags parameter had an invalid value
131 BADFLAGS = 3,
132
133 /// non-recoverable failure in name resolution
134 FAIL = 4,
135
136 /// address family not recognized
137 FAMILY = 5,
138
139 /// memory allocation failure
140 MEMORY = 6,
141
142 /// no address associated with hostname
143 NODATA = 7,
144
145 /// name does not resolve
146 NONAME = 8,
147
148 /// service not recognized for socket type
149 SERVICE = 9,
150
151 /// intended socket type was not recognized
152 SOCKTYPE = 10,
153
154 /// system error returned in errno
155 SYSTEM = 11,
156
157 /// invalid value for hints
158 BADHINTS = 12,
159
160 /// resolved protocol is unknown
161 PROTOCOL = 13,
162
163 /// argument buffer overflow
164 OVERFLOW = 14,
165
166 _,
167};
168
169pub const EAI_MAX = 15;
170
171pub const msghdr = extern struct {
172 /// optional address
173 msg_name: ?*sockaddr,
174
175 /// size of address
176 msg_namelen: socklen_t,
177
178 /// scatter/gather array
179 msg_iov: [*]iovec,
180
181 /// # elements in msg_iov
182 msg_iovlen: i32,
183
184 /// ancillary data
185 msg_control: ?*anyopaque,
186
187 /// ancillary data buffer len
188 msg_controllen: socklen_t,
189
190 /// flags on received message
191 msg_flags: i32,
192};
193
194pub const msghdr_const = extern struct {
195 /// optional address
196 msg_name: ?*const sockaddr,
197
198 /// size of address
199 msg_namelen: socklen_t,
200
201 /// scatter/gather array
202 msg_iov: [*]const iovec_const,
203
204 /// # elements in msg_iov
205 msg_iovlen: i32,
206
207 /// ancillary data
208 msg_control: ?*const anyopaque,
209
210 /// ancillary data buffer len
211 msg_controllen: socklen_t,
212
213 /// flags on received message
214 msg_flags: i32,
215};
216
217/// The stat structure used by libc.
218pub const Stat = extern struct {
219 dev: dev_t,
220 mode: mode_t,
221 ino: ino_t,
222 nlink: nlink_t,
223 uid: uid_t,
224 gid: gid_t,
225 rdev: dev_t,
226 atim: timespec,
227 mtim: timespec,
228 ctim: timespec,
229 birthtim: timespec,
230 size: off_t,
231 blocks: blkcnt_t,
232 blksize: blksize_t,
233 flags: u32,
234 gen: u32,
235 __spare: [2]u32,
236
237 pub fn atime(self: @This()) timespec {
238 return self.atim;
239 }
240
241 pub fn mtime(self: @This()) timespec {
242 return self.mtim;
243 }
244
245 pub fn ctime(self: @This()) timespec {
246 return self.ctim;
247 }
248
249 pub fn birthtime(self: @This()) timespec {
250 return self.birthtim;
251 }
252};
253
254pub const timespec = extern struct {
255 tv_sec: i64,
256 tv_nsec: isize,
257};
258
259pub const timeval = extern struct {
260 /// seconds
261 tv_sec: time_t,
262 /// microseconds
263 tv_usec: suseconds_t,
264};
265
266pub const MAXNAMLEN = 511;
267
268pub const dirent = extern struct {
269 fileno: ino_t,
270 reclen: u16,
271 namlen: u16,
272 type: u8,
273 name: [MAXNAMLEN + 1]u8,
274};
275
276pub const SOCK = struct {
277 pub const STREAM = 1;
278 pub const DGRAM = 2;
279 pub const RAW = 3;
280 pub const RDM = 4;
281 pub const SEQPACKET = 5;
282 pub const CONN_DGRAM = 6;
283 pub const DCCP = CONN_DGRAM;
284
285 pub const CLOEXEC = 0x10000000;
286 pub const NONBLOCK = 0x20000000;
287 pub const NOSIGPIPE = 0x40000000;
288 pub const FLAGS_MASK = 0xf0000000;
289};
290
291pub const SO = struct {
292 pub const DEBUG = 0x0001;
293 pub const ACCEPTCONN = 0x0002;
294 pub const REUSEADDR = 0x0004;
295 pub const KEEPALIVE = 0x0008;
296 pub const DONTROUTE = 0x0010;
297 pub const BROADCAST = 0x0020;
298 pub const USELOOPBACK = 0x0040;
299 pub const LINGER = 0x0080;
300 pub const OOBINLINE = 0x0100;
301 pub const REUSEPORT = 0x0200;
302 pub const NOSIGPIPE = 0x0800;
303 pub const ACCEPTFILTER = 0x1000;
304 pub const TIMESTAMP = 0x2000;
305 pub const RERROR = 0x4000;
306
307 pub const SNDBUF = 0x1001;
308 pub const RCVBUF = 0x1002;
309 pub const SNDLOWAT = 0x1003;
310 pub const RCVLOWAT = 0x1004;
311 pub const ERROR = 0x1007;
312 pub const TYPE = 0x1008;
313 pub const OVERFLOWED = 0x1009;
314
315 pub const NOHEADER = 0x100a;
316 pub const SNDTIMEO = 0x100b;
317 pub const RCVTIMEO = 0x100c;
318};
319
320pub const SOL = struct {
321 pub const SOCKET = 0xffff;
322};
323
324pub const PF = struct {
325 pub const UNSPEC = AF.UNSPEC;
326 pub const LOCAL = AF.LOCAL;
327 pub const UNIX = PF.LOCAL;
328 pub const INET = AF.INET;
329 pub const IMPLINK = AF.IMPLINK;
330 pub const PUP = AF.PUP;
331 pub const CHAOS = AF.CHAOS;
332 pub const NS = AF.NS;
333 pub const ISO = AF.ISO;
334 pub const OSI = AF.ISO;
335 pub const ECMA = AF.ECMA;
336 pub const DATAKIT = AF.DATAKIT;
337 pub const CCITT = AF.CCITT;
338 pub const SNA = AF.SNA;
339 pub const DECnet = AF.DECnet;
340 pub const DLI = AF.DLI;
341 pub const LAT = AF.LAT;
342 pub const HYLINK = AF.HYLINK;
343 pub const APPLETALK = AF.APPLETALK;
344 pub const OROUTE = AF.OROUTE;
345 pub const LINK = AF.LINK;
346 pub const COIP = AF.COIP;
347 pub const CNT = AF.CNT;
348 pub const INET6 = AF.INET6;
349 pub const IPX = AF.IPX;
350 pub const ISDN = AF.ISDN;
351 pub const E164 = AF.E164;
352 pub const NATM = AF.NATM;
353 pub const ARP = AF.ARP;
354 pub const BLUETOOTH = AF.BLUETOOTH;
355 pub const MPLS = AF.MPLS;
356 pub const ROUTE = AF.ROUTE;
357 pub const CAN = AF.CAN;
358 pub const ETHER = AF.ETHER;
359 pub const MAX = AF.MAX;
360};
361
362pub const AF = struct {
363 pub const UNSPEC = 0;
364 pub const LOCAL = 1;
365 pub const UNIX = LOCAL;
366 pub const INET = 2;
367 pub const IMPLINK = 3;
368 pub const PUP = 4;
369 pub const CHAOS = 5;
370 pub const NS = 6;
371 pub const ISO = 7;
372 pub const OSI = ISO;
373 pub const ECMA = 8;
374 pub const DATAKIT = 9;
375 pub const CCITT = 10;
376 pub const SNA = 11;
377 pub const DECnet = 12;
378 pub const DLI = 13;
379 pub const LAT = 14;
380 pub const HYLINK = 15;
381 pub const APPLETALK = 16;
382 pub const OROUTE = 17;
383 pub const LINK = 18;
384 pub const COIP = 20;
385 pub const CNT = 21;
386 pub const IPX = 23;
387 pub const INET6 = 24;
388 pub const ISDN = 26;
389 pub const E164 = ISDN;
390 pub const NATM = 27;
391 pub const ARP = 28;
392 pub const BLUETOOTH = 31;
393 pub const IEEE80211 = 32;
394 pub const MPLS = 33;
395 pub const ROUTE = 34;
396 pub const CAN = 35;
397 pub const ETHER = 36;
398 pub const MAX = 37;
399};
400
401pub const in_port_t = u16;
402pub const sa_family_t = u8;
403
404pub const sockaddr = extern struct {
405 /// total length
406 len: u8,
407 /// address family
408 family: sa_family_t,
409 /// actually longer; address value
410 data: [14]u8,
411
412 pub const SS_MAXSIZE = 128;
413 pub const storage = extern struct {
414 len: u8 align(8),
415 family: sa_family_t,
416 padding: [126]u8 = undefined,
417
418 comptime {
419 assert(@sizeOf(storage) == SS_MAXSIZE);
420 assert(@alignOf(storage) == 8);
421 }
422 };
423
424 pub const in = extern struct {
425 len: u8 = @sizeOf(in),
426 family: sa_family_t = AF.INET,
427 port: in_port_t,
428 addr: u32,
429 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
430 };
431
432 pub const in6 = extern struct {
433 len: u8 = @sizeOf(in6),
434 family: sa_family_t = AF.INET6,
435 port: in_port_t,
436 flowinfo: u32,
437 addr: [16]u8,
438 scope_id: u32,
439 };
440
441 /// Definitions for UNIX IPC domain.
442 pub const un = extern struct {
443 /// total sockaddr length
444 len: u8 = @sizeOf(un),
445
446 family: sa_family_t = AF.LOCAL,
447
448 /// path name
449 path: [104]u8,
450 };
451};
452
453pub const IFNAMESIZE = 16;
454
455pub const AI = struct {
456 /// get address to use bind()
457 pub const PASSIVE = 0x00000001;
458 /// fill ai_canonname
459 pub const CANONNAME = 0x00000002;
460 /// prevent host name resolution
461 pub const NUMERICHOST = 0x00000004;
462 /// prevent service name resolution
463 pub const NUMERICSERV = 0x00000008;
464 /// only if any address is assigned
465 pub const ADDRCONFIG = 0x00000400;
466};
467
468pub const CTL = struct {
469 pub const KERN = 1;
470 pub const DEBUG = 5;
471};
472
473pub const KERN = struct {
474 pub const PROC_ARGS = 48; // struct: process argv/env
475 pub const PROC_PATHNAME = 5; // path to executable
476 pub const IOV_MAX = 38;
477};
478
479pub const PATH_MAX = 1024;
480pub const NAME_MAX = 255;
481pub const IOV_MAX = KERN.IOV_MAX;
482
483pub const STDIN_FILENO = 0;
484pub const STDOUT_FILENO = 1;
485pub const STDERR_FILENO = 2;
486
487pub const PROT = struct {
488 pub const NONE = 0;
489 pub const READ = 1;
490 pub const WRITE = 2;
491 pub const EXEC = 4;
492};
493
494pub const CLOCK = struct {
495 pub const REALTIME = 0;
496 pub const VIRTUAL = 1;
497 pub const PROF = 2;
498 pub const MONOTONIC = 3;
499 pub const THREAD_CPUTIME_ID = 0x20000000;
500 pub const PROCESS_CPUTIME_ID = 0x40000000;
501};
502
503pub const MSF = struct {
504 pub const ASYNC = 1;
505 pub const INVALIDATE = 2;
506 pub const SYNC = 4;
507};
508
509pub const W = struct {
510 pub const NOHANG = 0x00000001;
511 pub const UNTRACED = 0x00000002;
512 pub const STOPPED = UNTRACED;
513 pub const CONTINUED = 0x00000010;
514 pub const NOWAIT = 0x00010000;
515 pub const EXITED = 0x00000020;
516 pub const TRAPPED = 0x00000040;
517
518 pub fn EXITSTATUS(s: u32) u8 {
519 return @as(u8, @intCast((s >> 8) & 0xff));
520 }
521 pub fn TERMSIG(s: u32) u32 {
522 return s & 0x7f;
523 }
524 pub fn STOPSIG(s: u32) u32 {
525 return EXITSTATUS(s);
526 }
527 pub fn IFEXITED(s: u32) bool {
528 return TERMSIG(s) == 0;
529 }
5309
531 pub fn IFCONTINUED(s: u32) bool {
532 return ((s & 0x7f) == 0xffff);
533 }
534
535 pub fn IFSTOPPED(s: u32) bool {
536 return ((s & 0x7f != 0x7f) and !IFCONTINUED(s));
537 }
538
539 pub fn IFSIGNALED(s: u32) bool {
540 return !IFSTOPPED(s) and !IFCONTINUED(s) and !IFEXITED(s);
541 }
542};
543
544pub const SA = struct {
545 pub const ONSTACK = 0x0001;
546 pub const RESTART = 0x0002;
547 pub const RESETHAND = 0x0004;
548 pub const NOCLDSTOP = 0x0008;
549 pub const NODEFER = 0x0010;
550 pub const NOCLDWAIT = 0x0020;
551 pub const SIGINFO = 0x0040;
552};
553
554// access function
555pub const F_OK = 0; // test for existence of file
556pub const X_OK = 1; // test for execute or search permission
557pub const W_OK = 2; // test for write permission
558pub const R_OK = 4; // test for read permission
559
560pub const F = struct {
561 pub const DUPFD = 0;
562 pub const GETFD = 1;
563 pub const SETFD = 2;
564 pub const GETFL = 3;
565 pub const SETFL = 4;
566 pub const GETOWN = 5;
567 pub const SETOWN = 6;
568 pub const GETLK = 7;
569 pub const SETLK = 8;
570 pub const SETLKW = 9;
571 pub const CLOSEM = 10;
572 pub const MAXFD = 11;
573 pub const DUPFD_CLOEXEC = 12;
574 pub const GETNOSIGPIPE = 13;
575 pub const SETNOSIGPIPE = 14;
576 pub const GETPATH = 15;
577
578 pub const RDLCK = 1;
579 pub const WRLCK = 3;
580 pub const UNLCK = 2;
581};
582
583pub const LOCK = struct {
584 pub const SH = 1;
585 pub const EX = 2;
586 pub const UN = 8;
587 pub const NB = 4;
588};
589
590pub const FD_CLOEXEC = 1;
591
592pub const SEEK = struct {
593 pub const SET = 0;
594 pub const CUR = 1;
595 pub const END = 2;
596};
597
598pub const DT = struct {
599 pub const UNKNOWN = 0;
600 pub const FIFO = 1;
601 pub const CHR = 2;
602 pub const DIR = 4;
603 pub const BLK = 6;
604 pub const REG = 8;
605 pub const LNK = 10;
606 pub const SOCK = 12;
607 pub const WHT = 14;
608};
609
610/// add event to kq (implies enable)
611pub const EV_ADD = 0x0001;
612
613/// delete event from kq
614pub const EV_DELETE = 0x0002;
615
616/// enable event
617pub const EV_ENABLE = 0x0004;
618
619/// disable event (not reported)
620pub const EV_DISABLE = 0x0008;
621
622/// only report one occurrence
623pub const EV_ONESHOT = 0x0010;
624
625/// clear event state after reporting
626pub const EV_CLEAR = 0x0020;
627
628/// force immediate event output
629/// ... with or without EV_ERROR
630/// ... use KEVENT_FLAG_ERROR_EVENTS
631/// on syscalls supporting flags
632pub const EV_RECEIPT = 0x0040;
633
634/// disable event after reporting
635pub const EV_DISPATCH = 0x0080;
636
637pub const EVFILT_READ = 0;
638pub const EVFILT_WRITE = 1;
639
640/// attached to aio requests
641pub const EVFILT_AIO = 2;
642
643/// attached to vnodes
644pub const EVFILT_VNODE = 3;
645
646/// attached to struct proc
647pub const EVFILT_PROC = 4;
648
649/// attached to struct proc
650pub const EVFILT_SIGNAL = 5;
651
652/// timers
653pub const EVFILT_TIMER = 6;
654
655/// Filesystem events
656pub const EVFILT_FS = 7;
657
658/// User events
659pub const EVFILT_USER = 1;
660
661/// On input, NOTE_TRIGGER causes the event to be triggered for output.
662pub const NOTE_TRIGGER = 0x08000000;
663
664/// low water mark
665pub const NOTE_LOWAT = 0x00000001;
666
667/// vnode was removed
668pub const NOTE_DELETE = 0x00000001;
669
670/// data contents changed
671pub const NOTE_WRITE = 0x00000002;
672
673/// size increased
674pub const NOTE_EXTEND = 0x00000004;
675
676/// attributes changed
677pub const NOTE_ATTRIB = 0x00000008;
678
679/// link count changed
680pub const NOTE_LINK = 0x00000010;
681
682/// vnode was renamed
683pub const NOTE_RENAME = 0x00000020;
684
685/// vnode access was revoked
686pub const NOTE_REVOKE = 0x00000040;
687
688/// process exited
689pub const NOTE_EXIT = 0x80000000;
690
691/// process forked
692pub const NOTE_FORK = 0x40000000;
693
694/// process exec'd
695pub const NOTE_EXEC = 0x20000000;
696
697/// mask for signal & exit status
698pub const NOTE_PDATAMASK = 0x000fffff;
699pub const NOTE_PCTRLMASK = 0xf0000000;
700
701pub const T = struct {
702 pub const IOCCBRK = 0x2000747a;
703 pub const IOCCDTR = 0x20007478;
704 pub const IOCCONS = 0x80047462;
705 pub const IOCDCDTIMESTAMP = 0x40107458;
706 pub const IOCDRAIN = 0x2000745e;
707 pub const IOCEXCL = 0x2000740d;
708 pub const IOCEXT = 0x80047460;
709 pub const IOCFLAG_CDTRCTS = 0x10;
710 pub const IOCFLAG_CLOCAL = 0x2;
711 pub const IOCFLAG_CRTSCTS = 0x4;
712 pub const IOCFLAG_MDMBUF = 0x8;
713 pub const IOCFLAG_SOFTCAR = 0x1;
714 pub const IOCFLUSH = 0x80047410;
715 pub const IOCGETA = 0x402c7413;
716 pub const IOCGETD = 0x4004741a;
717 pub const IOCGFLAGS = 0x4004745d;
718 pub const IOCGLINED = 0x40207442;
719 pub const IOCGPGRP = 0x40047477;
720 pub const IOCGQSIZE = 0x40047481;
721 pub const IOCGRANTPT = 0x20007447;
722 pub const IOCGSID = 0x40047463;
723 pub const IOCGSIZE = 0x40087468;
724 pub const IOCGWINSZ = 0x40087468;
725 pub const IOCMBIC = 0x8004746b;
726 pub const IOCMBIS = 0x8004746c;
727 pub const IOCMGET = 0x4004746a;
728 pub const IOCMSET = 0x8004746d;
729 pub const IOCM_CAR = 0x40;
730 pub const IOCM_CD = 0x40;
731 pub const IOCM_CTS = 0x20;
732 pub const IOCM_DSR = 0x100;
733 pub const IOCM_DTR = 0x2;
734 pub const IOCM_LE = 0x1;
735 pub const IOCM_RI = 0x80;
736 pub const IOCM_RNG = 0x80;
737 pub const IOCM_RTS = 0x4;
738 pub const IOCM_SR = 0x10;
739 pub const IOCM_ST = 0x8;
740 pub const IOCNOTTY = 0x20007471;
741 pub const IOCNXCL = 0x2000740e;
742 pub const IOCOUTQ = 0x40047473;
743 pub const IOCPKT = 0x80047470;
744 pub const IOCPKT_DATA = 0x0;
745 pub const IOCPKT_DOSTOP = 0x20;
746 pub const IOCPKT_FLUSHREAD = 0x1;
747 pub const IOCPKT_FLUSHWRITE = 0x2;
748 pub const IOCPKT_IOCTL = 0x40;
749 pub const IOCPKT_NOSTOP = 0x10;
750 pub const IOCPKT_START = 0x8;
751 pub const IOCPKT_STOP = 0x4;
752 pub const IOCPTMGET = 0x40287446;
753 pub const IOCPTSNAME = 0x40287448;
754 pub const IOCRCVFRAME = 0x80087445;
755 pub const IOCREMOTE = 0x80047469;
756 pub const IOCSBRK = 0x2000747b;
757 pub const IOCSCTTY = 0x20007461;
758 pub const IOCSDTR = 0x20007479;
759 pub const IOCSETA = 0x802c7414;
760 pub const IOCSETAF = 0x802c7416;
761 pub const IOCSETAW = 0x802c7415;
762 pub const IOCSETD = 0x8004741b;
763 pub const IOCSFLAGS = 0x8004745c;
764 pub const IOCSIG = 0x2000745f;
765 pub const IOCSLINED = 0x80207443;
766 pub const IOCSPGRP = 0x80047476;
767 pub const IOCSQSIZE = 0x80047480;
768 pub const IOCSSIZE = 0x80087467;
769 pub const IOCSTART = 0x2000746e;
770 pub const IOCSTAT = 0x80047465;
771 pub const IOCSTI = 0x80017472;
772 pub const IOCSTOP = 0x2000746f;
773 pub const IOCSWINSZ = 0x80087467;
774 pub const IOCUCNTL = 0x80047466;
775 pub const IOCXMTFRAME = 0x80087444;
776};
777
778pub const TCSA = enum(c_uint) {
779 NOW,
780 DRAIN,
781 FLUSH,
782 _,
783};
10pub extern "c" fn _lwp_self() lwpid_t;
11pub extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
78412
78513pub const TCIFLUSH = 1;
78614pub const TCOFLUSH = 2;
......@@ -790,104 +18,6 @@ pub const TCOON = 2;
79018pub const TCIOFF = 3;
79119pub const TCION = 4;
79220
793pub const winsize = extern struct {
794 ws_row: u16,
795 ws_col: u16,
796 ws_xpixel: u16,
797 ws_ypixel: u16,
798};
799
800const NSIG = 32;
801
802pub const SIG = struct {
803 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
804 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
805 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
806
807 pub const WORDS = 4;
808 pub const MAXSIG = 128;
809
810 pub const BLOCK = 1;
811 pub const UNBLOCK = 2;
812 pub const SETMASK = 3;
813
814 pub const HUP = 1;
815 pub const INT = 2;
816 pub const QUIT = 3;
817 pub const ILL = 4;
818 pub const TRAP = 5;
819 pub const ABRT = 6;
820 pub const IOT = ABRT;
821 pub const EMT = 7;
822 pub const FPE = 8;
823 pub const KILL = 9;
824 pub const BUS = 10;
825 pub const SEGV = 11;
826 pub const SYS = 12;
827 pub const PIPE = 13;
828 pub const ALRM = 14;
829 pub const TERM = 15;
830 pub const URG = 16;
831 pub const STOP = 17;
832 pub const TSTP = 18;
833 pub const CONT = 19;
834 pub const CHLD = 20;
835 pub const TTIN = 21;
836 pub const TTOU = 22;
837 pub const IO = 23;
838 pub const XCPU = 24;
839 pub const XFSZ = 25;
840 pub const VTALRM = 26;
841 pub const PROF = 27;
842 pub const WINCH = 28;
843 pub const INFO = 29;
844 pub const USR1 = 30;
845 pub const USR2 = 31;
846 pub const PWR = 32;
847
848 pub const RTMIN = 33;
849 pub const RTMAX = 63;
850
851 pub inline fn IDX(sig: usize) usize {
852 return sig - 1;
853 }
854 pub inline fn WORD(sig: usize) usize {
855 return IDX(sig) >> 5;
856 }
857 pub inline fn BIT(sig: usize) usize {
858 return 1 << (IDX(sig) & 31);
859 }
860 pub inline fn VALID(sig: usize) usize {
861 return sig <= MAXSIG and sig > 0;
862 }
863};
864
865/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
866pub const Sigaction = extern struct {
867 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
868 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
869
870 /// signal handler
871 handler: extern union {
872 handler: ?handler_fn,
873 sigaction: ?sigaction_fn,
874 },
875 /// signal mask to apply
876 mask: sigset_t,
877 /// signal options
878 flags: c_uint,
879};
880
881pub const sigval_t = extern union {
882 int: i32,
883 ptr: ?*anyopaque,
884};
885
886pub const siginfo_t = extern union {
887 pad: [128]u8,
888 info: _ksiginfo,
889};
890
89121pub const _ksiginfo = extern struct {
89222 signo: i32,
89323 code: i32,
......@@ -933,85 +63,6 @@ pub const _ksiginfo = extern struct {
93363 } align(@sizeOf(usize)),
93464};
93565
936pub const sigset_t = extern struct {
937 __bits: [SIG.WORDS]u32,
938};
939
940pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
941
942pub const mcontext_t = switch (builtin.cpu.arch) {
943 .aarch64 => extern struct {
944 gregs: [35]u64,
945 fregs: [528]u8 align(16),
946 spare: [8]u64,
947 },
948 .x86_64 => extern struct {
949 gregs: [26]u64,
950 mc_tlsbase: u64,
951 fpregs: [512]u8 align(8),
952 },
953 else => struct {},
954};
955
956pub const REG = switch (builtin.cpu.arch) {
957 .aarch64 => struct {
958 pub const FP = 29;
959 pub const SP = 31;
960 pub const PC = 32;
961 },
962 .arm => struct {
963 pub const FP = 11;
964 pub const SP = 13;
965 pub const PC = 15;
966 },
967 .x86_64 => struct {
968 pub const RDI = 0;
969 pub const RSI = 1;
970 pub const RDX = 2;
971 pub const RCX = 3;
972 pub const R8 = 4;
973 pub const R9 = 5;
974 pub const R10 = 6;
975 pub const R11 = 7;
976 pub const R12 = 8;
977 pub const R13 = 9;
978 pub const R14 = 10;
979 pub const R15 = 11;
980 pub const RBP = 12;
981 pub const RBX = 13;
982 pub const RAX = 14;
983 pub const GS = 15;
984 pub const FS = 16;
985 pub const ES = 17;
986 pub const DS = 18;
987 pub const TRAPNO = 19;
988 pub const ERR = 20;
989 pub const RIP = 21;
990 pub const CS = 22;
991 pub const RFLAGS = 23;
992 pub const RSP = 24;
993 pub const SS = 25;
994 },
995 else => struct {},
996};
997
998pub const ucontext_t = extern struct {
999 flags: u32,
1000 link: ?*ucontext_t,
1001 sigmask: sigset_t,
1002 stack: stack_t,
1003 mcontext: mcontext_t,
1004 __pad: [
1005 switch (builtin.cpu.arch) {
1006 .x86 => 4,
1007 .mips, .mipsel, .mips64, .mips64el => 14,
1008 .arm, .armeb, .thumb, .thumbeb => 1,
1009 .sparc, .sparcel, .sparc64 => if (@sizeOf(usize) == 4) 43 else 8,
1010 else => 0,
1011 }
1012 ]u32,
1013};
1014
101566pub const E = enum(u16) {
101667 /// No error occurred.
101768 SUCCESS = 0,
......@@ -1150,220 +201,3 @@ pub const E = enum(u16) {
1150201
1151202 _,
1152203};
1153
1154pub const MINSIGSTKSZ = 8192;
1155pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
1156
1157pub const SS_ONSTACK = 1;
1158pub const SS_DISABLE = 4;
1159
1160pub const stack_t = extern struct {
1161 sp: [*]u8,
1162 size: isize,
1163 flags: i32,
1164};
1165
1166pub const S = struct {
1167 pub const IFMT = 0o170000;
1168
1169 pub const IFIFO = 0o010000;
1170 pub const IFCHR = 0o020000;
1171 pub const IFDIR = 0o040000;
1172 pub const IFBLK = 0o060000;
1173 pub const IFREG = 0o100000;
1174 pub const IFLNK = 0o120000;
1175 pub const IFSOCK = 0o140000;
1176 pub const IFWHT = 0o160000;
1177
1178 pub const ISUID = 0o4000;
1179 pub const ISGID = 0o2000;
1180 pub const ISVTX = 0o1000;
1181 pub const IRWXU = 0o700;
1182 pub const IRUSR = 0o400;
1183 pub const IWUSR = 0o200;
1184 pub const IXUSR = 0o100;
1185 pub const IRWXG = 0o070;
1186 pub const IRGRP = 0o040;
1187 pub const IWGRP = 0o020;
1188 pub const IXGRP = 0o010;
1189 pub const IRWXO = 0o007;
1190 pub const IROTH = 0o004;
1191 pub const IWOTH = 0o002;
1192 pub const IXOTH = 0o001;
1193
1194 pub fn ISFIFO(m: u32) bool {
1195 return m & IFMT == IFIFO;
1196 }
1197
1198 pub fn ISCHR(m: u32) bool {
1199 return m & IFMT == IFCHR;
1200 }
1201
1202 pub fn ISDIR(m: u32) bool {
1203 return m & IFMT == IFDIR;
1204 }
1205
1206 pub fn ISBLK(m: u32) bool {
1207 return m & IFMT == IFBLK;
1208 }
1209
1210 pub fn ISREG(m: u32) bool {
1211 return m & IFMT == IFREG;
1212 }
1213
1214 pub fn ISLNK(m: u32) bool {
1215 return m & IFMT == IFLNK;
1216 }
1217
1218 pub fn ISSOCK(m: u32) bool {
1219 return m & IFMT == IFSOCK;
1220 }
1221
1222 pub fn IWHT(m: u32) bool {
1223 return m & IFMT == IFWHT;
1224 }
1225};
1226
1227pub const HOST_NAME_MAX = 255;
1228
1229pub const IPPROTO = struct {
1230 /// dummy for IP
1231 pub const IP = 0;
1232 /// IP6 hop-by-hop options
1233 pub const HOPOPTS = 0;
1234 /// control message protocol
1235 pub const ICMP = 1;
1236 /// group mgmt protocol
1237 pub const IGMP = 2;
1238 /// gateway^2 (deprecated)
1239 pub const GGP = 3;
1240 /// IP header
1241 pub const IPV4 = 4;
1242 /// IP inside IP
1243 pub const IPIP = 4;
1244 /// tcp
1245 pub const TCP = 6;
1246 /// exterior gateway protocol
1247 pub const EGP = 8;
1248 /// pup
1249 pub const PUP = 12;
1250 /// user datagram protocol
1251 pub const UDP = 17;
1252 /// xns idp
1253 pub const IDP = 22;
1254 /// tp-4 w/ class negotiation
1255 pub const TP = 29;
1256 /// DCCP
1257 pub const DCCP = 33;
1258 /// IP6 header
1259 pub const IPV6 = 41;
1260 /// IP6 routing header
1261 pub const ROUTING = 43;
1262 /// IP6 fragmentation header
1263 pub const FRAGMENT = 44;
1264 /// resource reservation
1265 pub const RSVP = 46;
1266 /// GRE encaps RFC 1701
1267 pub const GRE = 47;
1268 /// encap. security payload
1269 pub const ESP = 50;
1270 /// authentication header
1271 pub const AH = 51;
1272 /// IP Mobility RFC 2004
1273 pub const MOBILE = 55;
1274 /// IPv6 ICMP
1275 pub const IPV6_ICMP = 58;
1276 /// ICMP6
1277 pub const ICMPV6 = 58;
1278 /// IP6 no next header
1279 pub const NONE = 59;
1280 /// IP6 destination option
1281 pub const DSTOPTS = 60;
1282 /// ISO cnlp
1283 pub const EON = 80;
1284 /// Ethernet-in-IP
1285 pub const ETHERIP = 97;
1286 /// encapsulation header
1287 pub const ENCAP = 98;
1288 /// Protocol indep. multicast
1289 pub const PIM = 103;
1290 /// IP Payload Comp. Protocol
1291 pub const IPCOMP = 108;
1292 /// VRRP RFC 2338
1293 pub const VRRP = 112;
1294 /// Common Address Resolution Protocol
1295 pub const CARP = 112;
1296 /// L2TPv3
1297 pub const L2TP = 115;
1298 /// SCTP
1299 pub const SCTP = 132;
1300 /// PFSYNC
1301 pub const PFSYNC = 240;
1302 /// raw IP packet
1303 pub const RAW = 255;
1304};
1305
1306pub const rlimit_resource = enum(c_int) {
1307 CPU = 0,
1308 FSIZE = 1,
1309 DATA = 2,
1310 STACK = 3,
1311 CORE = 4,
1312 RSS = 5,
1313 MEMLOCK = 6,
1314 NPROC = 7,
1315 NOFILE = 8,
1316 SBSIZE = 9,
1317 VMEM = 10,
1318 NTHR = 11,
1319 _,
1320
1321 pub const AS: rlimit_resource = .VMEM;
1322};
1323
1324pub const rlim_t = u64;
1325
1326pub const RLIM = struct {
1327 /// No limit
1328 pub const INFINITY: rlim_t = (1 << 63) - 1;
1329
1330 pub const SAVED_MAX = INFINITY;
1331 pub const SAVED_CUR = INFINITY;
1332};
1333
1334pub const rlimit = extern struct {
1335 /// Soft limit
1336 cur: rlim_t,
1337 /// Hard limit
1338 max: rlim_t,
1339};
1340
1341pub const SHUT = struct {
1342 pub const RD = 0;
1343 pub const WR = 1;
1344 pub const RDWR = 2;
1345};
1346
1347pub const nfds_t = u32;
1348
1349pub const pollfd = extern struct {
1350 fd: fd_t,
1351 events: i16,
1352 revents: i16,
1353};
1354
1355pub const POLL = struct {
1356 /// Testable events (may be specified in events field).
1357 pub const IN = 0x0001;
1358 pub const PRI = 0x0002;
1359 pub const OUT = 0x0004;
1360 pub const RDNORM = 0x0040;
1361 pub const WRNORM = OUT;
1362 pub const RDBAND = 0x0080;
1363 pub const WRBAND = 0x0100;
1364
1365 /// Non-testable events (may not be specified in events field).
1366 pub const ERR = 0x0008;
1367 pub const HUP = 0x0010;
1368 pub const NVAL = 0x0020;
1369};
lib/std/c/openbsd.zig+36-1106
......@@ -4,50 +4,35 @@ const maxInt = std.math.maxInt;
44const builtin = @import("builtin");
55const iovec = std.posix.iovec;
66const iovec_const = std.posix.iovec_const;
7const passwd = std.c.passwd;
8const timespec = std.c.timespec;
9const uid_t = std.c.uid_t;
10const pid_t = std.c.pid_t;
711
8extern "c" fn __errno() *c_int;
9pub const _errno = __errno;
10
11pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
12pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
13
14pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
15
16pub extern "c" fn getthrid() pid_t;
17pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
18
19pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
20pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
12comptime {
13 assert(builtin.os.tag == .openbsd); // Prevent access of std.c symbols on wrong OS.
14}
2115
2216pub const pthread_spinlock_t = extern struct {
2317 inner: ?*anyopaque = null,
2418};
25pub const pthread_attr_t = extern struct {
26 inner: ?*anyopaque = null,
27};
28pub const pthread_key_t = c_int;
29
30pub const sem_t = ?*opaque {};
31
32pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
3319
3420pub extern "c" fn pledge(promises: ?[*:0]const u8, execpromises: ?[*:0]const u8) c_int;
3521pub extern "c" fn unveil(path: ?[*:0]const u8, permissions: ?[*:0]const u8) c_int;
22pub extern "c" fn getthrid() pid_t;
3623
37pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;
38pub extern "c" fn pthread_get_name_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) void;
39
40// https://github.com/openbsd/src/blob/2207c4325726fdc5c4bcd0011af0fdf7d3dab137/sys/sys/futex.h
41pub const FUTEX_WAIT = 1;
42pub const FUTEX_WAKE = 2;
43pub const FUTEX_REQUEUE = 3;
44pub const FUTEX_PRIVATE_FLAG = 128;
24pub const FUTEX = struct {
25 pub const WAIT = 1;
26 pub const WAKE = 2;
27 pub const REQUEUE = 3;
28 pub const PRIVATE_FLAG = 128;
29};
4530pub extern "c" fn futex(uaddr: ?*const volatile u32, op: c_int, val: c_int, timeout: ?*const timespec, uaddr2: ?*const volatile u32) c_int;
4631
4732pub const login_cap_t = extern struct {
48 lc_class: ?[*:0]const u8,
49 lc_cap: ?[*:0]const u8,
50 lc_style: ?[*:0]const u8,
33 class: ?[*:0]const u8,
34 cap: ?[*:0]const u8,
35 style: ?[*:0]const u8,
5136};
5237
5338pub extern "c" fn login_getclass(class: ?[*:0]const u8) ?*login_cap_t;
......@@ -94,21 +79,6 @@ pub extern "c" fn auth_cat(file: [*:0]const u8) c_int;
9479pub extern "c" fn auth_checknologin(lc: *login_cap_t) void;
9580// TODO: auth_set_va_list requires zig support for va_list type (#515)
9681
97pub const passwd = extern struct {
98 pw_name: ?[*:0]const u8, // user name
99 pw_passwd: ?[*:0]const u8, // encrypted password
100 pw_uid: uid_t, // user uid
101 pw_gid: gid_t, // user gid
102 pw_change: time_t, // password change time
103 pw_class: ?[*:0]const u8, // user access class
104 pw_gecos: ?[*:0]const u8, // Honeywell login info
105 pw_dir: ?[*:0]const u8, // home directory
106 pw_shell: ?[*:0]const u8, // default shell
107 pw_expire: time_t, // account expiration
108};
109
110pub extern "c" fn getpwuid(uid: uid_t) ?*passwd;
111pub extern "c" fn getpwnam(name: [*:0]const u8) ?*passwd;
11282pub extern "c" fn getpwuid_shadow(uid: uid_t) ?*passwd;
11383pub extern "c" fn getpwnam_shadow(name: [*:0]const u8) ?*passwd;
11484pub extern "c" fn getpwnam_r(name: [*:0]const u8, pw: *passwd, buf: [*]u8, buflen: usize, pwretp: *?*passwd) c_int;
......@@ -125,622 +95,14 @@ pub extern "c" fn bcrypt_newhash(pass: [*:0]const u8, log_rounds: c_int, hash: [
12595pub extern "c" fn bcrypt_checkpass(pass: [*:0]const u8, goodhash: [*:0]const u8) c_int;
12696pub extern "c" fn pw_dup(pw: *const passwd) ?*passwd;
12797
128pub const blkcnt_t = i64;
129pub const blksize_t = i32;
130pub const clock_t = i64;
131pub const dev_t = i32;
132pub const fd_t = c_int;
133pub const gid_t = u32;
134pub const ino_t = u64;
135pub const mode_t = u32;
136pub const nlink_t = u32;
137pub const off_t = i64;
138pub const pid_t = i32;
139pub const socklen_t = u32;
140pub const time_t = i64;
141pub const uid_t = u32;
142
143/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
144pub const Kevent = extern struct {
145 ident: usize,
146 filter: c_short,
147 flags: u16,
148 fflags: c_uint,
149 data: i64,
150 udata: usize,
151};
152
153// Modes and flags for dlopen()
154// include/dlfcn.h
155
156pub const RTLD = struct {
157 /// Bind function calls lazily.
158 pub const LAZY = 1;
159 /// Bind function calls immediately.
160 pub const NOW = 2;
161 /// Make symbols globally available.
162 pub const GLOBAL = 0x100;
163 /// Opposite of GLOBAL, and the default.
164 pub const LOCAL = 0x000;
165 /// Trace loaded objects and exit.
166 pub const TRACE = 0x200;
167};
168
169pub const dl_phdr_info = extern struct {
170 dlpi_addr: std.elf.Addr,
171 dlpi_name: ?[*:0]const u8,
172 dlpi_phdr: [*]std.elf.Phdr,
173 dlpi_phnum: std.elf.Half,
174};
175
176pub const Flock = extern struct {
177 start: off_t,
178 len: off_t,
179 pid: pid_t,
180 type: c_short,
181 whence: c_short,
182};
183
184pub const addrinfo = extern struct {
185 flags: c_int,
186 family: c_int,
187 socktype: c_int,
188 protocol: c_int,
189 addrlen: socklen_t,
190 addr: ?*sockaddr,
191 canonname: ?[*:0]u8,
192 next: ?*addrinfo,
193};
194
195pub const EAI = enum(c_int) {
196 /// address family for hostname not supported
197 ADDRFAMILY = -9,
198
199 /// name could not be resolved at this time
200 AGAIN = -3,
201
202 /// flags parameter had an invalid value
203 BADFLAGS = -1,
204
205 /// non-recoverable failure in name resolution
206 FAIL = -4,
207
208 /// address family not recognized
209 FAMILY = -6,
210
211 /// memory allocation failure
212 MEMORY = -10,
213
214 /// no address associated with hostname
215 NODATA = -5,
216
217 /// name does not resolve
218 NONAME = -2,
219
220 /// service not recognized for socket type
221 SERVICE = -8,
222
223 /// intended socket type was not recognized
224 SOCKTYPE = -7,
225
226 /// system error returned in errno
227 SYSTEM = -11,
228
229 /// invalid value for hints
230 BADHINTS = -12,
231
232 /// resolved protocol is unknown
233 PROTOCOL = -13,
234
235 /// argument buffer overflow
236 OVERFLOW = -14,
237
238 _,
239};
240
241pub const EAI_MAX = 15;
242
243pub const msghdr = extern struct {
244 /// optional address
245 name: ?*sockaddr,
246 /// size of address
247 namelen: socklen_t,
248 /// scatter/gather array
249 iov: [*]iovec,
250 /// # elements in iov
251 iovlen: c_uint,
252 /// ancillary data
253 control: ?*anyopaque,
254 /// ancillary data buffer len
255 controllen: socklen_t,
256 /// flags on received message
257 flags: c_int,
258};
259
260pub const msghdr_const = extern struct {
261 /// optional address
262 name: ?*const sockaddr,
263 /// size of address
264 namelen: socklen_t,
265 /// scatter/gather array
266 iov: [*]const iovec_const,
267 /// # elements in iov
268 iovlen: c_uint,
269 /// ancillary data
270 control: ?*const anyopaque,
271 /// ancillary data buffer len
272 controllen: socklen_t,
273 /// flags on received message
274 flags: c_int,
275};
276
277pub const Stat = extern struct {
278 mode: mode_t,
279 dev: dev_t,
280 ino: ino_t,
281 nlink: nlink_t,
282 uid: uid_t,
283 gid: gid_t,
284 rdev: dev_t,
285 atim: timespec,
286 mtim: timespec,
287 ctim: timespec,
288 size: off_t,
289 blocks: blkcnt_t,
290 blksize: blksize_t,
291 flags: u32,
292 gen: u32,
293 birthtim: timespec,
294
295 pub fn atime(self: @This()) timespec {
296 return self.atim;
297 }
298
299 pub fn mtime(self: @This()) timespec {
300 return self.mtim;
301 }
302
303 pub fn ctime(self: @This()) timespec {
304 return self.ctim;
305 }
306
307 pub fn birthtime(self: @This()) timespec {
308 return self.birthtim;
309 }
310};
311
312pub const timespec = extern struct {
313 tv_sec: time_t,
314 tv_nsec: c_long,
315};
316
317pub const timeval = extern struct {
318 tv_sec: time_t,
319 tv_usec: c_long,
320};
321
322pub const timezone = extern struct {
323 tz_minuteswest: c_int,
324 tz_dsttime: c_int,
325};
326
327pub const MAXNAMLEN = 255;
328
329pub const dirent = extern struct {
330 fileno: ino_t,
331 off: off_t,
332 reclen: u16,
333 type: u8,
334 namlen: u8,
335 _: u32 align(1) = 0,
336 name: [MAXNAMLEN + 1]u8,
337};
338
339pub const in_port_t = u16;
340pub const sa_family_t = u8;
341
342pub const sockaddr = extern struct {
343 /// total length
344 len: u8,
345 /// address family
346 family: sa_family_t,
347 /// actually longer; address value
348 data: [14]u8,
349
350 pub const SS_MAXSIZE = 256;
351 pub const storage = extern struct {
352 len: u8 align(8),
353 family: sa_family_t,
354 padding: [254]u8 = undefined,
355
356 comptime {
357 assert(@sizeOf(storage) == SS_MAXSIZE);
358 assert(@alignOf(storage) == 8);
359 }
360 };
361
362 pub const in = extern struct {
363 len: u8 = @sizeOf(in),
364 family: sa_family_t = AF.INET,
365 port: in_port_t,
366 addr: u32,
367 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
368 };
369
370 pub const in6 = extern struct {
371 len: u8 = @sizeOf(in6),
372 family: sa_family_t = AF.INET6,
373 port: in_port_t,
374 flowinfo: u32,
375 addr: [16]u8,
376 scope_id: u32,
377 };
378
379 /// Definitions for UNIX IPC domain.
380 pub const un = extern struct {
381 /// total sockaddr length
382 len: u8 = @sizeOf(un),
383
384 family: sa_family_t = AF.LOCAL,
385
386 /// path name
387 path: [104]u8,
388 };
389};
390
391pub const IFNAMESIZE = 16;
392
393pub const AI = struct {
394 /// get address to use bind()
395 pub const PASSIVE = 1;
396 /// fill ai_canonname
397 pub const CANONNAME = 2;
398 /// prevent host name resolution
399 pub const NUMERICHOST = 4;
400 /// prevent service name resolution
401 pub const NUMERICSERV = 16;
402 /// only if any address is assigned
403 pub const ADDRCONFIG = 64;
404};
405
406pub const PATH_MAX = 1024;
407pub const NAME_MAX = 255;
408pub const IOV_MAX = 1024;
409
410pub const STDIN_FILENO = 0;
411pub const STDOUT_FILENO = 1;
412pub const STDERR_FILENO = 2;
413
414pub const PROT = struct {
415 pub const NONE = 0;
416 pub const READ = 1;
417 pub const WRITE = 2;
418 pub const EXEC = 4;
419};
420
421pub const CLOCK = struct {
422 pub const REALTIME = 0;
423 pub const PROCESS_CPUTIME_ID = 2;
424 pub const MONOTONIC = 3;
425 pub const THREAD_CPUTIME_ID = 4;
426};
427
428pub const MSF = struct {
429 pub const ASYNC = 1;
430 pub const INVALIDATE = 2;
431 pub const SYNC = 4;
432};
433
434pub const W = struct {
435 pub const NOHANG = 1;
436 pub const UNTRACED = 2;
437 pub const CONTINUED = 8;
438
439 pub fn EXITSTATUS(s: u32) u8 {
440 return @as(u8, @intCast((s >> 8) & 0xff));
441 }
442 pub fn TERMSIG(s: u32) u32 {
443 return (s & 0x7f);
444 }
445 pub fn STOPSIG(s: u32) u32 {
446 return EXITSTATUS(s);
447 }
448 pub fn IFEXITED(s: u32) bool {
449 return TERMSIG(s) == 0;
450 }
451
452 pub fn IFCONTINUED(s: u32) bool {
453 return ((s & 0o177777) == 0o177777);
454 }
455
456 pub fn IFSTOPPED(s: u32) bool {
457 return (s & 0xff == 0o177);
458 }
459
460 pub fn IFSIGNALED(s: u32) bool {
461 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
462 }
463};
464
465pub const SA = struct {
466 pub const ONSTACK = 0x0001;
467 pub const RESTART = 0x0002;
468 pub const RESETHAND = 0x0004;
469 pub const NOCLDSTOP = 0x0008;
470 pub const NODEFER = 0x0010;
471 pub const NOCLDWAIT = 0x0020;
472 pub const SIGINFO = 0x0040;
473};
474
475// access function
476pub const F_OK = 0; // test for existence of file
477pub const X_OK = 1; // test for execute or search permission
478pub const W_OK = 2; // test for write permission
479pub const R_OK = 4; // test for read permission
480
481pub const F = struct {
482 pub const DUPFD = 0;
483 pub const GETFD = 1;
484 pub const SETFD = 2;
485 pub const GETFL = 3;
486 pub const SETFL = 4;
487
488 pub const GETOWN = 5;
489 pub const SETOWN = 6;
490
491 pub const GETLK = 7;
492 pub const SETLK = 8;
493 pub const SETLKW = 9;
494
495 pub const RDLCK = 1;
496 pub const UNLCK = 2;
497 pub const WRLCK = 3;
498};
499
500pub const LOCK = struct {
501 pub const SH = 0x01;
502 pub const EX = 0x02;
503 pub const NB = 0x04;
504 pub const UN = 0x08;
505};
506
507pub const FD_CLOEXEC = 1;
508
509pub const SEEK = struct {
510 pub const SET = 0;
511 pub const CUR = 1;
512 pub const END = 2;
513};
514
515pub const SOCK = struct {
516 pub const STREAM = 1;
517 pub const DGRAM = 2;
518 pub const RAW = 3;
519 pub const RDM = 4;
520 pub const SEQPACKET = 5;
521
522 pub const CLOEXEC = 0x8000;
523 pub const NONBLOCK = 0x4000;
524};
525
526pub const SO = struct {
527 pub const DEBUG = 0x0001;
528 pub const ACCEPTCONN = 0x0002;
529 pub const REUSEADDR = 0x0004;
530 pub const KEEPALIVE = 0x0008;
531 pub const DONTROUTE = 0x0010;
532 pub const BROADCAST = 0x0020;
533 pub const USELOOPBACK = 0x0040;
534 pub const LINGER = 0x0080;
535 pub const OOBINLINE = 0x0100;
536 pub const REUSEPORT = 0x0200;
537 pub const TIMESTAMP = 0x0800;
538 pub const BINDANY = 0x1000;
539 pub const ZEROIZE = 0x2000;
540 pub const SNDBUF = 0x1001;
541 pub const RCVBUF = 0x1002;
542 pub const SNDLOWAT = 0x1003;
543 pub const RCVLOWAT = 0x1004;
544 pub const SNDTIMEO = 0x1005;
545 pub const RCVTIMEO = 0x1006;
546 pub const ERROR = 0x1007;
547 pub const TYPE = 0x1008;
548 pub const NETPROC = 0x1020;
549 pub const RTABLE = 0x1021;
550 pub const PEERCRED = 0x1022;
551 pub const SPLICE = 0x1023;
552 pub const DOMAIN = 0x1024;
553 pub const PROTOCOL = 0x1025;
554};
555
556pub const SOL = struct {
557 pub const SOCKET = 0xffff;
558};
559
560pub const PF = struct {
561 pub const UNSPEC = AF.UNSPEC;
562 pub const LOCAL = AF.LOCAL;
563 pub const UNIX = AF.UNIX;
564 pub const INET = AF.INET;
565 pub const APPLETALK = AF.APPLETALK;
566 pub const INET6 = AF.INET6;
567 pub const DECnet = AF.DECnet;
568 pub const KEY = AF.KEY;
569 pub const ROUTE = AF.ROUTE;
570 pub const SNA = AF.SNA;
571 pub const MPLS = AF.MPLS;
572 pub const BLUETOOTH = AF.BLUETOOTH;
573 pub const ISDN = AF.ISDN;
574 pub const MAX = AF.MAX;
575};
576
577pub const AF = struct {
578 pub const UNSPEC = 0;
579 pub const UNIX = 1;
580 pub const LOCAL = UNIX;
581 pub const INET = 2;
582 pub const APPLETALK = 16;
583 pub const INET6 = 24;
584 pub const KEY = 30;
585 pub const ROUTE = 17;
586 pub const SNA = 11;
587 pub const MPLS = 33;
588 pub const BLUETOOTH = 32;
589 pub const ISDN = 26;
590 pub const MAX = 36;
591};
592
593pub const DT = struct {
594 pub const UNKNOWN = 0;
595 pub const FIFO = 1;
596 pub const CHR = 2;
597 pub const DIR = 4;
598 pub const BLK = 6;
599 pub const REG = 8;
600 pub const LNK = 10;
601 pub const SOCK = 12;
602 pub const WHT = 14; // XXX
603};
604
605pub const EV_ADD = 0x0001;
606pub const EV_DELETE = 0x0002;
607pub const EV_ENABLE = 0x0004;
608pub const EV_DISABLE = 0x0008;
609pub const EV_ONESHOT = 0x0010;
610pub const EV_CLEAR = 0x0020;
611pub const EV_RECEIPT = 0x0040;
612pub const EV_DISPATCH = 0x0080;
613pub const EV_FLAG1 = 0x2000;
614pub const EV_ERROR = 0x4000;
615pub const EV_EOF = 0x8000;
616
617pub const EVFILT_READ = -1;
618pub const EVFILT_WRITE = -2;
619pub const EVFILT_AIO = -3;
620pub const EVFILT_VNODE = -4;
621pub const EVFILT_PROC = -5;
622pub const EVFILT_SIGNAL = -6;
623pub const EVFILT_TIMER = -7;
624pub const EVFILT_EXCEPT = -9;
625
626// data/hint flags for EVFILT_{READ|WRITE}
627pub const NOTE_LOWAT = 0x0001;
628pub const NOTE_EOF = 0x0002;
629
630// data/hint flags for EVFILT_EXCEPT and EVFILT_{READ|WRITE}
631pub const NOTE_OOB = 0x0004;
632
633// data/hint flags for EVFILT_VNODE
634pub const NOTE_DELETE = 0x0001;
635pub const NOTE_WRITE = 0x0002;
636pub const NOTE_EXTEND = 0x0004;
637pub const NOTE_ATTRIB = 0x0008;
638pub const NOTE_LINK = 0x0010;
639pub const NOTE_RENAME = 0x0020;
640pub const NOTE_REVOKE = 0x0040;
641pub const NOTE_TRUNCATE = 0x0080;
642
643// data/hint flags for EVFILT_PROC
644pub const NOTE_EXIT = 0x80000000;
645pub const NOTE_FORK = 0x40000000;
646pub const NOTE_EXEC = 0x20000000;
647pub const NOTE_PDATAMASK = 0x000fffff;
648pub const NOTE_PCTRLMASK = 0xf0000000;
649pub const NOTE_TRACK = 0x00000001;
650pub const NOTE_TRACKERR = 0x00000002;
651pub const NOTE_CHILD = 0x00000004;
652
653// data/hint flags for EVFILT_DEVICE
654pub const NOTE_CHANGE = 0x00000001;
655
656pub const T = struct {
657 pub const IOCCBRK = 0x2000747a;
658 pub const IOCCDTR = 0x20007478;
659 pub const IOCCONS = 0x80047462;
660 pub const IOCDCDTIMESTAMP = 0x40107458;
661 pub const IOCDRAIN = 0x2000745e;
662 pub const IOCEXCL = 0x2000740d;
663 pub const IOCEXT = 0x80047460;
664 pub const IOCFLAG_CDTRCTS = 0x10;
665 pub const IOCFLAG_CLOCAL = 0x2;
666 pub const IOCFLAG_CRTSCTS = 0x4;
667 pub const IOCFLAG_MDMBUF = 0x8;
668 pub const IOCFLAG_SOFTCAR = 0x1;
669 pub const IOCFLUSH = 0x80047410;
670 pub const IOCGETA = 0x402c7413;
671 pub const IOCGETD = 0x4004741a;
672 pub const IOCGFLAGS = 0x4004745d;
673 pub const IOCGLINED = 0x40207442;
674 pub const IOCGPGRP = 0x40047477;
675 pub const IOCGQSIZE = 0x40047481;
676 pub const IOCGRANTPT = 0x20007447;
677 pub const IOCGSID = 0x40047463;
678 pub const IOCGSIZE = 0x40087468;
679 pub const IOCGWINSZ = 0x40087468;
680 pub const IOCMBIC = 0x8004746b;
681 pub const IOCMBIS = 0x8004746c;
682 pub const IOCMGET = 0x4004746a;
683 pub const IOCMSET = 0x8004746d;
684 pub const IOCM_CAR = 0x40;
685 pub const IOCM_CD = 0x40;
686 pub const IOCM_CTS = 0x20;
687 pub const IOCM_DSR = 0x100;
688 pub const IOCM_DTR = 0x2;
689 pub const IOCM_LE = 0x1;
690 pub const IOCM_RI = 0x80;
691 pub const IOCM_RNG = 0x80;
692 pub const IOCM_RTS = 0x4;
693 pub const IOCM_SR = 0x10;
694 pub const IOCM_ST = 0x8;
695 pub const IOCNOTTY = 0x20007471;
696 pub const IOCNXCL = 0x2000740e;
697 pub const IOCOUTQ = 0x40047473;
698 pub const IOCPKT = 0x80047470;
699 pub const IOCPKT_DATA = 0x0;
700 pub const IOCPKT_DOSTOP = 0x20;
701 pub const IOCPKT_FLUSHREAD = 0x1;
702 pub const IOCPKT_FLUSHWRITE = 0x2;
703 pub const IOCPKT_IOCTL = 0x40;
704 pub const IOCPKT_NOSTOP = 0x10;
705 pub const IOCPKT_START = 0x8;
706 pub const IOCPKT_STOP = 0x4;
707 pub const IOCPTMGET = 0x40287446;
708 pub const IOCPTSNAME = 0x40287448;
709 pub const IOCRCVFRAME = 0x80087445;
710 pub const IOCREMOTE = 0x80047469;
711 pub const IOCSBRK = 0x2000747b;
712 pub const IOCSCTTY = 0x20007461;
713 pub const IOCSDTR = 0x20007479;
714 pub const IOCSETA = 0x802c7414;
715 pub const IOCSETAF = 0x802c7416;
716 pub const IOCSETAW = 0x802c7415;
717 pub const IOCSETD = 0x8004741b;
718 pub const IOCSFLAGS = 0x8004745c;
719 pub const IOCSIG = 0x2000745f;
720 pub const IOCSLINED = 0x80207443;
721 pub const IOCSPGRP = 0x80047476;
722 pub const IOCSQSIZE = 0x80047480;
723 pub const IOCSSIZE = 0x80087467;
724 pub const IOCSTART = 0x2000746e;
725 pub const IOCSTAT = 0x80047465;
726 pub const IOCSTI = 0x80017472;
727 pub const IOCSTOP = 0x2000746f;
728 pub const IOCSWINSZ = 0x80087467;
729 pub const IOCUCNTL = 0x80047466;
730 pub const IOCXMTFRAME = 0x80087444;
731};
732
733// BSD Authentication
734pub const auth_item_t = c_int;
735
736pub const AUTHV = struct {
737 pub const ALL: auth_item_t = 0;
738 pub const CHALLENGE: auth_item_t = 1;
739 pub const CLASS: auth_item_t = 2;
740 pub const NAME: auth_item_t = 3;
741 pub const SERVICE: auth_item_t = 4;
742 pub const STYLE: auth_item_t = 5;
743 pub const INTERACTIVE: auth_item_t = 6;
98pub const auth_item_t = enum(c_int) {
99 ALL = 0,
100 CHALLENGE = 1,
101 CLASS = 2,
102 NAME = 3,
103 SERVICE = 4,
104 STYLE = 5,
105 INTERACTIVE = 6,
744106};
745107
746108pub const BI = struct {
......@@ -770,132 +132,20 @@ pub const AUTH = struct {
770132 pub const ALLOW: c_int = (OKAY | ROOTOKAY | SECURE);
771133};
772134
773pub const TCSA = enum(c_uint) {
774 NOW,
775 DRAIN,
776 FLUSH,
777 _,
778};
779
780pub const TCIFLUSH = 1;
781pub const TCOFLUSH = 2;
782pub const TCIOFLUSH = 3;
783pub const TCOOFF = 1;
784pub const TCOON = 2;
785pub const TCIOFF = 3;
786pub const TCION = 4;
787
788pub const winsize = extern struct {
789 ws_row: c_ushort,
790 ws_col: c_ushort,
791 ws_xpixel: c_ushort,
792 ws_ypixel: c_ushort,
793};
794
795const NSIG = 33;
796
797pub const SIG = struct {
798 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
799 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
800 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
801 pub const CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);
802 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
803
804 pub const HUP = 1;
805 pub const INT = 2;
806 pub const QUIT = 3;
807 pub const ILL = 4;
808 pub const TRAP = 5;
809 pub const ABRT = 6;
810 pub const IOT = ABRT;
811 pub const EMT = 7;
812 pub const FPE = 8;
813 pub const KILL = 9;
814 pub const BUS = 10;
815 pub const SEGV = 11;
816 pub const SYS = 12;
817 pub const PIPE = 13;
818 pub const ALRM = 14;
819 pub const TERM = 15;
820 pub const URG = 16;
821 pub const STOP = 17;
822 pub const TSTP = 18;
823 pub const CONT = 19;
824 pub const CHLD = 20;
825 pub const TTIN = 21;
826 pub const TTOU = 22;
827 pub const IO = 23;
828 pub const XCPU = 24;
829 pub const XFSZ = 25;
830 pub const VTALRM = 26;
831 pub const PROF = 27;
832 pub const WINCH = 28;
833 pub const INFO = 29;
834 pub const USR1 = 30;
835 pub const USR2 = 31;
836 pub const PWR = 32;
837
838 pub const BLOCK = 1;
839 pub const UNBLOCK = 2;
840 pub const SETMASK = 3;
841};
842
843/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
844pub const Sigaction = extern struct {
845 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
846 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
847
848 /// signal handler
849 handler: extern union {
850 handler: ?handler_fn,
851 sigaction: ?sigaction_fn,
852 },
853 /// signal mask to apply
854 mask: sigset_t,
855 /// signal options
856 flags: c_uint,
857};
858
859pub const sigval = extern union {
860 int: c_int,
861 ptr: ?*anyopaque,
135pub const TCFLUSH = enum(u32) {
136 none = 0,
137 I = 1,
138 O = 2,
139 IO = 3,
862140};
863141
864pub const siginfo_t = extern struct {
865 signo: c_int,
866 code: c_int,
867 errno: c_int,
868 data: extern union {
869 proc: extern struct {
870 pid: pid_t,
871 pdata: extern union {
872 kill: extern struct {
873 uid: uid_t,
874 value: sigval,
875 },
876 cld: extern struct {
877 utime: clock_t,
878 stime: clock_t,
879 status: c_int,
880 },
881 },
882 },
883 fault: extern struct {
884 addr: *allowzero anyopaque,
885 trapno: c_int,
886 },
887 __pad: [128 - 3 * @sizeOf(c_int)]u8,
888 },
142pub const TCIO = enum(u32) {
143 OOFF = 1,
144 OON = 2,
145 IOFF = 3,
146 ION = 4,
889147};
890148
891comptime {
892 if (@sizeOf(usize) == 4)
893 std.debug.assert(@sizeOf(siginfo_t) == 128)
894 else
895 // Take into account the padding between errno and data fields.
896 std.debug.assert(@sizeOf(siginfo_t) == 136);
897}
898
899149pub const ucontext_t = switch (builtin.cpu.arch) {
900150 .x86_64 => extern struct {
901151 sc_rdi: c_long,
......@@ -943,9 +193,6 @@ pub const ucontext_t = switch (builtin.cpu.arch) {
943193 else => @compileError("missing ucontext_t type definition"),
944194};
945195
946pub const sigset_t = c_uint;
947pub const empty_sigset: sigset_t = 0;
948
949196pub const E = enum(u16) {
950197 /// No error occurred.
951198 SUCCESS = 0,
......@@ -1070,327 +317,10 @@ pub const E = enum(u16) {
1070317 _,
1071318};
1072319
1073const _MAX_PAGE_SHIFT = switch (builtin.cpu.arch) {
320pub const MAX_PAGE_SHIFT = switch (builtin.cpu.arch) {
1074321 .x86 => 12,
1075322 .sparc64 => 13,
1076323};
1077pub const MINSIGSTKSZ = 1 << _MAX_PAGE_SHIFT;
1078pub const SIGSTKSZ = MINSIGSTKSZ + (1 << _MAX_PAGE_SHIFT) * 4;
1079
1080pub const SS_ONSTACK = 0x0001;
1081pub const SS_DISABLE = 0x0004;
1082
1083pub const stack_t = extern struct {
1084 sp: [*]u8,
1085 size: usize,
1086 flags: c_int,
1087};
1088
1089pub const S = struct {
1090 pub const IFMT = 0o170000;
1091
1092 pub const IFIFO = 0o010000;
1093 pub const IFCHR = 0o020000;
1094 pub const IFDIR = 0o040000;
1095 pub const IFBLK = 0o060000;
1096 pub const IFREG = 0o100000;
1097 pub const IFLNK = 0o120000;
1098 pub const IFSOCK = 0o140000;
1099
1100 pub const ISUID = 0o4000;
1101 pub const ISGID = 0o2000;
1102 pub const ISVTX = 0o1000;
1103 pub const IRWXU = 0o700;
1104 pub const IRUSR = 0o400;
1105 pub const IWUSR = 0o200;
1106 pub const IXUSR = 0o100;
1107 pub const IRWXG = 0o070;
1108 pub const IRGRP = 0o040;
1109 pub const IWGRP = 0o020;
1110 pub const IXGRP = 0o010;
1111 pub const IRWXO = 0o007;
1112 pub const IROTH = 0o004;
1113 pub const IWOTH = 0o002;
1114 pub const IXOTH = 0o001;
1115
1116 pub fn ISFIFO(m: u32) bool {
1117 return m & IFMT == IFIFO;
1118 }
1119
1120 pub fn ISCHR(m: u32) bool {
1121 return m & IFMT == IFCHR;
1122 }
1123
1124 pub fn ISDIR(m: u32) bool {
1125 return m & IFMT == IFDIR;
1126 }
1127
1128 pub fn ISBLK(m: u32) bool {
1129 return m & IFMT == IFBLK;
1130 }
1131
1132 pub fn ISREG(m: u32) bool {
1133 return m & IFMT == IFREG;
1134 }
1135
1136 pub fn ISLNK(m: u32) bool {
1137 return m & IFMT == IFLNK;
1138 }
1139
1140 pub fn ISSOCK(m: u32) bool {
1141 return m & IFMT == IFSOCK;
1142 }
1143};
1144
1145pub const HOST_NAME_MAX = 255;
1146
1147pub const IPPROTO = struct {
1148 /// dummy for IP
1149 pub const IP = 0;
1150 /// IP6 hop-by-hop options
1151 pub const HOPOPTS = IP;
1152 /// control message protocol
1153 pub const ICMP = 1;
1154 /// group mgmt protocol
1155 pub const IGMP = 2;
1156 /// gateway^2 (deprecated)
1157 pub const GGP = 3;
1158 /// IP header
1159 pub const IPV4 = IPIP;
1160 /// IP inside IP
1161 pub const IPIP = 4;
1162 /// tcp
1163 pub const TCP = 6;
1164 /// exterior gateway protocol
1165 pub const EGP = 8;
1166 /// pup
1167 pub const PUP = 12;
1168 /// user datagram protocol
1169 pub const UDP = 17;
1170 /// xns idp
1171 pub const IDP = 22;
1172 /// tp-4 w/ class negotiation
1173 pub const TP = 29;
1174 /// IP6 header
1175 pub const IPV6 = 41;
1176 /// IP6 routing header
1177 pub const ROUTING = 43;
1178 /// IP6 fragmentation header
1179 pub const FRAGMENT = 44;
1180 /// resource reservation
1181 pub const RSVP = 46;
1182 /// GRE encaps RFC 1701
1183 pub const GRE = 47;
1184 /// encap. security payload
1185 pub const ESP = 50;
1186 /// authentication header
1187 pub const AH = 51;
1188 /// IP Mobility RFC 2004
1189 pub const MOBILE = 55;
1190 /// IPv6 ICMP
1191 pub const IPV6_ICMP = 58;
1192 /// ICMP6
1193 pub const ICMPV6 = 58;
1194 /// IP6 no next header
1195 pub const NONE = 59;
1196 /// IP6 destination option
1197 pub const DSTOPTS = 60;
1198 /// ISO cnlp
1199 pub const EON = 80;
1200 /// Ethernet-in-IP
1201 pub const ETHERIP = 97;
1202 /// encapsulation header
1203 pub const ENCAP = 98;
1204 /// Protocol indep. multicast
1205 pub const PIM = 103;
1206 /// IP Payload Comp. Protocol
1207 pub const IPCOMP = 108;
1208 /// VRRP RFC 2338
1209 pub const VRRP = 112;
1210 /// Common Address Resolution Protocol
1211 pub const CARP = 112;
1212 /// PFSYNC
1213 pub const PFSYNC = 240;
1214 /// raw IP packet
1215 pub const RAW = 255;
1216};
1217
1218pub const rlimit_resource = enum(c_int) {
1219 CPU,
1220 FSIZE,
1221 DATA,
1222 STACK,
1223 CORE,
1224 RSS,
1225 MEMLOCK,
1226 NPROC,
1227 NOFILE,
1228
1229 _,
1230};
1231
1232pub const rlim_t = u64;
1233
1234pub const RLIM = struct {
1235 /// No limit
1236 pub const INFINITY: rlim_t = (1 << 63) - 1;
1237
1238 pub const SAVED_MAX = INFINITY;
1239 pub const SAVED_CUR = INFINITY;
1240};
1241
1242pub const rlimit = extern struct {
1243 /// Soft limit
1244 cur: rlim_t,
1245 /// Hard limit
1246 max: rlim_t,
1247};
1248
1249pub const SHUT = struct {
1250 pub const RD = 0;
1251 pub const WR = 1;
1252 pub const RDWR = 2;
1253};
1254
1255pub const nfds_t = c_uint;
1256
1257pub const pollfd = extern struct {
1258 fd: fd_t,
1259 events: c_short,
1260 revents: c_short,
1261};
1262
1263pub const POLL = struct {
1264 pub const IN = 0x0001;
1265 pub const PRI = 0x0002;
1266 pub const OUT = 0x0004;
1267 pub const ERR = 0x0008;
1268 pub const HUP = 0x0010;
1269 pub const NVAL = 0x0020;
1270 pub const RDNORM = 0x0040;
1271 pub const NORM = RDNORM;
1272 pub const WRNORM = OUT;
1273 pub const RDBAND = 0x0080;
1274 pub const WRBAND = 0x0100;
1275};
1276
1277pub const CTL = struct {
1278 pub const UNSPEC = 0;
1279 pub const KERN = 1;
1280 pub const VM = 2;
1281 pub const FS = 3;
1282 pub const NET = 4;
1283 pub const DEBUG = 5;
1284 pub const HW = 6;
1285 pub const MACHDEP = 7;
1286
1287 pub const DDB = 9;
1288 pub const VFS = 10;
1289};
1290
1291pub const KERN = struct {
1292 pub const OSTYPE = 1;
1293 pub const OSRELEASE = 2;
1294 pub const OSREV = 3;
1295 pub const VERSION = 4;
1296 pub const MAXVNODES = 5;
1297 pub const MAXPROC = 6;
1298 pub const MAXFILES = 7;
1299 pub const ARGMAX = 8;
1300 pub const SECURELVL = 9;
1301 pub const HOSTNAME = 10;
1302 pub const HOSTID = 11;
1303 pub const CLOCKRATE = 12;
1304
1305 pub const PROF = 16;
1306 pub const POSIX1 = 17;
1307 pub const NGROUPS = 18;
1308 pub const JOB_CONTROL = 19;
1309 pub const SAVED_IDS = 20;
1310 pub const BOOTTIME = 21;
1311 pub const DOMAINNAME = 22;
1312 pub const MAXPARTITIONS = 23;
1313 pub const RAWPARTITION = 24;
1314 pub const MAXTHREAD = 25;
1315 pub const NTHREADS = 26;
1316 pub const OSVERSION = 27;
1317 pub const SOMAXCONN = 28;
1318 pub const SOMINCONN = 29;
1319
1320 pub const NOSUIDCOREDUMP = 32;
1321 pub const FSYNC = 33;
1322 pub const SYSVMSG = 34;
1323 pub const SYSVSEM = 35;
1324 pub const SYSVSHM = 36;
1325
1326 pub const MSGBUFSIZE = 38;
1327 pub const MALLOCSTATS = 39;
1328 pub const CPTIME = 40;
1329 pub const NCHSTATS = 41;
1330 pub const FORKSTAT = 42;
1331 pub const NSELCOLL = 43;
1332 pub const TTY = 44;
1333 pub const CCPU = 45;
1334 pub const FSCALE = 46;
1335 pub const NPROCS = 47;
1336 pub const MSGBUF = 48;
1337 pub const POOL = 49;
1338 pub const STACKGAPRANDOM = 50;
1339 pub const SYSVIPC_INFO = 51;
1340 pub const ALLOWKMEM = 52;
1341 pub const WITNESSWATCH = 53;
1342 pub const SPLASSERT = 54;
1343 pub const PROC_ARGS = 55;
1344 pub const NFILES = 56;
1345 pub const TTYCOUNT = 57;
1346 pub const NUMVNODES = 58;
1347 pub const MBSTAT = 59;
1348 pub const WITNESS = 60;
1349 pub const SEMINFO = 61;
1350 pub const SHMINFO = 62;
1351 pub const INTRCNT = 63;
1352 pub const WATCHDOG = 64;
1353 pub const ALLOWDT = 65;
1354 pub const PROC = 66;
1355 pub const MAXCLUSTERS = 67;
1356 pub const EVCOUNT = 68;
1357 pub const TIMECOUNTER = 69;
1358 pub const MAXLOCKSPERUID = 70;
1359 pub const CPTIME2 = 71;
1360 pub const CACHEPCT = 72;
1361 pub const FILE = 73;
1362 pub const WXABORT = 74;
1363 pub const CONSDEV = 75;
1364 pub const NETLIVELOCKS = 76;
1365 pub const POOL_DEBUG = 77;
1366 pub const PROC_CWD = 78;
1367 pub const PROC_NOBROADCASTKILL = 79;
1368 pub const PROC_VMMAP = 80;
1369 pub const GLOBAL_PTRACE = 81;
1370 pub const CONSBUFSIZE = 82;
1371 pub const CONSBUF = 83;
1372 pub const AUDIO = 84;
1373 pub const CPUSTATS = 85;
1374 pub const PFSTATUS = 86;
1375 pub const TIMEOUT_STATS = 87;
1376 pub const UTC_OFFSET = 88;
1377 pub const VIDEO = 89;
1378
1379 pub const PROC_ALL = 0;
1380 pub const PROC_PID = 1;
1381 pub const PROC_PGRP = 2;
1382 pub const PROC_SESSION = 3;
1383 pub const PROC_TTY = 4;
1384 pub const PROC_UID = 5;
1385 pub const PROC_RUID = 6;
1386 pub const PROC_KTHREAD = 7;
1387 pub const PROC_SHOW_THREADS = 0x40000000;
1388
1389 pub const PROC_ARGV = 1;
1390 pub const PROC_NARGV = 2;
1391 pub const PROC_ENV = 3;
1392 pub const PROC_NENV = 4;
1393};
1394324
1395325pub const HW = struct {
1396326 pub const MACHINE = 1;
lib/std/c/solaris.zig+22-1479
......@@ -1,61 +1,29 @@
1const builtin = @import("builtin");
12const std = @import("../std.zig");
23const assert = std.debug.assert;
3const builtin = @import("builtin");
4const maxInt = std.math.maxInt;
5const iovec = std.posix.iovec;
6const iovec_const = std.posix.iovec_const;
7const timezone = std.c.timezone;
4const SO = std.c.SO;
5const fd_t = std.c.fd_t;
6const gid_t = std.c.gid_t;
7const ino_t = std.c.ino_t;
8const mode_t = std.c.mode_t;
9const off_t = std.c.off_t;
10const pid_t = std.c.pid_t;
11const pthread_t = std.c.pthread_t;
12const sockaddr = std.c.sockaddr;
13const socklen_t = std.c.socklen_t;
14const timespec = std.c.timespec;
15const uid_t = std.c.uid_t;
16const IFNAMESIZE = std.c.IFNAMESIZE;
817
9extern "c" fn ___errno() *c_int;
10pub const _errno = ___errno;
11
12pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
13pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*anyopaque) c_int;
18comptime {
19 assert(builtin.os.tag == .solaris or builtin.os.tag == .illumos); // Prevent access of std.c symbols on wrong OS.
20}
1421
15pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
16pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
17pub extern "c" fn pipe2(fds: *[2]fd_t, flags: std.c.O) c_int;
18pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
19pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
22pub extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
2023pub extern "c" fn sysconf(sc: c_int) i64;
21pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;
22pub extern "c" fn madvise(address: [*]u8, len: usize, advise: u32) c_int;
23
24pub const pthread_attr_t = extern struct {
25 mutexattr: ?*anyopaque = null,
26};
27pub const pthread_key_t = c_int;
2824
29pub const sem_t = extern struct {
30 count: u32 = 0,
31 type: u16 = 0,
32 magic: u16 = 0x534d,
33 __pad1: [3]u64 = [_]u64{0} ** 3,
34 __pad2: [2]u64 = [_]u64{0} ** 2,
35};
36
37pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
38pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
39
40pub const blkcnt_t = i64;
41pub const blksize_t = i32;
42pub const clock_t = i64;
43pub const dev_t = i32;
44pub const fd_t = c_int;
45pub const gid_t = u32;
46pub const ino_t = u64;
47pub const mode_t = u32;
48pub const nlink_t = u32;
49pub const off_t = i64;
50pub const pid_t = i32;
51pub const socklen_t = u32;
52pub const time_t = i64;
53pub const suseconds_t = i64;
54pub const uid_t = u32;
5525pub const major_t = u32;
5626pub const minor_t = u32;
57pub const port_t = c_int;
58pub const nfds_t = usize;
5927pub const id_t = i32;
6028pub const taskid_t = id_t;
6129pub const projid_t = id_t;
......@@ -63,896 +31,18 @@ pub const poolid_t = id_t;
6331pub const zoneid_t = id_t;
6432pub const ctid_t = id_t;
6533
66pub const dl_phdr_info = extern struct {
67 dlpi_addr: std.elf.Addr,
68 dlpi_name: ?[*:0]const u8,
69 dlpi_phdr: [*]std.elf.Phdr,
70 dlpi_phnum: std.elf.Half,
71 /// Incremented when a new object is mapped into the process.
72 dlpi_adds: u64,
73 /// Incremented when an object is unmapped from the process.
74 dlpi_subs: u64,
75};
76
77pub const RTLD = struct {
78 pub const LAZY = 0x00001;
79 pub const NOW = 0x00002;
80 pub const NOLOAD = 0x00004;
81 pub const GLOBAL = 0x00100;
82 pub const LOCAL = 0x00000;
83 pub const PARENT = 0x00200;
84 pub const GROUP = 0x00400;
85 pub const WORLD = 0x00800;
86 pub const NODELETE = 0x01000;
87 pub const FIRST = 0x02000;
88 pub const CONFGEN = 0x10000;
89
90 pub const NEXT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -1)))));
91 pub const DEFAULT = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -2)))));
92 pub const SELF = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -3)))));
93 pub const PROBE = @as(*anyopaque, @ptrFromInt(@as(usize, @bitCast(@as(isize, -4)))));
94};
95
96pub const Flock = extern struct {
97 type: c_short,
98 whence: c_short,
99 start: off_t,
100 // len == 0 means until end of file.
101 len: off_t,
102 sysid: c_int,
103 pid: pid_t,
104 __pad: [4]c_long,
105};
106
107pub const utsname = extern struct {
108 sysname: [256:0]u8,
109 nodename: [256:0]u8,
110 release: [256:0]u8,
111 version: [256:0]u8,
112 machine: [256:0]u8,
113 domainname: [256:0]u8,
114};
115
116pub const addrinfo = extern struct {
117 flags: i32,
118 family: i32,
119 socktype: i32,
120 protocol: i32,
121 addrlen: socklen_t,
122 canonname: ?[*:0]u8,
123 addr: ?*sockaddr,
124 next: ?*addrinfo,
125};
126
127pub const EAI = enum(c_int) {
128 /// address family for hostname not supported
129 ADDRFAMILY = 1,
130 /// name could not be resolved at this time
131 AGAIN = 2,
132 /// flags parameter had an invalid value
133 BADFLAGS = 3,
134 /// non-recoverable failure in name resolution
135 FAIL = 4,
136 /// address family not recognized
137 FAMILY = 5,
138 /// memory allocation failure
139 MEMORY = 6,
140 /// no address associated with hostname
141 NODATA = 7,
142 /// name does not resolve
143 NONAME = 8,
144 /// service not recognized for socket type
145 SERVICE = 9,
146 /// intended socket type was not recognized
147 SOCKTYPE = 10,
148 /// system error returned in errno
149 SYSTEM = 11,
150 /// argument buffer overflow
151 OVERFLOW = 12,
152 /// resolved protocol is unknown
153 PROTOCOL = 13,
154
155 _,
156};
157
158pub const EAI_MAX = 14;
159
160pub const msghdr = extern struct {
161 /// optional address
162 msg_name: ?*sockaddr,
163 /// size of address
164 msg_namelen: socklen_t,
165 /// scatter/gather array
166 msg_iov: [*]iovec,
167 /// # elements in msg_iov
168 msg_iovlen: i32,
169 /// ancillary data
170 msg_control: ?*anyopaque,
171 /// ancillary data buffer len
172 msg_controllen: socklen_t,
173 /// flags on received message
174 msg_flags: i32,
175};
176
177pub const msghdr_const = extern struct {
178 /// optional address
179 msg_name: ?*const sockaddr,
180 /// size of address
181 msg_namelen: socklen_t,
182 /// scatter/gather array
183 msg_iov: [*]const iovec_const,
184 /// # elements in msg_iov
185 msg_iovlen: i32,
186 /// ancillary data
187 msg_control: ?*const anyopaque,
188 /// ancillary data buffer len
189 msg_controllen: socklen_t,
190 /// flags on received message
191 msg_flags: i32,
192};
193
19434pub const cmsghdr = extern struct {
195 cmsg_len: socklen_t,
196 cmsg_level: i32,
197 cmsg_type: i32,
35 len: socklen_t,
36 level: i32,
37 type: i32,
19838};
19939
200/// The stat structure used by libc.
201pub const Stat = extern struct {
202 dev: dev_t,
203 ino: ino_t,
204 mode: mode_t,
205 nlink: nlink_t,
206 uid: uid_t,
207 gid: gid_t,
208 rdev: dev_t,
209 size: off_t,
210 atim: timespec,
211 mtim: timespec,
212 ctim: timespec,
213 blksize: blksize_t,
214 blocks: blkcnt_t,
215 fstype: [16]u8,
216
217 pub fn atime(self: @This()) timespec {
218 return self.atim;
219 }
220
221 pub fn mtime(self: @This()) timespec {
222 return self.mtim;
223 }
224
225 pub fn ctime(self: @This()) timespec {
226 return self.ctim;
227 }
228};
229
230pub const timespec = extern struct {
231 tv_sec: i64,
232 tv_nsec: isize,
233};
234
235pub const timeval = extern struct {
236 /// seconds
237 tv_sec: time_t,
238 /// microseconds
239 tv_usec: suseconds_t,
240};
241
242pub const MAXNAMLEN = 511;
243
244pub const dirent = extern struct {
245 /// Inode number of entry.
246 ino: ino_t,
247 /// Offset of this entry on disk.
248 off: off_t,
249 /// Length of this record.
250 reclen: u16,
251 /// File name.
252 name: [MAXNAMLEN:0]u8,
253};
254
255pub const SOCK = struct {
256 /// Datagram.
257 pub const DGRAM = 1;
258 /// STREAM.
259 pub const STREAM = 2;
260 /// Raw-protocol interface.
261 pub const RAW = 4;
262 /// Reliably-delivered message.
263 pub const RDM = 5;
264 /// Sequenced packed stream.
265 pub const SEQPACKET = 6;
266
267 pub const NONBLOCK = 0x100000;
268 pub const NDELAY = 0x200000;
269 pub const CLOEXEC = 0x080000;
270};
271
272pub const SO = struct {
273 pub const DEBUG = 0x0001;
274 pub const ACCEPTCONN = 0x0002;
275 pub const REUSEADDR = 0x0004;
276 pub const KEEPALIVE = 0x0008;
277 pub const DONTROUTE = 0x0010;
278 pub const BROADCAST = 0x0020;
279 pub const USELOOPBACK = 0x0040;
280 pub const LINGER = 0x0080;
281 pub const OOBINLINE = 0x0100;
282 pub const DGRAM_ERRIND = 0x0200;
283 pub const RECVUCRED = 0x0400;
284
285 pub const SNDBUF = 0x1001;
286 pub const RCVBUF = 0x1002;
287 pub const SNDLOWAT = 0x1003;
288 pub const RCVLOWAT = 0x1004;
289 pub const SNDTIMEO = 0x1005;
290 pub const RCVTIMEO = 0x1006;
291 pub const ERROR = 0x1007;
292 pub const TYPE = 0x1008;
293 pub const PROTOTYPE = 0x1009;
294 pub const ANON_MLP = 0x100a;
295 pub const MAC_EXEMPT = 0x100b;
296 pub const DOMAIN = 0x100c;
297 pub const RCVPSH = 0x100d;
298
299 pub const SECATTR = 0x1011;
300 pub const TIMESTAMP = 0x1013;
301 pub const ALLZONES = 0x1014;
302 pub const EXCLBIND = 0x1015;
303 pub const MAC_IMPLICIT = 0x1016;
304 pub const VRRP = 0x1017;
305};
306
307pub const SOMAXCONN = 128;
308
30940pub const SCM = struct {
31041 pub const UCRED = 0x1012;
31142 pub const RIGHTS = 0x1010;
31243 pub const TIMESTAMP = SO.TIMESTAMP;
31344};
31445
315pub const AF = struct {
316 pub const UNSPEC = 0;
317 pub const UNIX = 1;
318 pub const LOCAL = UNIX;
319 pub const FILE = UNIX;
320 pub const INET = 2;
321 pub const IMPLINK = 3;
322 pub const PUP = 4;
323 pub const CHAOS = 5;
324 pub const NS = 6;
325 pub const NBS = 7;
326 pub const ECMA = 8;
327 pub const DATAKIT = 9;
328 pub const CCITT = 10;
329 pub const SNA = 11;
330 pub const DECnet = 12;
331 pub const DLI = 13;
332 pub const LAT = 14;
333 pub const HYLINK = 15;
334 pub const APPLETALK = 16;
335 pub const NIT = 17;
336 pub const @"802" = 18;
337 pub const OSI = 19;
338 pub const X25 = 20;
339 pub const OSINET = 21;
340 pub const GOSIP = 22;
341 pub const IPX = 23;
342 pub const ROUTE = 24;
343 pub const LINK = 25;
344 pub const INET6 = 26;
345 pub const KEY = 27;
346 pub const NCA = 28;
347 pub const POLICY = 29;
348 pub const INET_OFFLOAD = 30;
349 pub const TRILL = 31;
350 pub const PACKET = 32;
351 pub const LX_NETLINK = 33;
352 pub const MAX = 33;
353};
354
355pub const SOL = struct {
356 pub const SOCKET = 0xffff;
357 pub const ROUTE = 0xfffe;
358 pub const PACKET = 0xfffd;
359 pub const FILTER = 0xfffc;
360};
361
362pub const PF = struct {
363 pub const UNSPEC = AF.UNSPEC;
364 pub const UNIX = AF.UNIX;
365 pub const LOCAL = UNIX;
366 pub const FILE = UNIX;
367 pub const INET = AF.INET;
368 pub const IMPLINK = AF.IMPLINK;
369 pub const PUP = AF.PUP;
370 pub const CHAOS = AF.CHAOS;
371 pub const NS = AF.NS;
372 pub const NBS = AF.NBS;
373 pub const ECMA = AF.ECMA;
374 pub const DATAKIT = AF.DATAKIT;
375 pub const CCITT = AF.CCITT;
376 pub const SNA = AF.SNA;
377 pub const DECnet = AF.DECnet;
378 pub const DLI = AF.DLI;
379 pub const LAT = AF.LAT;
380 pub const HYLINK = AF.HYLINK;
381 pub const APPLETALK = AF.APPLETALK;
382 pub const NIT = AF.NIT;
383 pub const @"802" = AF.@"802";
384 pub const OSI = AF.OSI;
385 pub const X25 = AF.X25;
386 pub const OSINET = AF.OSINET;
387 pub const GOSIP = AF.GOSIP;
388 pub const IPX = AF.IPX;
389 pub const ROUTE = AF.ROUTE;
390 pub const LINK = AF.LINK;
391 pub const INET6 = AF.INET6;
392 pub const KEY = AF.KEY;
393 pub const NCA = AF.NCA;
394 pub const POLICY = AF.POLICY;
395 pub const TRILL = AF.TRILL;
396 pub const PACKET = AF.PACKET;
397 pub const LX_NETLINK = AF.LX_NETLINK;
398 pub const MAX = AF.MAX;
399};
400
401pub const in_port_t = u16;
402pub const sa_family_t = u16;
403
404pub const sockaddr = extern struct {
405 /// address family
406 family: sa_family_t,
407
408 /// actually longer; address value
409 data: [14]u8,
410
411 pub const SS_MAXSIZE = 256;
412 pub const storage = extern struct {
413 family: sa_family_t align(8),
414 padding: [254]u8 = undefined,
415
416 comptime {
417 assert(@sizeOf(storage) == SS_MAXSIZE);
418 assert(@alignOf(storage) == 8);
419 }
420 };
421
422 pub const in = extern struct {
423 family: sa_family_t = AF.INET,
424 port: in_port_t,
425 addr: u32,
426 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
427 };
428
429 pub const in6 = extern struct {
430 family: sa_family_t = AF.INET6,
431 port: in_port_t,
432 flowinfo: u32,
433 addr: [16]u8,
434 scope_id: u32,
435 __src_id: u32 = 0,
436 };
437
438 /// Definitions for UNIX IPC domain.
439 pub const un = extern struct {
440 family: sa_family_t = AF.UNIX,
441 path: [108]u8,
442 };
443};
444
445pub const AI = struct {
446 /// IPv4-mapped IPv6 address
447 pub const V4MAPPED = 0x0001;
448 pub const ALL = 0x0002;
449 /// only if any address is assigned
450 pub const ADDRCONFIG = 0x0004;
451 /// get address to use bind()
452 pub const PASSIVE = 0x0008;
453 /// fill ai_canonname
454 pub const CANONNAME = 0x0010;
455 /// prevent host name resolution
456 pub const NUMERICHOST = 0x0020;
457 /// prevent service name resolution
458 pub const NUMERICSERV = 0x0040;
459};
460
461pub const NI = struct {
462 pub const NOFQDN = 0x0001;
463 pub const NUMERICHOST = 0x0002;
464 pub const NAMEREQD = 0x0004;
465 pub const NUMERICSERV = 0x0008;
466 pub const DGRAM = 0x0010;
467 pub const WITHSCOPEID = 0x0020;
468 pub const NUMERICSCOPE = 0x0040;
469
470 pub const MAXHOST = 1025;
471 pub const MAXSERV = 32;
472};
473
474pub const NAME_MAX = 255;
475pub const PATH_MAX = 1024;
476pub const IOV_MAX = 1024;
477
478pub const STDIN_FILENO = 0;
479pub const STDOUT_FILENO = 1;
480pub const STDERR_FILENO = 2;
481
482pub const PROT = struct {
483 pub const NONE = 0;
484 pub const READ = 1;
485 pub const WRITE = 2;
486 pub const EXEC = 4;
487};
488
489pub const CLOCK = struct {
490 pub const VIRTUAL = 1;
491 pub const THREAD_CPUTIME_ID = 2;
492 pub const REALTIME = 3;
493 pub const MONOTONIC = 4;
494 pub const PROCESS_CPUTIME_ID = 5;
495 pub const HIGHRES = MONOTONIC;
496 pub const PROF = THREAD_CPUTIME_ID;
497};
498
499pub const MSF = struct {
500 pub const ASYNC = 1;
501 pub const INVALIDATE = 2;
502 pub const SYNC = 4;
503};
504
505pub const MADV = struct {
506 /// no further special treatment
507 pub const NORMAL = 0;
508 /// expect random page references
509 pub const RANDOM = 1;
510 /// expect sequential page references
511 pub const SEQUENTIAL = 2;
512 /// will need these pages
513 pub const WILLNEED = 3;
514 /// don't need these pages
515 pub const DONTNEED = 4;
516 /// contents can be freed
517 pub const FREE = 5;
518 /// default access
519 pub const ACCESS_DEFAULT = 6;
520 /// next LWP to access heavily
521 pub const ACCESS_LWP = 7;
522 /// many processes to access heavily
523 pub const ACCESS_MANY = 8;
524 /// contents will be purged
525 pub const PURGE = 9;
526};
527
528pub const W = struct {
529 pub const EXITED = 0o001;
530 pub const TRAPPED = 0o002;
531 pub const UNTRACED = 0o004;
532 pub const STOPPED = UNTRACED;
533 pub const CONTINUED = 0o010;
534 pub const NOHANG = 0o100;
535 pub const NOWAIT = 0o200;
536
537 pub fn EXITSTATUS(s: u32) u8 {
538 return @as(u8, @intCast((s >> 8) & 0xff));
539 }
540 pub fn TERMSIG(s: u32) u32 {
541 return s & 0x7f;
542 }
543 pub fn STOPSIG(s: u32) u32 {
544 return EXITSTATUS(s);
545 }
546 pub fn IFEXITED(s: u32) bool {
547 return TERMSIG(s) == 0;
548 }
549
550 pub fn IFCONTINUED(s: u32) bool {
551 return ((s & 0o177777) == 0o177777);
552 }
553
554 pub fn IFSTOPPED(s: u32) bool {
555 return (s & 0x00ff != 0o177) and !(s & 0xff00 != 0);
556 }
557
558 pub fn IFSIGNALED(s: u32) bool {
559 return s & 0x00ff > 0 and s & 0xff00 == 0;
560 }
561};
562
563pub const SA = struct {
564 pub const ONSTACK = 0x00000001;
565 pub const RESETHAND = 0x00000002;
566 pub const RESTART = 0x00000004;
567 pub const SIGINFO = 0x00000008;
568 pub const NODEFER = 0x00000010;
569 pub const NOCLDWAIT = 0x00010000;
570};
571
572// access function
573pub const F_OK = 0; // test for existence of file
574pub const X_OK = 1; // test for execute or search permission
575pub const W_OK = 2; // test for write permission
576pub const R_OK = 4; // test for read permission
577
578pub const F = struct {
579 /// Unlock a previously locked region
580 pub const ULOCK = 0;
581 /// Lock a region for exclusive use
582 pub const LOCK = 1;
583 /// Test and lock a region for exclusive use
584 pub const TLOCK = 2;
585 /// Test a region for other processes locks
586 pub const TEST = 3;
587
588 /// Duplicate fildes
589 pub const DUPFD = 0;
590 /// Get fildes flags
591 pub const GETFD = 1;
592 /// Set fildes flags
593 pub const SETFD = 2;
594 /// Get file flags
595 pub const GETFL = 3;
596 /// Get file flags including open-only flags
597 pub const GETXFL = 45;
598 /// Set file flags
599 pub const SETFL = 4;
600
601 /// Unused
602 pub const CHKFL = 8;
603 /// Duplicate fildes at third arg
604 pub const DUP2FD = 9;
605 /// Like DUP2FD with O_CLOEXEC set EINVAL is fildes matches arg1
606 pub const DUP2FD_CLOEXEC = 36;
607 /// Like DUPFD with O_CLOEXEC set
608 pub const DUPFD_CLOEXEC = 37;
609
610 /// Is the file desc. a stream ?
611 pub const ISSTREAM = 13;
612 /// Turn on private access to file
613 pub const PRIV = 15;
614 /// Turn off private access to file
615 pub const NPRIV = 16;
616 /// UFS quota call
617 pub const QUOTACTL = 17;
618 /// Get number of BLKSIZE blocks allocated
619 pub const BLOCKS = 18;
620 /// Get optimal I/O block size
621 pub const BLKSIZE = 19;
622 /// Get owner (socket emulation)
623 pub const GETOWN = 23;
624 /// Set owner (socket emulation)
625 pub const SETOWN = 24;
626 /// Object reuse revoke access to file desc.
627 pub const REVOKE = 25;
628 /// Does vp have NFS locks private to lock manager
629 pub const HASREMOTELOCKS = 26;
630
631 /// Set file lock
632 pub const SETLK = 6;
633 /// Set file lock and wait
634 pub const SETLKW = 7;
635 /// Allocate file space
636 pub const ALLOCSP = 10;
637 /// Free file space
638 pub const FREESP = 11;
639 /// Get file lock
640 pub const GETLK = 14;
641 /// Get file lock owned by file
642 pub const OFD_GETLK = 47;
643 /// Set file lock owned by file
644 pub const OFD_SETLK = 48;
645 /// Set file lock owned by file and wait
646 pub const OFD_SETLKW = 49;
647 /// Set a file share reservation
648 pub const SHARE = 40;
649 /// Remove a file share reservation
650 pub const UNSHARE = 41;
651 /// Create Poison FD
652 pub const BADFD = 46;
653
654 /// Read lock
655 pub const RDLCK = 1;
656 /// Write lock
657 pub const WRLCK = 2;
658 /// Remove lock(s)
659 pub const UNLCK = 3;
660 /// remove remote locks for a given system
661 pub const UNLKSYS = 4;
662
663 // f_access values
664 /// Read-only share access
665 pub const RDACC = 0x1;
666 /// Write-only share access
667 pub const WRACC = 0x2;
668 /// Read-Write share access
669 pub const RWACC = 0x3;
670
671 // f_deny values
672 /// Don't deny others access
673 pub const NODNY = 0x0;
674 /// Deny others read share access
675 pub const RDDNY = 0x1;
676 /// Deny others write share access
677 pub const WRDNY = 0x2;
678 /// Deny others read or write share access
679 pub const RWDNY = 0x3;
680 /// private flag: Deny delete share access
681 pub const RMDNY = 0x4;
682};
683
684pub const LOCK = struct {
685 pub const SH = 1;
686 pub const EX = 2;
687 pub const NB = 4;
688 pub const UN = 8;
689};
690
691pub const FD_CLOEXEC = 1;
692
693pub const SEEK = struct {
694 pub const SET = 0;
695 pub const CUR = 1;
696 pub const END = 2;
697 pub const DATA = 3;
698 pub const HOLE = 4;
699};
700
701fn tioc(t: u16, num: u8) u16 {
702 return (t << 8) | num;
703}
704
705pub const T = struct {
706 pub const CGETA = tioc('T', 1);
707 pub const CSETA = tioc('T', 2);
708 pub const CSETAW = tioc('T', 3);
709 pub const CSETAF = tioc('T', 4);
710 pub const CSBRK = tioc('T', 5);
711 pub const CXONC = tioc('T', 6);
712 pub const CFLSH = tioc('T', 7);
713 pub const IOCGWINSZ = tioc('T', 104);
714 pub const IOCSWINSZ = tioc('T', 103);
715 // Softcarrier ioctls
716 pub const IOCGSOFTCAR = tioc('T', 105);
717 pub const IOCSSOFTCAR = tioc('T', 106);
718 // termios ioctls
719 pub const CGETS = tioc('T', 13);
720 pub const CSETS = tioc('T', 14);
721 pub const CSANOW = tioc('T', 14);
722 pub const CSETSW = tioc('T', 15);
723 pub const CSADRAIN = tioc('T', 15);
724 pub const CSETSF = tioc('T', 16);
725 pub const IOCSETLD = tioc('T', 123);
726 pub const IOCGETLD = tioc('T', 124);
727 // NTP PPS ioctls
728 pub const IOCGPPS = tioc('T', 125);
729 pub const IOCSPPS = tioc('T', 126);
730 pub const IOCGPPSEV = tioc('T', 127);
731
732 pub const IOCGETD = tioc('t', 0);
733 pub const IOCSETD = tioc('t', 1);
734 pub const IOCHPCL = tioc('t', 2);
735 pub const IOCGETP = tioc('t', 8);
736 pub const IOCSETP = tioc('t', 9);
737 pub const IOCSETN = tioc('t', 10);
738 pub const IOCEXCL = tioc('t', 13);
739 pub const IOCNXCL = tioc('t', 14);
740 pub const IOCFLUSH = tioc('t', 16);
741 pub const IOCSETC = tioc('t', 17);
742 pub const IOCGETC = tioc('t', 18);
743 /// bis local mode bits
744 pub const IOCLBIS = tioc('t', 127);
745 /// bic local mode bits
746 pub const IOCLBIC = tioc('t', 126);
747 /// set entire local mode word
748 pub const IOCLSET = tioc('t', 125);
749 /// get local modes
750 pub const IOCLGET = tioc('t', 124);
751 /// set break bit
752 pub const IOCSBRK = tioc('t', 123);
753 /// clear break bit
754 pub const IOCCBRK = tioc('t', 122);
755 /// set data terminal ready
756 pub const IOCSDTR = tioc('t', 121);
757 /// clear data terminal ready
758 pub const IOCCDTR = tioc('t', 120);
759 /// set local special chars
760 pub const IOCSLTC = tioc('t', 117);
761 /// get local special chars
762 pub const IOCGLTC = tioc('t', 116);
763 /// driver output queue size
764 pub const IOCOUTQ = tioc('t', 115);
765 /// void tty association
766 pub const IOCNOTTY = tioc('t', 113);
767 /// get a ctty
768 pub const IOCSCTTY = tioc('t', 132);
769 /// stop output, like ^S
770 pub const IOCSTOP = tioc('t', 111);
771 /// start output, like ^Q
772 pub const IOCSTART = tioc('t', 110);
773 /// get pgrp of tty
774 pub const IOCGPGRP = tioc('t', 20);
775 /// set pgrp of tty
776 pub const IOCSPGRP = tioc('t', 21);
777 /// get session id on ctty
778 pub const IOCGSID = tioc('t', 22);
779 /// simulate terminal input
780 pub const IOCSTI = tioc('t', 23);
781 /// set all modem bits
782 pub const IOCMSET = tioc('t', 26);
783 /// bis modem bits
784 pub const IOCMBIS = tioc('t', 27);
785 /// bic modem bits
786 pub const IOCMBIC = tioc('t', 28);
787 /// get all modem bits
788 pub const IOCMGET = tioc('t', 29);
789};
790
791pub const winsize = extern struct {
792 ws_row: u16,
793 ws_col: u16,
794 ws_xpixel: u16,
795 ws_ypixel: u16,
796};
797
798const NSIG = 75;
799
800pub const SIG = struct {
801 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
802 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
803 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
804 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(2);
805
806 pub const WORDS = 4;
807 pub const MAXSIG = 75;
808
809 pub const SIG_BLOCK = 1;
810 pub const SIG_UNBLOCK = 2;
811 pub const SIG_SETMASK = 3;
812
813 pub const HUP = 1;
814 pub const INT = 2;
815 pub const QUIT = 3;
816 pub const ILL = 4;
817 pub const TRAP = 5;
818 pub const IOT = 6;
819 pub const ABRT = 6;
820 pub const EMT = 7;
821 pub const FPE = 8;
822 pub const KILL = 9;
823 pub const BUS = 10;
824 pub const SEGV = 11;
825 pub const SYS = 12;
826 pub const PIPE = 13;
827 pub const ALRM = 14;
828 pub const TERM = 15;
829 pub const USR1 = 16;
830 pub const USR2 = 17;
831 pub const CLD = 18;
832 pub const CHLD = 18;
833 pub const PWR = 19;
834 pub const WINCH = 20;
835 pub const URG = 21;
836 pub const POLL = 22;
837 pub const IO = .POLL;
838 pub const STOP = 23;
839 pub const TSTP = 24;
840 pub const CONT = 25;
841 pub const TTIN = 26;
842 pub const TTOU = 27;
843 pub const VTALRM = 28;
844 pub const PROF = 29;
845 pub const XCPU = 30;
846 pub const XFSZ = 31;
847 pub const WAITING = 32;
848 pub const LWP = 33;
849 pub const FREEZE = 34;
850 pub const THAW = 35;
851 pub const CANCEL = 36;
852 pub const LOST = 37;
853 pub const XRES = 38;
854 pub const JVM1 = 39;
855 pub const JVM2 = 40;
856 pub const INFO = 41;
857
858 pub const RTMIN = 42;
859 pub const RTMAX = 74;
860
861 pub inline fn IDX(sig: usize) usize {
862 return sig - 1;
863 }
864 pub inline fn WORD(sig: usize) usize {
865 return IDX(sig) >> 5;
866 }
867 pub inline fn BIT(sig: usize) usize {
868 return 1 << (IDX(sig) & 31);
869 }
870 pub inline fn VALID(sig: usize) usize {
871 return sig <= MAXSIG and sig > 0;
872 }
873};
874
875/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
876pub const Sigaction = extern struct {
877 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
878 pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
879
880 /// signal options
881 flags: c_uint,
882 /// signal handler
883 handler: extern union {
884 handler: ?handler_fn,
885 sigaction: ?sigaction_fn,
886 },
887 /// signal mask to apply
888 mask: sigset_t,
889};
890
891pub const sigval_t = extern union {
892 int: c_int,
893 ptr: ?*anyopaque,
894};
895
896pub const siginfo_t = extern struct {
897 signo: c_int,
898 code: c_int,
899 errno: c_int,
900 // 64bit architectures insert 4bytes of padding here, this is done by
901 // correctly aligning the reason field
902 reason: extern union {
903 proc: extern struct {
904 pid: pid_t,
905 pdata: extern union {
906 kill: extern struct {
907 uid: uid_t,
908 value: sigval_t,
909 },
910 cld: extern struct {
911 utime: clock_t,
912 status: c_int,
913 stime: clock_t,
914 },
915 },
916 contract: ctid_t,
917 zone: zoneid_t,
918 },
919 fault: extern struct {
920 addr: *allowzero anyopaque,
921 trapno: c_int,
922 pc: ?*anyopaque,
923 },
924 file: extern struct {
925 // fd not currently available for SIGPOLL.
926 fd: c_int,
927 band: c_long,
928 },
929 prof: extern struct {
930 addr: ?*anyopaque,
931 timestamp: timespec,
932 syscall: c_short,
933 sysarg: u8,
934 fault: u8,
935 args: [8]c_long,
936 state: [10]c_int,
937 },
938 rctl: extern struct {
939 entity: i32,
940 },
941 __pad: [256 - 4 * @sizeOf(c_int)]u8,
942 } align(@sizeOf(usize)),
943};
944
945comptime {
946 std.debug.assert(@sizeOf(siginfo_t) == 256);
947 std.debug.assert(@alignOf(siginfo_t) == @sizeOf(usize));
948}
949
950pub const sigset_t = extern struct {
951 __bits: [SIG.WORDS]u32,
952};
953
954pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** SIG.WORDS };
955
95646pub const fpregset_t = extern union {
95747 regs: [130]u32,
95848 chip_state: extern struct {
......@@ -976,393 +66,11 @@ pub const fpregset_t = extern union {
97666 },
97767};
97868
979pub const mcontext_t = extern struct {
980 gregs: [28]u64,
981 fpregs: fpregset_t,
982};
983
984pub const REG = struct {
985 pub const R15 = 0;
986 pub const R14 = 1;
987 pub const R13 = 2;
988 pub const R12 = 3;
989 pub const R11 = 4;
990 pub const R10 = 5;
991 pub const R9 = 6;
992 pub const R8 = 7;
993 pub const RDI = 8;
994 pub const RSI = 9;
995 pub const RBP = 10;
996 pub const RBX = 11;
997 pub const RDX = 12;
998 pub const RCX = 13;
999 pub const RAX = 14;
1000 pub const RIP = 17;
1001 pub const RSP = 20;
1002};
1003
1004pub const ucontext_t = extern struct {
1005 flags: u64,
1006 link: ?*ucontext_t,
1007 sigmask: sigset_t,
1008 stack: stack_t,
1009 mcontext: mcontext_t,
1010 brand_data: [3]?*anyopaque,
1011 filler: [2]i64,
1012};
1013
101469pub const GETCONTEXT = 0;
101570pub const SETCONTEXT = 1;
101671pub const GETUSTACK = 2;
101772pub const SETUSTACK = 3;
101873
1019pub const E = enum(u16) {
1020 /// No error occurred.
1021 SUCCESS = 0,
1022 /// Not super-user
1023 PERM = 1,
1024 /// No such file or directory
1025 NOENT = 2,
1026 /// No such process
1027 SRCH = 3,
1028 /// interrupted system call
1029 INTR = 4,
1030 /// I/O error
1031 IO = 5,
1032 /// No such device or address
1033 NXIO = 6,
1034 /// Arg list too long
1035 @"2BIG" = 7,
1036 /// Exec format error
1037 NOEXEC = 8,
1038 /// Bad file number
1039 BADF = 9,
1040 /// No children
1041 CHILD = 10,
1042 /// Resource temporarily unavailable.
1043 /// also: WOULDBLOCK: Operation would block.
1044 AGAIN = 11,
1045 /// Not enough core
1046 NOMEM = 12,
1047 /// Permission denied
1048 ACCES = 13,
1049 /// Bad address
1050 FAULT = 14,
1051 /// Block device required
1052 NOTBLK = 15,
1053 /// Mount device busy
1054 BUSY = 16,
1055 /// File exists
1056 EXIST = 17,
1057 /// Cross-device link
1058 XDEV = 18,
1059 /// No such device
1060 NODEV = 19,
1061 /// Not a directory
1062 NOTDIR = 20,
1063 /// Is a directory
1064 ISDIR = 21,
1065 /// Invalid argument
1066 INVAL = 22,
1067 /// File table overflow
1068 NFILE = 23,
1069 /// Too many open files
1070 MFILE = 24,
1071 /// Inappropriate ioctl for device
1072 NOTTY = 25,
1073 /// Text file busy
1074 TXTBSY = 26,
1075 /// File too large
1076 FBIG = 27,
1077 /// No space left on device
1078 NOSPC = 28,
1079 /// Illegal seek
1080 SPIPE = 29,
1081 /// Read only file system
1082 ROFS = 30,
1083 /// Too many links
1084 MLINK = 31,
1085 /// Broken pipe
1086 PIPE = 32,
1087 /// Math arg out of domain of func
1088 DOM = 33,
1089 /// Math result not representable
1090 RANGE = 34,
1091 /// No message of desired type
1092 NOMSG = 35,
1093 /// Identifier removed
1094 IDRM = 36,
1095 /// Channel number out of range
1096 CHRNG = 37,
1097 /// Level 2 not synchronized
1098 L2NSYNC = 38,
1099 /// Level 3 halted
1100 L3HLT = 39,
1101 /// Level 3 reset
1102 L3RST = 40,
1103 /// Link number out of range
1104 LNRNG = 41,
1105 /// Protocol driver not attached
1106 UNATCH = 42,
1107 /// No CSI structure available
1108 NOCSI = 43,
1109 /// Level 2 halted
1110 L2HLT = 44,
1111 /// Deadlock condition.
1112 DEADLK = 45,
1113 /// No record locks available.
1114 NOLCK = 46,
1115 /// Operation canceled
1116 CANCELED = 47,
1117 /// Operation not supported
1118 NOTSUP = 48,
1119
1120 // Filesystem Quotas
1121 /// Disc quota exceeded
1122 DQUOT = 49,
1123
1124 // Convergent Error Returns
1125 /// invalid exchange
1126 BADE = 50,
1127 /// invalid request descriptor
1128 BADR = 51,
1129 /// exchange full
1130 XFULL = 52,
1131 /// no anode
1132 NOANO = 53,
1133 /// invalid request code
1134 BADRQC = 54,
1135 /// invalid slot
1136 BADSLT = 55,
1137 /// file locking deadlock error
1138 DEADLOCK = 56,
1139 /// bad font file fmt
1140 BFONT = 57,
1141
1142 // Interprocess Robust Locks
1143 /// process died with the lock
1144 OWNERDEAD = 58,
1145 /// lock is not recoverable
1146 NOTRECOVERABLE = 59,
1147 /// locked lock was unmapped
1148 LOCKUNMAPPED = 72,
1149 /// Facility is not active
1150 NOTACTIVE = 73,
1151 /// multihop attempted
1152 MULTIHOP = 74,
1153 /// trying to read unreadable message
1154 BADMSG = 77,
1155 /// path name is too long
1156 NAMETOOLONG = 78,
1157 /// value too large to be stored in data type
1158 OVERFLOW = 79,
1159 /// given log. name not unique
1160 NOTUNIQ = 80,
1161 /// f.d. invalid for this operation
1162 BADFD = 81,
1163 /// Remote address changed
1164 REMCHG = 82,
1165
1166 // Stream Problems
1167 /// Device not a stream
1168 NOSTR = 60,
1169 /// no data (for no delay io)
1170 NODATA = 61,
1171 /// timer expired
1172 TIME = 62,
1173 /// out of streams resources
1174 NOSR = 63,
1175 /// Machine is not on the network
1176 NONET = 64,
1177 /// Package not installed
1178 NOPKG = 65,
1179 /// The object is remote
1180 REMOTE = 66,
1181 /// the link has been severed
1182 NOLINK = 67,
1183 /// advertise error
1184 ADV = 68,
1185 /// srmount error
1186 SRMNT = 69,
1187 /// Communication error on send
1188 COMM = 70,
1189 /// Protocol error
1190 PROTO = 71,
1191
1192 // Shared Library Problems
1193 /// Can't access a needed shared lib.
1194 LIBACC = 83,
1195 /// Accessing a corrupted shared lib.
1196 LIBBAD = 84,
1197 /// .lib section in a.out corrupted.
1198 LIBSCN = 85,
1199 /// Attempting to link in too many libs.
1200 LIBMAX = 86,
1201 /// Attempting to exec a shared library.
1202 LIBEXEC = 87,
1203 /// Illegal byte sequence.
1204 ILSEQ = 88,
1205 /// Unsupported file system operation
1206 NOSYS = 89,
1207 /// Symbolic link loop
1208 LOOP = 90,
1209 /// Restartable system call
1210 RESTART = 91,
1211 /// if pipe/FIFO, don't sleep in stream head
1212 STRPIPE = 92,
1213 /// directory not empty
1214 NOTEMPTY = 93,
1215 /// Too many users (for UFS)
1216 USERS = 94,
1217
1218 // BSD Networking Software
1219 // Argument Errors
1220 /// Socket operation on non-socket
1221 NOTSOCK = 95,
1222 /// Destination address required
1223 DESTADDRREQ = 96,
1224 /// Message too long
1225 MSGSIZE = 97,
1226 /// Protocol wrong type for socket
1227 PROTOTYPE = 98,
1228 /// Protocol not available
1229 NOPROTOOPT = 99,
1230 /// Protocol not supported
1231 PROTONOSUPPORT = 120,
1232 /// Socket type not supported
1233 SOCKTNOSUPPORT = 121,
1234 /// Operation not supported on socket
1235 OPNOTSUPP = 122,
1236 /// Protocol family not supported
1237 PFNOSUPPORT = 123,
1238 /// Address family not supported by
1239 AFNOSUPPORT = 124,
1240 /// Address already in use
1241 ADDRINUSE = 125,
1242 /// Can't assign requested address
1243 ADDRNOTAVAIL = 126,
1244
1245 // Operational Errors
1246 /// Network is down
1247 NETDOWN = 127,
1248 /// Network is unreachable
1249 NETUNREACH = 128,
1250 /// Network dropped connection because
1251 NETRESET = 129,
1252 /// Software caused connection abort
1253 CONNABORTED = 130,
1254 /// Connection reset by peer
1255 CONNRESET = 131,
1256 /// No buffer space available
1257 NOBUFS = 132,
1258 /// Socket is already connected
1259 ISCONN = 133,
1260 /// Socket is not connected
1261 NOTCONN = 134,
1262 /// Can't send after socket shutdown
1263 SHUTDOWN = 143,
1264 /// Too many references: can't splice
1265 TOOMANYREFS = 144,
1266 /// Connection timed out
1267 TIMEDOUT = 145,
1268 /// Connection refused
1269 CONNREFUSED = 146,
1270 /// Host is down
1271 HOSTDOWN = 147,
1272 /// No route to host
1273 HOSTUNREACH = 148,
1274 /// operation already in progress
1275 ALREADY = 149,
1276 /// operation now in progress
1277 INPROGRESS = 150,
1278
1279 // SUN Network File System
1280 /// Stale NFS file handle
1281 STALE = 151,
1282
1283 _,
1284};
1285
1286pub const MINSIGSTKSZ = 2048;
1287pub const SIGSTKSZ = 8192;
1288
1289pub const SS_ONSTACK = 0x1;
1290pub const SS_DISABLE = 0x2;
1291
1292pub const stack_t = extern struct {
1293 sp: [*]u8,
1294 size: isize,
1295 flags: i32,
1296};
1297
1298pub const S = struct {
1299 pub const IFMT = 0o170000;
1300
1301 pub const IFIFO = 0o010000;
1302 pub const IFCHR = 0o020000;
1303 pub const IFDIR = 0o040000;
1304 pub const IFBLK = 0o060000;
1305 pub const IFREG = 0o100000;
1306 pub const IFLNK = 0o120000;
1307 pub const IFSOCK = 0o140000;
1308 /// SunOS 2.6 Door
1309 pub const IFDOOR = 0o150000;
1310 /// Solaris 10 Event Port
1311 pub const IFPORT = 0o160000;
1312
1313 pub const ISUID = 0o4000;
1314 pub const ISGID = 0o2000;
1315 pub const ISVTX = 0o1000;
1316 pub const IRWXU = 0o700;
1317 pub const IRUSR = 0o400;
1318 pub const IWUSR = 0o200;
1319 pub const IXUSR = 0o100;
1320 pub const IRWXG = 0o070;
1321 pub const IRGRP = 0o040;
1322 pub const IWGRP = 0o020;
1323 pub const IXGRP = 0o010;
1324 pub const IRWXO = 0o007;
1325 pub const IROTH = 0o004;
1326 pub const IWOTH = 0o002;
1327 pub const IXOTH = 0o001;
1328
1329 pub fn ISFIFO(m: u32) bool {
1330 return m & IFMT == IFIFO;
1331 }
1332
1333 pub fn ISCHR(m: u32) bool {
1334 return m & IFMT == IFCHR;
1335 }
1336
1337 pub fn ISDIR(m: u32) bool {
1338 return m & IFMT == IFDIR;
1339 }
1340
1341 pub fn ISBLK(m: u32) bool {
1342 return m & IFMT == IFBLK;
1343 }
1344
1345 pub fn ISREG(m: u32) bool {
1346 return m & IFMT == IFREG;
1347 }
1348
1349 pub fn ISLNK(m: u32) bool {
1350 return m & IFMT == IFLNK;
1351 }
1352
1353 pub fn ISSOCK(m: u32) bool {
1354 return m & IFMT == IFSOCK;
1355 }
1356
1357 pub fn ISDOOR(m: u32) bool {
1358 return m & IFMT == IFDOOR;
1359 }
1360
1361 pub fn ISPORT(m: u32) bool {
1362 return m & IFMT == IFPORT;
1363 }
1364};
1365
136674pub const POSIX_FADV = struct {
136775 pub const NORMAL = 0;
136876 pub const RANDOM = 1;
......@@ -1372,67 +80,6 @@ pub const POSIX_FADV = struct {
137280 pub const NOREUSE = 5;
137381};
137482
1375pub const HOST_NAME_MAX = 255;
1376
1377pub const IPPROTO = struct {
1378 /// dummy for IP
1379 pub const IP = 0;
1380 /// Hop by hop header for IPv6
1381 pub const HOPOPTS = 0;
1382 /// control message protocol
1383 pub const ICMP = 1;
1384 /// group control protocol
1385 pub const IGMP = 2;
1386 /// gateway^2 (deprecated)
1387 pub const GGP = 3;
1388 /// IP in IP encapsulation
1389 pub const ENCAP = 4;
1390 /// tcp
1391 pub const TCP = 6;
1392 /// exterior gateway protocol
1393 pub const EGP = 8;
1394 /// pup
1395 pub const PUP = 12;
1396 /// user datagram protocol
1397 pub const UDP = 17;
1398 /// xns idp
1399 pub const IDP = 22;
1400 /// IPv6 encapsulated in IP
1401 pub const IPV6 = 41;
1402 /// Routing header for IPv6
1403 pub const ROUTING = 43;
1404 /// Fragment header for IPv6
1405 pub const FRAGMENT = 44;
1406 /// rsvp
1407 pub const RSVP = 46;
1408 /// IPsec Encap. Sec. Payload
1409 pub const ESP = 50;
1410 /// IPsec Authentication Hdr.
1411 pub const AH = 51;
1412 /// ICMP for IPv6
1413 pub const ICMPV6 = 58;
1414 /// No next header for IPv6
1415 pub const NONE = 59;
1416 /// Destination options
1417 pub const DSTOPTS = 60;
1418 /// "hello" routing protocol
1419 pub const HELLO = 63;
1420 /// UNOFFICIAL net disk proto
1421 pub const ND = 77;
1422 /// ISO clnp
1423 pub const EON = 80;
1424 /// OSPF
1425 pub const OSPF = 89;
1426 /// PIM routing protocol
1427 pub const PIM = 103;
1428 /// Stream Control
1429 pub const SCTP = 132;
1430 /// raw IP packet
1431 pub const RAW = 255;
1432 /// Sockets Direct Protocol
1433 pub const PROTO_SDP = 257;
1434};
1435
143683pub const priority = enum(c_int) {
143784 PROCESS = 0,
143885 PGRP = 1,
......@@ -1446,93 +93,6 @@ pub const priority = enum(c_int) {
144693 CONTRACT = 9,
144794};
144895
1449pub const rlimit_resource = enum(c_int) {
1450 CPU = 0,
1451 FSIZE = 1,
1452 DATA = 2,
1453 STACK = 3,
1454 CORE = 4,
1455 NOFILE = 5,
1456 VMEM = 6,
1457 _,
1458
1459 pub const AS: rlimit_resource = .VMEM;
1460};
1461
1462pub const rlim_t = u64;
1463
1464pub const RLIM = struct {
1465 /// No limit
1466 pub const INFINITY: rlim_t = (1 << 63) - 3;
1467 pub const SAVED_MAX: rlim_t = (1 << 63) - 2;
1468 pub const SAVED_CUR: rlim_t = (1 << 63) - 1;
1469};
1470
1471pub const rlimit = extern struct {
1472 /// Soft limit
1473 cur: rlim_t,
1474 /// Hard limit
1475 max: rlim_t,
1476};
1477
1478pub const rusage = extern struct {
1479 utime: timeval,
1480 stime: timeval,
1481 maxrss: isize,
1482 ixrss: isize,
1483 idrss: isize,
1484 isrss: isize,
1485 minflt: isize,
1486 majflt: isize,
1487 nswap: isize,
1488 inblock: isize,
1489 oublock: isize,
1490 msgsnd: isize,
1491 msgrcv: isize,
1492 nsignals: isize,
1493 nvcsw: isize,
1494 nivcsw: isize,
1495
1496 pub const SELF = 0;
1497 pub const CHILDREN = -1;
1498 pub const THREAD = 1;
1499};
1500
1501pub const SHUT = struct {
1502 pub const RD = 0;
1503 pub const WR = 1;
1504 pub const RDWR = 2;
1505};
1506
1507pub const pollfd = extern struct {
1508 fd: fd_t,
1509 events: i16,
1510 revents: i16,
1511};
1512
1513/// Testable events (may be specified in ::pollfd::events).
1514pub const POLL = struct {
1515 pub const IN = 0x0001;
1516 pub const PRI = 0x0002;
1517 pub const OUT = 0x0004;
1518 pub const RDNORM = 0x0040;
1519 pub const WRNORM = .OUT;
1520 pub const RDBAND = 0x0080;
1521 pub const WRBAND = 0x0100;
1522 /// Read-side hangup.
1523 pub const RDHUP = 0x4000;
1524
1525 /// Non-testable events (may not be specified in events).
1526 pub const ERR = 0x0008;
1527 pub const HUP = 0x0010;
1528 pub const NVAL = 0x0020;
1529
1530 /// Events to control `/dev/poll` (not specified in revents)
1531 pub const REMOVE = 0x0800;
1532 pub const ONESHOT = 0x1000;
1533 pub const ET = 0x2000;
1534};
1535
153696/// Extensions to the ELF auxiliary vector.
153797pub const AT_SUN = struct {
153898 /// effective user id
......@@ -1594,7 +154,6 @@ pub const AF_SUN = struct {
1594154 pub const NOPLM = 0x00000004;
1595155};
1596156
1597// TODO: Add sysconf numbers when the other OSs do.
1598157pub const _SC = struct {
1599158 pub const NPROCESSORS_ONLN = 15;
1600159};
......@@ -1702,17 +261,6 @@ pub const FILE_EVENT = struct {
1702261 }
1703262};
1704263
1705pub const port_event = extern struct {
1706 events: u32,
1707 /// Event source.
1708 source: u16,
1709 __pad: u16,
1710 /// Source-specific object.
1711 object: ?*anyopaque,
1712 /// User cookie.
1713 cookie: ?*anyopaque,
1714};
1715
1716264pub const port_notify = extern struct {
1717265 /// Bind request(s) to port.
1718266 port: u32,
......@@ -1734,9 +282,6 @@ pub const file_obj = extern struct {
1734282// struct ifreq is marked obsolete, with struct lifreq preferred for interface requests.
1735283// Here we alias lifreq to ifreq to avoid chainging existing code in os and x.os.IPv6.
1736284pub const SIOCGLIFINDEX = IOWR('i', 133, lifreq);
1737pub const SIOCGIFINDEX = SIOCGLIFINDEX;
1738pub const MAX_HDW_LEN = 64;
1739pub const IFNAMESIZE = 32;
1740285
1741286pub const lif_nd_req = extern struct {
1742287 addr: sockaddr.storage,
......@@ -1746,7 +291,7 @@ pub const lif_nd_req = extern struct {
1746291 hdw_len: i32,
1747292 flags: i32,
1748293 __pad: i32,
1749 hdw_addr: [MAX_HDW_LEN]u8,
294 hdw_addr: [64]u8,
1750295};
1751296
1752297pub const lif_ifinfo_req = extern struct {
......@@ -1806,8 +351,6 @@ pub const lifreq = extern struct {
1806351 },
1807352};
1808353
1809pub const ifreq = lifreq;
1810
1811354const IoCtlCommand = enum(u32) {
1812355 none = 0x20000000, // no parameters
1813356 write = 0x40000000, // copy out parameters
lib/std/c/wasi.zig deleted-162
......@@ -1,162 +0,0 @@
1const builtin = @import("builtin");
2const std = @import("../std.zig");
3const wasi = std.os.wasi;
4
5extern threadlocal var errno: c_int;
6
7pub fn _errno() *c_int {
8 return &errno;
9}
10
11pub const PATH_MAX = 4096;
12
13pub const mode_t = u32;
14pub const time_t = i64;
15
16pub const timespec = extern struct {
17 tv_sec: time_t,
18 tv_nsec: isize,
19
20 pub fn fromTimestamp(tm: wasi.timestamp_t) timespec {
21 const tv_sec: wasi.timestamp_t = tm / 1_000_000_000;
22 const tv_nsec = tm - tv_sec * 1_000_000_000;
23 return .{
24 .tv_sec = @as(time_t, @intCast(tv_sec)),
25 .tv_nsec = @as(isize, @intCast(tv_nsec)),
26 };
27 }
28
29 pub fn toTimestamp(ts: timespec) wasi.timestamp_t {
30 return @as(wasi.timestamp_t, @intCast(ts.tv_sec * 1_000_000_000)) +
31 @as(wasi.timestamp_t, @intCast(ts.tv_nsec));
32 }
33};
34
35pub const STDIN_FILENO = 0;
36pub const STDOUT_FILENO = 1;
37pub const STDERR_FILENO = 2;
38
39pub const E = wasi.errno_t;
40
41pub const CLOCK = wasi.clockid_t;
42pub const IOV_MAX = 1024;
43pub const S = struct {
44 pub const IEXEC = @compileError("TODO audit this");
45 pub const IFBLK = 0x6000;
46 pub const IFCHR = 0x2000;
47 pub const IFDIR = 0x4000;
48 pub const IFIFO = 0xc000;
49 pub const IFLNK = 0xa000;
50 pub const IFMT = IFBLK | IFCHR | IFDIR | IFIFO | IFLNK | IFREG | IFSOCK;
51 pub const IFREG = 0x8000;
52 /// There's no concept of UNIX domain socket but we define this value here
53 /// in order to line with other OSes.
54 pub const IFSOCK = 0x1;
55};
56pub const fd_t = wasi.fd_t;
57pub const pid_t = c_int;
58pub const uid_t = u32;
59pub const gid_t = u32;
60pub const off_t = i64;
61pub const ino_t = wasi.inode_t;
62pub const dev_t = wasi.device_t;
63pub const nlink_t = c_ulonglong;
64pub const blksize_t = c_long;
65pub const blkcnt_t = c_longlong;
66
67pub const Stat = extern struct {
68 dev: dev_t,
69 ino: ino_t,
70 nlink: nlink_t,
71 mode: mode_t,
72 uid: uid_t,
73 gid: gid_t,
74 __pad0: c_uint = 0,
75 rdev: dev_t,
76 size: off_t,
77 blksize: blksize_t,
78 blocks: blkcnt_t,
79 atim: timespec,
80 mtim: timespec,
81 ctim: timespec,
82 __reserved: [3]c_longlong = [3]c_longlong{ 0, 0, 0 },
83
84 pub fn atime(self: @This()) timespec {
85 return self.atim;
86 }
87
88 pub fn mtime(self: @This()) timespec {
89 return self.mtim;
90 }
91
92 pub fn ctime(self: @This()) timespec {
93 return self.ctim;
94 }
95
96 pub fn fromFilestat(stat: wasi.filestat_t) Stat {
97 return .{
98 .dev = stat.dev,
99 .ino = stat.ino,
100 .mode = switch (stat.filetype) {
101 .UNKNOWN => 0,
102 .BLOCK_DEVICE => S.IFBLK,
103 .CHARACTER_DEVICE => S.IFCHR,
104 .DIRECTORY => S.IFDIR,
105 .REGULAR_FILE => S.IFREG,
106 .SOCKET_DGRAM => S.IFSOCK,
107 .SOCKET_STREAM => S.IFIFO,
108 .SYMBOLIC_LINK => S.IFLNK,
109 _ => 0,
110 },
111 .nlink = stat.nlink,
112 .size = @intCast(stat.size),
113 .atim = timespec.fromTimestamp(stat.atim),
114 .mtim = timespec.fromTimestamp(stat.mtim),
115 .ctim = timespec.fromTimestamp(stat.ctim),
116
117 .uid = 0,
118 .gid = 0,
119 .rdev = 0,
120 .blksize = 0,
121 .blocks = 0,
122 };
123 }
124};
125
126pub const F = struct {
127 pub const GETFD = 1;
128 pub const SETFD = 2;
129 pub const GETFL = 3;
130 pub const SETFL = 4;
131};
132
133pub const FD_CLOEXEC = 1;
134
135pub const F_OK = 0;
136pub const X_OK = 1;
137pub const W_OK = 2;
138pub const R_OK = 4;
139
140pub const SEEK = struct {
141 pub const SET: wasi.whence_t = .SET;
142 pub const CUR: wasi.whence_t = .CUR;
143 pub const END: wasi.whence_t = .END;
144};
145
146pub const nfds_t = usize;
147
148pub const pollfd = extern struct {
149 fd: fd_t,
150 events: i16,
151 revents: i16,
152};
153
154pub const POLL = struct {
155 pub const RDNORM = 0x1;
156 pub const WRNORM = 0x2;
157 pub const IN = RDNORM;
158 pub const OUT = WRNORM;
159 pub const ERR = 0x1000;
160 pub const HUP = 0x2000;
161 pub const NVAL = 0x4000;
162};
lib/std/c/windows.zig deleted-226
......@@ -1,226 +0,0 @@
1//! The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
2const std = @import("../std.zig");
3const ws2_32 = std.os.windows.ws2_32;
4const windows = std.os.windows;
5
6pub extern "c" fn _errno() *c_int;
7
8pub extern "c" fn _msize(memblock: ?*anyopaque) usize;
9
10// TODO: copied the else case and removed the socket function (because its in ws2_32)
11// need to verify which of these is actually supported on windows
12pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
13pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
14pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
15pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
16pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
17pub extern "c" fn sched_yield() c_int;
18pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
19pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
20pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
21pub extern "c" fn sigfillset(set: ?*sigset_t) void;
22pub extern "c" fn alarm(seconds: c_uint) c_uint;
23pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
24
25pub const fd_t = windows.HANDLE;
26pub const ino_t = windows.LARGE_INTEGER;
27pub const pid_t = windows.HANDLE;
28pub const mode_t = u0;
29
30pub const PATH_MAX = 260;
31
32pub const time_t = c_longlong;
33
34pub const timespec = extern struct {
35 tv_sec: time_t,
36 tv_nsec: c_long,
37};
38
39pub const timeval = extern struct {
40 tv_sec: c_long,
41 tv_usec: c_long,
42};
43
44pub const Stat = @compileError("TODO windows Stat definition");
45
46pub const sig_atomic_t = c_int;
47
48pub const sigset_t = @compileError("TODO windows sigset_t definition");
49pub const Sigaction = @compileError("TODO windows Sigaction definition");
50pub const timezone = @compileError("TODO windows timezone definition");
51pub const rusage = @compileError("TODO windows rusage definition");
52
53/// maximum signal number + 1
54pub const NSIG = 23;
55
56/// Signal types
57pub const SIG = struct {
58 /// interrupt
59 pub const INT = 2;
60 /// illegal instruction - invalid function image
61 pub const ILL = 4;
62 /// floating point exception
63 pub const FPE = 8;
64 /// segment violation
65 pub const SEGV = 11;
66 /// Software termination signal from kill
67 pub const TERM = 15;
68 /// Ctrl-Break sequence
69 pub const BREAK = 21;
70 /// abnormal termination triggered by abort call
71 pub const ABRT = 22;
72 /// SIGABRT compatible with other platforms, same as SIGABRT
73 pub const ABRT_COMPAT = 6;
74
75 // Signal action codes
76 /// default signal action
77 pub const DFL = 0;
78 /// ignore signal
79 pub const IGN = 1;
80 /// return current value
81 pub const GET = 2;
82 /// signal gets error
83 pub const SGE = 3;
84 /// acknowledge
85 pub const ACK = 4;
86 /// Signal error value (returned by signal call on error)
87 pub const ERR = -1;
88};
89
90pub const SEEK = struct {
91 pub const SET = 0;
92 pub const CUR = 1;
93 pub const END = 2;
94};
95
96/// Basic memory protection flags
97pub const PROT = struct {
98 /// page can not be accessed
99 pub const NONE = 0x0;
100 /// page can be read
101 pub const READ = 0x1;
102 /// page can be written
103 pub const WRITE = 0x2;
104 /// page can be executed
105 pub const EXEC = 0x4;
106};
107
108pub const E = enum(u16) {
109 /// No error occurred.
110 SUCCESS = 0,
111 PERM = 1,
112 NOENT = 2,
113 SRCH = 3,
114 INTR = 4,
115 IO = 5,
116 NXIO = 6,
117 @"2BIG" = 7,
118 NOEXEC = 8,
119 BADF = 9,
120 CHILD = 10,
121 AGAIN = 11,
122 NOMEM = 12,
123 ACCES = 13,
124 FAULT = 14,
125 BUSY = 16,
126 EXIST = 17,
127 XDEV = 18,
128 NODEV = 19,
129 NOTDIR = 20,
130 ISDIR = 21,
131 NFILE = 23,
132 MFILE = 24,
133 NOTTY = 25,
134 FBIG = 27,
135 NOSPC = 28,
136 SPIPE = 29,
137 ROFS = 30,
138 MLINK = 31,
139 PIPE = 32,
140 DOM = 33,
141 /// Also means `DEADLOCK`.
142 DEADLK = 36,
143 NAMETOOLONG = 38,
144 NOLCK = 39,
145 NOSYS = 40,
146 NOTEMPTY = 41,
147
148 INVAL = 22,
149 RANGE = 34,
150 ILSEQ = 42,
151
152 // POSIX Supplement
153 ADDRINUSE = 100,
154 ADDRNOTAVAIL = 101,
155 AFNOSUPPORT = 102,
156 ALREADY = 103,
157 BADMSG = 104,
158 CANCELED = 105,
159 CONNABORTED = 106,
160 CONNREFUSED = 107,
161 CONNRESET = 108,
162 DESTADDRREQ = 109,
163 HOSTUNREACH = 110,
164 IDRM = 111,
165 INPROGRESS = 112,
166 ISCONN = 113,
167 LOOP = 114,
168 MSGSIZE = 115,
169 NETDOWN = 116,
170 NETRESET = 117,
171 NETUNREACH = 118,
172 NOBUFS = 119,
173 NODATA = 120,
174 NOLINK = 121,
175 NOMSG = 122,
176 NOPROTOOPT = 123,
177 NOSR = 124,
178 NOSTR = 125,
179 NOTCONN = 126,
180 NOTRECOVERABLE = 127,
181 NOTSOCK = 128,
182 NOTSUP = 129,
183 OPNOTSUPP = 130,
184 OTHER = 131,
185 OVERFLOW = 132,
186 OWNERDEAD = 133,
187 PROTO = 134,
188 PROTONOSUPPORT = 135,
189 PROTOTYPE = 136,
190 TIME = 137,
191 TIMEDOUT = 138,
192 TXTBSY = 139,
193 WOULDBLOCK = 140,
194 DQUOT = 10069,
195 _,
196};
197
198pub const STRUNCATE = 80;
199
200pub const F_OK = 0;
201
202pub const in_port_t = u16;
203pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
204pub const socklen_t = ws2_32.socklen_t;
205
206pub const sockaddr = ws2_32.sockaddr;
207
208pub const in6_addr = [16]u8;
209pub const in_addr = u32;
210
211pub const addrinfo = ws2_32.addrinfo;
212pub const AF = ws2_32.AF;
213pub const MSG = ws2_32.MSG;
214pub const SOCK = ws2_32.SOCK;
215pub const TCP = ws2_32.TCP;
216pub const IPPROTO = ws2_32.IPPROTO;
217pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
218
219pub const nfds_t = c_ulong;
220pub const pollfd = ws2_32.pollfd;
221pub const POLL = ws2_32.POLL;
222pub const SOL = ws2_32.SOL;
223pub const SO = ws2_32.SO;
224pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
225
226pub const IFNAMESIZE = 30;
lib/std/crypto/Certificate/Bundle/macos.zig+1-1
......@@ -42,7 +42,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void {
4242
4343 const table_header = try reader.readStructEndian(TableHeader, .big);
4444
45 if (@as(std.c.cssm.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
45 if (@as(std.c.DB_RECORDTYPE, @enumFromInt(table_header.table_id)) != .X509_CERTIFICATE) {
4646 continue;
4747 }
4848
lib/std/crypto/tlcsprng.zig+6-26
......@@ -11,39 +11,19 @@ const posix = std.posix;
1111
1212/// We use this as a layer of indirection because global const pointers cannot
1313/// point to thread-local variables.
14pub const interface = std.Random{
14pub const interface: std.Random = .{
1515 .ptr = undefined,
1616 .fillFn = tlsCsprngFill,
1717};
1818
19const os_has_fork = switch (native_os) {
20 .dragonfly,
21 .freebsd,
22 .ios,
23 .kfreebsd,
24 .linux,
25 .macos,
26 .netbsd,
27 .openbsd,
28 .solaris,
29 .illumos,
30 .tvos,
31 .watchos,
32 .visionos,
33 .haiku,
34 => true,
35
36 else => false,
37};
38const os_has_arc4random = builtin.link_libc and @hasDecl(std.c, "arc4random_buf");
39const want_fork_safety = os_has_fork and !os_has_arc4random and
40 std.options.crypto_fork_safety;
19const os_has_fork = @TypeOf(posix.fork) != void;
20const os_has_arc4random = builtin.link_libc and (@TypeOf(std.c.arc4random_buf) != void);
21const want_fork_safety = os_has_fork and !os_has_arc4random and std.options.crypto_fork_safety;
4122const maybe_have_wipe_on_fork = builtin.os.isAtLeast(.linux, .{
4223 .major = 4,
4324 .minor = 14,
4425 .patch = 0,
4526}) orelse true;
46const is_haiku = native_os == .haiku;
4727
4828const Rng = std.Random.DefaultCsprng;
4929
......@@ -65,7 +45,7 @@ var install_atfork_handler = std.once(struct {
6545threadlocal var wipe_mem: []align(mem.page_size) u8 = &[_]u8{};
6646
6747fn tlsCsprngFill(_: *anyopaque, buffer: []u8) void {
68 if (builtin.link_libc and @hasDecl(std.c, "arc4random_buf")) {
48 if (os_has_arc4random) {
6949 // arc4random is already a thread-local CSPRNG.
7050 return std.c.arc4random_buf(buffer.ptr, buffer.len);
7151 }
......@@ -78,7 +58,7 @@ fn tlsCsprngFill(_: *anyopaque, buffer: []u8) void {
7858
7959 if (wipe_mem.len == 0) {
8060 // Not initialized yet.
81 if (want_fork_safety and maybe_have_wipe_on_fork or is_haiku) {
61 if (want_fork_safety and maybe_have_wipe_on_fork) {
8262 // Allocate a per-process page, madvise operates with page
8363 // granularity.
8464 wipe_mem = posix.mmap(
lib/std/debug.zig+22-28
......@@ -201,11 +201,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
201201 }
202202}
203203
204pub const have_ucontext = @hasDecl(posix.system, "ucontext_t") and
205 (native_os != .linux or switch (builtin.cpu.arch) {
206 .mips, .mipsel, .mips64, .mips64el, .riscv64 => false,
207 else => true,
208});
204pub const have_ucontext = posix.ucontext_t != void;
209205
210206/// Platform-specific thread state. This contains register state, and on some platforms
211207/// information about the stack. This is not safe to trivially copy, because some platforms
......@@ -237,14 +233,7 @@ pub fn relocateContext(context: *ThreadContext) void {
237233 };
238234}
239235
240pub const have_getcontext = native_os != .openbsd and native_os != .haiku and
241 !builtin.target.isAndroid() and
242 (native_os != .linux or switch (builtin.cpu.arch) {
243 .x86,
244 .x86_64,
245 => true,
246 else => builtin.link_libc and !builtin.target.isMusl(),
247});
236pub const have_getcontext = @TypeOf(posix.system.getcontext) != void;
248237
249238/// Capture the current context. The register values in the context will reflect the
250239/// state after the platform `getcontext` function returns.
......@@ -704,7 +693,7 @@ pub const StackIterator = struct {
704693 }
705694
706695 return true;
707 } else if (@hasDecl(posix.system, "msync") and native_os != .wasi and native_os != .emscripten) {
696 } else if (have_msync) {
708697 posix.msync(aligned_memory, posix.MSF.ASYNC) catch |err| {
709698 switch (err) {
710699 error.UnmappedMemory => return false,
......@@ -853,6 +842,11 @@ pub const StackIterator = struct {
853842 }
854843};
855844
845const have_msync = switch (native_os) {
846 .wasi, .emscripten, .windows => false,
847 else => true,
848};
849
856850pub fn writeCurrentStackTrace(
857851 out_stream: anytype,
858852 debug_info: *DebugInfo,
......@@ -2078,15 +2072,15 @@ pub const DebugInfo = struct {
20782072 if (posix.dl_iterate_phdr(&ctx, error{Found}, struct {
20792073 fn callback(info: *posix.dl_phdr_info, size: usize, context: *CtxTy) !void {
20802074 _ = size;
2081 if (context.address < info.dlpi_addr) return;
2082 const phdrs = info.dlpi_phdr[0..info.dlpi_phnum];
2075 if (context.address < info.addr) return;
2076 const phdrs = info.phdr[0..info.phnum];
20832077 for (phdrs) |*phdr| {
20842078 if (phdr.p_type != elf.PT_LOAD) continue;
20852079
2086 const seg_start = info.dlpi_addr +% phdr.p_vaddr;
2080 const seg_start = info.addr +% phdr.p_vaddr;
20872081 const seg_end = seg_start + phdr.p_memsz;
20882082 if (context.address >= seg_start and context.address < seg_end) {
2089 context.name = mem.sliceTo(info.dlpi_name, 0) orelse "";
2083 context.name = mem.sliceTo(info.name, 0) orelse "";
20902084 break;
20912085 }
20922086 } else return;
......@@ -2118,30 +2112,30 @@ pub const DebugInfo = struct {
21182112 fn callback(info: *posix.dl_phdr_info, size: usize, context: *CtxTy) !void {
21192113 _ = size;
21202114 // The base address is too high
2121 if (context.address < info.dlpi_addr)
2115 if (context.address < info.addr)
21222116 return;
21232117
2124 const phdrs = info.dlpi_phdr[0..info.dlpi_phnum];
2118 const phdrs = info.phdr[0..info.phnum];
21252119 for (phdrs) |*phdr| {
21262120 if (phdr.p_type != elf.PT_LOAD) continue;
21272121
21282122 // Overflowing addition is used to handle the case of VSDOs having a p_vaddr = 0xffffffffff700000
2129 const seg_start = info.dlpi_addr +% phdr.p_vaddr;
2123 const seg_start = info.addr +% phdr.p_vaddr;
21302124 const seg_end = seg_start + phdr.p_memsz;
21312125 if (context.address >= seg_start and context.address < seg_end) {
21322126 // Android libc uses NULL instead of an empty string to mark the
21332127 // main program
2134 context.name = mem.sliceTo(info.dlpi_name, 0) orelse "";
2135 context.base_address = info.dlpi_addr;
2128 context.name = mem.sliceTo(info.name, 0) orelse "";
2129 context.base_address = info.addr;
21362130 break;
21372131 }
21382132 } else return;
21392133
2140 for (info.dlpi_phdr[0..info.dlpi_phnum]) |phdr| {
2134 for (info.phdr[0..info.phnum]) |phdr| {
21412135 switch (phdr.p_type) {
21422136 elf.PT_NOTE => {
21432137 // Look for .note.gnu.build-id
2144 const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
2138 const note_bytes = @as([*]const u8, @ptrFromInt(info.addr + phdr.p_vaddr))[0..phdr.p_memsz];
21452139 const name_size = mem.readInt(u32, note_bytes[0..4], native_endian);
21462140 if (name_size != 4) continue;
21472141 const desc_size = mem.readInt(u32, note_bytes[4..8], native_endian);
......@@ -2151,7 +2145,7 @@ pub const DebugInfo = struct {
21512145 context.build_id = note_bytes[16..][0..desc_size];
21522146 },
21532147 elf.PT_GNU_EH_FRAME => {
2154 context.gnu_eh_frame = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
2148 context.gnu_eh_frame = @as([*]const u8, @ptrFromInt(info.addr + phdr.p_vaddr))[0..phdr.p_memsz];
21552149 },
21562150 else => {},
21572151 }
......@@ -2592,7 +2586,7 @@ pub const have_segfault_handling_support = switch (native_os) {
25922586 .windows,
25932587 => true,
25942588
2595 .freebsd, .openbsd => @hasDecl(std.c, "ucontext_t"),
2589 .freebsd, .openbsd => have_ucontext,
25962590 else => false,
25972591};
25982592
......@@ -2742,7 +2736,7 @@ fn handleSegfaultWindowsExtra(
27422736 label: ?[]const u8,
27432737) noreturn {
27442738 const exception_address = @intFromPtr(info.ExceptionRecord.ExceptionAddress);
2745 if (@hasDecl(windows, "CONTEXT")) {
2739 if (windows.CONTEXT != void) {
27462740 nosuspend switch (panic_stage) {
27472741 0 => {
27482742 panic_stage = 1;
lib/std/dynamic_library.zig+1-1
......@@ -440,7 +440,7 @@ pub const DlDynLib = struct {
440440
441441 pub fn openZ(path_c: [*:0]const u8) Error!DlDynLib {
442442 return .{
443 .handle = std.c.dlopen(path_c, std.c.RTLD.LAZY) orelse {
443 .handle = std.c.dlopen(path_c, .{ .LAZY = true }) orelse {
444444 return error.FileNotFound;
445445 },
446446 };
lib/std/elf.zig+1-5
......@@ -1082,11 +1082,7 @@ pub const Addr = switch (@sizeOf(usize)) {
10821082 8 => Elf64_Addr,
10831083 else => @compileError("expected pointer size of 32 or 64"),
10841084};
1085pub const Half = switch (@sizeOf(usize)) {
1086 4 => Elf32_Half,
1087 8 => Elf64_Half,
1088 else => @compileError("expected pointer size of 32 or 64"),
1089};
1085pub const Half = u16;
10901086
10911087/// Machine architectures.
10921088///
lib/std/fs/Dir.zig+12-13
......@@ -178,7 +178,8 @@ pub const Iterator = switch (native_os) {
178178 self.end_index = @as(usize, @intCast(rc));
179179 }
180180 const bsd_entry = @as(*align(1) posix.system.dirent, @ptrCast(&self.buf[self.index]));
181 const next_index = self.index + if (@hasDecl(posix.system.dirent, "reclen")) bsd_entry.reclen() else bsd_entry.reclen;
181 const next_index = self.index +
182 if (@hasField(posix.system.dirent, "reclen")) bsd_entry.reclen else bsd_entry.reclen();
182183 self.index = next_index;
183184
184185 const name = @as([*]u8, @ptrCast(&bsd_entry.name))[0..bsd_entry.namlen];
......@@ -880,16 +881,14 @@ pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File
880881 const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0);
881882 errdefer posix.close(fd);
882883
883 if (@hasDecl(posix.system, "LOCK")) {
884 if (!has_flock_open_flags and flags.lock != .none) {
885 // TODO: integrate async I/O
886 const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;
887 try posix.flock(fd, switch (flags.lock) {
888 .none => unreachable,
889 .shared => posix.LOCK.SH | lock_nonblocking,
890 .exclusive => posix.LOCK.EX | lock_nonblocking,
891 });
892 }
884 if (!has_flock_open_flags and flags.lock != .none) {
885 // TODO: integrate async I/O
886 const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;
887 try posix.flock(fd, switch (flags.lock) {
888 .none => unreachable,
889 .shared => posix.LOCK.SH | lock_nonblocking,
890 .exclusive => posix.LOCK.EX | lock_nonblocking,
891 });
893892 }
894893
895894 if (has_flock_open_flags and flags.lock_nonblocking) {
......@@ -2539,8 +2538,8 @@ const CopyFileRawError = error{SystemResources} || posix.CopyFileRangeError || p
25392538// The copy starts at offset 0, the initial offsets are preserved.
25402539// No metadata is transferred over.
25412540fn copy_file(fd_in: posix.fd_t, fd_out: posix.fd_t, maybe_size: ?u64) CopyFileRawError!void {
2542 if (comptime builtin.target.isDarwin()) {
2543 const rc = posix.system.fcopyfile(fd_in, fd_out, null, posix.system.COPYFILE_DATA);
2541 if (builtin.target.isDarwin()) {
2542 const rc = posix.system.fcopyfile(fd_in, fd_out, null, .{ .DATA = true });
25442543 switch (posix.errno(rc)) {
25452544 .SUCCESS => return,
25462545 .INVAL => unreachable,
lib/std/fs/File.zig+21-21
......@@ -420,9 +420,9 @@ pub const Stat = struct {
420420
421421 break :k .unknown;
422422 },
423 .atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
424 .mtime = @as(i128, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
425 .ctime = @as(i128, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
423 .atime = @as(i128, atime.sec) * std.time.ns_per_s + atime.nsec,
424 .mtime = @as(i128, mtime.sec) * std.time.ns_per_s + mtime.nsec,
425 .ctime = @as(i128, ctime.sec) * std.time.ns_per_s + ctime.nsec,
426426 };
427427 }
428428
......@@ -791,13 +791,13 @@ pub const MetadataUnix = struct {
791791 /// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01
792792 pub fn accessed(self: Self) i128 {
793793 const atime = self.stat.atime();
794 return @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec;
794 return @as(i128, atime.sec) * std.time.ns_per_s + atime.nsec;
795795 }
796796
797797 /// Returns the last time the file was modified in nanoseconds since UTC 1970-01-01
798798 pub fn modified(self: Self) i128 {
799799 const mtime = self.stat.mtime();
800 return @as(i128, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec;
800 return @as(i128, mtime.sec) * std.time.ns_per_s + mtime.nsec;
801801 }
802802
803803 /// Returns the time the file was created in nanoseconds since UTC 1970-01-01.
......@@ -807,17 +807,17 @@ pub const MetadataUnix = struct {
807807 const birthtime = self.stat.birthtime();
808808
809809 // If the filesystem doesn't support this the value *should* be:
810 // On FreeBSD: tv_nsec = 0, tv_sec = -1
811 // On NetBSD and OpenBSD: tv_nsec = 0, tv_sec = 0
810 // On FreeBSD: nsec = 0, sec = -1
811 // On NetBSD and OpenBSD: nsec = 0, sec = 0
812812 // On MacOS, it is set to ctime -- we cannot detect this!!
813813 switch (builtin.os.tag) {
814 .freebsd => if (birthtime.tv_sec == -1 and birthtime.tv_nsec == 0) return null,
815 .netbsd, .openbsd => if (birthtime.tv_sec == 0 and birthtime.tv_nsec == 0) return null,
814 .freebsd => if (birthtime.sec == -1 and birthtime.nsec == 0) return null,
815 .netbsd, .openbsd => if (birthtime.sec == 0 and birthtime.nsec == 0) return null,
816816 .macos => {},
817817 else => @compileError("Creation time detection not implemented for OS"),
818818 }
819819
820 return @as(i128, birthtime.tv_sec) * std.time.ns_per_s + birthtime.tv_nsec;
820 return @as(i128, birthtime.sec) * std.time.ns_per_s + birthtime.nsec;
821821 }
822822};
823823
......@@ -858,19 +858,19 @@ pub const MetadataLinux = struct {
858858
859859 /// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01
860860 pub fn accessed(self: Self) i128 {
861 return @as(i128, self.statx.atime.tv_sec) * std.time.ns_per_s + self.statx.atime.tv_nsec;
861 return @as(i128, self.statx.atime.sec) * std.time.ns_per_s + self.statx.atime.nsec;
862862 }
863863
864864 /// Returns the last time the file was modified in nanoseconds since UTC 1970-01-01
865865 pub fn modified(self: Self) i128 {
866 return @as(i128, self.statx.mtime.tv_sec) * std.time.ns_per_s + self.statx.mtime.tv_nsec;
866 return @as(i128, self.statx.mtime.sec) * std.time.ns_per_s + self.statx.mtime.nsec;
867867 }
868868
869869 /// Returns the time the file was created in nanoseconds since UTC 1970-01-01.
870870 /// Returns null if this is not supported by the filesystem, or on kernels before than version 4.11
871871 pub fn created(self: Self) ?i128 {
872872 if (self.statx.mask & std.os.linux.STATX_BTIME == 0) return null;
873 return @as(i128, self.statx.btime.tv_sec) * std.time.ns_per_s + self.statx.btime.tv_nsec;
873 return @as(i128, self.statx.btime.sec) * std.time.ns_per_s + self.statx.btime.nsec;
874874 }
875875};
876876
......@@ -1026,12 +1026,12 @@ pub fn metadata(self: File) MetadataError!Metadata {
10261026
10271027 // Hacky conversion from timespec to statx_timestamp
10281028 stx.atime = std.mem.zeroes(l.statx_timestamp);
1029 stx.atime.tv_sec = st.atim.tv_sec;
1030 stx.atime.tv_nsec = @as(u32, @intCast(st.atim.tv_nsec)); // Guaranteed to succeed (tv_nsec is always below 10^9)
1029 stx.atime.sec = st.atim.sec;
1030 stx.atime.nsec = @as(u32, @intCast(st.atim.nsec)); // Guaranteed to succeed (nsec is always below 10^9)
10311031
10321032 stx.mtime = std.mem.zeroes(l.statx_timestamp);
1033 stx.mtime.tv_sec = st.mtim.tv_sec;
1034 stx.mtime.tv_nsec = @as(u32, @intCast(st.mtim.tv_nsec));
1033 stx.mtime.sec = st.mtim.sec;
1034 stx.mtime.nsec = @as(u32, @intCast(st.mtim.nsec));
10351035
10361036 stx.mask = l.STATX_BASIC_STATS | l.STATX_MTIME;
10371037 },
......@@ -1072,12 +1072,12 @@ pub fn updateTimes(
10721072 }
10731073 const times = [2]posix.timespec{
10741074 posix.timespec{
1075 .tv_sec = math.cast(isize, @divFloor(atime, std.time.ns_per_s)) orelse maxInt(isize),
1076 .tv_nsec = math.cast(isize, @mod(atime, std.time.ns_per_s)) orelse maxInt(isize),
1075 .sec = math.cast(isize, @divFloor(atime, std.time.ns_per_s)) orelse maxInt(isize),
1076 .nsec = math.cast(isize, @mod(atime, std.time.ns_per_s)) orelse maxInt(isize),
10771077 },
10781078 posix.timespec{
1079 .tv_sec = math.cast(isize, @divFloor(mtime, std.time.ns_per_s)) orelse maxInt(isize),
1080 .tv_nsec = math.cast(isize, @mod(mtime, std.time.ns_per_s)) orelse maxInt(isize),
1079 .sec = math.cast(isize, @divFloor(mtime, std.time.ns_per_s)) orelse maxInt(isize),
1080 .nsec = math.cast(isize, @mod(mtime, std.time.ns_per_s)) orelse maxInt(isize),
10811081 },
10821082 };
10831083 try posix.futimens(self.handle, &times);
lib/std/heap.zig+7-4
......@@ -40,15 +40,18 @@ const CAllocator = struct {
4040 }
4141
4242 pub const supports_malloc_size = @TypeOf(malloc_size) != void;
43 pub const malloc_size = if (@hasDecl(c, "malloc_size"))
43 pub const malloc_size = if (@TypeOf(c.malloc_size) != void)
4444 c.malloc_size
45 else if (@hasDecl(c, "malloc_usable_size"))
45 else if (@TypeOf(c.malloc_usable_size) != void)
4646 c.malloc_usable_size
47 else if (@hasDecl(c, "_msize"))
47 else if (@TypeOf(c._msize) != void)
4848 c._msize
4949 else {};
5050
51 pub const supports_posix_memalign = @hasDecl(c, "posix_memalign");
51 pub const supports_posix_memalign = switch (builtin.os.tag) {
52 .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos => true,
53 else => false,
54 };
5255
5356 fn getHeader(ptr: [*]u8) *[*]u8 {
5457 return @as(*[*]u8, @ptrFromInt(@intFromPtr(ptr) - @sizeOf(usize)));
lib/std/net.zig+12-14
......@@ -248,14 +248,13 @@ pub const Address = extern union {
248248 posix.SO.REUSEADDR,
249249 &mem.toBytes(@as(c_int, 1)),
250250 );
251 switch (native_os) {
252 .windows => {},
253 else => try posix.setsockopt(
251 if (@hasDecl(posix.SO, "REUSEPORT")) {
252 try posix.setsockopt(
254253 sockfd,
255254 posix.SOL.SOCKET,
256255 posix.SO.REUSEPORT,
257256 &mem.toBytes(@as(c_int, 1)),
258 ),
257 );
259258 }
260259 }
261260
......@@ -853,8 +852,8 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
853852 defer allocator.free(port_c);
854853
855854 const ws2_32 = windows.ws2_32;
856 const hints = posix.addrinfo{
857 .flags = ws2_32.AI.NUMERICSERV,
855 const hints: posix.addrinfo = .{
856 .flags = .{ .NUMERICSERV = true },
858857 .family = posix.AF.UNSPEC,
859858 .socktype = posix.SOCK.STREAM,
860859 .protocol = posix.IPPROTO.TCP,
......@@ -925,8 +924,8 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
925924 defer allocator.free(port_c);
926925
927926 const sys = if (native_os == .windows) windows.ws2_32 else posix.system;
928 const hints = posix.addrinfo{
929 .flags = sys.AI.NUMERICSERV,
927 const hints: posix.addrinfo = .{
928 .flags = .{ .NUMERICSERV = true },
930929 .family = posix.AF.UNSPEC,
931930 .socktype = posix.SOCK.STREAM,
932931 .protocol = posix.IPPROTO.TCP,
......@@ -985,7 +984,6 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
985984 }
986985
987986 if (native_os == .linux) {
988 const flags = std.c.AI.NUMERICSERV;
989987 const family = posix.AF.UNSPEC;
990988 var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);
991989 defer lookup_addrs.deinit();
......@@ -993,7 +991,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) Get
993991 var canon = std.ArrayList(u8).init(arena);
994992 defer canon.deinit();
995993
996 try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port);
994 try linuxLookupName(&lookup_addrs, &canon, name, family, .{ .NUMERICSERV = true }, port);
997995
998996 result.addrs = try arena.alloc(Address, lookup_addrs.items.len);
999997 if (canon.items.len != 0) {
......@@ -1028,7 +1026,7 @@ fn linuxLookupName(
10281026 canon: *std.ArrayList(u8),
10291027 opt_name: ?[]const u8,
10301028 family: posix.sa_family_t,
1031 flags: u32,
1029 flags: posix.AI,
10321030 port: u16,
10331031) !void {
10341032 if (opt_name) |name| {
......@@ -1037,7 +1035,7 @@ fn linuxLookupName(
10371035 try canon.appendSlice(name);
10381036 if (Address.parseExpectingFamily(name, family, port)) |addr| {
10391037 try addrs.append(LookupAddr{ .addr = addr });
1040 } else |name_err| if ((flags & std.c.AI.NUMERICHOST) != 0) {
1038 } else |name_err| if (flags.NUMERICHOST) {
10411039 return name_err;
10421040 } else {
10431041 try linuxLookupNameFromHosts(addrs, canon, name, family, port);
......@@ -1269,10 +1267,10 @@ fn addrCmpLessThan(context: void, b: LookupAddr, a: LookupAddr) bool {
12691267fn linuxLookupNameFromNull(
12701268 addrs: *std.ArrayList(LookupAddr),
12711269 family: posix.sa_family_t,
1272 flags: u32,
1270 flags: posix.AI,
12731271 port: u16,
12741272) !void {
1275 if ((flags & std.c.AI.PASSIVE) != 0) {
1273 if (flags.PASSIVE) {
12761274 if (family != posix.AF.INET6) {
12771275 (try addrs.addOne()).* = LookupAddr{
12781276 .addr = Address.initIp4([1]u8{0} ** 4, port),
lib/std/os.zig+5-3
......@@ -23,6 +23,7 @@ const fs = std.fs;
2323const dl = @import("dynamic_library.zig");
2424const max_path_bytes = std.fs.max_path_bytes;
2525const posix = std.posix;
26const native_os = builtin.os.tag;
2627
2728pub const linux = @import("os/linux.zig");
2829pub const plan9 = @import("os/plan9.zig");
......@@ -33,7 +34,7 @@ pub const windows = @import("os/windows.zig");
3334
3435test {
3536 _ = linux;
36 if (builtin.os.tag == .uefi) {
37 if (native_os == .uefi) {
3738 _ = uefi;
3839 }
3940 _ = wasi;
......@@ -48,7 +49,7 @@ pub var environ: [][*:0]u8 = undefined;
4849/// Populated by startup code before main().
4950/// Not available on WASI or Windows without libc. See `std.process.argsAlloc`
5051/// or `std.process.argsWithAllocator` for a cross-platform alternative.
51pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (builtin.os.tag) {
52pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (native_os) {
5253 .windows => @compileError("argv isn't supported on Windows: use std.process.argsAlloc instead"),
5354 .wasi => @compileError("argv isn't supported on WASI: use std.process.argsAlloc instead"),
5455 else => undefined,
......@@ -103,7 +104,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
103104 if (!comptime isGetFdPathSupportedOnTarget(builtin.os)) {
104105 @compileError("querying for canonical path of a handle is unsupported on this host");
105106 }
106 switch (builtin.os.tag) {
107 switch (native_os) {
107108 .windows => {
108109 var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;
109110 const wide_slice = try windows.GetFinalPathNameByHandle(fd, .{}, wide_buf[0..]);
......@@ -150,6 +151,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
150151 const target = posix.readlinkZ(proc_path, out_buffer) catch |err| switch (err) {
151152 error.UnsupportedReparsePointType => unreachable,
152153 error.NotLink => unreachable,
154 error.InvalidUtf8 => unreachable, // WASI-only
153155 else => |e| return e,
154156 };
155157 return target;
lib/std/os/emscripten.zig+28-292
......@@ -1,10 +1,14 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const wasi = std.os.wasi;
4const linux = std.os.linux;
45const iovec = std.posix.iovec;
56const iovec_const = std.posix.iovec_const;
67const c = std.c;
78
9// TODO: go through this file and delete all the bits that are identical to linux because they can
10// be merged in the std.c namespace.
11
812pub const FILE = c.FILE;
913
1014var __stack_chk_guard: usize = 0;
......@@ -23,124 +27,9 @@ comptime {
2327 }
2428}
2529
26pub const PF = struct {
27 pub const UNSPEC = 0;
28 pub const LOCAL = 1;
29 pub const UNIX = LOCAL;
30 pub const FILE = LOCAL;
31 pub const INET = 2;
32 pub const AX25 = 3;
33 pub const IPX = 4;
34 pub const APPLETALK = 5;
35 pub const NETROM = 6;
36 pub const BRIDGE = 7;
37 pub const ATMPVC = 8;
38 pub const X25 = 9;
39 pub const INET6 = 10;
40 pub const ROSE = 11;
41 pub const DECnet = 12;
42 pub const NETBEUI = 13;
43 pub const SECURITY = 14;
44 pub const KEY = 15;
45 pub const NETLINK = 16;
46 pub const ROUTE = PF.NETLINK;
47 pub const PACKET = 17;
48 pub const ASH = 18;
49 pub const ECONET = 19;
50 pub const ATMSVC = 20;
51 pub const RDS = 21;
52 pub const SNA = 22;
53 pub const IRDA = 23;
54 pub const PPPOX = 24;
55 pub const WANPIPE = 25;
56 pub const LLC = 26;
57 pub const IB = 27;
58 pub const MPLS = 28;
59 pub const CAN = 29;
60 pub const TIPC = 30;
61 pub const BLUETOOTH = 31;
62 pub const IUCV = 32;
63 pub const RXRPC = 33;
64 pub const ISDN = 34;
65 pub const PHONET = 35;
66 pub const IEEE802154 = 36;
67 pub const CAIF = 37;
68 pub const ALG = 38;
69 pub const NFC = 39;
70 pub const VSOCK = 40;
71 pub const KCM = 41;
72 pub const QIPCRTR = 42;
73 pub const SMC = 43;
74 pub const XDP = 44;
75 pub const MAX = 45;
76};
77
78pub const AF = struct {
79 pub const UNSPEC = PF.UNSPEC;
80 pub const LOCAL = PF.LOCAL;
81 pub const UNIX = AF.LOCAL;
82 pub const FILE = AF.LOCAL;
83 pub const INET = PF.INET;
84 pub const AX25 = PF.AX25;
85 pub const IPX = PF.IPX;
86 pub const APPLETALK = PF.APPLETALK;
87 pub const NETROM = PF.NETROM;
88 pub const BRIDGE = PF.BRIDGE;
89 pub const ATMPVC = PF.ATMPVC;
90 pub const X25 = PF.X25;
91 pub const INET6 = PF.INET6;
92 pub const ROSE = PF.ROSE;
93 pub const DECnet = PF.DECnet;
94 pub const NETBEUI = PF.NETBEUI;
95 pub const SECURITY = PF.SECURITY;
96 pub const KEY = PF.KEY;
97 pub const NETLINK = PF.NETLINK;
98 pub const ROUTE = PF.ROUTE;
99 pub const PACKET = PF.PACKET;
100 pub const ASH = PF.ASH;
101 pub const ECONET = PF.ECONET;
102 pub const ATMSVC = PF.ATMSVC;
103 pub const RDS = PF.RDS;
104 pub const SNA = PF.SNA;
105 pub const IRDA = PF.IRDA;
106 pub const PPPOX = PF.PPPOX;
107 pub const WANPIPE = PF.WANPIPE;
108 pub const LLC = PF.LLC;
109 pub const IB = PF.IB;
110 pub const MPLS = PF.MPLS;
111 pub const CAN = PF.CAN;
112 pub const TIPC = PF.TIPC;
113 pub const BLUETOOTH = PF.BLUETOOTH;
114 pub const IUCV = PF.IUCV;
115 pub const RXRPC = PF.RXRPC;
116 pub const ISDN = PF.ISDN;
117 pub const PHONET = PF.PHONET;
118 pub const IEEE802154 = PF.IEEE802154;
119 pub const CAIF = PF.CAIF;
120 pub const ALG = PF.ALG;
121 pub const NFC = PF.NFC;
122 pub const VSOCK = PF.VSOCK;
123 pub const KCM = PF.KCM;
124 pub const QIPCRTR = PF.QIPCRTR;
125 pub const SMC = PF.SMC;
126 pub const XDP = PF.XDP;
127 pub const MAX = PF.MAX;
128};
129
130pub const CLOCK = struct {
131 pub const REALTIME = 0;
132 pub const MONOTONIC = 1;
133 pub const PROCESS_CPUTIME_ID = 2;
134 pub const THREAD_CPUTIME_ID = 3;
135 pub const MONOTONIC_RAW = 4;
136 pub const REALTIME_COARSE = 5;
137 pub const MONOTONIC_COARSE = 6;
138 pub const BOOTTIME = 7;
139 pub const REALTIME_ALARM = 8;
140 pub const BOOTTIME_ALARM = 9;
141 pub const SGI_CYCLE = 10;
142 pub const TAI = 11;
143};
30pub const PF = linux.PF;
31pub const AF = linux.AF;
32pub const CLOCK = linux.CLOCK;
14433
14534pub const CPU_SETSIZE = 128;
14635pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
......@@ -368,41 +257,7 @@ pub const IOV_MAX = 1024;
368257
369258pub const IPPORT_RESERVED = 1024;
370259
371pub const IPPROTO = struct {
372 pub const IP = 0;
373 pub const HOPOPTS = 0;
374 pub const ICMP = 1;
375 pub const IGMP = 2;
376 pub const IPIP = 4;
377 pub const TCP = 6;
378 pub const EGP = 8;
379 pub const PUP = 12;
380 pub const UDP = 17;
381 pub const IDP = 22;
382 pub const TP = 29;
383 pub const DCCP = 33;
384 pub const IPV6 = 41;
385 pub const ROUTING = 43;
386 pub const FRAGMENT = 44;
387 pub const RSVP = 46;
388 pub const GRE = 47;
389 pub const ESP = 50;
390 pub const AH = 51;
391 pub const ICMPV6 = 58;
392 pub const NONE = 59;
393 pub const DSTOPTS = 60;
394 pub const MTP = 92;
395 pub const BEETPH = 94;
396 pub const ENCAP = 98;
397 pub const PIM = 103;
398 pub const COMP = 108;
399 pub const SCTP = 132;
400 pub const MH = 135;
401 pub const UDPLITE = 136;
402 pub const MPLS = 137;
403 pub const RAW = 255;
404 pub const MAX = 256;
405};
260pub const IPPROTO = linux.IPPROTO;
406261
407262pub const LOCK = struct {
408263 pub const SH = 1;
......@@ -494,10 +349,7 @@ pub const RLIM = struct {
494349 pub const SAVED_CUR = INFINITY;
495350};
496351
497pub const rlimit = extern struct {
498 cur: rlim_t,
499 max: rlim_t,
500};
352pub const rlimit = c.rlimit;
501353
502354pub const rlimit_resource = enum(c_int) {
503355 CPU,
......@@ -544,8 +396,8 @@ pub const rusage = extern struct {
544396};
545397
546398pub const timeval = extern struct {
547 tv_sec: i64,
548 tv_usec: i32,
399 sec: i64,
400 usec: i32,
549401};
550402
551403pub const REG = struct {
......@@ -929,112 +781,13 @@ pub const TCP = struct {
929781 pub const REPAIR_OFF_NO_WP = -1;
930782};
931783
932pub const TCSA = enum(c_uint) {
933 NOW,
934 DRAIN,
935 FLUSH,
936 _,
937};
938
939pub const addrinfo = extern struct {
940 flags: i32,
941 family: i32,
942 socktype: i32,
943 protocol: i32,
944 addrlen: socklen_t,
945 addr: ?*sockaddr,
946 canonname: ?[*:0]u8,
947 next: ?*addrinfo,
948};
949
950pub const in_port_t = u16;
951pub const sa_family_t = u16;
952pub const socklen_t = u32;
784pub const TCSA = std.posix.TCSA;
785pub const addrinfo = c.addrinfo;
953786
954pub const sockaddr = extern struct {
955 family: sa_family_t,
956 data: [14]u8,
957
958 pub const SS_MAXSIZE = 128;
959 pub const storage = extern struct {
960 family: sa_family_t align(8),
961 padding: [SS_MAXSIZE - @sizeOf(sa_family_t)]u8 = undefined,
962
963 comptime {
964 std.debug.assert(@sizeOf(storage) == SS_MAXSIZE);
965 std.debug.assert(@alignOf(storage) == 8);
966 }
967 };
968
969 /// IPv4 socket address
970 pub const in = extern struct {
971 family: sa_family_t = AF.INET,
972 port: in_port_t,
973 addr: u32,
974 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
975 };
976
977 /// IPv6 socket address
978 pub const in6 = extern struct {
979 family: sa_family_t = AF.INET6,
980 port: in_port_t,
981 flowinfo: u32,
982 addr: [16]u8,
983 scope_id: u32,
984 };
985
986 /// UNIX domain socket address
987 pub const un = extern struct {
988 family: sa_family_t = AF.UNIX,
989 path: [108]u8,
990 };
991
992 /// Packet socket address
993 pub const ll = extern struct {
994 family: sa_family_t = AF.PACKET,
995 protocol: u16,
996 ifindex: i32,
997 hatype: u16,
998 pkttype: u8,
999 halen: u8,
1000 addr: [8]u8,
1001 };
1002
1003 /// Netlink socket address
1004 pub const nl = extern struct {
1005 family: sa_family_t = AF.NETLINK,
1006 __pad1: c_ushort = 0,
1007
1008 /// port ID
1009 pid: u32,
1010
1011 /// multicast groups mask
1012 groups: u32,
1013 };
1014
1015 pub const xdp = extern struct {
1016 family: u16 = AF.XDP,
1017 flags: u16,
1018 ifindex: u32,
1019 queue_id: u32,
1020 shared_umem_fd: u32,
1021 };
1022
1023 /// Address structure for vSockets
1024 pub const vm = extern struct {
1025 family: sa_family_t = AF.VSOCK,
1026 reserved1: u16 = 0,
1027 port: u32,
1028 cid: u32,
1029 flags: u8,
1030
1031 /// The total size of this structure should be exactly the same as that of struct sockaddr.
1032 zero: [3]u8 = [_]u8{0} ** 3,
1033 comptime {
1034 std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr));
1035 }
1036 };
1037};
787pub const in_port_t = c.in_port_t;
788pub const sa_family_t = c.sa_family_t;
789pub const socklen_t = c.socklen_t;
790pub const sockaddr = c.sockaddr;
1038791
1039792pub const blksize_t = i32;
1040793pub const nlink_t = u32;
......@@ -1046,16 +799,16 @@ pub const dev_t = u32;
1046799pub const blkcnt_t = i32;
1047800
1048801pub const pid_t = i32;
1049pub const fd_t = i32;
802pub const fd_t = c.fd_t;
1050803pub const uid_t = u32;
1051804pub const gid_t = u32;
1052805pub const clock_t = i32;
1053806
1054807pub const dl_phdr_info = extern struct {
1055 dlpi_addr: usize,
1056 dlpi_name: ?[*:0]const u8,
1057 dlpi_phdr: [*]std.elf.Phdr,
1058 dlpi_phnum: u16,
808 addr: usize,
809 name: ?[*:0]const u8,
810 phdr: [*]std.elf.Phdr,
811 phnum: u16,
1059812};
1060813
1061814pub const mcontext_t = extern struct {
......@@ -1065,25 +818,8 @@ pub const mcontext_t = extern struct {
1065818 cr2: usize,
1066819};
1067820
1068pub const msghdr = extern struct {
1069 name: ?*sockaddr,
1070 namelen: socklen_t,
1071 iov: [*]iovec,
1072 iovlen: i32,
1073 control: ?*anyopaque,
1074 controllen: socklen_t,
1075 flags: i32,
1076};
1077
1078pub const msghdr_const = extern struct {
1079 name: ?*const sockaddr,
1080 namelen: socklen_t,
1081 iov: [*]const iovec_const,
1082 iovlen: i32,
1083 control: ?*const anyopaque,
1084 controllen: socklen_t,
1085 flags: i32,
1086};
821pub const msghdr = std.c.msghdr;
822pub const msghdr_const = std.c.msghdr;
1087823
1088824pub const nfds_t = usize;
1089825pub const pollfd = extern struct {
......@@ -1099,13 +835,13 @@ pub const stack_t = extern struct {
1099835};
1100836
1101837pub const timespec = extern struct {
1102 tv_sec: time_t,
1103 tv_nsec: isize,
838 sec: time_t,
839 nsec: isize,
1104840};
1105841
1106842pub const timezone = extern struct {
1107 tz_minuteswest: i32,
1108 tz_dsttime: i32,
843 minuteswest: i32,
844 dsttime: i32,
1109845};
1110846
1111847pub const ucontext_t = extern struct {
lib/std/os/linux.zig+69-71
......@@ -20,6 +20,7 @@ const is_ppc64 = native_arch.isPPC64();
2020const is_sparc = native_arch.isSPARC();
2121const iovec = std.posix.iovec;
2222const iovec_const = std.posix.iovec_const;
23const winsize = std.posix.winsize;
2324const ACCMODE = std.posix.ACCMODE;
2425
2526test {
......@@ -44,7 +45,10 @@ const arch_bits = switch (native_arch) {
4445 .mips64, .mips64el => @import("linux/mips64.zig"),
4546 .powerpc, .powerpcle => @import("linux/powerpc.zig"),
4647 .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),
47 else => struct {},
48 else => struct {
49 pub const ucontext_t = void;
50 pub const getcontext = {};
51 },
4852};
4953pub const syscall0 = syscall_bits.syscall0;
5054pub const syscall1 = syscall_bits.syscall1;
......@@ -586,7 +590,7 @@ pub fn futex2_waitv(
586590 /// Optional absolute timeout.
587591 timeout: ?*const timespec,
588592 /// Clock to be used for the timeout, realtime or monotonic.
589 clockid: i32,
593 clockid: clockid_t,
590594) usize {
591595 return syscall5(
592596 .futex_waitv,
......@@ -612,7 +616,7 @@ pub fn futex2_wait(
612616 /// Optional absolute timeout.
613617 timeout: *const timespec,
614618 /// Clock to be used for the timeout, realtime or monotonic.
615 clockid: i32,
619 clockid: clockid_t,
616620) usize {
617621 return syscall6(
618622 .futex_wait,
......@@ -843,8 +847,8 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
843847 n,
844848 @intFromPtr(if (timeout >= 0)
845849 &timespec{
846 .tv_sec = @divTrunc(timeout, 1000),
847 .tv_nsec = @rem(timeout, 1000) * 1000000,
850 .sec = @divTrunc(timeout, 1000),
851 .nsec = @rem(timeout, 1000) * 1000000,
848852 }
849853 else
850854 null),
......@@ -1362,10 +1366,10 @@ pub fn flock(fd: fd_t, operation: i32) usize {
13621366}
13631367
13641368// We must follow the C calling convention when we call into the VDSO
1365const VdsoClockGettime = *align(1) const fn (i32, *timespec) callconv(.C) usize;
1369const VdsoClockGettime = *align(1) const fn (clockid_t, *timespec) callconv(.C) usize;
13661370var vdso_clock_gettime: ?VdsoClockGettime = &init_vdso_clock_gettime;
13671371
1368pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
1372pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize {
13691373 if (@hasDecl(VDSO, "CGT_SYM")) {
13701374 const ptr = @atomicLoad(?VdsoClockGettime, &vdso_clock_gettime, .unordered);
13711375 if (ptr) |f| {
......@@ -1376,10 +1380,10 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
13761380 }
13771381 }
13781382 }
1379 return syscall2(.clock_gettime, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp));
1383 return syscall2(.clock_gettime, @intFromEnum(clk_id), @intFromPtr(tp));
13801384}
13811385
1382fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
1386fn init_vdso_clock_gettime(clk: clockid_t, ts: *timespec) callconv(.C) usize {
13831387 const ptr: ?VdsoClockGettime = @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM));
13841388 // Note that we may not have a VDSO at all, update the stub address anyway
13851389 // so that clock_gettime will fall back on the good old (and slow) syscall
......@@ -1962,8 +1966,12 @@ pub fn eventfd(count: u32, flags: u32) usize {
19621966 return syscall2(.eventfd2, count, flags);
19631967}
19641968
1965pub fn timerfd_create(clockid: i32, flags: TFD) usize {
1966 return syscall2(.timerfd_create, @bitCast(@as(isize, clockid)), @as(u32, @bitCast(flags)));
1969pub fn timerfd_create(clockid: clockid_t, flags: TFD) usize {
1970 return syscall2(
1971 .timerfd_create,
1972 @intFromEnum(clockid),
1973 @as(u32, @bitCast(flags)),
1974 );
19671975}
19681976
19691977pub const itimerspec = extern struct {
......@@ -4029,19 +4037,22 @@ pub const EPOLL = struct {
40294037 pub const ET = (@as(u32, 1) << 31);
40304038};
40314039
4032pub const CLOCK = struct {
4033 pub const REALTIME = 0;
4034 pub const MONOTONIC = 1;
4035 pub const PROCESS_CPUTIME_ID = 2;
4036 pub const THREAD_CPUTIME_ID = 3;
4037 pub const MONOTONIC_RAW = 4;
4038 pub const REALTIME_COARSE = 5;
4039 pub const MONOTONIC_COARSE = 6;
4040 pub const BOOTTIME = 7;
4041 pub const REALTIME_ALARM = 8;
4042 pub const BOOTTIME_ALARM = 9;
4043 pub const SGI_CYCLE = 10;
4044 pub const TAI = 11;
4040pub const CLOCK = clockid_t;
4041
4042pub const clockid_t = enum(u32) {
4043 REALTIME = 0,
4044 MONOTONIC = 1,
4045 PROCESS_CPUTIME_ID = 2,
4046 THREAD_CPUTIME_ID = 3,
4047 MONOTONIC_RAW = 4,
4048 REALTIME_COARSE = 5,
4049 MONOTONIC_COARSE = 6,
4050 BOOTTIME = 7,
4051 REALTIME_ALARM = 8,
4052 BOOTTIME_ALARM = 9,
4053 SGI_CYCLE = 10,
4054 TAI = 11,
4055 _,
40454056};
40464057
40474058pub const CSIGNAL = 0x000000ff;
......@@ -4417,13 +4428,6 @@ pub const TFD = switch (native_arch) {
44174428 },
44184429};
44194430
4420pub const winsize = extern struct {
4421 ws_row: u16,
4422 ws_col: u16,
4423 ws_xpixel: u16,
4424 ws_ypixel: u16,
4425};
4426
44274431/// NSIG is the total number of signals defined.
44284432/// As signal numbers are sequential, NSIG is one greater than the largest defined signal number.
44294433pub const NSIG = if (is_mips) 128 else 65;
......@@ -4597,13 +4601,13 @@ pub const sockaddr = extern struct {
45974601};
45984602
45994603pub const mmsghdr = extern struct {
4600 msg_hdr: msghdr,
4601 msg_len: u32,
4604 hdr: msghdr,
4605 len: u32,
46024606};
46034607
46044608pub const mmsghdr_const = extern struct {
4605 msg_hdr: msghdr_const,
4606 msg_len: u32,
4609 hdr: msghdr_const,
4610 len: u32,
46074611};
46084612
46094613pub const epoll_data = extern union {
......@@ -4748,10 +4752,10 @@ pub const dirent64 = extern struct {
47484752};
47494753
47504754pub const dl_phdr_info = extern struct {
4751 dlpi_addr: usize,
4752 dlpi_name: ?[*:0]const u8,
4753 dlpi_phdr: [*]std.elf.Phdr,
4754 dlpi_phnum: u16,
4755 addr: usize,
4756 name: ?[*:0]const u8,
4757 phdr: [*]std.elf.Phdr,
4758 phnum: u16,
47554759};
47564760
47574761pub const CPU_SETSIZE = 128;
......@@ -4777,9 +4781,11 @@ pub const SIGSTKSZ = switch (native_arch) {
47774781 else => @compileError("SIGSTKSZ not defined for this architecture"),
47784782};
47794783
4780pub const SS_ONSTACK = 1;
4781pub const SS_DISABLE = 2;
4782pub const SS_AUTODISARM = 1 << 31;
4784pub const SS = struct {
4785 pub const ONSTACK = 1;
4786 pub const DISABLE = 2;
4787 pub const AUTODISARM = 1 << 31;
4788};
47834789
47844790pub const stack_t = if (is_mips)
47854791 // IRIX compatible stack_t
......@@ -5493,8 +5499,8 @@ pub const STATX_ATTR_ENCRYPTED = 0x0800;
54935499pub const STATX_ATTR_AUTOMOUNT = 0x1000;
54945500
54955501pub const statx_timestamp = extern struct {
5496 tv_sec: i64,
5497 tv_nsec: u32,
5502 sec: i64,
5503 nsec: u32,
54985504 __pad1: u32,
54995505};
55005506
......@@ -5562,7 +5568,7 @@ pub const Statx = extern struct {
55625568};
55635569
55645570pub const addrinfo = extern struct {
5565 flags: i32,
5571 flags: AI,
55665572 family: i32,
55675573 socktype: i32,
55685574 protocol: i32,
......@@ -5572,6 +5578,18 @@ pub const addrinfo = extern struct {
55725578 next: ?*addrinfo,
55735579};
55745580
5581pub const AI = packed struct(u32) {
5582 PASSIVE: bool = false,
5583 CANONNAME: bool = false,
5584 NUMERICHOST: bool = false,
5585 V4MAPPED: bool = false,
5586 ALL: bool = false,
5587 ADDRCONFIG: bool = false,
5588 _6: u4 = 0,
5589 NUMERICSERV: bool = false,
5590 _: u21 = 0,
5591};
5592
55755593pub const IPPORT_RESERVED = 1024;
55765594
55775595pub const IPPROTO = struct {
......@@ -6028,12 +6046,7 @@ pub const V = switch (native_arch) {
60286046 },
60296047};
60306048
6031pub const TCSA = enum(c_uint) {
6032 NOW,
6033 DRAIN,
6034 FLUSH,
6035 _,
6036};
6049pub const TCSA = std.posix.TCSA;
60376050
60386051pub const termios = switch (native_arch) {
60396052 .powerpc, .powerpcle, .powerpc64, .powerpc64le => extern struct {
......@@ -6097,55 +6110,40 @@ else
60976110 enum(c_int) {
60986111 /// Per-process CPU limit, in seconds.
60996112 CPU,
6100
61016113 /// Largest file that can be created, in bytes.
61026114 FSIZE,
6103
61046115 /// Maximum size of data segment, in bytes.
61056116 DATA,
6106
61076117 /// Maximum size of stack segment, in bytes.
61086118 STACK,
6109
61106119 /// Largest core file that can be created, in bytes.
61116120 CORE,
6112
61136121 /// Largest resident set size, in bytes.
61146122 /// This affects swapping; processes that are exceeding their
61156123 /// resident set size will be more likely to have physical memory
61166124 /// taken from them.
61176125 RSS,
6118
61196126 /// Number of processes.
61206127 NPROC,
6121
61226128 /// Number of open files.
61236129 NOFILE,
6124
61256130 /// Locked-in-memory address space.
61266131 MEMLOCK,
6127
61286132 /// Address space limit.
61296133 AS,
6130
61316134 /// Maximum number of file locks.
61326135 LOCKS,
6133
61346136 /// Maximum number of pending signals.
61356137 SIGPENDING,
6136
61376138 /// Maximum bytes in POSIX message queues.
61386139 MSGQUEUE,
6139
61406140 /// Maximum nice priority allowed to raise to.
61416141 /// Nice levels 19 .. -20 correspond to 0 .. 39
61426142 /// values of this resource limit.
61436143 NICE,
6144
61456144 /// Maximum realtime priority allowed for non-privileged
61466145 /// processes.
61476146 RTPRIO,
6148
61496147 /// Maximum CPU time in µs that a process scheduled under a real-time
61506148 /// scheduling policy may consume without making a blocking system
61516149 /// call before being forcibly descheduled.
......@@ -6223,13 +6221,13 @@ pub const POSIX_FADV = switch (native_arch) {
62236221
62246222/// The timespec struct used by the kernel.
62256223pub const kernel_timespec = if (@sizeOf(usize) >= 8) timespec else extern struct {
6226 tv_sec: i64,
6227 tv_nsec: i64,
6224 sec: i64,
6225 nsec: i64,
62286226};
62296227
62306228pub const timespec = extern struct {
6231 tv_sec: isize,
6232 tv_nsec: isize,
6229 sec: isize,
6230 nsec: isize,
62336231};
62346232
62356233pub const XDP = struct {
......@@ -7102,7 +7100,7 @@ pub const perf_event_attr = extern struct {
71027100 /// Defines size of the user stack to dump on samples.
71037101 sample_stack_user: u32 = 0,
71047102
7105 clockid: i32 = 0,
7103 clockid: clockid_t = 0,
71067104 /// Defines set of regs to dump for each sample
71077105 /// state captured on:
71087106 /// - precise = 0: PMU interrupt
lib/std/os/linux/IoUring.zig+6-6
......@@ -2261,7 +2261,7 @@ test "timeout (after a relative time)" {
22612261
22622262 const ms = 10;
22632263 const margin = 5;
2264 const ts: linux.kernel_timespec = .{ .tv_sec = 0, .tv_nsec = ms * 1000000 };
2264 const ts: linux.kernel_timespec = .{ .sec = 0, .nsec = ms * 1000000 };
22652265
22662266 const started = std.time.milliTimestamp();
22672267 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
......@@ -2290,7 +2290,7 @@ test "timeout (after a number of completions)" {
22902290 };
22912291 defer ring.deinit();
22922292
2293 const ts: linux.kernel_timespec = .{ .tv_sec = 3, .tv_nsec = 0 };
2293 const ts: linux.kernel_timespec = .{ .sec = 3, .nsec = 0 };
22942294 const count_completions: u64 = 1;
22952295 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
22962296 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
......@@ -2323,7 +2323,7 @@ test "timeout_remove" {
23232323 };
23242324 defer ring.deinit();
23252325
2326 const ts: linux.kernel_timespec = .{ .tv_sec = 3, .tv_nsec = 0 };
2326 const ts: linux.kernel_timespec = .{ .sec = 3, .nsec = 0 };
23272327 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
23282328 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
23292329 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
......@@ -2391,7 +2391,7 @@ test "accept/connect/recv/link_timeout" {
23912391 const sqe_recv = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);
23922392 sqe_recv.flags |= linux.IOSQE_IO_LINK;
23932393
2394 const ts = linux.kernel_timespec{ .tv_sec = 0, .tv_nsec = 1000000 };
2394 const ts = linux.kernel_timespec{ .sec = 0, .nsec = 1000000 };
23952395 _ = try ring.link_timeout(0x22222222, &ts, 0);
23962396
23972397 const nr_wait = try ring.submit();
......@@ -4248,7 +4248,7 @@ test "copy_cqes with wrapping sq.cqes buffer" {
42484248 {
42494249 for (0..2) |_| {
42504250 const sqe = try ring.get_sqe();
4251 sqe.prep_timeout(&.{ .tv_sec = 0, .tv_nsec = 10000 }, 0, 0);
4251 sqe.prep_timeout(&.{ .sec = 0, .nsec = 10000 }, 0, 0);
42524252 try testing.expect(try ring.submit() == 1);
42534253 }
42544254 var cqe_count: u32 = 0;
......@@ -4265,7 +4265,7 @@ test "copy_cqes with wrapping sq.cqes buffer" {
42654265 for (1..1024) |i| {
42664266 for (0..4) |_| {
42674267 const sqe = try ring.get_sqe();
4268 sqe.prep_timeout(&.{ .tv_sec = 0, .tv_nsec = 10000 }, 0, 0);
4268 sqe.prep_timeout(&.{ .sec = 0, .nsec = 10000 }, 0, 0);
42694269 try testing.expect(try ring.submit() == 1);
42704270 }
42714271 var cqe_count: u32 = 0;
lib/std/os/linux/arm-eabi.zig+7-4
......@@ -277,13 +277,13 @@ pub const Stat = extern struct {
277277};
278278
279279pub const timeval = extern struct {
280 tv_sec: i32,
281 tv_usec: i32,
280 sec: i32,
281 usec: i32,
282282};
283283
284284pub const timezone = extern struct {
285 tz_minuteswest: i32,
286 tz_dsttime: i32,
285 minuteswest: i32,
286 dsttime: i32,
287287};
288288
289289pub const mcontext_t = extern struct {
......@@ -319,4 +319,7 @@ pub const ucontext_t = extern struct {
319319 regspace: [64]u64,
320320};
321321
322/// TODO
323pub const getcontext = {};
324
322325pub const Elf_Symndx = u32;
lib/std/os/linux/arm64.zig+7-4
......@@ -236,13 +236,13 @@ pub const Stat = extern struct {
236236};
237237
238238pub const timeval = extern struct {
239 tv_sec: isize,
240 tv_usec: isize,
239 sec: isize,
240 usec: isize,
241241};
242242
243243pub const timezone = extern struct {
244 tz_minuteswest: i32,
245 tz_dsttime: i32,
244 minuteswest: i32,
245 dsttime: i32,
246246};
247247
248248pub const mcontext_t = extern struct {
......@@ -264,4 +264,7 @@ pub const ucontext_t = extern struct {
264264 mcontext: mcontext_t,
265265};
266266
267/// TODO
268pub const getcontext = {};
269
267270pub const Elf_Symndx = u32;
lib/std/os/linux/mips.zig+10-4
......@@ -326,13 +326,13 @@ pub const Stat = extern struct {
326326};
327327
328328pub const timeval = extern struct {
329 tv_sec: isize,
330 tv_usec: isize,
329 sec: isize,
330 usec: isize,
331331};
332332
333333pub const timezone = extern struct {
334 tz_minuteswest: i32,
335 tz_dsttime: i32,
334 minuteswest: i32,
335 dsttime: i32,
336336};
337337
338338pub const Elf_Symndx = u32;
......@@ -396,3 +396,9 @@ pub const rlimit_resource = enum(c_int) {
396396
397397 _,
398398};
399
400/// TODO
401pub const ucontext_t = void;
402
403/// TODO
404pub const getcontext = {};
lib/std/os/linux/mips64.zig+10-4
......@@ -311,13 +311,13 @@ pub const Stat = extern struct {
311311};
312312
313313pub const timeval = extern struct {
314 tv_sec: isize,
315 tv_usec: isize,
314 sec: isize,
315 usec: isize,
316316};
317317
318318pub const timezone = extern struct {
319 tz_minuteswest: i32,
320 tz_dsttime: i32,
319 minuteswest: i32,
320 dsttime: i32,
321321};
322322
323323pub const Elf_Symndx = u32;
......@@ -381,3 +381,9 @@ pub const rlimit_resource = enum(c_int) {
381381
382382 _,
383383};
384
385/// TODO
386pub const ucontext_t = void;
387
388/// TODO
389pub const getcontext = {};
lib/std/os/linux/powerpc.zig+7-4
......@@ -249,13 +249,13 @@ pub const Stat = extern struct {
249249};
250250
251251pub const timeval = extern struct {
252 tv_sec: time_t,
253 tv_usec: isize,
252 sec: time_t,
253 usec: isize,
254254};
255255
256256pub const timezone = extern struct {
257 tz_minuteswest: i32,
258 tz_dsttime: i32,
257 minuteswest: i32,
258 dsttime: i32,
259259};
260260
261261pub const greg_t = u32;
......@@ -290,3 +290,6 @@ pub const ucontext_t = extern struct {
290290pub const Elf_Symndx = u32;
291291
292292pub const MMAP2_UNIT = 4096;
293
294/// TODO
295pub const getcontext = {};
lib/std/os/linux/powerpc64.zig+7-4
......@@ -249,13 +249,13 @@ pub const Stat = extern struct {
249249};
250250
251251pub const timeval = extern struct {
252 tv_sec: isize,
253 tv_usec: isize,
252 sec: isize,
253 usec: isize,
254254};
255255
256256pub const timezone = extern struct {
257 tz_minuteswest: i32,
258 tz_dsttime: i32,
257 minuteswest: i32,
258 dsttime: i32,
259259};
260260
261261pub const greg_t = u64;
......@@ -298,3 +298,6 @@ pub const ucontext_t = extern struct {
298298};
299299
300300pub const Elf_Symndx = u32;
301
302/// TODO
303pub const getcontext = {};
lib/std/os/linux/riscv64.zig+8-2
......@@ -151,8 +151,8 @@ pub const dev_t = usize;
151151pub const blkcnt_t = isize;
152152
153153pub const timeval = extern struct {
154 tv_sec: time_t,
155 tv_usec: i64,
154 sec: time_t,
155 usec: i64,
156156};
157157
158158pub const Flock = extern struct {
......@@ -223,3 +223,9 @@ pub const Stat = extern struct {
223223pub const Elf_Symndx = u32;
224224
225225pub const VDSO = struct {};
226
227/// TODO
228pub const ucontext_t = void;
229
230/// TODO
231pub const getcontext = {};
lib/std/os/linux/sparc64.zig+7-4
......@@ -301,13 +301,13 @@ pub const Stat = extern struct {
301301};
302302
303303pub const timeval = extern struct {
304 tv_sec: isize,
305 tv_usec: i32,
304 sec: isize,
305 usec: i32,
306306};
307307
308308pub const timezone = extern struct {
309 tz_minuteswest: i32,
310 tz_dsttime: i32,
309 minuteswest: i32,
310 dsttime: i32,
311311};
312312
313313// TODO I'm not sure if the code below is correct, need someone with more
......@@ -412,6 +412,9 @@ pub const ucontext_t = extern struct {
412412 sigset: sigset_t,
413413};
414414
415/// TODO
416pub const getcontext = {};
417
415418pub const rlimit_resource = enum(c_int) {
416419 /// Per-process CPU limit, in seconds.
417420 CPU,
lib/std/os/linux/test.zig+2-2
......@@ -41,8 +41,8 @@ test "timer" {
4141 try expect(linux.E.init(timer_fd) == .SUCCESS);
4242
4343 const time_interval = linux.timespec{
44 .tv_sec = 0,
45 .tv_nsec = 2000000,
44 .sec = 0,
45 .nsec = 2000000,
4646 };
4747
4848 const new_time = linux.itimerspec{
lib/std/os/linux/x86.zig+4-4
......@@ -267,13 +267,13 @@ pub const Stat = extern struct {
267267};
268268
269269pub const timeval = extern struct {
270 tv_sec: i32,
271 tv_usec: i32,
270 sec: i32,
271 usec: i32,
272272};
273273
274274pub const timezone = extern struct {
275 tz_minuteswest: i32,
276 tz_dsttime: i32,
275 minuteswest: i32,
276 dsttime: i32,
277277};
278278
279279pub const mcontext_t = extern struct {
lib/std/os/linux/x86_64.zig+4-4
......@@ -272,13 +272,13 @@ pub const Stat = extern struct {
272272};
273273
274274pub const timeval = extern struct {
275 tv_sec: isize,
276 tv_usec: isize,
275 sec: isize,
276 usec: isize,
277277};
278278
279279pub const timezone = extern struct {
280 tz_minuteswest: i32,
281 tz_dsttime: i32,
280 minuteswest: i32,
281 dsttime: i32,
282282};
283283
284284pub const Elf_Symndx = u32;
lib/std/os/windows/ws2_32.zig+37-33
......@@ -676,23 +676,27 @@ pub const MSG = struct {
676676 pub const MAXIOVLEN = 16;
677677};
678678
679pub const AI = struct {
680 pub const PASSIVE = 1;
681 pub const CANONNAME = 2;
682 pub const NUMERICHOST = 4;
683 pub const NUMERICSERV = 8;
684 pub const DNS_ONLY = 16;
685 pub const ALL = 256;
686 pub const ADDRCONFIG = 1024;
687 pub const V4MAPPED = 2048;
688 pub const NON_AUTHORITATIVE = 16384;
689 pub const SECURE = 32768;
690 pub const RETURN_PREFERRED_NAMES = 65536;
691 pub const FQDN = 131072;
692 pub const FILESERVER = 262144;
693 pub const DISABLE_IDN_ENCODING = 524288;
694 pub const EXTENDED = 2147483648;
695 pub const RESOLUTION_HANDLE = 1073741824;
679pub const AI = packed struct(u32) {
680 PASSIVE: bool = false,
681 CANONNAME: bool = false,
682 NUMERICHOST: bool = false,
683 NUMERICSERV: bool = false,
684 DNS_ONLY: bool = false,
685 _5: u3 = 0,
686 ALL: bool = false,
687 _9: u1 = 0,
688 ADDRCONFIG: bool = false,
689 V4MAPPED: bool = false,
690 _12: u2 = 0,
691 NON_AUTHORITATIVE: bool = false,
692 SECURE: bool = false,
693 RETURN_PREFERRED_NAMES: bool = false,
694 FQDN: bool = false,
695 FILESERVER: bool = false,
696 DISABLE_IDN_ENCODING: bool = false,
697 _20: u10 = 0,
698 RESOLUTION_HANDLE: bool = false,
699 EXTENDED: bool = false,
696700};
697701
698702pub const FIONBIO = -2147195266;
......@@ -1068,8 +1072,8 @@ pub const sockproto = extern struct {
10681072};
10691073
10701074pub const linger = extern struct {
1071 l_onoff: u16,
1072 l_linger: u16,
1075 onoff: u16,
1076 linger: u16,
10731077};
10741078
10751079pub const WSANETWORKEVENTS = extern struct {
......@@ -1080,7 +1084,7 @@ pub const WSANETWORKEVENTS = extern struct {
10801084pub const addrinfo = addrinfoa;
10811085
10821086pub const addrinfoa = extern struct {
1083 flags: i32,
1087 flags: AI,
10841088 family: i32,
10851089 socktype: i32,
10861090 protocol: i32,
......@@ -1091,17 +1095,17 @@ pub const addrinfoa = extern struct {
10911095};
10921096
10931097pub const addrinfoexA = extern struct {
1094 ai_flags: i32,
1095 ai_family: i32,
1096 ai_socktype: i32,
1097 ai_protocol: i32,
1098 ai_addrlen: usize,
1099 ai_canonname: [*:0]u8,
1100 ai_addr: *sockaddr,
1101 ai_blob: *anyopaque,
1102 ai_bloblen: usize,
1103 ai_provider: *GUID,
1104 ai_next: *addrinfoexA,
1098 flags: AI,
1099 family: i32,
1100 socktype: i32,
1101 protocol: i32,
1102 addrlen: usize,
1103 canonname: [*:0]u8,
1104 addr: *sockaddr,
1105 blob: *anyopaque,
1106 bloblen: usize,
1107 provider: *GUID,
1108 next: *addrinfoexA,
11051109};
11061110
11071111pub const sockaddr = extern struct {
......@@ -1264,8 +1268,8 @@ pub const hostent = extern struct {
12641268};
12651269
12661270pub const timeval = extern struct {
1267 tv_sec: LONG,
1268 tv_usec: LONG,
1271 sec: LONG,
1272 usec: LONG,
12691273};
12701274
12711275// https://docs.microsoft.com/en-au/windows/win32/winsock/windows-sockets-error-codes-2
lib/std/posix.zig+72-67
......@@ -50,6 +50,7 @@ else switch (native_os) {
5050
5151pub const AF = system.AF;
5252pub const AF_SUN = system.AF_SUN;
53pub const AI = system.AI;
5354pub const ARCH = system.ARCH;
5455pub const AT = system.AT;
5556pub const AT_SUN = system.AT_SUN;
......@@ -72,10 +73,10 @@ pub const Kevent = system.Kevent;
7273pub const LOCK = system.LOCK;
7374pub const MADV = system.MADV;
7475pub const MAP = system.MAP;
75pub const MSF = system.MSF;
7676pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
7777pub const MFD = system.MFD;
7878pub const MMAP2_UNIT = system.MMAP2_UNIT;
79pub const MSF = system.MSF;
7980pub const MSG = system.MSG;
8081pub const NAME_MAX = system.NAME_MAX;
8182pub const O = system.O;
......@@ -90,7 +91,6 @@ pub const RR = system.RR;
9091pub const S = system.S;
9192pub const SA = system.SA;
9293pub const SC = system.SC;
93pub const _SC = system._SC;
9494pub const SEEK = system.SEEK;
9595pub const SHUT = system.SHUT;
9696pub const SIG = system.SIG;
......@@ -105,20 +105,22 @@ pub const SYS = system.SYS;
105105pub const Sigaction = system.Sigaction;
106106pub const Stat = system.Stat;
107107pub const T = system.T;
108pub const TCSA = system.TCSA;
109108pub const TCP = system.TCP;
110109pub const VDSO = system.VDSO;
111110pub const W = system.W;
111pub const _SC = system._SC;
112112pub const addrinfo = system.addrinfo;
113113pub const blkcnt_t = system.blkcnt_t;
114114pub const blksize_t = system.blksize_t;
115115pub const clock_t = system.clock_t;
116pub const clockid_t = system.clockid_t;
116117pub const cpu_set_t = system.cpu_set_t;
117118pub const dev_t = system.dev_t;
118119pub const dl_phdr_info = system.dl_phdr_info;
119120pub const empty_sigset = system.empty_sigset;
120pub const filled_sigset = system.filled_sigset;
121121pub const fd_t = system.fd_t;
122pub const file_obj = system.file_obj;
123pub const filled_sigset = system.filled_sigset;
122124pub const gid_t = system.gid_t;
123125pub const ifreq = system.ifreq;
124126pub const ino_t = system.ino_t;
......@@ -131,10 +133,9 @@ pub const nlink_t = system.nlink_t;
131133pub const off_t = system.off_t;
132134pub const pid_t = system.pid_t;
133135pub const pollfd = system.pollfd;
134pub const port_t = system.port_t;
135136pub const port_event = system.port_event;
136137pub const port_notify = system.port_notify;
137pub const file_obj = system.file_obj;
138pub const port_t = system.port_t;
138139pub const rlim_t = system.rlim_t;
139140pub const rlimit = system.rlimit;
140141pub const rlimit_resource = system.rlimit_resource;
......@@ -154,7 +155,6 @@ pub const ucontext_t = system.ucontext_t;
154155pub const uid_t = system.uid_t;
155156pub const user_desc = system.user_desc;
156157pub const utsname = system.utsname;
157pub const winsize = system.winsize;
158158
159159pub const termios = system.termios;
160160pub const CSIZE = system.CSIZE;
......@@ -188,6 +188,20 @@ pub const ACCMODE = enum(u2) {
188188 RDWR = 2,
189189};
190190
191pub const TCSA = enum(c_uint) {
192 NOW,
193 DRAIN,
194 FLUSH,
195 _,
196};
197
198pub const winsize = extern struct {
199 row: u16,
200 col: u16,
201 xpixel: u16,
202 ypixel: u16,
203};
204
191205pub const LOG = struct {
192206 /// system is unusable
193207 pub const EMERG = 0;
......@@ -226,6 +240,8 @@ pub fn errno(rc: anytype) E {
226240
227241/// Closes the file descriptor.
228242///
243/// Asserts the file descriptor is open.
244///
229245/// This function is not capable of returning any indication of failure. An
230246/// application which wants to ensure writes have succeeded before closing must
231247/// call `fsync` before `close`.
......@@ -239,13 +255,6 @@ pub fn close(fd: fd_t) void {
239255 _ = std.os.wasi.fd_close(fd);
240256 return;
241257 }
242 if (builtin.target.isDarwin()) {
243 // This avoids the EINTR problem.
244 switch (errno(std.c.@"close$NOCANCEL"(fd))) {
245 .BADF => unreachable, // Always a race condition.
246 else => return,
247 }
248 }
249258 switch (errno(system.close(fd))) {
250259 .BADF => unreachable, // Always a race condition.
251260 .INTR => return, // This is still a success. See https://github.com/ziglang/zig/issues/2425
......@@ -571,7 +580,15 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
571580 if (native_os == .windows) {
572581 return windows.RtlGenRandom(buffer);
573582 }
574 if (native_os == .linux or native_os == .freebsd) {
583 if (builtin.link_libc and @TypeOf(system.arc4random_buf) != void) {
584 system.arc4random_buf(buffer.ptr, buffer.len);
585 return;
586 }
587 if (native_os == .wasi) switch (wasi.random_get(buffer.ptr, buffer.len)) {
588 .SUCCESS => return,
589 else => |err| return unexpectedErrno(err),
590 };
591 if (@TypeOf(system.getrandom) != void) {
575592 var buf = buffer;
576593 const use_c = native_os != .linux or
577594 std.c.versionCheck(std.SemanticVersion{ .major = 2, .minor = 25, .patch = 0 });
......@@ -603,17 +620,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
603620 else => return unexpectedErrno(err),
604621 }
605622 }
606 switch (native_os) {
607 .netbsd, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => {
608 system.arc4random_buf(buffer.ptr, buffer.len);
609 return;
610 },
611 .wasi => switch (wasi.random_get(buffer.ptr, buffer.len)) {
612 .SUCCESS => return,
613 else => |err| return unexpectedErrno(err),
614 },
615 else => return getRandomBytesDevURandom(buffer),
616 }
623 return getRandomBytesDevURandom(buffer);
617624}
618625
619626fn getRandomBytesDevURandom(buf: []u8) !void {
......@@ -3430,7 +3437,7 @@ pub fn isatty(handle: fd_t) bool {
34303437 }
34313438 if (native_os == .linux) {
34323439 while (true) {
3433 var wsz: linux.winsize = undefined;
3440 var wsz: winsize = undefined;
34343441 const fd: usize = @bitCast(@as(isize, handle));
34353442 const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @intFromPtr(&wsz));
34363443 switch (linux.E.init(rc)) {
......@@ -4929,8 +4936,7 @@ pub fn pipe() PipeError![2]fd_t {
49294936}
49304937
49314938pub fn pipe2(flags: O) PipeError![2]fd_t {
4932 // https://github.com/ziglang/zig/issues/19352
4933 if (@hasDecl(system, "pipe2")) {
4939 if (@TypeOf(system.pipe2) != void) {
49344940 var fds: [2]fd_t = undefined;
49354941 switch (errno(system.pipe2(&fds, flags))) {
49364942 .SUCCESS => return fds,
......@@ -5438,8 +5444,8 @@ pub fn realpathW(pathname: []const u16, out_buffer: *[max_path_bytes]u8) RealPat
54385444/// Spurious wakeups are possible and no precision of timing is guaranteed.
54395445pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
54405446 var req = timespec{
5441 .tv_sec = cast(isize, seconds) orelse maxInt(isize),
5442 .tv_nsec = cast(isize, nanoseconds) orelse maxInt(isize),
5447 .sec = cast(isize, seconds) orelse maxInt(isize),
5448 .nsec = cast(isize, nanoseconds) orelse maxInt(isize),
54435449 };
54445450 var rem: timespec = undefined;
54455451 while (true) {
......@@ -5511,10 +5517,10 @@ pub fn dl_iterate_phdr(
55115517 } else unreachable;
55125518
55135519 var info = dl_phdr_info{
5514 .dlpi_addr = base_address,
5515 .dlpi_name = "/proc/self/exe",
5516 .dlpi_phdr = phdrs.ptr,
5517 .dlpi_phnum = ehdr.e_phnum,
5520 .addr = base_address,
5521 .name = "/proc/self/exe",
5522 .phdr = phdrs.ptr,
5523 .phnum = ehdr.e_phnum,
55185524 };
55195525
55205526 return callback(&info, @sizeOf(dl_phdr_info), context);
......@@ -5522,24 +5528,24 @@ pub fn dl_iterate_phdr(
55225528
55235529 // Last return value from the callback function.
55245530 while (it.next()) |entry| {
5525 var dlpi_phdr: [*]elf.Phdr = undefined;
5526 var dlpi_phnum: u16 = undefined;
5531 var phdr: [*]elf.Phdr = undefined;
5532 var phnum: u16 = undefined;
55275533
55285534 if (entry.l_addr != 0) {
55295535 const elf_header: *elf.Ehdr = @ptrFromInt(entry.l_addr);
5530 dlpi_phdr = @ptrFromInt(entry.l_addr + elf_header.e_phoff);
5531 dlpi_phnum = elf_header.e_phnum;
5536 phdr = @ptrFromInt(entry.l_addr + elf_header.e_phoff);
5537 phnum = elf_header.e_phnum;
55325538 } else {
55335539 // This is the running ELF image
5534 dlpi_phdr = @ptrFromInt(elf_base + ehdr.e_phoff);
5535 dlpi_phnum = ehdr.e_phnum;
5540 phdr = @ptrFromInt(elf_base + ehdr.e_phoff);
5541 phnum = ehdr.e_phnum;
55365542 }
55375543
55385544 var info = dl_phdr_info{
5539 .dlpi_addr = entry.l_addr,
5540 .dlpi_name = entry.l_name,
5541 .dlpi_phdr = dlpi_phdr,
5542 .dlpi_phnum = dlpi_phnum,
5545 .addr = entry.l_addr,
5546 .name = entry.l_name,
5547 .phdr = phdr,
5548 .phnum = phnum,
55435549 };
55445550
55455551 try callback(&info, @sizeOf(dl_phdr_info), context);
......@@ -5549,15 +5555,14 @@ pub fn dl_iterate_phdr(
55495555pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError;
55505556
55515557/// TODO: change this to return the timespec as a return value
5552/// TODO: look into making clk_id an enum
5553pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
5558pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void {
55545559 if (native_os == .wasi and !builtin.link_libc) {
55555560 var ts: timestamp_t = undefined;
5556 switch (system.clock_time_get(@bitCast(clk_id), 1, &ts)) {
5561 switch (system.clock_time_get(clock_id, 1, &ts)) {
55575562 .SUCCESS => {
55585563 tp.* = .{
5559 .tv_sec = @intCast(ts / std.time.ns_per_s),
5560 .tv_nsec = @intCast(ts % std.time.ns_per_s),
5564 .sec = @intCast(ts / std.time.ns_per_s),
5565 .nsec = @intCast(ts % std.time.ns_per_s),
55615566 };
55625567 },
55635568 .INVAL => return error.UnsupportedClock,
......@@ -5566,15 +5571,15 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
55665571 return;
55675572 }
55685573 if (native_os == .windows) {
5569 if (clk_id == CLOCK.REALTIME) {
5574 if (clock_id == .REALTIME) {
55705575 var ft: windows.FILETIME = undefined;
55715576 windows.kernel32.GetSystemTimeAsFileTime(&ft);
55725577 // FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch.
55735578 const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
55745579 const ft_per_s = std.time.ns_per_s / 100;
55755580 tp.* = .{
5576 .tv_sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows,
5577 .tv_nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100,
5581 .sec = @as(i64, @intCast(ft64 / ft_per_s)) + std.time.epoch.windows,
5582 .nsec = @as(c_long, @intCast(ft64 % ft_per_s)) * 100,
55785583 };
55795584 return;
55805585 } else {
......@@ -5583,7 +5588,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
55835588 }
55845589 }
55855590
5586 switch (errno(system.clock_gettime(clk_id, tp))) {
5591 switch (errno(system.clock_gettime(clock_id, tp))) {
55875592 .SUCCESS => return,
55885593 .FAULT => unreachable,
55895594 .INVAL => return error.UnsupportedClock,
......@@ -5591,13 +5596,13 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
55915596 }
55925597}
55935598
5594pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
5599pub fn clock_getres(clock_id: clockid_t, res: *timespec) ClockGetTimeError!void {
55955600 if (native_os == .wasi and !builtin.link_libc) {
55965601 var ts: timestamp_t = undefined;
5597 switch (system.clock_res_get(@bitCast(clk_id), &ts)) {
5602 switch (system.clock_res_get(@bitCast(clock_id), &ts)) {
55985603 .SUCCESS => res.* = .{
5599 .tv_sec = @intCast(ts / std.time.ns_per_s),
5600 .tv_nsec = @intCast(ts % std.time.ns_per_s),
5604 .sec = @intCast(ts / std.time.ns_per_s),
5605 .nsec = @intCast(ts % std.time.ns_per_s),
56015606 },
56025607 .INVAL => return error.UnsupportedClock,
56035608 else => |err| return unexpectedErrno(err),
......@@ -5605,7 +5610,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
56055610 return;
56065611 }
56075612
5608 switch (errno(system.clock_getres(clk_id, res))) {
5613 switch (errno(system.clock_getres(clock_id, res))) {
56095614 .SUCCESS => return,
56105615 .FAULT => unreachable,
56115616 .INVAL => return error.UnsupportedClock,
......@@ -5666,7 +5671,7 @@ pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*
56665671}
56675672
56685673pub const FutimensError = error{
5669 /// times is NULL, or both tv_nsec values are UTIME_NOW, and either:
5674 /// times is NULL, or both nsec values are UTIME_NOW, and either:
56705675 /// * the effective user ID of the caller does not match the owner
56715676 /// of the file, the caller does not have write access to the
56725677 /// file, and the caller is not privileged (Linux: does not have
......@@ -5678,8 +5683,8 @@ pub const FutimensError = error{
56785683 /// The caller attempted to change one or both timestamps to a value
56795684 /// other than the current time, or to change one of the timestamps
56805685 /// to the current time while leaving the other timestamp unchanged,
5681 /// (i.e., times is not NULL, neither tv_nsec field is UTIME_NOW,
5682 /// and neither tv_nsec field is UTIME_OMIT) and either:
5686 /// (i.e., times is not NULL, neither nsec field is UTIME_NOW,
5687 /// and neither nsec field is UTIME_OMIT) and either:
56835688 /// * the caller's effective user ID does not match the owner of
56845689 /// file, and the caller is not privileged (Linux: does not have
56855690 /// the CAP_FOWNER capability); or,
......@@ -5794,9 +5799,9 @@ pub fn res_mkquery(
57945799
57955800 // Make a reasonably unpredictable id
57965801 var ts: timespec = undefined;
5797 clock_gettime(CLOCK.REALTIME, &ts) catch {};
5798 const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.tv_nsec)));
5799 const unsec: UInt = @bitCast(ts.tv_nsec);
5802 clock_gettime(.REALTIME, &ts) catch {};
5803 const UInt = std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(ts.nsec)));
5804 const unsec: UInt = @bitCast(ts.nsec);
58005805 const id: u32 = @truncate(unsec + unsec / 65536);
58015806 q[0] = @truncate(id / 256);
58025807 q[1] = @truncate(id);
......@@ -7195,8 +7200,8 @@ pub const TimerFdCreateError = error{
71957200pub const TimerFdGetError = error{InvalidHandle} || UnexpectedError;
71967201pub const TimerFdSetError = TimerFdGetError || error{Canceled};
71977202
7198pub fn timerfd_create(clokid: i32, flags: system.TFD) TimerFdCreateError!fd_t {
7199 const rc = system.timerfd_create(clokid, @bitCast(flags));
7203pub fn timerfd_create(clock_id: clockid_t, flags: system.TFD) TimerFdCreateError!fd_t {
7204 const rc = system.timerfd_create(clock_id, @bitCast(flags));
72007205 return switch (errno(rc)) {
72017206 .SUCCESS => @intCast(rc),
72027207 .INVAL => unreachable,
lib/std/posix/test.zig+13-14
......@@ -483,7 +483,8 @@ test "sigaltstack" {
483483
484484// If the type is not available use void to avoid erroring out when `iter_fn` is
485485// analyzed
486const dl_phdr_info = if (@hasDecl(posix.system, "dl_phdr_info")) posix.dl_phdr_info else anyopaque;
486const have_dl_phdr_info = posix.system.dl_phdr_info != void;
487const dl_phdr_info = if (have_dl_phdr_info) posix.dl_phdr_info else anyopaque;
487488
488489const IterFnError = error{
489490 MissingPtLoadSegment,
......@@ -498,24 +499,24 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
498499 counter.* += @as(usize, 1);
499500
500501 // The image should contain at least a PT_LOAD segment
501 if (info.dlpi_phnum < 1) return error.MissingPtLoadSegment;
502 if (info.phnum < 1) return error.MissingPtLoadSegment;
502503
503504 // Quick & dirty validation of the phdr pointers, make sure we're not
504505 // pointing to some random gibberish
505506 var i: usize = 0;
506507 var found_load = false;
507 while (i < info.dlpi_phnum) : (i += 1) {
508 const phdr = info.dlpi_phdr[i];
508 while (i < info.phnum) : (i += 1) {
509 const phdr = info.phdr[i];
509510
510511 if (phdr.p_type != elf.PT_LOAD) continue;
511512
512 const reloc_addr = info.dlpi_addr + phdr.p_vaddr;
513 const reloc_addr = info.addr + phdr.p_vaddr;
513514 // Find the ELF header
514515 const elf_header = @as(*elf.Ehdr, @ptrFromInt(reloc_addr - phdr.p_offset));
515516 // Validate the magic
516517 if (!mem.eql(u8, elf_header.e_ident[0..4], elf.MAGIC)) return error.BadElfMagic;
517518 // Consistency check
518 if (elf_header.e_phnum != info.dlpi_phnum) return error.FailedConsistencyCheck;
519 if (elf_header.e_phnum != info.phnum) return error.FailedConsistencyCheck;
519520
520521 found_load = true;
521522 break;
......@@ -774,12 +775,10 @@ test "fsync" {
774775}
775776
776777test "getrlimit and setrlimit" {
777 if (!@hasDecl(posix.system, "rlimit")) {
778 return error.SkipZigTest;
779 }
778 if (posix.system.rlimit_resource == void) return error.SkipZigTest;
780779
781 inline for (std.meta.fields(posix.rlimit_resource)) |field| {
782 const resource = @as(posix.rlimit_resource, @enumFromInt(field.value));
780 inline for (@typeInfo(posix.rlimit_resource).Enum.fields) |field| {
781 const resource: posix.rlimit_resource = @enumFromInt(field.value);
783782 const limit = try posix.getrlimit(resource);
784783
785784 // XNU kernel does not support RLIMIT_STACK if a custom stack is active,
......@@ -1116,18 +1115,18 @@ test "access smoke test" {
11161115test "timerfd" {
11171116 if (native_os != .linux) return error.SkipZigTest;
11181117
1119 const tfd = try posix.timerfd_create(linux.CLOCK.MONOTONIC, .{ .CLOEXEC = true });
1118 const tfd = try posix.timerfd_create(.MONOTONIC, .{ .CLOEXEC = true });
11201119 defer posix.close(tfd);
11211120
11221121 // Fire event 10_000_000ns = 10ms after the posix.timerfd_settime call.
1123 var sit: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 10 * (1000 * 1000) } };
1122 var sit: linux.itimerspec = .{ .it_interval = .{ .sec = 0, .nsec = 0 }, .it_value = .{ .sec = 0, .nsec = 10 * (1000 * 1000) } };
11241123 try posix.timerfd_settime(tfd, .{}, &sit, null);
11251124
11261125 var fds: [1]posix.pollfd = .{.{ .fd = tfd, .events = linux.POLL.IN, .revents = 0 }};
11271126 try expectEqual(@as(usize, 1), try posix.poll(&fds, -1)); // -1 => infinite waiting
11281127
11291128 const git = try posix.timerfd_gettime(tfd);
1130 const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .tv_sec = 0, .tv_nsec = 0 }, .it_value = .{ .tv_sec = 0, .tv_nsec = 0 } };
1129 const expect_disarmed_timer: linux.itimerspec = .{ .it_interval = .{ .sec = 0, .nsec = 0 }, .it_value = .{ .sec = 0, .nsec = 0 } };
11311130 try expectEqual(expect_disarmed_timer, git);
11321131}
11331132
lib/std/process.zig+1-4
......@@ -1789,10 +1789,7 @@ pub fn cleanExit() void {
17891789/// On some systems, this raises the limit before seeing ProcessFdQuotaExceeded
17901790/// errors. On other systems, this does nothing.
17911791pub fn raiseFileDescriptorLimit() void {
1792 const have_rlimit = switch (native_os) {
1793 .windows, .wasi => false,
1794 else => true,
1795 };
1792 const have_rlimit = posix.rlimit_resource != void;
17961793 if (!have_rlimit) return;
17971794
17981795 var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
lib/std/time.zig+7-7
......@@ -115,10 +115,10 @@ pub fn nanoTimestamp() i128 {
115115 },
116116 else => {
117117 var ts: posix.timespec = undefined;
118 posix.clock_gettime(posix.CLOCK.REALTIME, &ts) catch |err| switch (err) {
118 posix.clock_gettime(.REALTIME, &ts) catch |err| switch (err) {
119119 error.UnsupportedClock, error.Unexpected => return 0, // "Precision of timing depends on hardware and OS".
120120 };
121 return (@as(i128, ts.tv_sec) * ns_per_s) + ts.tv_nsec;
121 return (@as(i128, ts.sec) * ns_per_s) + ts.nsec;
122122 },
123123 }
124124}
......@@ -229,9 +229,9 @@ pub const Instant = struct {
229229 return std.math.order(self.timestamp, other.timestamp);
230230 }
231231
232 var ord = std.math.order(self.timestamp.tv_sec, other.timestamp.tv_sec);
232 var ord = std.math.order(self.timestamp.sec, other.timestamp.sec);
233233 if (ord == .eq) {
234 ord = std.math.order(self.timestamp.tv_nsec, other.timestamp.tv_nsec);
234 ord = std.math.order(self.timestamp.nsec, other.timestamp.nsec);
235235 }
236236 return ord;
237237 }
......@@ -267,9 +267,9 @@ pub const Instant = struct {
267267 }
268268
269269 // Convert timespec diff to ns
270 const seconds = @as(u64, @intCast(self.timestamp.tv_sec - earlier.timestamp.tv_sec));
271 const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.tv_nsec));
272 return elapsed - @as(u32, @intCast(earlier.timestamp.tv_nsec));
270 const seconds = @as(u64, @intCast(self.timestamp.sec - earlier.timestamp.sec));
271 const elapsed = (seconds * ns_per_s) + @as(u32, @intCast(self.timestamp.nsec));
272 return elapsed - @as(u32, @intCast(earlier.timestamp.nsec));
273273 }
274274};
275275