diff options
| author | bors <bors@rust-lang.org> | 2020-04-03 20:56:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-04-03 20:56:05 +0000 |
| commit | 74bd074eefcf4915c73d1ab91bc90859664729e6 (patch) | |
| tree | 4eb869837e228d81b08b2fb4db3ad1af00942039 /src/libstd/sys/windows | |
| parent | f6fe99c798cb65280a9a56f442b371adcb7b8aa2 (diff) | |
| parent | 4c41ea36cda77748b532cf6d989a8d5d2fcc872e (diff) | |
| download | rust-74bd074eefcf4915c73d1ab91bc90859664729e6.tar.gz rust-74bd074eefcf4915c73d1ab91bc90859664729e6.zip | |
Auto merge of #70747 - Centril:rollup-2vx9bve, r=Centril
Rollup of 9 pull requests Successful merges: - #69860 (Use associated numeric consts in documentation) - #70576 (Update the description of the ticket to point at RFC 1721) - #70597 (Fix double-free and undefined behaviour in libstd::syn::unix::Thread::new) - #70640 (Hide `task_context` when lowering body) - #70641 (Remove duplicated code in trait selection) - #70707 (Remove unused graphviz emitter) - #70720 (Place TLS initializers with relocations in .tdata) - #70735 (Clean up E0502 explanation) - #70741 (Add test for #59023) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index c828243a59b..38839ea5e90 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -1,10 +1,9 @@ use crate::ffi::CStr; use crate::io; -use crate::mem; use crate::ptr; use crate::sys::c; use crate::sys::handle::Handle; -use crate::sys_common::thread::*; +use crate::sys::stack_overflow; use crate::time::Duration; use libc::c_void; @@ -20,7 +19,7 @@ pub struct Thread { impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> { - let p = box p; + let p = Box::into_raw(box p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -34,21 +33,27 @@ impl Thread { ptr::null_mut(), stack_size, thread_start, - &*p as *const _ as *mut _, + p as *mut _, c::STACK_SIZE_PARAM_IS_A_RESERVATION, ptr::null_mut(), ); return if ret as usize == 0 { + // The thread failed to start and as a result p was not consumed. Therefore, it is + // safe to reconstruct the box so that it gets deallocated. + drop(Box::from_raw(p)); Err(io::Error::last_os_error()) } else { - mem::forget(p); // ownership passed to CreateThread Ok(Thread { handle: Handle::new(ret) }) }; extern "system" fn thread_start(main: *mut c_void) -> c::DWORD { unsafe { - start_thread(main as *mut u8); + // Next, set up our stack overflow handler which may get triggered if we run + // out of stack. + let _handler = stack_overflow::Handler::new(); + // Finally, let's run some code. + Box::from_raw(main as *mut Box<dyn FnOnce()>)(); } 0 } |
