Jelajahi Sumber

Merge pull request #2917 from flysand7/sys-linux-additions

[sys/linux]: Fixes and additions
gingerBill 1 tahun lalu
induk
melakukan
87c835268a
4 mengubah file dengan 1883 tambahan dan 343 penghapusan
  1. 423 65
      core/sys/linux/bits.odin
  2. 166 29
      core/sys/linux/constants.odin
  3. 548 176
      core/sys/linux/sys.odin
  4. 746 73
      core/sys/linux/types.odin

+ 423 - 65
core/sys/linux/bits.odin

@@ -1,7 +1,9 @@
 package linux
 package linux
 
 
 
 
-/// Represents an error returned by most of syscalls
+/*
+	Represents an error returned by most of syscalls
+*/
 Errno :: enum i32 {
 Errno :: enum i32 {
 	NONE = 0,
 	NONE = 0,
 	// Errno-base
 	// Errno-base
@@ -142,8 +144,9 @@ Errno :: enum i32 {
 	EDEADLOCK       = EDEADLK,
 	EDEADLOCK       = EDEADLK,
 }
 }
 
 
-
-/// Bits for Open_Flags
+/*
+	Bits for Open_Flags
+*/
 Open_Flags_Bits :: enum {
 Open_Flags_Bits :: enum {
 	RDONLY    = 0,
 	RDONLY    = 0,
 	WRONLY    = 1,
 	WRONLY    = 1,
@@ -164,7 +167,9 @@ Open_Flags_Bits :: enum {
 	PATH      = 21,
 	PATH      = 21,
 }
 }
 
 
-/// Bits for FD_Flags bitset
+/*
+	Bits for FD_Flags bitset
+*/
 FD_Flags_Bits :: enum {
 FD_Flags_Bits :: enum {
 	SYMLINK_NOFOLLOW   = 8,
 	SYMLINK_NOFOLLOW   = 8,
 	REMOVEDIR          = 9,
 	REMOVEDIR          = 9,
@@ -177,7 +182,9 @@ FD_Flags_Bits :: enum {
 	RECURSIVE          = 15,
 	RECURSIVE          = 15,
 }
 }
 
 
-/// The bits for the Mode bitset.
+/*
+	The bits for the Mode bitset.
+*/
 Mode_Bits :: enum {
 Mode_Bits :: enum {
 	IXOTH  = 0,  // 0o0000001
 	IXOTH  = 0,  // 0o0000001
 	IWOTH  = 1,  // 0o0000002
 	IWOTH  = 1,  // 0o0000002
@@ -197,7 +204,9 @@ Mode_Bits :: enum {
 	IFREG  = 15, // 0o0100000
 	IFREG  = 15, // 0o0100000
 }
 }
 
 
-/// The bits used by the Statx_Mask bitset
+/*
+	The bits used by the Statx_Mask bitset
+*/
 Statx_Mask_Bits :: enum {
 Statx_Mask_Bits :: enum {
 	TYPE         = 0,
 	TYPE         = 0,
 	MODE         = 1,
 	MODE         = 1,
@@ -215,8 +224,10 @@ Statx_Mask_Bits :: enum {
 	DIOALIGN     = 13,
 	DIOALIGN     = 13,
 }
 }
 
 
-/// Bits found in Statx_Attr bitset
-/// You should not use these directly
+/*
+	Bits found in Statx_Attr bitset
+	You should not use these directly
+*/
 Statx_Attr_Bits :: enum {
 Statx_Attr_Bits :: enum {
 	COMPRESSED = 2,  // 0x00000004
 	COMPRESSED = 2,  // 0x00000004
 	IMMUTABLE  = 4,  // 0x00000010
 	IMMUTABLE  = 4,  // 0x00000010
@@ -229,7 +240,9 @@ Statx_Attr_Bits :: enum {
 	DAX        = 21, // 0x00200000
 	DAX        = 21, // 0x00200000
 }
 }
 
 
-/// Magic bits for filesystems returned by Stat_FS
+/*
+	Magic bits for filesystems returned by Stat_FS
+*/
 FS_Magic :: enum u32 {
 FS_Magic :: enum u32 {
 	ADFS_SUPER_MAGIC      = 0xadf5,
 	ADFS_SUPER_MAGIC      = 0xadf5,
 	AFFS_SUPER_MAGIC      = 0xadff,
 	AFFS_SUPER_MAGIC      = 0xadff,
@@ -317,7 +330,9 @@ FS_Magic :: enum u32 {
 	_XIAFS_SUPER_MAGIC    = 0x012fd16d,
 	_XIAFS_SUPER_MAGIC    = 0x012fd16d,
 }
 }
 
 
-/// Bits for FS_Flags bitset
+/*
+	Bits for FS_Flags bitset
+*/
 FS_Flags_Bits :: enum {
 FS_Flags_Bits :: enum {
 	RDONLY       = 0,
 	RDONLY       = 0,
 	NOSUID       = 1,
 	NOSUID       = 1,
@@ -340,20 +355,26 @@ Seek_Whence :: enum i16 {
 	HOLE = 4,
 	HOLE = 4,
 }
 }
 
 
-/// Bits for Close_Range_Flags
+/*
+	Bits for Close_Range_Flags
+*/
 Close_Range_Flags_Bits :: enum {
 Close_Range_Flags_Bits :: enum {
 	CLOEXEC = 2,
 	CLOEXEC = 2,
 	UNSHARE = 1,
 	UNSHARE = 1,
 }
 }
 
 
-/// Bits for Rename_Flags
+/*
+	Bits for Rename_Flags
+*/
 Rename_Flags_Bits :: enum {
 Rename_Flags_Bits :: enum {
 	EXCHANGE  = 1,
 	EXCHANGE  = 1,
 	NOREPLACE = 0,
 	NOREPLACE = 0,
 	WHITEOUT  = 2,
 	WHITEOUT  = 2,
 }
 }
 
 
-/// Type of the file in a directory entry
+/*
+	Type of the file in a directory entry
+*/
 Dirent_Type :: enum u8 {
 Dirent_Type :: enum u8 {
 	UNKNOWN = 0,
 	UNKNOWN = 0,
 	FIFO    = 1,
 	FIFO    = 1,
@@ -366,14 +387,18 @@ Dirent_Type :: enum u8 {
 	WHT     = 14,
 	WHT     = 14,
 }
 }
 
 
-/// Type of a lock for fcntl.2
+/*
+	Type of a lock for fcntl(2)
+*/
 FLock_Type :: enum i16 {
 FLock_Type :: enum i16 {
 	RDLCK = 0,
 	RDLCK = 0,
 	WRLCK = 1,
 	WRLCK = 1,
 	UNLCK = 2,
 	UNLCK = 2,
 }
 }
 
 
-/// Bits for FD_Notifications
+/*
+	Bits for FD_Notifications
+*/
 FD_Notifications_Bits :: enum {
 FD_Notifications_Bits :: enum {
 	ACCESS    = 0,
 	ACCESS    = 0,
 	MODIFY    = 1,
 	MODIFY    = 1,
@@ -384,7 +409,9 @@ FD_Notifications_Bits :: enum {
 	MULTISHOT = 31,
 	MULTISHOT = 31,
 }
 }
 
 
-/// Bits for seal
+/*
+	Bits for seal
+*/
 Seal_Bits :: enum {
 Seal_Bits :: enum {
 	SEAL         = 0,
 	SEAL         = 0,
 	SHRINK       = 1,
 	SHRINK       = 1,
@@ -408,14 +435,18 @@ FD_Lease :: enum {
 	UNLCK = 2,
 	UNLCK = 2,
 }
 }
 
 
-/// Kind of owner for FD_Owner
+/*
+	Kind of owner for FD_Owner
+*/
 F_Owner_Type :: enum i32 {
 F_Owner_Type :: enum i32 {
 	OWNER_TID  = 0,
 	OWNER_TID  = 0,
 	OWNER_PID  = 1,
 	OWNER_PID  = 1,
 	OWNER_PGRP = 2,
 	OWNER_PGRP = 2,
 }
 }
 
 
-/// Command for fcntl.2
+/*
+	Command for fcntl(2)
+*/
 FCntl_Command :: enum {
 FCntl_Command :: enum {
 	DUPFD             = 0,
 	DUPFD             = 0,
 	GETFD             = 1,
 	GETFD             = 1,
@@ -465,7 +496,9 @@ Fd_Poll_Events_Bits :: enum {
 	RDHUP  = 13,
 	RDHUP  = 13,
 }
 }
 
 
-/// Bits for Mem_Protection bitfield
+/*
+	Bits for Mem_Protection bitfield
+*/
 Mem_Protection_Bits :: enum{
 Mem_Protection_Bits :: enum{
 	READ      = 0,
 	READ      = 0,
 	WRITE     = 1,
 	WRITE     = 1,
@@ -479,7 +512,9 @@ Mem_Protection_Bits :: enum{
 	GROWSUP   = 25,
 	GROWSUP   = 25,
 }
 }
 
 
-/// Bits for Map_Flags
+/*
+	Bits for Map_Flags
+*/
 Map_Flags_Bits :: enum {
 Map_Flags_Bits :: enum {
 	SHARED          = 0,
 	SHARED          = 0,
 	PRIVATE         = 1,
 	PRIVATE         = 1,
@@ -504,19 +539,25 @@ Map_Flags_Bits :: enum {
 	UNINITIALIZED   = 26,
 	UNINITIALIZED   = 26,
 }
 }
 
 
-/// Bits for MLock_Flags
+/*
+	Bits for MLock_Flags
+*/
 MLock_Flags_Bits :: enum {
 MLock_Flags_Bits :: enum {
 	ONFAULT   = 0,
 	ONFAULT   = 0,
 }
 }
 
 
-/// Bits for MSync_Flags
+/*
+	Bits for MSync_Flags
+*/
 MSync_Flags_Bits :: enum {
 MSync_Flags_Bits :: enum {
 	ASYNC      = 0,
 	ASYNC      = 0,
 	INVALIDATE = 1,
 	INVALIDATE = 1,
 	SYNC       = 2,
 	SYNC       = 2,
 }
 }
 
 
-/// Argument for madvice.2
+/*
+	Argument for madvice(2)
+*/
 MAdvice :: enum {
 MAdvice :: enum {
 	NORMAL           = 0,
 	NORMAL           = 0,
 	RANDOM           = 1,
 	RANDOM           = 1,
@@ -545,27 +586,35 @@ MAdvice :: enum {
 	SOFT_OFFLINE     = 101,
 	SOFT_OFFLINE     = 101,
 }
 }
 
 
-/// Bits for PKey_Access_Rights
+/*
+	Bits for PKey_Access_Rights
+*/
 PKey_Access_Bits :: enum {
 PKey_Access_Bits :: enum {
 	DISABLE_ACCESS = 0,
 	DISABLE_ACCESS = 0,
 	DISABLE_WRITE  = 2,
 	DISABLE_WRITE  = 2,
 }
 }
 
 
-/// Bits for MRemap_Flags
+/*
+	Bits for MRemap_Flags
+*/
 MRemap_Flags_Bits :: enum {
 MRemap_Flags_Bits :: enum {
 	MAYMOVE   = 0,
 	MAYMOVE   = 0,
 	FIXED     = 1,
 	FIXED     = 1,
 	DONTUNMAP = 2,
 	DONTUNMAP = 2,
 }
 }
 
 
-/// Bits for Get_Random_Flags
+/*
+	Bits for Get_Random_Flags
+*/
 Get_Random_Flags_Bits :: enum {
 Get_Random_Flags_Bits :: enum {
 	RANDOM   = 0,
 	RANDOM   = 0,
 	NONBLOCK = 1,
 	NONBLOCK = 1,
 	INSECURE = 2,
 	INSECURE = 2,
 }
 }
 
 
-/// Bits for Perf_Flags
+/*
+	Bits for Perf_Flags
+*/
 Perf_Flags_Bits :: enum {
 Perf_Flags_Bits :: enum {
 	FD_NO_GROUP = 0,
 	FD_NO_GROUP = 0,
 	FD_OUTPUT   = 1,
 	FD_OUTPUT   = 1,
@@ -573,7 +622,9 @@ Perf_Flags_Bits :: enum {
 	FD_CLOEXEC  = 3,
 	FD_CLOEXEC  = 3,
 }
 }
 
 
-///  Union tag for Perf_Event_Attr struct
+/*
+	Union tag for Perf_Event_Attr struct
+*/
 Perf_Event_Type :: enum u32 {
 Perf_Event_Type :: enum u32 {
 	HARDWARE   = 0,
 	HARDWARE   = 0,
 	SOFTWARE   = 1,
 	SOFTWARE   = 1,
@@ -633,7 +684,9 @@ Perf_Cap_Flags_Bits :: enum u64 {
 	User_Time_Short    = 5,
 	User_Time_Short    = 5,
 }
 }
 
 
-/// Specifies the type of the hardware event that you want to get info about
+/*
+	Specifies the type of the hardware event that you want to get info about
+*/
 Perf_Hardware_Id :: enum u64 {
 Perf_Hardware_Id :: enum u64 {
 	CPU_CYCLES              = 0,
 	CPU_CYCLES              = 0,
 	INSTRUCTIONS            = 1,
 	INSTRUCTIONS            = 1,
@@ -647,7 +700,9 @@ Perf_Hardware_Id :: enum u64 {
 	REF_CPU_CYCLES          = 9,
 	REF_CPU_CYCLES          = 9,
 }
 }
 
 
-/// Specifies the cache for the particular cache event that you want to get info about
+/*
+	Specifies the cache for the particular cache event that you want to get info about
+*/
 Perf_Hardware_Cache_Id :: enum u64 {
 Perf_Hardware_Cache_Id :: enum u64 {
 	L1D      = 0,
 	L1D      = 0,
 	L1I      = 1,
 	L1I      = 1,
@@ -658,20 +713,26 @@ Perf_Hardware_Cache_Id :: enum u64 {
 	NODE     = 6,
 	NODE     = 6,
 }
 }
 
 
-/// Specifies the cache op that you want to get info about
+/*
+	Specifies the cache op that you want to get info about
+*/
 Perf_Hardware_Cache_Op_Id :: enum u64 {
 Perf_Hardware_Cache_Op_Id :: enum u64 {
 	READ     = 0,
 	READ     = 0,
 	WRITE    = 1,
 	WRITE    = 1,
 	PREFETCH = 2,
 	PREFETCH = 2,
 }
 }
 
 
-/// Specifies the cache operation result that you want to get info about
+/*
+	Specifies the cache operation result that you want to get info about
+*/
 Perf_Hardware_Cache_Result_Id :: enum u64 {
 Perf_Hardware_Cache_Result_Id :: enum u64 {
 	ACCESS   = 0,
 	ACCESS   = 0,
 	MISS     = 1,
 	MISS     = 1,
 }
 }
 
 
-/// Specifies the particular software event that you want to get info about
+/*
+	Specifies the particular software event that you want to get info about
+*/
 Perf_Software_Id :: enum u64 {
 Perf_Software_Id :: enum u64 {
 	CPU_CLOCK         = 0,
 	CPU_CLOCK         = 0,
 	TASK_CLOCK        = 1,
 	TASK_CLOCK        = 1,
@@ -688,7 +749,9 @@ Perf_Software_Id :: enum u64 {
 
 
 }
 }
 
 
-/// Specifies which values to include in the sample
+/*
+	Specifies which values to include in the sample
+*/
 Perf_Event_Sample_Type_Bits :: enum {
 Perf_Event_Sample_Type_Bits :: enum {
 	IP              = 0,
 	IP              = 0,
 	TID             = 1,
 	TID             = 1,
@@ -726,7 +789,9 @@ Perf_Read_Format_Bits :: enum {
 	LOST               = 4,
 	LOST               = 4,
 }
 }
 
 
-/// Chooses the breakpoint type
+/*
+	Chooses the breakpoint type
+*/
 Hardware_Breakpoint_Type :: enum u32 {
 Hardware_Breakpoint_Type :: enum u32 {
 	EMPTY   = 0,
 	EMPTY   = 0,
 	R       = 1,
 	R       = 1,
@@ -736,7 +801,9 @@ Hardware_Breakpoint_Type :: enum u32 {
 	INVALID = RW | X,
 	INVALID = RW | X,
 }
 }
 
 
-/// Bits for Branch_Sample_Type
+/*
+	Bits for Branch_Sample_Type
+*/
 Branch_Sample_Type_Bits :: enum {
 Branch_Sample_Type_Bits :: enum {
 	USER       = 0,
 	USER       = 0,
 	KERNEL     = 1,
 	KERNEL     = 1,
@@ -759,7 +826,9 @@ Branch_Sample_Type_Bits :: enum {
 	PRIV_SAVE  = 18,
 	PRIV_SAVE  = 18,
 }
 }
 
 
-/// Represent the type of Id
+/*
+	Represent the type of Id
+*/
 Id_Type :: enum uint {
 Id_Type :: enum uint {
 	ALL    = 0,
 	ALL    = 0,
 	PID    = 1,
 	PID    = 1,
@@ -767,7 +836,9 @@ Id_Type :: enum uint {
 	PIDFD  = 3,
 	PIDFD  = 3,
 }
 }
 
 
-/// Options for wait syscalls
+/*
+	Options for wait syscalls
+*/
 Wait_Option :: enum {
 Wait_Option :: enum {
 	WNOHANG     = 0,
 	WNOHANG     = 0,
 	WUNTRACED   = 1,
 	WUNTRACED   = 1,
@@ -781,12 +852,16 @@ Wait_Option :: enum {
 	__WCLONE    = 31,
 	__WCLONE    = 31,
 }
 }
 
 
-/// Bits for flags for pidfd
+/*
+	Bits for flags for pidfd
+*/
 Pid_FD_Flags_Bits :: enum {
 Pid_FD_Flags_Bits :: enum {
 	NONBLOCK = 11,
 	NONBLOCK = 11,
 }
 }
 
 
-/// Priority for process, process group, user
+/*
+	Priority for process, process group, user
+*/
 Priority_Which :: enum i32 {
 Priority_Which :: enum i32 {
 	PROCESS = 0,
 	PROCESS = 0,
 	PGRP    = 1,
 	PGRP    = 1,
@@ -849,10 +924,12 @@ Sig_Stack_Flag :: enum i32 {
 	AUTODISARM = 31,
 	AUTODISARM = 31,
 }
 }
 
 
-/// Type of socket to create
-///   For TCP you want to use SOCK_STREAM
-///   For UDP you want to use SOCK_DGRAM
-/// Also see Protocol
+/*
+	Type of socket to create
+    - For TCP you want to use SOCK_STREAM
+	- For UDP you want to use SOCK_DGRAM
+	Also see `Protocol`
+*/
 Socket_Type :: enum {
 Socket_Type :: enum {
 	STREAM    = 1,
 	STREAM    = 1,
 	DGRAM     = 2,
 	DGRAM     = 2,
@@ -863,13 +940,17 @@ Socket_Type :: enum {
 	PACKET    = 10,
 	PACKET    = 10,
 }
 }
 
 
-/// Bits for Socket_FD_Flags
+/*
+	Bits for Socket_FD_Flags
+*/
 Socket_FD_Flags_Bits :: enum {
 Socket_FD_Flags_Bits :: enum {
 	NONBLOCK  = 14,
 	NONBLOCK  = 14,
 	CLOEXEC   = 25,
 	CLOEXEC   = 25,
 }
 }
 
 
-/// Protocol family
+/*
+	Protocol family
+*/
 Protocol_Family :: enum u16 {
 Protocol_Family :: enum u16 {
 	UNSPEC       = 0,
 	UNSPEC       = 0,
 	LOCAL        = 1,
 	LOCAL        = 1,
@@ -922,11 +1003,13 @@ Protocol_Family :: enum u16 {
 	MCTP         = 45,
 	MCTP         = 45,
 }
 }
 
 
-/// The protocol number according to IANA protocol number list
-/// Full list of protocol numbers:
-///   https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
-/// Supported by the OS protocols can be queried by reading:
-///   /etc/protocols
+/*
+	The protocol number according to IANA protocol number list
+	Full list of protocol numbers:
+	  https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
+	Supported by the OS protocols can be queried by reading:
+	  /etc/protocols
+*/
 Protocol :: enum {
 Protocol :: enum {
 	HOPOPT          = 0,
 	HOPOPT          = 0,
 	ICMP            = 1,
 	ICMP            = 1,
@@ -1066,7 +1149,9 @@ Protocol :: enum {
 	Reserved        = 255,
 	Reserved        = 255,
 }
 }
 
 
-/// API Level for get/setsockopt.2
+/*
+	API Level for getsockopt(2)/setsockopt(2)
+*/
 Socket_API_Level :: enum {
 Socket_API_Level :: enum {
 	// Comes from <bits/socket-constants.h>
 	// Comes from <bits/socket-constants.h>
 	SOCKET          = 1,
 	SOCKET          = 1,
@@ -1103,8 +1188,10 @@ Socket_API_Level :: enum {
 	SMC             = 286,
 	SMC             = 286,
 }
 }
 
 
-/// If Socket_API_Level == .SOCKET, these are the options
-/// you can specify in get/setsockopt.2
+/*
+	If Socket_API_Level == .SOCKET, these are the options
+	you can specify in getsockopt(2)/setsockopt(2)
+*/
 Socket_Option :: enum {
 Socket_Option :: enum {
 	DEBUG                         = 1,
 	DEBUG                         = 1,
 	REUSEADDR                     = 2,
 	REUSEADDR                     = 2,
@@ -1249,7 +1336,9 @@ Socket_TCP_Option :: enum {
 	TX_DELAY             = 37,
 	TX_DELAY             = 37,
 }
 }
 
 
-/// Bits for Socket_Msg
+/*
+	Bits for Socket_Msg
+*/
 Socket_Msg_Bits :: enum {
 Socket_Msg_Bits :: enum {
 	OOB             = 0,
 	OOB             = 0,
 	PEEK            = 1,
 	PEEK            = 1,
@@ -1275,14 +1364,18 @@ Socket_Msg_Bits :: enum {
 	CMSG_CLOEXEC    = 30,
 	CMSG_CLOEXEC    = 30,
 }
 }
 
 
-/// Argument to shutdown.2
+/*
+	Argument to shutdown(2)
+*/
 Shutdown_How :: enum i32 {
 Shutdown_How :: enum i32 {
 	RD   = 0,
 	RD   = 0,
 	WR   = 1,
 	WR   = 1,
 	RDWR = 2,
 	RDWR = 2,
 }
 }
 
 
-/// Second argument to futex.2 syscall
+/*
+	Second argument to futex(2) syscall
+*/
 Futex_Op :: enum u32 {
 Futex_Op :: enum u32 {
 	WAIT              = 0,
 	WAIT              = 0,
 	WAKE              = 1,
 	WAKE              = 1,
@@ -1300,13 +1393,17 @@ Futex_Op :: enum u32 {
 	LOCK_PI2          = 13,
 	LOCK_PI2          = 13,
 }
 }
 
 
-/// Bits for Futex_Flags
+/*
+	Bits for Futex_Flags
+*/
 Futex_Flags_Bits :: enum {
 Futex_Flags_Bits :: enum {
 	PRIVATE    = 7,
 	PRIVATE    = 7,
 	REALTIME   = 8,
 	REALTIME   = 8,
 }
 }
 
 
-/// Kind of operation on futex, see FUTEX_WAKE_OP
+/*
+	Kind of operation on futex, see FUTEX_WAKE_OP
+*/
 Futex_Arg_Op :: enum {
 Futex_Arg_Op :: enum {
 	SET      = 0,  /* uaddr2 =       oparg; */
 	SET      = 0,  /* uaddr2 =       oparg; */
 	ADD      = 1,  /* uaddr2 +=      oparg; */
 	ADD      = 1,  /* uaddr2 +=      oparg; */
@@ -1320,7 +1417,9 @@ Futex_Arg_Op :: enum {
 	PO2_XOR  = 4,  /* uaddr2 ^=   1<<oparg; */
 	PO2_XOR  = 4,  /* uaddr2 ^=   1<<oparg; */
 }
 }
 
 
-/// Kind of comparison operation on futex, see FUTEX_WAKE_OP
+/*
+	Kind of comparison operation on futex, see FUTEX_WAKE_OP
+*/
 Futex_Cmp_Op :: enum {
 Futex_Cmp_Op :: enum {
 	EQ = 0,  /* if (oldval == cmparg) wake */
 	EQ = 0,  /* if (oldval == cmparg) wake */
 	NE = 1,  /* if (oldval != cmparg) wake */
 	NE = 1,  /* if (oldval != cmparg) wake */
@@ -1330,7 +1429,9 @@ Futex_Cmp_Op :: enum {
 	GE = 5,  /* if (oldval >= cmparg) wake */
 	GE = 5,  /* if (oldval >= cmparg) wake */
 }
 }
 
 
-/// The kind of resource limits
+/*
+	The kind of resource limits
+*/
 RLimit_Kind :: enum i32 {
 RLimit_Kind :: enum i32 {
 	CPU        = 0,
 	CPU        = 0,
 	FSIZE      = 1,
 	FSIZE      = 1,
@@ -1351,7 +1452,9 @@ RLimit_Kind :: enum i32 {
 	NLIMITS    = 16,
 	NLIMITS    = 16,
 }
 }
 
 
-/// Represents the user of resources
+/*
+	Represents the user of resources
+*/
 RUsage_Who :: enum i32 {
 RUsage_Who :: enum i32 {
 	CHILDREN = -1,
 	CHILDREN = -1,
 	SELF     =  0,
 	SELF     =  0,
@@ -1359,7 +1462,9 @@ RUsage_Who :: enum i32 {
 	LWP      =  THREAD,
 	LWP      =  THREAD,
 }
 }
 
 
-/// Bits for Personality_Flags
+/*
+	Bits for Personality_Flags
+*/
 UNAME26            :: 17
 UNAME26            :: 17
 ADDR_NO_RANDOMIZE  :: 18
 ADDR_NO_RANDOMIZE  :: 18
 FDPIC_FUNCPTRS     :: 19
 FDPIC_FUNCPTRS     :: 19
@@ -1372,8 +1477,10 @@ WHOLE_SECONDS      :: 25
 STICKY_TIMEOUTS    :: 26
 STICKY_TIMEOUTS    :: 26
 ADDR_LIMIT_3GB     :: 27
 ADDR_LIMIT_3GB     :: 27
 
 
-/// Personality type
-/// These go into the bottom 8 bits of the personality value
+/*
+	Personality type
+	These go into the bottom 8 bits of the personality value
+*/
 PER_LINUX       :: 0x0000
 PER_LINUX       :: 0x0000
 PER_LINUX_32BIT :: 0x0000 | ADDR_LIMIT_32BIT
 PER_LINUX_32BIT :: 0x0000 | ADDR_LIMIT_32BIT
 PER_LINUX_FDPIC :: 0x0000 | FDPIC_FUNCPTRS
 PER_LINUX_FDPIC :: 0x0000 | FDPIC_FUNCPTRS
@@ -1398,3 +1505,254 @@ PER_OSF4        :: 0x000f
 PER_HPUX        :: 0x0010
 PER_HPUX        :: 0x0010
 PER_MASK        :: 0x00ff
 PER_MASK        :: 0x00ff
 
 
+/*
+	Bits for access modes for shared memory
+*/
+IPC_Mode_Bits :: enum {
+	WROTH  = 1,
+	RDOTH  = 2,
+	WRGRP  = 4,
+	RDGRP  = 5,
+	WRUSR  = 7,
+	RDUSR  = 8,
+	DEST   = 9,
+	LOCKED = 10,
+}
+
+/*
+	Shared memory flags bits
+*/
+IPC_Flags_Bits :: enum {
+	IPC_CREAT     = 9,
+	IPC_EXCL      = 10,
+	IPC_NOWAIT    = 11,
+	// Semaphore
+	SEM_UNDO      = 9,
+	// Shared memory
+	SHM_HUGETLB   = 11,
+	SHM_NORESERVE = 12,
+	SHM_RDONLY    = 12,
+	SHM_RND       = 13,
+	SHM_REMAP     = 14,
+	SHM_EXEC      = 15,
+	// Message queue
+	MSG_NOERROR   = 12,
+	MSG_EXCEPT    = 13,
+	MSG_COPY      = 14,
+}
+
+/*
+	IPC memory commands
+*/
+IPC_Cmd :: enum i16 {
+	// IPC common
+	IPC_RMID     = 0,
+	IPC_SET      = 1,
+	IPC_STAT     = 2,
+	// Shared memory
+	SHM_LOCK     = 11,
+	SHM_UNLOCK   = 12,
+	SHM_STAT     = 13,
+	SHM_INFO     = 14,
+	SHM_STAT_ANY = 15,
+	// Semaphore
+	GETPID       = 11,
+	GETVAL       = 12,
+	GETALL       = 13,
+	GETNCNT      = 14,
+	GETZCNT      = 15,
+	SETVAL       = 16,
+	SETALL       = 17,
+	SEM_STAT     = 18,
+	SEM_INFO     = 19,
+	SEM_STAT_ANY = 20,
+	// Message queue
+	MSG_STAT     = 11,
+	MSG_INFO     = 12,
+	MSG_STAT_ANY = 13,
+}
+
+/*
+	File locking operation bits
+*/
+FLock_Op_Bits :: enum {
+	SH = 1,
+	EX = 2,
+	NB = 4,
+	UN = 8,
+}
+
+/*
+	ptrace requests
+*/
+PTrace_Request :: enum {
+	TRACEME                = 0,
+	PEEKTEXT               = 1,
+	PEEKDATA               = 2,
+	PEEKUSER               = 3,
+	POKETEXT               = 4,
+	POKEDATA               = 5,
+	POKEUSER               = 6,
+	CONT                   = 7,
+	KILL                   = 8,
+	SINGLESTEP             = 9,
+	GETREGS                = 12,
+	SETREGS                = 13,
+	GETFPREGS              = 14,
+	SETFPREGS              = 15,
+	ATTACH                 = 16,
+	DETACH                 = 17,
+	GETFPXREGS             = 18,
+	SETFPXREGS             = 19,
+	SYSCALL                = 24,
+	GET_THREAD_AREA        = 25,
+	SET_THREAD_AREA        = 26,
+	ARCH_PRCTL             = 30,
+	SYSEMU                 = 31,
+	SYSEMU_SINGLESTEP      = 32,
+	SINGLEBLOCK            = 33,
+	SETOPTIONS             = 0x4200,
+	GETEVENTMSG            = 0x4201,
+	GETSIGINFO             = 0x4202,
+	SETSIGINFO             = 0x4203,
+	GETREGSET              = 0x4204,
+	SETREGSET              = 0x4205,
+	SEIZE                  = 0x4206,
+	INTERRUPT              = 0x4207,
+	LISTEN                 = 0x4208,
+	PEEKSIGINFO            = 0x4209,
+	GETSIGMASK             = 0x420a,
+	SETSIGMASK             = 0x420b,
+	SECCOMP_GET_FILTER     = 0x420c,
+	SECCOMP_GET_METADATA   = 0x420d,
+	GET_SYSCALL_INFO       = 0x420e,
+	GET_RSEQ_CONFIGURATION = 0x420f,
+}
+
+/*
+	ptrace options
+*/
+PTrace_Options_Bits :: enum {
+	TRACESYSGOOD    = 0,
+	TRACEFORK       = 1,
+	TRACEVFORK      = 2,
+	TRACECLONE      = 3,
+	TRACEEXEC       = 4,
+	TRACEVFORKDONE  = 5,
+	TRACEEXIT       = 6,
+	TRACESECCOMP    = 7,
+	EXITKILL        = 20,
+	SUSPEND_SECCOMP = 21,
+}
+
+/*
+	ptrace event codes.
+*/
+PTrace_Event_Code :: enum {
+	EVENT_FORK       = 1,
+	EVENT_VFORK      = 2,
+	EVENT_CLONE      = 3,
+	EVENT_EXEC       = 4,
+	EVENT_VFORK_DONE = 5,
+	EVENT_EXIT       = 6,
+	EVENT_SECCOMP    = 7,
+	EVENT_STOP       = 128,
+}
+
+/*
+	ptrace's get syscall info operation.
+*/
+PTrace_Get_Syscall_Info_Op :: enum u8 {
+	NONE    = 0,
+	ENTRY   = 1,
+	EXIT    = 2,
+	SECCOMP = 3,
+}
+
+/*
+	ptrace's PEEKSIGINFO flags bits
+*/
+PTrace_Peek_Sig_Info_Flags_Bits :: enum {
+	SHARED = 0,
+}
+
+/*
+	Syslog actions.
+*/
+Syslog_Action :: enum i32 {
+	CLOSE         = 0,
+	OPEN          = 1,
+	READ          = 2,
+	READ_ALL      = 3,
+	READ_CLEAR    = 4,
+	CLEAR         = 5,
+	CONSOLE_OFF   = 6,
+	CONSOLE_ON    = 7,
+	CONSOLE_LEVEL = 8,
+	SIZE_UNREAD   = 9,
+	SIZE_BUFFER   = 10,
+}
+
+/*
+	Bits for splice flags.
+*/
+Splice_Flags_Bits :: enum {
+	MOVE     = 0x01,
+	NONBLOCK = 0x02,
+	MORE     = 0x04,
+	GIFT     = 0x08,
+}
+
+/*
+	Clock IDs for various system clocks.
+*/
+Clock_Id :: enum {
+	REALTIME           = 0,
+	MONOTONIC          = 1,
+	PROCESS_CPUTIME_ID = 2,
+	THREAD_CPUTIME_ID  = 3,
+	MONOTONIC_RAW      = 4,
+	REALTIME_COARSE    = 5,
+	MONOTONIC_COARSE   = 6,
+	BOOTTIME           = 7,
+	REALTIME_ALARM     = 8,
+	BOOTTIME_ALARM     = 9,
+}
+
+/*
+	Bits for POSIX interval timer flags.
+*/
+ITimer_Flags_Bits :: enum {
+	ABSTIME = 1,
+}
+
+/*
+	Bits for epoll_create(2) flags.
+*/
+EPoll_Flags_Bits :: enum {
+	FDCLOEXEC = 19,
+}
+
+EPoll_Event_Kind :: enum u32 {
+	IN        = 0x001,
+	PRI       = 0x002,
+	OUT       = 0x004,
+	RDNORM    = 0x040,
+	RDBAND    = 0x080,
+	WRNORM    = 0x100,
+	WRBAND    = 0x200,
+	MSG       = 0x400,
+	ERR       = 0x008,
+	HUP       = 0x010,
+	RDHUP     = 0x2000,
+	EXCLUSIVE = 1<<28,
+	WAKEUP    = 1<<29,
+	ONESHOT   = 1<<30,
+	ET        = 1<<31,
+}
+
+EPoll_Ctl_Opcode :: enum i32 {
+	ADD = 1,
+	DEL = 2,
+	MOD = 3,
+}

+ 166 - 29
core/sys/linux/constants.odin

@@ -1,26 +1,40 @@
 
 
 package linux
 package linux
 
 
-/// Special file descriptor to pass to `*at` functions to specify
-/// that relative paths are relative to current directory
+/*
+	Special file descriptor to pass to `*at` functions to specify
+	that relative paths are relative to current directory.
+*/
 AT_FDCWD :: Fd(-100)
 AT_FDCWD :: Fd(-100)
 
 
-/// Special value to put into timespec for utimensat() to set timestamp to the current time
+/*
+	Special value to put into timespec for utimensat() to set timestamp to the current time.
+*/
 UTIME_NOW  :: uint((1 << 30) - 1)
 UTIME_NOW  :: uint((1 << 30) - 1)
 
 
-/// Special value to put into the timespec for utimensat() to leave the corresponding field of the timestamp unchanged
+/*
+	Special value to put into the timespec for utimensat() to leave the corresponding field of the timestamp unchanged.
+*/
 UTIME_OMIT :: uint((1 << 30) - 2)
 UTIME_OMIT :: uint((1 << 30) - 2)
 
 
-/// For wait4: Pass this pid to wait for any process
+/*
+	For wait4: Pass this pid to wait for any process.
+*/
 WAIT_ANY    :: Pid(-1)
 WAIT_ANY    :: Pid(-1)
 
 
-/// For wait4: Pass this pid to wait for any process in current process group
+/*
+	For wait4: Pass this pid to wait for any process in current process group.
+*/
 WAIT_MYPGRP :: Pid(0)
 WAIT_MYPGRP :: Pid(0)
 
 
-/// Maximum priority (aka nice value) for the process
+/*
+	Maximum priority (aka nice value) for the process.
+*/
 PRIO_MAX :: 20
 PRIO_MAX :: 20
 
 
-/// Minimum priority (aka nice value) for the process
+/*
+	Minimum priority (aka nice value) for the process.
+*/
 PRIO_MIN :: -20
 PRIO_MIN :: -20
 
 
 SIGRTMIN :: Signal(32)
 SIGRTMIN :: Signal(32)
@@ -35,40 +49,64 @@ S_IFCHR  :: Mode{.IFCHR}
 S_IFDIR  :: Mode{.IFDIR}
 S_IFDIR  :: Mode{.IFDIR}
 S_IFREG  :: Mode{.IFREG}
 S_IFREG  :: Mode{.IFREG}
 
 
-/// Checks the Mode bits to see if the file is a named pipe (FIFO)
+/*
+	Checks the Mode bits to see if the file is a named pipe (FIFO).
+*/
 S_ISFIFO :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFFIFO  == (m & S_IFMT))}
 S_ISFIFO :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFFIFO  == (m & S_IFMT))}
 
 
-/// Check the Mode bits to see if the file is a character device
+/*
+	Check the Mode bits to see if the file is a character device.
+*/
 S_ISCHR  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFCHR  == (m & S_IFMT))}
 S_ISCHR  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFCHR  == (m & S_IFMT))}
-	
-/// Check the Mode bits to see if the file is a directory
+
+/*	
+	Check the Mode bits to see if the file is a directory.
+*/
 S_ISDIR  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFDIR  == (m & S_IFMT))}
 S_ISDIR  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFDIR  == (m & S_IFMT))}
 
 
-/// Check the Mode bits to see if the file is a register
+/*
+	Check the Mode bits to see if the file is a register.
+*/
 S_ISREG  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFREG  == (m & S_IFMT))}
 S_ISREG  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFREG  == (m & S_IFMT))}
 
 
-/// Check the Mode bits to see if the file is a socket
+/*
+	Check the Mode bits to see if the file is a socket.
+*/
 S_ISSOCK :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFSOCK == (m & S_IFMT))}
 S_ISSOCK :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFSOCK == (m & S_IFMT))}
 
 
-/// Check the Mode bits to see if the file is a symlink
+/*
+	Check the Mode bits to see if the file is a symlink.
+*/
 S_ISLNK  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFLNK  == (m & S_IFMT))}
 S_ISLNK  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFLNK  == (m & S_IFMT))}
 
 
-/// Check the Mode bits to see if the file is a block device
+/*
+	Check the Mode bits to see if the file is a block device.
+*/
 S_ISBLK  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFBLK  == (m & S_IFMT))}
 S_ISBLK  :: #force_inline proc "contextless" (m: Mode) -> bool {return (S_IFBLK  == (m & S_IFMT))}
 
 
-/// For access.2 syscall family: instruct to check if the file exists
+/*
+	For access.2 syscall family: instruct to check if the file exists.
+*/
 F_OK :: Mode{}
 F_OK :: Mode{}
 
 
-/// For access.2 syscall family: instruct to check if the file is executable
+/*
+	For access.2 syscall family: instruct to check if the file is executable.
+*/
 X_OK :: Mode{.IXOTH}
 X_OK :: Mode{.IXOTH}
 
 
-/// For access.2 syscall family: instruct to check if the file is writeable
+/*
+	For access.2 syscall family: instruct to check if the file is writeable.
+*/
 W_OK :: Mode{.IWOTH}
 W_OK :: Mode{.IWOTH}
 
 
-/// For access.2 syscall family: instruct to check if the file is readable
+/*
+	For access.2 syscall family: instruct to check if the file is readable.
+*/
 R_OK :: Mode{.IROTH}
 R_OK :: Mode{.IROTH}
 
 
-/// The stats you get by calling `stat`
+/*
+	The stats you get by calling `stat`.
+*/
 STATX_BASIC_STATS :: Statx_Mask {
 STATX_BASIC_STATS :: Statx_Mask {
 	.TYPE,
 	.TYPE,
 	.MODE,
 	.MODE,
@@ -83,6 +121,10 @@ STATX_BASIC_STATS :: Statx_Mask {
 	.BLOCKS,
 	.BLOCKS,
 }
 }
 
 
+/*
+	Tell `shmget` to create a new key
+*/
+IPC_PRIVATE :: Key(0)
 
 
 FCntl_Command_DUPFD            :: distinct FCntl_Command
 FCntl_Command_DUPFD            :: distinct FCntl_Command
 FCntl_Command_GETFD            :: distinct FCntl_Command
 FCntl_Command_GETFD            :: distinct FCntl_Command
@@ -165,28 +207,44 @@ Futex_Wait_requeue_Pi_Type :: distinct Futex_Op
 Futex_Cmp_requeue_Pi_Type  :: distinct Futex_Op
 Futex_Cmp_requeue_Pi_Type  :: distinct Futex_Op
 Futex_Lock_Pi2_Type        :: distinct Futex_Op
 Futex_Lock_Pi2_Type        :: distinct Futex_Op
 
 
-/// Wait on futex wakeup signal
+/*
+	Wait on futex wakeup signal.
+*/
 FUTEX_WAIT            :: Futex_Wait_Type(.WAIT)
 FUTEX_WAIT            :: Futex_Wait_Type(.WAIT)
 
 
-/// Wake up other processes waiting on the futex
+/*
+	Wake up other processes waiting on the futex.
+*/
 FUTEX_WAKE            :: Futex_Wake_Type(.WAKE)
 FUTEX_WAKE            :: Futex_Wake_Type(.WAKE)
 
 
-/// Not implemented. Basically, since
+/*
+	Not implemented. Basically, since.
+*/
 FUTEX_FD              :: Futex_Fd_Type(.FD)
 FUTEX_FD              :: Futex_Fd_Type(.FD)
 
 
-/// Requeue waiters from one futex to another
+/*
+	Requeue waiters from one futex to another.
+*/
 FUTEX_REQUEUE         :: Futex_Requeue_Type(.REQUEUE)
 FUTEX_REQUEUE         :: Futex_Requeue_Type(.REQUEUE)
 
 
-/// Requeue waiters from one futex to another if the value at mutex matches
+/*
+	Requeue waiters from one futex to another if the value at mutex matches.
+*/
 FUTEX_CMP_REQUEUE     :: Futex_Cmp_Requeue_Type(.CMP_REQUEUE)
 FUTEX_CMP_REQUEUE     :: Futex_Cmp_Requeue_Type(.CMP_REQUEUE)
 
 
-/// See man pages, I'm not describing it here
+/*
+	See man pages, I'm not describing it here.
+*/
 FUTEX_WAKE_OP         :: Futex_Wake_Op_Type(.WAKE_OP)
 FUTEX_WAKE_OP         :: Futex_Wake_Op_Type(.WAKE_OP)
 
 
-/// Wait on a futex, but the value is a bitset
+/*
+	Wait on a futex, but the value is a bitset.
+*/
 FUTEX_WAIT_BITSET     :: Futex_Wait_Bitset_Type(.WAIT_BITSET)
 FUTEX_WAIT_BITSET     :: Futex_Wait_Bitset_Type(.WAIT_BITSET)
 
 
-/// Wait on a futex, but the value is a bitset
+/*
+	Wait on a futex, but the value is a bitset.
+*/
 FUTEX_WAKE_BITSET     :: Futex_Wake_Bitset_Type(.WAKE_BITSET)
 FUTEX_WAKE_BITSET     :: Futex_Wake_Bitset_Type(.WAKE_BITSET)
 
 
 // TODO(flysand): Priority inversion futexes
 // TODO(flysand): Priority inversion futexes
@@ -197,3 +255,82 @@ FUTEX_WAIT_REQUEUE_PI :: Futex_Wait_requeue_Pi_Type(.WAIT_REQUEUE_PI)
 FUTEX_CMP_REQUEUE_PI  :: Futex_Cmp_requeue_Pi_Type(.CMP_REQUEUE_PI)
 FUTEX_CMP_REQUEUE_PI  :: Futex_Cmp_requeue_Pi_Type(.CMP_REQUEUE_PI)
 FUTEX_LOCK_PI2        :: Futex_Lock_Pi2_Type(.LOCK_PI2)
 FUTEX_LOCK_PI2        :: Futex_Lock_Pi2_Type(.LOCK_PI2)
 
 
+PTrace_Traceme_Type                :: distinct PTrace_Request
+PTrace_Peek_Type                   :: distinct PTrace_Request
+PTrace_Poke_Type                   :: distinct PTrace_Request
+PTrace_Cont_Type                   :: distinct PTrace_Request
+PTrace_Kill_Type                   :: distinct PTrace_Request
+PTrace_Singlestep_Type             :: distinct PTrace_Request
+PTrace_Getregs_Type                :: distinct PTrace_Request
+PTrace_Setregs_Type                :: distinct PTrace_Request
+PTrace_Getfpregs_Type              :: distinct PTrace_Request
+PTrace_Setfpregs_Type              :: distinct PTrace_Request
+PTrace_Attach_Type                 :: distinct PTrace_Request
+PTrace_Detach_Type                 :: distinct PTrace_Request
+PTrace_Getfpxregs_Type             :: distinct PTrace_Request
+PTrace_Setfpxregs_Type             :: distinct PTrace_Request
+PTrace_Syscall_Type                :: distinct PTrace_Request
+PTrace_Get_Thread_Area_Type        :: distinct PTrace_Request
+PTrace_Set_Thread_Area_Type        :: distinct PTrace_Request
+PTrace_Arch_Prctl_Type             :: distinct PTrace_Request
+PTrace_Sysemu_Type                 :: distinct PTrace_Request
+PTrace_Sysemu_Singlestep_Type      :: distinct PTrace_Request
+PTrace_Singleblock_Type            :: distinct PTrace_Request
+PTrace_Setoptions_Type             :: distinct PTrace_Request
+PTrace_Geteventmsg_Type            :: distinct PTrace_Request
+PTrace_Getsiginfo_Type             :: distinct PTrace_Request
+PTrace_Setsiginfo_Type             :: distinct PTrace_Request
+PTrace_Getregset_Type              :: distinct PTrace_Request
+PTrace_Setregset_Type              :: distinct PTrace_Request
+PTrace_Seize_Type                  :: distinct PTrace_Request
+PTrace_Interrupt_Type              :: distinct PTrace_Request
+PTrace_Listen_Type                 :: distinct PTrace_Request
+PTrace_Peeksiginfo_Type            :: distinct PTrace_Request
+PTrace_Getsigmask_Type             :: distinct PTrace_Request
+PTrace_Setsigmask_Type             :: distinct PTrace_Request
+PTrace_Seccomp_Get_Filter_Type     :: distinct PTrace_Request
+PTrace_Seccomp_Get_Metadata_Type   :: distinct PTrace_Request
+PTrace_Get_Syscall_Info_Type       :: distinct PTrace_Request
+PTrace_Get_RSeq_Configuration_Type :: distinct PTrace_Request
+
+PTRACE_TRACEME                :: PTrace_Traceme_Type(.TRACEME)
+PTRACE_PEEKTEXT               :: PTrace_Peek_Type(.PEEKTEXT)
+PTRACE_PEEKDATA               :: PTrace_Peek_Type(.PEEKDATA)
+PTRACE_PEEKUSER               :: PTrace_Peek_Type(.PEEKUSER)
+PTRACE_POKETEXT               :: PTrace_Poke_Type(.POKETEXT)
+PTRACE_POKEDATA               :: PTrace_Poke_Type(.POKEDATA)
+PTRACE_POKEUSER               :: PTrace_Poke_Type(.POKEUSER)
+PTRACE_CONT                   :: PTrace_Cont_Type(.CONT)
+PTRACE_KILL                   :: PTrace_Kill_Type(.KILL)
+PTRACE_SINGLESTEP             :: PTrace_Singlestep_Type(.SINGLESTEP)
+PTRACE_GETREGS                :: PTrace_Getregs_Type(.GETREGS)
+PTRACE_SETREGS                :: PTrace_Setregs_Type(.SETREGS)
+PTRACE_GETFPREGS              :: PTrace_Getfpregs_Type(.GETFPREGS)
+PTRACE_SETFPREGS              :: PTrace_Setfpregs_Type(.SETFPREGS)
+PTRACE_ATTACH                 :: PTrace_Attach_Type(.ATTACH)
+PTRACE_DETACH                 :: PTrace_Detach_Type(.DETACH)
+PTRACE_GETFPXREGS             :: PTrace_Getfpxregs_Type(.GETFPXREGS)
+PTRACE_SETFPXREGS             :: PTrace_Setfpxregs_Type(.SETFPXREGS)
+PTRACE_SYSCALL                :: PTrace_Syscall_Type(.SYSCALL)
+PTRACE_GET_THREAD_AREA        :: PTrace_Get_Thread_Area_Type(.GET_THREAD_AREA)
+PTRACE_SET_THREAD_AREA        :: PTrace_Set_Thread_Area_Type(.SET_THREAD_AREA)
+PTRACE_ARCH_PRCTL             :: PTrace_Arch_Prctl_Type(.ARCH_PRCTL)
+PTRACE_SYSEMU                 :: PTrace_Sysemu_Type(.SYSEMU)
+PTRACE_SYSEMU_SINGLESTEP      :: PTrace_Sysemu_Singlestep_Type(.SYSEMU_SINGLESTEP)
+PTRACE_SINGLEBLOCK            :: PTrace_Singleblock_Type(.SINGLEBLOCK)
+PTRACE_SETOPTIONS             :: PTrace_Setoptions_Type(.SETOPTIONS)
+PTRACE_GETEVENTMSG            :: PTrace_Geteventmsg_Type(.GETEVENTMSG)
+PTRACE_GETSIGINFO             :: PTrace_Getsiginfo_Type(.GETSIGINFO)
+PTRACE_SETSIGINFO             :: PTrace_Setsiginfo_Type(.SETSIGINFO)
+PTRACE_GETREGSET              :: PTrace_Getregset_Type(.GETREGSET)
+PTRACE_SETREGSET              :: PTrace_Setregset_Type(.SETREGSET)
+PTRACE_SEIZE                  :: PTrace_Seize_Type(.SEIZE)
+PTRACE_INTERRUPT              :: PTrace_Interrupt_Type(.INTERRUPT)
+PTRACE_LISTEN                 :: PTrace_Listen_Type(.LISTEN)
+PTRACE_PEEKSIGINFO            :: PTrace_Peeksiginfo_Type(.PEEKSIGINFO)
+PTRACE_GETSIGMASK             :: PTrace_Getsigmask_Type(.GETSIGMASK)
+PTRACE_SETSIGMASK             :: PTrace_Setsigmask_Type(.SETSIGMASK)
+PTRACE_SECCOMP_GET_FILTER     :: PTrace_Seccomp_Get_Filter_Type(.SECCOMP_GET_FILTER)
+PTRACE_SECCOMP_GET_METADATA   :: PTrace_Seccomp_Get_Metadata_Type(.SECCOMP_GET_METADATA)
+PTRACE_GET_SYSCALL_INFO       :: PTrace_Get_Syscall_Info_Type(.GET_SYSCALL_INFO)
+PTRACE_GET_RSEQ_CONFIGURATION :: PTrace_Get_RSeq_Configuration_Type(.GET_RSEQ_CONFIGURATION)

File diff ditekan karena terlalu besar
+ 548 - 176
core/sys/linux/sys.odin


+ 746 - 73
core/sys/linux/types.odin

@@ -1,56 +1,104 @@
 //+build linux
 //+build linux
 package linux
 package linux
 
 
-/// Represents storage device handle
+/*
+	Type for storage device handle.
+*/
 Dev :: distinct int
 Dev :: distinct int
 
 
-/// Represents 32-bit user id
+/*
+	Type for 32-bit User IDs.
+*/
 Uid :: distinct u32
 Uid :: distinct u32
 
 
-/// Represents 32-bit group id
+/*
+	Type for 32-bit Group IDs.
+*/
 Gid :: distinct u32
 Gid :: distinct u32
 
 
-/// Process id's
+/*
+	Type for Process IDs, Thread IDs, Thread group ID.
+*/
 Pid :: distinct int
 Pid :: distinct int
 
 
-/// Represents pid, pifd, pgid values in general
+/*
+	Type for any of: pid, pidfd, pgid.
+*/
 Id :: distinct uint
 Id :: distinct uint
 
 
-/// Represents a file descriptor
+/*
+	Represents a file descriptor.
+*/
 Fd  :: distinct i32
 Fd  :: distinct i32
 
 
-/// Represents a PID file descriptor
+/*
+	Type for PID file descriptors.
+*/
 Pid_FD :: distinct i32
 Pid_FD :: distinct i32
 
 
-/// Represents 64-bit inode number for files
-/// Used pretty much only in struct Stat64 for 32-bit platforms
+/*
+	Type for 64-bit inode number for files.
+	Used pretty much only in struct Stat64 for 32-bit platforms.
+*/
 Inode :: distinct u64
 Inode :: distinct u64
 
 
-/// Represents time with nanosecond precision
+/*
+	Shared memory identifiers used by shmget(2) and other calls.
+*/
+Key :: distinct i32
+
+/*
+	Represents timer IDs.
+*/
+Timer :: distinct i32
+
+/*
+	Represents time with nanosecond precision.
+*/
 Time_Spec :: struct {
 Time_Spec :: struct {
 	time_sec:  uint,
 	time_sec:  uint,
 	time_nsec: uint,
 	time_nsec: uint,
 }
 }
 
 
-/// Represents time with millisecond precision
+/*
+	Represents time with millisecond precision.
+*/
 Time_Val :: struct {
 Time_Val :: struct {
 	seconds:      int,
 	seconds:      int,
 	microseconds: int,
 	microseconds: int,
 }
 }
 
 
-/// open.2 flags
+/*
+	Access and modification times for files
+*/
+UTim_Buf :: struct {
+	actime:  uint,
+	modtime: uint,
+}
+
+/*
+	Flags for open(2).
+*/
 Open_Flags :: bit_set[Open_Flags_Bits; u32]
 Open_Flags :: bit_set[Open_Flags_Bits; u32]
 
 
-/// Flags for the file descriptor to be passed in some syscalls
+/*
+	Flags for the file descriptors.
+*/
 FD_Flags :: bit_set[FD_Flags_Bits; i32]
 FD_Flags :: bit_set[FD_Flags_Bits; i32]
 
 
-/// Represents file's permission and status bits
-/// Example:
-///   When you're passing a value of this type the recommended usage is
-///     sys.Mode{.S_IXOTH, .S_IROTH} | sys.S_IRWXU | sys.S_IRWXG
-///   This would generate a mode that has full permissions for the
-///   file's owner and group, and only "read" and "execute" bits
-///   for others.
+/*
+	Represents file's permission and status bits
+**Example:**
+	When you're passing a value of this type the recommended usage is:
+	
+	```
+	  linux.Mode{.S_IXOTH, .S_IROTH} | linux.S_IRWXU | linux.S_IRWXG
+	```
+	  
+	This would generate a mode that has full permissions for the
+	file's owner and group, and only "read" and "execute" bits
+	for others.
+*/
 Mode :: bit_set[Mode_Bits; u32]
 Mode :: bit_set[Mode_Bits; u32]
 
 
 when ODIN_ARCH == .amd64 {
 when ODIN_ARCH == .amd64 {
@@ -111,29 +159,38 @@ when ODIN_ARCH == .amd64 {
 	}
 	}
 }
 }
 
 
-/// Represents the file state.
-/// Mirrors struct stat in glibc/linux kernel.
-/// If you're on 32-bit platform, consider using Stat64 instead
+/*
+	Represents the file state.
+	If you're on 32-bit platform, consider using Stat64 instead.
+*/
 Stat :: struct {
 Stat :: struct {
 	using _impl_stat: _Arch_Stat,
 	using _impl_stat: _Arch_Stat,
 }
 }
 
 
-/// Timestamp type used for Statx struct
+/*
+	Timestamp type used for Statx struct
+*/
 Statx_Timestamp :: struct {
 Statx_Timestamp :: struct {
 	sec:  i64,
 	sec:  i64,
 	nsec: u32,
 	nsec: u32,
 	_:       i32,
 	_:       i32,
 }
 }
 
 
-/// Query params/results for `statx()`
+/*
+	Query params/results for `statx()`.
+*/
 Statx_Mask :: bit_set[Statx_Mask_Bits; u32]
 Statx_Mask :: bit_set[Statx_Mask_Bits; u32]
 
 
-/// File attributes, returned by statx. This bitset is also
-/// used to specify which attributes are present, not just
-/// their value.
+/*
+	File attributes, returned by statx. This bitset is also
+	used to specify which attributes are present, not just
+	their value.
+*/
 Statx_Attr :: bit_set[Statx_Attr_Bits; u64]
 Statx_Attr :: bit_set[Statx_Attr_Bits; u64]
 
 
-/// The extended Stat struct
+/*
+	The extended Stat struct, the argument to statx(2) syscall.
+*/
 Statx :: struct {
 Statx :: struct {
 	mask:                Statx_Mask,
 	mask:                Statx_Mask,
 	blksize:             u32,
 	blksize:             u32,
@@ -165,7 +222,9 @@ Statx :: struct {
 	_:                   [12]u64,
 	_:                   [12]u64,
 }
 }
 
 
-/// Mount flags for filesystem
+/*
+	Mount flags for filesystem.
+*/
 FS_Flags :: bit_set[FS_Flags_Bits; u32]
 FS_Flags :: bit_set[FS_Flags_Bits; u32]
 
 
 when size_of(int) == 8 {
 when size_of(int) == 8 {
@@ -205,19 +264,28 @@ when size_of(int) == 8 {
 	}
 	}
 }
 }
 
 
+/*
+	Struct for statfs(2).
+*/
 Stat_FS :: struct {
 Stat_FS :: struct {
 	using _impl_stat_fs: _Arch_Stat_FS,
 	using _impl_stat_fs: _Arch_Stat_FS,
 }
 }
 
 
-/// Flags for close_range.2
+/*
+	Flags for close_range(2).
+*/
 Close_Range_Flags :: bit_set[Close_Range_Flags_Bits; u32]
 Close_Range_Flags :: bit_set[Close_Range_Flags_Bits; u32]
 
 
-/// Flags for rename.2
+/*
+	Flags for rename(2).
+*/
 Rename_Flags :: bit_set[Rename_Flags_Bits; u32]
 Rename_Flags :: bit_set[Rename_Flags_Bits; u32]
 
 
-/// Directory entry
-/// Recommended to use this with dirent_iterator()
-/// and dirent_name()
+/*
+	Directory entry record.
+	Recommended iterate these with `dirent_iterator()`,
+	and obtain the name via `dirent_name()`.
+*/
 Dirent :: struct {
 Dirent :: struct {
 	ino:    Inode,
 	ino:    Inode,
 	off:    i64,
 	off:    i64,
@@ -226,7 +294,9 @@ Dirent :: struct {
 	name:   [0]u8, // See dirent_name
 	name:   [0]u8, // See dirent_name
 }
 }
 
 
-/// Lock record for fcntl.2
+/*
+	Lock record for fcntl(2).
+*/
 FLock :: struct {
 FLock :: struct {
 	type:   FLock_Type,
 	type:   FLock_Type,
 	whence: Seek_Whence,
 	whence: Seek_Whence,
@@ -235,50 +305,83 @@ FLock :: struct {
 	pid:    Pid,
 	pid:    Pid,
 }
 }
 
 
-/// Flags for fcntl_notify
+/*
+	File locking operations.
+	Use one of `EX`, `RW` or `UN` to specify the operation, and add `UN` if
+	you need a non-blocking operation.
+*/
+FLock_Op :: bit_set[FLock_Op_Bits; i32]
+
+/*
+	Flags for `fcntl_notify()`.
+*/
 FD_Notifications :: bit_set[FD_Notifications_Bits; i32]
 FD_Notifications :: bit_set[FD_Notifications_Bits; i32]
 
 
-/// Seals for fcntl_add_seals
+/*
+	Seals for `fcntl_add_seals()`.
+*/
 Seal :: bit_set[Seal_Bits; i32]
 Seal :: bit_set[Seal_Bits; i32]
 
 
-/// Represents owner that receives events on file updates
+/*
+	Represents owner that receives events on file updates.
+*/
 F_Owner :: struct {
 F_Owner :: struct {
 	type: F_Owner_Type,
 	type: F_Owner_Type,
 	pid:  Pid,
 	pid:  Pid,
 }
 }
 
 
-/// Events for ppoll
+/*
+	Events for ppoll(2).
+*/
 Fd_Poll_Events :: bit_set[Fd_Poll_Events_Bits; u16]
 Fd_Poll_Events :: bit_set[Fd_Poll_Events_Bits; u16]
 
 
-/// Struct for ppoll
+/*
+	Struct for ppoll(2).
+*/
 Poll_Fd :: struct {
 Poll_Fd :: struct {
 	fd:      Fd,
 	fd:      Fd,
 	events:  Fd_Poll_Events,
 	events:  Fd_Poll_Events,
 	revents: Fd_Poll_Events,
 	revents: Fd_Poll_Events,
 }
 }
 
 
-/// Specifies protection for memory pages
+/*
+	Specifies protection for memory pages.
+*/
 Mem_Protection :: bit_set[Mem_Protection_Bits; i32]
 Mem_Protection :: bit_set[Mem_Protection_Bits; i32]
 
 
-/// Flags for mmap
+/*
+	Flags for mmap.
+*/
 Map_Flags :: bit_set[Map_Flags_Bits; i32]
 Map_Flags :: bit_set[Map_Flags_Bits; i32]
 
 
-/// Flags for mlock.2
+/*
+	Flags for mlock(2).
+*/
 MLock_Flags :: bit_set[MLock_Flags_Bits; u32]
 MLock_Flags :: bit_set[MLock_Flags_Bits; u32]
 
 
-/// Flags for msync.2
+/*
+	Flags for msync(2).
+*/
 MSync_Flags :: bit_set[MSync_Flags_Bits; i32]
 MSync_Flags :: bit_set[MSync_Flags_Bits; i32]
 
 
-/// Access rights for pkey_alloc.2
+/*
+	Access rights for pkey_alloc(2).
+*/
 PKey_Access_Rights :: bit_set[PKey_Access_Bits; u32]
 PKey_Access_Rights :: bit_set[PKey_Access_Bits; u32]
 
 
-/// Flags for mremap.2
+/*
+	Flags for mremap(2).
+*/
 MRemap_Flags :: bit_set[MRemap_Flags_Bits; i32]
 MRemap_Flags :: bit_set[MRemap_Flags_Bits; i32]
 
 
-/// Flags for getrandom syscall
+/*
+	Flags for getrandom(2) syscall.
+*/
 Get_Random_Flags :: bit_set[Get_Random_Flags_Bits; i32]
 Get_Random_Flags :: bit_set[Get_Random_Flags_Bits; i32]
 
 
-/// Flags for perf_event_open syscall
+/*
+	Flags for perf_event_open(2) syscall.
+*/
 Perf_Flags :: bit_set[Perf_Flags_Bits; uint]
 Perf_Flags :: bit_set[Perf_Flags_Bits; uint]
 
 
 Perf_Event_Flags :: distinct bit_set[Perf_Event_Flags_Bits; u64]
 Perf_Event_Flags :: distinct bit_set[Perf_Event_Flags_Bits; u64]
@@ -289,10 +392,14 @@ Perf_Cap_Flags :: distinct bit_set[Perf_Cap_Flags_Bits; u64]
 
 
 Perf_Event_Sample_Type :: bit_set[Perf_Event_Sample_Type_Bits; u64]
 Perf_Event_Sample_Type :: bit_set[Perf_Event_Sample_Type_Bits; u64]
 
 
-/// Specifies which branches to include in branch record
+/*
+	Specifies which branches to include in branch record.
+*/
 Branch_Sample_Type :: bit_set[Branch_Sample_Type_Bits; u64]
 Branch_Sample_Type :: bit_set[Branch_Sample_Type_Bits; u64]
 
 
-/// The struct for perf_event_open
+/*
+	The struct for perf_event_open.
+*/
 Perf_Event_Attr :: struct #packed {
 Perf_Event_Attr :: struct #packed {
 	type:               Perf_Event_Type,
 	type:               Perf_Event_Type,
 	size:               u32,
 	size:               u32,
@@ -336,7 +443,9 @@ Perf_Event_Attr :: struct #packed {
 	_:                  u16,
 	_:                  u16,
 }
 }
 
 
-/// The ring buffer structure when mmaping Perf_Event_Attr
+/*
+	The ring buffer structure when mmaping Perf_Event_Attr.
+*/
 Perf_Event_Mmap_Page :: struct #packed {
 Perf_Event_Mmap_Page :: struct #packed {
 	version:        u32,
 	version:        u32,
 	compat_version: u32,
 	compat_version: u32,
@@ -371,10 +480,14 @@ Perf_Event_Mmap_Page :: struct #packed {
 
 
 // TODO(flysand): Its taking too much effort to bind the other data structures related to perf_event_open
 // TODO(flysand): Its taking too much effort to bind the other data structures related to perf_event_open
 
 
-/// Options for wait4() and waitpid()
+/*
+	Options for wait4(2) and waitpid(2).
+*/
 Wait_Options :: bit_set[Wait_Option; i32]
 Wait_Options :: bit_set[Wait_Option; i32]
 
 
-/// Flags for pidfd_open.2
+/*
+	Flags for pidfd_open(2).
+*/
 Pid_FD_Flags :: bit_set[Pid_FD_Flags_Bits; i32]
 Pid_FD_Flags :: bit_set[Pid_FD_Flags_Bits; i32]
 
 
 // Note(flysand): these could, in principle be implemented with bitfields,
 // Note(flysand): these could, in principle be implemented with bitfields,
@@ -441,6 +554,28 @@ Sig_Info :: struct #packed {
 	},
 	},
 }
 }
 
 
+SIGEV_MAX_SIZE :: 64
+SIGEV_PAD_SIZE :: ((SIGEV_MAX_SIZE-size_of(i32)*2+size_of(Sig_Val))/size_of(i32))
+
+Sig_Val :: struct #raw_union {
+	sival_int: i32,
+	sival_ptr: rawptr,
+}
+
+Sig_Event :: struct {
+	value:  Sig_Val,
+	signo:  i32,
+	notify: i32,
+	using _: struct #raw_union {
+		_: [SIGEV_PAD_SIZE]u32,
+		thread_id: Pid,
+		using _: struct {
+			notify_function:  #type proc "c" (val: Sig_Val),
+			notify_attribute: rawptr,
+		},
+	},
+}
+
 Sig_Stack_Flags :: bit_set[Sig_Stack_Flag; i32]
 Sig_Stack_Flags :: bit_set[Sig_Stack_Flag; i32]
 
 
 Sig_Stack :: struct {
 Sig_Stack :: struct {
@@ -459,27 +594,36 @@ Sig_Action :: struct($T: typeid) {
 	mask: Sig_Set,
 	mask: Sig_Set,
 }
 }
 
 
-
-/// Flags for the socket file descriptor
-/// Note, on linux these are technically passed by OR'ing together
-/// with Socket_Type, our wrapper does this under the hood.
+/*
+	Flags for the socket file descriptor.
+	Note, on linux these are technically passed by OR'ing together
+	with Socket_Type, our wrapper does this under the hood.
+*/
 Socket_FD_Flags :: bit_set[Socket_FD_Flags_Bits; int]
 Socket_FD_Flags :: bit_set[Socket_FD_Flags_Bits; int]
 
 
-/// Address family for the socket
-/// Typically there's one address family for every protocol family
+/*
+	Address family for the socket.
+	Typically there's one address family for every protocol family.
+*/
 Address_Family :: distinct Protocol_Family
 Address_Family :: distinct Protocol_Family
 
 
-/// Flags for the socket for send/recv calls
+/*
+	Flags for the socket for send/recv calls.
+*/
 Socket_Msg :: bit_set[Socket_Msg_Bits; i32]
 Socket_Msg :: bit_set[Socket_Msg_Bits; i32]
 
 
-/// Struct representing IPv4 socket address
+/*
+	Struct representing IPv4 socket address.
+*/
 Sock_Addr_In :: struct #packed {
 Sock_Addr_In :: struct #packed {
 	sin_family: Address_Family,
 	sin_family: Address_Family,
 	sin_port:   u16be,
 	sin_port:   u16be,
 	sin_addr:   [4]u8,
 	sin_addr:   [4]u8,
 }
 }
 
 
-/// Struct representing IPv6 socket address
+/*
+	Struct representing IPv6 socket address.
+*/
 Sock_Addr_In6 :: struct #packed {
 Sock_Addr_In6 :: struct #packed {
 	sin6_family:   Address_Family,
 	sin6_family:   Address_Family,
 	sin6_port:     u16be,
 	sin6_port:     u16be,
@@ -488,7 +632,9 @@ Sock_Addr_In6 :: struct #packed {
 	sin6_scope_id: u32,
 	sin6_scope_id: u32,
 }
 }
 
 
-/// Struct representing an arbitrary socket address
+/*
+	Struct representing an arbitrary socket address.
+*/
 Sock_Addr_Any :: struct #raw_union {
 Sock_Addr_Any :: struct #raw_union {
 	using _: struct {
 	using _: struct {
 		family: Address_Family,
 		family: Address_Family,
@@ -498,13 +644,38 @@ Sock_Addr_Any :: struct #raw_union {
 	using ipv6: Sock_Addr_In6,
 	using ipv6: Sock_Addr_In6,
 }
 }
 
 
-/// Just an alias to make futex-values more visible
+/*
+	Message header for sendmsg/recvmsg
+*/
+Msg_Hdr :: struct {
+	name:       rawptr,
+	namelen:    i32,
+	iov:        []IO_Vec, // ptr followed by length, abi matches
+	control:    []u8,
+	flags:      Socket_Msg,
+}
+
+/*
+	Multiple message header for sendmmsg/recvmmsg
+*/
+MMsg_Hdr :: struct {
+	hdr: Msg_Hdr,
+	len: u32,
+}
+
+/*
+	Just an alias to make futex-values more visible
+*/
 Futex :: u32
 Futex :: u32
 
 
-/// Flags for the futex (they are kept separately)
+/*
+	Flags for the futex (they are kept separately)
+*/
 Futex_Flags :: bit_set[Futex_Flags_Bits; u32]
 Futex_Flags :: bit_set[Futex_Flags_Bits; u32]
 
 
-/// Times
+/*
+	Times
+*/
 Tms :: struct {
 Tms :: struct {
 	tms_utime:  int,
 	tms_utime:  int,
 	tms_stime:  int,
 	tms_stime:  int,
@@ -512,8 +683,10 @@ Tms :: struct {
 	tms_cstime: int,
 	tms_cstime: int,
 }
 }
 
 
-/// "Unix time-sharing system name", allegedly
-/// Basically system info
+/*
+	"Unix time-sharing system name", allegedly.
+	Basically system info.
+*/
 UTS_Name :: struct {
 UTS_Name :: struct {
 	sysname:    [65]u8 `fmt:"s,0"`,
 	sysname:    [65]u8 `fmt:"s,0"`,
 	nodename:   [65]u8 `fmt:"s,0"`,
 	nodename:   [65]u8 `fmt:"s,0"`,
@@ -523,7 +696,9 @@ UTS_Name :: struct {
 	domainname: [65]u8 `fmt:"s,0"`,
 	domainname: [65]u8 `fmt:"s,0"`,
 }
 }
 
 
-/// Return buffer for the sysinfo syscall
+/*
+	Return buffer for the sysinfo syscall
+*/
 Sys_Info :: struct {
 Sys_Info :: struct {
 	uptime:    int,
 	uptime:    int,
 	loads:     [3]int,
 	loads:     [3]int,
@@ -540,14 +715,17 @@ Sys_Info :: struct {
 	_padding:  [20 - (2 * size_of(int)) - size_of(i32)]u8,
 	_padding:  [20 - (2 * size_of(int)) - size_of(i32)]u8,
 }
 }
 
 
-/// Resource limit
+/*
+	Resource limit
+*/
 RLimit :: struct {
 RLimit :: struct {
 	cur: uint,
 	cur: uint,
 	max: uint,
 	max: uint,
 }
 }
 
 
-/// Structure representing how much of each resource
-/// got used.
+/*
+	Structure representing how much of each resource got used.
+*/	
 RUsage :: struct {
 RUsage :: struct {
 	utime:         Time_Val,
 	utime:         Time_Val,
 	stime:         Time_Val,
 	stime:         Time_Val,
@@ -566,3 +744,498 @@ RUsage :: struct {
 	nvcsw_word:    int,
 	nvcsw_word:    int,
 	nivcsw_word:   int,
 	nivcsw_word:   int,
 }
 }
+
+/*
+	Struct used for IO operations
+*/
+IO_Vec :: struct {
+	base: rawptr,
+	len:  uint,
+}
+
+/*
+	Access mode for shared memory
+*/
+IPC_Mode :: bit_set[IPC_Mode_Bits; u32]
+
+/*
+	Flags used by IPC objects
+*/
+IPC_Flags :: bit_set[IPC_Flags_Bits; i16]
+
+/*
+	Permissions for IPC objects
+*/
+IPC_Perm :: struct {
+	key:  Key,
+	uid:  u32,
+	gid:  u32,
+	cuid: u32,
+	cgid: u32,
+	mode: IPC_Mode,
+	seq:  u16,
+	_:    [2 + 2*size_of(int)]u8,
+}
+
+when size_of(int) == 8 || ODIN_ARCH == .i386 {
+	// 32-bit and 64-bit x86, 64-bit arm
+	_Arch_Shmid_DS :: struct {
+		perm:   IPC_Perm,
+		segsz:  uint,
+		atime:  int,
+		dtime:  int,
+		ctime:  int,
+		cpid:   Pid,
+		lpid:   Pid,
+		nattch: uint,
+		_:      [2]uint,
+	}
+} else {
+	// Other 32-bit platforms
+	// NOTE(flysand): I'm not risking assuming it's little endian...
+	_Arch_Shmid_DS :: struct {
+		perm:       IPC_Perm,
+		segsz:      uint,
+		atime:      uint,
+		atime_high: uint,
+		dtime:      uint,
+		dtime_high: uint,
+		ctime:      uint,
+		ctime_high: uint,
+		cpid:       Pid,
+		lpid:       Pid,
+		nattach:    uint,
+		_:          [2]uint,        
+	}
+}
+
+/*
+	SystemV shared memory data.
+*/
+Shmid_DS :: _Arch_Shmid_DS
+
+/*
+	SystemV shared memory info.
+*/
+Shm_Info :: struct {
+	used_ids:       i32,
+	shm_tot:        uint,
+	shm_rss:        uint,
+	shm_swp:        uint,
+	swap_attempts:  uint,
+	swap_successes: uint,
+}
+
+/*
+	SystemV semaphore operation.
+*/
+Sem_Buf :: struct {
+	num: u16,
+	op:  IPC_Cmd,
+	flg: IPC_Flags,
+}
+
+when ODIN_ARCH == .i386 {
+	_Arch_Semid_DS :: struct {
+		perm:       IPC_Perm,
+		otime:      uint,
+		otime_high: uint,
+		ctime:      uint,
+		ctime_high: uint,
+		nsems:      uint,
+		_:          [2]uint,
+	}
+} else when ODIN_ARCH == .amd64 {
+	_Arch_Semid_DS :: struct {
+		perm:       IPC_Perm,
+		otime:      int,
+		ctime:      int,
+		nsems:      uint,
+		_:          [2]uint,
+	}
+} else when ODIN_ARCH == .arm32 {
+	_Arch_Semid_DS :: struct {
+		perm:       IPC_Perm,
+		otime:      uint,
+		otime_high: uint,
+		ctime:      uint,
+		ctime_high: uint,
+		nsems:      uint,
+		_:          [2]uint,
+	}
+} else when ODIN_ARCH == .arm64 {
+	_Arch_Semid_DS :: struct {
+		perm:       IPC_Perm,
+		otime:      int,
+		ctime:      int,
+		sem_nsems:  uint,
+		__unused3:  uint,
+		__unused4:  uint,
+	}
+}
+
+/*
+	Architecture-specific semaphore data.
+*/
+Semid_DS :: _Arch_Semid_DS
+
+/*
+	Argument for semctl functions
+*/
+Sem_Un :: struct #raw_union {
+	val:   i32,
+	buf:   rawptr,
+	array: u16,
+	__buf: Sem_Info,
+	_:     uintptr,
+}
+
+/*
+	SystenV semaphore info.
+*/
+Sem_Info :: struct {
+	semmap: i32,
+	mni: i32,
+	mns: i32,
+	mnu: i32,
+	msl: i32,
+	opm: i32,
+	ume: i32,
+	usz: i32,
+	vmx: i32,
+	aem: i32,
+}
+
+/*
+	Template for the struct used for sending and receiving messages
+*/
+Msg_Buf :: struct {
+	type: int,
+	text: [0]u8,
+}
+
+/*
+	SystemV message queue data.
+*/
+Msqid_DS :: struct {
+	perm:   IPC_Perm,
+	stime:  uint,
+	rtime:  uint,
+	ctime:  uint,
+	cbytes: uint,
+	qnum:   uint,
+	qbytes: uint,
+	lspid:  Pid,
+	lrpid:  Pid,
+	_:      [2]uint,
+}
+
+/*
+	Interval timer types
+*/
+ITimer_Which :: enum {
+	REAL    = 0,
+	VIRTUAL = 1,
+	PROF    = 2,
+}
+
+/*
+	Interval timer value
+*/
+ITimer_Val :: struct {
+	interval: Time_Val,
+	value:    Time_Val,
+}
+
+ITimer_Spec :: struct {
+	interval: Time_Spec,
+	value:    Time_Spec,
+}
+
+/*
+	Flags for POSIX interval timers.
+*/
+ITimer_Flags :: bit_set[ITimer_Flags_Bits; u32]
+
+when ODIN_ARCH == .arm32 {
+	_Arch_User_Regs :: struct {
+		cpsr:             uint,
+		pc:               uint,
+		lr:               uint,
+		sp:               uint,
+		ip:               uint,
+		fp:               uint,
+		r10:              uint,
+		r9:               uint,
+		r8:               uint,
+		r7:               uint,
+		r6:               uint,
+		r5:               uint,
+		r4:               uint,
+		r3:               uint,
+		r2:               uint,
+		r1:               uint,
+		r0:               uint,
+		ORIG_r0:          uint,
+	}
+	// TODO(flysand): Idk what to do about these, couldn't find their
+	// definitions
+	_Arch_User_FP_Regs :: struct {}
+	_Arch_User_FPX_Regs :: struct {}
+} else when ODIN_ARCH == .arm64 {
+	_Arch_User_Regs :: struct {
+		regs:             [31]uint,
+		sp:               uint,
+		pc:               uint,
+		pstate:           uint,
+	}
+	_Arch_User_FP_Regs :: struct {
+		vregs:            [32]u128,
+		fpsr:             u32,
+		fpcr:             u32,
+		_:                [2]u32,
+	}
+	_Arch_User_FPX_Regs :: struct {}
+} else when ODIN_ARCH == .i386 {
+	_Arch_User_Regs :: struct {
+		ebx:              uint,
+		ecx:              uint,
+		edx:              uint,
+		esi:              uint,
+		edi:              uint,
+		ebp:              uint,
+		eax:              uint,
+		xds:              uint,
+		xes:              uint,
+		xfs:              uint,
+		xgs:              uint,
+		orig_eax:         uint,
+		eip:              uint,
+		xcs:              uint,
+		eflags:           uint,
+		esp:              uint,
+		xss:              uint,
+	}
+	// x87 FPU state
+	_Arch_User_FP_Regs :: struct {
+		cwd:              uint,
+		swd:              uint,
+		twd:              uint,
+		fip:              uint,
+		fcs:              uint,
+		foo:              uint,
+		fos:              uint,
+		st_space:         [20]uint,
+	}
+	// FXSR instruction set state
+	_Arch_User_FPX_Regs :: struct {
+		cwd:              u16,
+		swd:              u16,
+		twd:              u16,
+		fop:              u16,
+		fip:              uint,
+		fcs:              uint,
+		foo:              uint,
+		fos:              uint,
+		mxcsr:            uint,
+		_:                uint,
+		st_space:         [32]uint,
+		xmm_space:        [32]uint,
+		padding:          [56]uint,
+	}
+} else when ODIN_ARCH == .amd64 {
+	_Arch_User_Regs :: struct {
+		// Callee-preserved, may not be correct if the syscall doesn't need
+		// these registers
+		r15:              uint,
+		r14:              uint,
+		r13:              uint,
+		r12:              uint,
+		rbp:              uint,
+		rbx:              uint,
+		// Always saved
+		r11:              uint,
+		r10:              uint,
+		r9:               uint,
+		r8:               uint,
+		rax:              uint,
+		rcx:              uint,
+		rdx:              uint,
+		rsi:              uint,
+		rdi:              uint,
+		// On syscall entry this is the syscall number, on CPU exception this
+		// is the error code, on hardware interrupt this is its IRQ number
+		orig_rax:         uint,
+		// Return frame for iretq
+		rip:              uint,
+		cs:               uint,
+		eflags:           uint,
+		rsp:              uint,
+		ss:               uint,
+	}
+	// All floating point state
+	_Arch_User_FP_Regs :: struct {
+		cwd:              u16,
+		swd:              u16,
+		twd:              u16,
+		fop:              u16,
+		rip:              uint,
+		rdp:              uint,
+		mxcsr:            u32,
+		mxcsr_mask:       u32,
+		st_space:         [32]u32,
+		xmm_space:        [64]u32,
+		_:                [24]u32,
+	}
+	// FXSR instruction set state
+	_Arch_User_FPX_Regs :: struct {
+		cwd:              u16,
+		swd:              u16,
+		twd:              u16,
+		fop:              u16,
+		fip:              uint,
+		fcs:              uint,
+		foo:              uint,
+		fos:              uint,
+		mxcsr:            uint,
+		_:                uint,
+		st_space:         [32]uint,
+		xmm_space:        [32]uint,
+		padding:          [56]uint,
+	}
+}
+
+/*
+	Architecture-specific registers struct.
+*/
+User_Regs :: _Arch_User_Regs
+
+/*
+	Architecture-specific floating-point registers
+*/
+User_FP_Regs :: _Arch_User_FP_Regs
+
+/*
+	Architecture-specific extended floating-point registers.
+	Currently only used for x86 CPU's.
+*/
+User_FPX_Regs :: _Arch_User_FPX_Regs
+
+/*
+	ptrace options.
+*/
+PTrace_Options :: bit_set[PTrace_Options_Bits; u32]
+
+/*
+	ptrace's PEEKSIGINFO argument.
+*/
+PTrace_Peek_Sig_Info_Args :: struct {
+	off:   u64,
+	flags: PTrace_Peek_Sig_Info_Flags,
+	nr:    i32,
+}
+
+/*
+	ptrace's PEEKSIGINFO flags.
+*/
+PTrace_Peek_Sig_Info_Flags :: bit_set[PTrace_Peek_Sig_Info_Flags_Bits; u32]
+
+/*
+	ptrace's SECCOMP metadata.
+*/
+PTrace_Seccomp_Metadata :: struct {
+	filter_off: u64,
+	flags:      u64,
+}
+
+/*
+	ptrace's results of GET_SYSCALL_INFO.
+*/
+PTrace_Syscall_Info :: struct {
+	op:                  PTrace_Get_Syscall_Info_Op,
+	arch:                u32, // TODO: AUDIT_ARCH*
+	instruction_pointer: u64,
+	stack_pointer:       u64,
+	using _: struct #raw_union {
+		entry: struct {
+			nr:       u64,
+			args:     [6]u64,
+		},
+		exit: struct {
+			rval:     i64,
+			is_error: b8,
+		},
+		seccomp: struct {
+			nr:       u64,
+			args:     [6]u64,
+			ret_data: u32,
+		},
+	},
+}
+
+/*
+	ptrace's results of GET_RSEQ_CONFIGURATION.
+*/
+PTrace_RSeq_Configuration :: struct {
+	rseq_abi_pointer: u64,
+	rseq_abi_size:    u32,
+	signature:        u32,
+	flags:            u32,
+	_:                u32,
+}
+
+/*
+	Note types for PTRACE_GETREGSET. Mirrors constants in `elf` definition,
+	files though this enum only contains the constants defined for architectures
+	Odin can compile to.
+*/
+PTrace_Note_Type :: enum {
+	NT_PRSTATUS             = 1,
+	NT_PRFPREG              = 2,
+	NT_PRPSINFO             = 3,
+	NT_TASKSTRUCT           = 4,
+	NT_AUXV                 = 6,
+	NT_SIGINFO              = 0x53494749,
+	NT_FILE                 = 0x46494c45,
+	NT_PRXFPREG             = 0x46e62b7f,
+	NT_386_TLS              = 0x200,
+	NT_386_IOPERM           = 0x201,
+	NT_X86_XSTATE           = 0x202,
+	NT_X86_SHSTK            = 0x204,
+	NT_ARM_VFP              = 0x400,
+	NT_ARM_TLS              = 0x401,
+	NT_ARM_HW_BREAK         = 0x402,
+	NT_ARM_HW_WATCH         = 0x403,
+	NT_ARM_SYSTEM_CALL      = 0x404,
+	NT_ARM_SVE              = 0x405,
+	NT_ARM_PAC_MASK         = 0x406,
+	NT_ARM_PACA_KEYS        = 0x407,
+	NT_ARM_PACG_KEYS        = 0x408,
+	NT_ARM_TAGGED_ADDR_CTRL = 0x409,
+	NT_ARM_PAC_ENABLED_KEYS = 0x40a,
+	NT_ARM_SSVE             = 0x40b,
+	NT_ARM_ZA               = 0x40c,
+	NT_ARM_ZT               = 0x40d,
+}
+
+/*
+	Flags for splice(2) and tee(2) syscalls.
+*/
+Splice_Flags :: bit_set[Splice_Flags_Bits; u32]
+
+/*
+	Flags for epoll_create(2) syscall.
+*/
+EPoll_Flags :: bit_set[EPoll_Flags_Bits; i32]
+
+EPoll_Data :: struct #raw_union {
+	ptr: rawptr,
+	fd:  Fd,
+	u32: u32,
+	u64: u64,
+}
+
+EPoll_Event :: struct #packed {
+	events: EPoll_Event_Kind,
+	data:   EPoll_Data,
+}

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini