1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pub use self::arch::*;
#[cfg(not(target_os = "macos"))]
pub mod arch {
extern {
#[linkage = "extern_weak"]
static __dso_handle: *mut u8;
#[linkage = "extern_weak"]
static __cxa_thread_atexit_impl: *const u8;
}
pub fn register(t: *mut u8, dtor: unsafe extern fn(*mut u8)) {
use core::mem;
type Dtor = unsafe extern fn(dtor: unsafe extern fn(*mut u8), arg: *mut u8, dso_handle: *mut u8) -> i32;
assert!(!__cxa_thread_atexit_impl.is_null());
unsafe {
mem::transmute::<*const u8, Dtor>(__cxa_thread_atexit_impl)
(dtor, t, &__dso_handle as *const _ as *mut _)
};
}
}
#[cfg(target_os = "macos")]
pub mod arch {
extern {
fn _tlv_atexit(dtor: unsafe extern fn(*mut u8), arg: *mut u8);
}
pub fn register(t: *mut u8, dtor: unsafe extern fn(*mut u8)) {
_tlv_atexit(dtor, t);
}
}