Skip to content

Commit 6f7d193

Browse files
committed
Ensure userspace allocation is 8-byte aligned
1 parent 531752f commit 6f7d193

File tree

1 file changed

+4
-1
lines changed
  • library/std/src/sys/sgx/abi/usercalls

1 file changed

+4
-1
lines changed

library/std/src/sys/sgx/abi/usercalls/alloc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use crate::arch::asm;
44
use crate::cell::UnsafeCell;
5+
use crate::cmp;
56
use crate::convert::TryInto;
67
use crate::mem;
78
use crate::ops::{CoerceUnsized, Deref, DerefMut, Index, IndexMut};
@@ -212,7 +213,9 @@ where
212213
unsafe {
213214
// Mustn't call alloc with size 0.
214215
let ptr = if size > 0 {
215-
rtunwrap!(Ok, super::alloc(size, T::align_of())) as _
216+
// `copy_to_userspace` is more efficient when data is 8-byte aligned
217+
let alignment = cmp::max(T::align_of(), 8);
218+
rtunwrap!(Ok, super::alloc(size, alignment)) as _
216219
} else {
217220
T::align_of() as _ // dangling pointer ok for size 0
218221
};

0 commit comments

Comments
 (0)