Skip to content

Commit 7744548

Browse files
authored
syssbrk syscall
1 parent bc2017e commit 7744548

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

library/std/src/sys/pal/safaos/syscalls.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,21 @@ fn syscall1(num: usize, arg1: usize) -> ErrorStatus {
5555

5656
crate::mem::transmute(result)
5757
}
58+
}
59+
60+
fn syscall2(num: usize, arg1: usize, arg2: usize) -> ErrorStatus {
61+
let result: u16;
62+
unsafe {
63+
asm!(
64+
"int 0x80",
65+
in("rax") num,
66+
in("rdi") arg1,
67+
in("rsi") arg2,
68+
lateout("rax") result,
69+
);
5870

71+
crate::mem::transmute(result)
72+
}
5973
}
6074

6175
fn syscall5(
@@ -97,7 +111,9 @@ pub fn syssync(fd: usize) -> ErrorStatus {
97111
syscall1(0x10, fd)
98112
}
99113

100-
101114
pub fn syssbrk(size: isize) -> Result<*mut u8, ErrorStatus> {
102-
todo!()
103-
}
115+
let mut target_ptr: *mut u8 = core::ptr::null_mut();
116+
let err = syscall2(0x12, size as usize, (&mut target_ptr) as *mut _ as usize);
117+
118+
if err != ErrorStatus::None { Err(err) } else { Ok(target_ptr) }
119+
}

0 commit comments

Comments
 (0)