]> git.lizzy.rs Git - rust.git/blobdiff - src/liballoc_jemalloc/lib.rs
std: Stop prefixing jemalloc symbols
[rust.git] / src / liballoc_jemalloc / lib.rs
index 2c46e37ac32b20e7aa7efe7c83975c8f1da58990..bda001eb4f426fbac09f0de84a7eeeb01ec62542 100644 (file)
 #[cfg(not(cargobuild))]
 extern {}
 
+// Note that the symbols here are prefixed by default on OSX (we don't
+// explicitly request it), and on Android we explicitly request it as
+// unprefixing cause segfaults (mismatches in allocators).
 extern {
-    fn je_mallocx(size: size_t, flags: c_int) -> *mut c_void;
-    fn je_rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
-    fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
-    fn je_sdallocx(ptr: *mut c_void, size: size_t, flags: c_int);
-    fn je_nallocx(size: size_t, flags: c_int) -> size_t;
+    #[cfg_attr(any(target_os = "macos", target_os = "android"),
+               link_name = "je_mallocx")]
+    fn mallocx(size: size_t, flags: c_int) -> *mut c_void;
+    #[cfg_attr(any(target_os = "macos", target_os = "android"),
+               link_name = "je_rallocx")]
+    fn rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
+    #[cfg_attr(any(target_os = "macos", target_os = "android"),
+               link_name = "je_xallocx")]
+    fn xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;
+    #[cfg_attr(any(target_os = "macos", target_os = "android"),
+               link_name = "je_sdallocx")]
+    fn sdallocx(ptr: *mut c_void, size: size_t, flags: c_int);
+    #[cfg_attr(any(target_os = "macos", target_os = "android"),
+               link_name = "je_nallocx")]
+    fn nallocx(size: size_t, flags: c_int) -> size_t;
 }
 
 // The minimum alignment guaranteed by the architecture. This value is used to
@@ -78,7 +91,7 @@ fn align_to_flags(align: usize) -> c_int {
 #[no_mangle]
 pub extern "C" fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
     let flags = align_to_flags(align);
-    unsafe { je_mallocx(size as size_t, flags) as *mut u8 }
+    unsafe { mallocx(size as size_t, flags) as *mut u8 }
 }
 
 #[no_mangle]
@@ -88,7 +101,7 @@ pub extern "C" fn __rust_reallocate(ptr: *mut u8,
                                     align: usize)
                                     -> *mut u8 {
     let flags = align_to_flags(align);
-    unsafe { je_rallocx(ptr as *mut c_void, size as size_t, flags) as *mut u8 }
+    unsafe { rallocx(ptr as *mut c_void, size as size_t, flags) as *mut u8 }
 }
 
 #[no_mangle]
@@ -98,19 +111,19 @@ pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
                                             align: usize)
                                             -> usize {
     let flags = align_to_flags(align);
-    unsafe { je_xallocx(ptr as *mut c_void, size as size_t, 0, flags) as usize }
+    unsafe { xallocx(ptr as *mut c_void, size as size_t, 0, flags) as usize }
 }
 
 #[no_mangle]
 pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
     let flags = align_to_flags(align);
-    unsafe { je_sdallocx(ptr as *mut c_void, old_size as size_t, flags) }
+    unsafe { sdallocx(ptr as *mut c_void, old_size as size_t, flags) }
 }
 
 #[no_mangle]
 pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
     let flags = align_to_flags(align);
-    unsafe { je_nallocx(size as size_t, flags) as usize }
+    unsafe { nallocx(size as size_t, flags) as usize }
 }
 
 // These symbols are used by jemalloc on android but the really old android