diff --git a/core/sys/linux/bits.odin b/core/sys/linux/bits.odin index c7c0e5ae6..fa5c31cce 100644 --- a/core/sys/linux/bits.odin +++ b/core/sys/linux/bits.odin @@ -1,7 +1,9 @@ package linux -/// Represents an error returned by most of syscalls +/* + Represents an error returned by most of syscalls +*/ Errno :: enum i32 { NONE = 0, // Errno-base @@ -142,8 +144,9 @@ Errno :: enum i32 { EDEADLOCK = EDEADLK, } - -/// Bits for Open_Flags +/* + Bits for Open_Flags +*/ Open_Flags_Bits :: enum { RDONLY = 0, WRONLY = 1, @@ -164,7 +167,9 @@ Open_Flags_Bits :: enum { PATH = 21, } -/// Bits for FD_Flags bitset +/* + Bits for FD_Flags bitset +*/ FD_Flags_Bits :: enum { SYMLINK_NOFOLLOW = 8, REMOVEDIR = 9, @@ -177,7 +182,9 @@ FD_Flags_Bits :: enum { RECURSIVE = 15, } -/// The bits for the Mode bitset. +/* + The bits for the Mode bitset. +*/ Mode_Bits :: enum { IXOTH = 0, // 0o0000001 IWOTH = 1, // 0o0000002 @@ -197,7 +204,9 @@ Mode_Bits :: enum { IFREG = 15, // 0o0100000 } -/// The bits used by the Statx_Mask bitset +/* + The bits used by the Statx_Mask bitset +*/ Statx_Mask_Bits :: enum { TYPE = 0, MODE = 1, @@ -215,8 +224,10 @@ Statx_Mask_Bits :: enum { 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 { COMPRESSED = 2, // 0x00000004 IMMUTABLE = 4, // 0x00000010 @@ -229,7 +240,9 @@ Statx_Attr_Bits :: enum { DAX = 21, // 0x00200000 } -/// Magic bits for filesystems returned by Stat_FS +/* + Magic bits for filesystems returned by Stat_FS +*/ FS_Magic :: enum u32 { ADFS_SUPER_MAGIC = 0xadf5, AFFS_SUPER_MAGIC = 0xadff, @@ -317,7 +330,9 @@ FS_Magic :: enum u32 { _XIAFS_SUPER_MAGIC = 0x012fd16d, } -/// Bits for FS_Flags bitset +/* + Bits for FS_Flags bitset +*/ FS_Flags_Bits :: enum { RDONLY = 0, NOSUID = 1, @@ -340,20 +355,26 @@ Seek_Whence :: enum i16 { HOLE = 4, } -/// Bits for Close_Range_Flags +/* + Bits for Close_Range_Flags +*/ Close_Range_Flags_Bits :: enum { CLOEXEC = 2, UNSHARE = 1, } -/// Bits for Rename_Flags +/* + Bits for Rename_Flags +*/ Rename_Flags_Bits :: enum { EXCHANGE = 1, NOREPLACE = 0, WHITEOUT = 2, } -/// Type of the file in a directory entry +/* + Type of the file in a directory entry +*/ Dirent_Type :: enum u8 { UNKNOWN = 0, FIFO = 1, @@ -366,14 +387,18 @@ Dirent_Type :: enum u8 { WHT = 14, } -/// Type of a lock for fcntl.2 +/* + Type of a lock for fcntl(2) +*/ FLock_Type :: enum i16 { RDLCK = 0, WRLCK = 1, UNLCK = 2, } -/// Bits for FD_Notifications +/* + Bits for FD_Notifications +*/ FD_Notifications_Bits :: enum { ACCESS = 0, MODIFY = 1, @@ -384,7 +409,9 @@ FD_Notifications_Bits :: enum { MULTISHOT = 31, } -/// Bits for seal +/* + Bits for seal +*/ Seal_Bits :: enum { SEAL = 0, SHRINK = 1, @@ -408,14 +435,18 @@ FD_Lease :: enum { UNLCK = 2, } -/// Kind of owner for FD_Owner +/* + Kind of owner for FD_Owner +*/ F_Owner_Type :: enum i32 { OWNER_TID = 0, OWNER_PID = 1, OWNER_PGRP = 2, } -/// Command for fcntl.2 +/* + Command for fcntl(2) +*/ FCntl_Command :: enum { DUPFD = 0, GETFD = 1, @@ -465,7 +496,9 @@ Fd_Poll_Events_Bits :: enum { RDHUP = 13, } -/// Bits for Mem_Protection bitfield +/* + Bits for Mem_Protection bitfield +*/ Mem_Protection_Bits :: enum{ READ = 0, WRITE = 1, @@ -479,7 +512,9 @@ Mem_Protection_Bits :: enum{ GROWSUP = 25, } -/// Bits for Map_Flags +/* + Bits for Map_Flags +*/ Map_Flags_Bits :: enum { SHARED = 0, PRIVATE = 1, @@ -504,19 +539,25 @@ Map_Flags_Bits :: enum { UNINITIALIZED = 26, } -/// Bits for MLock_Flags +/* + Bits for MLock_Flags +*/ MLock_Flags_Bits :: enum { ONFAULT = 0, } -/// Bits for MSync_Flags +/* + Bits for MSync_Flags +*/ MSync_Flags_Bits :: enum { ASYNC = 0, INVALIDATE = 1, SYNC = 2, } -/// Argument for madvice.2 +/* + Argument for madvice(2) +*/ MAdvice :: enum { NORMAL = 0, RANDOM = 1, @@ -545,27 +586,35 @@ MAdvice :: enum { SOFT_OFFLINE = 101, } -/// Bits for PKey_Access_Rights +/* + Bits for PKey_Access_Rights +*/ PKey_Access_Bits :: enum { DISABLE_ACCESS = 0, DISABLE_WRITE = 2, } -/// Bits for MRemap_Flags +/* + Bits for MRemap_Flags +*/ MRemap_Flags_Bits :: enum { MAYMOVE = 0, FIXED = 1, DONTUNMAP = 2, } -/// Bits for Get_Random_Flags +/* + Bits for Get_Random_Flags +*/ Get_Random_Flags_Bits :: enum { RANDOM = 0, NONBLOCK = 1, INSECURE = 2, } -/// Bits for Perf_Flags +/* + Bits for Perf_Flags +*/ Perf_Flags_Bits :: enum { FD_NO_GROUP = 0, FD_OUTPUT = 1, @@ -573,7 +622,9 @@ Perf_Flags_Bits :: enum { FD_CLOEXEC = 3, } -/// Union tag for Perf_Event_Attr struct +/* + Union tag for Perf_Event_Attr struct +*/ Perf_Event_Type :: enum u32 { HARDWARE = 0, SOFTWARE = 1, @@ -633,7 +684,9 @@ Perf_Cap_Flags_Bits :: enum u64 { 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 { CPU_CYCLES = 0, INSTRUCTIONS = 1, @@ -647,7 +700,9 @@ Perf_Hardware_Id :: enum u64 { 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 { L1D = 0, L1I = 1, @@ -658,20 +713,26 @@ Perf_Hardware_Cache_Id :: enum u64 { 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 { READ = 0, WRITE = 1, 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 { ACCESS = 0, 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 { CPU_CLOCK = 0, 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 { IP = 0, TID = 1, @@ -717,7 +780,9 @@ Perf_Event_Sample_Type_Bits :: enum { WEIGHT_STRUCT = 24, } -/// Describes field sets to include in mmaped page +/* + Describes field sets to include in mmaped page +*/ Perf_Read_Format :: enum { TOTAL_TIME_ENABLED = 0, TOTAL_TIME_RUNNING = 1, @@ -726,7 +791,9 @@ Perf_Read_Format :: enum { LOST = 4, } -/// Chooses the breakpoint type +/* + Chooses the breakpoint type +*/ Hardware_Breakpoint_Type :: enum u32 { EMPTY = 0, R = 1, @@ -736,7 +803,9 @@ Hardware_Breakpoint_Type :: enum u32 { INVALID = RW | X, } -/// Bits for Branch_Sample_Type +/* + Bits for Branch_Sample_Type +*/ Branch_Sample_Type_Bits :: enum { USER = 0, KERNEL = 1, @@ -759,7 +828,9 @@ Branch_Sample_Type_Bits :: enum { PRIV_SAVE = 18, } -/// Represent the type of Id +/* + Represent the type of Id +*/ Id_Type :: enum uint { ALL = 0, PID = 1, @@ -767,7 +838,9 @@ Id_Type :: enum uint { PIDFD = 3, } -/// Options for wait syscalls +/* + Options for wait syscalls +*/ Wait_Option :: enum { WNOHANG = 0, WUNTRACED = 1, @@ -781,12 +854,16 @@ Wait_Option :: enum { __WCLONE = 31, } -/// Bits for flags for pidfd +/* + Bits for flags for pidfd +*/ Pid_FD_Flags_Bits :: enum { NONBLOCK = 11, } -/// Priority for process, process group, user +/* + Priority for process, process group, user +*/ Priority_Which :: enum i32 { PROCESS = 0, PGRP = 1, @@ -849,10 +926,12 @@ Sig_Stack_Flag :: enum i32 { 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 { STREAM = 1, DGRAM = 2, @@ -863,13 +942,17 @@ Socket_Type :: enum { PACKET = 10, } -/// Bits for Socket_FD_Flags +/* + Bits for Socket_FD_Flags +*/ Socket_FD_Flags_Bits :: enum { NONBLOCK = 14, CLOEXEC = 25, } -/// Protocol family +/* + Protocol family +*/ Protocol_Family :: enum u16 { UNSPEC = 0, LOCAL = 1, @@ -922,11 +1005,13 @@ Protocol_Family :: enum u16 { 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 { HOPOPT = 0, ICMP = 1, @@ -1066,7 +1151,9 @@ Protocol :: enum { Reserved = 255, } -/// API Level for get/setsockopt.2 +/* + API Level for getsockopt(2)/setsockopt(2) +*/ Socket_API_Level :: enum { // Comes from SOCKET = 1, @@ -1103,8 +1190,10 @@ Socket_API_Level :: enum { 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 { DEBUG = 1, REUSEADDR = 2, @@ -1249,7 +1338,9 @@ Socket_TCP_Option :: enum { TX_DELAY = 37, } -/// Bits for Socket_Msg +/* + Bits for Socket_Msg +*/ Socket_Msg_Bits :: enum { OOB = 0, PEEK = 1, @@ -1275,14 +1366,18 @@ Socket_Msg_Bits :: enum { CMSG_CLOEXEC = 30, } -/// Argument to shutdown.2 +/* + Argument to shutdown(2) +*/ Shutdown_How :: enum i32 { RD = 0, WR = 1, RDWR = 2, } -/// Second argument to futex.2 syscall +/* + Second argument to futex(2) syscall +*/ Futex_Op :: enum u32 { WAIT = 0, WAKE = 1, @@ -1300,13 +1395,17 @@ Futex_Op :: enum u32 { LOCK_PI2 = 13, } -/// Bits for Futex_Flags +/* + Bits for Futex_Flags +*/ Futex_Flags_Bits :: enum { PRIVATE = 7, REALTIME = 8, } -/// Kind of operation on futex, see FUTEX_WAKE_OP +/* + Kind of operation on futex, see FUTEX_WAKE_OP +*/ Futex_Arg_Op :: enum { SET = 0, /* uaddr2 = oparg; */ ADD = 1, /* uaddr2 += oparg; */ @@ -1320,7 +1419,9 @@ Futex_Arg_Op :: enum { PO2_XOR = 4, /* uaddr2 ^= 1<= cmparg) wake */ } -/// The kind of resource limits +/* + The kind of resource limits +*/ RLimit_Kind :: enum i32 { CPU = 0, FSIZE = 1, @@ -1351,7 +1454,9 @@ RLimit_Kind :: enum i32 { NLIMITS = 16, } -/// Represents the user of resources +/* + Represents the user of resources +*/ RUsage_Who :: enum i32 { CHILDREN = -1, SELF = 0, @@ -1359,7 +1464,9 @@ RUsage_Who :: enum i32 { LWP = THREAD, } -/// Bits for Personality_Flags +/* + Bits for Personality_Flags +*/ UNAME26 :: 17 ADDR_NO_RANDOMIZE :: 18 FDPIC_FUNCPTRS :: 19 @@ -1372,8 +1479,10 @@ WHOLE_SECONDS :: 25 STICKY_TIMEOUTS :: 26 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_32BIT :: 0x0000 | ADDR_LIMIT_32BIT PER_LINUX_FDPIC :: 0x0000 | FDPIC_FUNCPTRS diff --git a/core/sys/linux/constants.odin b/core/sys/linux/constants.odin index a1bcd09ab..6294602e9 100644 --- a/core/sys/linux/constants.odin +++ b/core/sys/linux/constants.odin @@ -1,26 +1,40 @@ 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) -/// 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) -/// 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) -/// For wait4: Pass this pid to wait for any process +/* + For wait4: Pass this pid to wait for any process. +*/ 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) -/// Maximum priority (aka nice value) for the process +/* + Maximum priority (aka nice value) for the process. +*/ PRIO_MAX :: 20 -/// Minimum priority (aka nice value) for the process +/* + Minimum priority (aka nice value) for the process. +*/ PRIO_MIN :: -20 SIGRTMIN :: Signal(32) @@ -35,40 +49,64 @@ S_IFCHR :: Mode{.IFCHR} S_IFDIR :: Mode{.IFDIR} 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))} -/// 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))} - -/// 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))} -/// 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))} -/// 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))} -/// 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))} -/// 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))} -/// 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{} -/// 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} -/// 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} -/// 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} -/// The stats you get by calling `stat` +/* + The stats you get by calling `stat`. +*/ STATX_BASIC_STATS :: Statx_Mask { .TYPE, .MODE, @@ -169,28 +207,44 @@ Futex_Wait_requeue_Pi_Type :: distinct Futex_Op Futex_Cmp_requeue_Pi_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) -/// Wake up other processes waiting on the futex +/* + Wake up other processes waiting on the futex. +*/ FUTEX_WAKE :: Futex_Wake_Type(.WAKE) -/// Not implemented. Basically, since +/* + Not implemented. Basically, since. +*/ 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) -/// 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) -/// 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) -/// 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) -/// 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) // TODO(flysand): Priority inversion futexes diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index 13226939e..ef243706d 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -4,35 +4,40 @@ package linux import "core:intrinsics" -/// Read data from file into the buffer -/// Returns the number of bytes successfully read, which may be less than the size -/// of the buffer even if the termination is successfull -/// -/// Available since Linux 1.0 -/// Before Linux 3.14, this operation is not atomic (i.e. not thread safe). +/* + Read data from file into the buffer + Returns the number of bytes successfully read, which may be less than the size + of the buffer even if the termination is successfull. + Available since Linux 1.0. + Before Linux 3.14, this operation is not atomic (i.e. not thread safe). +*/ read :: proc "contextless" (fd: Fd, buf: []$T) -> (int, Errno) { ret := syscall(SYS_read, fd, raw_data(buf), len(buf) * size_of(T)) return errno_unwrap(ret, int) } -/// Write the data from a buffer into the file -/// Returns the number of bytes successfully written, which may be less than the size -/// of the buffer, even if the termination is successfull -/// When using direct I/O, error doesn't mean the write has failed. Partial data may -/// have been written. -/// If .Eintr is returned, the write operation has failed due to interrupt. You'll probably -/// need to restart this syscall -/// -/// Available since Linux 1.0 -/// Before Linux 3.14 this operation is not atomic (i.e. not thread safe) +/* + Write the data from a buffer into the file + Returns the number of bytes successfully written, which may be less than the size + of the buffer, even if the termination is successfull + When using direct I/O, error doesn't mean the write has failed. Partial data may + have been written. + If .Eintr is returned, the write operation has failed due to interrupt. You'll probably + need to restart this syscall + + Available since Linux 1.0 + Before Linux 3.14 this operation is not atomic (i.e. not thread safe) +*/ write :: proc "contextless" (fd: Fd, buf: []$T) -> (int, Errno) { ret := syscall(SYS_write, fd, raw_data(buf), len(buf)*size_of(T)) return errno_unwrap(ret, int) } -/// Open file, get the file descriptor -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Open file, get the file descriptor + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ open :: proc "contextless" (name: cstring, flags: Open_Flags, mode: Mode = {}) -> (Fd, Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_openat, AT_FDCWD, transmute(uintptr) name, transmute(u32) mode) @@ -43,20 +48,24 @@ open :: proc "contextless" (name: cstring, flags: Open_Flags, mode: Mode = {}) - } } -/// Close the file -/// Available since Linux 1.0 +/* + Close the file. + Available since Linux 1.0. +*/ close :: proc "contextless" (fd: Fd) -> (Errno) { ret := syscall(SYS_close, fd) return Errno(-ret) } -/// Get file status -/// -/// Returns information about the file in struct pointed to by `stat` parameter. -/// -/// Available since Linux 1.0 -/// For 32-bit systems a different syscall is used that became available since 2.4 -/// Not available on arm64 +/* + Get file status. + + Returns information about the file in struct pointed to by `stat` parameter. + + Available since Linux 1.0 + For 32-bit systems a different syscall is used that became available since 2.4. + Not available on ARM64. +*/ stat :: proc "contextless" (filename: cstring, stat: ^Stat) -> (Errno) { when size_of(int) == 8 { when ODIN_ARCH == .arm64 { @@ -72,12 +81,14 @@ stat :: proc "contextless" (filename: cstring, stat: ^Stat) -> (Errno) { } } -/// Get file status from file descriptor -/// -/// Returns information about the file in struct pointed to by `stat` parameter. -/// -/// Available since Linux 1.0 -/// For 32-bit systems a different syscall is used that became available since 2.4 +/* + Get file status from file descriptor. + + Returns information about the file in struct pointed to by `stat` parameter. + + Available since Linux 1.0. + For 32-bit systems a different syscall is used that became available since 2.4. +*/ fstat :: proc "contextless" (fd: Fd, stat: ^Stat) -> (Errno) { when size_of(int) == 8 { ret := syscall(SYS_fstat, stat) @@ -88,14 +99,16 @@ fstat :: proc "contextless" (fd: Fd, stat: ^Stat) -> (Errno) { } } -/// Get information about the file that's potentially a symbolic link -/// The information is returned in a struct pointed to by `stat` parameter. -/// The difference with stat, fstat is that if the file is a symbolic link, -/// stat and fstat will dereference the link. lstat doesn't dereference symlinks -/// -/// Available since Linux 1.0 -/// For 32-bit systems a different syscall is used that became available since 2.4 -/// Not available on arm64 +/* + Get information about the file that's potentially a symbolic link + The information is returned in a struct pointed to by `stat` parameter. + The difference with stat, fstat is that if the file is a symbolic link, + stat and fstat will dereference the link. lstat doesn't dereference symlinks. + + Available since Linux 1.0. + For 32-bit systems a different syscall is used that became available since 2.4. + Not available on arm64. +*/ lstat :: proc "contextless" (filename: cstring, stat: ^Stat) -> (Errno) { when size_of(int) == 8 { when ODIN_ARCH == .arm64 { @@ -110,8 +123,10 @@ lstat :: proc "contextless" (filename: cstring, stat: ^Stat) -> (Errno) { } } -/// Wait on event on a file descriptor -/// Available since Linux 2.2 +/* + Wait on event on a file descriptor. + Available since Linux 2.2. +*/ poll :: proc "contextless" (fds: []Poll_Fd, timeout: i32) -> (i32, Errno) { when ODIN_ARCH == .arm64 { seconds := cast(uint) timeout / 1000 @@ -125,10 +140,11 @@ poll :: proc "contextless" (fds: []Poll_Fd, timeout: i32) -> (i32, Errno) { } } - -/// Seek the file stream to specified offset -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 1.2 +/* + Seek the file stream to specified offset. + Available since Linux 1.0. + On 32-bit platforms available since Linux 1.2. +*/ lseek :: proc "contextless" (fd: Fd, off: i64, whence: Seek_Whence) -> (Errno) { when size_of(int) == 8 { ret := syscall(SYS_lseek, fd, off, whence) @@ -139,9 +155,11 @@ lseek :: proc "contextless" (fd: Fd, off: i64, whence: Seek_Whence) -> (Errno) { } } -/// Map files into memory -/// Available since Linux 1.0 -/// On 32-bit platforms since Linux 1.0 +/* + Map files into memory. + Available since Linux 1.0. + On 32-bit platforms since Linux 1.0. +*/ mmap :: proc "contextless" (addr: uintptr, size: uint, prot: Mem_Protection, flags: Map_Flags, fd: Fd = Fd(-1), offset: i64 = 0) -> (rawptr, Errno) { when size_of(int) == 8 { ret := syscall(SYS_mmap, addr, size, transmute(i32) prot, transmute(i32) flags, fd, offset) @@ -152,14 +170,19 @@ mmap :: proc "contextless" (addr: uintptr, size: uint, prot: Mem_Protection, fla } } -/// Protect memory region +/* + Protect memory region. + Available since Linux 1.0. +*/ mprotect :: proc "contextless" (addr: rawptr, size: uint, prot: Mem_Protection) -> (Errno) { ret := syscall(SYS_mprotect, addr, size, transmute(i32) prot) return Errno(-ret) } -/// Unmap memory -/// Available since Linux 1.0 +/* + Unmap memory. + Available since Linux 1.0. +*/ munmap :: proc "contextless" (addr: rawptr, size: uint) -> (Errno) { ret := syscall(SYS_mmap, addr, size) return Errno(-ret) @@ -176,14 +199,18 @@ brk :: proc "contextless" (addr: uintptr) -> (Errno) { return Errno(-ret) } -/// Alter an action taken by a process +/* + Alter an action taken by a process. +*/ rt_sigaction :: proc "contextless" (sig: Signal, sigaction: ^Sig_Action, old_sigaction: ^Sig_Action) -> Errno { ret := syscall(SYS_rt_sigaction, sig, sigaction, old_sigaction, size_of(Sig_Set)) return Errno(-ret) } -/// Examime and alter blocked signals -/// Available since Linux 2.2 +/* + Examime and alter blocked signals. + Available since Linux 2.2. +*/ rt_sigprocmask :: proc "contextless" (mask_kind: Sig_Mask_Kind, new_set: ^Sig_Set, old_set: ^Sig_Set) -> Errno { ret := syscall(SYS_rt_sigprocmask, mask_kind, new_set, old_set, size_of(Sig_Set)) return Errno(-ret) @@ -191,17 +218,21 @@ rt_sigprocmask :: proc "contextless" (mask_kind: Sig_Mask_Kind, new_set: ^Sig_Se // TODO(flysand): ioctl -/// Read the file at a specified offset -/// Note, it is not an error to return less bytes than requested -/// Available since Linux 2.2 +/* + Read the file at a specified offset. + Note, it is not an error to return less bytes than requested. + Available since Linux 2.2. +*/ pread :: proc "contextless" (fd: Fd, buf: []$T, offset: i64) -> (int, Errno) { ret := syscall(SYS_pread64, fd, raw_data(buf), compat64_arg_pair(len(buf)*size_of(T))) return errno_unwrap(ret, int) } -/// Read the file at a specified offset -/// Note, it is not an error to return less bytes than requested -/// Available since Linux 2.2 +/* + Read the file at a specified offset. + Note, it is not an error to return less bytes than requested. + Available since Linux 2.2. +*/ pwrite :: proc "contextless" (fd: Fd, buf: []$T, offset: i64) -> (int, Errno) { ret := syscall(SYS_pwrite64, fd, raw_data(buf), compat64_arg_pair(len(buf)*size_of(T))) return errno_unwrap(ret, int) @@ -225,11 +256,13 @@ writev :: proc "contextless" (fd: Fd, iov: []IO_Vec) -> (int, Errno) { return errno_unwrap(ret, int) } -/// Check user permissions for a file -/// If Mode is F_OK, checks whether the file exists -/// Similarly, X_OK, W_OK, R_OK check if the file is executable, writeable, readable respectively -/// Available since Linux 1.0 -/// For ARM64 available since Linux 2.6.16 +/* + Check user permissions for a file. + If Mode is F_OK, checks whether the file exists. + Similarly, X_OK, W_OK, R_OK check if the file is executable, writeable, readable respectively. + Available since Linux 1.0. + For ARM64 available since Linux 2.6.16. +*/ access :: proc "contextless" (name: cstring, mode: Mode = F_OK) -> (bool, Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_faccessat, AT_FDCWD, cast(rawptr) name, transmute(u32) mode) @@ -240,8 +273,10 @@ access :: proc "contextless" (name: cstring, mode: Mode = F_OK) -> (bool, Errno) } } -/// Create a pipe -/// Available since Linux 2.6.27 +/* + Create a pipe + Available since Linux 2.6.27 +*/ pipe2 :: proc "contextless" (pipes: ^[2]Fd, flags: Open_Flags) -> (Errno) { ret := syscall(SYS_pipe2, pipes, transmute(u32) flags) return Errno(-ret) @@ -269,8 +304,10 @@ mremap :: proc "contextless" (old_addr: rawptr, old_size: uint, new_size: uint, } } -/// Sync file with memory map -/// Available since Linux 2.0 +/* + Sync file with memory map. + Available since Linux 2.0. +*/ msync :: proc "contextless" (addr: rawptr, size: uint, flags: MSync_Flags) -> (Errno) { ret := syscall(SYS_msync, addr, size, transmute(i32) flags) return Errno(-ret) @@ -285,8 +322,10 @@ mincore :: proc "contextless" (addr: rawptr, size: uint, vec: []b8) -> (Errno) { return Errno(-ret) } -/// Give advice about use of memory -/// Available since Linux 2.4 +/* + Give advice about use of memory. + Available since Linux 2.4. +*/ madvise :: proc "contextless" (addr: rawptr, size: uint, advice: MAdvice) -> (Errno) { ret := syscall(SYS_madvise, addr, size, advice) return Errno(-ret) @@ -331,16 +370,20 @@ shmctl_stat :: proc "contextless" (index: int, cmd: IPC_Cmd, buf: ^Shmid_DS) -> */ shmctl :: proc {shmctl_ds, shmctl_info, shmctl_stat} -/// Allocate a new file descriptor that refers to the same file as the one provided -/// Available since Linux 1.0 +/* + Allocate a new file descriptor that refers to the same file as the one provided. + Available since Linux 1.0. +*/ dup :: proc "contextless" (fd: Fd) -> (Fd, Errno) { ret := syscall(SYS_dup, fd) return errno_unwrap(ret, Fd) } -/// Adjust an existing file descriptor to point to the same file as `old` -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.27 +/* + Adjust an existing file descriptor to point to the same file as `old`. + Available since Linux 1.0. + On ARM64 available since Linux 2.6.27. +*/ dup2 :: proc "contextless" (old: Fd, new: Fd) -> (Fd, Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_dup3, old, new, 0) @@ -394,9 +437,11 @@ getitimer :: proc "contextless" (which: ITimer_Which, new: ^ITimer_Val, old: ^IT return Errno(-ret) } -/// Returns the thread group ID of the current process -/// Note that it doesn't return the pid, despite it's name. -/// Available since Linux 1.0 +/* + Returns the thread group ID of the current process. + Note that it doesn't return the pid, despite it's name. + Available since Linux 1.0. +*/ getpid :: proc "contextless" () -> Pid { return cast(Pid) syscall(SYS_getpid) } @@ -416,16 +461,20 @@ sendfile :: proc "contextless" (out: Fd, in: Fd, offset: ^i64, count: uint) -> ( } } -/// Create a socket file descriptor -/// Available since Linux 2.0 +/* + Create a socket file descriptor. + Available since Linux 2.0. +*/ socket :: proc "contextless" (domain: Address_Family, socktype: Socket_Type, sockflags: Socket_FD_Flags, protocol: Protocol) -> (Fd, Errno) { sock_type_flags: int = cast(int) socktype | transmute(int) sockflags ret := syscall(SYS_socket, domain, sock_type_flags, protocol) return errno_unwrap(ret, Fd) } -/// Connect the socket to the address -/// Available since Linux 2.0 +/* + Connect the socket to the address. + Available since Linux 2.0. +*/ connect :: proc "contextless" (sock: Fd, addr: ^$T) -> (Errno) where T == Sock_Addr_In || @@ -436,9 +485,11 @@ where return Errno(-ret) } -/// Accept a pending connection or block until new connection appears -/// Depends on Sock_FD_Flags of the `sock` parameter. -/// Available since Linux 2.0 +/* + Accept a pending connection or block until new connection appears. + Depends on Sock_FD_Flags of the `sock` parameter. + Available since Linux 2.0. +*/ accept :: proc "contextless" (sock: Fd, addr: ^$T, sockflags: Socket_FD_Flags = {}) -> (Fd, Errno) where T == Sock_Addr_In || @@ -483,12 +534,16 @@ send_noaddr :: proc "contextless" (sock: Fd, buf: []u8, flags: Socket_Msg) -> (i return errno_unwrap(ret, int) } -/// Receive a message from a socket -/// Available since Linux 2.0 +/* + Receive a message from a socket. + Available since Linux 2.0. +*/ recv :: proc {recvfrom, recv_noaddr} -/// Send a message through a socket -/// Available since Linux 2.0 +/* + Send a message through a socket. + Available since Linux 2.0. +*/ send :: proc {sendto, send_noaddr} /* @@ -518,8 +573,10 @@ shutdown :: proc "contextless" (sock: Fd, how: Shutdown_How) -> (Errno) { return Errno(-ret) } -/// Bind a socket to the given local address -/// Available since Linux 2.0 +/* + Bind a socket to the given local address. + Available since Linux 2.0. +*/ bind :: proc "contextless" (sock: Fd, addr: ^$T) -> (Errno) where T == Sock_Addr_In || @@ -530,8 +587,10 @@ where return Errno(-ret) } -/// Marks the socket as a socket that listen to connections using accept.2 -/// Available since Linux 2.0 +/* + Marks the socket as a socket that listen to connections using accept(2). + Available since Linux 2.0. +*/ listen :: proc "contextless" (sock: Fd, queue_len: i32) -> (Errno) { ret := syscall(SYS_listen, sock, queue_len) return Errno(-ret) @@ -604,8 +663,10 @@ where return setsockopt_base(sock, cast(int) level, cast(int) opt, val) } -/// Set socket option for a given socket API level -/// Available since Linux 2.0 +/* + Set socket option for a given socket API level. + Available since Linux 2.0. +*/ setsockopt :: proc { setsockopt_sock, setsockopt_tcp, @@ -648,8 +709,10 @@ where return getsockopt_base(sock, cast(int) level, cast(int) opt, val) } -/// Get socket option for a given socket API level -/// Available since Linux 2.0 +/* + Get socket option for a given socket API level. + Available since Linux 2.0. +*/ getsockopt :: proc { getsockopt_sock, getsockopt_tcp, @@ -659,8 +722,10 @@ getsockopt :: proc { // TODO(flysand): clone (probably not in this PR, maybe not ever) -/// Creates a copy of the running process -/// Available since Linux 1.0 +/* + Creates a copy of the running process. + Available since Linux 1.0. +*/ fork :: proc "contextless" () -> (Pid, Errno) { when ODIN_ARCH == .arm64 { // Note(flysand): this syscall is not documented, but the bottom 8 bits of flags @@ -700,21 +765,27 @@ execve :: proc "contextless" (name: cstring, argv: [^]cstring, envp: [^]cstring) } } -/// Exit the thread with a given exit code -/// Available since Linux 1.0 +/* + Exit the thread with a given exit code. + Available since Linux 1.0. +*/ exit :: proc "contextless" (code: i32) -> ! { syscall(SYS_exit, code) unreachable() } -/// Wait for the process to change state -/// Available since Linux 1.0 +/* + Wait for the process to change state. + Available since Linux 1.0. +*/ wait4 :: proc "contextless" (pid: Pid, status: ^u32, options: Wait_Options) -> (Pid, Errno) { ret := syscall(SYS_wait4, pid, status, transmute(u32) options) return errno_unwrap(ret, Pid) } -/// See wait4 +/* + See `wait4` for documentation. +*/ waitpid :: wait4 /* @@ -726,8 +797,10 @@ kill :: proc "contextless" (pid: Pid, signal: Signal) -> (Errno) { return Errno(-ret) } -/// Get system information -/// Available since Linux 1.0 +/* + Get system information. + Available since Linux 1.0. +*/ uname :: proc "contextless" (uts_name: ^UTS_Name) -> (Errno) { ret := syscall(SYS_uname, uts_name) return Errno(-ret) @@ -983,7 +1056,10 @@ flock :: proc "contextless" (fd: Fd, operation: FLock_Op) -> (Errno) { return Errno(-ret) } -/// Sync state of the file with the storage device +/* + Sync state of the file with the storage device. + Available since Linux 1.0. +*/ fsync :: proc "contextless" (fd: Fd) -> (Errno) { ret := syscall(SYS_fsync, fd) return Errno(-ret) @@ -999,8 +1075,11 @@ fdatasync :: proc "contextless" (fd: Fd) -> (Errno) { return Errno(-ret) } -/// Truncate a file to specified length -/// On 32-bit architectures available since Linux 2.4 +/* + Truncate a file to specified length. + Available since Linux 1.0. + On 32-bit architectures available since Linux 2.4. +*/ truncate :: proc "contextless" (name: cstring, length: i64) -> (Errno) { when size_of(int) == 4 { ret := syscall(SYS_truncate64, cast(rawptr) name, compat64_arg_pair(length)) @@ -1011,8 +1090,10 @@ truncate :: proc "contextless" (name: cstring, length: i64) -> (Errno) { } } -/// Truncate a file specified by file descriptor to specified length -/// On 32-bit architectures available since 2.4 +/* + Truncate a file specified by file descriptor to specified length. + On 32-bit architectures available since 2.4. +*/ ftruncate :: proc "contextless" (fd: Fd, length: i64) -> (Errno) { when size_of(int) == 4 { ret := syscall(SYS_ftruncate64, fd, compat64_arg_pair(length)) @@ -1023,38 +1104,48 @@ ftruncate :: proc "contextless" (fd: Fd, length: i64) -> (Errno) { } } -/// Retrieve the contents of the directory specified by dirfd -/// Returns the number of bytes written -/// Available since Linux 2.4 +/* + Retrieve the contents of the directory specified by dirfd. + Returns the number of bytes written. + Available since Linux 2.4. +*/ getdents :: proc "contextless" (dirfd: Fd, buf: []u8) -> (int, Errno) { ret := syscall(SYS_getdents64, dirfd, raw_data(buf), len(buf)) return errno_unwrap(ret, int) } -/// Get current working directory -/// Available since Linux 1.0 +/* + Get current working directory. + Available since Linux 1.0. +*/ getcwd :: proc "contextless" (buf: []u8) -> (int, Errno) { ret := syscall(SYS_getcwd, raw_data(buf), len(buf)) return errno_unwrap(ret, int) } -/// Change working directory to the directory specified by path -/// Available since Linux 1.0 +/* + Change working directory to the directory specified by path. + Available since Linux 1.0. +*/ chdir :: proc "contextless" (path: cstring) -> (Errno) { ret := syscall(SYS_chdir, cast(rawptr) path) return Errno(-ret) } -/// Change working directory to the directory specified by dirfd -/// Available since Linux 1.0 +/* + Change working directory to the directory specified by dirfd. + Available since Linux 1.0. +*/ fchdir :: proc "contextless" (fd: Fd) -> (Errno) { ret := syscall(SYS_fchdir, fd) return Errno(-ret) } -/// Rename (move) the file -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Rename (move) the file. + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ rename :: proc "contextless" (old: cstring, new: cstring) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_renameat, AT_FDCWD, cast(rawptr) old, AT_FDCWD, cast(rawptr) new) @@ -1065,9 +1156,11 @@ rename :: proc "contextless" (old: cstring, new: cstring) -> (Errno) { } } -/// Creates a directory -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Creates a directory. + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ mkdir :: proc "contextless" (name: cstring, mode: Mode) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_mkdirat, AT_FDCWD, cast(rawptr) name, transmute(u32) mode) @@ -1078,9 +1171,11 @@ mkdir :: proc "contextless" (name: cstring, mode: Mode) -> (Errno) { } } -/// Remove a directory specified by name -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Remove a directory specified by name. + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ rmdir :: proc "contextless" (name: cstring) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_unlinkat, AT_FDCWD, cast(rawptr) name, transmute(i32) FD_Flags{.REMOVEDIR}) @@ -1105,9 +1200,11 @@ creat :: proc "contextless" (name: cstring, mode: Mode) -> (Errno) { } } -/// Create a hard link on a file -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Create a hard link on a file. + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ link :: proc "contextless" (target: cstring, linkpath: cstring) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_linkat, AT_FDCWD, cast(rawptr) target, AT_FDCWD, cast(rawptr) linkpath) @@ -1118,9 +1215,11 @@ link :: proc "contextless" (target: cstring, linkpath: cstring) -> (Errno) { } } -/// Delete a name, and possible a file it refers to -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Delete a name, and possible a file it refers to. + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ unlink :: proc "contextless" (name: cstring) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_unlinkat, AT_FDCWD, cast(rawptr) name, 0) @@ -1131,9 +1230,11 @@ unlink :: proc "contextless" (name: cstring) -> (Errno) { } } -/// Create a symbolic link -/// Available since Linux 1.0 -/// On arm64 available since Linux 2.6.16 +/* + Create a symbolic link. + Available since Linux 1.0. + On arm64 available since Linux 2.6.16. +*/ symlink :: proc "contextless" (target: cstring, linkpath: cstring) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_symlinkat, AT_FDCWD, cast(rawptr) target, cast(rawptr) linkpath) @@ -1144,9 +1245,11 @@ symlink :: proc "contextless" (target: cstring, linkpath: cstring) -> (Errno) { } } -/// Read the value of a symbolic link -/// Available since Linux 1.0 -/// On arm64 available since Linux 2.6.16 +/* + Read the value of a symbolic link. + Available since Linux 1.0. + On arm64 available since Linux 2.6.16. +*/ readlink :: proc "contextless" (name: cstring, buf: []u8) -> (int, Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_readlinkat, AT_FDCWD, cast(rawptr) name, raw_data(buf), len(buf)) @@ -1157,9 +1260,11 @@ readlink :: proc "contextless" (name: cstring, buf: []u8) -> (int, Errno) { } } -/// Change file permissions -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Change file permissions. + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ chmod :: proc "contextless" (name: cstring, mode: Mode) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_fchmodat, cast(rawptr) name, transmute(u32) mode, 0) @@ -1170,17 +1275,21 @@ chmod :: proc "contextless" (name: cstring, mode: Mode) -> (Errno) { } } -/// Change file permissions through a file descriptor -/// Available since Linux 1.0 +/* + Change file permissions through a file descriptor. + Available since Linux 1.0. +*/ fchmod :: proc "contextless" (fd: Fd, mode: Mode) -> (Errno) { ret := syscall(SYS_fchmod, fd, transmute(u32) mode) return Errno(-ret) } -/// Change ownership of a file -/// Available since Linux 2.2 -/// On 32-bit architectures available since Linux 2.4 -/// On ARM64 available since Linux 2.6.16 +/* + Change ownership of a file. + Available since Linux 2.2. + On 32-bit architectures available since Linux 2.4. + On ARM64 available since Linux 2.6.16. +*/ chown :: proc "contextless" (name: cstring, uid: Uid, gid: Gid) -> (Errno) { when size_of(int) == 4 { ret := syscall(SYS_chown32, cast(rawptr) name, uid, gid) @@ -1194,9 +1303,11 @@ chown :: proc "contextless" (name: cstring, uid: Uid, gid: Gid) -> (Errno) { } } -/// Change ownership of a file by file descriptor -/// Available since Linux 1.0 -/// On 32-bit architecvtures available since Linux 2.4 +/* + Change ownership of a file by file descriptor. + Available since Linux 1.0. + On 32-bit architecvtures available since Linux 2.4. +*/ fchown :: proc "contextless" (fd: Fd, uid: Uid, gid: Gid) -> (Errno) { when size_of(int) == 4 { ret := syscall(SYS_fchown32, fd, uid, gid) @@ -1207,10 +1318,12 @@ fchown :: proc "contextless" (fd: Fd, uid: Uid, gid: Gid) -> (Errno) { } } -/// Change ownership of a file. Unlike chown, if a file is a symlink dooesn't dereference it -/// Available since Linux 1.0 -/// On 32-bit architectures available since Linux 2.4 -/// On ARM64 available since Linux 2.6.16 +/* + Change ownership of a file. Unlike chown, if a file is a symlink dooesn't dereference it. + Available since Linux 1.0. + On 32-bit architectures available since Linux 2.4. + On ARM64 available since Linux 2.6.16. +*/ lchown :: proc "contextless" (name: cstring, uid: Uid, gid: Gid) -> (Errno) { when size_of(int) == 4 { ret := syscall(SYS_lchown32, cast(rawptr) name, uid, gid) @@ -1242,28 +1355,37 @@ gettimeofday :: proc "contextless" (tv: ^Time_Val) -> (Errno) { return Errno(-ret) } -/// Get limits on resources -/// Available since Linux 1.0 +/* + Get limits on resources. + Available since Linux 1.0. +*/ getrlimit :: proc "contextless" (kind: RLimit_Kind, resource: ^RLimit) -> (Errno) { ret := syscall(SYS_getrlimit, kind, resource) return Errno(-ret) } -/// Get resource usage -/// Available since Linux 1.0 +/* + Get resource usage. + Available since Linux 1.0. +*/ getrusage :: proc "contextless" (who: RUsage_Who, rusage: ^RUsage) -> (Errno) { ret := syscall(SYS_getrusage, who, rusage) return Errno(-ret) } -/// Get information about the system +/* + Get information about the system. + Available since Linux 1.0. +*/ sysinfo :: proc "contextless" (sysinfo: ^Sys_Info) -> (Errno) { ret := syscall(SYS_sysinfo, sysinfo) return Errno(-ret) } -/// Get current process times -/// Available since Linux 1.0 +/* + Get current process times. + Available since Linux 1.0. +*/ times :: proc "contextless" (tms: ^Tms) -> (Errno) { ret := syscall(SYS_times, cast(rawptr) tms) return Errno(-ret) @@ -1443,9 +1565,11 @@ ptrace :: proc { ptrace_detach, } -/// Get real user ID -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Get real user ID. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ getuid :: proc "contextless" () -> Uid { when size_of(int) == 8 { return cast(Uid) syscall(SYS_getuid) @@ -1463,10 +1587,11 @@ syslog :: proc "contextless" (act: Syslog_Action, buf: []u8) -> (int, Errno) { return errno_unwrap(ret, int) } - -/// Get real group ID -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Get real group ID. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ getgid :: proc "contextless" () -> Gid { when size_of(int) == 8 { return cast(Gid) syscall(SYS_getgid) @@ -1475,9 +1600,11 @@ getgid :: proc "contextless" () -> Gid { } } -/// Set effective user id -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Set effective User ID. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ @(require_results) setuid :: proc "contextless" (uid: Uid) -> (Errno) { when size_of(int) == 8 { @@ -1489,10 +1616,12 @@ setuid :: proc "contextless" (uid: Uid) -> (Errno) { } } -/// Set effective group id -/// If the process is privileged also sets real group id -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Set effective group id. + If the process is privileged also sets real group id. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ @(require_results) setgid :: proc "contextless" (gid: Gid) -> (Errno) { when size_of(int) == 8 { @@ -1504,9 +1633,11 @@ setgid :: proc "contextless" (gid: Gid) -> (Errno) { } } -/// Get effective user ID -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Get effective user ID. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ geteuid :: proc "contextless" () -> Uid { when size_of(int) == 8 { return cast(Uid) syscall(SYS_geteuid) @@ -1515,9 +1646,11 @@ geteuid :: proc "contextless" () -> Uid { } } -/// Get effective group ID -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Get effective group ID. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ getegid :: proc "contextless" () -> Gid { when size_of(int) == 8 { return cast(Gid) syscall(SYS_getegid) @@ -1526,21 +1659,27 @@ getegid :: proc "contextless" () -> Gid { } } -/// Set process group -/// Available since Linux 1.0 +/* + Set process group. + Available since Linux 1.0. +*/ setpgid :: proc "contextless" (pid: Pid, pgid: Pid) -> (Errno) { ret := syscall(SYS_setpgid, pid, pgid) return Errno(-ret) } -/// Get the parent process ID -/// Available since Linux 1.0 +/* + Get the parent process ID. + Available since Linux 1.0. +*/ getppid :: proc "contextless" () -> Pid { return cast(Pid) syscall(SYS_getppid) } -/// Get process group -/// Available since Linux 1.0 +/* + Get process group. + Available since Linux 1.0. +*/ getpgrp :: proc "contextless" () -> (Pid, Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_getpgid, 0) @@ -1551,17 +1690,21 @@ getpgrp :: proc "contextless" () -> (Pid, Errno) { } } -/// Create a session and set the process group ID -/// Available since Linux 2.0 +/* + Create a session and set the process group ID. + Available since Linux 2.0. +*/ setsid :: proc "contextless" () -> (Errno) { ret := syscall(SYS_setsid) return Errno(-ret) } -/// Set real and/or effective user id -/// If any of the arguments is -1, the corresponding id is not changed -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Set real and/or effective user id. + If any of the arguments is -1, the corresponding id is not changed. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ @(require_results) setreuid :: proc "contextless" (real: Uid, effective: Uid) -> (Errno) { when size_of(int) == 8 { @@ -1573,10 +1716,12 @@ setreuid :: proc "contextless" (real: Uid, effective: Uid) -> (Errno) { } } -/// Set real and/or effective group id -/// If any of the arguments is -1, the corresponding id is not changed -/// Available since Linux 1.0 -/// On 32-bit platforms available since Linux 2.4 +/* + Set real and/or effective group id. + If any of the arguments is -1, the corresponding id is not changed. + Available since Linux 1.0. + On 32-bit platforms available since Linux 2.4. +*/ @(require_results) setregid :: proc "contextless" (real: Gid, effective: Gid) -> (Errno) { when size_of(int) == 8 { @@ -1618,10 +1763,12 @@ setgroups :: proc "contextless" (gids: []Gid) -> (Errno) { } } -/// Set real, effective and/or saved user id -/// If any of the arguments is -1, the corresponding id is not changed -/// Available since Linux 2.2 -/// On 32-bit platforms available since Linux 2.4 +/* + Set real, effective and/or saved user id. + If any of the arguments is -1, the corresponding id is not changed. + Available since Linux 2.2. + On 32-bit platforms available since Linux 2.4. +*/ @(require_results) setresuid :: proc "contextless" (real: Uid, effective: Uid, saved: Uid) -> (Errno) { when size_of(int) == 8 { @@ -1633,9 +1780,11 @@ setresuid :: proc "contextless" (real: Uid, effective: Uid, saved: Uid) -> (Errn } } -/// Get real, effective and saved user id -/// Available since Linux 2.2 -/// On 32-bit platforms available since Linux 2.4 +/* + Get real, effective and saved user id. + Available since Linux 2.2. + On 32-bit platforms available since Linux 2.4. +*/ getresuid :: proc "contextless" (real: ^Uid, effective: ^Uid, saved: ^Uid) -> (Errno) { when size_of(int) == 8 { ret := syscall(SYS_getresuid, cast(rawptr) real, cast(rawptr) effective, cast(rawptr) saved) @@ -1646,10 +1795,12 @@ getresuid :: proc "contextless" (real: ^Uid, effective: ^Uid, saved: ^Uid) -> (E } } -/// Set real, effective and/or saved group id -/// If any of the arguments is -1, the corresponding id is not changed -/// Available since Linux 2.2 -/// On 32-bit platforms available since Linux 2.4 +/* + Set real, effective and/or saved group id. + If any of the arguments is -1, the corresponding id is not changed. + Available since Linux 2.2. + On 32-bit platforms available since Linux 2.4. +*/ @(require_results) setresgid :: proc "contextless" (real: Gid, effective: Gid, saved: Uid) -> (Errno) { when size_of(int) == 8 { @@ -1661,9 +1812,11 @@ setresgid :: proc "contextless" (real: Gid, effective: Gid, saved: Uid) -> (Errn } } -/// Get real, effective and saved group id -/// Available since Linux 2.2 -/// On 32-bit platforms available since Linux 2.4 +/* + Get real, effective and saved group id. + Available since Linux 2.2. + On 32-bit platforms available since Linux 2.4. +*/ getresgid :: proc "contextless" (real: ^Gid, effective: ^Gid, saved: ^Gid) -> (Errno) { when size_of(int) == 8 { ret := syscall(SYS_getresgid, cast(rawptr) real, cast(rawptr) effective, cast(rawptr) saved) @@ -1674,15 +1827,19 @@ getresgid :: proc "contextless" (real: ^Gid, effective: ^Gid, saved: ^Gid) -> (E } } -/// Get process group -/// Available since Linux 1.0 +/* + Get process group. + Available since Linux 1.0. +*/ getpgid :: proc "contextless" (pid: Pid) -> (Pid, Errno) { ret := syscall(SYS_getpgid, pid) return errno_unwrap(ret, Pid) } -/// Get session ID of the calling process -/// Available since Linux 2.0 +/* + Get session ID of the calling process. + Available since Linux 2.0. +*/ getsid :: proc "contextless" (pid: Pid) -> (Pid, Errno) { ret := syscall(SYS_getsid, pid) return errno_unwrap(ret, Pid) @@ -1692,46 +1849,60 @@ getsid :: proc "contextless" (pid: Pid) -> (Pid, Errno) { // TODO(flysand): capset -/// Examine pending signals -/// Available since Linux 2.2 +/* + Examine pending signals. + Available since Linux 2.2. +*/ rt_sigpending :: proc "contextless" (sigs: ^Sig_Set) -> Errno { ret := syscall(SYS_rt_sigpending, sigs, size_of(Sig_Set)) return Errno(-ret) } -/// Synchronously wait for queued signals -/// Available since Linux 2.2 +/* + Synchronously wait for queued signals. + Available since Linux 2.2. +*/ rt_sigtimedwait :: proc "contextless" (sigs: ^Sig_Set, info: ^Sig_Info, time_sus: ^Time_Spec) -> (Signal, Errno) { ret := syscall(SYS_rt_sigtimedwait, sigs, info, time_sus, size_of(Sig_Set)) return errno_unwrap(ret, Signal) } -/// Send signal information to a process -/// Available since Linux 2.2 +/* + Send signal information to a process. + Available since Linux 2.2. +*/ rt_sigqueueinfo :: proc "contextless" (pid: Pid, sig: Signal, si: ^Sig_Info) -> (Errno) { ret := syscall(SYS_rt_sigqueueinfo, pid, sig, si) return Errno(-ret) } -/// Replace the signal mask for a value with the new mask until a signal is received -/// Available since Linux 2.2 +/* + Replace the signal mask for a value with the new mask until a signal is received. + Available since Linux 2.2. +*/ rt_sigsuspend :: proc "contextless" (sigset: ^Sig_Set) -> Errno { ret := syscall(SYS_rt_sigsuspend, sigset, size_of(Sig_Set)) return Errno(-ret) } -/// Set or get signal stack context -/// Available since Linux 2.2 +/* + Set or get signal stack context. + Available since Linux 2.2. +*/ sigaltstack :: proc "contextless" (stack: ^Sig_Stack, old_stack: ^Sig_Stack) -> (Errno) { ret := syscall(SYS_sigaltstack, stack, old_stack) return Errno(-ret) } -/// Create a special or ordinary file -/// `mode` parameter contains both the the file mode and the type of the node to create -/// -> Add one of S_IFSOCK, S_IFBLK, S_IFFIFO, S_IFCHR to mode -/// Available since Linux 1.0 -/// On ARM64 available since Linux 2.6.16 +/* + Create a special or ordinary file. + + `mode` parameter contains both the the file mode and the type of the node to create. + -> Add one of S_IFSOCK, S_IFBLK, S_IFFIFO, S_IFCHR to mode. + + Available since Linux 1.0. + On ARM64 available since Linux 2.6.16. +*/ mknod :: proc "contextless" (name: cstring, mode: Mode, dev: Dev) -> (Errno) { when ODIN_ARCH == .arm64 { ret := syscall(SYS_mknodat, AT_FDCWD, cast(rawptr) name, transmute(u32) mode, dev) @@ -1742,8 +1913,10 @@ mknod :: proc "contextless" (name: cstring, mode: Mode, dev: Dev) -> (Errno) { } } -/// Set the process execution domain -/// Available since Linux 1.2 +/* + Set the process execution domain. + Available since Linux 1.2. +*/ personality :: proc "contextless" (personality: uint) -> (uint, Errno) { ret := syscall(SYS_personality, personality) return errno_unwrap(ret, uint) @@ -1751,10 +1924,12 @@ personality :: proc "contextless" (personality: uint) -> (uint, Errno) { // TODO(flysand): ustat -/// Query information about filesystem -/// -/// Available since Linux 1.0 -/// For 32-bit systems a different syscall is used that became available since 2.6 +/* + Query information about filesystem. + + Available since Linux 1.0. + For 32-bit systems a different syscall is used that became available since 2.6. +*/ statfs :: proc "contextless" (path: cstring, statfs: ^Stat_FS) -> (Errno) { when size_of(int) == 8 { ret := syscall(SYS_statfs, transmute(uintptr) path, statfs) @@ -1765,10 +1940,12 @@ statfs :: proc "contextless" (path: cstring, statfs: ^Stat_FS) -> (Errno) { } } -/// Query information about filesystem by file descriptor -/// -/// Available since Linux 1.0 -/// For 32-bit systems a different syscall is used that became available since 2.6 +/* + Query information about filesystem by file descriptor. + + Available since Linux 1.0. + For 32-bit systems a different syscall is used that became available since 2.6. +*/ fstatfs :: proc "contextless" (fd: Fd, statfs: ^Stat_FS) -> (Errno) { when size_of(int) == 8 { ret := syscall(SYS_statfs, fd, statfs) @@ -1781,8 +1958,10 @@ fstatfs :: proc "contextless" (fd: Fd, statfs: ^Stat_FS) -> (Errno) { // TODO(flysand): sysfs -/// Get priority on user, process group or process -/// Available since Linux 1.0 +/* + Get priority on user, process group or process. + Available since Linux 1.0. +*/ getpriority :: proc "contextless" (which: Priority_Which, who: i32) -> (i32, Errno) { ret := syscall(SYS_getpriority, which, who) prio, err := errno_unwrap(ret, i32) @@ -1792,8 +1971,10 @@ getpriority :: proc "contextless" (which: Priority_Which, who: i32) -> (i32, Err return prio, err } -/// Set priority on user, process group or process -/// Available since Linux 1.0 +/* + Set priority on user, process group or process. + Available since Linux 1.0. +*/ setpriority :: proc "contextless" (which: Priority_Which, who: i32, prio: i32) -> (Errno) { ret := syscall(SYS_setpriority, which, who, prio) return Errno(-ret) @@ -1813,9 +1994,11 @@ setpriority :: proc "contextless" (which: Priority_Which, who: i32, prio: i32) - // TODO(flysand): sched_rr_get_interval -/// Lock and memory -/// Available since Linux 2.0 -/// If flags specified, available since Linux 4.4 +/* + Lock and memory. + Available since Linux 2.0. + If flags specified, available since Linux 4.4. +*/ mlock :: proc "contextless" (addr: rawptr, size: uint, flags: MLock_Flags = {}) -> (Errno) { // Pretty darn recent syscall, better call simpler version if we can if flags > {} { @@ -1827,20 +2010,28 @@ mlock :: proc "contextless" (addr: rawptr, size: uint, flags: MLock_Flags = {}) } } -/// Unlock memory -/// Available since Linux 2.0 +/* + Unlock memory. + Available since Linux 2.0. +*/ munlock :: proc "contextless" (addr: rawptr, size: uint) -> (Errno) { ret := syscall(SYS_munlock, addr, size) return Errno(-ret) } -/// Lock all memory +/* + Lock all memory. + Available since Linux 2.0. +*/ mlockall :: proc "contextless" (flags: MLock_Flags = {}) -> (Errno) { ret := syscall(SYS_mlockall, transmute(i32) flags) return Errno(-ret) } -/// Unlock all memory +/* + Unlock all memory. + Available since Linux 2.0. +*/ munlockall :: proc "contextless" () -> (Errno) { ret := syscall(SYS_munlockall) return Errno(-ret) @@ -1860,8 +2051,10 @@ munlockall :: proc "contextless" () -> (Errno) { // TODO(flysand): adj_timex -/// Set limits on resources -/// Available since Linux 1.0 +/* + Set limits on resources. + Available since Linux 1.0. +*/ setrlimit :: proc "contextless" (kind: RLimit_Kind, resource: ^RLimit) -> (Errno) { ret := syscall(SYS_setrlimit, kind, resource) return Errno(-ret) @@ -1883,17 +2076,21 @@ setrlimit :: proc "contextless" (kind: RLimit_Kind, resource: ^RLimit) -> (Errno // TODO(flysand): reboot -/// Set hostname -/// Note: to get the host name, use `uname` syscall -/// Available since Linux 1.0 +/* + Set hostname. + Note: to get the host name, use `uname` syscall. + Available since Linux 1.0. +*/ sethostname :: proc "contextless" (hostname: string) -> (Errno) { ret := syscall(SYS_sethostname, raw_data(hostname), len(hostname)) return Errno(-ret) } -/// Set domain name -/// Note: to get the domain name, use `uname` syscall -/// Available since Linux 2.2 +/* + Set domain name. + Note: to get the domain name, use `uname` syscall. + Available since Linux 2.2. +*/ setdomainname :: proc "contextless" (name: string) -> (Errno) { ret := syscall(SYS_setdomainname, raw_data(name), len(name)) return Errno(-ret) @@ -1921,12 +2118,14 @@ setdomainname :: proc "contextless" (name: string) -> (Errno) { // TODO(flysand): security -/// Returns the thread ID of the current process -/// This is what the kernel calls "pid" -/// Let me insert a tiny rant here, this terminology is confusing: -/// sometimes pid refers to a thread, and other times it refers -/// to a thread group (process group?) -/// Anyway, this syscall is available since Linux 1.0 +/* + Returns the thread ID of the current process + This is what the kernel calls "pid". + Let me insert a tiny rant here, this terminology is confusing: + sometimes pid refers to a thread, and other times it refers + to a thread group (process group?) + Anyway, this syscall is available since Linux 1.0 +*/ gettid :: proc "contextless" () -> Pid { return cast(Pid) syscall(SYS_gettid) } @@ -1966,15 +2165,19 @@ time :: proc "contextless" (tloc: ^uint) -> (Errno) { return Errno(-ret) } -/// Wait on a futex until it's signaled +/* + Wait on a futex until it's signaled. +*/ futex_wait :: proc "contextless" (futex: ^Futex, op: Futex_Wait_Type, flags: Futex_Flags, val: u32, timeout: ^Time_Spec = nil) -> (Errno) { futex_flags := cast(u32) op + transmute(u32) flags ret := syscall(SYS_futex, futex, futex_flags, val, timeout) return Errno(-ret) } -/// Wake up other threads on a futex -/// n_wakeup specifies the number of processes to wakeup. Specify max(i32) to wake up all processes waiting +/* + Wake up other threads on a futex + n_wakeup specifies the number of processes to wakeup. Specify max(i32) to wake up all processes waiting +*/ futex_wake :: proc "contextless" (futex: ^Futex, op: Futex_Wake_Type, flags: Futex_Flags, n_wakeup: i32) -> (int, Errno) { futex_flags := cast(u32) op + transmute(u32) flags ret := syscall(SYS_futex, futex, futex_flags, n_wakeup) @@ -1983,12 +2186,14 @@ futex_wake :: proc "contextless" (futex: ^Futex, op: Futex_Wake_Type, flags: Fut // NOTE(flysand): futex_fd is racy, so not implemented -/// Requeues processes waiting on futex `futex` to wait on futex `requeue_futex` -/// `requeue_threshold` specifies the maximum amount of waiters to wake up, the rest of the waiters will be requeued -/// `requeue_max` specifies the maximum amount of waiters that are required at `requeue_futex` -/// The operation blocks until the `requeue_max` requirement is satisfied -/// If the value of the mutex is not equal to `val`, fails with EAGAIN before any further checks -/// Returns the total number of waiters that have been woken up plus the number of waiters requeued +/* + Requeues processes waiting on futex `futex` to wait on futex `requeue_futex` + `requeue_threshold` specifies the maximum amount of waiters to wake up, the rest of the waiters will be requeued + `requeue_max` specifies the maximum amount of waiters that are required at `requeue_futex` + The operation blocks until the `requeue_max` requirement is satisfied + If the value of the mutex is not equal to `val`, fails with EAGAIN before any further checks + Returns the total number of waiters that have been woken up plus the number of waiters requeued. +*/ futex_cmp_requeue :: proc "contextless" (futex: ^Futex, op: Futex_Cmp_Requeue_Type, flags: Futex_Flags, requeue_threshold: u32, requeue_max: i32, requeue_futex: ^Futex, val: i32) -> (int, Errno) { @@ -1997,8 +2202,10 @@ futex_cmp_requeue :: proc "contextless" (futex: ^Futex, op: Futex_Cmp_Requeue_Ty return errno_unwrap(ret, int) } -/// See `futex_cmp_requeue`, this function does the same thing but doesn't check the value of the futex -/// Returns the total number of waiters that have been woken up +/* + See `futex_cmp_requeue`, this function does the same thing but doesn't check the value of the futex. + Returns the total number of waiters that have been woken up. +*/ futex_requeue :: proc "contextless" (futex: ^Futex, op: Futex_Requeue_Type, flags: Futex_Flags, requeue_threshold: u32, requeue_max: i32, requeue_futex: ^Futex) -> (int, Errno) { @@ -2007,8 +2214,10 @@ futex_requeue :: proc "contextless" (futex: ^Futex, op: Futex_Requeue_Type, flag return errno_unwrap(ret, int) } -/// Okay, for this one, see the man pages, the description for it is pretty long and very specific. It's sole -/// purpose is to allow implementing conditional values sync primitive, it seems like +/* + Okay, for this one, see the man pages, the description for it is pretty long and very specific. It's sole. + purpose is to allow implementing conditional values sync primitive, it seems like. +*/ futex_wake_op :: proc "contextless" (futex: ^Futex, op: Futex_Wake_Op_Type, flags: Futex_Flags, wakeup: i32, dst_wakeup, dst: ^Futex, futex_op: u32) -> (int, Errno) { @@ -2017,7 +2226,9 @@ futex_wake_op :: proc "contextless" (futex: ^Futex, op: Futex_Wake_Op_Type, flag return errno_unwrap(ret, int) } -/// Same as wait, but mask specifies bits that must be equal for the mutex to wake up +/* + Same as wait, but mask specifies bits that must be equal for the mutex to wake up. +*/ futex_wait_bitset :: proc "contextless" (futex: ^Futex, op: Futex_Wait_Bitset_Type, flags: Futex_Flags, val: u32, timeout: ^Time_Spec, mask: u32) -> (int, Errno) { @@ -2026,7 +2237,9 @@ futex_wait_bitset :: proc "contextless" (futex: ^Futex, op: Futex_Wait_Bitset_Ty return errno_unwrap(ret, int) } -/// Wake up on bitset +/* + Wake up on bitset. +*/ futex_wake_bitset :: proc "contextless" (futex: ^Futex, op: Futex_Wake_Bitset_Type, flags: Futex_Flags, n_wakeup: u32, mask: u32) -> (int, Errno) { futex_flags := cast(u32) op + transmute(u32) flags @@ -2074,9 +2287,11 @@ futex :: proc { // TODO(flysand): remap_file_pages -/// Set the address of the futex that's gonna be waken when -/// current thread terminates -/// Available since Linux 2.6 +/* + Set the address of the futex that's gonna be waken when. + current thread terminates. + Available since Linux 2.6. +*/ set_tid_address :: proc "contextless" (tidptr: ^u32) { syscall(SYS_set_tid_address, tidptr) } @@ -2138,8 +2353,10 @@ timer_delete :: proc "contextless" (timer: Timer) -> (Errno) { // TODO(flysand): clock_nanosleep -/// Exit the thread group -/// Available since Linux 2.6 +/* + Exit the thread group. + Available since Linux 2.6. +*/ exit_group :: proc "contextless" (code: i32) -> ! { syscall(SYS_exit_group, code) unreachable() @@ -2182,9 +2399,10 @@ tgkill :: proc "contextless" (tgid, tid: Pid, sig: Signal) -> (Errno) { // TODO(flysand): kexec_load - -/// Wait on process, process group or pid file descriptor -/// Available since Linux 2.6.10 +/* + Wait on process, process group or pid file descriptor. + Available since Linux 2.6.10. +*/ waitid :: proc "contextless" (id_type: Id_Type, id: Id, sig_info: ^Sig_Info, options: Wait_Options) -> (Errno) { ret := syscall(SYS_waitid, id_type, id, sig_info, transmute(i32) options) return Errno(-ret) @@ -2208,36 +2426,46 @@ waitid :: proc "contextless" (id_type: Id_Type, id: Id, sig_info: ^Sig_Info, opt // TODO(flysand): migrate_pages -/// Open file at the specified file descriptor -/// Available since Linux 2.6.16 +/* + Open file at the specified file descriptor. + Available since Linux 2.6.16. +*/ openat :: proc "contextless" (fd: Fd, name: cstring, flags: Open_Flags, mode: Mode = {}) -> (Fd, Errno) { ret := syscall(SYS_openat, fd, AT_FDCWD, transmute(uintptr) name, transmute(u32) mode) return errno_unwrap(ret, Fd) } -/// Create a directory relative to specified dirfd -/// Available since Linux 2.6.16 +/* + Create a directory relative to specified dirfd. + Available since Linux 2.6.16. +*/ mkdirat :: proc "contextless" (dirfd: Fd, name: cstring, mode: Mode) -> (Errno) { ret := syscall(SYS_mkdirat, dirfd, cast(rawptr) name, transmute(u32) mode) return Errno(-ret) } -/// Create a special or ordinary file wrt given directory specified by dirfd -/// Available since Linux 2.6.16 +/* + Create a special or ordinary file wrt given directory specified by dirfd. + Available since Linux 2.6.16. +*/ mknodat :: proc "contextless" (dirfd: Fd, name: cstring, mode: Mode, dev: Dev) -> (Errno) { ret := syscall(SYS_mknodat, dirfd, cast(rawptr) name, transmute(u32) mode, dev) return Errno(-ret) } -/// Change the ownership of the file specified relative to directory -/// Available since Linux 2.6.16 +/* + Change the ownership of the file specified relative to directory. + Available since Linux 2.6.16. +*/ fchownat :: proc "contextless" (dirfd: Fd, name: cstring, uid: Uid, gid: Gid) -> (Errno) { ret := syscall(SYS_fchownat, dirfd, cast(rawptr) name, uid, gid) return Errno(-ret) } -/// Get information about a file at a specific directory -/// Available since Linux 2.6.16 +/* + Get information about a file at a specific directory. + Available since Linux 2.6.16. +*/ fstatat :: proc "contextless" (dirfd: Fd, name: cstring, stat: ^Stat, flags: FD_Flags) -> (Errno) { when size_of(int) == 4 { ret := syscall(SYS_fstatat64, dirfd, cast(rawptr) name, stat, transmute(i32) flags) @@ -2251,50 +2479,64 @@ fstatat :: proc "contextless" (dirfd: Fd, name: cstring, stat: ^Stat, flags: FD_ } } -/// Remove a directory entry relative to a directory file descriptor -/// Available since Linux 2.6.16 +/* + Remove a directory entry relative to a directory file descriptor. + Available since Linux 2.6.16. +*/ unlinkat :: proc "contextless" (dirfd: Fd, name: cstring, flags: FD_Flags) -> (Errno) { ret := syscall(SYS_unlinkat, dirfd, cast(rawptr) name, transmute(i32) flags) return Errno(-ret) } -/// Rename the file with names relative to the specified dirfd's -/// Available since Linux 2.6.16 +/* + Rename the file with names relative to the specified dirfd's. + Available since Linux 2.6.16. +*/ renameat :: proc "contextless" (oldfd: Fd, old: cstring, newfd: Fd, new: cstring) -> (Errno) { ret := syscall(SYS_renameat, oldfd, cast(rawptr) old, newfd, cast(rawptr) new) return Errno(-ret) } -/// Creates a hard link on a file relative to specified dirfd -/// Available since Linux 2.6.16 +/* + Creates a hard link on a file relative to specified dirfd. + Available since Linux 2.6.16. +*/ linkat :: proc "contextless" (target_dirfd: Fd, oldpath: cstring, link_dirfd: Fd, link: cstring, flags: FD_Flags) -> (Errno) { ret := syscall(SYS_linkat, target_dirfd, cast(rawptr) oldpath, link_dirfd, cast(rawptr) link, transmute(i32) flags) return Errno(-ret) } -/// Create a symbolic link at specified dirfd -/// Available since Linux 2.6.16 +/* + Create a symbolic link at specified dirfd. + Available since Linux 2.6.16. +*/ symlinkat :: proc "contextless" (dirfd: Fd, target: cstring, linkpath: cstring) -> (Errno) { ret := syscall(SYS_symlinkat, dirfd, cast(rawptr) target, cast(rawptr) linkpath) return Errno(-ret) } -/// Read the value of a symbolic link at given dirfd -/// Available since Linux 2.6.16 +/* + Read the value of a symbolic link at given dirfd. + Available since Linux 2.6.16. +*/ readlinkat :: proc "contextless" (dirfd: Fd, name: cstring, buf: []u8) -> (int, Errno) { ret := syscall(SYS_readlinkat, dirfd, cast(rawptr) name, raw_data(buf), len(buf)) return errno_unwrap(ret, int) } -/// Change the file mode at a specified file descriptor -/// Available since Linux 2.6.16 +/* + Change the file mode at a specified file descriptor. + Available since Linux 2.6.16. +*/ fchmodat :: proc "contextless" (dirfd: Fd, name: cstring, mode: Mode, flags: FD_Flags) -> (Errno) { ret := syscall(SYS_fchmodat, cast(rawptr) name, transmute(u32) mode, transmute(i32) flags) return Errno(-ret) } -/// Checks the user permissions for a file at specified dirfd -/// Available since Linux 2.6.16 +/* + Checks the user permissions for a file at specified dirfd. + Available since Linux 2.6.16. +*/ faccessat :: proc "contextless" (dirfd: Fd, name: cstring, mode: Mode = F_OK) -> (bool, Errno) { ret := syscall(SYS_faccessat, dirfd, cast(rawptr) name, transmute(u32) mode) return errno_unwrap(ret, bool) @@ -2302,8 +2544,10 @@ faccessat :: proc "contextless" (dirfd: Fd, name: cstring, mode: Mode = F_OK) -> // TODO(flysand): pselect6 -/// Wait for events on a file descriptor -/// Available since Linux 2.6.16 +/* + Wait for events on a file descriptor. + Available since Linux 2.6.16. +*/ ppoll :: proc "contextless" (fds: []Poll_Fd, timeout: ^Time_Spec, sigmask: ^Sig_Set) -> (Errno) { when size_of(int) == 8 { ret := syscall(SYS_ppoll, raw_data(fds), len(fds), timeout, sigmask, size_of(Sig_Set)) @@ -2344,8 +2588,10 @@ tee :: proc "contextless" (fd_in: Fd, fd_out: Fd, len: uint, flags: Splice_Flags // TODO(flysand): move_pages -/// Change file timestamps with nanosecond precision -/// Available since Linux 2.6.22 +/* + Change file timestamps with nanosecond precision. + Available since Linux 2.6.22. +*/ utimensat :: proc "contextless" (dirfd: Fd, name: cstring, timespec: ^Time_Spec, flags: FD_Flags) -> (Errno) { ret := syscall(SYS_utimensat, dirfd, cast(rawptr) name, timespec, transmute(i32) flags) return Errno(-ret) @@ -2373,9 +2619,11 @@ utimensat :: proc "contextless" (dirfd: Fd, name: cstring, timespec: ^Time_Spec, // TODO(flysand): epoll_create1 -/// Adjust an existing file descriptor to point to the same file as `old` -/// In addition to dup2 allows to pass O_CLOEXEC flag -/// Available since Linux 2.6.27 +/* + Adjust an existing file descriptor to point to the same file as `old`. + In addition to dup2 allows to pass O_CLOEXEC flag. + Available since Linux 2.6.27. +*/ dup3 :: proc "contextless" (old: Fd, new: Fd, flags: Open_Flags) -> (Fd, Errno) { ret := syscall(SYS_dup3, old, new, transmute(i32) flags) return errno_unwrap(ret, Fd) @@ -2394,8 +2642,10 @@ rt_tgsigqueueinfo :: proc "contextless" (tgid: Pid, pid: Pid, sig: Signal, si: ^ return Errno(-ret) } -/// Set up performance monitoring -/// Available since Linux 2.6.31 +/* + Set up performance monitoring. + Available since Linux 2.6.31. +*/ perf_event_open :: proc "contextless" (attr: ^Perf_Event_Attr, pid: Pid, cpu: int, group_fd: Fd, flags: Perf_Flags = {}) -> (Fd, Errno) { ret := syscall(SYS_perf_event_open, attr, pid, cpu, group_fd, transmute(uint) flags) return errno_unwrap(ret, Fd) @@ -2449,8 +2699,10 @@ sendmmsg :: proc "contextless" (sock: Fd, msg_vec: []MMsg_Hdr, flags: Socket_Msg // TODO(flysand): sched_getattr -/// Rename the file with names relative to the specified dirfd's with other options -/// Available since Linux 3.15 +/* + Rename the file with names relative to the specified dirfd's with other options. + Available since Linux 3.15. +*/ renameat2 :: proc "contextless" (oldfd: Fd, old: cstring, newfd: Fd, new: cstring, flags: Rename_Flags) -> (Errno) { ret := syscall(SYS_renameat2, oldfd, cast(rawptr) old, newfd, cast(rawptr) new, transmute(u32) flags) return Errno(-ret) @@ -2496,14 +2748,16 @@ execveat :: proc "contextless" (dirfd: Fd, name: cstring, argv: [^]cstring, envp // TODO(flysand): pkey_free -/// Query extended information about the file -/// -/// The file can be specified as: -/// absolute pathname: `dir` parameter is ignored -/// relatvie pathname: `dir` parameter specifies the base directory's fd -/// file descriptor: `AT_EMPTY_PATH` is passed in flags, pathname is empty, `dir` specifies the file descriptor -/// -/// Available since Linux 4.11 +/* + Query extended information about the file + + The file can be specified as: + - absolute pathname: `dir` parameter is ignored + - relatvie pathname: `dir` parameter specifies the base directory's fd + - file descriptor: `AT_EMPTY_PATH` is passed in flags, pathname is empty, `dir` specifies the file descriptor + + Available since Linux 4.11 +*/ statx :: proc "contextless" (dir: Fd, pathname: cstring, flags: FD_Flags, mask: Statx_Mask, statx: ^Statx) -> (Errno) { ret := syscall(SYS_statx, dir, transmute(uintptr) pathname, transmute(i32) flags, transmute(u32) mask, statx) return Errno(-ret) @@ -2533,10 +2787,12 @@ statx :: proc "contextless" (dir: Fd, pathname: cstring, flags: FD_Flags, mask: // TODO(flysand): fspick -/// Creates a new PID file descriptor -/// The process identified by `pid` must be a pid group leader -/// The returned `pidfd` has `CLOEXEC` semantics -/// Available since Linux 5.3 +/* + Creates a new PID file descriptor. + The process identified by `pid` must be a pid group leader. + The returned `pidfd` has `CLOEXEC` semantics. + Available since Linux 5.3. +*/ pidfd_open :: proc "contextless" (pid: Pid, flags: Pid_FD_Flags) -> (Pid_FD, Errno) { ret := syscall(SYS_pidfd_open, pid, transmute(i32) flags) return errno_unwrap(ret, Pid_FD) @@ -2544,9 +2800,11 @@ pidfd_open :: proc "contextless" (pid: Pid, flags: Pid_FD_Flags) -> (Pid_FD, Err // TODO(flysand): clone3 (probably not this PR) -/// Close the range of files as an atomic operation -/// The range of file descriptors is inclusive, and may contain invalid file descriptors -/// Available since Linux 5.9 +/* + Close the range of files as an atomic operation. + The range of file descriptors is inclusive, and may contain invalid file descriptors. + Available since Linux 5.9. +*/ close_range :: proc "contextless" (lo: Fd, hi: Fd, flags: Close_Range_Flags) -> (Errno) { ret := syscall(SYS_close_range, lo, hi, transmute(u32) flags) return Errno(-ret) @@ -2554,17 +2812,21 @@ close_range :: proc "contextless" (lo: Fd, hi: Fd, flags: Close_Range_Flags) -> // TODO(flysand): openat2 -/// Get a file descriptor from another process -/// `fd` refers to a file descriptor number to get -/// `flags` must be zero -/// Available since Linux 5.3 +/* + Get a file descriptor from another process. + - `fd` refers to a file descriptor number to get. + - `flags` must be zero. + Available since Linux 5.3. +*/ pidfd_getfd :: proc "contextless" (pidfd: Pid_FD, fd: Fd, flags: i32 = 0) -> (Fd, Errno) { ret := syscall(SYS_pidfd_getfd, pidfd, fd, flags) return errno_unwrap(ret, Fd) } -/// Checks the user permissions for a file at specified dirfd (with flags) -/// Available since Linux 5.8 +/* + Checks the user permissions for a file at specified dirfd (with flags). + Available since Linux 5.8. +*/ faccessat2 :: proc "contextless" (dirfd: Fd, name: cstring, mode: Mode = F_OK, flags: FD_Flags = FD_Flags{}) -> (bool, Errno) { ret := syscall(SYS_faccessat2, dirfd, cast(rawptr) name, transmute(u32) mode, transmute(i32) flags) return errno_unwrap(ret, bool) diff --git a/core/sys/linux/types.odin b/core/sys/linux/types.odin index f763cf15f..fb2cfe8f6 100644 --- a/core/sys/linux/types.odin +++ b/core/sys/linux/types.odin @@ -1,46 +1,68 @@ //+build linux package linux -/// Represents storage device handle +/* + Type for storage device handle. +*/ Dev :: distinct int -/// Represents 32-bit user id +/* + Type for 32-bit User IDs. +*/ Uid :: distinct u32 -/// Represents 32-bit group id +/* + Type for 32-bit Group IDs. +*/ Gid :: distinct u32 -/// Process id's +/* + Type for Process IDs, Thread IDs, Thread group ID. +*/ Pid :: distinct int -/// Represents pid, pifd, pgid values in general +/* + Type for any of: pid, pidfd, pgid. +*/ Id :: distinct uint -/// Represents a file descriptor +/* + Represents a file descriptor. +*/ Fd :: distinct i32 -/// Represents a PID file descriptor +/* + Type for PID file descriptors. +*/ 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 -/// Shared memory identifiers used by `shm*` calls +/* + Shared memory identifiers used by shmget(2) and other calls. +*/ Key :: distinct i32 /* - Represents timer IDs + Represents timer IDs. */ Timer :: distinct i32 -/// Represents time with nanosecond precision +/* + Represents time with nanosecond precision. +*/ Time_Spec :: struct { time_sec: uint, time_nsec: uint, } -/// Represents time with millisecond precision +/* + Represents time with millisecond precision. +*/ Time_Val :: struct { seconds: int, microseconds: int, @@ -52,22 +74,31 @@ Time_Val :: struct { UTim_Buf :: struct { actime: uint, modtime: uint, -}; +} - -/// open.2 flags +/* + Flags for open(2). +*/ 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] -/// 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] when ODIN_ARCH == .amd64 { @@ -128,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 { using _impl_stat: _Arch_Stat, } -/// Timestamp type used for Statx struct +/* + Timestamp type used for Statx struct +*/ Statx_Timestamp :: struct { sec: i64, nsec: u32, _: i32, } -/// Query params/results for `statx()` +/* + Query params/results for `statx()`. +*/ 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] -/// The extended Stat struct +/* + The extended Stat struct, the argument to statx(2) syscall. +*/ Statx :: struct { mask: Statx_Mask, blksize: u32, @@ -182,7 +222,9 @@ Statx :: struct { _: [12]u64, } -/// Mount flags for filesystem +/* + Mount flags for filesystem. +*/ FS_Flags :: bit_set[FS_Flags_Bits; u32] when size_of(int) == 8 { @@ -222,19 +264,28 @@ when size_of(int) == 8 { } } +/* + Struct for statfs(2). +*/ Stat_FS :: struct { 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] -/// Flags for rename.2 +/* + Flags for rename(2). +*/ 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 { ino: Inode, off: i64, @@ -243,7 +294,9 @@ Dirent :: struct { name: [0]u8, // See dirent_name } -/// Lock record for fcntl.2 +/* + Lock record for fcntl(2). +*/ FLock :: struct { type: FLock_Type, whence: Seek_Whence, @@ -259,50 +312,76 @@ FLock :: struct { */ FLock_Op :: bit_set[FLock_Op_Bits; i32] -/// Flags for fcntl_notify +/* + Flags for `fcntl_notify()`. +*/ FD_Notifications :: bit_set[FD_Notifications_Bits; i32] -/// Seals for fcntl_add_seals +/* + Seals for `fcntl_add_seals()`. +*/ 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 { type: F_Owner_Type, pid: Pid, } -/// Events for ppoll +/* + Events for ppoll(2). +*/ Fd_Poll_Events :: bit_set[Fd_Poll_Events_Bits; u16] -/// Struct for ppoll +/* + Struct for ppoll(2). +*/ Poll_Fd :: struct { fd: Fd, events: 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] -/// Flags for mmap +/* + Flags for mmap. +*/ Map_Flags :: bit_set[Map_Flags_Bits; i32] -/// Flags for mlock.2 +/* + Flags for mlock(2). +*/ MLock_Flags :: bit_set[MLock_Flags_Bits; u32] -/// Flags for msync.2 +/* + Flags for msync(2). +*/ 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] -/// Flags for mremap.2 +/* + Flags for mremap(2). +*/ 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] -/// Flags for perf_event_open syscall +/* + Flags for perf_event_open(2) syscall. +*/ Perf_Flags :: bit_set[Perf_Flags_Bits; uint] 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] -/// 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] -/// The struct for perf_event_open +/* + The struct for perf_event_open. +*/ Perf_Event_Attr :: struct #packed { type: Perf_Event_Type, size: u32, @@ -358,7 +441,9 @@ Perf_Event_Attr :: struct #packed { _: 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 { 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 -/// Options for wait4() and waitpid() +/* + Options for wait4(2) and waitpid(2). +*/ 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] // Note(flysand): these could, in principle be implemented with bitfields, @@ -503,27 +592,36 @@ Sig_Action :: struct($T: typeid) { 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] -/// 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 -/// Flags for the socket for send/recv calls +/* + Flags for the socket for send/recv calls. +*/ Socket_Msg :: bit_set[Socket_Msg_Bits; i32] -/// Struct representing IPv4 socket address +/* + Struct representing IPv4 socket address. +*/ Sock_Addr_In :: struct #packed { sin_family: Address_Family, sin_port: u16be, sin_addr: [4]u8, } -/// Struct representing IPv6 socket address +/* + Struct representing IPv6 socket address. +*/ Sock_Addr_In6 :: struct #packed { sin6_family: Address_Family, sin6_port: u16be, @@ -532,7 +630,9 @@ Sock_Addr_In6 :: struct #packed { sin6_scope_id: u32, } -/// Struct representing an arbitrary socket address +/* + Struct representing an arbitrary socket address. +*/ Sock_Addr_Any :: struct #raw_union { using _: struct { family: Address_Family, @@ -561,13 +661,19 @@ MMsg_Hdr :: struct { len: u32, } -/// Just an alias to make futex-values more visible +/* + Just an alias to make futex-values more visible +*/ 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] -/// Times +/* + Times +*/ Tms :: struct { tms_utime: int, tms_stime: int, @@ -575,8 +681,10 @@ Tms :: struct { tms_cstime: int, } -/// "Unix time-sharing system name", allegedly -/// Basically system info +/* + "Unix time-sharing system name", allegedly. + Basically system info. +*/ UTS_Name :: struct { sysname: [65]u8 `fmt:"s,0"`, nodename: [65]u8 `fmt:"s,0"`, @@ -586,7 +694,9 @@ UTS_Name :: struct { domainname: [65]u8 `fmt:"s,0"`, } -/// Return buffer for the sysinfo syscall +/* + Return buffer for the sysinfo syscall +*/ Sys_Info :: struct { uptime: int, loads: [3]int, @@ -603,14 +713,17 @@ Sys_Info :: struct { _padding: [20 - (2 * size_of(int)) - size_of(i32)]u8, } -/// Resource limit +/* + Resource limit +*/ RLimit :: struct { cur: uint, max: uint, } -/// Structure representing how much of each resource -/// got used. +/* + Structure representing how much of each resource got used. +*/ RUsage :: struct { utime: Time_Val, stime: Time_Val, @@ -1088,4 +1201,7 @@ PTrace_Note_Type :: enum { NT_ARM_ZT = 0x40d, } +/* + Flags for splice(2) and tee(2) syscalls. +*/ Splice_Flags :: bit_set[Splice_Flags_Bits; u32]