vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / os / arch / x86_64 / system_time.cpp
blob47a98240dbd179e03380b0c3950bd9dc70f0e2d8
1 /*
2 * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <stdint.h>
10 static uint64_t cv_factor;
11 static uint64_t cv_factor_nsec;
14 extern "C" void
15 __x86_setup_system_time(uint64_t cv, uint64_t cv_nsec)
17 cv_factor = cv;
18 cv_factor_nsec = cv_nsec;
22 static inline uint64_t
23 rdtsc()
25 uint64_t lo, hi;
26 __asm__("rdtsc" : "=a" (lo), "=d" (hi));
27 return lo | (hi << 32);
31 extern "C" [[gnu::optimize("omit-frame-pointer")]] int64_t
32 system_time()
34 __uint128_t time = static_cast<__uint128_t>(rdtsc()) * cv_factor;
35 return time >> 64;
39 extern "C" [[gnu::optimize("omit-frame-pointer")]] int64_t
40 system_time_nsecs()
42 __uint128_t t = static_cast<__uint128_t>(rdtsc()) * cv_factor_nsec;
43 return t >> 32;