diff --git a/Cargo.toml b/Cargo.toml index e219645..fc5cf5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,7 @@ path = "src/bin.rs" [dependencies] detours-sys = "0.1" -clap = "2.33" \ No newline at end of file +clap = "2.33" + +[target.'cfg(windows)'.dependencies] +winapi = { version = "0.3", features = ["processthreadsapi", "std", "synchapi"] } \ No newline at end of file diff --git a/src/bin.rs b/src/bin.rs index 875f596..b7314c0 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -1,5 +1,6 @@ extern crate clap; extern crate detours_sys; +extern crate winapi; use std::error::Error; use std::ffi::OsStr; @@ -7,6 +8,10 @@ use std::mem; use std::os::windows::ffi::OsStrExt; use std::ptr; +use winapi::um::processthreadsapi::{GetExitCodeProcess, ResumeThread}; +use winapi::um::synchapi::WaitForSingleObject; +use winapi::um::winbase::{INFINITE, WAIT_FAILED}; + use clap::{App, AppSettings, Arg}; #[macro_use] @@ -63,23 +68,13 @@ fn main() -> Result<(), Box> { "nvcuda_redirect.dll".as_ptr() as *const i8, Option::None ), - 0 + |x| x == 0 ); - Ok(()) - /* - - cmd_line.as_mut_ptr(), - ptr::null_mut(), - ptr::null_mut(), - 0, - 0x10, - ptr::null_mut(), - ptr::null(), - &mut startup_info as *mut _, - &mut proc_info as *mut _, - "nvcuda_redirect.dll".as_ptr() as *const i8, - Option::None, - */ + os_call!(ResumeThread(proc_info.hThread), |x| x as i32 != -1); + os_call!(WaitForSingleObject(proc_info.hProcess, INFINITE), |x| x != WAIT_FAILED); + let mut child_exit_code : u32 = 0; + os_call!(GetExitCodeProcess(proc_info.hProcess, &mut child_exit_code as *mut _), |x| x != 0); + std::process::exit(child_exit_code as i32) } fn copy_to(from: &OsStr, to: &mut Vec) { diff --git a/src/win.rs b/src/win.rs index 3055202..ec57ffb 100644 --- a/src/win.rs +++ b/src/win.rs @@ -1,7 +1,6 @@ #![allow(non_snake_case)] use std::error; -use std::error::Error; use std::fmt; use std::ptr; @@ -50,7 +49,7 @@ macro_rules! last_ident { macro_rules! os_call { ($($path:ident)::+ ($($args:expr),*), $success:expr) => { let result = unsafe{ $($path)::+ ($($args),+) }; - if result != $success { + if !($success)(result) { let name = last_ident!($($path),+); let err_code = $crate::win::errno(); Err($crate::win::OsError{