Skip to content

Commit a52eaaa

Browse files
committed
Disable runtime split stack support on Windows
1 parent 91e30ec commit a52eaaa

File tree

3 files changed

+13
-56
lines changed

3 files changed

+13
-56
lines changed

src/librustrt/stack.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ pub unsafe fn record_sp_limit(limit: uint) {
200200
asm!("movq $0, %fs:112" :: "r"(limit) :: "volatile")
201201
}
202202
#[cfg(target_arch = "x86_64", target_os = "windows")] #[inline(always)]
203-
unsafe fn target_record_sp_limit(limit: uint) {
204-
// see: http://en.wikipedia.org/wiki/Win32_Thread_Information_Block
205-
// store this inside of the "arbitrary data slot", but double the size
206-
// because this is 64 bit instead of 32 bit
207-
asm!("movq $0, %gs:0x28" :: "r"(limit) :: "volatile")
203+
unsafe fn target_record_sp_limit(_: uint) {
208204
}
209205
#[cfg(target_arch = "x86_64", target_os = "freebsd")] #[inline(always)]
210206
unsafe fn target_record_sp_limit(limit: uint) {
@@ -228,10 +224,7 @@ pub unsafe fn record_sp_limit(limit: uint) {
228224
asm!("movl $0, %gs:48" :: "r"(limit) :: "volatile")
229225
}
230226
#[cfg(target_arch = "x86", target_os = "windows")] #[inline(always)]
231-
unsafe fn target_record_sp_limit(limit: uint) {
232-
// see: http://en.wikipedia.org/wiki/Win32_Thread_Information_Block
233-
// store this inside of the "arbitrary data slot"
234-
asm!("movl $0, %fs:0x14" :: "r"(limit) :: "volatile")
227+
unsafe fn target_record_sp_limit(_: uint) {
235228
}
236229

237230
// mips, arm - Some brave soul can port these to inline asm, but it's over
@@ -282,9 +275,7 @@ pub unsafe fn get_sp_limit() -> uint {
282275
}
283276
#[cfg(target_arch = "x86_64", target_os = "windows")] #[inline(always)]
284277
unsafe fn target_get_sp_limit() -> uint {
285-
let limit;
286-
asm!("movq %gs:0x28, $0" : "=r"(limit) ::: "volatile");
287-
return limit;
278+
return 1024;
288279
}
289280
#[cfg(target_arch = "x86_64", target_os = "freebsd")] #[inline(always)]
290281
unsafe fn target_get_sp_limit() -> uint {
@@ -318,9 +309,7 @@ pub unsafe fn get_sp_limit() -> uint {
318309
}
319310
#[cfg(target_arch = "x86", target_os = "windows")] #[inline(always)]
320311
unsafe fn target_get_sp_limit() -> uint {
321-
let limit;
322-
asm!("movl %fs:0x14, $0" : "=r"(limit) ::: "volatile");
323-
return limit;
312+
return 1024;
324313
}
325314

326315
// mips, arm - Some brave soul can port these to inline asm, but it's over

src/libstd/rand/os.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ mod imp {
136136
use os;
137137
use rand::Rng;
138138
use result::{Ok, Err};
139-
use rt::stack;
140139
use self::libc::{DWORD, BYTE, LPCSTR, BOOL};
141140
use self::libc::types::os::arch::extra::{LONG_PTR};
142141
use slice::MutableSlice;
@@ -159,7 +158,6 @@ mod imp {
159158
static PROV_RSA_FULL: DWORD = 1;
160159
static CRYPT_SILENT: DWORD = 64;
161160
static CRYPT_VERIFYCONTEXT: DWORD = 0xF0000000;
162-
static NTE_BAD_SIGNATURE: DWORD = 0x80090006;
163161

164162
#[allow(non_snake_case)]
165163
extern "system" {
@@ -178,48 +176,12 @@ mod imp {
178176
/// Create a new `OsRng`.
179177
pub fn new() -> IoResult<OsRng> {
180178
let mut hcp = 0;
181-
let mut ret = unsafe {
179+
let ret = unsafe {
182180
CryptAcquireContextA(&mut hcp, 0 as LPCSTR, 0 as LPCSTR,
183181
PROV_RSA_FULL,
184182
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)
185183
};
186184

187-
// FIXME #13259:
188-
// It turns out that if we can't acquire a context with the
189-
// NTE_BAD_SIGNATURE error code, the documentation states:
190-
//
191-
// The provider DLL signature could not be verified. Either the
192-
// DLL or the digital signature has been tampered with.
193-
//
194-
// Sounds fishy, no? As it turns out, our signature can be bad
195-
// because our Thread Information Block (TIB) isn't exactly what it
196-
// expects. As to why, I have no idea. The only data we store in the
197-
// TIB is the stack limit for each thread, but apparently that's
198-
// enough to make the signature valid.
199-
//
200-
// Furthermore, this error only happens the *first* time we call
201-
// CryptAcquireContext, so we don't have to worry about future
202-
// calls.
203-
//
204-
// Anyway, the fix employed here is that if we see this error, we
205-
// pray that we're not close to the end of the stack, temporarily
206-
// set the stack limit to 0 (what the TIB originally was), acquire a
207-
// context, and then reset the stack limit.
208-
//
209-
// Again, I'm not sure why this is the fix, nor why we're getting
210-
// this error. All I can say is that this seems to allow libnative
211-
// to progress where it otherwise would be hindered. Who knew?
212-
if ret == 0 && os::errno() as DWORD == NTE_BAD_SIGNATURE {
213-
unsafe {
214-
let limit = stack::get_sp_limit();
215-
stack::record_sp_limit(0);
216-
ret = CryptAcquireContextA(&mut hcp, 0 as LPCSTR, 0 as LPCSTR,
217-
PROV_RSA_FULL,
218-
CRYPT_VERIFYCONTEXT | CRYPT_SILENT);
219-
stack::record_sp_limit(limit);
220-
}
221-
}
222-
223185
if ret == 0 {
224186
Err(IoError::last_error())
225187
} else {

src/test/run-pass/out-of-stack.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ fn main() {
4242
let silent = Command::new(args[0].as_slice()).arg("silent").output().unwrap();
4343
assert!(!silent.status.success());
4444
let error = String::from_utf8_lossy(silent.error.as_slice());
45-
assert!(error.as_slice().contains("has overflowed its stack"));
45+
// FIXME #17562: Windows is using stack probes and isn't wired up to print an error
46+
if !cfg!(windows) {
47+
assert!(error.as_slice().contains("has overflowed its stack"));
48+
}
4649

4750
let loud = Command::new(args[0].as_slice()).arg("loud").output().unwrap();
4851
assert!(!loud.status.success());
4952
let error = String::from_utf8_lossy(silent.error.as_slice());
50-
assert!(error.as_slice().contains("has overflowed its stack"));
53+
// FIXME #17562: Windows is using stack probes and isn't wired up to print an error
54+
if !cfg!(windows) {
55+
assert!(error.as_slice().contains("has overflowed its stack"));
56+
}
5157
}
5258
}

0 commit comments

Comments
 (0)