diff options
Diffstat (limited to 'Libraries/LibC/time.cpp')
-rw-r--r-- | Libraries/LibC/time.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Libraries/LibC/time.cpp b/Libraries/LibC/time.cpp index 4cd2e47fd9..d0d156d67e 100644 --- a/Libraries/LibC/time.cpp +++ b/Libraries/LibC/time.cpp @@ -1,10 +1,11 @@ +#include <Kernel/KernelInfoPage.h> #include <Kernel/Syscall.h> #include <assert.h> #include <errno.h> +#include <string.h> #include <sys/time.h> #include <sys/times.h> #include <time.h> -#include <string.h> extern "C" { @@ -21,8 +22,17 @@ time_t time(time_t* tloc) int gettimeofday(struct timeval* __restrict__ tv, void* __restrict__) { - int rc = syscall(SC_gettimeofday, tv); - __RETURN_WITH_ERRNO(rc, rc, -1); + static volatile KernelInfoPage* kernel_info; + if (!kernel_info) + kernel_info = (volatile KernelInfoPage*)syscall(SC_get_kernel_info_page); + + for (;;) { + auto serial = kernel_info->serial; + *tv = const_cast<struct timeval&>(kernel_info->now); + if (serial == kernel_info->serial) + break; + } + return 0; } char* ctime(const time_t*) |