Skip to content

Commit 6d09f2c

Browse files
committed
windows adding CONTEXT type for x86_64 arch.
1 parent 1ac780a commit 6d09f2c

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

libc-test/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ fn test_windows(target: &str) {
539539
let gnu = target.contains("gnu");
540540

541541
let mut cfg = ctest_cfg();
542+
if target.contains("msvc") {
543+
cfg.flag("/wd4324");
544+
}
542545
cfg.define("_WIN32_WINNT", Some("0x8000"));
543546

544547
headers! { cfg:
@@ -603,6 +606,13 @@ fn test_windows(target: &str) {
603606
_ => false,
604607
});
605608

609+
cfg.skip_struct(move |ty| {
610+
if ty.starts_with("__c_anonymous_") {
611+
return true;
612+
}
613+
return false;
614+
});
615+
606616
cfg.skip_const(move |name| {
607617
match name {
608618
// FIXME: API error:
@@ -616,6 +626,10 @@ fn test_windows(target: &str) {
616626
}
617627
});
618628

629+
cfg.skip_field(move |s, field| match s {
630+
"CONTEXT" if field == "Fp" => true,
631+
_ => false,
632+
});
619633
// FIXME: All functions point to the wrong addresses?
620634
cfg.skip_fn_ptrcheck(|_| true);
621635

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONTEXT

src/windows/msvc.rs renamed to src/windows/msvc/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ extern "C" {
1111
#[link_name = "_strnicmp"]
1212
pub fn strnicmp(s1: *const ::c_char, s2: *const ::c_char, n: ::size_t) -> ::c_int;
1313
}
14+
15+
cfg_if! {
16+
if #[cfg(target_arch = "x86_64")] {
17+
mod x86_64;
18+
pub use self::x86_64::*;
19+
} else {
20+
// Unknown target_arch
21+
}
22+
}

src/windows/msvc/x86_64.rs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
pub type XMM_SAVE_AREA32 = XSAVE_FORMAT;
2+
3+
s_no_extra_traits! {
4+
#[repr(align(16))]
5+
pub union __c_anonymous_CONTEXT_FP {
6+
pub FltSave: ::XMM_SAVE_AREA32,
7+
pub Xmm: __c_anonymous_CONTEXT_XMM,
8+
}
9+
}
10+
11+
cfg_if! {
12+
if #[cfg(feature = "extra_traits")] {
13+
impl PartialEq for __c_anonymous_CONTEXT_FP {
14+
fn eq(&self, other: &__c_anonymous_CONTEXT_FP) -> bool {
15+
unsafe {
16+
self.FltSave == other.FltSave ||
17+
self.Xmm == other.Xmm
18+
}
19+
}
20+
}
21+
impl Eq for __c_anonymous_CONTEXT_FP {}
22+
impl ::fmt::Debug for __c_anonymous_CONTEXT_FP {
23+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
24+
unsafe {
25+
f.debug_struct("__c_anonymous_CONTEXT_FP")
26+
.field("FltSave", &self.FltSave)
27+
.finish()
28+
}
29+
}
30+
}
31+
impl ::hash::Hash for __c_anonymous_CONTEXT_FP {
32+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
33+
unsafe {
34+
self.FltSave.hash(state);
35+
self.Xmm.hash(state);
36+
}
37+
}
38+
}
39+
}
40+
}
41+
42+
s! {
43+
#[repr(align(16))]
44+
pub struct M128A {
45+
pub Low: ::c_ulonglong,
46+
pub High: ::c_longlong,
47+
}
48+
49+
#[repr(align(16))]
50+
pub struct XSAVE_FORMAT {
51+
pub ControlWord: ::c_ushort,
52+
pub StatusWord: ::c_ushort,
53+
pub TagWord: ::c_uchar,
54+
_Reserved1: ::c_uchar,
55+
pub ErrorOpcode: ::c_ushort,
56+
pub ErrorOffset: ::c_ulong,
57+
pub ErrorSelector: ::c_ushort,
58+
_Reserved2: ::c_ushort,
59+
pub DataOffset: ::c_ulong,
60+
pub DataSelector: ::c_ushort,
61+
_Reserved3: ::c_ushort,
62+
pub MxCsr: ::c_ulong,
63+
pub MxCsr_Mask: ::c_ulong,
64+
pub FloatRegisters: [M128A; 8],
65+
pub XmmRegisters: [M128A; 16],
66+
_Reserved4: [::c_uchar; 96],
67+
}
68+
69+
#[repr(align(16))]
70+
pub struct __c_anonymous_CONTEXT_XMM {
71+
pub Header: [M128A; 2],
72+
pub Legacy: [M128A; 8],
73+
pub Xmm0: M128A,
74+
pub Xmm1: M128A,
75+
pub Xmm2: M128A,
76+
pub Xmm3: M128A,
77+
pub Xmm4: M128A,
78+
pub Xmm5: M128A,
79+
pub Xmm6: M128A,
80+
pub Xmm7: M128A,
81+
pub Xmm8: M128A,
82+
pub Xmm9: M128A,
83+
pub Xmm10: M128A,
84+
pub Xmm11: M128A,
85+
pub Xmm12: M128A,
86+
pub Xmm13: M128A,
87+
pub Xmm14: M128A,
88+
pub Xmm15: M128A,
89+
}
90+
91+
#[repr(align(16))]
92+
pub struct CONTEXT {
93+
pub P1Home: u64,
94+
pub P2Home: u64,
95+
pub P3Home: u64,
96+
pub P4Home: u64,
97+
pub P5Home: u64,
98+
pub P6Home: u64,
99+
pub ContextFlags: ::c_ulong,
100+
pub MxCsr: ::c_ulong,
101+
pub SegCs: ::c_ushort,
102+
pub SegDs: ::c_ushort,
103+
pub SegEs: ::c_ushort,
104+
pub SegFs: ::c_ushort,
105+
pub SegGs: ::c_ushort,
106+
pub SegSs: ::c_ushort,
107+
pub EFlags: ::c_ulong,
108+
pub Dr0: u64,
109+
pub Dr1: u64,
110+
pub Dr2: u64,
111+
pub Dr3: u64,
112+
pub Dr6: u64,
113+
pub Dr7: u64,
114+
pub Rax: u64,
115+
pub Rcx: u64,
116+
pub Rdx: u64,
117+
pub Rbx: u64,
118+
pub Rsp: u64,
119+
pub Rbp: u64,
120+
pub Rsi: u64,
121+
pub Rdi: u64,
122+
pub R8: u64,
123+
pub R9: u64,
124+
pub R10: u64,
125+
pub R11: u64,
126+
pub R12: u64,
127+
pub R13: u64,
128+
pub R14: u64,
129+
pub R15: u64,
130+
pub Rip: u64,
131+
pub Fp: __c_anonymous_CONTEXT_FP,
132+
pub VectorRegister: [M128A; 26],
133+
pub VectorControl: u64,
134+
pub DebugControl: u64,
135+
pub LastBranchToRip: u64,
136+
pub LastBranchFromRip: u64,
137+
pub LastExceptionToRip: u64,
138+
pub LastExceptionFromRip: u64,
139+
}
140+
}

0 commit comments

Comments
 (0)