@@ -3,7 +3,6 @@ use std::str;
3
3
4
4
use rustc_middle:: ty:: layout:: LayoutOf ;
5
5
use rustc_span:: Symbol ;
6
- use rustc_target:: abi:: { Align , Size } ;
7
6
use rustc_target:: spec:: abi:: Abi ;
8
7
9
8
use crate :: shims:: alloc:: EvalContextExt as _;
@@ -304,38 +303,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
304
303
let align = this. read_target_usize ( align) ?;
305
304
let size = this. read_target_usize ( size) ?;
306
305
307
- // Alignment must be a power of 2, and "supported by the implementation".
308
- // We decide that "supported by the implementation" means that the
309
- // size must be a multiple of the alignment. (This restriction seems common
310
- // enough that it is stated on <https://en.cppreference.com/w/c/memory/aligned_alloc>
311
- // as a general rule, but the actual standard has no such rule.)
312
- // If any of these are violated, we have to return NULL.
313
- // All fundamental alignments must be supported.
314
- //
315
- // macOS and Illumos are buggy in that they require the alignment
316
- // to be at least the size of a pointer, so they do not support all fundamental
317
- // alignments. We do not emulate those platform bugs.
318
- //
319
- // Linux also sets errno to EINVAL, but that's non-standard behavior that we do not
320
- // emulate.
321
- // FreeBSD says some of these cases are UB but that's violating the C standard.
322
- // http://en.cppreference.com/w/cpp/memory/c/aligned_alloc
323
- // Linux: https://linux.die.net/man/3/aligned_alloc
324
- // FreeBSD: https://man.freebsd.org/cgi/man.cgi?query=aligned_alloc&apropos=0&sektion=3&manpath=FreeBSD+9-current&format=html
325
- match size. checked_rem ( align) {
326
- Some ( 0 ) if align. is_power_of_two ( ) => {
327
- let align = align. max ( this. malloc_align ( size) . bytes ( ) ) ;
328
- let ptr = this. allocate_ptr (
329
- Size :: from_bytes ( size) ,
330
- Align :: from_bytes ( align) . unwrap ( ) ,
331
- MiriMemoryKind :: C . into ( ) ,
332
- ) ?;
333
- this. write_pointer ( ptr, dest) ?;
334
- } ,
335
- _ => {
336
- this. write_null ( dest) ?;
337
- }
338
- }
306
+ let res = this. aligned_alloc ( align, size) ?;
307
+ this. write_pointer ( res, dest) ?;
339
308
}
340
309
341
310
// Dynamic symbol loading
0 commit comments