sydtime/
lib.rs

1//
2// libsydtime: Rust-based C LD_PRELOAD library to replace vDSO time calls with syscalls
3// time/src/lib.rs: LD_PRELOAD library
4//
5// Copyright (c) 2023 Ali Polatel <alip@chesswob.org>
6//
7// SPDX-License-Identifier: LGPL-3.0
8
9use libc::{c_int, time_t, timespec, timeval, timezone};
10
11/// Hook for `gettimeofday`
12#[no_mangle]
13pub unsafe extern "C" fn gettimeofday(tv: *mut timeval, tz: *mut timezone) -> c_int {
14    libc::syscall(libc::SYS_gettimeofday, tv, tz) as c_int
15}
16
17/// Hook for `clock_getres`
18#[no_mangle]
19pub unsafe extern "C" fn clock_getres(clk_id: c_int, tp: *mut timespec) -> c_int {
20    libc::syscall(libc::SYS_clock_getres, clk_id, tp) as c_int
21}
22
23/// Hook for `clock_gettime`
24#[no_mangle]
25pub unsafe extern "C" fn clock_gettime(clk_id: c_int, tp: *mut timespec) -> c_int {
26    libc::syscall(libc::SYS_clock_gettime, clk_id, tp) as c_int
27}
28
29/// Hook for `time`
30#[no_mangle]
31pub unsafe extern "C" fn time(tloc: *mut time_t) -> time_t {
32    libc::syscall(libc::SYS_time, tloc) as time_t
33}