1 #[cfg(not(target_env = "musl"))] 2 use crate::errno::Errno; 3 use crate::sys::signal::SigSet; 4 #[cfg(not(target_env = "musl"))] 5 use crate::Result; 6 #[cfg(not(target_env = "musl"))] 7 use std::mem; 8 9 #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] 10 pub struct UContext { 11 context: libc::ucontext_t, 12 } 13 14 impl UContext { 15 #[cfg(not(target_env = "musl"))] get() -> Result<UContext>16 pub fn get() -> Result<UContext> { 17 let mut context = mem::MaybeUninit::<libc::ucontext_t>::uninit(); 18 let res = unsafe { libc::getcontext(context.as_mut_ptr()) }; 19 Errno::result(res).map(|_| unsafe { 20 UContext { 21 context: context.assume_init(), 22 } 23 }) 24 } 25 26 #[cfg(not(target_env = "musl"))] set(&self) -> Result<()>27 pub fn set(&self) -> Result<()> { 28 let res = unsafe { 29 libc::setcontext(&self.context as *const libc::ucontext_t) 30 }; 31 Errno::result(res).map(drop) 32 } 33 sigmask_mut(&mut self) -> &mut SigSet34 pub fn sigmask_mut(&mut self) -> &mut SigSet { 35 unsafe { 36 &mut *(&mut self.context.uc_sigmask as *mut libc::sigset_t 37 as *mut SigSet) 38 } 39 } 40 sigmask(&self) -> &SigSet41 pub fn sigmask(&self) -> &SigSet { 42 unsafe { 43 &*(&self.context.uc_sigmask as *const libc::sigset_t 44 as *const SigSet) 45 } 46 } 47 } 48