mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Ensure userspace allocation is 8-byte aligned
This commit is contained in:
committed by
Mark Rousskov
parent
b5d842f65c
commit
36e6ca7d11
@@ -2,6 +2,7 @@
|
||||
|
||||
use crate::arch::asm;
|
||||
use crate::cell::UnsafeCell;
|
||||
use crate::cmp;
|
||||
use crate::convert::TryInto;
|
||||
use crate::mem;
|
||||
use crate::ops::{CoerceUnsized, Deref, DerefMut, Index, IndexMut};
|
||||
@@ -212,7 +213,9 @@ fn new_uninit_bytes(size: usize) -> Self {
|
||||
unsafe {
|
||||
// Mustn't call alloc with size 0.
|
||||
let ptr = if size > 0 {
|
||||
rtunwrap!(Ok, super::alloc(size, T::align_of())) as _
|
||||
// `copy_to_userspace` is more efficient when data is 8-byte aligned
|
||||
let alignment = cmp::max(T::align_of(), 8);
|
||||
rtunwrap!(Ok, super::alloc(size, alignment)) as _
|
||||
} else {
|
||||
T::align_of() as _ // dangling pointer ok for size 0
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user