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