Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux POSIX support #4118

Merged
merged 35 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c0521c6
Add linux support for errno.
andradei Aug 21, 2024
ef06cd9
Initial implementation of linux-specifig dirent struct.
andradei Aug 21, 2024
1adea2f
Merge branch 'master' of github.com:odin-lang/Odin into posix-linux
andradei Aug 24, 2024
90aa7df
Add POSIX dirent struct for Linux.
andradei Aug 24, 2024
9c06898
Add comma to last dirent struct member.
andradei Aug 24, 2024
d8e4a1b
Fix comment typo on POSIX ENOTSUP constant.
andradei Aug 24, 2024
2794eb3
On Linux POSIX, ENOTSUP and EOPNOTSUPP have the same value.
andradei Aug 24, 2024
e0b7847
Fix else when clause.
andradei Aug 24, 2024
7d94810
Fix ino_t and ino_t32 types for POSIX linux.
andradei Aug 27, 2024
4532202
Merge branch 'master' of github.com:odin-lang/Odin into posix-linux
andradei Aug 28, 2024
f0e631c
Use native types on linux POSIX structs.
andradei Aug 29, 2024
4577d54
Add contants RTLD contants on os_linux and posix (dlfcn).
andradei Aug 29, 2024
3557955
Align the dirent struct for linux
andradei Aug 30, 2024
575aedc
Implement POSIX support for Linux for the following facilities:
andradei Aug 31, 2024
186565b
Simplify the implementation of POSIX langinfo for Linux:
andradei Aug 31, 2024
a248d49
Add Linux support for POSIX limits.
andradei Sep 2, 2024
35f961d
Add POSIX Linux support for net_if and netdb.
andradei Sep 2, 2024
f072136
Implement POSIX linux support for poll and netinet_tcp. Incomplete su…
andradei Sep 3, 2024
d93f55c
Reuse POSIX netinet_in constants for linux.
andradei Sep 3, 2024
9e4b45f
Add linux to OS check.
andradei Sep 3, 2024
92ff046
Fix some compilation errors on POSIX linux.
andradei Sep 10, 2024
ff82396
Add Linux support for POSIX sys ipc, mman, time, utsname.
andradei Sep 10, 2024
1632f19
In-progress support for POSIX on Linux for sys/socket.
andradei Sep 11, 2024
55a9ba1
Finish sys/socket POSIX support for Linux.
andradei Sep 12, 2024
af94c4a
Add initial POSIX support for Linux for wordexp.
andradei Sep 14, 2024
aa91479
Fix O_NOFOLLOW typo. Add Linux support for POSIX fcntl.
andradei Sep 14, 2024
8616842
Implement Linux POSIX compliance for poll, sched, sys/select. Fix enu…
andradei Sep 15, 2024
97e06cb
Fix bit flags on fcntl linux POSIX implemention. Add sys/sem linux im…
andradei Sep 16, 2024
10702f1
Implement POSIX pthread, signal, sys/resource, unistd for Linux.
andradei Sep 22, 2024
5162c6c
Rename sigaction duplicate type to sigaction_t on linux, following ot…
andradei Sep 22, 2024
c68d847
Satisfy the compiler.
andradei Sep 22, 2024
04c08c2
Resolve bit set differences between linux and other platforms in posi…
andradei Sep 22, 2024
cc60725
Move bit set creation to compiler guard. Fix indentation on posix/sys…
andradei Sep 22, 2024
c1a67f3
Fix O_Flag_Bits.EXEC for non Linux platforms on posix/fcntl.
andradei Sep 22, 2024
5cd1784
review/correct/cleanup posix linux PR
laytan Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/os/os_linux.odin
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Pid :: distinct i32
File_Time :: distinct u64
Socket :: distinct int

ino_t :: u64
andradei marked this conversation as resolved.
Show resolved Hide resolved
ino_t32 :: u32

INVALID_HANDLE :: ~Handle(0)

