Stage #[repr(packed)] in std::rt

This commit is contained in:
Corey Richardson 2014-08-15 01:47:28 -04:00
parent cf5d28083d
commit 21bd17fcc1
3 changed files with 40 additions and 8 deletions

View File

@ -166,16 +166,16 @@ fn new_regs() -> Box<Registers> {
#[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
}

View File

@ -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;
}

View File

@ -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,