Skip to content

Commit

Permalink
Add Linux support for POSIX sys ipc, mman, time, utsname.
Browse files Browse the repository at this point in the history
  • Loading branch information
andradei committed Sep 10, 2024
1 parent 92ff046 commit ff82396
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/sys/posix/sys_ipc.odin
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ IPC_Flag_Bits :: enum c.int {
}
IPC_Flags :: bit_set[IPC_Flag_Bits; c.int]

when ODIN_OS == .Darwin {
when ODIN_OS == .Darwin || ODIN_OS == .Linux {

key_t :: distinct c.int32_t

Expand Down
11 changes: 8 additions & 3 deletions core/sys/posix/sys_mman.odin
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ when ODIN_OS == .NetBSD {
@(private) LMSYNC :: "msync"
}

when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Linux {

PROT_EXEC :: 0x04
_PROT_NONE :: 0x00
Expand All @@ -174,7 +174,7 @@ when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
MAP_PRIVATE :: 0x0002
MAP_SHARED :: 0x0001

when ODIN_OS == .Darwin {
when ODIN_OS == .Darwin || ODIN_OS == .Linux {
MS_INVALIDATE :: 0x0002
_MS_SYNC :: 0x0010
} else when ODIN_OS == .NetBSD {
Expand All @@ -184,13 +184,18 @@ when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
MS_INVALIDATE :: 0x0004
_MS_SYNC :: 0x0002
}

MS_ASYNC :: 0x0001
MS_SYNC :: Sync_Flags{Sync_Flags_Bits(log2(_MS_SYNC))}

MCL_CURRENT :: 0x0001
MCL_FUTURE :: 0x0002

MAP_FAILED :: rawptr(~uintptr(0))
when ODIN_OS == .Linux {
MAP_FAILED :: rawptr(~uintptr(-1))
} else {
MAP_FAILED :: rawptr(~uintptr(0))
}

POSIX_MADV_DONTNEED :: 4
POSIX_MADV_NORMAL :: 0
Expand Down
2 changes: 1 addition & 1 deletion core/sys/posix/sys_time.odin
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ when ODIN_OS == .NetBSD {
@(private) LUTIMES :: "utimes"
}

when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Linux {

itimerval :: struct {
it_interval: timeval, /* [PSX] timer interval */
Expand Down
13 changes: 9 additions & 4 deletions core/sys/posix/sys_utsname.odin
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ foreign lib {
uname :: proc(uname: ^utsname) -> c.int ---
}

when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {

@(private)
_SYS_NAMELEN :: 256
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Linux {

when ODIN_OS == .Linux {
@(private)
_SYS_NAMELEN :: 65
} else {
@(private)
_SYS_NAMELEN :: 256
}

utsname :: struct {
sysname: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of OS */
Expand Down

0 comments on commit ff82396

Please sign in to comment.