linux_syscalls/env/vdso/
riscv.rs1use 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 rt_sigreturn(&self) -> *const core::ffi::c_void {
17 self.0.rt_sigreturn
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 clock_gettime(&self) -> *const core::ffi::c_void {
27 self.0.clock_gettime
28 }
29
30 #[inline]
31 pub fn clock_getres(&self) -> *const core::ffi::c_void {
32 self.0.clock_getres
33 }
34
35 #[inline]
36 pub fn getcpu(&self) -> *const core::ffi::c_void {
37 self.0.getcpu
38 }
39
40 #[inline]
41 pub fn flush_icache(&self) -> *const core::ffi::c_void {
42 self.0.flush_icache
43 }
44}
45
46pub(crate) static mut VDSO: UnsafeCell<Vdso> = UnsafeCell::new(Vdso(RawVdso {
47 rt_sigreturn: core::ptr::null(),
48 gettimeofday: core::ptr::null(),
49 clock_gettime: core::ptr::null(),
50 clock_getres: core::ptr::null(),
51 getcpu: core::ptr::null(),
52 flush_icache: core::ptr::null(),
53}));
54
55pub(crate) unsafe fn init() {
56 if let Some(vdso) =
57 crate::env::aux::get::<SysInfoHeader>().and_then(|info| unsafe { RawVdso::from_ptr(info) })
58 {
59 (*VDSO.get()).0 = vdso;
60 }
61}