hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

types.ha (20527B)


      1 // License: MPL-2.0
      2 // (c) 2021 Alexey Yerin <yyp@disroot.org>
      3 // (c) 2021 Bor Grošelj Simić <bor.groseljsimic@telemach.net>
      4 // (c) 2021 Drew DeVault <sir@cmpwn.com>
      5 // (c) 2021 Eyal Sawady <ecs@d2evs.net>
      6 // (c) 2021 Kiëd Llaentenn <kiedtl@tilde.team>
      7 // (c) 2021 Mykyta Holubakha <hilobakho@gmail.com>
      8 // (c) 2022 Sebastian <sebastian@sebsite.pw>
      9 // (c) 2022 Vincent Dagonneau <v@vda.io>
     10 
     11 export type off_t = u64;
     12 export type dev_t = u64;
     13 export type ino_t = u64;
     14 export type nlink_t = u64;
     15 export type mode_t = uint;
     16 export type id_t = uint;
     17 export type uid_t = uint;
     18 export type gid_t = uint;
     19 export type time_t = i64;
     20 export type suseconds_t = i64;
     21 export type nfds_t = u64;
     22 export type pid_t = int;
     23 export type timer_t = int;
     24 export type clock_t = i64;
     25 export type si_band_t = i64;
     26 
     27 export def NSIG: int = 64;
     28 
     29 export type sigset = struct {
     30 	__val: [1]u64,
     31 };
     32 
     33 export type timeval = struct {
     34 	tv_sec:  time_t,
     35 	tv_usec: suseconds_t,
     36 };
     37 
     38 export type timespec = struct {
     39 	tv_sec:  time_t,
     40 	tv_nsec: i64,
     41 };
     42 
     43 export type itimerspec = struct {
     44 	it_interval: timespec,
     45 	it_value: timespec,
     46 };
     47 
     48 export def AT_FDCWD: int		= -100;
     49 export def AT_SYMLINK_NOFOLLOW: int	= 0x100;
     50 export def AT_REMOVEDIR: int		= 0x200;
     51 export def AT_SYMLINK_FOLLOW: int	= 0x400;
     52 export def AT_EACCESS: int		= 0x200;
     53 export def AT_NO_AUTOMOUNT: int		= 0x800;
     54 export def AT_EMPTY_PATH: int		= 0x1000;
     55 export def AT_STATX_SYNC_TYPE: int	= 0x6000;
     56 export def AT_STATX_SYNC_AS_STAT: int	= 0x0000;
     57 export def AT_STATX_FORCE_SYNC: int	= 0x2000;
     58 export def AT_STATX_DONT_SYNC: int	= 0x4000;
     59 export def AT_RECURSIVE: int		= 0x8000;
     60 
     61 export def S_IFDIR: mode_t = 0o040000;
     62 export def S_IFCHR: mode_t = 0o020000;
     63 export def S_IFBLK: mode_t = 0o060000;
     64 export def S_IFREG: mode_t = 0o100000;
     65 export def S_IFIFO: mode_t = 0o010000;
     66 export def S_IFLNK: mode_t = 0o120000;
     67 export def S_IFSOCK: mode_t = 0o140000;
     68 
     69 // O_DIRECTORY is arch specific
     70 export def O_RDONLY: int	= 0o0;
     71 export def O_WRONLY: int	= 0o1;
     72 export def O_RDWR: int		= 0o2;
     73 export def O_ACCMODE: int	= 0o3;
     74 export def O_CREATE: int	= 0o100;
     75 export def O_EXCLUSIVE: int	= 0o200;
     76 export def O_NOCTTY: int	= 0o400;
     77 export def O_TRUNC: int		= 0o1000;
     78 export def O_APPEND: int	= 0o2000;
     79 export def O_NONBLOCK: int	= 0o4000;
     80 export def O_DSYNC: int		= 0o10000;
     81 export def O_SYNC: int		= 0o4010000;
     82 export def O_RSYNC: int		= 0o4010000;
     83 export def O_NOFOLLOW: int	= 0o400000;
     84 export def O_NOATIME: int	= 0o1000000;
     85 export def O_CLOEXEC: int	= 0o2000000;
     86 export def O_PATH: int		= 0o10000000;
     87 export def O_TMPFILE: int	= 0o20000000;
     88 
     89 type statx_timestamp = struct {
     90 	tv_sec:  i64,
     91 	tv_nsec: u32,
     92 };
     93 
     94 type stx = struct {
     95 	mask:       u32,
     96 	blksize:    u32,
     97 	attributes: u64,
     98 	nlink:      u32,
     99 	uid:        u32,
    100 	gid:        u32,
    101 	mode:       u16,
    102 	ino:        u64,
    103 	sz:         u64,
    104 	blocks:     u64,
    105 	attr_mask:  u64,
    106 	atime:      statx_timestamp,
    107 	btime:      statx_timestamp,
    108 	ctime:      statx_timestamp,
    109 	mtime:      statx_timestamp,
    110 	rdev_major: u32,
    111 	rdev_minor: u32,
    112 	dev_major:  u32,
    113 	dev_minor:  u32,
    114 	__reserved: [14]u64,
    115 };
    116 
    117 // Note: the st type does not match the kernel API. The kernel API has a stat
    118 // buffer which varies from arch to arch, but because we always use statx(2) and
    119 // copy the data from the stx type, we don't have to deal with that nonsense.
    120 export type st = struct {
    121 	dev:    dev_t,
    122 	ino:    ino_t,
    123 	mode:   mode_t,
    124 	nlink:  nlink_t,
    125 	uid:    uid_t,
    126 	gid:    gid_t,
    127 	rdev:   dev_t,
    128 	sz:     u64,
    129 	blksz:  u64,
    130 	blocks: u64,
    131 	atime:  timespec,
    132 	mtime:  timespec,
    133 	ctime:  timespec,
    134 };
    135 
    136 def STATX_TYPE: uint		= 0x00000001;
    137 def STATX_MODE: uint		= 0x00000002;
    138 def STATX_NLINK: uint		= 0x00000004;
    139 def STATX_UID: uint		= 0x00000008;
    140 def STATX_GID: uint		= 0x00000010;
    141 def STATX_ATIME: uint		= 0x00000020;
    142 def STATX_MTIME: uint		= 0x00000040;
    143 def STATX_CTIME: uint		= 0x00000080;
    144 def STATX_INO: uint		= 0x00000100;
    145 def STATX_SIZE: uint		= 0x00000200;
    146 def STATX_BLOCKS: uint		= 0x00000400;
    147 def STATX_BASIC_STATS: uint	= 0x000007FF;
    148 def STATX_BTIME: uint		= 0x00000800;
    149 def STATX_MNT_ID: uint		= 0x00001000;
    150 
    151 export def SIGHUP: int		= 1;
    152 export def SIGINT: int		= 2;
    153 export def SIGQUIT: int		= 3;
    154 export def SIGILL: int		= 4;
    155 export def SIGTRAP: int		= 5;
    156 export def SIGABRT: int		= 6;
    157 export def SIGBUS: int		= 7;
    158 export def SIGFPE: int		= 8;
    159 export def SIGKILL: int		= 9;
    160 export def SIGUSR1: int		= 10;
    161 export def SIGSEGV: int		= 11;
    162 export def SIGUSR2: int		= 12;
    163 export def SIGPIPE: int		= 13;
    164 export def SIGALRM: int		= 14;
    165 export def SIGTERM: int		= 15;
    166 export def SIGSTKFLT: int	= 16;
    167 export def SIGCHLD: int		= 17;
    168 export def SIGCONT: int		= 18;
    169 export def SIGSTOP: int		= 19;
    170 export def SIGTSTP: int		= 20;
    171 export def SIGTTIN: int		= 21;
    172 export def SIGTTOU: int		= 22;
    173 export def SIGURG: int		= 23;
    174 export def SIGXCPU: int		= 24;
    175 export def SIGXFSZ: int		= 25;
    176 export def SIGVTALRM: int	= 26;
    177 export def SIGPROF: int		= 27;
    178 export def SIGWINCH: int	= 28;
    179 export def SIGIO: int		= 29;
    180 export def SIGPOLL: int		= 29;
    181 export def SIGPWR: int		= 30;
    182 export def SIGSYS: int		= 31;
    183 
    184 export def MAP_SHARED: uint		= 0x01;
    185 export def MAP_PRIVATE: uint		= 0x02;
    186 export def MAP_SHARED_VALIDATE: uint	= 0x03;
    187 export def MAP_FIXED: uint		= 0x10;
    188 export def MAP_ANON: uint		= 0x20;
    189 export def MAP_NORESERVE: uint		= 0x4000;
    190 export def MAP_GROWSDOWN: uint		= 0x0100;
    191 export def MAP_DENYWRITE: uint		= 0x0800;
    192 export def MAP_EXECUTABLE: uint		= 0x1000;
    193 export def MAP_LOCKED: uint		= 0x2000;
    194 export def MAP_POPULATE: uint		= 0x8000;
    195 export def MAP_NONBLOCK: uint		= 0x10000;
    196 export def MAP_STACK: uint		= 0x20000;
    197 export def MAP_HUGETLB: uint		= 0x40000;
    198 export def MAP_SYNC: uint		= 0x80000;
    199 export def MAP_FIXED_NOREPLACE: uint	= 0x100000;
    200 export def MAP_FILE: uint		= 0;
    201 export def MAP_HUGE_SHIFT: uint		= 26;
    202 export def MAP_HUGE_MASK: uint		= 0x3F;
    203 export def MAP_HUGE_64KB: uint		= 16 << 26;
    204 export def MAP_HUGE_512KB: uint		= 19 << 26;
    205 export def MAP_HUGE_1MB: uint		= 20 << 26;
    206 export def MAP_HUGE_2MB: uint		= 21 << 26;
    207 export def MAP_HUGE_8MB: uint		= 23 << 26;
    208 export def MAP_HUGE_16MB: uint		= 24 << 26;
    209 export def MAP_HUGE_32MB: uint		= 25 << 26;
    210 export def MAP_HUGE_256MB: uint		= 28 << 26;
    211 export def MAP_HUGE_512MB: uint		= 29 << 26;
    212 export def MAP_HUGE_1GB: uint		= 30 << 26;
    213 export def MAP_HUGE_2GB: uint		= 31 << 26;
    214 export def MAP_HUGE_16GB: uint		= 34 << 26;
    215 
    216 export def PROT_NONE: uint	= 0;
    217 export def PROT_READ: uint 	= 1;
    218 export def PROT_WRITE: uint	= 2;
    219 export def PROT_EXEC: uint	= 4;
    220 export def PROT_GROWSDOWN: uint	= 0x01000000;
    221 export def PROT_GROWSUP: uint	= 0x02000000;
    222 
    223 export def F_OK: int = 0;
    224 export def R_OK: int = 4;
    225 export def W_OK: int = 2;
    226 export def X_OK: int = 1;
    227 
    228 export def F_DUPFD: int = 0;
    229 export def F_DUPFD_CLOEXEC: int = 1030;
    230 export def F_GETFD: int = 1;
    231 export def F_SETFD: int = 2;
    232 export def F_GETFL: int = 3;
    233 export def F_SETFL: int = 4;
    234 export def F_SETOWN: int = 8;
    235 export def F_GETOWN: int = 9;
    236 export def F_SETSIG: int = 10;
    237 export def F_GETSIG: int = 11;
    238 export def F_GETLK: int = 12;
    239 export def F_SETLK: int = 13;
    240 export def F_SETLKW: int = 14;
    241 export def F_SETOWN_EX: int = 15;
    242 export def F_GETOWN_EX: int = 16;
    243 export def F_GETOWNER_UIDS: int = 17;
    244 
    245 export def F_RDLCK: i16 = 0;
    246 export def F_WRLCK: i16 = 1;
    247 export def F_UNLCK: i16 = 2;
    248 
    249 export def FD_CLOEXEC: int = 1;
    250 
    251 export type st_flock = struct {
    252 	l_type: i16,
    253 	l_whence: i16,
    254 	l_start: i64,
    255 	l_len: i64,
    256 	pid: int,
    257 };
    258 
    259 export type f_owner_ex = struct {
    260 	_type: int,
    261 	pid: int,
    262 };
    263 
    264 export def CLOCK_REALTIME: int			= 0;
    265 export def CLOCK_MONOTONIC: int			= 1;
    266 export def CLOCK_PROCESS_CPUTIME_ID: int	= 2;
    267 export def CLOCK_THREAD_CPUTIME_ID: int		= 3;
    268 export def CLOCK_MONOTONIC_RAW: int		= 4;
    269 export def CLOCK_REALTIME_COARSE: int		= 5;
    270 export def CLOCK_MONOTONIC_COARSE: int		= 6;
    271 export def CLOCK_BOOTTIME: int			= 7;
    272 export def CLOCK_REALTIME_ALARM: int		= 8;
    273 export def CLOCK_BOOTTIME_ALARM: int		= 9;
    274 export def CLOCK_SGI_CYCLE: int			= 10;
    275 export def CLOCK_TAI: int			= 11;
    276 
    277 export type open_how = struct {
    278 	flags: u64,
    279 	mode: u64,
    280 	resolve: u64,
    281 };
    282 
    283 export def RESOLVE_NO_XDEV: u64		= 0x01;
    284 export def RESOLVE_NO_MAGICLINKS: u64	= 0x02;
    285 export def RESOLVE_NO_SYMLINKS: u64	= 0x04;
    286 export def RESOLVE_BENEATH: u64		= 0x08;
    287 export def RESOLVE_IN_ROOT: u64		= 0x10;
    288 
    289 export def DT_UNKNOWN: u8	= 0;
    290 export def DT_FIFO: u8		= 1;
    291 export def DT_CHR: u8		= 2;
    292 export def DT_DIR: u8		= 4;
    293 export def DT_BLK: u8		= 6;
    294 export def DT_REG: u8		= 8;
    295 export def DT_LNK: u8		= 10;
    296 export def DT_SOCK: u8		= 12;
    297 
    298 export type dirent64 = struct {
    299 	d_ino: ino_t,
    300 	d_off: off_t,
    301 	d_reclen: u16,
    302 	d_type: u8,
    303 	d_name: [*]char,
    304 };
    305 
    306 export def WNOHANG: int		= 1;
    307 export def WUNTRACED: int	= 2;
    308 export def WSTOPPED: int	= 2;
    309 export def WEXITED: int		= 4;
    310 export def WCONTINUED: int	= 8;
    311 export def WNOWAIT: int		= 0x1000000;
    312 
    313 export fn wexitstatus(s: int) int = (s & 0xff00) >> 8;
    314 export fn wtermsig(s: int) int = s & 0x7f;
    315 export fn wstopsig(s: int) int = wexitstatus(s);
    316 export fn wcoredump(s: int) int = s & 0x80;
    317 export fn wifexited(s: int) bool = wtermsig(s) <= 0;
    318 export fn wifstopped(s: int) bool = (((s & 0xFFFF) * 0x10001) >> 8) > 0x7f00;
    319 export fn wifsignaled(s: int) bool = (s & 0xFFFF) - 1 < 0xFF;
    320 export fn wifcontinued(s: int) bool = s == 0xFFFF;
    321 
    322 export type rusage = struct {
    323 	ru_utime: timeval,
    324 	ru_stime: timeval,
    325 	ru_maxrss: u64,
    326 	ru_ixrss: u64,
    327 	ru_idrss: u64,
    328 	ru_isrss: u64,
    329 	ru_minflt: u64,
    330 	ru_majflt: u64,
    331 	ru_nswap: u64,
    332 	ru_inblock: u64,
    333 	ru_oublock: u64,
    334 	ru_msgsnd: u64,
    335 	ru_msgrcv: u64,
    336 	ru_nsignals: u64,
    337 	ru_nvcsw: u64,
    338 	ru_nivcsw: u64,
    339 	__reserved: [16]u64,
    340 };
    341 
    342 export type utsname = struct {
    343 	sysname:    [65]char,
    344 	nodename:   [65]char,
    345 	release:    [65]char,
    346 	version:    [65]char,
    347 	machine:    [65]char,
    348 	domainname: [65]char,
    349 };
    350 
    351 export def POLLIN: i16 = 0x001;
    352 export def POLLPRI: i16 = 0x002;
    353 export def POLLOUT: i16 = 0x004;
    354 export def POLLERR: i16 = 0x008;
    355 export def POLLHUP: i16 = 0x010;
    356 export def POLLVAL: i16 = 0x020;
    357 
    358 export type pollfd = struct {
    359 	fd: int,
    360 	events: i16,
    361 	revents: i16,
    362 };
    363 
    364 export def EPOLL_CLOEXEC: int = O_CLOEXEC;
    365 
    366 // Valid opcodes to issue to sys_epoll_ctl()
    367 export def EPOLL_CTL_ADD: int = 1;
    368 export def EPOLL_CTL_DEL: int = 2;
    369 export def EPOLL_CTL_MOD: int = 3;
    370 
    371 // Epoll event masks
    372 export def EPOLLIN: u32 = 0x00000001;
    373 export def EPOLLPRI: u32 = 0x00000002;
    374 export def EPOLLOUT: u32 = 0x00000004;
    375 export def EPOLLERR: u32 = 0x00000008;
    376 export def EPOLLHUP: u32 = 0x00000010;
    377 export def EPOLLNVAL: u32 = 0x00000020;
    378 export def EPOLLRDNORM: u32 = 0x00000040;
    379 export def EPOLLRDBAND: u32 = 0x00000080;
    380 export def EPOLLWRNORM: u32 = 0x00000100;
    381 export def EPOLLWRBAND: u32 = 0x00000200;
    382 export def EPOLLMSG: u32 = 0x00000400;
    383 export def EPOLLRDHUP: u32 = 0x00002000;
    384 export def EPOLLWAKEUP: u32 = 1 << 29;
    385 export def EPOLLONESHOT: u32 = 1 << 30;
    386 export def EPOLLET: u32 = 1 << 31;
    387 
    388 export type epoll_data = union {
    389 	ptr: *void,
    390 	fd: int,
    391 	u32_: u32,
    392 	u64_: u64,
    393 };
    394 
    395 export type epoll_event = struct {
    396 	events: u32,
    397 	@offset(4) data: epoll_data,
    398 };
    399 
    400 export def EFD_CLOEXEC: int = O_CLOEXEC;
    401 export def EFD_NONBLOCK: int = O_NONBLOCK;
    402 export def EFD_SEMAPHORE: int = 1;
    403 
    404 export def TFD_TIMER_ABSTIME: int = 1;
    405 export def TFD_TIMER_CANCEL_ON_SET: int = 2;
    406 
    407 export def SIG_BLOCK: int = 0;
    408 export def SIG_UNBLOCK: int = 1;
    409 export def SIG_SETMASK: int = 2;
    410 
    411 def SI_MAX_SIZE: size = 128;
    412 
    413 export type sigval = union {
    414 	sival_t: int,
    415 	sival_ptr: *void,
    416 };
    417 
    418 export type siginfo = union {
    419 	struct {
    420 		si_signo: int,
    421 		si_errno: int,
    422 		si_code: int,
    423 
    424 		union {
    425 			// kill()
    426 			struct {
    427 				si_pid: pid_t,
    428 				si_uid: u32,
    429 			},
    430 
    431 			// POSIX.1b timers
    432 			struct {
    433 				si_tid: timer_t,
    434 				si_overrun: int,
    435 				_sigval: sigval, // @ signals
    436 				si_sys_private: int,
    437 			},
    438 
    439 			// POSIX.1b signals
    440 			struct {
    441 				_sig_pid: pid_t, // @kill
    442 				_sig_uid: u32, // @ kill
    443 				union {
    444 					si_value: sigval,
    445 					si_int: int,
    446 					si_ptr: *void,
    447 				}
    448 			},
    449 
    450 			// SIGCHLD
    451 			struct {
    452 				_chld_pid: pid_t, // @ kill
    453 				_chld_uid: u32, // @ kill
    454 				si_status: int,
    455 				si_utime: clock_t,
    456 				si_stime: clock_t,
    457 			},
    458 
    459 			// SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT
    460 			struct {
    461 				si_addr: *void,
    462 
    463 				union {
    464 					// used when si_code=BUS_MCEERR_AR or
    465 					// used when si_code=BUS_MCEERR_AO
    466 					si_addr_lsb: i16,
    467 
    468 					struct {
    469 						_dummy_bnd: [__ADDR_BND_PKEY_PAD]u8,
    470 						si_lower: *void,
    471 						si_upper: *void,
    472 					},
    473 
    474 					struct {
    475 						_dummy_pkey: [__ADDR_BND_PKEY_PAD]u8,
    476 						si_pkey: u32,
    477 					},
    478 				},
    479 			},
    480 
    481 			// SIGPOLL
    482 			struct {
    483 				si_band: si_band_t,
    484 				si_fd: int,
    485 			},
    486 
    487 			// SIGSYS
    488 			struct {
    489 				si_call_addr: *void,
    490 				si_syscall: int,
    491 				si_arch: uint,
    492 			},
    493 		},
    494 	},
    495 	_si_pad: [SI_MAX_SIZE - 3 * size(int)]u8,
    496 };
    497 
    498 export def SA_NOCLDSTOP: u64 = 0x00000001;
    499 export def SA_NOCLDWAIT: u64 = 0x00000002;
    500 export def SA_SIGINFO: u64 = 0x00000004;
    501 export def SA_ONSTACK: u64 = 0x08000000;
    502 export def SA_RESTART: u64 = 0x10000000;
    503 export def SA_NODEFER: u64 = 0x40000000;
    504 export def SA_RESETHAND: u64 = 0x80000000;
    505 export def SA_NOMASK: u64 = SA_NODEFER;
    506 export def SA_ONESHOT: u64 = SA_RESETHAND;
    507 export def SA_RESTORER: u64 = 0x04000000;
    508 
    509 export type sigact = struct {
    510 	union {
    511 		sa_handler: *fn (_: int) void,
    512 		sa_sigaction: *fn (_: int, _: *siginfo, _: *void) void,
    513 	},
    514 	sa_flags: u64,
    515 	sa_restorer: *fn () void,
    516 	sa_mask: sigset,
    517 };
    518 
    519 export def SFD_NONBLOCK: int = O_NONBLOCK;
    520 export def SFD_CLOEXEC: int = O_CLOEXEC;
    521 
    522 export type signalfd_siginfo = struct {
    523 	ssi_signo: u32,
    524 	ssi_errno: i32,
    525 	ssi_code: i32,
    526 	ssi_pid: u32,
    527 	ssi_uid: u32,
    528 	ssi_fd: i32 ,
    529 	ssi_tid: u32,
    530 	ssi_band: u32,
    531 	ssi_overrun: u32,
    532 	ssi_trapno: u32,
    533 	ssi_status: i32,
    534 	ssi_int: i32,
    535 	ssi_ptr: u64,
    536 	ssi_utime: u64,
    537 	ssi_stime: u64,
    538 	ssi_addr: u64,
    539 	ssi_addr_lsb: u16,
    540 	__pad2: u16,
    541 	ssi_syscall: i32,
    542 	ssi_call_addr: u64,
    543 	ssi_arch: u32,
    544 
    545 	__pad: [28]u8, // pad to 128 bytes
    546 };
    547 
    548 export type iovec = struct {
    549 	iov_base: *void,
    550 	iov_len: size
    551 };
    552 
    553 export def PRIO_PROCESS: int = 0;
    554 export def PRIO_PGRP: int = 1;
    555 export def PRIO_USER: int = 2;
    556 
    557 export type winsize = struct {
    558 	ws_row: u16,
    559 	ws_col: u16,
    560 	ws_xpixel: u16,
    561 	ws_ypixel: u16,
    562 };
    563 
    564 export type termios = struct {
    565 	c_iflag: tcflag,
    566 	c_oflag: tcflag,
    567 	c_cflag: tcflag,
    568 	c_lflag: tcflag,
    569 	c_line: cc,
    570 	c_cc: [NCCS]cc,
    571 };
    572 
    573 export def NCCS: size = 19;
    574 
    575 export type cc = enum char {
    576 	VINTR    = 0,
    577 	VQUIT    = 1,
    578 	VERASE   = 2,
    579 	VKILL    = 3,
    580 	VEOF     = 4,
    581 	VTIME    = 5,
    582 	VMIN     = 6,
    583 	VSWTC    = 7,
    584 	VSTART   = 8,
    585 	VSTOP    = 9,
    586 	VSUSP    = 10,
    587 	VEOL     = 11,
    588 	VREPRINT = 12,
    589 	VDISCARD = 13,
    590 	VWERASE  = 14,
    591 	VLNEXT   = 15,
    592 	VEOL2    = 16,
    593 };
    594 
    595 export type tcflag = enum uint {
    596 	// c_iflag bit meaning
    597 	IGNBRK  = 0o00001,
    598 	BRKINT  = 0o00002,
    599 	IGNPAR  = 0o00004,
    600 	PARMRK  = 0o00010,
    601 	INPCK   = 0o00020,
    602 	ISTRIP  = 0o00040,
    603 	INLCR   = 0o00100,
    604 	IGNCR   = 0o00200,
    605 	ICRNL   = 0o00400,
    606 	IUCLC   = 0o01000,
    607 	IXON    = 0o02000,
    608 	IXANY   = 0o04000,
    609 	IXOFF   = 0o10000,
    610 	IMAXBEL = 0o20000,
    611 	IUTF8   = 0o40000,
    612 
    613 	// c_oflag bit meaning
    614 	OPOST  = 0o000001,
    615 	OLCUC  = 0o000002,
    616 	ONLCR  = 0o000004,
    617 	OCRNL  = 0o000010,
    618 	ONOCR  = 0o000020,
    619 	ONLRET = 0o000040,
    620 	OFILL  = 0o000100,
    621 	OFDEL  = 0o000200,
    622 	NLDLY  = 0o000400,
    623 	NL0    = 0o000000,
    624 	NL1    = 0o000400,
    625 	CRDLY  = 0o003000,
    626 	CR0    = 0o000000,
    627 	CR1    = 0o001000,
    628 	CR2    = 0o002000,
    629 	CR3    = 0o003000,
    630 	TABDLY = 0o014000,
    631 	TAB0   = 0o000000,
    632 	TAB1   = 0o004000,
    633 	TAB2   = 0o010000,
    634 	TAB3   = 0o014000,
    635 	XTABS  = 0o014000,
    636 	BSDLY  = 0o020000,
    637 	BS0    = 0o000000,
    638 	BS1    = 0o020000,
    639 	VTDLY  = 0o040000,
    640 	VT0    = 0o000000,
    641 	VT1    = 0o040000,
    642 	FFDLY  = 0o100000,
    643 	FF0    = 0o000000,
    644 	FF1    = 0o100000,
    645 
    646 	// c_cflag bit meaning
    647 	CBAUD    = 0o010017,
    648 	B0       = 0o000000,
    649 	B50      = 0o000001,
    650 	B75      = 0o000002,
    651 	B110     = 0o000003,
    652 	B134     = 0o000004,
    653 	B150     = 0o000005,
    654 	B200     = 0o000006,
    655 	B300     = 0o000007,
    656 	B600     = 0o000010,
    657 	B1200    = 0o000011,
    658 	B1800    = 0o000012,
    659 	B2400    = 0o000013,
    660 	B4800    = 0o000014,
    661 	B9600    = 0o000015,
    662 	B19200   = 0o000016,
    663 	B38400   = 0o000017,
    664 	EXTA     = B19200,
    665 	EXTB     = B38400,
    666 	CSIZE    = 0o000060,
    667 	CS5      = 0o000000,
    668 	CS6      = 0o000020,
    669 	CS7      = 0o000040,
    670 	CS8      = 0o000060,
    671 	CSTOPB   = 0o000100,
    672 	CREAD    = 0o000200,
    673 	PARENB   = 0o000400,
    674 	PARODD   = 0o001000,
    675 	HUPCL    = 0o002000,
    676 	CLOCAL   = 0o004000,
    677 	CBAUDEX  = 0o010000,
    678 	BOTHER   = 0o010000,
    679 	B57600   = 0o010001,
    680 	B115200  = 0o010002,
    681 	B230400  = 0o010003,
    682 	B460800  = 0o010004,
    683 	B500000  = 0o010005,
    684 	B576000  = 0o010006,
    685 	B921600  = 0o010007,
    686 	B1000000 = 0o010010,
    687 	B1152000 = 0o010011,
    688 	B1500000 = 0o010012,
    689 	B2000000 = 0o010013,
    690 	B2500000 = 0o010014,
    691 	B3000000 = 0o010015,
    692 	B3500000 = 0o010016,
    693 	B4000000 = 0o010017,
    694 	CIBAUD   = 0o02003600000,
    695 	CMSPAR   = 0o10000000000,
    696 	CRTSCTS  = 0o20000000000,
    697 
    698 	// c_lflag bit meaning
    699 	ISIG    = 0o000001,
    700 	ICANON  = 0o000002,
    701 	XCASE   = 0o000004,
    702 	ECHO    = 0o000010,
    703 	ECHOE   = 0o000020,
    704 	ECHOK   = 0o000040,
    705 	ECHONL  = 0o000100,
    706 	NOFLSH  = 0o000200,
    707 	TOSTOP  = 0o000400,
    708 	ECHOCTL = 0o001000,
    709 	ECHOPRT = 0o002000,
    710 	ECHOKE  = 0o004000,
    711 	FLUSHO  = 0o010000,
    712 	PENDIN  = 0o040000,
    713 	IEXTEN  = 0o100000,
    714 	EXTPROC = 0o200000,
    715 };
    716 
    717 
    718 export def TIOCGWINSZ: u64 = 0x5413;
    719 export def TIOCSWINSZ: u64 = 0x5414;
    720 export def TIOCSCTTY: u64 = 0x540e;
    721 export def TIOCNOTTY: u64 = 0x5422;
    722 export def TIOCGPTN: u64 = 0x80045430;
    723 export def TIOCGPTPEER: u64 = 0x5441;
    724 export def TIOCSPTLCK: u64 = 0x40045431;
    725 export def TCGETS: u64 = 0x5401;
    726 export def TCSETS: u64 = 0x5402;
    727 
    728 export def MLOCK_ONFAULT: uint = 0x01;
    729 
    730 export def MCL_CURRENT: int = 1;
    731 export def MCL_FUTURE: int = 2;
    732 export def MCL_ONFAULT: int = 4;
    733 
    734 export def PTRACE_TRACEME: int = 0;
    735 export def PTRACE_PEEKTEXT: int = 1;
    736 export def PTRACE_PEEKDATA: int = 2;
    737 export def PTRACE_PEEKUSER: int = 3;
    738 export def PTRACE_POKETEXT: int = 4;
    739 export def PTRACE_POKEDATA: int = 5;
    740 export def PTRACE_POKEUSER: int = 6;
    741 export def PTRACE_CONT: int = 7;
    742 export def PTRACE_KILL: int = 8;
    743 export def PTRACE_SINGLESTEP: int = 9;
    744 export def PTRACE_GETREGS: int = 12;
    745 export def PTRACE_SETREGS: int = 13;
    746 export def PTRACE_GETFPREGS: int = 14;
    747 export def PTRACE_SETFPREGS: int = 15;
    748 export def PTRACE_ATTACH: int = 16;
    749 export def PTRACE_DETACH: int = 17;
    750 export def PTRACE_GETFPXREGS: int = 18;
    751 export def PTRACE_SETFPXREGS: int = 19;
    752 export def PTRACE_SYSCALL: int = 24;
    753 export def PTRACE_SETOPTIONS: int = 0x4200;
    754 export def PTRACE_GETEVENTMSG: int = 0x4201;
    755 export def PTRACE_GETSIGINFO: int = 0x4202;
    756 export def PTRACE_SETSIGINFO: int = 0x4203;
    757 export def PTRACE_GETREGSET: int = 0x4204;
    758 export def PTRACE_SETREGSET: int = 0x4205;
    759 export def PTRACE_SEIZE: int = 0x4206;
    760 export def PTRACE_INTERRUPT: int = 0x4207;
    761 export def PTRACE_LISTEN: int = 0x4208;
    762 export def PTRACE_PEEKSIGINFO: int = 0x4209;
    763 export def PTRACE_GETSIGMASK: int = 0x420a;
    764 export def PTRACE_SETSIGMASK: int = 0x420b;
    765 export def PTRACE_SECCOMP_GET_FILTER: int = 0x420c;
    766 export def PTRACE_SECCOMP_GET_METADATA: int = 0x420d;
    767 export def PTRACE_GET_SYSCALL_INFO: int = 0x420e;
    768 export def PTRACE_GET_RSEQ_CONFIGURATION: int =	0x420f;
    769 
    770 export def PTRACE_O_TRACESYSGOOD: u64 = 0x00000001;
    771 export def PTRACE_O_TRACEFORK: u64 = 0x00000002;
    772 export def PTRACE_O_TRACEVFORK: u64 = 0x00000004;
    773 export def PTRACE_O_TRACECLONE: u64 = 0x00000008;
    774 export def PTRACE_O_TRACEEXEC: u64 = 0x00000010;
    775 export def PTRACE_O_TRACEVFORKDONE: u64 = 0x00000020;
    776 export def PTRACE_O_TRACEEXIT: u64 = 0x00000040;
    777 export def PTRACE_O_TRACESECCOMP: u64 = 0x00000080;
    778 export def PTRACE_O_EXITKILL: u64 = 0x00100000;
    779 export def PTRACE_O_SUSPEND_SECCOMP: u64 = 0x00200000;
    780 export def PTRACE_O_MASK: u64 = 0x003000ff;
    781 
    782 export def PTRACE_EVENT_FORK: int = 1;
    783 export def PTRACE_EVENT_VFORK: int = 2;
    784 export def PTRACE_EVENT_CLONE: int = 3;
    785 export def PTRACE_EVENT_EXEC: int = 4;
    786 export def PTRACE_EVENT_VFORK_DONE: int = 5;
    787 export def PTRACE_EVENT_EXIT: int = 6;
    788 export def PTRACE_EVENT_SECCOMP: int = 7;
    789 export def PTRACE_EVENT_STOP: int = 128;
    790 
    791 export def PTRACE_SYSCALL_INFO_NONE: u8 = 0;
    792 export def PTRACE_SYSCALL_INFO_ENTRY: u8 = 1;
    793 export def PTRACE_SYSCALL_INFO_EXIT: u8 = 2;
    794 export def PTRACE_SYSCALL_INFO_SECCOMP: u8 = 3;
    795 
    796 export def PTRACE_PEEKSIGINFO_SHARED: u32 = 1;
    797 
    798 export type ptrace_peeksiginfo_args = struct {
    799 	off: u64,
    800 	flags: u32,
    801 	nr: i32,
    802 };
    803 
    804 export type ptrace_syscall_info = struct {
    805 	op: u8,
    806 	arch: u32,
    807 	instruction_pointer: u64,
    808 	stack_pointer: u64,
    809 	union {
    810 		entry: struct {
    811 			nr: u64,
    812 			args: [6]u64,
    813 		},
    814 		exit: struct {
    815 			rval: i64,
    816 			is_error: u8,
    817 		},
    818 		seccomp: struct {
    819 			nr: u64,
    820 			args: [6]u64,
    821 			ret_data: u64,
    822 		},
    823 	},
    824 };
    825 
    826 export def STDIN_FILENO: int = 0;
    827 export def STDOUT_FILENO: int = 1;
    828 export def STDERR_FILENO: int = 2;