| ... | ... | @@ -959,10 +959,13 @@ pub fn waitpid(pid: i32, status: *i32, options: i32) usize { |
| 959 | 959 | return syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); |
| 960 | 960 | } |
| 961 | 961 | |
| 962 | var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); |
| 963 | |
| 962 | 964 | pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { |
| 963 | 965 | if (VDSO_CGT_SYM.len != 0) { |
| 964 | | const f = @atomicLoad(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, builtin.AtomicOrder.Unordered); |
| 965 | | if (@ptrToInt(f) != 0) { |
| 966 | const ptr = @atomicLoad(?*const c_void, &vdso_clock_gettime, .Unordered); |
| 967 | if (ptr) |fn_ptr| { |
| 968 | const f = @ptrCast(@typeOf(clock_gettime), fn_ptr); |
| 966 | 969 | const rc = f(clk_id, tp); |
| 967 | 970 | switch (rc) { |
| 968 | 971 | 0, @bitCast(usize, isize(-EINVAL)) => return rc, |
| ... | ... | @@ -972,13 +975,18 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { |
| 972 | 975 | } |
| 973 | 976 | return syscall2(SYS_clock_gettime, @bitCast(usize, isize(clk_id)), @ptrToInt(tp)); |
| 974 | 977 | } |
| 975 | | var vdso_clock_gettime = init_vdso_clock_gettime; |
| 978 | |
| 976 | 979 | extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize { |
| 977 | | const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM); |
| 978 | | var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr); |
| 979 | | _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic); |
| 980 | | if (@ptrToInt(f) == 0) return @bitCast(usize, isize(-ENOSYS)); |
| 981 | | return f(clk, ts); |
| 980 | const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM)); |
| 981 | // Note that we may not have a VDSO at all, update the stub address anyway |
| 982 | // so that clock_gettime will fall back on the good old (and slow) syscall |
| 983 | _ = @cmpxchgStrong(?*const c_void, &vdso_clock_gettime, &init_vdso_clock_gettime, ptr, .Monotonic, .Monotonic); |
| 984 | // Call into the VDSO if available |
| 985 | if (ptr) |fn_ptr| { |
| 986 | const f = @ptrCast(@typeOf(clock_gettime), fn_ptr); |
| 987 | return f(clk, ts); |
| 988 | } |
| 989 | return @bitCast(usize, isize(-ENOSYS)); |
| 982 | 990 | } |
| 983 | 991 | |
| 984 | 992 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { |