aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2022-02-15 21:04:09 +0100
committerGitHub <noreply@github.com>2022-02-15 21:04:09 +0100
commit855e7beab1b3a0ced45436d609112ed0576c2eec (patch)
treeeeb0790f85abeaea08009729bbd13d0f616a0ef1
parentedc13c29df049198c7c0bfb0a58a9ac9600c31dc (diff)
parent31f544c2586028881ea9294f233a8a02fe5b37e4 (diff)
Merge pull request #1488 from colrdavidson/master
Add fork and personality
-rw-r--r--core/os/os_linux.odin28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin
index ae4a03944..dfb4b7948 100644
--- a/core/os/os_linux.odin
+++ b/core/os/os_linux.odin
@@ -11,6 +11,7 @@ import "core:intrinsics"
import "core:sys/unix"
Handle :: distinct i32
+Pid :: distinct i32
File_Time :: distinct u64
Errno :: distinct i32
@@ -150,6 +151,8 @@ ERFKILL: Errno : 132 /* Operation not possible due to RF-kill */
EHWPOISON: Errno : 133 /* Memory page has hardware error */
+ADDR_NO_RANDOMIZE :: 0x40000
+
O_RDONLY :: 0x00000
O_WRONLY :: 0x00001
O_RDWR :: 0x00002
@@ -270,6 +273,15 @@ AT_FDCWD :: -100
AT_REMOVEDIR :: uintptr(0x200)
AT_SYMLINK_NOFOLLOW :: uintptr(0x100)
+_unix_personality :: proc(persona: u64) -> int {
+ return int(intrinsics.syscall(unix.SYS_personality, uintptr(persona)))
+}
+
+_unix_fork :: proc() -> Pid {
+ res := int(intrinsics.syscall(unix.SYS_fork))
+ return -1 if res < 0 else Pid(res)
+}
+
_unix_open :: proc(path: cstring, flags: int, mode: int = 0o000) -> Handle {
when ODIN_ARCH != .arm64 {
res := int(intrinsics.syscall(unix.SYS_open, uintptr(rawptr(path)), uintptr(flags), uintptr(mode)))
@@ -431,6 +443,22 @@ get_last_error :: proc() -> int {
return __errno_location()^
}
+personality :: proc(persona: u64) -> (Errno) {
+ res := _unix_personality(persona)
+ if res == -1 {
+ return _get_errno(res)
+ }
+ return ERROR_NONE
+}
+
+fork :: proc() -> (Pid, Errno) {
+ pid := _unix_fork()
+ if pid == -1 {
+ return -1, _get_errno(int(pid))
+ }
+ return pid, ERROR_NONE
+}
+
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Errno) {
cstr := strings.clone_to_cstring(path)
handle := _unix_open(cstr, flags, mode)