about summary refs log tree commit diff
path: root/src/liballoc_system
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2018-04-02 11:06:19 +0900
committerMike Hommey <mh@glandium.org>2018-04-02 12:29:23 +0900
commit98175a8793942a60bce944050ba4fcb1cd067055 (patch)
tree23383cdb4799a0fdc37daf312b5b7fac31d06d65 /src/liballoc_system
parent06fa27d7c84a21af8449e06f3c50b243c4d5a7ad (diff)
downloadrust-98175a8793942a60bce944050ba4fcb1cd067055.tar.gz
rust-98175a8793942a60bce944050ba4fcb1cd067055.zip
Reject huge alignments on macos with system allocator only
ef8804ba277b055fdc3e6d148e680e3c1b597ad8 addressed #30170 by rejecting
huge alignments at the allocator API level, transforming a specific
platform bug/limitation into an enforced API limitation on all
platforms.

This change essentially reverts that commit, and instead makes alloc()
itself return AllocErr::Unsupported when receiving huge alignments.

This was discussed in https://github.com/rust-lang/rust/issues/32838#issuecomment-368348408
and following.
Diffstat (limited to 'src/liballoc_system')
-rw-r--r--src/liballoc_system/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs
index 1d5e7b73be5..1175aafb4a3 100644
--- a/src/liballoc_system/lib.rs
+++ b/src/liballoc_system/lib.rs
@@ -134,6 +134,14 @@ mod platform {
             let ptr = if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
                 libc::malloc(layout.size()) as *mut u8
             } else {
+                #[cfg(target_os = "macos")]
+                {
+                    if layout.align() > (1 << 31) {
+                        return Err(AllocErr::Unsupported {
+                            details: "requested alignment too large"
+                        })
+                    }
+                }
                 aligned_malloc(&layout)
             };
             if !ptr.is_null() {