@@ -67,6 +67,10 @@ mod contents {
6767 target_os = "dragonfly" , target_os = "windows" , target_env = "musl" ) ,
6868 link_name = "je_nallocx" ) ]
6969 fn nallocx ( size : size_t , flags : c_int ) -> size_t ;
70+ #[ cfg_attr( any( target_os = "macos" , target_os = "android" , target_os = "ios" ,
71+ target_os = "dragonfly" , target_os = "windows" , target_env = "musl" ) ,
72+ link_name = "je_sallocx" ) ]
73+ fn sallocx ( ptr : * mut c_void , flags : c_int ) -> size_t ;
7074 }
7175
7276 const MALLOCX_ZERO : c_int = 0x40 ;
@@ -211,17 +215,28 @@ mod contents {
211215 #[ no_mangle]
212216 #[ linkage = "external" ]
213217 pub unsafe extern fn __rde_realloc_excess ( ptr : * mut u8 ,
214- old_size : usize ,
218+ _old_size : usize ,
215219 old_align : usize ,
216220 new_size : usize ,
217221 new_align : usize ,
218222 excess : * mut usize ,
219223 err : * mut u8 ) -> * mut u8 {
220- let p = __rde_realloc ( ptr, old_size, old_align, new_size, new_align, err) ;
221- if !p. is_null ( ) {
222- * excess = new_size;
224+ if new_align != old_align {
225+ ptr:: write ( err as * mut AllocErr ,
226+ AllocErr :: Unsupported { details : "can't change alignments" } ) ;
227+ return 0 as * mut u8
223228 }
224- return p
229+
230+ let flags = align_to_flags ( new_align) ;
231+ let ptr = rallocx ( ptr as * mut c_void , new_size, flags) as usize ;
232+ let alloc_size = sallocx ( ptr as * mut c_void , flags) ;
233+ if ptr. is_null ( ) {
234+ let layout = Layout :: from_size_align_unchecked ( new_size, new_align) ;
235+ ptr:: write ( err as * mut AllocErr ,
236+ AllocErr :: Exhausted { request : layout } ) ;
237+ }
238+ * excess = alloc_size;
239+ ptr
225240 }
226241
227242 #[ no_mangle]
0 commit comments