aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Davidson <colrdavidson@gmail.com>2022-02-11 08:10:48 -0800
committerColin Davidson <colrdavidson@gmail.com>2022-02-11 08:10:48 -0800
commitf77cd5533d8fdda0abc9052e63c1f13a57db73ae (patch)
treef86157161e1dc1fae408a6bd416e2105b4c93e48
parent546faab0cbfb08ec5158a4f7510a4fd9cf353487 (diff)
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 3288388ea..3a9136b43 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)