@@ -67,6 +67,10 @@ mod contents {
67
67
target_os = "dragonfly" , target_os = "windows" , target_env = "musl" ) ,
68
68
link_name = "je_nallocx" ) ]
69
69
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 ( size : size_t , flags : c_int ) -> size_t ;
70
74
}
71
75
72
76
const MALLOCX_ZERO : c_int = 0x40 ;
@@ -201,27 +205,47 @@ mod contents {
201
205
align : usize ,
202
206
excess : * mut usize ,
203
207
err : * mut u8 ) -> * mut u8 {
204
- let p = __rde_alloc ( size, align, err) ;
205
- if !p. is_null ( ) {
206
- * excess = size;
208
+ let flags = align_to_flags ( align) ;
209
+ let ptr = mallocx ( size as size_t , flags) as * mut u8 ;
210
+ if ptr. is_null ( ) {
211
+ let layout = Layout :: from_size_align_unchecked ( size, align) ;
212
+ ptr:: write ( err as * mut AllocErr ,
213
+ AllocErr :: Exhausted { request : layout } ) ;
214
+ } else {
215
+ * excess = sallocx ( size as size_t , flags) as usize ;
207
216
}
208
- return p
217
+ ptr
209
218
}
210
219
211
220
#[ no_mangle]
212
221
#[ linkage = "external" ]
213
222
pub unsafe extern fn __rde_realloc_excess ( ptr : * mut u8 ,
214
- old_size : usize ,
223
+ _old_size : usize ,
215
224
old_align : usize ,
216
225
new_size : usize ,
217
226
new_align : usize ,
218
227
excess : * mut usize ,
219
228
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;
229
+ if new_align != old_align {
230
+ ptr:: write (
231
+ err as * mut AllocErr ,
232
+ AllocErr :: Unsupported { details : "can't change alignments" } ,
233
+ ) ;
234
+ return 0 as * mut u8
223
235
}
224
- return p
236
+
237
+ let flags = align_to_flags ( new_align) ;
238
+ let ptr = rallocx ( ptr as * mut c_void , new_size as size_t , flags) as * mut u8 ;
239
+ if ptr. is_null ( ) {
240
+ let layout = Layout :: from_size_align_unchecked ( new_size, new_align) ;
241
+ ptr:: write (
242
+ err as * mut AllocErr ,
243
+ AllocErr :: Exhausted { request : layout } ,
244
+ ) ;
245
+ } else {
246
+ * excess = sallocx ( new_size as size_t , flags) as usize ;
247
+ }
248
+ ptr
225
249
}
226
250
227
251
#[ no_mangle]
0 commit comments