Skip to content

Commit 69769fb

Browse files
committedApr 17, 2018
Auto merge of #972 - gnzlbg:packed, r=alexcrichton
Fix undefined-behavior on MacOSX structs in stdbuilds Some MacOSX structs have an incorrect layout that results in undefined behavior. This is because on `x86_64` the MacOSX kernel headers define these using `#pragma pack 4`. This PR fixes their layout using `repr(packed(4))` . Since it is only available on nightly, it is only enabled for stdbuilds .
2 parents 735a5a9 + 77837a0 commit 69769fb

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed
 

‎.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ env:
2222
secure: "e2/3QjgRN9atOuSHp22TrYG7QVKcYUWY48Hi9b60w+r1+BhPkTseIJLte7WefRhdXtqpjjUJTooKDhnurFOeHaCT+nmBgiv+FPU893sBl4bhesY4m0vgUJVbNZcs6lTImYekWVb+aqjGdgV/XAgCw7c3kPmrZV0MzGDWL64Xaps="
2323
matrix:
2424
include:
25-
# 1.0.0 compat
25+
# 1.13.0 compat
2626
- env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1
27-
rust: 1.0.0
27+
rust: 1.13.0
2828
script: rm -f Cargo.lock && cargo build
2929
install:
3030

‎libc-test/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,9 @@ fn main() {
416416
// which is absent in glibc, has to be defined.
417417
"__timeval" if linux => true,
418418

419-
// The alignment of this is 4 on 64-bit OSX...
419+
// Fixed on stdbuild with repr(packed(4))
420+
// Once repr_packed stabilizes we can fix this unconditionally
421+
// and remove this check.
420422
"kevent" | "shmid_ds" if apple && x86_64 => true,
421423

422424
// This is actually a union, not a struct

‎src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
// Attributes needed when building as part of the standard library
8989
#![cfg_attr(feature = "stdbuild", feature(no_std, staged_api, custom_attribute, cfg_target_vendor))]
90-
#![cfg_attr(feature = "stdbuild", feature(link_cfg))]
90+
#![cfg_attr(feature = "stdbuild", feature(link_cfg, repr_packed))]
9191
#![cfg_attr(feature = "stdbuild", no_std)]
9292
#![cfg_attr(feature = "stdbuild", staged_api)]
9393
#![cfg_attr(feature = "stdbuild", allow(warnings))]

‎src/unix/bsd/apple/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ s! {
245245
pub f_reserved: [::uint32_t; 8],
246246
}
247247

248-
// FIXME: this should have align 4 but it's got align 8 on 64-bit
248+
#[cfg_attr(feature = "stdbuild", repr(packed(4)))]
249249
pub struct kevent {
250250
pub ident: ::uintptr_t,
251251
pub filter: ::int16_t,
@@ -524,7 +524,7 @@ s! {
524524
pub _key: ::key_t,
525525
}
526526

527-
// FIXME: this should have align 4 but it's got align 8 on 64-bit
527+
#[cfg_attr(feature = "stdbuild", repr(packed(4)))]
528528
pub struct shmid_ds {
529529
pub shm_perm: ipc_perm,
530530
pub shm_segsz: ::size_t,

0 commit comments

Comments
 (0)
Please sign in to comment.