kernel: usercopy functions

This commit is contained in:
Matheus
2024-06-09 19:31:26 -03:00
parent 429f56aced
commit 50b4b45d00
53 changed files with 712 additions and 260 deletions
+11 -13
View File
@@ -7,30 +7,28 @@
#define CLOCK_REALTIME 0
#define CLOCK_BOOTTIME 7
syscallret_t syscall_clockget(context_t *, int clockid, timespec_t *tp){
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();
case CLOCK_REALTIME: {
timespec_t ts = timekeeper_time();
usercopy_touser(tp, &ts, sizeof(timespec_t));
ret.errno = 0;
break;
case CLOCK_BOOTTIME:
// TODO safe memcpy
*tp = timekeeper_timefromboot();
}
case CLOCK_BOOTTIME: {
timespec_t ts = timekeeper_timefromboot();
usercopy_touser(tp, &ts, sizeof(timespec_t));
ret.errno = 0;
break;
default:
}
default: {
ret.errno = EINVAL;
break;
}
}
ret.ret = ret.errno ? -1 : 0;