syscalls: clockget

This commit is contained in:
Matheus
2023-07-05 22:13:29 -03:00
parent 3019ae0a55
commit e05e74e1a5
4 changed files with 61 additions and 10 deletions
+3 -1
View File
@@ -27,6 +27,7 @@ extern syscall_faccessat
extern syscall_unlinkat
extern syscall_ioctl
extern syscall_mkdirat
extern syscall_clockget
syscalltab:
dq syscall_print
dq syscall_mmap
@@ -56,7 +57,8 @@ dq syscall_faccessat
dq syscall_unlinkat
dq syscall_ioctl
dq syscall_mkdirat
syscallcount equ 28
dq syscall_clockget
syscallcount equ 29
section .text
global arch_syscall_entry
; on entry:
+5 -3
View File
@@ -4,7 +4,7 @@
#ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 28
#define SYSCALL_COUNT 29
#define LOGSTR(x) arch_e9_puts(x)
static char *name[] = {
@@ -35,7 +35,8 @@ static char *name[] = {
"faccessat",
"unlinkat",
"ioctl",
"mkdirat"
"mkdirat",
"clockget"
};
static char *args[] = {
@@ -66,7 +67,8 @@ static char *args[] = {
"dirfd %d pathname %s mode %d flags %d", // faccessat
"dirfd %d pathname %d flags %d", // unlinkat
"fd %d request %lu argument %d", // ioctl
"dirfd %d path %s mode %o" // mkdirat
"dirfd %d path %s mode %o", // mkdirat
"clockid %d timespec %p" // clockget
};
#endif
+40
View File
@@ -0,0 +1,40 @@
#include <kernel/syscalls.h>
#include <kernel/abi.h>
#include <time.h>
#include <kernel/timekeeper.h>
#include <kernel/vmm.h>
#define CLOCK_REALTIME 0
#define CLOCK_BOOTTIME 7
syscallret_t syscall_clockget(context_t *, int clockid, timespec_t *tp){
syscallret_t ret = {
.ret = -1
};
if ((void *)tp > USERSPACE_END) {
ret.errno = EFAULT;
return ret;
}
switch (clockid) {
case CLOCK_REALTIME:
// TODO safe memcpy
*tp = timekeeper_time();
ret.errno = 0;
break;
case CLOCK_BOOTTIME:
// TODO safe memcpy
*tp = timekeeper_timefromboot();
ret.errno = 0;
break;
default:
ret.errno = EINVAL;
break;
}
ret.ret = ret.errno ? -1 : 0;
return ret;
}