From 428bb164f33951e561a1eed8e636077ad6ce2506 Mon Sep 17 00:00:00 2001 From: Sebastian Wicki Date: Tue, 22 Sep 2015 11:48:00 +0200 Subject: [PATCH] Fix alignment of pthread types on NetBSD --- src/libstd/sys/unix/sync.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/libstd/sys/unix/sync.rs b/src/libstd/sys/unix/sync.rs index aabeb41a369d2..954bfbb6b18b7 100644 --- a/src/libstd/sys/unix/sync.rs +++ b/src/libstd/sys/unix/sync.rs @@ -254,53 +254,61 @@ mod os { mod os { use libc; - // size of the type minus width of the magic int field + // size of the type minus width of the magic and alignment field #[cfg(target_arch = "x86_64")] - const __PTHREAD_MUTEX_SIZE__: usize = 48 - 4; + const __PTHREAD_MUTEX_SIZE__: usize = 48 - 4 - 8; #[cfg(target_arch = "x86_64")] - const __PTHREAD_COND_SIZE__: usize = 40 - 4; + const __PTHREAD_MUTEXATTR_SIZE__: usize = 16 - 8; // no magic field #[cfg(target_arch = "x86_64")] - const __PTHREAD_RWLOCK_SIZE__: usize = 64 - 4; + const __PTHREAD_COND_SIZE__: usize = 40 - 4 - 8; + + #[cfg(target_arch = "x86_64")] + const __PTHREAD_RWLOCK_SIZE__: usize = 64 - 4 - 8; const _PTHREAD_MUTEX_MAGIC_INIT: libc::c_uint = 0x33330003; const _PTHREAD_COND_MAGIC_INIT: libc::c_uint = 0x55550005; const _PTHREAD_RWLOCK_MAGIC_INIT: libc::c_uint = 0x99990009; - // note the actual structs are smaller - - #[repr(C, packed)] + #[repr(C)] pub struct pthread_mutex_t { __magic: libc::c_uint, __opaque: [u8; __PTHREAD_MUTEX_SIZE__], + __align: libc::c_longlong, } - #[repr(C, packed)] + #[repr(C)] pub struct pthread_mutexattr_t { - __opaque: [u8; 16], + __opaque: [u8; __PTHREAD_MUTEXATTR_SIZE__], + __align: libc::c_longlong, } - #[repr(C, packed)] + #[repr(C)] pub struct pthread_cond_t { __magic: libc::c_uint, __opaque: [u8; __PTHREAD_COND_SIZE__], + __align: libc::c_longlong, } - #[repr(C, packed)] + #[repr(C)] pub struct pthread_rwlock_t { __magic: libc::c_uint, __opaque: [u8; __PTHREAD_RWLOCK_SIZE__], + __align: libc::c_longlong, } pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __magic: _PTHREAD_MUTEX_MAGIC_INIT, __opaque: [0; __PTHREAD_MUTEX_SIZE__], + __align: 0, }; pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { __magic: _PTHREAD_COND_MAGIC_INIT, __opaque: [0; __PTHREAD_COND_SIZE__], + __align: 0, }; pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { __magic: _PTHREAD_RWLOCK_MAGIC_INIT, __opaque: [0; __PTHREAD_RWLOCK_SIZE__], + __align: 0, }; pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2;