@@ -41,12 +41,25 @@ use libc::{c_int, c_void, size_t};
4141#[ cfg( not( cargobuild) ) ]
4242extern { }
4343
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).
4447extern {
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 ;
5063}
5164
5265// The minimum alignment guaranteed by the architecture. This value is used to
@@ -78,7 +91,7 @@ fn align_to_flags(align: usize) -> c_int {
7891#[ no_mangle]
7992pub extern "C" fn __rust_allocate ( size : usize , align : usize ) -> * mut u8 {
8093 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 }
8295}
8396
8497#[ no_mangle]
@@ -88,7 +101,7 @@ pub extern "C" fn __rust_reallocate(ptr: *mut u8,
88101 align : usize )
89102 -> * mut u8 {
90103 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 }
92105}
93106
94107#[ no_mangle]
@@ -98,19 +111,19 @@ pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
98111 align : usize )
99112 -> usize {
100113 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 }
102115}
103116
104117#[ no_mangle]
105118pub extern "C" fn __rust_deallocate ( ptr : * mut u8 , old_size : usize , align : usize ) {
106119 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) }
108121}
109122
110123#[ no_mangle]
111124pub extern "C" fn __rust_usable_size ( size : usize , align : usize ) -> usize {
112125 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 }
114127}
115128
116129// These symbols are used by jemalloc on android but the really old android
0 commit comments