linux_syscalls/env/vdso/
x86_64.rs

1use core::cell::UnsafeCell;
2
3use crate::env::aux::SysInfoHeader;
4
5pub use linux_raw_vdso::Vdso as RawVdso;
6
7#[non_exhaustive]
8#[repr(transparent)]
9pub struct Vdso(pub(crate) RawVdso);
10
11unsafe impl Send for Vdso {}
12unsafe impl Sync for Vdso {}
13
14impl Vdso {
15    #[inline]
16    pub fn clock_gettime(&self) -> *const core::ffi::c_void {
17        self.0.clock_gettime
18    }
19
20    #[inline]
21    pub fn gettimeofday(&self) -> *const core::ffi::c_void {
22        self.0.gettimeofday
23    }
24
25    #[inline]
26    pub fn time(&self) -> *const core::ffi::c_void {
27        self.0.time
28    }
29
30    #[inline]
31    pub fn getcpu(&self) -> *const core::ffi::c_void {
32        self.0.getcpu
33    }
34}
35
36pub(crate) static mut VDSO: UnsafeCell<Vdso> = UnsafeCell::new(Vdso(RawVdso {
37    clock_gettime: core::ptr::null(),
38    gettimeofday: core::ptr::null(),
39    time: core::ptr::null(),
40    getcpu: core::ptr::null(),
41}));
42
43pub(crate) unsafe fn init() {
44    if let Some(vdso) =
45        crate::env::aux::get::<SysInfoHeader>().and_then(|info| unsafe { RawVdso::from_ptr(info) })
46    {
47        (*VDSO.get()).0 = vdso;
48    }
49}