Skip to content

Commit 62e09af

Browse files
committed
Auto merge of #3183 - ChrisDenton:align-stack-buffer, r=<try>
Use aligned `cmsghdr` structs `test_cmsg_nxthdr` Fixes #3181. I could find no reason for using unaligned structs in this test.
2 parents 82f6fd2 + 8a0ee82 commit 62e09af

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

libc-test/test/cmsg.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ mod t {
1111

1212
extern "C" {
1313
pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr;
14-
// see below
15-
#[cfg(not(target_arch = "sparc64"))]
1614
pub fn cmsg_nxthdr(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr;
1715
pub fn cmsg_space(length: c_uint) -> usize;
1816
pub fn cmsg_len(length: c_uint) -> usize;
@@ -51,28 +49,24 @@ mod t {
5149
}
5250
}
5351

54-
// Skip on sparc64
55-
// https://github.com/rust-lang/libc/issues/1239
56-
#[cfg(not(target_arch = "sparc64"))]
5752
#[test]
58-
// FIXME: This triggers alignment checks for pointer dereferences:
59-
// https://github.com/rust-lang/libc/issues/3181
60-
#[ignore]
6153
fn test_cmsg_nxthdr() {
6254
use std::ptr;
55+
// Stack alignment helper.
56+
// Note: on Sparc32, cmsghdr is 8 byte aligned.
57+
#[repr(align(8))]
58+
struct Align8<T>(T);
6359

64-
let mut buffer = [0u8; 256];
60+
let mut buffer = Align8([0_u8; 260]);
6561
let mut mhdr: msghdr = unsafe { mem::zeroed() };
6662
let pmhdr = &mhdr as *const msghdr;
6763
for start_ofs in 0..64 {
68-
let pcmsghdr = &mut buffer[start_ofs] as *mut u8 as *mut cmsghdr;
64+
let pcmsghdr = &mut buffer.0 as *mut u8 as *mut cmsghdr;
6965
mhdr.msg_control = pcmsghdr as *mut c_void;
7066
mhdr.msg_controllen = (160 - start_ofs) as _;
7167
for cmsg_len in 0..64 {
7268
for next_cmsg_len in 0..32 {
73-
for i in buffer[start_ofs..].iter_mut() {
74-
*i = 0;
75-
}
69+
buffer.0.fill(0);
7670
unsafe {
7771
(*pcmsghdr).cmsg_len = cmsg_len;
7872
let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr);

0 commit comments

Comments
 (0)