Skip to content

Commit 21bd17f

Browse files
committed
Stage #[repr(packed)] in std::rt
1 parent cf5d280 commit 21bd17f

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

src/libgreen/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ fn new_regs() -> Box<Registers> {
166166

167167
#[cfg(target_arch = "x86")]
168168
fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
169-
procedure: raw::Procedure, sp: *mut libc::uintptr_t) {
170-
169+
procedure: raw::Procedure, sp: *mut uint) {
170+
let sp = sp as *mut uint;
171171
// x86 has interesting stack alignment requirements, so do some alignment
172172
// plus some offsetting to figure out what the actual stack should be.
173173
let sp = align_down(sp);
174174
let sp = mut_offset(sp, -4);
175175

176-
unsafe { *mut_offset(sp, 2) = procedure.env as libc::uintptr_t };
177-
unsafe { *mut_offset(sp, 1) = procedure.code as libc::uintptr_t };
178-
unsafe { *mut_offset(sp, 0) = arg as libc::uintptr_t };
176+
unsafe { *mut_offset(sp, 2) = procedure.env as uint };
177+
unsafe { *mut_offset(sp, 1) = procedure.code as uint };
178+
unsafe { *mut_offset(sp, 0) = arg as uint };
179179
let sp = mut_offset(sp, -1);
180180
unsafe { *sp = 0 }; // The final return address
181181

@@ -316,7 +316,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: InitFn, arg: uint,
316316
}
317317

318318
fn align_down(sp: *mut uint) -> *mut uint {
319-
let sp = (sp as libc::uintptr_t) & !(16 - 1);
319+
let sp = (sp as uint) & !(16 - 1);
320320
sp as *mut uint
321321
}
322322

src/libgreen/stack.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ impl Stack {
6868

6969
// FIXME: Using the FFI to call a C macro. Slow
7070
stk.valgrind_id = unsafe {
71-
rust_valgrind_stack_register(stk.start() as *const libc::uintptr_t, stk.end() as *const libc::uintptr_t)
71+
rust_valgrind_stack_register(stk.start() as *const libc::uintptr_t,
72+
stk.end() as *const libc::uintptr_t)
7273
};
7374
return stk;
7475
}

src/libstd/rt/backtrace.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,8 @@ mod imp {
701701
static IMAGE_FILE_MACHINE_IA64: libc::DWORD = 0x0200;
702702
static IMAGE_FILE_MACHINE_AMD64: libc::DWORD = 0x8664;
703703

704-
#[repr(packed)]
704+
#[cfg(stage0)]
705+
#[packed]
705706
struct SYMBOL_INFO {
706707
SizeOfStruct: libc::c_ulong,
707708
TypeIndex: libc::c_ulong,
@@ -723,6 +724,30 @@ mod imp {
723724
Name: [libc::c_char, ..MAX_SYM_NAME],
724725
}
725726

727+
#[cfg(not(stage0))]
728+
#[repr(C, packed)]
729+
struct SYMBOL_INFO {
730+
SizeOfStruct: libc::c_ulong,
731+
TypeIndex: libc::c_ulong,
732+
Reserved: [u64, ..2],
733+
Index: libc::c_ulong,
734+
Size: libc::c_ulong,
735+
ModBase: u64,
736+
Flags: libc::c_ulong,
737+
Value: u64,
738+
Address: u64,
739+
Register: libc::c_ulong,
740+
Scope: libc::c_ulong,
741+
Tag: libc::c_ulong,
742+
NameLen: libc::c_ulong,
743+
MaxNameLen: libc::c_ulong,
744+
// note that windows has this as 1, but it basically just means that
745+
// the name is inline at the end of the struct. For us, we just bump
746+
// the struct size up to MAX_SYM_NAME.
747+
Name: [libc::c_char, ..MAX_SYM_NAME],
748+
}
749+
750+
726751
#[repr(C)]
727752
enum ADDRESS_MODE {
728753
AddrMode1616,
@@ -772,6 +797,7 @@ mod imp {
772797

773798
static MAXIMUM_SUPPORTED_EXTENSION: uint = 512;
774799

800+
#[repr(C)]
775801
pub struct CONTEXT {
776802
ContextFlags: libc::DWORD,
777803
Dr0: libc::DWORD,
@@ -800,6 +826,7 @@ mod imp {
800826
ExtendedRegisters: [u8, ..MAXIMUM_SUPPORTED_EXTENSION],
801827
}
802828

829+
#[repr(C)]
803830
pub struct FLOATING_SAVE_AREA {
804831
ControlWord: libc::DWORD,
805832
StatusWord: libc::DWORD,
@@ -829,6 +856,7 @@ mod imp {
829856
use libc::{c_longlong, c_ulonglong};
830857
use libc::types::os::arch::extra::{WORD, DWORD, DWORDLONG};
831858

859+
#[repr(C)]
832860
pub struct CONTEXT {
833861
P1Home: DWORDLONG,
834862
P2Home: DWORDLONG,
@@ -886,11 +914,13 @@ mod imp {
886914
LastExceptionFromRip: DWORDLONG,
887915
}
888916

917+
#[repr(C)]
889918
pub struct M128A {
890919
Low: c_ulonglong,
891920
High: c_longlong
892921
}
893922

923+
#[repr(C)]
894924
pub struct FLOATING_SAVE_AREA {
895925
_Dummy: [u8, ..512] // FIXME: Fill this out
896926
}
@@ -907,6 +937,7 @@ mod imp {
907937
}
908938
}
909939

940+
#[repr(C)]
910941
struct Cleanup {
911942
handle: libc::HANDLE,
912943
SymCleanup: SymCleanupFn,

0 commit comments

Comments
 (0)