_Platform_Error :: linux.Errno
Expand Down
40 changes: 35 additions & 5 deletions core/sys/posix/dirent.odin
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,41 @@ when ODIN_OS == .Darwin {
} else when ODIN_OS == .NetBSD {

dirent :: struct {
d_ino: ino_t, /* [PSX] file number of entry */
d_reclen: c.uint16_t, /* length of this record */
d_namelen: c.uint16_t, /* length of string in d_name */
d_type: D_Type, /* file type */
d_name: [512]c.char `fmt:"s,0"`, /* [PSX] entry name */
d_ino: ino_t, /* [PSX] file number of entry */
d_reclen: c.uint16_t, /* length of this record */
d_namelen: c.uint16_t, /* length of string in d_name */
d_type: D_Type, /* file type */
d_name: [512]c.char `fmt:"s,0"`, /* [PSX] entry name */
}

} else when ODIN_OS == .Linux {

when ODIN_ARCH == .i386 || ODIN_ARCH == .wasm32 || ODIN_ARCH == .arm32 {
andradei marked this conversation as resolved.
Show resolved Hide resolved

dirent :: struct {
andradei marked this conversation as resolved.
Show resolved Hide resolved
d_ino: ino_t32, /* [PSX] file number of entry */
andradei marked this conversation as resolved.
Show resolved Hide resolved
d_off: off_t32, /* directory offset of the next entry */
d_reclen: c.uint16_t, /* length of this record */
d_type: D_Type, /* file type */
d_name: [256]c.char `fmt:"s,0"`, /* [PSX] entry name */
}
} else when ODIN_ARCH == .amd64 || ODIN_ARCH == .wasm64p32 || ODIN_ARCH == .arm64 {
andradei marked this conversation as resolved.
Show resolved Hide resolved

dirent :: struct {
d_ino: ino_t, /* [PSX] file number of entry */
d_off: off_t, /* directory offset of the next entry */
d_reclen: c.uint16_t, /* length of this record */
d_type: D_Type, /* file type */
d_name: [256]c.char `fmt:"s,0"`, /* [PSX] entry name */
}
}

dirent64 :: struct {
laytan marked this conversation as resolved.
Show resolved Hide resolved
d_ino: ino_t, /* [PSX] file number of entry */
d_off: off_t, /* directory offset of the next entry */
d_reclen: c.uint16_t, /* length of this record */
d_type: D_Type, /* file type */
d_name: [256]c.char `fmt:"s,0"`, /* [PSX] entry name */
}

} else {
Expand Down
101 changes: 95 additions & 6 deletions core/sys/posix/errno.odin
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ when ODIN_OS == .Darwin {
EMLINK :: 31
EPIPE :: 32
EAGAIN :: 35
EWOULDBLOCK :: 35
EWOULDBLOCK :: EAGAIN
EINPROGRESS :: 36
EALREADY :: 37
ENOTSOCK :: 38
Expand All @@ -151,7 +151,7 @@ when ODIN_OS == .Darwin {
ENOPROTOOPT :: 42
EPROTONOSUPPORT :: 43
ENOTSUP :: 45
EOPNOTSUPP :: 45
EOPNOTSUPP :: ENOTSUP
EAFNOSUPPORT :: 47
EADDRINUSE :: 48
EADDRNOTAVAIL :: 49
Expand Down Expand Up @@ -220,7 +220,7 @@ when ODIN_OS == .Darwin {
EMLINK :: 31
EPIPE :: 32
EAGAIN :: 35
EWOULDBLOCK :: 35
EWOULDBLOCK :: EAGAIN
EINPROGRESS :: 36
EALREADY :: 37
ENOTSOCK :: 38
Expand All @@ -230,7 +230,7 @@ when ODIN_OS == .Darwin {
ENOPROTOOPT :: 42
EPROTONOSUPPORT :: 43
ENOTSUP :: 45
EOPNOTSUPP :: 45
EOPNOTSUPP :: ENOTSUP
EAFNOSUPPORT :: 47
EADDRINUSE :: 48
EADDRNOTAVAIL :: 49
Expand Down Expand Up @@ -301,7 +301,7 @@ when ODIN_OS == .Darwin {
EMLINK :: 31
EPIPE :: 32
EAGAIN :: 35
EWOULDBLOCK :: 35
EWOULDBLOCK :: EAGAIN
EINPROGRESS :: 36
EALREADY :: 37
ENOTSOCK :: 38
Expand All @@ -311,7 +311,7 @@ when ODIN_OS == .Darwin {
ENOPROTOOPT :: 42
EPROTONOSUPPORT :: 43
ENOTSUP :: 45
EOPNOTSUPP :: 45
EOPNOTSUPP :: ENOTSUP
EAFNOSUPPORT :: 47
EADDRINUSE :: 48
EADDRNOTAVAIL :: 49
Expand Down Expand Up @@ -367,6 +367,95 @@ when ODIN_OS == .Darwin {
ETIME :: -1
}

} else when ODIN_OS == .Linux {
EPERM :: 1
ENOENT :: 2
ESRCH :: 3
EINTR :: 4
EIO :: 5
ENXIO :: 6
E2BIG :: 7
ENOEXEC :: 8
EBADF :: 9
ECHILD :: 10
EAGAIN :: 11
EWOULDBLOCK :: EAGAIN
ENOMEM :: 12
EACCES :: 13
EFAULT :: 14
EBUSY :: 16
EEXIST :: 17
EXDEV :: 18
ENODEV :: 19
ENOTDIR :: 20
EISDIR :: 21
EINVAL :: 22
ENFILE :: 23
EMFILE :: 24
ENOTTY :: 25
ETXTBSY :: 26
EFBIG :: 27
ENOSPC :: 28
ESPIPE :: 29
EROFS :: 30
EMLINK :: 31
EPIPE :: 32

EDEADLK :: 35
ENAMETOOLONG :: 36
ENOLCK :: 37
ENOSYS :: 38
ENOTEMPTY :: 39
ELOOP :: 40
ENOMSG :: 42
EIDRM :: 43

ENOSTR :: 60
ENODATA :: 61
ETIME :: 62
ENOSR :: 63

ENOLINK :: 67

EPROTO :: 71
EMULTIHOP :: 72
EBADMSG :: 74
EOVERFLOW :: 75

ENOTSOCK :: 88
EDESTADDRREQ :: 89
EMSGSIZE :: 90
EPROTOTYPE :: 91
ENOPROTOOPT :: 92
EPROTONOSUPPORT :: 93

EOPNOTSUPP :: 95
ENOTSUP :: EOPNOTSUPP
EAFNOSUPPORT :: 97
EADDRINUSE :: 98
EADDRNOTAVAIL :: 99
ENETDOWN :: 100
ENETUNREACH :: 101
ENETRESET :: 102
ECONNABORTED :: 103
ECONNRESET :: 104
ENOBUFS :: 105
EISCONN :: 106
ENOTCONN :: 107

ETIMEDOUT :: 110
ECONNREFUSED :: 111

EHOSTUNREACH :: 113
EALREADY :: 114
EINPROGRESS :: 115
ESTALE :: 116

EDQUOT :: 122
ECANCELED :: 125

EOWNERDEAD :: 130
ENOTRECOVERABLE :: 131
} else {
#panic("posix is unimplemented for the current target")
}
Expand Down
3 changes: 3 additions & 0 deletions core/sys/posix/fcntl.odin
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ when ODIN_OS == .Darwin {
l_whence: c.short, /* [PSX] flag (Whence) of starting offset */
}

} else when ODIN_OS == .Linux {
off_t :: distinct c.uint64_t
andradei marked this conversation as resolved.
Show resolved Hide resolved
off_t32 :: distinct c.uint32_t
} else {
#panic("posix is unimplemented for the current target")
}
3 changes: 3 additions & 0 deletions core/sys/posix/sys_stat.odin
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ when ODIN_OS == .Darwin {
UTIME_NOW :: -2
UTIME_OMIT :: -1

} else when ODIN_OS == .Linux {
ino_t :: distinct u64
ino_t32 :: distinct u32
andradei marked this conversation as resolved.
Show resolved Hide resolved
} else {
#panic("posix is unimplemented for the current target")
}