about summary refs log tree commit diff
path: root/library/std/src/sys/unix/alloc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/unix/alloc.rs')
-rw-r--r--library/std/src/sys/unix/alloc.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/alloc.rs b/library/std/src/sys/unix/alloc.rs
index 9d6567c9fb4..af0089978ec 100644
--- a/library/std/src/sys/unix/alloc.rs
+++ b/library/std/src/sys/unix/alloc.rs
@@ -59,7 +59,8 @@ cfg_if::cfg_if! {
         target_os = "redox",
         target_os = "solaris",
         target_os = "espidf",
-        target_os = "horizon"
+        target_os = "horizon",
+        target_os = "vita",
     ))] {
         #[inline]
         unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
@@ -85,7 +86,11 @@ cfg_if::cfg_if! {
     } else if #[cfg(target_os = "wasi")] {
         #[inline]
         unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
-            libc::aligned_alloc(layout.align(), layout.size()) as *mut u8
+            // C11 aligned_alloc requires that the size be a multiple of the alignment.
+            // Layout already checks that the size rounded up doesn't overflow isize::MAX.
+            let align = layout.align();
+            let size = layout.size().next_multiple_of(align);
+            libc::aligned_alloc(align, size) as *mut u8
         }
     } else {
         #[inline]