Last active
January 4, 2019 22:54
-
-
Save Hi-Angel/6e96e3bfd4ee28c046954debfdea6c8e to your computer and use it in GitHub Desktop.
Revisions
-
Hi-Angel revised this gist
Jan 4, 2019 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,13 +10,11 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp) { = (clock_gettime_ptr) dlsym(RTLD_NEXT, "clock_gettime"); int ret = real_clock_gettime(clk_id, tp); if (ret != -1) { const short AMOUNT_TO_SLOW = 4; const time_t NSEC_FRAC = 1000000000 / AMOUNT_TO_SLOW; const long nsec_part = NSEC_FRAC * (tp->tv_sec % AMOUNT_TO_SLOW); tp->tv_nsec = tp->tv_nsec / AMOUNT_TO_SLOW + nsec_part; tp->tv_sec = tp->tv_sec / AMOUNT_TO_SLOW; } return ret; } -
Hi-Angel revised this gist
Jan 4, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,6 @@ pub extern "C" fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { let f = libc::dlsym(libc::RTLD_NEXT, "clock_gettime\0".as_ptr() as *const i8); std::mem::transmute::<*const libc::c_void, ClockGettimeType>(f) }; } let ret = real_clock_gettime(clk_id, tp); if ret != -1 { -
Hi-Angel created this gist
Jan 4, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #include <dlfcn.h> #include <stdio.h> #include <string.h> #include <time.h> extern "C" int clock_gettime(clockid_t clk_id, struct timespec *tp) { using clock_gettime_ptr = int (*)(clockid_t, struct timespec*); const static clock_gettime_ptr real_clock_gettime = (clock_gettime_ptr) dlsym(RTLD_NEXT, "clock_gettime"); int ret = real_clock_gettime(clk_id, tp); if (ret != -1) { // printf("orig sec %li, nsec %li", tp->tv_sec, tp->tv_nsec); const short AMOUNT_TO_SLOW = 4; const time_t NSEC_FRAC = 1000000000 / AMOUNT_TO_SLOW; const long nsec_part = NSEC_FRAC * (tp->tv_sec % AMOUNT_TO_SLOW); tp->tv_nsec = tp->tv_nsec / AMOUNT_TO_SLOW + nsec_part; tp->tv_sec = tp->tv_sec / AMOUNT_TO_SLOW; // printf("\tnow sec %li, nsec %li\n", tp->tv_sec, tp->tv_nsec); } return ret; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #[macro_use] extern crate lazy_static; extern crate libc; use libc::{clockid_t, timespec, c_int}; #[no_mangle] pub extern "C" fn clock_gettime(clk_id: clockid_t, tp: *mut timespec) -> c_int { type ClockGettimeType = fn(clk_id: clockid_t, tp: *mut timespec) -> c_int; unsafe { lazy_static! { static ref real_clock_gettime: ClockGettimeType = unsafe { let f = libc::dlsym(libc::RTLD_NEXT, "clock_gettime\0".as_ptr() as *const i8); std::mem::transmute::<*const libc::c_void, ClockGettimeType>(f) }; } let ret = real_clock_gettime(clk_id, tp); if ret != -1 { let amount_to_slow = 4; let nsec_frac = 1000000000 / amount_to_slow; let nsec_part = nsec_frac * ((*tp).tv_sec % amount_to_slow); (*tp).tv_nsec = (*tp).tv_nsec / amount_to_slow + nsec_part; (*tp).tv_sec = (*tp).tv_sec / amount_to_slow; } ret } }