Debian Codegraph @

rt/+netbsd/types.ha

raw
1 // SPDX-License-Identifier: MPL-2.0
2 // (c) Hare authors <https://harelang.org>
3
4 export type time_t = i64;
5 export type suseconds_t = i64;
6 export type dev_t = u64;
7 export type ino_t = u64;
8 export type nlink_t = u64;
9 export type id_t = uint;
10 export type pid_t = u64;
11 export type lwpid_t = i32;
12 export type uid_t = u32;
13 export type gid_t = u32;
14 export type off_t = i64;
15 export type blkcnt_t = i64;
16 export type blksize_t = i32;
17 export type fflags_t = u32;
18 export type mode_t = u32;
19 export type nfds_t = uint;
20 export type rlim_t = u64;
21
22 export type path = (str | []u8 | *const u8);
23
24 // Maximum length of a file path including the NUL terminator.
25 export def PATH_MAX = 1024z;
26
27 // Max bytes in a file name
28 export def NAME_MAX: int = 511;
29
30 export def NGROUPS_MAX: size = 1023;
31 export def NSIG: int = 32;
32
33 export type sigset = struct {
34 __bits: [4]u32,
35 };
36
37 export def SA_ONSTACK: int = 0x0001;
38 export def SA_RESTART: int = 0x0002;
39 export def SA_RESETHAND: int = 0x0004;
40 export def SA_NOCLDSTOP: int = 0x0008;
41 export def SA_NODEFER: int = 0x0010;
42 export def SA_NOCLDWAIT: int = 0x0020;
43 export def SA_SIGINFO: int = 0x0040;
44
45 export def SIG_ERR: uintptr = -1;
46 export def SIG_DFL: uintptr = 0;
47 export def SIG_IGN: uintptr = 1;
48 export def SIG_CATCH: uintptr = 2;
49 export def SIG_HOLD: uintptr = 3;
50
51 export type sigact = struct {
52 union {
53 sa_handler: nullable *fn (_: int) void,
54 sa_sigaction: nullable *fn (_: int, _: *siginfo,
55 _: *opaque) void,
56 },
57 sa_mask: sigset,
58 sa_flags: int,
59 };
60
61 export def SIG_BLOCK: int = 1;
62 export def SIG_UNBLOCK: int = 2;
63 export def SIG_SETMASK: int = 3;
64
65 export type sigval = union {
66 sival_t: int,
67 sival_ptr: *opaque,
68 };
69
70 export type stack_t = struct {
71 ss_sp: *opaque,
72 ss_size: size,
73 ss_flags: int,
74 };
75
76 export type pollfd = struct {
77 fd: int,
78 events: i16,
79 revents: i16,
80 };
81
82 export type timespec = struct {
83 tv_sec: time_t,
84 tv_nsec: i64,
85 };
86
87 export def UTIME_OMIT = -0x2;
88
89 export type timeval = struct {
90 tv_sec: time_t,
91 tv_usec: suseconds_t,
92 };
93
94 export type st_flock = struct {
95 l_start: off_t,
96 l_len: off_t,
97 l_pid: pid_t,
98 l_type: i16,
99 l_whence: i16,
100 l_sysid: int,
101 };
102
103 export type st = struct {
104 dev: dev_t,
105 ino: ino_t,
106 nlink: nlink_t,
107 mode: mode_t,
108 uid: uid_t,
109 gid: gid_t,
110 rdev: dev_t,
111 atime: timespec,
112 mtime: timespec,
113 ctime: timespec,
114 btime: timespec,
115 sz: off_t,
116 blocks: blkcnt_t,
117 blksz: blksize_t,
118 flags: fflags_t,
119 };
120
121 export type stat = struct {
122 st_dev: u64,
123 st_mode: mode_t,
124 _: u32, // padding
125 st_ino: u64,
126 st_nlink: u32,
127 st_uid: uid_t,
128 st_gid: gid_t,
129 _: u32, // padding
130 st_rdev: u64,
131 st_atim: timespec,
132 st_mtim: timespec,
133 st_ctim: timespec,
134 st_birthtim: timespec,
135 st_size: off_t,
136 st_blocks: blkcnt_t,
137 st_blksize: blksize_t,
138 st_flags: fflags_t,
139 st_gen: u32,
140 st_spare: [2]u32,
141 };
142
143 export type fsid_t = struct {
144 __fsid_val: [2]u32,
145 };
146
147 export def VFS_NAMELEN: int = 32;
148 export def VFS_MNAMELEN: int = 1024;
149
150 export type statvfs = struct {
151 // copy of mount exported flags
152 f_flag: u64,
153 // file system block size
154 f_bsize: u64,
155 // fundamental file system block size
156 f_frsize: u64,
157 // optimal file system block size
158 f_iosize: u64,
159
160 // The following are in units of f_frsize
161
162 // number of blocks in file system,
163 f_blocks: u64,
164 // free blocks avail in file system
165 f_bfree: u64,
166 // free blocks avail to non-root
167 f_bavail: u64,
168 // blocks reserved for root
169 f_bresvd: u64,
170
171 // total file nodes in file system
172 f_files: u64,
173 // free file nodes in file system
174 f_ffree: u64,
175 // free file nodes avail to non-root
176 f_favail: u64,
177 // file nodes reserved for root
178 f_fresvd: u64,
179
180 // count of sync reads since mount
181 f_syncreads: u64,
182 // count of sync writes since mount
183 f_syncwrites: u64,
184
185 // count of async reads since mount
186 f_asyncreads: u64,
187 // count of async writes since mount
188 f_asyncwrites: u64,
189
190 // NetBSD compatible fsid
191 f_fsidx: fsid_t,
192 // Posix compatible fsid
193 f_fsid: u64,
194 // maximum filename length
195 f_namemax: u64,
196 // user that mounted the file system
197 f_owner: uid_t,
198 _: u32, // padding
199
200 // spare space
201 f_spare: [4]u64,
202
203 // fs type name
204 f_fstypename: [VFS_NAMELEN]u8,
205 // directory on which mounted
206 f_mntonname: [VFS_MNAMELEN]u8,
207 // mounted file system
208 f_mntfromname: [VFS_MNAMELEN]u8,
209 // disk label name if avail
210 f_mntfromlabel: [VFS_MNAMELEN]u8,
211 };
212
213 export type dirent = struct {
214 // file number of entry
215 d_fileno: ino_t,
216 // length of this record
217 d_reclen: u16,
218 // length of d_name
219 d_namlen: u16,
220 // file type, see below
221 d_type: u8,
222 d_name: [NAME_MAX + 1]u8,
223 };
224
225 export type iovec = struct {
226 iov_base: nullable *opaque,
227 iov_len: size
228 };
229
230 export type winsize = struct {
231 ws_row: u16,
232 ws_col: u16,
233 ws_xpixel: u16,
234 ws_ypixel: u16,
235 };
236
237 export type termios = struct {
238 c_iflag: tcflag,
239 c_oflag: tcflag,
240 c_cflag: tcflag,
241 c_lflag: tcflag,
242 c_cc: [NCCS]cc,
243 };
244
245 export def NCCS: size = 20;
246
247 export type tcflag = enum uint {
248 // c_iflag bits
249 IGNBRK = 0x00000001,
250 BRKINT = 0x00000002,
251 IGNPAR = 0x00000004,
252 PARMRK = 0x00000008,
253 INPCK = 0x00000010,
254 ISTRIP = 0x00000020,
255 INLCR = 0x00000040,
256 IGNCR = 0x00000080,
257 ICRNL = 0x00000100,
258 IXON = 0x00000200,
259 IXOFF = 0x00000400,
260 IXANY = 0x00000800,
261 IMAXBEL = 0x00002000,
262
263 // c_oflag bits
264 OPOST = 0x00000001,
265 ONLCR = 0x00000002,
266 TABDLY = 0x00000004,
267 TAB0 = 0x00000000,
268 TAB3 = 0x00000004,
269 ONOEOT = 0x00000008,
270 OCRNL = 0x00000010,
271 ONOCR = 0x00000020,
272 ONLRET = 0x00000040,
273
274 // c_cflag bits
275 CIGNORE = 0x00000001,
276 CSIZE = 0x00000300,
277 CS5 = 0x00000000,
278 CS6 = 0x00000100,
279 CS7 = 0x00000200,
280 CS8 = 0x00000300,
281 CSTOPB = 0x00000400,
282 CREAD = 0x00000800,
283 PARENB = 0x00001000,
284 PARODD = 0x00002000,
285 HUPCL = 0x00004000,
286 CLOCAL = 0x00008000,
287 CCTS_OFLOW = 0x00010000,
288 CRTS_IFLOW = 0x00020000,
289 CRTSCTS = (CCTS_OFLOW | CRTS_IFLOW),
290 CDTR_IFLOW = 0x00040000,
291 CDSR_OFLOW = 0x00080000,
292 CCAR_OFLOW = 0x00100000,
293 CNO_RTSDTR = 0x00200000,
294
295 // c_lflag bits
296 ECHOKE = 0x00000001,
297 ECHOE = 0x00000002,
298 ECHOK = 0x00000004,
299 ECHO = 0x00000008,
300 ECHONL = 0x00000010,
301 ECHOPRT = 0x00000020,
302 ECHOCTL = 0x00000040,
303 ISIG = 0x00000080,
304 ICANON = 0x00000100,
305 ALTWERASE = 0x00000200,
306 IEXTEN = 0x00000400,
307 EXTPROC = 0x00000800,
308 TOSTOP = 0x00400000,
309 FLUSHO = 0x00800000,
310 NOKERNINFO = 0x02000000,
311 PENDIN = 0x20000000,
312 NOFLSH = 0x80000000,
313 };
314
315 export type cc = enum u8 {
316 VEOF = 0,
317 VEOL = 1,
318 VEOL2 = 2,
319 VERASE = 3,
320 VWERASE = 4,
321 VKILL = 5,
322 VREPRINT = 6,
323 VERASE2 = 7,
324 VINTR = 8,
325 VQUIT = 9,
326 VSUSP = 10,
327 VDSUSP = 11,
328 VSTART = 12,
329 VSTOP = 13,
330 VLNEXT = 14,
331 VDISCARD = 15,
332 VMIN = 16,
333 VTIME = 17,
334 VSTATUS = 18,
335 };
336
337 export def TIOCGWINSZ: u64 = 0x40087468;
338 export def TIOCSWINSZ: u64 = 0x80087467;
339 export def TIOCGETA: u64 = 0x402c7413;
340 export def TIOCSETA: u64 = 0x802c7414;
341 export def TIOCPTSNAME: u64 = 0x48087448;
342 export def TIOCSPGRP: u64 = 0x80047476;
343 export def TIOCGPGRP: u64 = 0x40047477;
344 export def FIODGNAME: u64 = 0x80106678;
345
346 export type ptmget = struct {
347 cfd: int,
348 sfd: int,
349 cn: [PATH_MAX]u8,
350 sn: [PATH_MAX]u8,
351 };
352
353 export type rusage = struct {
354 // user time used
355 ru_utime: timeval,
356 // system time used
357 ru_stime: timeval,
358 // max resident set size
359 ru_maxrss: i64,
360 // integral shared memory size
361 ru_ixrss: i64,
362 // integral unshared data "
363 ru_idrss: i64,
364 // integral unshared stack "
365 ru_isrss: i64,
366 // page reclaims
367 ru_minflt: i64,
368 // page faults
369 ru_majflt: i64,
370 // swaps
371 ru_nswap: i64,
372 // block input operations
373 ru_inblock: i64,
374 // block output operations
375 ru_oublock: i64,
376 // messages sent
377 ru_msgsnd: i64,
378 // messages received
379 ru_msgrcv: i64,
380 // signals received
381 ru_nsignals: i64,
382 // voluntary context switches
383 ru_nvcsw: i64,
384 // involuntary "
385 ru_nivcsw: i64,
386 };
387
388 export def DT_UNKNOWN: u8 = 0;
389 export def DT_FIFO: u8 = 1;
390 export def DT_CHR: u8 = 2;
391 export def DT_DIR: u8 = 4;
392 export def DT_BLK: u8 = 6;
393 export def DT_REG: u8 = 8;
394 export def DT_LNK: u8 = 10;
395 export def DT_SOCK: u8 = 12;
396 export def DT_WHT: u8 = 14;
397
398 export def O_RDONLY: int = 0x0000;
399 export def O_WRONLY: int = 0x0001;
400 export def O_RDWR: int = 0x0002;
401 export def O_ACCMODE: int = 0x0003;
402 export def O_NONBLOCK: int = 0x0004;
403 export def O_APPEND: int = 0x0008;
404 export def O_SHLOCK: int = 0x0010;
405 export def O_EXLOCK: int = 0x0020;
406 export def O_ASYNC: int = 0x0040;
407 export def O_FSYNC: int = 0x0080;
408 export def O_SYNC: int = 0x0080;
409 export def O_NOFOLLOW: int = 0x0100;
410 export def O_CREAT: int = 0x0200;
411 export def O_TRUNC: int = 0x0400;
412 export def O_EXCL: int = 0x0800;
413 export def O_NOCTTY: int = 0x8000;
414 export def O_DIRECT: int = 0x00010000;
415 export def O_DIRECTORY: int = 0x00020000;
416 export def O_EXEC: int = 0x00040000;
417 export def O_TTY_INIT: int = 0x00080000;
418 export def O_CLOEXEC: int = 0x00400000;
419 export def O_DSYNC: int = 0x01000000;
420 export def O_RSYNC: int = 0x00020000;
421
422 export def AT_FDCWD: int = -100;
423 export def AT_EACCESS: int = 0x0100;
424 export def AT_SYMLINK_NOFOLLOW: int = 0x0200;
425 export def AT_SYMLINK_FOLLOW: int = 0x0400;
426 export def AT_REMOVEDIR: int = 0x0800;
427 export def AT_RESOLVE_BENEATH: int = 0x2000;
428
429 // set user id on execution
430 export def S_ISUID: u64 = 0o004000;
431 // set group id on execution
432 export def S_ISGID: u64 = 0o002000;
433 // sticky bit
434 export def S_ISTXT: u64 = 0o001000;
435 // RWX mask for owner
436 export def S_IRWXU: u64 = 0o000700;
437 // R for owner
438 export def S_IRUSR: u64 = 0o000400;
439 // W for owner
440 export def S_IWUSR: u64 = 0o000200;
441 // X for owner
442 export def S_IXUSR: u64 = 0o000100;
443 export def S_IREAD: u64 = S_IRUSR;
444 export def S_IWRITE: u64 = S_IWUSR;
445 export def S_IEXEC: u64 = S_IXUSR;
446 // RWX mask for group
447 export def S_IRWXG: u64 = 0o000070;
448 // R for group
449 export def S_IRGRP: u64 = 0o000040;
450 // W for group
451 export def S_IWGRP: u64 = 0o000020;
452 // X for group
453 export def S_IXGRP: u64 = 0o000010;
454 // RWX mask for other
455 export def S_IRWXO: u64 = 0o000007;
456 // R for other
457 export def S_IROTH: u64 = 0o000004;
458 // W for other
459 export def S_IWOTH: u64 = 0o000002;
460 // X for other
461 export def S_IXOTH: u64 = 0o000001;
462 // type of file mask
463 export def S_IFMT: u64 = 0o170000;
464 // named pipe (fifo)
465 export def S_IFIFO: u64 = 0o010000;
466 // character special
467 export def S_IFCHR: u64 = 0o020000;
468 // directory
469 export def S_IFDIR: u64 = 0o040000;
470 // block special
471 export def S_IFBLK: u64 = 0o060000;
472 // regular
473 export def S_IFREG: u64 = 0o100000;
474 // symbolic link
475 export def S_IFLNK: u64 = 0o120000;
476 // save swapped text even after use
477 export def S_ISVTX: u64 = 0o001000;
478 // socket
479 export def S_IFSOCK: u64 = 0o140000;
480 // whiteout
481 export def S_IFWHT: u64 = 0o160000;
482 // Archive state 1, ls -l shows 'a'
483 export def S_ARCH1: u64 = 0o200000;
484 // Archive state 2, ls -l shows 'A'
485 export def S_ARCH2: u64 = 0o400000;
486
487 export def MAP_SHARED: uint = 0x0001;
488 export def MAP_PRIVATE: uint = 0x0002;
489 export def MAP_FIXED: uint = 0x0010;
490 export def MAP_HASSEMAPHORE: uint = 0x0200;
491 export def MAP_STACK: uint = 0x0400;
492 export def MAP_NOSYNC: uint = 0x0800;
493 export def MAP_FILE: uint = 0x0000;
494 export def MAP_ANON: uint = 0x1000;
495 export def MAP_GUARD: uint = 0x00002000;
496 export def MAP_EXCL: uint = 0x00004000;
497 export def MAP_NOCORE: uint = 0x00020000;
498 export def MAP_PREFAULT_READ: uint = 0x00040000;
499 export def MAP_32BIT: uint = 0x00080000;
500
501 export def PROT_NONE: uint = 0x00;
502 export def PROT_READ: uint = 0x01;
503 export def PROT_WRITE: uint = 0x02;
504 export def PROT_EXEC: uint = 0x04;
505
506 export def SIGHUP: int = 1;
507 export def SIGINT: int = 2;
508 export def SIGQUIT: int = 3;
509 export def SIGILL: int = 4;
510 export def SIGTRAP: int = 5;
511 export def SIGABRT: int = 6;
512 export def SIGIOT: int = SIGABRT;
513 export def SIGEMT: int = 7;
514 export def SIGFPE: int = 8;
515 export def SIGKILL: int = 9;
516 export def SIGBUS: int = 10;
517 export def SIGSEGV: int = 11;
518 export def SIGSYS: int = 12;
519 export def SIGPIPE: int = 13;
520 export def SIGALRM: int = 14;
521 export def SIGTERM: int = 15;
522 export def SIGURG: int = 16;
523 export def SIGSTOP: int = 17;
524 export def SIGTSTP: int = 18;
525 export def SIGCONT: int = 19;
526 export def SIGCHLD: int = 20;
527 export def SIGTTIN: int = 21;
528 export def SIGTTOU: int = 22;
529 export def SIGIO: int = 23;
530 export def SIGXCPU: int = 24;
531 export def SIGXFSZ: int = 25;
532 export def SIGVTALRM: int = 26;
533 export def SIGPROF: int = 27;
534 export def SIGWINCH: int = 28;
535 export def SIGINFO: int = 29;
536 export def SIGUSR1: int = 30;
537 export def SIGUSR2: int = 31;
538 export def SIGTHR: int = 32;
539 export def SIGLWP: int = SIGTHR;
540 export def SIGLIBRT: int = 33;
541
542 export def F_DUPFD: int = 0;
543 export def F_GETFD: int = 1;
544 export def F_SETFD: int = 2;
545 export def F_GETFL: int = 3;
546 export def F_SETFL: int = 4;
547 export def F_GETOWN: int = 5;
548 export def F_SETOWN: int = 6;
549 export def F_OGETLK: int = 7;
550 export def F_OSETLK: int = 8;
551 export def F_OSETLKW: int = 9;
552 export def F_DUP2FD: int = 10;
553 export def F_GETLK: int = 11;
554 export def F_SETLK: int = 12;
555 export def F_SETLKW: int = 13;
556 export def F_SETLK_REMOTE: int = 14;
557 export def F_READAHEAD: int = 15;
558 export def F_RDAHEAD: int = 16;
559 export def F_DUPFD_CLOEXEC: int = 12;
560 export def F_DUP2FD_CLOEXEC: int = 18;
561 export def F_ADD_SEALS: int = 16;
562 export def F_GET_SEALS: int = 17;
563 export def F_ISUNIONSTACK: int = 21;
564
565 export def F_SEAL_SEAL: int = 0x0001;
566 export def F_SEAL_SHRINK: int = 0x0002;
567 export def F_SEAL_GROW: int = 0x0004;
568 export def F_SEAL_WRITE: int = 0x0008;
569
570 export def FD_CLOEXEC: int = 1;
571 export def F_UNLCKSYS: int = 4;
572 export def F_CANCEL: int = 5;
573
574 export def F_RDLCK: i16 = 1;
575 export def F_UNLCK: i16 = 2;
576 export def F_WRLCK: i16 = 3;
577
578 export def PRIO_PROCESS: int = 0;
579 export def PRIO_PGRP: int = 1;
580 export def PRIO_USER: int = 2;
581
582 export def F_OK: int = 0;
583 export def X_OK: int = 0x01;
584 export def W_OK: int = 0x02;
585 export def R_OK: int = 0x04;
586
587 export def CLOCK_REALTIME: int = 0;
588 export def CLOCK_VIRTUAL: int = 1;
589 export def CLOCK_PROF: int = 2;
590 export def CLOCK_MONOTONIC: int = 3;
591 export def CLOCK_THREAD_CPUTIME_ID: int = 0x20000000;
592 export def CLOCK_PROCESS_CPUTIME_ID: int = 0x40000000;
593
594 export def TIMER_ABSTIME: int = 1;
595
596 export def WNOHANG: int = 1;
597 export def WUNTRACED: int = 2;
598 export def WSTOPPED: int = WUNTRACED;
599 export def WCONTINUED: int = 4;
600 export def WNOWAIT: int = 8;
601 export def WEXITED: int = 16;
602 export def WTRAPPED: int = 32;
603
604 export def STDIN_FILENO: int = 0;
605 export def STDOUT_FILENO: int = 1;
606 export def STDERR_FILENO: int = 2;
607
608 export def SEEK_SET: int = 0;
609 export def SEEK_CUR: int = 1;
610 export def SEEK_END: int = 2;
611
612 // Flock operations
613 export def LOCK_SH: int = 1;
614 export def LOCK_EX: int = 2;
615 export def LOCK_NB: int = 4;
616 export def LOCK_UN: int = 8;
617
618 export type rlimit = struct {
619 rlim_cur: rlim_t,
620 rlim_max: rlim_t,
621 };
622
623 export def RLIM_INFINITY: rlim_t = -1;
624
625 export def RLIMIT_CPU: int = 0;
626 export def RLIMIT_FSIZE: int = 1;
627 export def RLIMIT_DATA: int = 2;
628 export def RLIMIT_STACK: int = 3;
629 export def RLIMIT_CORE: int = 4;
630 export def RLIMIT_RSS: int = 5;
631 export def RLIMIT_MEMLOCK: int = 6;
632 export def RLIMIT_NPROC: int = 7;
633 export def RLIMIT_NOFILE: int = 8;
634 export def RLIMIT_SBSIZE: int = 9;
635 export def RLIMIT_VMEM: int = 10;
636 export def RLIMIT_AS: int = RLIMIT_VMEM;
637 export def RLIMIT_NPTS: int = 11;
638 export def RLIMIT_SWAP: int = 12;
639 export def RLIMIT_KQUEUES: int = 13;
640 export def RLIMIT_UMTXP: int = 14;
641 // number of threads
642 export def RLIMIT_NTHR: int = 11;
643
644 export def SHUT_RD: int = 0;
645 export def SHUT_WR: int = 1;
646 export def SHUT_RDWR: int = 2;
647
648 // non-existent device
649 export def NODEV: int = -1;
650
651 // synchronously wait for I/O to complete
652 export def MNT_WAIT: int = 1;
653 // start all I/O, but do not wait for it
654 export def MNT_NOWAIT: int = 2;
655 // push data not written by filesystem syncer
656 export def MNT_LAZY: int = 3;
657
658 // Efficient memory file-system
659 export def MOUNT_TMPFS = "tmpfs";
660 export def MOUNT_SHMFS = MOUNT_TMPFS;
661
662 // Shared memory objects are supported using tmpfs.
663 export def SHMFS_DIR_PATH = "/var/shm";
664 export def SHMFS_DIR_MODE = (S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO);
665 export def SHMFS_OBJ_PREFIX = ".shmobj_";
666
667 // Signal
668 export def __SIGTRAMP_SIGINFO_VERSION = 2;
669
670 // Scheduling
671 export type sched_param = struct {
672 sched_priority: int
673 };
674 // Policies
675 export def SCHED_NONE: int = -1;
676 export def SCHED_OTHER: int = 0;
677 export def SCHED_FIFO: int = 1;
678 export def SCHED_RR: int = 2;
679 // a special lwpid, used in _sched_{g,s}etparam(), referring to all LWPs in the process
680 export def P_ALL_LWPS: lwpid_t = 0;