[sys/linux]: Documentation improvements

This commit is contained in:
flysand7
2023-11-04 13:35:13 +11:00
parent 1e622979f8
commit 574d2baf09
4 changed files with 1064 additions and 523 deletions
+175 -66
View File
@@ -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,
@@ -717,7 +780,9 @@ Perf_Event_Sample_Type_Bits :: enum {
WEIGHT_STRUCT = 24, WEIGHT_STRUCT = 24,
} }
/// Describes field sets to include in mmaped page /*
Describes field sets to include in mmaped page
*/
Perf_Read_Format :: enum { Perf_Read_Format :: enum {
TOTAL_TIME_ENABLED = 0, TOTAL_TIME_ENABLED = 0,
TOTAL_TIME_RUNNING = 1, TOTAL_TIME_RUNNING = 1,
@@ -726,7 +791,9 @@ Perf_Read_Format :: 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 +803,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 +828,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 +838,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 +854,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 +926,12 @@ Sig_Stack_Flag :: enum i32 {
AUTODISARM = 31, AUTODISARM = 31,
} }
/// Type of socket to create /*
/// For TCP you want to use SOCK_STREAM Type of socket to create
/// For UDP you want to use SOCK_DGRAM - For TCP you want to use SOCK_STREAM
/// Also see Protocol - 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 +942,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 +1005,13 @@ Protocol_Family :: enum u16 {
MCTP = 45, MCTP = 45,
} }
/// The protocol number according to IANA protocol number list /*
/// Full list of protocol numbers: The protocol number according to IANA protocol number list
/// https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml Full list of protocol numbers:
/// Supported by the OS protocols can be queried by reading: https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
/// /etc/protocols 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 +1151,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 +1190,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 +1338,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 +1366,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 +1395,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 +1419,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 +1431,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 +1454,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 +1464,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 +1479,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
+83 -29
View File
@@ -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,
@@ -169,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
+613 -351
View File
File diff suppressed because it is too large Load Diff
+193 -77
View File
@@ -1,46 +1,68 @@
//+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
/// Shared memory identifiers used by `shm*` calls /*
Shared memory identifiers used by shmget(2) and other calls.
*/
Key :: distinct i32 Key :: distinct i32
/* /*
Represents timer IDs Represents timer IDs.
*/ */
Timer :: distinct i32 Timer :: distinct i32
/// Represents time with nanosecond precision /*
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,
@@ -52,22 +74,31 @@ Time_Val :: struct {
UTim_Buf :: struct { UTim_Buf :: struct {
actime: uint, actime: uint,
modtime: uint, modtime: uint,
}; }
/*
/// open.2 flags 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: Represents file's permission and status bits
/// When you're passing a value of this type the recommended usage is **Example:**
/// sys.Mode{.S_IXOTH, .S_IROTH} | sys.S_IRWXU | sys.S_IRWXG When you're passing a value of this type the recommended usage is:
/// This would generate a mode that has full permissions for the
/// file's owner and group, and only "read" and "execute" bits ```
/// for others. 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 {
@@ -128,29 +159,38 @@ when ODIN_ARCH == .amd64 {
} }
} }
/// Represents the file state. /*
/// Mirrors struct stat in glibc/linux kernel. Represents the file state.
/// If you're on 32-bit platform, consider using Stat64 instead 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 File attributes, returned by statx. This bitset is also
/// their value. 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,
@@ -182,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 {
@@ -222,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() Directory entry record.
/// and dirent_name() 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,
@@ -243,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,
@@ -259,50 +312,76 @@ FLock :: struct {
*/ */
FLock_Op :: bit_set[FLock_Op_Bits; i32] FLock_Op :: bit_set[FLock_Op_Bits; i32]
/// Flags for fcntl_notify /*
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]
@@ -311,10 +390,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,
@@ -358,7 +441,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,
@@ -393,10 +478,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,
@@ -503,27 +592,36 @@ Sig_Action :: struct($T: typeid) {
mask: Sig_Set, mask: Sig_Set,
} }
/*
/// Flags for the socket file descriptor Flags for the socket file descriptor.
/// Note, on linux these are technically passed by OR'ing together Note, on linux these are technically passed by OR'ing together
/// with Socket_Type, our wrapper does this under the hood. 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,
@@ -532,7 +630,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,
@@ -561,13 +661,19 @@ MMsg_Hdr :: struct {
len: u32, len: u32,
} }
/// Just an alias to make futex-values more visible /*
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,
@@ -575,8 +681,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"`,
@@ -586,7 +694,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,
@@ -603,14 +713,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,
@@ -1088,4 +1201,7 @@ PTrace_Note_Type :: enum {
NT_ARM_ZT = 0x40d, NT_ARM_ZT = 0x40d,
} }
/*
Flags for splice(2) and tee(2) syscalls.
*/
Splice_Flags :: bit_set[Splice_Flags_Bits; u32] Splice_Flags :: bit_set[Splice_Flags_Bits; u32]