authorgravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2025-03-10 20:02:49+00:00
committergravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2025-03-11 14:59:29+00:00
log79a0de2a2f5467e0ac7a20743e21a409677bfd95
treed578c247ad56db43d7f6469aa8f3bcc8f732c318
parent423907c2700ae5812a6abccca8cf6db29c7dad9e

std.c: Add definitions for SerenityOS


2 files changed, 1025 insertions(+), 57 deletions(-)

lib/std/c.zig+950-57
......@@ -19,6 +19,7 @@ const netbsd = @import("c/netbsd.zig");
1919const dragonfly = @import("c/dragonfly.zig");
2020const haiku = @import("c/haiku.zig");
2121const openbsd = @import("c/openbsd.zig");
22const serenity = @import("c/serenity.zig");
2223
2324// These constants are shared among all operating systems even when not linking
2425// libc.
......@@ -75,12 +76,14 @@ pub const ino_t = switch (native_os) {
7576 .wasi => wasi.inode_t,
7677 .windows => windows.LARGE_INTEGER,
7778 .haiku => i64,
79 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L38
7880 else => u64,
7981};
8082
8183pub const off_t = switch (native_os) {
8284 .linux => linux.off_t,
8385 .emscripten => emscripten.off_t,
86 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L39
8487 else => i64,
8588};
8689
......@@ -105,7 +108,8 @@ pub const timespec = switch (native_os) {
105108 @as(wasi.timestamp_t, @intCast(ts.nsec));
106109 }
107110 },
108 .windows => extern struct {
111 // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20
112 .windows, .serenity => extern struct {
109113 sec: time_t,
110114 nsec: c_long,
111115 },
......@@ -129,7 +133,8 @@ pub const dev_t = switch (native_os) {
129133 .emscripten => emscripten.dev_t,
130134 .wasi => wasi.device_t,
131135 .openbsd, .haiku, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => i32,
132 .netbsd, .freebsd => u64,
136 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L43
137 .netbsd, .freebsd, .serenity => u64,
133138 else => void,
134139};
135140
......@@ -137,7 +142,8 @@ pub const mode_t = switch (native_os) {
137142 .linux => linux.mode_t,
138143 .emscripten => emscripten.mode_t,
139144 .openbsd, .haiku, .netbsd, .solaris, .illumos, .wasi, .windows => u32,
140 .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .dragonfly => u16,
145 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44
146 .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .dragonfly, .serenity => u16,
141147 else => u0,
142148};
143149
......@@ -145,7 +151,8 @@ pub const nlink_t = switch (native_os) {
145151 .linux => linux.nlink_t,
146152 .emscripten => emscripten.nlink_t,
147153 .wasi => c_ulonglong,
148 .freebsd => u64,
154 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L45
155 .freebsd, .serenity => u64,
149156 .openbsd, .netbsd, .solaris, .illumos => u32,
150157 .haiku => i32,
151158 else => void,
......@@ -154,12 +161,14 @@ pub const nlink_t = switch (native_os) {
154161pub const uid_t = switch (native_os) {
155162 .linux => linux.uid_t,
156163 .emscripten => emscripten.uid_t,
164 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L28
157165 else => u32,
158166};
159167
160168pub const gid_t = switch (native_os) {
161169 .linux => linux.gid_t,
162170 .emscripten => emscripten.gid_t,
171 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L29
163172 else => u32,
164173};
165174
......@@ -167,11 +176,14 @@ pub const blksize_t = switch (native_os) {
167176 .linux => linux.blksize_t,
168177 .emscripten => emscripten.blksize_t,
169178 .wasi => c_long,
179 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L42
180 .serenity => u64,
170181 else => i32,
171182};
172183
173184pub const passwd = switch (native_os) {
174 .linux => extern struct {
185 // https://github.com/SerenityOS/serenity/blob/7442cfb5072b74a62c0e061e6e9ff44fda08780d/Userland/Libraries/LibC/pwd.h#L15-L23
186 .linux, .serenity => extern struct {
175187 name: ?[*:0]const u8, // username
176188 passwd: ?[*:0]const u8, // user password
177189 uid: uid_t, // user ID
......@@ -199,6 +211,8 @@ pub const blkcnt_t = switch (native_os) {
199211 .linux => linux.blkcnt_t,
200212 .emscripten => emscripten.blkcnt_t,
201213 .wasi => c_longlong,
214 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L41
215 .serenity => u64,
202216 else => i64,
203217};
204218
......@@ -206,6 +220,7 @@ pub const fd_t = switch (native_os) {
206220 .linux => linux.fd_t,
207221 .wasi => wasi.fd_t,
208222 .windows => windows.HANDLE,
223 .serenity => c_int,
209224 else => i32,
210225};
211226
......@@ -309,6 +324,14 @@ pub const clockid_t = switch (native_os) {
309324 MONOTONIC = 3,
310325 THREAD_CPUTIME_ID = 4,
311326 },
327 // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L24-L36
328 .serenity => enum(c_int) {
329 REALTIME = 0,
330 MONOTONIC = 1,
331 MONOTONIC_RAW = 2,
332 REALTIME_COARSE = 3,
333 MONOTONIC_COARSE = 4,
334 },
312335 else => void,
313336};
314337pub const CPU_COUNT = switch (native_os) {
......@@ -681,6 +704,93 @@ pub const E = switch (native_os) {
681704 .dragonfly => dragonfly.E,
682705 .haiku => haiku.E,
683706 .openbsd => openbsd.E,
707 // https://github.com/SerenityOS/serenity/blob/dd59fe35c7e5bbaf6b6b3acb3f9edc56619d4b66/Kernel/API/POSIX/errno.h
708 .serenity => enum(c_int) {
709 SUCCESS = 0,
710 PERM = 1,
711 NOENT = 2,
712 SRCH = 3,
713 INTR = 4,
714 IO = 5,
715 NXIO = 6,
716 @"2BIG" = 7,
717 NOEXEC = 8,
718 BADF = 9,
719 CHILD = 10,
720 AGAIN = 11,
721 NOMEM = 12,
722 ACCES = 13,
723 FAULT = 14,
724 NOTBLK = 15,
725 BUSY = 16,
726 EXIST = 17,
727 XDEV = 18,
728 NODEV = 19,
729 NOTDIR = 20,
730 ISDIR = 21,
731 INVAL = 22,
732 NFILE = 23,
733 MFILE = 24,
734 NOTTY = 25,
735 TXTBSY = 26,
736 FBIG = 27,
737 NOSPC = 28,
738 SPIPE = 29,
739 ROFS = 30,
740 MLINK = 31,
741 PIPE = 32,
742 RANGE = 33,
743 NAMETOOLONG = 34,
744 LOOP = 35,
745 OVERFLOW = 36,
746 OPNOTSUPP = 37,
747 NOSYS = 38,
748 NOTIMPL = 39,
749 AFNOSUPPORT = 40,
750 NOTSOCK = 41,
751 ADDRINUSE = 42,
752 NOTEMPTY = 43,
753 DOM = 44,
754 CONNREFUSED = 45,
755 HOSTDOWN = 46,
756 ADDRNOTAVAIL = 47,
757 ISCONN = 48,
758 CONNABORTED = 49,
759 ALREADY = 50,
760 CONNRESET = 51,
761 DESTADDRREQ = 52,
762 HOSTUNREACH = 53,
763 ILSEQ = 54,
764 MSGSIZE = 55,
765 NETDOWN = 56,
766 NETUNREACH = 57,
767 NETRESET = 58,
768 NOBUFS = 59,
769 NOLCK = 60,
770 NOMSG = 61,
771 NOPROTOOPT = 62,
772 NOTCONN = 63,
773 SHUTDOWN = 64,
774 TOOMANYREFS = 65,
775 SOCKTNOSUPPORT = 66,
776 PROTONOSUPPORT = 67,
777 DEADLK = 68,
778 TIMEDOUT = 69,
779 PROTOTYPE = 70,
780 INPROGRESS = 71,
781 NOTHREAD = 72,
782 PROTO = 73,
783 NOTSUP = 74,
784 PFNOSUPPORT = 75,
785 DIRINTOSELF = 76,
786 DQUOT = 77,
787 NOTRECOVERABLE = 78,
788 CANCELED = 79,
789 PROMISEVIOLATION = 80,
790 STALE = 81,
791 SRCNOTFOUND = 82,
792 _,
793 },
684794 else => void,
685795};
686796pub const Elf_Symndx = switch (native_os) {
......@@ -1054,6 +1164,24 @@ pub const F = switch (native_os) {
10541164 pub const UNLCK = 2;
10551165 pub const WRLCK = 3;
10561166 },
1167 .serenity => struct {
1168 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L15-L24
1169 pub const DUPFD = 0;
1170 pub const GETFD = 1;
1171 pub const SETFD = 2;
1172 pub const GETFL = 3;
1173 pub const SETFL = 4;
1174 pub const ISTTY = 5;
1175 pub const GETLK = 6;
1176 pub const SETLK = 7;
1177 pub const SETLKW = 8;
1178 pub const DUPFD_CLOEXEC = 9;
1179
1180 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L45-L47
1181 pub const RDLCK = 0;
1182 pub const WRLCK = 1;
1183 pub const UNLCK = 2;
1184 },
10571185 else => void,
10581186};
10591187pub const FD_CLOEXEC = switch (native_os) {
......@@ -1129,18 +1257,29 @@ pub const Flock = switch (native_os) {
11291257 len: off_t,
11301258 pid: pid_t,
11311259 },
1260 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L54-L60
1261 .serenity => extern struct {
1262 type: c_short,
1263 whence: c_short,
1264 start: off_t,
1265 len: off_t,
1266 pid: pid_t,
1267 },
11321268 else => void,
11331269};
11341270pub const HOST_NAME_MAX = switch (native_os) {
11351271 .linux => linux.HOST_NAME_MAX,
11361272 .macos, .ios, .tvos, .watchos, .visionos => 72,
11371273 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd => 255,
1274 // https://github.com/SerenityOS/serenity/blob/c87557e9c1865fa1a6440de34ff6ce6fc858a2b7/Kernel/API/POSIX/sys/limits.h#L22
1275 .serenity => 64,
11381276 else => {},
11391277};
11401278pub const IOV_MAX = switch (native_os) {
11411279 .linux => linux.IOV_MAX,
11421280 .emscripten => emscripten.IOV_MAX,
1143 .openbsd, .haiku, .solaris, .illumos, .wasi => 1024,
1281 // https://github.com/SerenityOS/serenity/blob/098af0f846a87b651731780ff48420205fd33754/Kernel/API/POSIX/sys/uio.h#L16
1282 .openbsd, .haiku, .solaris, .illumos, .wasi, .serenity => 1024,
11441283 .macos, .ios, .tvos, .watchos, .visionos => 16,
11451284 .dragonfly, .netbsd, .freebsd => KERN.IOV_MAX,
11461285 else => {},
......@@ -1425,6 +1564,16 @@ pub const MADV = switch (native_os) {
14251564 pub const INVAL = 10;
14261565 pub const SETMAP = 11;
14271566 },
1567 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L35-L41
1568 .serenity => struct {
1569 pub const NORMAL = 0x0;
1570 pub const SET_VOLATILE = 0x1;
1571 pub const SET_NONVOLATILE = 0x2;
1572 pub const DONTNEED = 0x3;
1573 pub const WILLNEED = 0x4;
1574 pub const SEQUENTIAL = 0x5;
1575 pub const RANDOM = 0x6;
1576 },
14281577 else => void,
14291578};
14301579pub const MSF = switch (native_os) {
......@@ -1444,6 +1593,12 @@ pub const MSF = switch (native_os) {
14441593 pub const INVALIDATE = 2;
14451594 pub const SYNC = 4;
14461595 },
1596 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L50-L52
1597 .serenity => struct {
1598 pub const SYNC = 1;
1599 pub const ASYNC = 2;
1600 pub const INVALIDATE = 4;
1601 },
14471602 else => void,
14481603};
14491604pub const MMAP2_UNIT = switch (native_os) {
......@@ -1456,7 +1611,8 @@ pub const NAME_MAX = switch (native_os) {
14561611 // Haiku's headers make this 256, to contain room for the terminating null
14571612 // character, but POSIX definition says that NAME_MAX does not include the
14581613 // terminating null.
1459 .haiku, .openbsd, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => 255,
1614 // https://github.com/SerenityOS/serenity/blob/c87557e9c1865fa1a6440de34ff6ce6fc858a2b7/Kernel/API/POSIX/sys/limits.h#L20
1615 .haiku, .openbsd, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .serenity => 255,
14601616 else => {},
14611617};
14621618pub const PATH_MAX = switch (native_os) {
......@@ -1464,7 +1620,7 @@ pub const PATH_MAX = switch (native_os) {
14641620 .emscripten => emscripten.PATH_MAX,
14651621 .wasi => 4096,
14661622 .windows => 260,
1467 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => 1024,
1623 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .serenity => 1024,
14681624 else => {},
14691625};
14701626
......@@ -1597,6 +1753,19 @@ pub const POLL = switch (native_os) {
15971753 pub const RDBAND = 0x0080;
15981754 pub const WRBAND = 0x0100;
15991755 },
1756 // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L15-L24
1757 .serenity => struct {
1758 pub const IN = 0x0001;
1759 pub const PRI = 0x0002;
1760 pub const OUT = 0x0004;
1761 pub const ERR = 0x0008;
1762 pub const HUP = 0x0010;
1763 pub const NVAL = 0x0020;
1764 pub const RDNORM = IN;
1765 pub const WRNORM = OUT;
1766 pub const WRBAND = 0x1000;
1767 pub const RDHUP = 0x2000;
1768 },
16001769 else => void,
16011770};
16021771
......@@ -1604,7 +1773,8 @@ pub const POLL = switch (native_os) {
16041773pub const PROT = switch (native_os) {
16051774 .linux => linux.PROT,
16061775 .emscripten => emscripten.PROT,
1607 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .windows => struct {
1776 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L28-L31
1777 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd, .windows, .serenity => struct {
16081778 /// page can not be accessed
16091779 pub const NONE = 0x0;
16101780 /// page can be read
......@@ -1719,7 +1889,8 @@ pub const REG = switch (native_os) {
17191889pub const RLIM = switch (native_os) {
17201890 .linux => linux.RLIM,
17211891 .emscripten => emscripten.RLIM,
1722 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
1892 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L52
1893 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .serenity => struct {
17231894 /// No limit
17241895 pub const INFINITY: rlim_t = (1 << 63) - 1;
17251896
......@@ -2174,6 +2345,66 @@ pub const S = switch (native_os) {
21742345 return m & IFMT == IFSOCK;
21752346 }
21762347 },
2348 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/sys/stat.h#L16-L51
2349 .serenity => struct {
2350 pub const IFMT = 0o170000;
2351 pub const IFDIR = 0o040000;
2352 pub const IFCHR = 0o020000;
2353 pub const IFBLK = 0o060000;
2354 pub const IFREG = 0o100000;
2355 pub const IFIFO = 0o010000;
2356 pub const IFLNK = 0o120000;
2357 pub const IFSOCK = 0o140000;
2358
2359 pub const ISUID = 0o4000;
2360 pub const ISGID = 0o2000;
2361 pub const ISVTX = 0o1000;
2362 pub const IRUSR = 0o400;
2363 pub const IWUSR = 0o200;
2364 pub const IXUSR = 0o100;
2365 pub const IREAD = IRUSR;
2366 pub const IWRITE = IWUSR;
2367 pub const IEXEC = IXUSR;
2368 pub const IRGRP = 0o040;
2369 pub const IWGRP = 0o020;
2370 pub const IXGRP = 0o010;
2371 pub const IROTH = 0o004;
2372 pub const IWOTH = 0o002;
2373 pub const IXOTH = 0o001;
2374
2375 pub const IRWXU = IRUSR | IWUSR | IXUSR;
2376
2377 pub const IRWXG = IRWXU >> 3;
2378 pub const IRWXO = IRWXG >> 3;
2379
2380 pub fn ISDIR(m: u32) bool {
2381 return m & IFMT == IFDIR;
2382 }
2383
2384 pub fn ISCHR(m: u32) bool {
2385 return m & IFMT == IFCHR;
2386 }
2387
2388 pub fn ISBLK(m: u32) bool {
2389 return m & IFMT == IFBLK;
2390 }
2391
2392 pub fn ISREG(m: u32) bool {
2393 return m & IFMT == IFREG;
2394 }
2395
2396 pub fn ISFIFO(m: u32) bool {
2397 return m & IFMT == IFIFO;
2398 }
2399
2400 pub fn ISLNK(m: u32) bool {
2401 return m & IFMT == IFLNK;
2402 }
2403
2404 pub fn ISSOCK(m: u32) bool {
2405 return m & IFMT == IFSOCK;
2406 }
2407 },
21772408 else => void,
21782409};
21792410pub const SA = switch (native_os) {
......@@ -2254,6 +2485,18 @@ pub const SA = switch (native_os) {
22542485 pub const NOCLDWAIT = 0x0020;
22552486 pub const SIGINFO = 0x0040;
22562487 },
2488 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L65-L71
2489 .serenity => struct {
2490 pub const NOCLDSTOP = 1;
2491 pub const NOCLDWAIT = 2;
2492 pub const SIGINFO = 4;
2493 pub const ONSTACK = 0x08000000;
2494 pub const RESTART = 0x10000000;
2495 pub const NODEFER = 0x40000000;
2496 pub const RESETHAND = 0x80000000;
2497 pub const NOMASK = NODEFER;
2498 pub const ONESHOT = RESETHAND;
2499 },
22572500 else => void,
22582501};
22592502pub const sigval_t = switch (native_os) {
......@@ -2298,6 +2541,24 @@ pub const _SC = switch (native_os) {
22982541 PAGESIZE = 11,
22992542 NPROCESSORS_ONLN = 15,
23002543 },
2544 // https://github.com/SerenityOS/serenity/blob/1dfc9e2df39dd23f1de92530677c845aae4345f2/Kernel/API/POSIX/unistd.h#L36-L52
2545 .serenity => enum(c_int) {
2546 MONOTONIC_CLOCK = 0,
2547 NPROCESSORS_CONF = 1,
2548 NPROCESSORS_ONLN = 2,
2549 OPEN_MAX = 3,
2550 HOST_NAME_MAX = 4,
2551 TTY_NAME_MAX = 5,
2552 PAGESIZE = 6,
2553 GETPW_R_SIZE_MAX = 7,
2554 GETGR_R_SIZE_MAX = 8,
2555 CLK_TCK = 9,
2556 SYMLOOP_MAX = 10,
2557 MAPPED_FILES = 11,
2558 ARG_MAX = 12,
2559 IOV_MAX = 13,
2560 PHYS_PAGES = 14,
2561 },
23012562 else => void,
23022563};
23032564
......@@ -2309,7 +2570,8 @@ pub const SEEK = switch (native_os) {
23092570 pub const CUR: wasi.whence_t = .CUR;
23102571 pub const END: wasi.whence_t = .END;
23112572 },
2312 .openbsd, .haiku, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .windows => struct {
2573 // https://github.com/SerenityOS/serenity/blob/808ce594db1f2190e5212a250e900bde2ffe710b/Kernel/API/POSIX/stdio.h#L15-L17
2574 .openbsd, .haiku, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .windows, .serenity => struct {
23132575 pub const SET = 0;
23142576 pub const CUR = 1;
23152577 pub const END = 2;
......@@ -2326,6 +2588,7 @@ pub const SEEK = switch (native_os) {
23262588pub const SHUT = switch (native_os) {
23272589 .linux => linux.SHUT,
23282590 .emscripten => emscripten.SHUT,
2591 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L40-L42
23292592 else => struct {
23302593 pub const RD = 0;
23312594 pub const WR = 1;
......@@ -2785,6 +3048,42 @@ pub const SIG = switch (native_os) {
27853048 pub const UNBLOCK = 2;
27863049 pub const SETMASK = 3;
27873050 },
3051 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h
3052 .serenity => struct {
3053 pub const INVAL = 0;
3054 pub const HUP = 1;
3055 pub const INT = 2;
3056 pub const QUIT = 3;
3057 pub const ILL = 4;
3058 pub const TRAP = 5;
3059 pub const ABRT = 6;
3060 pub const BUS = 7;
3061 pub const FPE = 8;
3062 pub const KILL = 9;
3063 pub const USR1 = 10;
3064 pub const SEGV = 11;
3065 pub const USR2 = 12;
3066 pub const PIPE = 13;
3067 pub const ALRM = 14;
3068 pub const TERM = 15;
3069 pub const STKFLT = 16;
3070 pub const CHLD = 17;
3071 pub const CONT = 18;
3072 pub const STOP = 19;
3073 pub const TSTP = 20;
3074 pub const TTIN = 21;
3075 pub const TTOU = 22;
3076 pub const URG = 23;
3077 pub const XCPU = 24;
3078 pub const XFSZ = 25;
3079 pub const VTALRM = 26;
3080 pub const PROF = 27;
3081 pub const WINCH = 28;
3082 pub const IO = 29;
3083 pub const INFO = 30;
3084 pub const SYS = 31;
3085 pub const CANCEL = 32;
3086 },
27883087 else => void,
27893088};
27903089
......@@ -2792,6 +3091,8 @@ pub const SIOCGIFINDEX = switch (native_os) {
27923091 .linux => linux.SIOCGIFINDEX,
27933092 .emscripten => emscripten.SIOCGIFINDEX,
27943093 .solaris, .illumos => solaris.SIOCGLIFINDEX,
3094 // https://github.com/SerenityOS/serenity/blob/cb10f70394fb7e9cfc77f827adb2e46d199bc3a5/Kernel/API/Ioctl.h#L118
3095 .serenity => 34,
27953096 else => void,
27963097};
27973098
......@@ -2936,6 +3237,18 @@ pub const Sigaction = switch (native_os) {
29363237 /// signal options
29373238 flags: c_uint,
29383239 },
3240 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L39-L46
3241 .serenity => extern struct {
3242 pub const handler_fn = *align(1) const fn (c_int) callconv(.c) void;
3243 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.c) void;
3244
3245 handler: extern union {
3246 handler: ?handler_fn,
3247 sigaction: ?sigaction_fn,
3248 },
3249 mask: sigset_t,
3250 flags: c_int,
3251 },
29393252 else => void,
29403253};
29413254pub const T = switch (native_os) {
......@@ -3311,6 +3624,22 @@ pub const T = switch (native_os) {
33113624 pub const IOCGDRAINWAIT = 0x40047456;
33123625 pub const IOCISPTMASTER = 0x20007455;
33133626 },
3627 // https://github.com/SerenityOS/serenity/blob/cb10f70394fb7e9cfc77f827adb2e46d199bc3a5/Kernel/API/Ioctl.h#L84-L96
3628 .serenity => struct {
3629 pub const IOCGPGRP = 0;
3630 pub const IOCSPGRP = 1;
3631 pub const CGETS = 2;
3632 pub const CSETS = 3;
3633 pub const CSETSW = 4;
3634 pub const CSETSF = 5;
3635 pub const CFLSH = 6;
3636 pub const IOCGWINSZ = 7;
3637 pub const IOCSCTTY = 8;
3638 pub const IOCSTI = 9;
3639 pub const IOCNOTTY = 10;
3640 pub const IOCSWINSZ = 11;
3641 pub const IOCGPTN = 12;
3642 },
33143643 else => void,
33153644};
33163645pub const IOCPARM_MASK = switch (native_os) {
......@@ -3546,6 +3875,43 @@ pub const W = switch (native_os) {
35463875 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
35473876 }
35483877 },
3878 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/sys/wait.h
3879 .serenity => struct {
3880 pub const NOHANG = 1;
3881 pub const UNTRACED = 2;
3882 pub const STOPPED = UNTRACED;
3883 pub const EXITED = 4;
3884 pub const CONTINUED = 8;
3885 pub const NOWAIT = 0x1000000;
3886
3887 pub fn EXITSTATUS(s: u32) u8 {
3888 return @intCast((s & 0xff00) >> 8);
3889 }
3890
3891 pub fn STOPSIG(s: u32) u32 {
3892 return EXITSTATUS(s);
3893 }
3894
3895 pub fn TERMSIG(s: u32) u32 {
3896 return s & 0x7f;
3897 }
3898
3899 pub fn IFEXITED(s: u32) bool {
3900 return TERMSIG(s) == 0;
3901 }
3902
3903 pub fn IFSTOPPED(s: u32) bool {
3904 return (s & 0xff) == 0x7f;
3905 }
3906
3907 pub fn IFSIGNALED(s: u32) bool {
3908 return (((s & 0x7f) + 1) >> 1) > 0;
3909 }
3910
3911 pub fn IFCONTINUED(s: u32) bool {
3912 return s == 0xffff;
3913 }
3914 },
35493915 else => void,
35503916};
35513917pub const clock_t = switch (native_os) {
......@@ -3556,6 +3922,8 @@ pub const clock_t = switch (native_os) {
35563922 .openbsd, .solaris, .illumos => i64,
35573923 .netbsd => u32,
35583924 .haiku => i32,
3925 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L50
3926 .serenity => u64,
35593927 else => void,
35603928};
35613929pub const cpu_set_t = switch (native_os) {
......@@ -3568,7 +3936,7 @@ pub const dl_phdr_info = switch (native_os) {
35683936 .emscripten => emscripten.dl_phdr_info,
35693937 .freebsd => extern struct {
35703938 /// Module relocation base.
3571 addr: if (builtin.target.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,
3939 addr: std.elf.Addr,
35723940 /// Module name.
35733941 name: ?[*:0]const u8,
35743942 /// Pointer to module's phdr.
......@@ -3592,11 +3960,12 @@ pub const dl_phdr_info = switch (native_os) {
35923960 /// Incremented when an object is unmapped from the process.
35933961 subs: u64,
35943962 },
3595 .openbsd, .haiku, .dragonfly, .netbsd => extern struct {
3963 // https://github.com/SerenityOS/serenity/blob/45d81dceed81df0c8ef75b440b20cc0938195faa/Userland/Libraries/LibC/link.h#L15-L20
3964 .openbsd, .haiku, .dragonfly, .netbsd, .serenity => extern struct {
35963965 addr: usize,
35973966 name: ?[*:0]const u8,
35983967 phdr: [*]std.elf.Phdr,
3599 phnum: u16,
3968 phnum: std.elf.Half,
36003969 },
36013970 else => void,
36023971};
......@@ -3608,6 +3977,26 @@ pub const ifreq = switch (native_os) {
36083977 .linux => linux.ifreq,
36093978 .emscripten => emscripten.ifreq,
36103979 .solaris, .illumos => lifreq,
3980 // https://github.com/SerenityOS/serenity/blob/9882848e0bf783dfc8e8a6d887a848d70d9c58f4/Kernel/API/POSIX/net/if.h#L49-L82
3981 .serenity => extern struct {
3982 // Not actually in a union, but the stdlib expects one for ifreq
3983 ifrn: extern union {
3984 name: [IFNAMESIZE]u8,
3985 },
3986 ifru: extern union {
3987 addr: sockaddr,
3988 dstaddr: sockaddr,
3989 broadaddr: sockaddr,
3990 netmask: sockaddr,
3991 hwaddr: sockaddr,
3992 flags: c_short,
3993 metric: c_int,
3994 vnetid: i64,
3995 media: u64,
3996 data: ?*anyopaque,
3997 index: c_uint,
3998 },
3999 },
36114000 else => void,
36124001};
36134002pub const itimerspec = switch (native_os) {
......@@ -3650,6 +4039,16 @@ pub const msghdr = switch (native_os) {
36504039 /// flags on received message
36514040 flags: i32,
36524041 },
4042 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L74-L82
4043 .serenity => extern struct {
4044 name: ?*anyopaque,
4045 namelen: socklen_t,
4046 iov: [*]iovec,
4047 iovlen: c_int,
4048 control: ?*anyopaque,
4049 controllen: socklen_t,
4050 flags: c_int,
4051 },
36534052 else => void,
36544053};
36554054pub const msghdr_const = switch (native_os) {
......@@ -3684,6 +4083,15 @@ pub const msghdr_const = switch (native_os) {
36844083 /// flags on received message
36854084 flags: i32,
36864085 },
4086 .serenity => extern struct {
4087 name: ?*const anyopaque,
4088 namelen: socklen_t,
4089 iov: [*]const iovec,
4090 iovlen: c_int,
4091 control: ?*const anyopaque,
4092 controllen: socklen_t,
4093 flags: c_int,
4094 },
36874095 else => void,
36884096};
36894097pub const nfds_t = switch (native_os) {
......@@ -3692,6 +4100,8 @@ pub const nfds_t = switch (native_os) {
36924100 .haiku, .solaris, .illumos, .wasi => usize,
36934101 .windows => c_ulong,
36944102 .openbsd, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => u32,
4103 // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L32
4104 .serenity => c_uint,
36954105 else => void,
36964106};
36974107pub const perf_event_attr = switch (native_os) {
......@@ -3702,12 +4112,20 @@ pub const pid_t = switch (native_os) {
37024112 .linux => linux.pid_t,
37034113 .emscripten => emscripten.pid_t,
37044114 .windows => windows.HANDLE,
4115 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L31-L32
4116 .serenity => c_int,
37054117 else => i32,
37064118};
37074119pub const pollfd = switch (native_os) {
37084120 .linux => linux.pollfd,
37094121 .emscripten => emscripten.pollfd,
37104122 .windows => ws2_32.pollfd,
4123 // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L26-L30
4124 .serenity => extern struct {
4125 fd: fd_t,
4126 events: c_short,
4127 revents: c_short,
4128 },
37114129 else => extern struct {
37124130 fd: fd_t,
37134131 events: i16,
......@@ -3719,11 +4137,14 @@ pub const rlim_t = switch (native_os) {
37194137 .emscripten => emscripten.rlim_t,
37204138 .openbsd, .netbsd, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => u64,
37214139 .haiku, .dragonfly, .freebsd => i64,
4140 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L54
4141 .serenity => usize,
37224142 else => void,
37234143};
37244144pub const rlimit = switch (native_os) {
37254145 .linux, .emscripten => linux.rlimit,
37264146 .windows => void,
4147 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L56-L59
37274148 else => extern struct {
37284149 /// Soft limit
37294150 cur: rlim_t,
......@@ -3825,6 +4246,17 @@ pub const rlimit_resource = switch (native_os) {
38254246 NOVMON = 7,
38264247 _,
38274248 },
4249 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L42-L48
4250 .serenity => enum(c_int) {
4251 CORE = 1,
4252 CPU = 2,
4253 DATA = 3,
4254 FSIZE = 4,
4255 NOFILE = 5,
4256 STACK = 6,
4257 AS = 7,
4258 _,
4259 },
38284260 else => void,
38294261};
38304262pub const rusage = switch (native_os) {
......@@ -3873,6 +4305,28 @@ pub const rusage = switch (native_os) {
38734305 pub const CHILDREN = -1;
38744306 pub const THREAD = 1;
38754307 },
4308 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L18-L38
4309 .serenity => extern struct {
4310 utime: timeval,
4311 stime: timeval,
4312 maxrss: c_long,
4313 ixrss: c_long,
4314 idrss: c_long,
4315 isrss: c_long,
4316 minflt: c_long,
4317 majflt: c_long,
4318 nswap: c_long,
4319 inblock: c_long,
4320 oublock: c_long,
4321 msgsnd: c_long,
4322 msgrcv: c_long,
4323 nsignals: c_long,
4324 nvcsw: c_long,
4325 nivcsw: c_long,
4326
4327 pub const SELF = 1;
4328 pub const CHILDREN = 2;
4329 },
38764330 else => void,
38774331};
38784332
......@@ -4050,12 +4504,25 @@ pub const siginfo_t = switch (native_os) {
40504504 assert(@sizeOf(@This()) == 136);
40514505 }
40524506 },
4507 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L27-L37
4508 .serenity => extern struct {
4509 signo: c_int,
4510 code: c_int,
4511 errno: c_int,
4512 pid: pid_t,
4513 uid: uid_t,
4514 addr: ?*anyopaque,
4515 status: c_int,
4516 band: c_int,
4517 value: sigval,
4518 },
40534519 else => void,
40544520};
40554521pub const sigset_t = switch (native_os) {
40564522 .linux => linux.sigset_t,
40574523 .emscripten => emscripten.sigset_t,
4058 .openbsd, .macos, .ios, .tvos, .watchos, .visionos => u32,
4524 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L19
4525 .openbsd, .macos, .ios, .tvos, .watchos, .visionos, .serenity => u32,
40594526 .dragonfly, .netbsd, .solaris, .illumos, .freebsd => extern struct {
40604527 __bits: [SIG.WORDS]u32,
40614528 },
......@@ -4075,7 +4542,8 @@ pub const filled_sigset = switch (native_os) {
40754542};
40764543pub const sigval = switch (native_os) {
40774544 .linux => linux.sigval,
4078 .openbsd, .dragonfly, .freebsd => extern union {
4545 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L22-L25
4546 .openbsd, .dragonfly, .freebsd, .serenity => extern union {
40794547 int: c_int,
40804548 ptr: ?*anyopaque,
40814549 },
......@@ -4144,7 +4612,8 @@ pub const addrinfo = if (builtin.abi.isAndroid()) extern struct {
41444612 addr: ?*sockaddr,
41454613 next: ?*addrinfo,
41464614 },
4147 .openbsd => extern struct {
4615 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L66-L75
4616 .openbsd, .serenity => extern struct {
41484617 flags: AI,
41494618 family: c_int,
41504619 socktype: c_int,
......@@ -4460,11 +4929,41 @@ pub const sockaddr = switch (native_os) {
44604929 path: [104]u8,
44614930 };
44624931 },
4932 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L110-L114
4933 .serenity => extern struct {
4934 family: sa_family_t,
4935 data: [26]u8,
4936
4937 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/netinet/in.h
4938 const in_addr = u32;
4939 const in6_addr = [16]u8;
4940 pub const in = extern struct {
4941 family: sa_family_t = AF.INET,
4942 port: in_port_t,
4943 addr: in_addr,
4944 zero: [8]u8 = @splat(0),
4945 };
4946 pub const in6 = extern struct {
4947 family: sa_family_t = AF.INET6,
4948 port: in_port_t,
4949 flowinfo: u32,
4950 addr: in6_addr,
4951 scope_id: u32,
4952 };
4953
4954 // https://github.com/SerenityOS/serenity/blob/b92e6b02e53b2927732f31b1442cad420b62d1ef/Kernel/API/POSIX/sys/un.h
4955 const UNIX_PATH_MAX = 108;
4956 pub const un = extern struct {
4957 family: sa_family_t = AF.LOCAL,
4958 path: [UNIX_PATH_MAX]u8,
4959 };
4960 },
44634961 else => void,
44644962};
44654963pub const socklen_t = switch (native_os) {
44664964 .linux, .emscripten => linux.socklen_t,
44674965 .windows => ws2_32.socklen_t,
4966 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L57
44684967 else => u32,
44694968};
44704969pub const in_port_t = u16;
......@@ -4472,7 +4971,8 @@ pub const sa_family_t = switch (native_os) {
44724971 .linux, .emscripten => linux.sa_family_t,
44734972 .windows => ws2_32.ADDRESS_FAMILY,
44744973 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => u8,
4475 .solaris, .illumos => u16,
4974 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L66
4975 .solaris, .illumos, .serenity => u16,
44764976 else => void,
44774977};
44784978pub const AF = if (builtin.abi.isAndroid()) struct {
......@@ -4751,6 +5251,15 @@ pub const AF = if (builtin.abi.isAndroid()) struct {
47515251 pub const ISDN = 26;
47525252 pub const MAX = 36;
47535253 },
5254 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L17-L22
5255 .serenity => struct {
5256 pub const UNSPEC = 0;
5257 pub const LOCAL = 1;
5258 pub const UNIX = LOCAL;
5259 pub const INET = 2;
5260 pub const INET6 = 3;
5261 pub const MAX = 4;
5262 },
47545263 else => void,
47555264};
47565265pub const PF = if (builtin.abi.isAndroid()) struct {
......@@ -5020,11 +5529,21 @@ pub const PF = if (builtin.abi.isAndroid()) struct {
50205529 pub const ISDN = AF.ISDN;
50215530 pub const MAX = AF.MAX;
50225531 },
5532 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L24-L29
5533 .serenity => struct {
5534 pub const LOCAL = AF.LOCAL;
5535 pub const UNIX = AF.LOCAL;
5536 pub const INET = AF.INET;
5537 pub const INET6 = AF.INET6;
5538 pub const UNSPEC = AF.UNSPEC;
5539 pub const MAX = AF.MAX;
5540 },
50235541 else => void,
50245542};
50255543pub const DT = switch (native_os) {
50265544 .linux => linux.DT,
5027 .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => struct {
5545 // https://github.com/SerenityOS/serenity/blob/1262a7d1424d0d2e89d80644409721cbf056ab17/Kernel/API/POSIX/dirent.h#L16-L35
5546 .netbsd, .freebsd, .openbsd, .macos, .ios, .tvos, .watchos, .visionos, .serenity => struct {
50285547 pub const UNKNOWN = 0;
50295548 pub const FIFO = 1;
50305549 pub const CHR = 2;
......@@ -5047,17 +5566,6 @@ pub const DT = switch (native_os) {
50475566 pub const WHT = 14;
50485567 pub const DBF = 15;
50495568 },
5050 .openbsd => struct {
5051 pub const UNKNOWN = 0;
5052 pub const FIFO = 1;
5053 pub const CHR = 2;
5054 pub const DIR = 4;
5055 pub const BLK = 6;
5056 pub const REG = 8;
5057 pub const LNK = 10;
5058 pub const SOCK = 12;
5059 pub const WHT = 14; // XXX
5060 },
50615569 else => void,
50625570};
50635571pub const MSG = switch (native_os) {
......@@ -5078,6 +5586,18 @@ pub const MSG = switch (native_os) {
50785586 pub const EOF = 0x0400;
50795587 pub const NOSIGNAL = 0x0800;
50805588 },
5589 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L56-L64
5590 .serenity => struct {
5591 pub const TRUNC = 0x1;
5592 pub const CTRUNC = 0x2;
5593 pub const PEEK = 0x4;
5594 pub const OOB = 0x8;
5595 pub const DONTROUTE = 0x10;
5596 pub const WAITALL = 0x20;
5597 pub const DONTWAIT = 0x40;
5598 pub const NOSIGNAL = 0x80;
5599 pub const EOR = 0x100;
5600 },
50815601 else => void,
50825602};
50835603pub const SOCK = switch (native_os) {
......@@ -5168,6 +5688,17 @@ pub const SOCK = switch (native_os) {
51685688 pub const CLOEXEC = 0x8000;
51695689 pub const NONBLOCK = 0x4000;
51705690 },
5691 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L31-L38
5692 .serenity => struct {
5693 pub const STREAM = 1;
5694 pub const DGRAM = 2;
5695 pub const RAW = 3;
5696 pub const RDM = 4;
5697 pub const SEQPACKET = 5;
5698
5699 pub const NONBLOCK = 0o4000;
5700 pub const CLOEXEC = 0o2000000;
5701 },
51715702 else => void,
51725703};
51735704pub const TCP = switch (native_os) {
......@@ -5175,6 +5706,11 @@ pub const TCP = switch (native_os) {
51755706 .linux => linux.TCP,
51765707 .emscripten => emscripten.TCP,
51775708 .windows => ws2_32.TCP,
5709 // https://github.com/SerenityOS/serenity/blob/61ac554a3403838f79ca746bd1c65ded6f97d124/Kernel/API/POSIX/netinet/tcp.h#L13-L14
5710 .serenity => struct {
5711 pub const NODELAY = 10;
5712 pub const MAXSEG = 11;
5713 },
51785714 else => void,
51795715};
51805716pub const IPPROTO = switch (native_os) {
......@@ -5759,6 +6295,20 @@ pub const IPPROTO = switch (native_os) {
57596295 /// raw IP packet
57606296 pub const RAW = 255;
57616297 },
6298 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L44-L54
6299 .serenity => struct {
6300 pub const IP = 0;
6301 pub const ICMP = 1;
6302 pub const IGMP = 2;
6303 pub const IPIP = 4;
6304 pub const TCP = 6;
6305 pub const UDP = 17;
6306 pub const IPV6 = 41;
6307 pub const ESP = 50;
6308 pub const AH = 51;
6309 pub const ICMPV6 = 58;
6310 pub const RAW = 255;
6311 },
57626312 else => void,
57636313};
57646314pub const SOL = switch (native_os) {
......@@ -5774,6 +6324,10 @@ pub const SOL = switch (native_os) {
57746324 pub const PACKET = 0xfffd;
57756325 pub const FILTER = 0xfffc;
57766326 },
6327 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L127
6328 .serenity => struct {
6329 pub const SOCKET = 1;
6330 },
57776331 else => void,
57786332};
57796333pub const SO = switch (native_os) {
......@@ -5991,12 +6545,35 @@ pub const SO = switch (native_os) {
59916545 pub const DOMAIN = 0x1024;
59926546 pub const PROTOCOL = 0x1025;
59936547 },
6548 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L130-L150
6549 .serenity => struct {
6550 pub const RCVTIMEO = 0;
6551 pub const SNDTIMEO = 1;
6552 pub const TYPE = 2;
6553 pub const ERROR = 3;
6554 pub const PEERCRED = 4;
6555 pub const RCVBUF = 5;
6556 pub const SNDBUF = 6;
6557 pub const DEBUG = 7;
6558 pub const REUSEADDR = 8;
6559 pub const BINDTODEVICE = 9;
6560 pub const KEEPALIVE = 10;
6561 pub const TIMESTAMP = 11;
6562 pub const BROADCAST = 12;
6563 pub const LINGER = 13;
6564 pub const ACCEPTCONN = 14;
6565 pub const DONTROUTE = 15;
6566 pub const OOBINLINE = 16;
6567 pub const SNDLOWAT = 17;
6568 pub const RCVLOWAT = 18;
6569 },
59946570 else => void,
59956571};
59966572pub const SOMAXCONN = switch (native_os) {
59976573 .linux => linux.SOMAXCONN,
59986574 .windows => ws2_32.SOMAXCONN,
5999 .solaris, .illumos => 128,
6575 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L128
6576 .solaris, .illumos, .serenity => 128,
60006577 .openbsd => 28,
60016578 else => void,
60026579};
......@@ -6004,7 +6581,8 @@ pub const IFNAMESIZE = switch (native_os) {
60046581 .linux => linux.IFNAMESIZE,
60056582 .emscripten => emscripten.IFNAMESIZE,
60066583 .windows => 30,
6007 .openbsd, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => 16,
6584 // https://github.com/SerenityOS/serenity/blob/9882848e0bf783dfc8e8a6d887a848d70d9c58f4/Kernel/API/POSIX/net/if.h#L50
6585 .openbsd, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos, .serenity => 16,
60086586 .solaris, .illumos => 32,
60096587 else => void,
60106588};
......@@ -6020,6 +6598,12 @@ pub const stack_t = switch (native_os) {
60206598 /// SS_DISABLE and/or SS_ONSTACK.
60216599 flags: i32,
60226600 },
6601 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L48-L52
6602 .serenity => extern struct {
6603 sp: *anyopaque,
6604 flags: c_int,
6605 size: usize,
6606 },
60236607 else => extern struct {
60246608 sp: [*]u8,
60256609 size: isize,
......@@ -6030,10 +6614,12 @@ pub const time_t = switch (native_os) {
60306614 .linux => linux.time_t,
60316615 .emscripten => emscripten.time_t,
60326616 .haiku, .dragonfly => isize,
6617 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47
60336618 else => i64,
60346619};
60356620pub const suseconds_t = switch (native_os) {
6036 .solaris, .illumos => i64,
6621 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L49
6622 .solaris, .illumos, .serenity => i64,
60376623 .freebsd, .dragonfly => c_long,
60386624 .netbsd => c_int,
60396625 .haiku => i32,
......@@ -6051,7 +6637,8 @@ pub const timeval = switch (native_os) {
60516637 sec: c_long,
60526638 usec: i32,
60536639 },
6054 .dragonfly, .netbsd, .freebsd, .solaris, .illumos => extern struct {
6640 // https://github.com/SerenityOS/serenity/blob/6b6eca0631c893c5f8cfb8274cdfe18e2d0637c0/Kernel/API/POSIX/sys/time.h#L15-L18
6641 .dragonfly, .netbsd, .freebsd, .solaris, .illumos, .serenity => extern struct {
60556642 /// seconds
60566643 sec: time_t,
60576644 /// microseconds
......@@ -6070,6 +6657,11 @@ pub const timezone = switch (native_os) {
60706657 minuteswest: i32,
60716658 dsttime: i32,
60726659 },
6660 // https://github.com/SerenityOS/serenity/blob/ba776390b5878ec0be1a9e595a3471a6cfe0a0cf/Userland/Libraries/LibC/sys/time.h#L19-L22
6661 .serenity => extern struct {
6662 minuteswest: c_int,
6663 dsttime: c_int,
6664 },
60736665 else => void,
60746666};
60756667
......@@ -6127,7 +6719,8 @@ pub const ucontext_t = switch (native_os) {
61276719 arg: ?*void,
61286720 _spare: [4]c_int,
61296721 },
6130 .haiku => extern struct {
6722 // https://github.com/SerenityOS/serenity/blob/87eac0e424cff4a1f941fb704b9362a08654c24d/Kernel/API/POSIX/ucontext.h#L19-L24
6723 .haiku, .serenity => extern struct {
61316724 link: ?*ucontext_t,
61326725 sigmask: sigset_t,
61336726 stack: stack_t,
......@@ -6222,6 +6815,47 @@ pub const mcontext_t = switch (native_os) {
62226815 },
62236816 .dragonfly => dragonfly.mcontext_t,
62246817 .haiku => haiku.mcontext_t,
6818 .serenity => switch (native_arch) {
6819 // https://github.com/SerenityOS/serenity/blob/200e91cd7f1ec5453799a2720d4dc114a59cc289/Kernel/Arch/aarch64/mcontext.h#L15-L19
6820 .aarch64 => extern struct {
6821 x: [31]u64,
6822 sp: u64,
6823 pc: u64,
6824 },
6825 // https://github.com/SerenityOS/serenity/blob/66f8d0f031ef25c409dbb4fecaa454800fecae0f/Kernel/Arch/riscv64/mcontext.h#L15-L18
6826 .riscv64 => extern struct {
6827 x: [31]u64,
6828 pc: u64,
6829 },
6830 // https://github.com/SerenityOS/serenity/blob/7b9ea3efdec9f86a1042893e8107d0b23aad8727/Kernel/Arch/x86_64/mcontext.h#L15-L40
6831 .x86_64 => extern struct {
6832 rax: u64,
6833 rcx: u64,
6834 rdx: u64,
6835 rbx: u64,
6836 rsp: u64,
6837 rbp: u64,
6838 rsi: u64,
6839 rdi: u64,
6840 rip: u64,
6841 r8: u64,
6842 r9: u64,
6843 r10: u64,
6844 r11: u64,
6845 r12: u64,
6846 r13: u64,
6847 r14: u64,
6848 r15: u64,
6849 rflags: u64,
6850 cs: u32,
6851 ss: u32,
6852 ds: u32,
6853 es: u32,
6854 fs: u32,
6855 gs: u32,
6856 },
6857 else => struct {},
6858 },
62256859 else => void,
62266860};
62276861
......@@ -6247,6 +6881,16 @@ pub const utsname = switch (native_os) {
62476881 version: [256:0]u8,
62486882 machine: [256:0]u8,
62496883 },
6884 // https://github.com/SerenityOS/serenity/blob/d794ed1de7a46482272683f8dc4c858806390f29/Kernel/API/POSIX/sys/utsname.h#L17-L23
6885 .serenity => extern struct {
6886 sysname: [UTSNAME_ENTRY_LEN:0]u8,
6887 nodename: [UTSNAME_ENTRY_LEN:0]u8,
6888 release: [UTSNAME_ENTRY_LEN:0]u8,
6889 version: [UTSNAME_ENTRY_LEN:0]u8,
6890 machine: [UTSNAME_ENTRY_LEN:0]u8,
6891
6892 const UTSNAME_ENTRY_LEN = 65;
6893 },
62506894 else => void,
62516895};
62526896pub const PR = switch (native_os) {
......@@ -6265,6 +6909,8 @@ pub const _errno = switch (native_os) {
62656909 .solaris, .illumos => private.___errno,
62666910 .openbsd, .netbsd => private.__errno,
62676911 .haiku => haiku._errnop,
6912 // https://github.com/SerenityOS/serenity/blob/a353ceecf13b6f156a078e32f1ddf1d21366934c/Userland/Libraries/LibC/errno.h#L33
6913 .serenity => private.__errno_location,
62686914 else => {},
62696915};
62706916
......@@ -6340,6 +6986,16 @@ pub const RTLD = switch (native_os) {
63406986 FIRST: bool = false,
63416987 _: u23 = 0,
63426988 },
6989 // https://github.com/SerenityOS/serenity/blob/36a26d7fa80bc9c72b19442912d8967f448368ff/Userland/Libraries/LibC/dlfcn.h#L13-L17
6990 .serenity => packed struct(c_int) {
6991 DEFAULT: bool = false,
6992 _1: u1,
6993 LAZY: bool = false,
6994 NOW: bool = false,
6995 GLOBAL: bool = false,
6996 LOCAL: bool = false,
6997 _: std.meta.Int(.unsigned, @bitSizeOf(c_int) - 6) = 0,
6998 },
63436999 else => void,
63447000};
63457001
......@@ -6413,11 +7069,20 @@ pub const dirent = switch (native_os) {
64137069 _: u32 align(1) = 0,
64147070 name: [MAXNAMLEN:0]u8,
64157071 },
7072 // https://github.com/SerenityOS/serenity/blob/abc150085f532f123b598949218893cb272ccc4c/Userland/Libraries/LibC/dirent.h#L14-L20
7073 .serenity => extern struct {
7074 ino: ino_t,
7075 off: off_t,
7076 reclen: c_ushort,
7077 type: u8,
7078 name: [256:0]u8,
7079 },
64167080 else => void,
64177081};
64187082pub const MAXNAMLEN = switch (native_os) {
64197083 .netbsd, .solaris, .illumos => 511,
6420 .haiku => NAME_MAX,
7084 // https://github.com/SerenityOS/serenity/blob/1262a7d1424d0d2e89d80644409721cbf056ab17/Kernel/API/POSIX/dirent.h#L37
7085 .haiku, .serenity => NAME_MAX,
64217086 .openbsd => 255,
64227087 else => {},
64237088};
......@@ -6499,6 +7164,17 @@ pub const AI = if (builtin.abi.isAndroid()) packed struct(u32) {
64997164 _: u19 = 0,
65007165 },
65017166 .windows => ws2_32.AI,
7167 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L90-L96
7168 .serenity => packed struct(c_int) {
7169 PASSIVE: bool = false,
7170 CANONNAME: bool = false,
7171 NUMERICHOST: bool = false,
7172 NUMERICSERV: bool = false,
7173 V4MAPPED: bool = false,
7174 ALL: bool = false,
7175 ADDRCONFIG: bool = false,
7176 _: std.meta.Int(.unsigned, @bitSizeOf(c_int) - 7) = 0,
7177 },
65027178 else => void,
65037179};
65047180
......@@ -6523,6 +7199,15 @@ pub const NI = switch (native_os) {
65237199 NUMERICSCOPE: bool = false,
65247200 _: u25 = 0,
65257201 },
7202 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L101-L105
7203 .serenity => packed struct(c_int) {
7204 NUMERICHOST: bool = false,
7205 NUMERICSERV: bool = false,
7206 NAMEREQD: bool = false,
7207 NOFQDN: bool = false,
7208 DGRAM: bool = false,
7209 _: std.meta.Int(.unsigned, @bitSizeOf(c_int) - 5) = 0,
7210 },
65267211 else => void,
65277212};
65287213
......@@ -6675,6 +7360,22 @@ pub const EAI = if (builtin.abi.isAndroid()) enum(c_int) {
66757360 OVERFLOW = -14,
66767361 _,
66777362 },
7363 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L77-L88
7364 .serenity => enum(c_int) {
7365 ADDRFAMILY = 1,
7366 AGAIN = 2,
7367 BADFLAGS = 3,
7368 FAIL = 4,
7369 FAMILY = 5,
7370 MEMORY = 6,
7371 NODATA = 7,
7372 NONAME = 8,
7373 SERVICE = 9,
7374 SOCKTYPE = 10,
7375 SYSTEM = 11,
7376 OVERFLOW = 12,
7377 _,
7378 },
66787379 else => void,
66797380};
66807381
......@@ -7097,6 +7798,34 @@ pub const Stat = switch (native_os) {
70977798 return self.birthtim;
70987799 }
70997800 },
7801 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/sys/stat.h#L53-L67
7802 .serenity => extern struct {
7803 dev: dev_t,
7804 ino: ino_t,
7805 mode: mode_t,
7806 nlink: nlink_t,
7807 uid: uid_t,
7808 gid: gid_t,
7809 rdev: dev_t,
7810 size: off_t,
7811 blksize: blksize_t,
7812 blocks: blkcnt_t,
7813 atim: timespec,
7814 mtim: timespec,
7815 ctim: timespec,
7816
7817 pub fn atime(self: @This()) timespec {
7818 return self.atim;
7819 }
7820
7821 pub fn mtime(self: @This()) timespec {
7822 return self.mtim;
7823 }
7824
7825 pub fn ctime(self: @This()) timespec {
7826 return self.ctim;
7827 }
7828 },
71007829 else => void,
71017830};
71027831
......@@ -7159,6 +7888,13 @@ pub const pthread_mutex_t = switch (native_os) {
71597888 .emscripten => extern struct {
71607889 data: [24]u8 align(4) = [_]u8{0} ** 24,
71617890 },
7891 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L68-L73
7892 .serenity => extern struct {
7893 lock: u32 = 0,
7894 owner: pthread_t = 0,
7895 level: c_int = 0,
7896 type: c_int = 0,
7897 },
71627898 else => void,
71637899};
71647900
......@@ -7201,6 +7937,12 @@ pub const pthread_cond_t = switch (native_os) {
72017937 .fuchsia, .emscripten => extern struct {
72027938 data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48,
72037939 },
7940 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L80-L84
7941 .serenity => extern struct {
7942 mutex: ?*pthread_mutex_t = null,
7943 value: u32 = 0,
7944 clockid: clockid_t = .REALTIME_COARSE,
7945 },
72047946 else => void,
72057947};
72067948
......@@ -7258,6 +8000,10 @@ pub const pthread_rwlock_t = switch (native_os) {
72588000 .emscripten => extern struct {
72598001 size: [32]u8 align(4) = [_]u8{0} ** 32,
72608002 },
8003 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86
8004 .serenity => extern struct {
8005 inner: u64 = 0,
8006 },
72618007 else => void,
72628008};
72638009
......@@ -7270,7 +8016,8 @@ pub const pthread_attr_t = switch (native_os) {
72708016 __sig: c_long,
72718017 __opaque: [56]u8,
72728018 },
7273 .freebsd => extern struct {
8019 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L75
8020 .freebsd, .openbsd, .serenity => extern struct {
72748021 inner: ?*anyopaque = null,
72758022 },
72768023 .solaris, .illumos => extern struct {
......@@ -7288,16 +8035,14 @@ pub const pthread_attr_t = switch (native_os) {
72888035 guard_size: i32,
72898036 stack_address: ?*anyopaque,
72908037 },
7291 .openbsd => extern struct {
7292 inner: ?*anyopaque = null,
7293 },
72948038 else => void,
72958039};
72968040
72978041pub const pthread_key_t = switch (native_os) {
72988042 .linux, .emscripten => c_uint,
72998043 .macos, .ios, .tvos, .watchos, .visionos => c_ulong,
7300 .openbsd, .solaris, .illumos => c_int,
8044 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L65
8045 .openbsd, .solaris, .illumos, .serenity => c_int,
73018046 else => void,
73028047};
73038048
......@@ -7353,6 +8098,12 @@ pub const sem_t = switch (native_os) {
73538098 },
73548099 padding: [2]i32,
73558100 },
8101 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/semaphore.h#L23-L27
8102 .serenity => extern struct {
8103 magic: u32,
8104 value: u32,
8105 flags: u8,
8106 },
73568107 else => void,
73578108};
73588109
......@@ -7556,6 +8307,13 @@ pub const AT = switch (native_os) {
75568307 /// file.
75578308 pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3;
75588309 },
8310 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L49-L52
8311 .serenity => struct {
8312 pub const FDCWD = -100;
8313 pub const SYMLINK_NOFOLLOW = 0x100;
8314 pub const REMOVEDIR = 0x200;
8315 pub const EACCESS = 0x400;
8316 },
75598317 else => void,
75608318};
75618319
......@@ -7771,6 +8529,23 @@ pub const O = switch (native_os) {
77718529 TMPFILE: bool = false,
77728530 _: u9 = 0,
77738531 },
8532 // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L28-L43
8533 .serenity => packed struct(c_int) {
8534 ACCMODE: std.posix.ACCMODE = .RDONLY,
8535 EXEC: bool = false,
8536 CREAT: bool = false,
8537 EXCL: bool = false,
8538 NOCTTY: bool = false,
8539 TRUNC: bool = false,
8540 APPEND: bool = false,
8541 NONBLOCK: bool = false,
8542 DIRECTORY: bool = false,
8543 NOFOLLOW: bool = false,
8544 CLOEXEC: bool = false,
8545 DIRECT: bool = false,
8546 SYNC: bool = false,
8547 _: std.meta.Int(.unsigned, @bitSizeOf(c_int) - 14) = 0,
8548 },
77748549 else => void,
77758550};
77768551
......@@ -7910,6 +8685,21 @@ pub const MAP = switch (native_os) {
79108685 @"32BIT": bool = false,
79118686 _: u12 = 0,
79128687 },
8688 // https://github.com/SerenityOS/serenity/blob/6d59d4d3d9e76e39112842ec487840828f1c9bfe/Kernel/API/POSIX/sys/mman.h#L16-L26
8689 .serenity => packed struct(c_int) {
8690 FILE: bool = false,
8691 SHARED: bool = false,
8692 PRIVATE: bool = false,
8693 _3: u2 = 0,
8694 FIXED: bool = false,
8695 ANONYMOUS: bool = false,
8696 STACK: bool = false,
8697 NORESERVE: bool = false,
8698 RANDOMIZED: bool = false,
8699 PURGEABLE: bool = false,
8700 FIXED_NOREPLACE: bool = false,
8701 _: std.meta.Int(.unsigned, @bitSizeOf(c_int) - 12) = 0,
8702 },
79138703 else => void,
79148704};
79158705
......@@ -8020,6 +8810,27 @@ pub const V = switch (native_os) {
80208810 LNEXT,
80218811 EOL2,
80228812 },
8813 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L32-L49
8814 .serenity => enum {
8815 INTR,
8816 QUIT,
8817 ERASE,
8818 KILL,
8819 EOF,
8820 TIME,
8821 MIN,
8822 SWTC,
8823 START,
8824 STOP,
8825 SUSP,
8826 EOL,
8827 REPRINT,
8828 DISCARD,
8829 WERASE,
8830 LNEXT,
8831 EOL2,
8832 INFO,
8833 },
80238834 else => void,
80248835};
80258836
......@@ -8028,7 +8839,8 @@ pub const NCCS = switch (native_os) {
80288839 .macos, .ios, .tvos, .watchos, .visionos, .freebsd, .netbsd, .openbsd, .dragonfly => 20,
80298840 .haiku => 11,
80308841 .solaris, .illumos => 19,
8031 .emscripten, .wasi => 32,
8842 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L15
8843 .emscripten, .wasi, .serenity => 32,
80328844 else => void,
80338845};
80348846
......@@ -8043,7 +8855,8 @@ pub const termios = switch (native_os) {
80438855 ispeed: speed_t align(8),
80448856 ospeed: speed_t,
80458857 },
8046 .freebsd, .netbsd, .dragonfly, .openbsd => extern struct {
8858 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L21-L29
8859 .freebsd, .netbsd, .dragonfly, .openbsd, .serenity => extern struct {
80478860 iflag: tc_iflag_t,
80488861 oflag: tc_oflag_t,
80498862 cflag: tc_cflag_t,
......@@ -8171,7 +8984,8 @@ pub const tc_iflag_t = switch (native_os) {
81718984 DOSMODE: bool = false,
81728985 _: u16 = 0,
81738986 },
8174 .emscripten, .wasi => packed struct(u32) {
8987 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L52-L66
8988 .emscripten, .wasi, .serenity => packed struct(u32) {
81758989 IGNBRK: bool = false,
81768990 BRKINT: bool = false,
81778991 IGNPAR: bool = false,
......@@ -8263,7 +9077,8 @@ pub const tc_oflag_t = switch (native_os) {
82639077 WRAP: bool = false,
82649078 _: u14 = 0,
82659079 },
8266 .haiku, .wasi, .emscripten => packed struct(u32) {
9080 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L69-L97
9081 .haiku, .wasi, .emscripten, .serenity => packed struct(u32) {
82679082 OPOST: bool = false,
82689083 OLCUC: bool = false,
82699084 ONLCR: bool = false,
......@@ -8422,6 +9237,19 @@ pub const tc_cflag_t = switch (native_os) {
84229237 CLOCAL: bool = false,
84239238 _: u20 = 0,
84249239 },
9240 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L131-L141
9241 .serenity => packed struct(u32) {
9242 _0: u4 = 0,
9243 CSIZE: CSIZE = .CS5,
9244 CSTOPB: bool = false,
9245 CREAD: bool = false,
9246 PARENB: bool = false,
9247 PARODD: bool = false,
9248 HUPCL: bool = false,
9249 CLOCAL: bool = false,
9250 CBAUDEX: bool = false,
9251 _: u19 = 0,
9252 },
84259253 else => void,
84269254};
84279255
......@@ -8548,6 +9376,27 @@ pub const tc_lflag_t = switch (native_os) {
85489376 IEXTEN: bool = false,
85499377 _: u16 = 0,
85509378 },
9379 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L168-L189
9380 .serenity => packed struct(u32) {
9381 ISIG: bool = false,
9382 ICANON: bool = false,
9383 XCASE: bool = false,
9384 ECHO: bool = false,
9385 ECHOE: bool = false,
9386 ECHOK: bool = false,
9387 ECHONL: bool = false,
9388 NOFLSH: bool = false,
9389 TOSTOP: bool = false,
9390 ECHOCTL: bool = false,
9391 ECHOPRT: bool = false,
9392 ECHOKE: bool = false,
9393 FLUSHO: bool = false,
9394 PENDIN: bool = false,
9395 _14: u6 = 0,
9396 IEXTEN: bool = false,
9397 EXTPROC: bool = false,
9398 _: u15 = 0,
9399 },
85519400 else => void,
85529401};
85539402
......@@ -8696,7 +9545,8 @@ pub const speed_t = switch (native_os) {
86969545 B3500000 = 30,
86979546 B4000000 = 31,
86989547 },
8699 .emscripten, .wasi => enum(u32) {
9548 // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L111-L159
9549 .emscripten, .wasi, .serenity => enum(u32) {
87009550 B0 = 0o0000000,
87019551 B50 = 0o0000001,
87029552 B75 = 0o0000002,
......@@ -8735,7 +9585,11 @@ pub const speed_t = switch (native_os) {
87359585
87369586pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;
87379587
8738pub const sig_atomic_t = c_int;
9588pub const sig_atomic_t = switch (native_os) {
9589 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L20
9590 .serenity => u32,
9591 else => c_int,
9592};
87399593
87409594/// maximum signal number + 1
87419595pub const NSIG = switch (native_os) {
......@@ -8744,7 +9598,8 @@ pub const NSIG = switch (native_os) {
87449598 .haiku => 65,
87459599 .netbsd, .freebsd => 32,
87469600 .solaris, .illumos => 75,
8747 .openbsd => 33,
9601 // https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h#L42
9602 .openbsd, .serenity => 33,
87489603 else => {},
87499604};
87509605
......@@ -8758,6 +9613,8 @@ pub const MINSIGSTKSZ = switch (native_os) {
87589613 .solaris, .illumos => 2048,
87599614 .haiku, .netbsd => 8192,
87609615 .openbsd => 1 << openbsd.MAX_PAGE_SHIFT,
9616 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L58
9617 .serenity => 4096,
87619618 else => {},
87629619};
87639620pub const SIGSTKSZ = switch (native_os) {
......@@ -8766,6 +9623,8 @@ pub const SIGSTKSZ = switch (native_os) {
87669623 .solaris, .illumos => 8192,
87679624 .haiku => 16384,
87689625 .openbsd => MINSIGSTKSZ + (1 << openbsd.MAX_PAGE_SHIFT) * 4,
9626 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L59
9627 .serenity => 32768,
87699628 else => {},
87709629};
87719630pub const SS = switch (native_os) {
......@@ -8774,7 +9633,8 @@ pub const SS = switch (native_os) {
87749633 pub const ONSTACK = 1;
87759634 pub const DISABLE = 4;
87769635 },
8777 .haiku, .solaris, .illumos => struct {
9636 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L54-L55
9637 .haiku, .solaris, .illumos, .serenity => struct {
87789638 pub const ONSTACK = 0x1;
87799639 pub const DISABLE = 0x2;
87809640 },
......@@ -9267,6 +10127,12 @@ pub const NOTE = switch (native_os) {
926710127 else => void,
926810128};
926910129
10130pub const FUTEX = switch (native_os) {
10131 .openbsd => openbsd.FUTEX,
10132 .serenity => serenity.FUTEX,
10133 else => void,
10134};
10135
927010136// Unix-like systems
927110137pub const DIR = opaque {};
927210138pub extern "c" fn opendir(pathname: [*:0]const u8) ?*DIR;
......@@ -9327,7 +10193,7 @@ pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: us
932710193pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int;
932810194
932910195pub const arc4random_buf = switch (native_os) {
9330 .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .macos, .ios, .tvos, .watchos, .visionos => private.arc4random_buf,
10196 .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .macos, .ios, .tvos, .watchos, .visionos, .serenity => private.arc4random_buf,
933110197 else => {},
933210198};
933310199pub const getentropy = switch (native_os) {
......@@ -9395,7 +10261,7 @@ pub const sigaltstack = switch (native_os) {
939510261
939610262pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
939710263pub const pipe2 = switch (native_os) {
9398 .dragonfly, .emscripten, .netbsd, .freebsd, .solaris, .illumos, .openbsd, .linux => private.pipe2,
10264 .dragonfly, .emscripten, .netbsd, .freebsd, .solaris, .illumos, .openbsd, .linux, .serenity => private.pipe2,
939910265 else => {},
940010266};
940110267pub const copy_file_range = switch (native_os) {
......@@ -9501,15 +10367,15 @@ pub const _msize = switch (native_os) {
950110367 else => {},
950210368};
950310369pub const malloc_size = switch (native_os) {
9504 .macos, .ios, .tvos, .watchos, .visionos => private.malloc_size,
10370 .macos, .ios, .tvos, .watchos, .visionos, .serenity => private.malloc_size,
950510371 else => {},
950610372};
950710373pub const malloc_usable_size = switch (native_os) {
9508 .freebsd, .linux => private.malloc_usable_size,
10374 .freebsd, .linux, .serenity => private.malloc_usable_size,
950910375 else => {},
951010376};
951110377pub const posix_memalign = switch (native_os) {
9512 .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos => private.posix_memalign,
10378 .dragonfly, .netbsd, .freebsd, .solaris, .openbsd, .linux, .macos, .ios, .tvos, .watchos, .visionos, .serenity => private.posix_memalign,
951310379 else => {},
951410380};
951510381pub const sysconf = switch (native_os) {
......@@ -9532,6 +10398,12 @@ pub const flock = switch (native_os) {
953210398 else => private.flock,
953310399};
953410400
10401pub const futex = switch (native_os) {
10402 .openbsd => openbsd.futex,
10403 .serenity => serenity.futex,
10404 else => {},
10405};
10406
953510407pub extern "c" var environ: [*:null]?[*:0]u8;
953610408
953710409pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
......@@ -9582,6 +10454,7 @@ pub const fork = switch (native_os) {
958210454 .watchos,
958310455 .visionos,
958410456 .haiku,
10457 .serenity,
958510458 => private.fork,
958610459 else => {},
958710460};
......@@ -9825,7 +10698,11 @@ pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.c)
982510698pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
982610699pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.c) E;
982710700
9828pub const pthread_t = *opaque {};
10701pub const pthread_t = switch (native_os) {
10702 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L64
10703 .serenity => c_int,
10704 else => *opaque {},
10705};
982910706pub const FILE = opaque {};
983010707
983110708pub extern "c" fn dlopen(path: ?[*:0]const u8, mode: RTLD) ?*anyopaque;
......@@ -9958,7 +10835,6 @@ pub const thread_id = haiku.thread_id;
995810835
995910836pub const AUTH = openbsd.AUTH;
996010837pub const BI = openbsd.BI;
9961pub const FUTEX = openbsd.FUTEX;
996210838pub const HW = openbsd.HW;
996310839pub const PTHREAD_STACK_MIN = openbsd.PTHREAD_STACK_MIN;
996410840pub const TCFLUSH = openbsd.TCFLUSH;
......@@ -9999,7 +10875,6 @@ pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;
999910875pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;
1000010876pub const bcrypt_newhash = openbsd.bcrypt_newhash;
1000110877pub const endpwent = openbsd.endpwent;
10002pub const futex = openbsd.futex;
1000310878pub const getpwent = openbsd.getpwent;
1000410879pub const getpwnam_r = openbsd.getpwnam_r;
1000510880pub const getpwnam_shadow = openbsd.getpwnam_shadow;
......@@ -10226,6 +11101,24 @@ pub const lwp_gettid = dragonfly.lwp_gettid;
1022611101pub const umtx_sleep = dragonfly.umtx_sleep;
1022711102pub const umtx_wakeup = dragonfly.umtx_wakeup;
1022811103
11104pub const PERF_EVENT = serenity.PERF_EVENT;
11105pub const disown = serenity.disown;
11106pub const profiling_enable = serenity.profiling_enable;
11107pub const profiling_disable = serenity.profiling_disable;
11108pub const profiling_free_buffer = serenity.profiling_free_buffer;
11109pub const futex_wait = serenity.futex_wait;
11110pub const futex_wake = serenity.futex_wake;
11111pub const purge = serenity.purge;
11112pub const perf_event = serenity.perf_event;
11113pub const perf_register_string = serenity.perf_register_string;
11114pub const get_stack_bounds = serenity.get_stack_bounds;
11115pub const anon_create = serenity.anon_create;
11116pub const serenity_readlink = serenity.serenity_readlink;
11117pub const serenity_open = serenity.serenity_open;
11118pub const getkeymap = serenity.getkeymap;
11119pub const setkeymap = serenity.setkeymap;
11120pub const internet_checksum = serenity.internet_checksum;
11121
1022911122/// External definitions shared by two or more operating systems.
1023011123const private = struct {
1023111124 extern "c" fn close(fd: fd_t) c_int;
lib/std/c/serenity.zig created+75
......@@ -0,0 +1,75 @@
1const std = @import("../std.zig");
2const assert = std.debug.assert;
3const builtin = @import("builtin");
4const O = std.c.O;
5const clockid_t = std.c.clockid_t;
6const pid_t = std.c.pid_t;
7const timespec = std.c.timespec;
8
9comptime {
10 assert(builtin.os.tag == .serenity); // Prevent access of std.c symbols on wrong OS.
11}
12
13// https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/futex.h#L46-L53
14pub const FUTEX = struct {
15 pub const WAIT = 1;
16 pub const WAKE = 2;
17 pub const REQUEUE = 3;
18 pub const CMP_REQUEUE = 4;
19 pub const WAKE_OP = 5;
20 pub const WAIT_BITSET = 9;
21 pub const WAKE_BITSET = 10;
22
23 pub const CLOCK_REALTIME = 1 << 8;
24 pub const PRIVATE_FLAG = 1 << 9;
25};
26
27// https://github.com/SerenityOS/serenity/blob/54e79aa1d90bbcb69014255a59afb085802719d3/Kernel/API/POSIX/serenity.h#L18-L36
28pub const PERF_EVENT = packed struct(c_int) {
29 SAMPLE: bool = false,
30 MALLOC: bool = false,
31 FREE: bool = false,
32 MMAP: bool = false,
33 MUNMAP: bool = false,
34 PROCESS_CREATE: bool = false,
35 PROCESS_EXEC: bool = false,
36 PROCESS_EXIT: bool = false,
37 THREAD_CREATE: bool = false,
38 THREAD_EXIT: bool = false,
39 CONTEXT_SWITCH: bool = false,
40 KMALLOC: bool = false,
41 KFREE: bool = false,
42 PAGE_FAULT: bool = false,
43 SYSCALL: bool = false,
44 SIGNPOST: bool = false,
45 FILESYSTEM: bool = false,
46};
47
48// https://github.com/SerenityOS/serenity/blob/abc150085f532f123b598949218893cb272ccc4c/Userland/Libraries/LibC/serenity.h
49
50pub extern "c" fn disown(pid: pid_t) c_int;
51
52pub extern "c" fn profiling_enable(pid: pid_t, event_mask: PERF_EVENT) c_int;
53pub extern "c" fn profiling_disable(pid: pid_t) c_int;
54pub extern "c" fn profiling_free_buffer(pid: pid_t) c_int;
55
56pub extern "c" fn futex(userspace_address: *u32, futex_op: c_int, value: u32, timeout: *const timespec, userspace_address2: *u32, value3: u32) c_int;
57pub extern "c" fn futex_wait(userspace_address: *u32, value: u32, abstime: *const timespec, clockid: clockid_t, process_shared: c_int) c_int;
58pub extern "c" fn futex_wake(userspace_address: *u32, count: u32, process_shared: c_int) c_int;
59
60pub extern "c" fn purge(mode: c_int) c_int;
61
62pub extern "c" fn perf_event(type: PERF_EVENT, arg1: usize, arg2: usize) c_int;
63pub extern "c" fn perf_register_string(string: [*]const u8, string_length: usize) c_int;
64
65pub extern "c" fn get_stack_bounds(user_stack_base: *usize, user_stack_size: *usize) c_int;
66
67pub extern "c" fn anon_create(size: usize, options: O) c_int;
68
69pub extern "c" fn serenity_readlink(path: [*]const u8, path_length: usize, buffer: [*]u8, buffer_size: usize) c_int;
70pub extern "c" fn serenity_open(path: [*]const u8, path_length: usize, options: c_int, ...) c_int;
71
72pub extern "c" fn getkeymap(name_buffer: [*]u8, name_buffer_size: usize, map: [*]u32, shift_map: [*]u32, alt_map: [*]u32, altgr_map: [*]u32, shift_altgr_map: [*]u32) c_int;
73pub extern "c" fn setkeymap(name: [*]const u8, map: [*]const u32, shift_map: [*]const u32, alt_map: [*]const u32, altgr_map: [*]const u32, shift_altgr_map: [*]const u32) c_int;
74
75pub extern "c" fn internet_checksum(ptr: *const anyopaque, count: usize) u16;