authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-16 23:38:00+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-16 22:10:38-04:00
log51aaa02679002ba65b270414bf94860fdcbe7c59
treefbb723b4ed5ab5a2f042af9243daa47a55baa12c
parent2eba779af5ee2dd90ac383abe8e548d893ea4ffc

VDSO calls must use the C CC


1 files changed, 5 insertions(+), 2 deletions(-)

std/os/linux.zig+5-2
...@@ -961,11 +961,14 @@ pub fn waitpid(pid: i32, status: *i32, options: i32) usize {...@@ -961,11 +961,14 @@ pub fn waitpid(pid: i32, status: *i32, options: i32) usize {
961961
962var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);962var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);
963963
964// We must follow the C calling convention when we call into the VDSO
965const vdso_clock_gettime_ty = extern fn (i32, *timespec) usize;
966
964pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {967pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
965 if (VDSO_CGT_SYM.len != 0) {968 if (VDSO_CGT_SYM.len != 0) {
966 const ptr = @atomicLoad(?*const c_void, &vdso_clock_gettime, .Unordered);969 const ptr = @atomicLoad(?*const c_void, &vdso_clock_gettime, .Unordered);
967 if (ptr) |fn_ptr| {970 if (ptr) |fn_ptr| {
968 const f = @ptrCast(@typeOf(clock_gettime), fn_ptr);971 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
969 const rc = f(clk_id, tp);972 const rc = f(clk_id, tp);
970 switch (rc) {973 switch (rc) {
971 0, @bitCast(usize, isize(-EINVAL)) => return rc,974 0, @bitCast(usize, isize(-EINVAL)) => return rc,
...@@ -983,7 +986,7 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {...@@ -983,7 +986,7 @@ extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {
983 _ = @cmpxchgStrong(?*const c_void, &vdso_clock_gettime, &init_vdso_clock_gettime, ptr, .Monotonic, .Monotonic);986 _ = @cmpxchgStrong(?*const c_void, &vdso_clock_gettime, &init_vdso_clock_gettime, ptr, .Monotonic, .Monotonic);
984 // Call into the VDSO if available987 // Call into the VDSO if available
985 if (ptr) |fn_ptr| {988 if (ptr) |fn_ptr| {
986 const f = @ptrCast(@typeOf(clock_gettime), fn_ptr);989 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
987 return f(clk, ts);990 return f(clk, ts);
988 }991 }
989 return @bitCast(usize, isize(-ENOSYS));992 return @bitCast(usize, isize(-ENOSYS));