about summary refs log tree commit diff
path: root/library/std/src/sys/sgx
diff options
context:
space:
mode:
authorRaoul Strackx <raoul.strackx@fortanix.com>2022-03-23 10:03:00 +0100
committerRaoul Strackx <raoul.strackx@fortanix.com>2022-06-15 11:06:48 +0200
commit6f7d1937e20edf00ea2b5d7c2c8ce2dab2830452 (patch)
tree7063246cdd6cce51d1b5bfd92d904e92189ca718 /library/std/src/sys/sgx
parent531752f39ab662a73e7ab580bf8a06c6bfeef486 (diff)
downloadrust-6f7d1937e20edf00ea2b5d7c2c8ce2dab2830452.tar.gz
rust-6f7d1937e20edf00ea2b5d7c2c8ce2dab2830452.zip
Ensure userspace allocation is 8-byte aligned
Diffstat (limited to 'library/std/src/sys/sgx')
-rw-r--r--library/std/src/sys/sgx/abi/usercalls/alloc.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/library/std/src/sys/sgx/abi/usercalls/alloc.rs b/library/std/src/sys/sgx/abi/usercalls/alloc.rs
index b37e9b257ed..4c1f279857f 100644
--- a/library/std/src/sys/sgx/abi/usercalls/alloc.rs
+++ b/library/std/src/sys/sgx/abi/usercalls/alloc.rs
@@ -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 @@ where
         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
             };