aboutsummaryrefslogtreecommitdiff
path: root/core/sys
diff options
context:
space:
mode:
authorIsaac Andrade <andradei@proton.me>2024-09-15 18:43:51 -0600
committerIsaac Andrade <andradei@proton.me>2024-09-15 18:43:51 -0600
commit97e06cb98e890643d17f5ebca3b029f4dd21d6aa (patch)
treed12946c8639aedbbaddb0dba8a5e7c0ad870d5fb /core/sys
parent8616842ec6694b14f3c3f534c92bda670304c4ed (diff)
Fix bit flags on fcntl linux POSIX implemention. Add sys/sem linux implementation.
Diffstat (limited to 'core/sys')
-rw-r--r--core/sys/posix/fcntl.odin9
-rw-r--r--core/sys/posix/sys_sem.odin30
2 files changed, 37 insertions, 2 deletions
diff --git a/core/sys/posix/fcntl.odin b/core/sys/posix/fcntl.odin
index d48e39d02..3350238e4 100644
--- a/core/sys/posix/fcntl.odin
+++ b/core/sys/posix/fcntl.odin
@@ -123,12 +123,16 @@ O_Flag_Bits :: enum c.int {
NONBLOCK = log2(O_NONBLOCK),
// Write I/O shall complete as defined by synchronized I/O file integrity completion.
SYNC = log2(O_SYNC),
+
// NOTE: use with `posix.O_RSYNC + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
// this bit set enum because it is 0 on some platforms and a value on others.
// RSYNC = O_RSYNC,
// Execute only.
- EXEC = O_EXEC when ODIN_OS == .Linux else log2(O_EXEC),
+ // NOTE: use with `posix.O_ENTER + { .OTHER_FLAG, .OTHER_FLAG }`, unfortunately can't be in
+ // this bit set enum because it is 0 on some platforms and a value on others.
+ // EXEC = O_EXEC
+
// Reading and writing.
RDWR = log2(O_RDWR),
// Writing only.
@@ -139,7 +143,8 @@ O_Flag_Bits :: enum c.int {
O_Flags :: bit_set[O_Flag_Bits; c.int]
// A mask of all the access mode bits.
-O_ACCMODE :: O_Flags{ .EXEC, .RDWR, .WRONLY }
+// NOTE: .EXEC and .RDONLY also belong here, but they are 0 on some platforms.
+O_ACCMODE :: O_Flags{ .RDWR, .WRONLY }
AT_Flag_Bits :: enum c.int {
EACCESS = log2(AT_EACCESS),
diff --git a/core/sys/posix/sys_sem.odin b/core/sys/posix/sys_sem.odin
index 3fcde325b..9f45ab1fe 100644
--- a/core/sys/posix/sys_sem.odin
+++ b/core/sys/posix/sys_sem.odin
@@ -127,6 +127,36 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
sem_flg: c.short, /* [PSX] operation flags */
}
+} else when ODIN_OS == .Linux {
+
+ SEM_UNDO :: 0x1000 // undo the operation on exit
+
+ // Commands for `semctl'.
+ GETPID :: 11
+ GETVAL :: 12
+ GETALL :: 13
+ GETNCNT :: 14
+ GETZCNT :: 15
+ SETVAL :: 16
+ SETALL :: 17
+
+ semid_ds :: struct {
+ sem_perm: ipc_perm, // [PSX] operation permission structure
+ sem_otime: time_t, // [PSX] last semop()
+ __sem_otime_high: c.ulong,
+ sem_ctime: time_t, // [PSX] last time changed by semctl()
+ __sem_ctime_high: c.ulong,
+ sem_nsems: c.ulong, // [PSX] number of semaphores in set
+ __glibc_reserved3: c.ulong,
+ __glibc_reserved4: c.ulong,
+ }
+
+ sembuf :: struct {
+ sem_num: c.ushort, /* [PSX] semaphore number */
+ sem_op: c.short, /* [PSX] semaphore operation */
+ sem_flg: c.short, /* [PSX] operation flags */
+ }
+
} else {
#panic("posix is unimplemented for the current target")
}