From 6e8ff999589a7b4c7f62f7128f3e028a7b3ea64f Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Mon, 26 May 2014 23:56:52 -0700 Subject: librustc: handle repr on structs, require it for ffi, unify with packed As of RFC 18, struct layout is undefined. Opting into a C-compatible struct layout is now down with #[repr(C)]. For consistency, specifying a packed layout is now also down with #[repr(packed)]. Both can be specified. To fix errors caused by this, just add #[repr(C)] to the structs, and change #[packed] to #[repr(packed)] Closes #14309 [breaking-change] --- src/libstd/rt/backtrace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd/rt') diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index a4491b2ab1d..5ef1286500c 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -701,7 +701,7 @@ mod imp { static IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200; static IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664; - #[packed] + #[repr(packed)] struct SYMBOL_INFO { SizeOfStruct: libc::c_ulong, TypeIndex: libc::c_ulong, -- cgit 1.4.1-3-g733a5 From 21bd17fcc12ac277ac34c0a92010070f0a861ae1 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Fri, 15 Aug 2014 01:47:28 -0400 Subject: Stage #[repr(packed)] in std::rt --- src/libgreen/context.rs | 12 ++++++------ src/libgreen/stack.rs | 3 ++- src/libstd/rt/backtrace.rs | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) (limited to 'src/libstd/rt') diff --git a/src/libgreen/context.rs b/src/libgreen/context.rs index dfed121b3ce..64537ea12d9 100644 --- a/src/libgreen/context.rs +++ b/src/libgreen/context.rs @@ -166,16 +166,16 @@ fn new_regs() -> Box { #[cfg(target_arch = "x86")] fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint, - procedure: raw::Procedure, sp: *mut libc::uintptr_t) { - + procedure: raw::Procedure, sp: *mut uint) { + let sp = sp as *mut uint; // x86 has interesting stack alignment requirements, so do some alignment // plus some offsetting to figure out what the actual stack should be. let sp = align_down(sp); let sp = mut_offset(sp, -4); - unsafe { *mut_offset(sp, 2) = procedure.env as libc::uintptr_t }; - unsafe { *mut_offset(sp, 1) = procedure.code as libc::uintptr_t }; - unsafe { *mut_offset(sp, 0) = arg as libc::uintptr_t }; + unsafe { *mut_offset(sp, 2) = procedure.env as uint }; + unsafe { *mut_offset(sp, 1) = procedure.code as uint }; + unsafe { *mut_offset(sp, 0) = arg as uint }; let sp = mut_offset(sp, -1); unsafe { *sp = 0 }; // The final return address @@ -316,7 +316,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint, } fn align_down(sp: *mut uint) -> *mut uint { - let sp = (sp as libc::uintptr_t) & !(16 - 1); + let sp = (sp as uint) & !(16 - 1); sp as *mut uint } diff --git a/src/libgreen/stack.rs b/src/libgreen/stack.rs index eea5105de8c..4673e7b3ba2 100644 --- a/src/libgreen/stack.rs +++ b/src/libgreen/stack.rs @@ -68,7 +68,8 @@ impl Stack { // FIXME: Using the FFI to call a C macro. Slow stk.valgrind_id = unsafe { - rust_valgrind_stack_register(stk.start() as *const libc::uintptr_t, stk.end() as *const libc::uintptr_t) + rust_valgrind_stack_register(stk.start() as *const libc::uintptr_t, + stk.end() as *const libc::uintptr_t) }; return stk; } diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 5ef1286500c..1b005f49b88 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -701,7 +701,8 @@ mod imp { static IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200; static IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664; - #[repr(packed)] + #[cfg(stage0)] + #[packed] struct SYMBOL_INFO { SizeOfStruct: libc::c_ulong, TypeIndex: libc::c_ulong, @@ -723,6 +724,30 @@ mod imp { Name: [libc::c_char, ..MAX_SYM_NAME], } + #[cfg(not(stage0))] + #[repr(C, packed)] + struct SYMBOL_INFO { + SizeOfStruct: libc::c_ulong, + TypeIndex: libc::c_ulong, + Reserved: [u64, ..2], + Index: libc::c_ulong, + Size: libc::c_ulong, + ModBase: u64, + Flags: libc::c_ulong, + Value: u64, + Address: u64, + Register: libc::c_ulong, + Scope: libc::c_ulong, + Tag: libc::c_ulong, + NameLen: libc::c_ulong, + MaxNameLen: libc::c_ulong, + // note that windows has this as 1, but it basically just means that + // the name is inline at the end of the struct. For us, we just bump + // the struct size up to MAX_SYM_NAME. + Name: [libc::c_char, ..MAX_SYM_NAME], + } + + #[repr(C)] enum ADDRESS_MODE { AddrMode1616, @@ -772,6 +797,7 @@ mod imp { static MAXIMUM_SUPPORTED_EXTENSION: uint = 512; + #[repr(C)] pub struct CONTEXT { ContextFlags: libc::DWORD, Dr0: libc::DWORD, @@ -800,6 +826,7 @@ mod imp { ExtendedRegisters: [u8, ..MAXIMUM_SUPPORTED_EXTENSION], } + #[repr(C)] pub struct FLOATING_SAVE_AREA { ControlWord: libc::DWORD, StatusWord: libc::DWORD, @@ -829,6 +856,7 @@ mod imp { use libc::{c_longlong, c_ulonglong}; use libc::types::os::arch::extra::{WORD, DWORD, DWORDLONG}; + #[repr(C)] pub struct CONTEXT { P1Home: DWORDLONG, P2Home: DWORDLONG, @@ -886,11 +914,13 @@ mod imp { LastExceptionFromRip: DWORDLONG, } + #[repr(C)] pub struct M128A { Low: c_ulonglong, High: c_longlong } + #[repr(C)] pub struct FLOATING_SAVE_AREA { _Dummy: [u8, ..512] // FIXME: Fill this out } @@ -907,6 +937,7 @@ mod imp { } } + #[repr(C)] struct Cleanup { handle: libc::HANDLE, SymCleanup: SymCleanupFn, -- cgit 1.4.1-3-g733a5