mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 13:48:21 +00:00
syscalls: nanosleep
This commit is contained in:
@@ -34,6 +34,7 @@ extern syscall_fchmod
|
||||
extern syscall_fchmodat
|
||||
extern syscall_umask
|
||||
extern syscall_poll
|
||||
extern syscall_nanosleep
|
||||
syscalltab:
|
||||
dq syscall_print
|
||||
dq syscall_mmap
|
||||
@@ -70,7 +71,8 @@ dq syscall_fchmod
|
||||
dq syscall_fchmodat
|
||||
dq syscall_umask
|
||||
dq syscall_poll
|
||||
syscallcount equ 35
|
||||
dq syscall_nanosleep
|
||||
syscallcount equ 36
|
||||
section .text
|
||||
global arch_syscall_entry
|
||||
; on entry:
|
||||
|
||||
@@ -42,7 +42,8 @@ static char *name[] = {
|
||||
"fchmod",
|
||||
"fchmodat",
|
||||
"umask",
|
||||
"poll"
|
||||
"poll",
|
||||
"nanosleep"
|
||||
};
|
||||
|
||||
static char *args[] = {
|
||||
@@ -80,7 +81,8 @@ static char *args[] = {
|
||||
"fd %d mode %o", // fchmod
|
||||
"dirfd %d path %s mode %o flags %d", // fchmodat
|
||||
"mode %o", // umask
|
||||
"fds %p nfds %d timeout %d" // poll
|
||||
"fds %p nfds %d timeout %d", // poll
|
||||
"time %p remaining %p" // nanosleep
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <time.h>
|
||||
#include <kernel/vmm.h>
|
||||
#include <kernel/timer.h>
|
||||
#include <arch/cpu.h>
|
||||
|
||||
static void timeout(context_t *, dpcarg_t arg) {
|
||||
thread_t *thread = arg;
|
||||
sched_wakeup(thread, 0);
|
||||
}
|
||||
|
||||
syscallret_t syscall_nanosleep(context_t *, timespec_t *utime, timespec_t *remaining) {
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
if ((void *)utime > USERSPACE_END || (void *)remaining > USERSPACE_END) {
|
||||
ret.errno = EFAULT;
|
||||
return ret;
|
||||
}
|
||||
|
||||
timespec_t time = *utime;
|
||||
|
||||
if (time.ns > 999999999 || time.ns < 0) {
|
||||
ret.errno = EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
timerentry_t sleepentry;
|
||||
sched_preparesleep(true);
|
||||
|
||||
sched_targetcpu(_cpu());
|
||||
timer_insert(_cpu()->timer, &sleepentry, timeout, _cpu()->thread, time.s * 1000000 + time.ns / 1000, false);
|
||||
|
||||
ret.errno = sched_yield();
|
||||
|
||||
if (ret.errno) {
|
||||
// XXX interruptible wait might break things
|
||||
timer_remove(_cpu()->timer, &sleepentry);
|
||||
}
|
||||
|
||||
sched_targetcpu(NULL);
|
||||
|
||||
ret.ret = 0;
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user