27 lines
662 B
C++
27 lines
662 B
C++
#include "arch/Timer.h"
|
|
#include "memory/MemoryManager.h"
|
|
#include "sys/Syscall.h"
|
|
#include <bits/clockid.h>
|
|
#include <bits/timespec.h>
|
|
|
|
Result<u64> sys_clock_gettime(Registers*, SyscallArgs args)
|
|
{
|
|
clockid_t id = (clockid_t)args[0];
|
|
struct timespec* ts = (struct timespec*)args[1];
|
|
|
|
switch (id)
|
|
{
|
|
case CLOCK_MONOTONIC: {
|
|
if (!MemoryManager::copy_to_user_typed(ts, Timer::monotonic_clock())) return err(EFAULT);
|
|
break;
|
|
}
|
|
case CLOCK_REALTIME: {
|
|
if (!MemoryManager::copy_to_user_typed(ts, Timer::realtime_clock())) return err(EFAULT);
|
|
break;
|
|
}
|
|
default: return err(EINVAL);
|
|
}
|
|
|
|
return 0;
|
|
}
|