1const std = @import("../std.zig");
2const clock_t = std.c.clock_t;
3const clockid_t = std.c.clockid_t;
4const pid_t = std.c.pid_t;
5const pthread_t = std.c.pthread_t;
6const sigval_t = std.c.sigval_t;
7const uid_t = std.c.uid_t;
8const timespec = std.c.timespec;
9
10pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: c_int) c_int;
11
12pub const lwpid_t = i32;
13
14pub extern "c" fn pthread_setname_np(thread: pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
15
16pub extern "c" fn _lwp_self() lwpid_t;
17
18pub extern "c" fn ___lwp_park60(
19 clock_id: clockid_t,
20 flags: packed struct(u32) {
21 ABSTIME: bool = false,
22 unused: u31 = 0,
23 },
24 ts: ?*timespec,
25 unpark: lwpid_t,
26 hint: ?*const anyopaque,
27 unpark_hint: ?*const anyopaque,
28) c_int;
29
30pub extern "c" fn _lwp_unpark(lwp: lwpid_t, hint: ?*const anyopaque) c_int;
31pub extern "c" fn _lwp_unpark_all(targets: [*]const lwpid_t, ntargets: usize, hint: ?*const anyopaque) c_int;
32
33pub const TCIFLUSH = 1;
34pub const TCOFLUSH = 2;
35pub const TCIOFLUSH = 3;
36pub const TCOOFF = 1;
37pub const TCOON = 2;
38pub const TCIOFF = 3;
39pub const TCION = 4;
40
41pub const _ksiginfo = extern struct {
42 signo: std.c.SIG,
43 code: i32,
44 errno: i32,
45 // 64bit architectures insert 4bytes of padding here, this is done by
46 // correctly aligning the reason field
47 reason: extern union {
48 rt: extern struct {
49 pid: pid_t,
50 uid: uid_t,
51 value: sigval_t,
52 },
53 child: extern struct {
54 pid: pid_t,
55 uid: uid_t,
56 status: i32,
57 utime: clock_t,
58 stime: clock_t,
59 },
60 fault: extern struct {
61 addr: *allowzero anyopaque,
62 trap: i32,
63 trap2: i32,
64 trap3: i32,
65 },
66 poll: extern struct {
67 band: i32,
68 fd: i32,
69 },
70 syscall: extern struct {
71 sysnum: i32,
72 retval: [2]i32,
73 @"error": i32,
74 args: [8]u64,
75 },
76 ptrace_state: extern struct {
77 pe_report_event: i32,
78 option: extern union {
79 pe_other_pid: pid_t,
80 pe_lwp: lwpid_t,
81 },
82 },
83 } align(@sizeOf(usize)),
84};
85
86pub const E = enum(u16) {
87 /// No error occurred.
88 SUCCESS = 0,
89 PERM = 1, // Operation not permitted
90 NOENT = 2, // No such file or directory
91 SRCH = 3, // No such process
92 INTR = 4, // Interrupted system call
93 IO = 5, // Input/output error
94 NXIO = 6, // Device not configured
95 @"2BIG" = 7, // Argument list too long
96 NOEXEC = 8, // Exec format error
97 BADF = 9, // Bad file descriptor
98 CHILD = 10, // No child processes
99 DEADLK = 11, // Resource deadlock avoided
100 // 11 was AGAIN
101 NOMEM = 12, // Cannot allocate memory
102 ACCES = 13, // Permission denied
103 FAULT = 14, // Bad address
104 NOTBLK = 15, // Block device required
105 BUSY = 16, // Device busy
106 EXIST = 17, // File exists
107 XDEV = 18, // Cross-device link
108 NODEV = 19, // Operation not supported by device
109 NOTDIR = 20, // Not a directory
110 ISDIR = 21, // Is a directory
111 INVAL = 22, // Invalid argument
112 NFILE = 23, // Too many open files in system
113 MFILE = 24, // Too many open files
114 NOTTY = 25, // Inappropriate ioctl for device
115 TXTBSY = 26, // Text file busy
116 FBIG = 27, // File too large
117 NOSPC = 28, // No space left on device
118 SPIPE = 29, // Illegal seek
119 ROFS = 30, // Read-only file system
120 MLINK = 31, // Too many links
121 PIPE = 32, // Broken pipe
122
123 // math software
124 DOM = 33, // Numerical argument out of domain
125 RANGE = 34, // Result too large or too small
126
127 // non-blocking and interrupt i/o
128 // also: WOULDBLOCK: operation would block
129 AGAIN = 35, // Resource temporarily unavailable
130 INPROGRESS = 36, // Operation now in progress
131 ALREADY = 37, // Operation already in progress
132
133 // ipc/network software -- argument errors
134 NOTSOCK = 38, // Socket operation on non-socket
135 DESTADDRREQ = 39, // Destination address required
136 MSGSIZE = 40, // Message too long
137 PROTOTYPE = 41, // Protocol wrong type for socket
138 NOPROTOOPT = 42, // Protocol option not available
139 PROTONOSUPPORT = 43, // Protocol not supported
140 SOCKTNOSUPPORT = 44, // Socket type not supported
141 OPNOTSUPP = 45, // Operation not supported
142 PFNOSUPPORT = 46, // Protocol family not supported
143 AFNOSUPPORT = 47, // Address family not supported by protocol family
144 ADDRINUSE = 48, // Address already in use
145 ADDRNOTAVAIL = 49, // Can't assign requested address
146
147 // ipc/network software -- operational errors
148 NETDOWN = 50, // Network is down
149 NETUNREACH = 51, // Network is unreachable
150 NETRESET = 52, // Network dropped connection on reset
151 CONNABORTED = 53, // Software caused connection abort
152 CONNRESET = 54, // Connection reset by peer
153 NOBUFS = 55, // No buffer space available
154 ISCONN = 56, // Socket is already connected
155 NOTCONN = 57, // Socket is not connected
156 SHUTDOWN = 58, // Can't send after socket shutdown
157 TOOMANYREFS = 59, // Too many references: can't splice
158 TIMEDOUT = 60, // Operation timed out
159 CONNREFUSED = 61, // Connection refused
160
161 LOOP = 62, // Too many levels of symbolic links
162 NAMETOOLONG = 63, // File name too long
163
164 // should be rearranged
165 HOSTDOWN = 64, // Host is down
166 HOSTUNREACH = 65, // No route to host
167 NOTEMPTY = 66, // Directory not empty
168
169 // quotas & mush
170 PROCLIM = 67, // Too many processes
171 USERS = 68, // Too many users
172 DQUOT = 69, // Disc quota exceeded
173
174 // Network File System
175 STALE = 70, // Stale NFS file handle
176 REMOTE = 71, // Too many levels of remote in path
177 BADRPC = 72, // RPC struct is bad
178 RPCMISMATCH = 73, // RPC version wrong
179 PROGUNAVAIL = 74, // RPC prog. not avail
180 PROGMISMATCH = 75, // Program version wrong
181 PROCUNAVAIL = 76, // Bad procedure for program
182
183 NOLCK = 77, // No locks available
184 NOSYS = 78, // Function not implemented
185
186 FTYPE = 79, // Inappropriate file type or format
187 AUTH = 80, // Authentication error
188 NEEDAUTH = 81, // Need authenticator
189
190 // SystemV IPC
191 IDRM = 82, // Identifier removed
192 NOMSG = 83, // No message of desired type
193 OVERFLOW = 84, // Value too large to be stored in data type
194
195 // Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995
196 ILSEQ = 85, // Illegal byte sequence
197
198 // From IEEE Std 1003.1-2001
199 // Base, Realtime, Threads or Thread Priority Scheduling option errors
200 NOTSUP = 86, // Not supported
201
202 // Realtime option errors
203 CANCELED = 87, // Operation canceled
204
205 // Realtime, XSI STREAMS option errors
206 BADMSG = 88, // Bad or Corrupt message
207
208 // XSI STREAMS option errors
209 NODATA = 89, // No message available
210 NOSR = 90, // No STREAM resources
211 NOSTR = 91, // Not a STREAM
212 TIME = 92, // STREAM ioctl timeout
213
214 // File system extended attribute errors
215 NOATTR = 93, // Attribute not found
216
217 // Realtime, XSI STREAMS option errors
218 MULTIHOP = 94, // Multihop attempted
219 NOLINK = 95, // Link has been severed
220 PROTO = 96, // Protocol error
221
222 _,
223};
224
225// https://github.com/NetBSD/src/blob/80bf25a5691072d4755e84567ccbdf0729370dea/sys/netinet/in.h#L276
226pub const IP = struct {
227 pub const OPTIONS = 1;
228 pub const HDRINCL = 2;
229 pub const TOS = 3;
230 pub const TTL = 4;
231 pub const RECVOPTS = 5;
232 pub const RECVRETOPTS = 6;
233 pub const RECVDSTADDR = 7;
234 pub const RETOPTS = 8;
235 pub const MULTICAST_IF = 9;
236 pub const MULTICAST_TTL = 10;
237 pub const MULTICAST_LOOP = 11;
238 pub const ADD_MEMBERSHIP = 12;
239 pub const DROP_MEMBERSHIP = 13;
240 pub const PORTALGO = 18;
241 pub const PORTRANGE = 19;
242 pub const RECVIF = 20;
243 pub const ERRORMTU = 21;
244 pub const IPSEC_POLICY = 22;
245 pub const RECVTTL = 23;
246 pub const MINTTL = 24;
247 pub const PKTINFO = 25;
248 pub const RECVPKTINFO = 26;
249 pub const BINDANY = 27;
250 pub const SENDSRCADDR = RECVDSTADDR;
251 pub const DEFAULT_MULTICAST_TTL = 1;
252 pub const DEFAULT_MULTICAST_LOOP = 1;
253 pub const MAX_MEMBERSHIPS = 20;
254 pub const PORTRANGE_DEFAULT = 0;
255 pub const PORTRANGE_HIGH = 1;
256 pub const PORTRANGE_LOW = 2;
257};
258
259// https://github.com/NetBSD/src/blob/80bf25a5691072d4755e84567ccbdf0729370dea/sys/netinet6/in6.h#L370
260pub const IPV6 = struct {
261 pub const UNICAST_HOPS = 4;
262 pub const MULTICAST_IF = 9;
263 pub const MULTICAST_HOPS = 10;
264 pub const MULTICAST_LOOP = 11;
265 pub const JOIN_GROUP = 12;
266 pub const LEAVE_GROUP = 13;
267 pub const PORTRANGE = 14;
268 pub const PORTALGO = 17;
269 pub const @"2292PKTINFO" = 19;
270 pub const @"2292HOPLIMIT" = 20;
271 pub const @"2292NEXTHOP" = 21;
272 pub const @"2292HOPOPTS" = 22;
273 pub const @"2292DSTOPTS" = 23;
274 pub const @"2292RTHDR" = 24;
275 pub const @"2292PKTOPTIONS" = 25;
276 pub const CHECKSUM = 26;
277 pub const V6ONLY = 27;
278 pub const IPSEC_POLICY = 28;
279 pub const FAITH = 29;
280 pub const RTHDRDSTOPTS = 35;
281 pub const RECVPKTINFO = 36;
282 pub const RECVHOPLIMIT = 37;
283 pub const RECVRTHDR = 38;
284 pub const RECVHOPOPTS = 39;
285 pub const RECVDSTOPTS = 40;
286 pub const RECVRTHDRDSTOPTS = 41;
287 pub const USE_MIN_MTU = 42;
288 pub const RECVPATHMTU = 43;
289 pub const PATHMTU = 44;
290 pub const PKTINFO = 46;
291 pub const HOPLIMIT = 47;
292 pub const NEXTHOP = 48;
293 pub const HOPOPTS = 49;
294 pub const DSTOPTS = 50;
295 pub const RTHDR = 51;
296 pub const RECVTCLASS = 57;
297 pub const OTCLASS = 58;
298 pub const TCLASS = 61;
299 pub const DONTFRAG = 62;
300 pub const PREFER_TEMPADDR = 63;
301 pub const BINDANY = 64;
302 pub const RTHDR_LOOSE = 0;
303 pub const RTHDR_STRICT = 1;
304 pub const RTHDR_TYPE_0 = 0;
305 pub const DEFAULT_MULTICAST_HOPS = 1;
306 pub const DEFAULT_MULTICAST_LOOP = 1;
307 pub const PORTRANGE_DEFAULT = 0;
308 pub const PORTRANGE_HIGH = 1;
309 pub const PORTRANGE_LOW = 2;
310};
311
312// https://github.com/NetBSD/src/blob/80bf25a5691072d4755e84567ccbdf0729370dea/sys/netinet/ip.h#L140
313pub const IPTOS = struct {
314 pub const DSCP_CS0 = 0x00;
315 pub const DSCP_CS1 = 0x20;
316 pub const DSCP_AF11 = 0x28;
317 pub const DSCP_AF12 = 0x30;
318 pub const DSCP_AF13 = 0x38;
319 pub const DSCP_CS2 = 0x40;
320 pub const DSCP_AF21 = 0x48;
321 pub const DSCP_AF22 = 0x50;
322 pub const DSCP_AF23 = 0x58;
323 pub const DSCP_CS3 = 0x60;
324 pub const DSCP_AF31 = 0x68;
325 pub const DSCP_AF32 = 0x70;
326 pub const DSCP_AF33 = 0x78;
327 pub const DSCP_CS4 = 0x80;
328 pub const DSCP_AF41 = 0x88;
329 pub const DSCP_AF42 = 0x90;
330 pub const DSCP_AF43 = 0x98;
331 pub const DSCP_CS5 = 0xa0;
332 pub const DSCP_EF = 0xb8;
333 pub const DSCP_CS6 = 0xc0;
334 pub const DSCP_CS7 = 0xe0;
335 pub const CLASS_CS0 = 0x00;
336 pub const CLASS_CS1 = 0x20;
337 pub const CLASS_CS2 = 0x40;
338 pub const CLASS_CS3 = 0x60;
339 pub const CLASS_CS4 = 0x80;
340 pub const CLASS_CS5 = 0xa0;
341 pub const CLASS_CS6 = 0xc0;
342 pub const CLASS_CS7 = 0xe0;
343 pub const CLASS_DEFAULT = CLASS_CS0;
344 pub const CLASS_MASK = 0xe0;
345 pub fn CLASS(t: anytype) @TypeOf(t) {
346 return t & CLASS_MASK;
347 }
348 pub const DSCP_MASK = 0xfc;
349 pub fn DSCP(t: anytype) @TypeOf(t) {
350 return t & DSCP_MASK;
351 }
352 pub const ECN_NOTECT = 0x00;
353 pub const ECN_ECT1 = 0x01;
354 pub const ECN_ECT0 = 0x02;
355 pub const ECN_CE = 0x03;
356 pub const ECN_MASK = 0x03;
357 pub fn ECN(t: anytype) @TypeOf(t) {
358 return t & ECN_MASK;
359 }
360 pub const ECN_NOT_ECT = 0x00;
361 pub const LOWDELAY = 0x10;
362 pub const THROUGHPUT = 0x08;
363 pub const RELIABILITY = 0x04;
364 pub const MINCOST = 0x02;
365 pub const CE = 0x01;
366 pub const ECT = 0x02;
367 pub const PREC_NETCONTROL = 0xe0;
368 pub const PREC_INTERNETCONTROL = 0xc0;
369 pub const PREC_CRITIC_ECP = 0xa0;
370 pub const PREC_FLASHOVERRIDE = 0x80;
371 pub const PREC_FLASH = 0x60;
372 pub const PREC_IMMEDIATE = 0x40;
373 pub const PREC_PRIORITY = 0x20;
374 pub const PREC_ROUTINE = 0x00;
375};
376
377// https://github.com/NetBSD/src/blob/2579a44b3da9597de159e42cb1b5db0d382bd511/sys/netinet/tcp.h#L126
378pub const TCP = struct {
379 pub const NODELAY = 1;
380 pub const MAXSEG = 2;
381 pub const KEEPIDLE = 3;
382 pub const KEEPINTVL = 5;
383 pub const KEEPCNT = 6;
384 pub const KEEPINIT = 7;
385 pub const INFO = 9;
386 pub const MD5SIG = 0x10;
387 pub const CONGCTL = 0x20;
388};