@@ -41,12 +41,25 @@ use libc::{c_int, c_void, size_t};
41
41
#[ cfg( not( cargobuild) ) ]
42
42
extern { }
43
43
44
+ // Note that the symbols here are prefixed by default on OSX (we don't
45
+ // explicitly request it), and on Android we explicitly request it as
46
+ // unprefixing cause segfaults (mismatches in allocators).
44
47
extern {
45
- fn je_mallocx ( size : size_t , flags : c_int ) -> * mut c_void ;
46
- fn je_rallocx ( ptr : * mut c_void , size : size_t , flags : c_int ) -> * mut c_void ;
47
- fn je_xallocx ( ptr : * mut c_void , size : size_t , extra : size_t , flags : c_int ) -> size_t ;
48
- fn je_sdallocx ( ptr : * mut c_void , size : size_t , flags : c_int ) ;
49
- fn je_nallocx ( size : size_t , flags : c_int ) -> size_t ;
48
+ #[ cfg_attr( any( target_os = "macos" , target_os = "android" ) ,
49
+ link_name = "je_mallocx" ) ]
50
+ fn mallocx ( size : size_t , flags : c_int ) -> * mut c_void ;
51
+ #[ cfg_attr( any( target_os = "macos" , target_os = "android" ) ,
52
+ link_name = "je_rallocx" ) ]
53
+ fn rallocx ( ptr : * mut c_void , size : size_t , flags : c_int ) -> * mut c_void ;
54
+ #[ cfg_attr( any( target_os = "macos" , target_os = "android" ) ,
55
+ link_name = "je_xallocx" ) ]
56
+ fn xallocx ( ptr : * mut c_void , size : size_t , extra : size_t , flags : c_int ) -> size_t ;
57
+ #[ cfg_attr( any( target_os = "macos" , target_os = "android" ) ,
58
+ link_name = "je_sdallocx" ) ]
59
+ fn sdallocx ( ptr : * mut c_void , size : size_t , flags : c_int ) ;
60
+ #[ cfg_attr( any( target_os = "macos" , target_os = "android" ) ,
61
+ link_name = "je_nallocx" ) ]
62
+ fn nallocx ( size : size_t , flags : c_int ) -> size_t ;
50
63
}
51
64
52
65
// The minimum alignment guaranteed by the architecture. This value is used to
@@ -78,7 +91,7 @@ fn align_to_flags(align: usize) -> c_int {
78
91
#[ no_mangle]
79
92
pub extern "C" fn __rust_allocate ( size : usize , align : usize ) -> * mut u8 {
80
93
let flags = align_to_flags ( align) ;
81
- unsafe { je_mallocx ( size as size_t , flags) as * mut u8 }
94
+ unsafe { mallocx ( size as size_t , flags) as * mut u8 }
82
95
}
83
96
84
97
#[ no_mangle]
@@ -88,7 +101,7 @@ pub extern "C" fn __rust_reallocate(ptr: *mut u8,
88
101
align : usize )
89
102
-> * mut u8 {
90
103
let flags = align_to_flags ( align) ;
91
- unsafe { je_rallocx ( ptr as * mut c_void , size as size_t , flags) as * mut u8 }
104
+ unsafe { rallocx ( ptr as * mut c_void , size as size_t , flags) as * mut u8 }
92
105
}
93
106
94
107
#[ no_mangle]
@@ -98,19 +111,19 @@ pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
98
111
align : usize )
99
112
-> usize {
100
113
let flags = align_to_flags ( align) ;
101
- unsafe { je_xallocx ( ptr as * mut c_void , size as size_t , 0 , flags) as usize }
114
+ unsafe { xallocx ( ptr as * mut c_void , size as size_t , 0 , flags) as usize }
102
115
}
103
116
104
117
#[ no_mangle]
105
118
pub extern "C" fn __rust_deallocate ( ptr : * mut u8 , old_size : usize , align : usize ) {
106
119
let flags = align_to_flags ( align) ;
107
- unsafe { je_sdallocx ( ptr as * mut c_void , old_size as size_t , flags) }
120
+ unsafe { sdallocx ( ptr as * mut c_void , old_size as size_t , flags) }
108
121
}
109
122
110
123
#[ no_mangle]
111
124
pub extern "C" fn __rust_usable_size ( size : usize , align : usize ) -> usize {
112
125
let flags = align_to_flags ( align) ;
113
- unsafe { je_nallocx ( size as size_t , flags) as usize }
126
+ unsafe { nallocx ( size as size_t , flags) as usize }
114
127
}
115
128
116
129
// These symbols are used by jemalloc on android but the really old android
0 commit comments