@@ -20,6 +20,30 @@ cfg_if::cfg_if! {
20
20
}
21
21
}
22
22
23
+ // Android with api less than 21 define sig* functions inline, so it is not
24
+ // available for dynamic link. Implementing sigemptyset and sigaddset allow us
25
+ // to support older Android version (independent of libc version).
26
+ // The following implementations are based on https://git.io/vSkNf
27
+ cfg_if::cfg_if! {
28
+ if #[cfg(target_os = "android")] {
29
+ pub unsafe fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int {
30
+ set.write_bytes(0u8, 1);
31
+ return 0;
32
+ }
33
+ #[allow(dead_code)]
34
+ pub unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int {
35
+ use crate::{slice, mem};
36
+
37
+ let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::<libc::sigset_t>());
38
+ let bit = (signum - 1) as usize;
39
+ raw[bit / 8] |= 1 << (bit % 8);
40
+ return 0;
41
+ }
42
+ } else {
43
+ pub use libc::{sigemptyset, sigaddset};
44
+ }
45
+ }
46
+
23
47
////////////////////////////////////////////////////////////////////////////////
24
48
// Command
25
49
////////////////////////////////////////////////////////////////////////////////
@@ -429,36 +453,6 @@ mod tests {
429
453
}
430
454
}
431
455
432
- // Android with api less than 21 define sig* functions inline, so it is not
433
- // available for dynamic link. Implementing sigemptyset and sigaddset allow us
434
- // to support older Android version (independent of libc version).
435
- // The following implementations are based on https://git.io/vSkNf
436
-
437
- #[cfg(not(target_os = "android"))]
438
- extern {
439
- #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
440
- fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int;
441
-
442
- #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
443
- fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int;
444
- }
445
-
446
- #[cfg(target_os = "android")]
447
- unsafe fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int {
448
- set.write_bytes(0u8, 1);
449
- return 0;
450
- }
451
-
452
- #[cfg(target_os = "android")]
453
- unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int {
454
- use crate::slice;
455
-
456
- let raw = slice::from_raw_parts_mut(set as *mut u8, mem::size_of::<libc::sigset_t>());
457
- let bit = (signum - 1) as usize;
458
- raw[bit / 8] |= 1 << (bit % 8);
459
- return 0;
460
- }
461
-
462
456
// See #14232 for more information, but it appears that signal delivery to a
463
457
// newly spawned process may just be raced in the macOS, so to prevent this
464
458
// test from being flaky we ignore it on macOS.
0 commit comments