add win32 kill api - #1716
Conversation
| process.wait(); | ||
|
|
||
| #[cfg(windows)] | ||
| std::thread::sleep(std::time::Duration::from_millis(150)); |
There was a problem hiding this comment.
reason: the new method kills the process much faster than before, so the OS info is not yet updated when the information is refreshed.
| use windows::core::PCWSTR; | ||
| use windows::core::{PCSTR, s, w}; | ||
|
|
||
| type NtSuspendProcess = unsafe extern "system" fn(HANDLE) -> i32; |
There was a problem hiding this comment.
I removed all Nt* calls because some windows antivirus are very unhappy about them. Not sure it's a good idea to try to reintroduce them.
There was a problem hiding this comment.
The alternatives to these functions would make implementation of the pause/resume functionality difficult. If they are only used for that functionality, would the antivirus trigger if they are never used? The alternative is to suspend the threads one by one which is more involved or not attempt this at all, which would constrain this to pr to trying TerminateProcess.
There was a problem hiding this comment.
The alternative is actually the current code: to not support these features.
There was a problem hiding this comment.
I have removed the ntdll calls. The only thing left is TerminateProcess. If that is too much, I will close the PR.
| PROCESS_QUERY_INFORMATION | ||
| | PROCESS_VM_READ | ||
| | PROCESS_SUSPEND_RESUME | ||
| | PROCESS_TERMINATE, |
There was a problem hiding this comment.
If you absolutely need PROCESS_TERMINATE, then use OpenProcess directly in kill_with_win32.
| match signal { | ||
| Signal::Kill => unsafe { TerminateProcess(h, 1) }.map_err(|_| ()), | ||
| _ => Err(()), | ||
| } |
There was a problem hiding this comment.
Please find a way to wait for the process to be actually removed before returning.
|
I am going to close this for now, and I may come back to this later. |
use the win32 api to kill the process if possible, and add ability to stop and resume process.