about summary refs log tree commit diff
path: root/src/liballoc_jemalloc
diff options
context:
space:
mode:
authorgnzlbg <gonzalobg88@gmail.com>2017-10-25 10:22:24 +0200
committergnzlbg <gonzalobg88@gmail.com>2017-10-25 14:18:20 +0200
commitd16c140b7cd014f03064f6f66f35baaa0b9cb7ce (patch)
treee7e7c707bb6157bff2b502f52676ea6b7c59ba2d /src/liballoc_jemalloc
parent6c0d50f9fabe78fa8497041c14ce73787a4aef87 (diff)
downloadrust-d16c140b7cd014f03064f6f66f35baaa0b9cb7ce.tar.gz
rust-d16c140b7cd014f03064f6f66f35baaa0b9cb7ce.zip
[jemalloc] set correct excess in realloc_excess
Diffstat (limited to 'src/liballoc_jemalloc')
-rw-r--r--src/liballoc_jemalloc/lib.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/liballoc_jemalloc/lib.rs b/src/liballoc_jemalloc/lib.rs
index d153f19c462..a1401e65f38 100644
--- a/src/liballoc_jemalloc/lib.rs
+++ b/src/liballoc_jemalloc/lib.rs
@@ -67,6 +67,10 @@ mod contents {
                        target_os = "dragonfly", target_os = "windows", target_env = "musl"),
                    link_name = "je_nallocx")]
         fn nallocx(size: size_t, flags: c_int) -> size_t;
+        #[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios",
+                       target_os = "dragonfly", target_os = "windows", target_env = "musl"),
+                   link_name = "je_sallocx")]
+        fn sallocx(ptr: *mut c_void, flags: c_int) -> size_t;
     }
 
     const MALLOCX_ZERO: c_int = 0x40;
@@ -211,17 +215,28 @@ mod contents {
     #[no_mangle]
     #[linkage = "external"]
     pub unsafe extern fn __rde_realloc_excess(ptr: *mut u8,
-                                              old_size: usize,
+                                              _old_size: usize,
                                               old_align: usize,
                                               new_size: usize,
                                               new_align: usize,
                                               excess: *mut usize,
                                               err: *mut u8) -> *mut u8 {
-        let p = __rde_realloc(ptr, old_size, old_align, new_size, new_align, err);
-        if !p.is_null() {
-            *excess = new_size;
+        if new_align != old_align {
+            ptr::write(err as *mut AllocErr,
+                       AllocErr::Unsupported { details: "can't change alignments" });
+            return 0 as *mut u8
         }
-        return p
+
+        let flags = align_to_flags(new_align);
+        let ptr = rallocx(ptr as *mut c_void, new_size, flags) as usize;
+        let alloc_size = sallocx(ptr as *mut c_void, flags);
+        if ptr.is_null() {
+            let layout = Layout::from_size_align_unchecked(new_size, new_align);
+            ptr::write(err as *mut AllocErr,
+                       AllocErr::Exhausted { request: layout });
+        }
+        *excess = alloc_size;
+        ptr
     }
 
     #[no_mangle]