about summary refs log tree commit diff
path: root/src/liballoc_system
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-04 03:48:22 +0000
committerbors <bors@rust-lang.org>2018-04-04 03:48:22 +0000
commit20338a52401bda3024fd91010a143913a8dc9a6c (patch)
treeae228154da10f194280f1efe3994b7a73ec4b792 /src/liballoc_system
parent199b7e211d6d9173fded261e0a4de984efc0c2eb (diff)
parent98175a8793942a60bce944050ba4fcb1cd067055 (diff)
downloadrust-20338a52401bda3024fd91010a143913a8dc9a6c.tar.gz
rust-20338a52401bda3024fd91010a143913a8dc9a6c.zip
Auto merge of #49573 - glandium:huge-align, r=SimonSapin
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 6c1e9cb0b9c..d4404e564e0 100644
--- a/src/liballoc_system/lib.rs
+++ b/src/liballoc_system/lib.rs
@@ -131,6 +131,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() {