signal.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. use core::mem;
  2. use super::{
  3. super::{types::*, PalSignal},
  4. e, Sys,
  5. };
  6. use crate::header::{
  7. signal::{sigaction, sigset_t, stack_t},
  8. sys_time::itimerval,
  9. };
  10. impl PalSignal for Sys {
  11. fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
  12. e(unsafe { syscall!(GETITIMER, which, out) }) as c_int
  13. }
  14. fn kill(pid: pid_t, sig: c_int) -> c_int {
  15. e(unsafe { syscall!(KILL, pid, sig) }) as c_int
  16. }
  17. fn killpg(pgrp: pid_t, sig: c_int) -> c_int {
  18. e(unsafe { syscall!(KILL, -(pgrp as isize) as pid_t, sig) }) as c_int
  19. }
  20. fn raise(sig: c_int) -> c_int {
  21. let tid = e(unsafe { syscall!(GETTID) }) as pid_t;
  22. if tid == !0 {
  23. -1
  24. } else {
  25. e(unsafe { syscall!(TKILL, tid, sig) }) as c_int
  26. }
  27. }
  28. fn setitimer(which: c_int, new: *const itimerval, old: *mut itimerval) -> c_int {
  29. e(unsafe { syscall!(SETITIMER, which, new, old) }) as c_int
  30. }
  31. fn sigaction(sig: c_int, act: Option<&sigaction>, oact: Option<&mut sigaction>) -> c_int {
  32. e(unsafe {
  33. syscall!(
  34. RT_SIGACTION,
  35. sig,
  36. act.map_or_else(core::ptr::null, |x| x as *const _),
  37. oact.map_or_else(core::ptr::null_mut, |x| x as *mut _),
  38. mem::size_of::<sigset_t>()
  39. )
  40. }) as c_int
  41. }
  42. fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -> c_int {
  43. e(unsafe { syscall!(SIGALTSTACK, ss, old_ss) }) as c_int
  44. }
  45. fn sigprocmask(how: c_int, set: *const sigset_t, oset: *mut sigset_t) -> c_int {
  46. e(unsafe { syscall!(RT_SIGPROCMASK, how, set, oset, mem::size_of::<sigset_t>()) }) as c_int
  47. }
  48. }