mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
kernel: usercopy functions
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user