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");...@@ -19,6 +19,7 @@ const netbsd = @import("c/netbsd.zig");
19const dragonfly = @import("c/dragonfly.zig");19const dragonfly = @import("c/dragonfly.zig");
20const haiku = @import("c/haiku.zig");20const haiku = @import("c/haiku.zig");
21const openbsd = @import("c/openbsd.zig");21const openbsd = @import("c/openbsd.zig");
22const serenity = @import("c/serenity.zig");
2223
23// These constants are shared among all operating systems even when not linking24// These constants are shared among all operating systems even when not linking
24// libc.25// libc.
...@@ -75,12 +76,14 @@ pub const ino_t = switch (native_os) {...@@ -75,12 +76,14 @@ pub const ino_t = switch (native_os) {
75 .wasi => wasi.inode_t,76 .wasi => wasi.inode_t,
76 .windows => windows.LARGE_INTEGER,77 .windows => windows.LARGE_INTEGER,
77 .haiku => i64,78 .haiku => i64,
79 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L38
78 else => u64,80 else => u64,
79};81};
8082
81pub const off_t = switch (native_os) {83pub const off_t = switch (native_os) {
82 .linux => linux.off_t,84 .linux => linux.off_t,
83 .emscripten => emscripten.off_t,85 .emscripten => emscripten.off_t,
86 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L39
84 else => i64,87 else => i64,
85};88};
8689
...@@ -105,7 +108,8 @@ pub const timespec = switch (native_os) {...@@ -105,7 +108,8 @@ pub const timespec = switch (native_os) {
105 @as(wasi.timestamp_t, @intCast(ts.nsec));108 @as(wasi.timestamp_t, @intCast(ts.nsec));
106 }109 }
107 },110 },
108 .windows => extern struct {111 // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20
112 .windows, .serenity => extern struct {
109 sec: time_t,113 sec: time_t,
110 nsec: c_long,114 nsec: c_long,
111 },115 },
...@@ -129,7 +133,8 @@ pub const dev_t = switch (native_os) {...@@ -129,7 +133,8 @@ pub const dev_t = switch (native_os) {
129 .emscripten => emscripten.dev_t,133 .emscripten => emscripten.dev_t,
130 .wasi => wasi.device_t,134 .wasi => wasi.device_t,
131 .openbsd, .haiku, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => i32,135 .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,
133 else => void,138 else => void,
134};139};
135140
...@@ -137,7 +142,8 @@ pub const mode_t = switch (native_os) {...@@ -137,7 +142,8 @@ pub const mode_t = switch (native_os) {
137 .linux => linux.mode_t,142 .linux => linux.mode_t,
138 .emscripten => emscripten.mode_t,143 .emscripten => emscripten.mode_t,
139 .openbsd, .haiku, .netbsd, .solaris, .illumos, .wasi, .windows => u32,144 .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,
141 else => u0,147 else => u0,
142};148};
143149
...@@ -145,7 +151,8 @@ pub const nlink_t = switch (native_os) {...@@ -145,7 +151,8 @@ pub const nlink_t = switch (native_os) {
145 .linux => linux.nlink_t,151 .linux => linux.nlink_t,
146 .emscripten => emscripten.nlink_t,152 .emscripten => emscripten.nlink_t,
147 .wasi => c_ulonglong,153 .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,
149 .openbsd, .netbsd, .solaris, .illumos => u32,156 .openbsd, .netbsd, .solaris, .illumos => u32,
150 .haiku => i32,157 .haiku => i32,
151 else => void,158 else => void,
...@@ -154,12 +161,14 @@ pub const nlink_t = switch (native_os) {...@@ -154,12 +161,14 @@ pub const nlink_t = switch (native_os) {
154pub const uid_t = switch (native_os) {161pub const uid_t = switch (native_os) {
155 .linux => linux.uid_t,162 .linux => linux.uid_t,
156 .emscripten => emscripten.uid_t,163 .emscripten => emscripten.uid_t,
164 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L28
157 else => u32,165 else => u32,
158};166};
159167
160pub const gid_t = switch (native_os) {168pub const gid_t = switch (native_os) {
161 .linux => linux.gid_t,169 .linux => linux.gid_t,
162 .emscripten => emscripten.gid_t,170 .emscripten => emscripten.gid_t,
171 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L29
163 else => u32,172 else => u32,
164};173};
165174
...@@ -167,11 +176,14 @@ pub const blksize_t = switch (native_os) {...@@ -167,11 +176,14 @@ pub const blksize_t = switch (native_os) {
167 .linux => linux.blksize_t,176 .linux => linux.blksize_t,
168 .emscripten => emscripten.blksize_t,177 .emscripten => emscripten.blksize_t,
169 .wasi => c_long,178 .wasi => c_long,
179 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L42
180 .serenity => u64,
170 else => i32,181 else => i32,
171};182};
172183
173pub const passwd = switch (native_os) {184pub 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 {
175 name: ?[*:0]const u8, // username187 name: ?[*:0]const u8, // username
176 passwd: ?[*:0]const u8, // user password188 passwd: ?[*:0]const u8, // user password
177 uid: uid_t, // user ID189 uid: uid_t, // user ID
...@@ -199,6 +211,8 @@ pub const blkcnt_t = switch (native_os) {...@@ -199,6 +211,8 @@ pub const blkcnt_t = switch (native_os) {
199 .linux => linux.blkcnt_t,211 .linux => linux.blkcnt_t,
200 .emscripten => emscripten.blkcnt_t,212 .emscripten => emscripten.blkcnt_t,
201 .wasi => c_longlong,213 .wasi => c_longlong,
214 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L41
215 .serenity => u64,
202 else => i64,216 else => i64,
203};217};
204218
...@@ -206,6 +220,7 @@ pub const fd_t = switch (native_os) {...@@ -206,6 +220,7 @@ pub const fd_t = switch (native_os) {
206 .linux => linux.fd_t,220 .linux => linux.fd_t,
207 .wasi => wasi.fd_t,221 .wasi => wasi.fd_t,
208 .windows => windows.HANDLE,222 .windows => windows.HANDLE,
223 .serenity => c_int,
209 else => i32,224 else => i32,
210};225};
211226
...@@ -309,6 +324,14 @@ pub const clockid_t = switch (native_os) {...@@ -309,6 +324,14 @@ pub const clockid_t = switch (native_os) {
309 MONOTONIC = 3,324 MONOTONIC = 3,
310 THREAD_CPUTIME_ID = 4,325 THREAD_CPUTIME_ID = 4,
311 },326 },
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 },
312 else => void,335 else => void,
313};336};
314pub const CPU_COUNT = switch (native_os) {337pub const CPU_COUNT = switch (native_os) {
...@@ -681,6 +704,93 @@ pub const E = switch (native_os) {...@@ -681,6 +704,93 @@ pub const E = switch (native_os) {
681 .dragonfly => dragonfly.E,704 .dragonfly => dragonfly.E,
682 .haiku => haiku.E,705 .haiku => haiku.E,
683 .openbsd => openbsd.E,706 .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 },
684 else => void,794 else => void,
685};795};
686pub const Elf_Symndx = switch (native_os) {796pub const Elf_Symndx = switch (native_os) {
...@@ -1054,6 +1164,24 @@ pub const F = switch (native_os) {...@@ -1054,6 +1164,24 @@ pub const F = switch (native_os) {
1054 pub const UNLCK = 2;1164 pub const UNLCK = 2;
1055 pub const WRLCK = 3;1165 pub const WRLCK = 3;
1056 },1166 },
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 },
1057 else => void,1185 else => void,
1058};1186};
1059pub const FD_CLOEXEC = switch (native_os) {1187pub const FD_CLOEXEC = switch (native_os) {
...@@ -1129,18 +1257,29 @@ pub const Flock = switch (native_os) {...@@ -1129,18 +1257,29 @@ pub const Flock = switch (native_os) {
1129 len: off_t,1257 len: off_t,
1130 pid: pid_t,1258 pid: pid_t,
1131 },1259 },
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 },
1132 else => void,1268 else => void,
1133};1269};
1134pub const HOST_NAME_MAX = switch (native_os) {1270pub const HOST_NAME_MAX = switch (native_os) {
1135 .linux => linux.HOST_NAME_MAX,1271 .linux => linux.HOST_NAME_MAX,
1136 .macos, .ios, .tvos, .watchos, .visionos => 72,1272 .macos, .ios, .tvos, .watchos, .visionos => 72,
1137 .openbsd, .haiku, .dragonfly, .netbsd, .solaris, .illumos, .freebsd => 255,1273 .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,
1138 else => {},1276 else => {},
1139};1277};
1140pub const IOV_MAX = switch (native_os) {1278pub const IOV_MAX = switch (native_os) {
1141 .linux => linux.IOV_MAX,1279 .linux => linux.IOV_MAX,
1142 .emscripten => emscripten.IOV_MAX,1280 .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,
1144 .macos, .ios, .tvos, .watchos, .visionos => 16,1283 .macos, .ios, .tvos, .watchos, .visionos => 16,
1145 .dragonfly, .netbsd, .freebsd => KERN.IOV_MAX,1284 .dragonfly, .netbsd, .freebsd => KERN.IOV_MAX,
1146 else => {},1285 else => {},
...@@ -1425,6 +1564,16 @@ pub const MADV = switch (native_os) {...@@ -1425,6 +1564,16 @@ pub const MADV = switch (native_os) {
1425 pub const INVAL = 10;1564 pub const INVAL = 10;
1426 pub const SETMAP = 11;1565 pub const SETMAP = 11;
1427 },1566 },
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 },
1428 else => void,1577 else => void,
1429};1578};
1430pub const MSF = switch (native_os) {1579pub const MSF = switch (native_os) {
...@@ -1444,6 +1593,12 @@ pub const MSF = switch (native_os) {...@@ -1444,6 +1593,12 @@ pub const MSF = switch (native_os) {
1444 pub const INVALIDATE = 2;1593 pub const INVALIDATE = 2;
1445 pub const SYNC = 4;1594 pub const SYNC = 4;
1446 },1595 },
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 },
1447 else => void,1602 else => void,
1448};1603};
1449pub const MMAP2_UNIT = switch (native_os) {1604pub const MMAP2_UNIT = switch (native_os) {
...@@ -1456,7 +1611,8 @@ pub const NAME_MAX = switch (native_os) {...@@ -1456,7 +1611,8 @@ pub const NAME_MAX = switch (native_os) {
1456 // Haiku's headers make this 256, to contain room for the terminating null1611 // Haiku's headers make this 256, to contain room for the terminating null
1457 // character, but POSIX definition says that NAME_MAX does not include the1612 // character, but POSIX definition says that NAME_MAX does not include the
1458 // terminating null.1613 // 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,
1460 else => {},1616 else => {},
1461};1617};
1462pub const PATH_MAX = switch (native_os) {1618pub const PATH_MAX = switch (native_os) {
...@@ -1464,7 +1620,7 @@ pub const PATH_MAX = switch (native_os) {...@@ -1464,7 +1620,7 @@ pub const PATH_MAX = switch (native_os) {
1464 .emscripten => emscripten.PATH_MAX,1620 .emscripten => emscripten.PATH_MAX,
1465 .wasi => 4096,1621 .wasi => 4096,
1466 .windows => 260,1622 .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,
1468 else => {},1624 else => {},
1469};1625};
14701626
...@@ -1597,6 +1753,19 @@ pub const POLL = switch (native_os) {...@@ -1597,6 +1753,19 @@ pub const POLL = switch (native_os) {
1597 pub const RDBAND = 0x0080;1753 pub const RDBAND = 0x0080;
1598 pub const WRBAND = 0x0100;1754 pub const WRBAND = 0x0100;
1599 },1755 },
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 },
1600 else => void,1769 else => void,
1601};1770};
16021771
...@@ -1604,7 +1773,8 @@ pub const POLL = switch (native_os) {...@@ -1604,7 +1773,8 @@ pub const POLL = switch (native_os) {
1604pub const PROT = switch (native_os) {1773pub const PROT = switch (native_os) {
1605 .linux => linux.PROT,1774 .linux => linux.PROT,
1606 .emscripten => emscripten.PROT,1775 .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 {
1608 /// page can not be accessed1778 /// page can not be accessed
1609 pub const NONE = 0x0;1779 pub const NONE = 0x0;
1610 /// page can be read1780 /// page can be read
...@@ -1719,7 +1889,8 @@ pub const REG = switch (native_os) {...@@ -1719,7 +1889,8 @@ pub const REG = switch (native_os) {
1719pub const RLIM = switch (native_os) {1889pub const RLIM = switch (native_os) {
1720 .linux => linux.RLIM,1890 .linux => linux.RLIM,
1721 .emscripten => emscripten.RLIM,1891 .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 {
1723 /// No limit1894 /// No limit
1724 pub const INFINITY: rlim_t = (1 << 63) - 1;1895 pub const INFINITY: rlim_t = (1 << 63) - 1;
17251896
...@@ -2174,6 +2345,66 @@ pub const S = switch (native_os) {...@@ -2174,6 +2345,66 @@ pub const S = switch (native_os) {
2174 return m & IFMT == IFSOCK;2345 return m & IFMT == IFSOCK;
2175 }2346 }
2176 },2347 },
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 },
2177 else => void,2408 else => void,
2178};2409};
2179pub const SA = switch (native_os) {2410pub const SA = switch (native_os) {
...@@ -2254,6 +2485,18 @@ pub const SA = switch (native_os) {...@@ -2254,6 +2485,18 @@ pub const SA = switch (native_os) {
2254 pub const NOCLDWAIT = 0x0020;2485 pub const NOCLDWAIT = 0x0020;
2255 pub const SIGINFO = 0x0040;2486 pub const SIGINFO = 0x0040;
2256 },2487 },
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 },
2257 else => void,2500 else => void,
2258};2501};
2259pub const sigval_t = switch (native_os) {2502pub const sigval_t = switch (native_os) {
...@@ -2298,6 +2541,24 @@ pub const _SC = switch (native_os) {...@@ -2298,6 +2541,24 @@ pub const _SC = switch (native_os) {
2298 PAGESIZE = 11,2541 PAGESIZE = 11,
2299 NPROCESSORS_ONLN = 15,2542 NPROCESSORS_ONLN = 15,
2300 },2543 },
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 },
2301 else => void,2562 else => void,
2302};2563};
23032564
...@@ -2309,7 +2570,8 @@ pub const SEEK = switch (native_os) {...@@ -2309,7 +2570,8 @@ pub const SEEK = switch (native_os) {
2309 pub const CUR: wasi.whence_t = .CUR;2570 pub const CUR: wasi.whence_t = .CUR;
2310 pub const END: wasi.whence_t = .END;2571 pub const END: wasi.whence_t = .END;
2311 },2572 },
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 {
2313 pub const SET = 0;2575 pub const SET = 0;
2314 pub const CUR = 1;2576 pub const CUR = 1;
2315 pub const END = 2;2577 pub const END = 2;
...@@ -2326,6 +2588,7 @@ pub const SEEK = switch (native_os) {...@@ -2326,6 +2588,7 @@ pub const SEEK = switch (native_os) {
2326pub const SHUT = switch (native_os) {2588pub const SHUT = switch (native_os) {
2327 .linux => linux.SHUT,2589 .linux => linux.SHUT,
2328 .emscripten => emscripten.SHUT,2590 .emscripten => emscripten.SHUT,
2591 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L40-L42
2329 else => struct {2592 else => struct {
2330 pub const RD = 0;2593 pub const RD = 0;
2331 pub const WR = 1;2594 pub const WR = 1;
...@@ -2785,6 +3048,42 @@ pub const SIG = switch (native_os) {...@@ -2785,6 +3048,42 @@ pub const SIG = switch (native_os) {
2785 pub const UNBLOCK = 2;3048 pub const UNBLOCK = 2;
2786 pub const SETMASK = 3;3049 pub const SETMASK = 3;
2787 },3050 },
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 },
2788 else => void,3087 else => void,
2789};3088};
27903089
...@@ -2792,6 +3091,8 @@ pub const SIOCGIFINDEX = switch (native_os) {...@@ -2792,6 +3091,8 @@ pub const SIOCGIFINDEX = switch (native_os) {
2792 .linux => linux.SIOCGIFINDEX,3091 .linux => linux.SIOCGIFINDEX,
2793 .emscripten => emscripten.SIOCGIFINDEX,3092 .emscripten => emscripten.SIOCGIFINDEX,
2794 .solaris, .illumos => solaris.SIOCGLIFINDEX,3093 .solaris, .illumos => solaris.SIOCGLIFINDEX,
3094 // https://github.com/SerenityOS/serenity/blob/cb10f70394fb7e9cfc77f827adb2e46d199bc3a5/Kernel/API/Ioctl.h#L118
3095 .serenity => 34,
2795 else => void,3096 else => void,
2796};3097};
27973098
...@@ -2936,6 +3237,18 @@ pub const Sigaction = switch (native_os) {...@@ -2936,6 +3237,18 @@ pub const Sigaction = switch (native_os) {
2936 /// signal options3237 /// signal options
2937 flags: c_uint,3238 flags: c_uint,
2938 },3239 },
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 },
2939 else => void,3252 else => void,
2940};3253};
2941pub const T = switch (native_os) {3254pub const T = switch (native_os) {
...@@ -3311,6 +3624,22 @@ pub const T = switch (native_os) {...@@ -3311,6 +3624,22 @@ pub const T = switch (native_os) {
3311 pub const IOCGDRAINWAIT = 0x40047456;3624 pub const IOCGDRAINWAIT = 0x40047456;
3312 pub const IOCISPTMASTER = 0x20007455;3625 pub const IOCISPTMASTER = 0x20007455;
3313 },3626 },
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 },
3314 else => void,3643 else => void,
3315};3644};
3316pub const IOCPARM_MASK = switch (native_os) {3645pub const IOCPARM_MASK = switch (native_os) {
...@@ -3546,6 +3875,43 @@ pub const W = switch (native_os) {...@@ -3546,6 +3875,43 @@ pub const W = switch (native_os) {
3546 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);3875 return (((s) & 0o177) != 0o177) and (((s) & 0o177) != 0);
3547 }3876 }
3548 },3877 },
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 },
3549 else => void,3915 else => void,
3550};3916};
3551pub const clock_t = switch (native_os) {3917pub const clock_t = switch (native_os) {
...@@ -3556,6 +3922,8 @@ pub const clock_t = switch (native_os) {...@@ -3556,6 +3922,8 @@ pub const clock_t = switch (native_os) {
3556 .openbsd, .solaris, .illumos => i64,3922 .openbsd, .solaris, .illumos => i64,
3557 .netbsd => u32,3923 .netbsd => u32,
3558 .haiku => i32,3924 .haiku => i32,
3925 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L50
3926 .serenity => u64,
3559 else => void,3927 else => void,
3560};3928};
3561pub const cpu_set_t = switch (native_os) {3929pub const cpu_set_t = switch (native_os) {
...@@ -3568,7 +3936,7 @@ pub const dl_phdr_info = switch (native_os) {...@@ -3568,7 +3936,7 @@ pub const dl_phdr_info = switch (native_os) {
3568 .emscripten => emscripten.dl_phdr_info,3936 .emscripten => emscripten.dl_phdr_info,
3569 .freebsd => extern struct {3937 .freebsd => extern struct {
3570 /// Module relocation base.3938 /// Module relocation base.
3571 addr: if (builtin.target.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,3939 addr: std.elf.Addr,
3572 /// Module name.3940 /// Module name.
3573 name: ?[*:0]const u8,3941 name: ?[*:0]const u8,
3574 /// Pointer to module's phdr.3942 /// Pointer to module's phdr.
...@@ -3592,11 +3960,12 @@ pub const dl_phdr_info = switch (native_os) {...@@ -3592,11 +3960,12 @@ pub const dl_phdr_info = switch (native_os) {
3592 /// Incremented when an object is unmapped from the process.3960 /// Incremented when an object is unmapped from the process.
3593 subs: u64,3961 subs: u64,
3594 },3962 },
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 {
3596 addr: usize,3965 addr: usize,
3597 name: ?[*:0]const u8,3966 name: ?[*:0]const u8,
3598 phdr: [*]std.elf.Phdr,3967 phdr: [*]std.elf.Phdr,
3599 phnum: u16,3968 phnum: std.elf.Half,
3600 },3969 },
3601 else => void,3970 else => void,
3602};3971};
...@@ -3608,6 +3977,26 @@ pub const ifreq = switch (native_os) {...@@ -3608,6 +3977,26 @@ pub const ifreq = switch (native_os) {
3608 .linux => linux.ifreq,3977 .linux => linux.ifreq,
3609 .emscripten => emscripten.ifreq,3978 .emscripten => emscripten.ifreq,
3610 .solaris, .illumos => lifreq,3979 .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 },
3611 else => void,4000 else => void,
3612};4001};
3613pub const itimerspec = switch (native_os) {4002pub const itimerspec = switch (native_os) {
...@@ -3650,6 +4039,16 @@ pub const msghdr = switch (native_os) {...@@ -3650,6 +4039,16 @@ pub const msghdr = switch (native_os) {
3650 /// flags on received message4039 /// flags on received message
3651 flags: i32,4040 flags: i32,
3652 },4041 },
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 },
3653 else => void,4052 else => void,
3654};4053};
3655pub const msghdr_const = switch (native_os) {4054pub const msghdr_const = switch (native_os) {
...@@ -3684,6 +4083,15 @@ pub const msghdr_const = switch (native_os) {...@@ -3684,6 +4083,15 @@ pub const msghdr_const = switch (native_os) {
3684 /// flags on received message4083 /// flags on received message
3685 flags: i32,4084 flags: i32,
3686 },4085 },
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 },
3687 else => void,4095 else => void,
3688};4096};
3689pub const nfds_t = switch (native_os) {4097pub const nfds_t = switch (native_os) {
...@@ -3692,6 +4100,8 @@ pub const nfds_t = switch (native_os) {...@@ -3692,6 +4100,8 @@ pub const nfds_t = switch (native_os) {
3692 .haiku, .solaris, .illumos, .wasi => usize,4100 .haiku, .solaris, .illumos, .wasi => usize,
3693 .windows => c_ulong,4101 .windows => c_ulong,
3694 .openbsd, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => u32,4102 .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,
3695 else => void,4105 else => void,
3696};4106};
3697pub const perf_event_attr = switch (native_os) {4107pub const perf_event_attr = switch (native_os) {
...@@ -3702,12 +4112,20 @@ pub const pid_t = switch (native_os) {...@@ -3702,12 +4112,20 @@ pub const pid_t = switch (native_os) {
3702 .linux => linux.pid_t,4112 .linux => linux.pid_t,
3703 .emscripten => emscripten.pid_t,4113 .emscripten => emscripten.pid_t,
3704 .windows => windows.HANDLE,4114 .windows => windows.HANDLE,
4115 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L31-L32
4116 .serenity => c_int,
3705 else => i32,4117 else => i32,
3706};4118};
3707pub const pollfd = switch (native_os) {4119pub const pollfd = switch (native_os) {
3708 .linux => linux.pollfd,4120 .linux => linux.pollfd,
3709 .emscripten => emscripten.pollfd,4121 .emscripten => emscripten.pollfd,
3710 .windows => ws2_32.pollfd,4122 .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 },
3711 else => extern struct {4129 else => extern struct {
3712 fd: fd_t,4130 fd: fd_t,
3713 events: i16,4131 events: i16,
...@@ -3719,11 +4137,14 @@ pub const rlim_t = switch (native_os) {...@@ -3719,11 +4137,14 @@ pub const rlim_t = switch (native_os) {
3719 .emscripten => emscripten.rlim_t,4137 .emscripten => emscripten.rlim_t,
3720 .openbsd, .netbsd, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => u64,4138 .openbsd, .netbsd, .solaris, .illumos, .macos, .ios, .tvos, .watchos, .visionos => u64,
3721 .haiku, .dragonfly, .freebsd => i64,4139 .haiku, .dragonfly, .freebsd => i64,
4140 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L54
4141 .serenity => usize,
3722 else => void,4142 else => void,
3723};4143};
3724pub const rlimit = switch (native_os) {4144pub const rlimit = switch (native_os) {
3725 .linux, .emscripten => linux.rlimit,4145 .linux, .emscripten => linux.rlimit,
3726 .windows => void,4146 .windows => void,
4147 // https://github.com/SerenityOS/serenity/blob/aae106e37b48f2158e68902293df1e4bf7b80c0f/Userland/Libraries/LibC/sys/resource.h#L56-L59
3727 else => extern struct {4148 else => extern struct {
3728 /// Soft limit4149 /// Soft limit
3729 cur: rlim_t,4150 cur: rlim_t,
...@@ -3825,6 +4246,17 @@ pub const rlimit_resource = switch (native_os) {...@@ -3825,6 +4246,17 @@ pub const rlimit_resource = switch (native_os) {
3825 NOVMON = 7,4246 NOVMON = 7,
3826 _,4247 _,
3827 },4248 },
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 },
3828 else => void,4260 else => void,
3829};4261};
3830pub const rusage = switch (native_os) {4262pub const rusage = switch (native_os) {
...@@ -3873,6 +4305,28 @@ pub const rusage = switch (native_os) {...@@ -3873,6 +4305,28 @@ pub const rusage = switch (native_os) {
3873 pub const CHILDREN = -1;4305 pub const CHILDREN = -1;
3874 pub const THREAD = 1;4306 pub const THREAD = 1;
3875 },4307 },
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 },
3876 else => void,4330 else => void,
3877};4331};
38784332
...@@ -4050,12 +4504,25 @@ pub const siginfo_t = switch (native_os) {...@@ -4050,12 +4504,25 @@ pub const siginfo_t = switch (native_os) {
4050 assert(@sizeOf(@This()) == 136);4504 assert(@sizeOf(@This()) == 136);
4051 }4505 }
4052 },4506 },
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 },
4053 else => void,4519 else => void,
4054};4520};
4055pub const sigset_t = switch (native_os) {4521pub const sigset_t = switch (native_os) {
4056 .linux => linux.sigset_t,4522 .linux => linux.sigset_t,
4057 .emscripten => emscripten.sigset_t,4523 .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,
4059 .dragonfly, .netbsd, .solaris, .illumos, .freebsd => extern struct {4526 .dragonfly, .netbsd, .solaris, .illumos, .freebsd => extern struct {
4060 __bits: [SIG.WORDS]u32,4527 __bits: [SIG.WORDS]u32,
4061 },4528 },
...@@ -4075,7 +4542,8 @@ pub const filled_sigset = switch (native_os) {...@@ -4075,7 +4542,8 @@ pub const filled_sigset = switch (native_os) {
4075};4542};
4076pub const sigval = switch (native_os) {4543pub const sigval = switch (native_os) {
4077 .linux => linux.sigval,4544 .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 {
4079 int: c_int,4547 int: c_int,
4080 ptr: ?*anyopaque,4548 ptr: ?*anyopaque,
4081 },4549 },
...@@ -4144,7 +4612,8 @@ pub const addrinfo = if (builtin.abi.isAndroid()) extern struct {...@@ -4144,7 +4612,8 @@ pub const addrinfo = if (builtin.abi.isAndroid()) extern struct {
4144 addr: ?*sockaddr,4612 addr: ?*sockaddr,
4145 next: ?*addrinfo,4613 next: ?*addrinfo,
4146 },4614 },
4147 .openbsd => extern struct {4615 // https://github.com/SerenityOS/serenity/blob/d510d2aeb2facbd8f6c383d70fd1b033e1fee5dd/Userland/Libraries/LibC/netdb.h#L66-L75
4616 .openbsd, .serenity => extern struct {
4148 flags: AI,4617 flags: AI,
4149 family: c_int,4618 family: c_int,
4150 socktype: c_int,4619 socktype: c_int,
...@@ -4460,11 +4929,41 @@ pub const sockaddr = switch (native_os) {...@@ -4460,11 +4929,41 @@ pub const sockaddr = switch (native_os) {
4460 path: [104]u8,4929 path: [104]u8,
4461 };4930 };
4462 },4931 },
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 },
4463 else => void,4961 else => void,
4464};4962};
4465pub const socklen_t = switch (native_os) {4963pub const socklen_t = switch (native_os) {
4466 .linux, .emscripten => linux.socklen_t,4964 .linux, .emscripten => linux.socklen_t,
4467 .windows => ws2_32.socklen_t,4965 .windows => ws2_32.socklen_t,
4966 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L57
4468 else => u32,4967 else => u32,
4469};4968};
4470pub const in_port_t = u16;4969pub const in_port_t = u16;
...@@ -4472,7 +4971,8 @@ pub const sa_family_t = switch (native_os) {...@@ -4472,7 +4971,8 @@ pub const sa_family_t = switch (native_os) {
4472 .linux, .emscripten => linux.sa_family_t,4971 .linux, .emscripten => linux.sa_family_t,
4473 .windows => ws2_32.ADDRESS_FAMILY,4972 .windows => ws2_32.ADDRESS_FAMILY,
4474 .openbsd, .haiku, .dragonfly, .netbsd, .freebsd, .macos, .ios, .tvos, .watchos, .visionos => u8,4973 .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,
4476 else => void,4976 else => void,
4477};4977};
4478pub const AF = if (builtin.abi.isAndroid()) struct {4978pub const AF = if (builtin.abi.isAndroid()) struct {
...@@ -4751,6 +5251,15 @@ pub const AF = if (builtin.abi.isAndroid()) struct {...@@ -4751,6 +5251,15 @@ pub const AF = if (builtin.abi.isAndroid()) struct {
4751 pub const ISDN = 26;5251 pub const ISDN = 26;
4752 pub const MAX = 36;5252 pub const MAX = 36;
4753 },5253 },
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 },
4754 else => void,5263 else => void,
4755};5264};
4756pub const PF = if (builtin.abi.isAndroid()) struct {5265pub const PF = if (builtin.abi.isAndroid()) struct {
...@@ -5020,11 +5529,21 @@ pub const PF = if (builtin.abi.isAndroid()) struct {...@@ -5020,11 +5529,21 @@ pub const PF = if (builtin.abi.isAndroid()) struct {
5020 pub const ISDN = AF.ISDN;5529 pub const ISDN = AF.ISDN;
5021 pub const MAX = AF.MAX;5530 pub const MAX = AF.MAX;
5022 },5531 },
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 },
5023 else => void,5541 else => void,
5024};5542};
5025pub const DT = switch (native_os) {5543pub const DT = switch (native_os) {
5026 .linux => linux.DT,5544 .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 {
5028 pub const UNKNOWN = 0;5547 pub const UNKNOWN = 0;
5029 pub const FIFO = 1;5548 pub const FIFO = 1;
5030 pub const CHR = 2;5549 pub const CHR = 2;
...@@ -5047,17 +5566,6 @@ pub const DT = switch (native_os) {...@@ -5047,17 +5566,6 @@ pub const DT = switch (native_os) {
5047 pub const WHT = 14;5566 pub const WHT = 14;
5048 pub const DBF = 15;5567 pub const DBF = 15;
5049 },5568 },
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 },
5061 else => void,5569 else => void,
5062};5570};
5063pub const MSG = switch (native_os) {5571pub const MSG = switch (native_os) {
...@@ -5078,6 +5586,18 @@ pub const MSG = switch (native_os) {...@@ -5078,6 +5586,18 @@ pub const MSG = switch (native_os) {
5078 pub const EOF = 0x0400;5586 pub const EOF = 0x0400;
5079 pub const NOSIGNAL = 0x0800;5587 pub const NOSIGNAL = 0x0800;
5080 },5588 },
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 },
5081 else => void,5601 else => void,
5082};5602};
5083pub const SOCK = switch (native_os) {5603pub const SOCK = switch (native_os) {
...@@ -5168,6 +5688,17 @@ pub const SOCK = switch (native_os) {...@@ -5168,6 +5688,17 @@ pub const SOCK = switch (native_os) {
5168 pub const CLOEXEC = 0x8000;5688 pub const CLOEXEC = 0x8000;
5169 pub const NONBLOCK = 0x4000;5689 pub const NONBLOCK = 0x4000;
5170 },5690 },
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 },
5171 else => void,5702 else => void,
5172};5703};
5173pub const TCP = switch (native_os) {5704pub const TCP = switch (native_os) {
...@@ -5175,6 +5706,11 @@ pub const TCP = switch (native_os) {...@@ -5175,6 +5706,11 @@ pub const TCP = switch (native_os) {
5175 .linux => linux.TCP,5706 .linux => linux.TCP,
5176 .emscripten => emscripten.TCP,5707 .emscripten => emscripten.TCP,
5177 .windows => ws2_32.TCP,5708 .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 },
5178 else => void,5714 else => void,
5179};5715};
5180pub const IPPROTO = switch (native_os) {5716pub const IPPROTO = switch (native_os) {
...@@ -5759,6 +6295,20 @@ pub const IPPROTO = switch (native_os) {...@@ -5759,6 +6295,20 @@ pub const IPPROTO = switch (native_os) {
5759 /// raw IP packet6295 /// raw IP packet
5760 pub const RAW = 255;6296 pub const RAW = 255;
5761 },6297 },
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 },
5762 else => void,6312 else => void,
5763};6313};
5764pub const SOL = switch (native_os) {6314pub const SOL = switch (native_os) {
...@@ -5774,6 +6324,10 @@ pub const SOL = switch (native_os) {...@@ -5774,6 +6324,10 @@ pub const SOL = switch (native_os) {
5774 pub const PACKET = 0xfffd;6324 pub const PACKET = 0xfffd;
5775 pub const FILTER = 0xfffc;6325 pub const FILTER = 0xfffc;
5776 },6326 },
6327 // https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L127
6328 .serenity => struct {
6329 pub const SOCKET = 1;
6330 },
5777 else => void,6331 else => void,
5778};6332};
5779pub const SO = switch (native_os) {6333pub const SO = switch (native_os) {
...@@ -5991,12 +6545,35 @@ pub const SO = switch (native_os) {...@@ -5991,12 +6545,35 @@ pub const SO = switch (native_os) {
5991 pub const DOMAIN = 0x1024;6545 pub const DOMAIN = 0x1024;
5992 pub const PROTOCOL = 0x1025;6546 pub const PROTOCOL = 0x1025;
5993 },6547 },
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 },
5994 else => void,6570 else => void,
5995};6571};
5996pub const SOMAXCONN = switch (native_os) {6572pub const SOMAXCONN = switch (native_os) {
5997 .linux => linux.SOMAXCONN,6573 .linux => linux.SOMAXCONN,
5998 .windows => ws2_32.SOMAXCONN,6574 .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,
6000 .openbsd => 28,6577 .openbsd => 28,
6001 else => void,6578 else => void,
6002};6579};
...@@ -6004,7 +6581,8 @@ pub const IFNAMESIZE = switch (native_os) {...@@ -6004,7 +6581,8 @@ pub const IFNAMESIZE = switch (native_os) {
6004 .linux => linux.IFNAMESIZE,6581 .linux => linux.IFNAMESIZE,
6005 .emscripten => emscripten.IFNAMESIZE,6582 .emscripten => emscripten.IFNAMESIZE,
6006 .windows => 30,6583 .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,
6008 .solaris, .illumos => 32,6586 .solaris, .illumos => 32,
6009 else => void,6587 else => void,
6010};6588};
...@@ -6020,6 +6598,12 @@ pub const stack_t = switch (native_os) {...@@ -6020,6 +6598,12 @@ pub const stack_t = switch (native_os) {
6020 /// SS_DISABLE and/or SS_ONSTACK.6598 /// SS_DISABLE and/or SS_ONSTACK.
6021 flags: i32,6599 flags: i32,
6022 },6600 },
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 },
6023 else => extern struct {6607 else => extern struct {
6024 sp: [*]u8,6608 sp: [*]u8,
6025 size: isize,6609 size: isize,
...@@ -6030,10 +6614,12 @@ pub const time_t = switch (native_os) {...@@ -6030,10 +6614,12 @@ pub const time_t = switch (native_os) {
6030 .linux => linux.time_t,6614 .linux => linux.time_t,
6031 .emscripten => emscripten.time_t,6615 .emscripten => emscripten.time_t,
6032 .haiku, .dragonfly => isize,6616 .haiku, .dragonfly => isize,
6617 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47
6033 else => i64,6618 else => i64,
6034};6619};
6035pub const suseconds_t = switch (native_os) {6620pub 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,
6037 .freebsd, .dragonfly => c_long,6623 .freebsd, .dragonfly => c_long,
6038 .netbsd => c_int,6624 .netbsd => c_int,
6039 .haiku => i32,6625 .haiku => i32,
...@@ -6051,7 +6637,8 @@ pub const timeval = switch (native_os) {...@@ -6051,7 +6637,8 @@ pub const timeval = switch (native_os) {
6051 sec: c_long,6637 sec: c_long,
6052 usec: i32,6638 usec: i32,
6053 },6639 },
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 {
6055 /// seconds6642 /// seconds
6056 sec: time_t,6643 sec: time_t,
6057 /// microseconds6644 /// microseconds
...@@ -6070,6 +6657,11 @@ pub const timezone = switch (native_os) {...@@ -6070,6 +6657,11 @@ pub const timezone = switch (native_os) {
6070 minuteswest: i32,6657 minuteswest: i32,
6071 dsttime: i32,6658 dsttime: i32,
6072 },6659 },
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 },
6073 else => void,6665 else => void,
6074};6666};
60756667
...@@ -6127,7 +6719,8 @@ pub const ucontext_t = switch (native_os) {...@@ -6127,7 +6719,8 @@ pub const ucontext_t = switch (native_os) {
6127 arg: ?*void,6719 arg: ?*void,
6128 _spare: [4]c_int,6720 _spare: [4]c_int,
6129 },6721 },
6130 .haiku => extern struct {6722 // https://github.com/SerenityOS/serenity/blob/87eac0e424cff4a1f941fb704b9362a08654c24d/Kernel/API/POSIX/ucontext.h#L19-L24
6723 .haiku, .serenity => extern struct {
6131 link: ?*ucontext_t,6724 link: ?*ucontext_t,
6132 sigmask: sigset_t,6725 sigmask: sigset_t,
6133 stack: stack_t,6726 stack: stack_t,
...@@ -6222,6 +6815,47 @@ pub const mcontext_t = switch (native_os) {...@@ -6222,6 +6815,47 @@ pub const mcontext_t = switch (native_os) {
6222 },6815 },
6223 .dragonfly => dragonfly.mcontext_t,6816 .dragonfly => dragonfly.mcontext_t,
6224 .haiku => haiku.mcontext_t,6817 .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 },
6225 else => void,6859 else => void,
6226};6860};
62276861
...@@ -6247,6 +6881,16 @@ pub const utsname = switch (native_os) {...@@ -6247,6 +6881,16 @@ pub const utsname = switch (native_os) {
6247 version: [256:0]u8,6881 version: [256:0]u8,
6248 machine: [256:0]u8,6882 machine: [256:0]u8,
6249 },6883 },
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 },
6250 else => void,6894 else => void,
6251};6895};
6252pub const PR = switch (native_os) {6896pub const PR = switch (native_os) {
...@@ -6265,6 +6909,8 @@ pub const _errno = switch (native_os) {...@@ -6265,6 +6909,8 @@ pub const _errno = switch (native_os) {
6265 .solaris, .illumos => private.___errno,6909 .solaris, .illumos => private.___errno,
6266 .openbsd, .netbsd => private.__errno,6910 .openbsd, .netbsd => private.__errno,
6267 .haiku => haiku._errnop,6911 .haiku => haiku._errnop,
6912 // https://github.com/SerenityOS/serenity/blob/a353ceecf13b6f156a078e32f1ddf1d21366934c/Userland/Libraries/LibC/errno.h#L33
6913 .serenity => private.__errno_location,
6268 else => {},6914 else => {},
6269};6915};
62706916
...@@ -6340,6 +6986,16 @@ pub const RTLD = switch (native_os) {...@@ -6340,6 +6986,16 @@ pub const RTLD = switch (native_os) {
6340 FIRST: bool = false,6986 FIRST: bool = false,
6341 _: u23 = 0,6987 _: u23 = 0,
6342 },6988 },
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 },
6343 else => void,6999 else => void,
6344};7000};
63457001
...@@ -6413,11 +7069,20 @@ pub const dirent = switch (native_os) {...@@ -6413,11 +7069,20 @@ pub const dirent = switch (native_os) {
6413 _: u32 align(1) = 0,7069 _: u32 align(1) = 0,
6414 name: [MAXNAMLEN:0]u8,7070 name: [MAXNAMLEN:0]u8,
6415 },7071 },
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 },
6416 else => void,7080 else => void,
6417};7081};
6418pub const MAXNAMLEN = switch (native_os) {7082pub const MAXNAMLEN = switch (native_os) {
6419 .netbsd, .solaris, .illumos => 511,7083 .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,
6421 .openbsd => 255,7086 .openbsd => 255,
6422 else => {},7087 else => {},
6423};7088};
...@@ -6499,6 +7164,17 @@ pub const AI = if (builtin.abi.isAndroid()) packed struct(u32) {...@@ -6499,6 +7164,17 @@ pub const AI = if (builtin.abi.isAndroid()) packed struct(u32) {
6499 _: u19 = 0,7164 _: u19 = 0,
6500 },7165 },
6501 .windows => ws2_32.AI,7166 .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 },
6502 else => void,7178 else => void,
6503};7179};
65047180
...@@ -6523,6 +7199,15 @@ pub const NI = switch (native_os) {...@@ -6523,6 +7199,15 @@ pub const NI = switch (native_os) {
6523 NUMERICSCOPE: bool = false,7199 NUMERICSCOPE: bool = false,
6524 _: u25 = 0,7200 _: u25 = 0,
6525 },7201 },
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 },
6526 else => void,7211 else => void,
6527};7212};
65287213
...@@ -6675,6 +7360,22 @@ pub const EAI = if (builtin.abi.isAndroid()) enum(c_int) {...@@ -6675,6 +7360,22 @@ pub const EAI = if (builtin.abi.isAndroid()) enum(c_int) {
6675 OVERFLOW = -14,7360 OVERFLOW = -14,
6676 _,7361 _,
6677 },7362 },
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 },
6678 else => void,7379 else => void,
6679};7380};
66807381
...@@ -7097,6 +7798,34 @@ pub const Stat = switch (native_os) {...@@ -7097,6 +7798,34 @@ pub const Stat = switch (native_os) {
7097 return self.birthtim;7798 return self.birthtim;
7098 }7799 }
7099 },7800 },
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 },
7100 else => void,7829 else => void,
7101};7830};
71027831
...@@ -7159,6 +7888,13 @@ pub const pthread_mutex_t = switch (native_os) {...@@ -7159,6 +7888,13 @@ pub const pthread_mutex_t = switch (native_os) {
7159 .emscripten => extern struct {7888 .emscripten => extern struct {
7160 data: [24]u8 align(4) = [_]u8{0} ** 24,7889 data: [24]u8 align(4) = [_]u8{0} ** 24,
7161 },7890 },
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 },
7162 else => void,7898 else => void,
7163};7899};
71647900
...@@ -7201,6 +7937,12 @@ pub const pthread_cond_t = switch (native_os) {...@@ -7201,6 +7937,12 @@ pub const pthread_cond_t = switch (native_os) {
7201 .fuchsia, .emscripten => extern struct {7937 .fuchsia, .emscripten => extern struct {
7202 data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48,7938 data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48,
7203 },7939 },
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 },
7204 else => void,7946 else => void,
7205};7947};
72067948
...@@ -7258,6 +8000,10 @@ pub const pthread_rwlock_t = switch (native_os) {...@@ -7258,6 +8000,10 @@ pub const pthread_rwlock_t = switch (native_os) {
7258 .emscripten => extern struct {8000 .emscripten => extern struct {
7259 size: [32]u8 align(4) = [_]u8{0} ** 32,8001 size: [32]u8 align(4) = [_]u8{0} ** 32,
7260 },8002 },
8003 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86
8004 .serenity => extern struct {
8005 inner: u64 = 0,
8006 },
7261 else => void,8007 else => void,
7262};8008};
72638009
...@@ -7270,7 +8016,8 @@ pub const pthread_attr_t = switch (native_os) {...@@ -7270,7 +8016,8 @@ pub const pthread_attr_t = switch (native_os) {
7270 __sig: c_long,8016 __sig: c_long,
7271 __opaque: [56]u8,8017 __opaque: [56]u8,
7272 },8018 },
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 {
7274 inner: ?*anyopaque = null,8021 inner: ?*anyopaque = null,
7275 },8022 },
7276 .solaris, .illumos => extern struct {8023 .solaris, .illumos => extern struct {
...@@ -7288,16 +8035,14 @@ pub const pthread_attr_t = switch (native_os) {...@@ -7288,16 +8035,14 @@ pub const pthread_attr_t = switch (native_os) {
7288 guard_size: i32,8035 guard_size: i32,
7289 stack_address: ?*anyopaque,8036 stack_address: ?*anyopaque,
7290 },8037 },
7291 .openbsd => extern struct {
7292 inner: ?*anyopaque = null,
7293 },
7294 else => void,8038 else => void,
7295};8039};
72968040
7297pub const pthread_key_t = switch (native_os) {8041pub const pthread_key_t = switch (native_os) {
7298 .linux, .emscripten => c_uint,8042 .linux, .emscripten => c_uint,
7299 .macos, .ios, .tvos, .watchos, .visionos => c_ulong,8043 .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,
7301 else => void,8046 else => void,
7302};8047};
73038048
...@@ -7353,6 +8098,12 @@ pub const sem_t = switch (native_os) {...@@ -7353,6 +8098,12 @@ pub const sem_t = switch (native_os) {
7353 },8098 },
7354 padding: [2]i32,8099 padding: [2]i32,
7355 },8100 },
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 },
7356 else => void,8107 else => void,
7357};8108};
73588109
...@@ -7556,6 +8307,13 @@ pub const AT = switch (native_os) {...@@ -7556,6 +8307,13 @@ pub const AT = switch (native_os) {
7556 /// file.8307 /// file.
7557 pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3;8308 pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3;
7558 },8309 },
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 },
7559 else => void,8317 else => void,
7560};8318};
75618319
...@@ -7771,6 +8529,23 @@ pub const O = switch (native_os) {...@@ -7771,6 +8529,23 @@ pub const O = switch (native_os) {
7771 TMPFILE: bool = false,8529 TMPFILE: bool = false,
7772 _: u9 = 0,8530 _: u9 = 0,
7773 },8531 },
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 },
7774 else => void,8549 else => void,
7775};8550};
77768551
...@@ -7910,6 +8685,21 @@ pub const MAP = switch (native_os) {...@@ -7910,6 +8685,21 @@ pub const MAP = switch (native_os) {
7910 @"32BIT": bool = false,8685 @"32BIT": bool = false,
7911 _: u12 = 0,8686 _: u12 = 0,
7912 },8687 },
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 },
7913 else => void,8703 else => void,
7914};8704};
79158705
...@@ -8020,6 +8810,27 @@ pub const V = switch (native_os) {...@@ -8020,6 +8810,27 @@ pub const V = switch (native_os) {
8020 LNEXT,8810 LNEXT,
8021 EOL2,8811 EOL2,
8022 },8812 },
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 },
8023 else => void,8834 else => void,
8024};8835};
80258836
...@@ -8028,7 +8839,8 @@ pub const NCCS = switch (native_os) {...@@ -8028,7 +8839,8 @@ pub const NCCS = switch (native_os) {
8028 .macos, .ios, .tvos, .watchos, .visionos, .freebsd, .netbsd, .openbsd, .dragonfly => 20,8839 .macos, .ios, .tvos, .watchos, .visionos, .freebsd, .netbsd, .openbsd, .dragonfly => 20,
8029 .haiku => 11,8840 .haiku => 11,
8030 .solaris, .illumos => 19,8841 .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,
8032 else => void,8844 else => void,
8033};8845};
80348846
...@@ -8043,7 +8855,8 @@ pub const termios = switch (native_os) {...@@ -8043,7 +8855,8 @@ pub const termios = switch (native_os) {
8043 ispeed: speed_t align(8),8855 ispeed: speed_t align(8),
8044 ospeed: speed_t,8856 ospeed: speed_t,
8045 },8857 },
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 {
8047 iflag: tc_iflag_t,8860 iflag: tc_iflag_t,
8048 oflag: tc_oflag_t,8861 oflag: tc_oflag_t,
8049 cflag: tc_cflag_t,8862 cflag: tc_cflag_t,
...@@ -8171,7 +8984,8 @@ pub const tc_iflag_t = switch (native_os) {...@@ -8171,7 +8984,8 @@ pub const tc_iflag_t = switch (native_os) {
8171 DOSMODE: bool = false,8984 DOSMODE: bool = false,
8172 _: u16 = 0,8985 _: u16 = 0,
8173 },8986 },
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) {
8175 IGNBRK: bool = false,8989 IGNBRK: bool = false,
8176 BRKINT: bool = false,8990 BRKINT: bool = false,
8177 IGNPAR: bool = false,8991 IGNPAR: bool = false,
...@@ -8263,7 +9077,8 @@ pub const tc_oflag_t = switch (native_os) {...@@ -8263,7 +9077,8 @@ pub const tc_oflag_t = switch (native_os) {
8263 WRAP: bool = false,9077 WRAP: bool = false,
8264 _: u14 = 0,9078 _: u14 = 0,
8265 },9079 },
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) {
8267 OPOST: bool = false,9082 OPOST: bool = false,
8268 OLCUC: bool = false,9083 OLCUC: bool = false,
8269 ONLCR: bool = false,9084 ONLCR: bool = false,
...@@ -8422,6 +9237,19 @@ pub const tc_cflag_t = switch (native_os) {...@@ -8422,6 +9237,19 @@ pub const tc_cflag_t = switch (native_os) {
8422 CLOCAL: bool = false,9237 CLOCAL: bool = false,
8423 _: u20 = 0,9238 _: u20 = 0,
8424 },9239 },
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 },
8425 else => void,9253 else => void,
8426};9254};
84279255
...@@ -8548,6 +9376,27 @@ pub const tc_lflag_t = switch (native_os) {...@@ -8548,6 +9376,27 @@ pub const tc_lflag_t = switch (native_os) {
8548 IEXTEN: bool = false,9376 IEXTEN: bool = false,
8549 _: u16 = 0,9377 _: u16 = 0,
8550 },9378 },
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 },
8551 else => void,9400 else => void,
8552};9401};
85539402
...@@ -8696,7 +9545,8 @@ pub const speed_t = switch (native_os) {...@@ -8696,7 +9545,8 @@ pub const speed_t = switch (native_os) {
8696 B3500000 = 30,9545 B3500000 = 30,
8697 B4000000 = 31,9546 B4000000 = 31,
8698 },9547 },
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) {
8700 B0 = 0o0000000,9550 B0 = 0o0000000,
8701 B50 = 0o0000001,9551 B50 = 0o0000001,
8702 B75 = 0o0000002,9552 B75 = 0o0000002,
...@@ -8735,7 +9585,11 @@ pub const speed_t = switch (native_os) {...@@ -8735,7 +9585,11 @@ pub const speed_t = switch (native_os) {
87359585
8736pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int;9586pub 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
8740/// maximum signal number + 19594/// maximum signal number + 1
8741pub const NSIG = switch (native_os) {9595pub const NSIG = switch (native_os) {
...@@ -8744,7 +9598,8 @@ pub const NSIG = switch (native_os) {...@@ -8744,7 +9598,8 @@ pub const NSIG = switch (native_os) {
8744 .haiku => 65,9598 .haiku => 65,
8745 .netbsd, .freebsd => 32,9599 .netbsd, .freebsd => 32,
8746 .solaris, .illumos => 75,9600 .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,
8748 else => {},9603 else => {},
8749};9604};
87509605
...@@ -8758,6 +9613,8 @@ pub const MINSIGSTKSZ = switch (native_os) {...@@ -8758,6 +9613,8 @@ pub const MINSIGSTKSZ = switch (native_os) {
8758 .solaris, .illumos => 2048,9613 .solaris, .illumos => 2048,
8759 .haiku, .netbsd => 8192,9614 .haiku, .netbsd => 8192,
8760 .openbsd => 1 << openbsd.MAX_PAGE_SHIFT,9615 .openbsd => 1 << openbsd.MAX_PAGE_SHIFT,
9616 // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L58
9617 .serenity => 4096,
8761 else => {},9618 else => {},
8762};9619};
8763pub const SIGSTKSZ = switch (native_os) {9620pub const SIGSTKSZ = switch (native_os) {
...@@ -8766,6 +9623,8 @@ pub const SIGSTKSZ = switch (native_os) {...@@ -8766,6 +9623,8 @@ pub const SIGSTKSZ = switch (native_os) {
8766 .solaris, .illumos => 8192,9623 .solaris, .illumos => 8192,
8767 .haiku => 16384,9624 .haiku => 16384,
8768 .openbsd => MINSIGSTKSZ + (1 << openbsd.MAX_PAGE_SHIFT) * 4,9625 .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,
8769 else => {},9628 else => {},
8770};9629};
8771pub const SS = switch (native_os) {9630pub const SS = switch (native_os) {
...@@ -8774,7 +9633,8 @@ pub const SS = switch (native_os) {...@@ -8774,7 +9633,8 @@ pub const SS = switch (native_os) {
8774 pub const ONSTACK = 1;9633 pub const ONSTACK = 1;
8775 pub const DISABLE = 4;9634 pub const DISABLE = 4;
8776 },9635 },
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 {
8778 pub const ONSTACK = 0x1;9638 pub const ONSTACK = 0x1;
8779 pub const DISABLE = 0x2;9639 pub const DISABLE = 0x2;
8780 },9640 },
...@@ -9267,6 +10127,12 @@ pub const NOTE = switch (native_os) {...@@ -9267,6 +10127,12 @@ pub const NOTE = switch (native_os) {
9267 else => void,10127 else => void,
9268};10128};
926910129
10130pub const FUTEX = switch (native_os) {
10131 .openbsd => openbsd.FUTEX,
10132 .serenity => serenity.FUTEX,
10133 else => void,
10134};
10135
9270// Unix-like systems10136// Unix-like systems
9271pub const DIR = opaque {};10137pub const DIR = opaque {};
9272pub extern "c" fn opendir(pathname: [*:0]const u8) ?*DIR;10138pub 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...@@ -9327,7 +10193,7 @@ pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: us
9327pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int;10193pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int;
932810194
9329pub const arc4random_buf = switch (native_os) {10195pub 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,
9331 else => {},10197 else => {},
9332};10198};
9333pub const getentropy = switch (native_os) {10199pub const getentropy = switch (native_os) {
...@@ -9395,7 +10261,7 @@ pub const sigaltstack = switch (native_os) {...@@ -9395,7 +10261,7 @@ pub const sigaltstack = switch (native_os) {
939510261
9396pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;10262pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
9397pub const pipe2 = switch (native_os) {10263pub 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,
9399 else => {},10265 else => {},
9400};10266};
9401pub const copy_file_range = switch (native_os) {10267pub const copy_file_range = switch (native_os) {
...@@ -9501,15 +10367,15 @@ pub const _msize = switch (native_os) {...@@ -9501,15 +10367,15 @@ pub const _msize = switch (native_os) {
9501 else => {},10367 else => {},
9502};10368};
9503pub const malloc_size = switch (native_os) {10369pub 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,
9505 else => {},10371 else => {},
9506};10372};
9507pub const malloc_usable_size = switch (native_os) {10373pub const malloc_usable_size = switch (native_os) {
9508 .freebsd, .linux => private.malloc_usable_size,10374 .freebsd, .linux, .serenity => private.malloc_usable_size,
9509 else => {},10375 else => {},
9510};10376};
9511pub const posix_memalign = switch (native_os) {10377pub 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,
9513 else => {},10379 else => {},
9514};10380};
9515pub const sysconf = switch (native_os) {10381pub const sysconf = switch (native_os) {
...@@ -9532,6 +10398,12 @@ pub const flock = switch (native_os) {...@@ -9532,6 +10398,12 @@ pub const flock = switch (native_os) {
9532 else => private.flock,10398 else => private.flock,
9533};10399};
953410400
10401pub const futex = switch (native_os) {
10402 .openbsd => openbsd.futex,
10403 .serenity => serenity.futex,
10404 else => {},
10405};
10406
9535pub extern "c" var environ: [*:null]?[*:0]u8;10407pub extern "c" var environ: [*:null]?[*:0]u8;
953610408
9537pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;10409pub 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) {...@@ -9582,6 +10454,7 @@ pub const fork = switch (native_os) {
9582 .watchos,10454 .watchos,
9583 .visionos,10455 .visionos,
9584 .haiku,10456 .haiku,
10457 .serenity,
9585 => private.fork,10458 => private.fork,
9586 else => {},10459 else => {},
9587};10460};
...@@ -9825,7 +10698,11 @@ pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.c)...@@ -9825,7 +10698,11 @@ pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.c)
9825pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.c) E;10698pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
9826pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.c) E;10699pub 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};
9829pub const FILE = opaque {};10706pub const FILE = opaque {};
983010707
9831pub extern "c" fn dlopen(path: ?[*:0]const u8, mode: RTLD) ?*anyopaque;10708pub extern "c" fn dlopen(path: ?[*:0]const u8, mode: RTLD) ?*anyopaque;
...@@ -9958,7 +10835,6 @@ pub const thread_id = haiku.thread_id;...@@ -9958,7 +10835,6 @@ pub const thread_id = haiku.thread_id;
995810835
9959pub const AUTH = openbsd.AUTH;10836pub const AUTH = openbsd.AUTH;
9960pub const BI = openbsd.BI;10837pub const BI = openbsd.BI;
9961pub const FUTEX = openbsd.FUTEX;
9962pub const HW = openbsd.HW;10838pub const HW = openbsd.HW;
9963pub const PTHREAD_STACK_MIN = openbsd.PTHREAD_STACK_MIN;10839pub const PTHREAD_STACK_MIN = openbsd.PTHREAD_STACK_MIN;
9964pub const TCFLUSH = openbsd.TCFLUSH;10840pub const TCFLUSH = openbsd.TCFLUSH;
...@@ -9999,7 +10875,6 @@ pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;...@@ -9999,7 +10875,6 @@ pub const bcrypt_checkpass = openbsd.bcrypt_checkpass;
9999pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;10875pub const bcrypt_gensalt = openbsd.bcrypt_gensalt;
10000pub const bcrypt_newhash = openbsd.bcrypt_newhash;10876pub const bcrypt_newhash = openbsd.bcrypt_newhash;
10001pub const endpwent = openbsd.endpwent;10877pub const endpwent = openbsd.endpwent;
10002pub const futex = openbsd.futex;
10003pub const getpwent = openbsd.getpwent;10878pub const getpwent = openbsd.getpwent;
10004pub const getpwnam_r = openbsd.getpwnam_r;10879pub const getpwnam_r = openbsd.getpwnam_r;
10005pub const getpwnam_shadow = openbsd.getpwnam_shadow;10880pub const getpwnam_shadow = openbsd.getpwnam_shadow;
...@@ -10226,6 +11101,24 @@ pub const lwp_gettid = dragonfly.lwp_gettid;...@@ -10226,6 +11101,24 @@ pub const lwp_gettid = dragonfly.lwp_gettid;
10226pub const umtx_sleep = dragonfly.umtx_sleep;11101pub const umtx_sleep = dragonfly.umtx_sleep;
10227pub const umtx_wakeup = dragonfly.umtx_wakeup;11102pub 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
10229/// External definitions shared by two or more operating systems.11122/// External definitions shared by two or more operating systems.
10230const private = struct {11123const private = struct {
10231 extern "c" fn close(fd: fd_t) c_int;11124 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;