Browse Source

Merge pull request #1488 from colrdavidson/master

Add fork and personality
Jeroen van Rijn 3 years ago
parent
commit
855e7beab1
1 changed files with 28 additions and 0 deletions
  1. 28 0
      core/os/os_linux.odin

+ 28 - 0
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)