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