mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Write more tests and improve kill() on Windows
This commit is contained in:
parent
b81a1bd9a8
commit
d458642790
6 changed files with 183 additions and 13 deletions
|
@ -42,7 +42,7 @@ __msabi extern typeof(ExitThread) *const __imp_ExitThread;
|
|||
* @see cthread_exit()
|
||||
* @noreturn
|
||||
*/
|
||||
privileged wontreturn void _Exit1(int rc) {
|
||||
wontreturn void _Exit1(int rc) {
|
||||
#ifdef __x86_64__
|
||||
char cf;
|
||||
int ax, dx, di, si;
|
||||
|
|
|
@ -29,7 +29,13 @@
|
|||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Prints miniature crash report.
|
||||
* Prints miniature crash report, e.g.
|
||||
*
|
||||
* struct sigaction sa = {
|
||||
* .sa_sigaction = __minicrash,
|
||||
* .sa_flags = SA_SIGINFO | SA_RESETHAND,
|
||||
* };
|
||||
* sigaction(SIGSEGV, &sa, 0);
|
||||
*
|
||||
* This function may be called from a signal handler to print vital
|
||||
* information about the cause of a crash. Only vital number values
|
||||
|
|
|
@ -20,9 +20,14 @@
|
|||
#include "libc/calls/syscall-nt.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/nt/console.h"
|
||||
#include "libc/nt/enum/ctrlevent.h"
|
||||
#include "libc/nt/enum/processaccess.h"
|
||||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/proc/proc.internal.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
|
@ -55,17 +60,26 @@ textwindows int sys_kill_nt(int pid, int sig) {
|
|||
}
|
||||
|
||||
// find existing handle we own for process
|
||||
int64_t handle;
|
||||
int64_t handle, closeme = 0;
|
||||
if (!(handle = __proc_handle(pid))) {
|
||||
return esrch();
|
||||
if ((handle = OpenProcess(kNtProcessTerminate, false, pid))) {
|
||||
closeme = handle;
|
||||
} else {
|
||||
goto OnError;
|
||||
}
|
||||
}
|
||||
|
||||
// perform actual kill
|
||||
// process will report WIFSIGNALED with WTERMSIG(sig)
|
||||
if (TerminateProcess(handle, sig)) return 0;
|
||||
STRACE("TerminateProcess() failed with %d", GetLastError());
|
||||
bool32 ok = TerminateProcess(handle, sig);
|
||||
if (closeme) CloseHandle(closeme);
|
||||
if (ok) return 0;
|
||||
|
||||
// handle error
|
||||
OnError:
|
||||
switch (GetLastError()) {
|
||||
case kNtErrorInvalidHandle:
|
||||
case kNtErrorInvalidParameter:
|
||||
return esrch();
|
||||
default:
|
||||
return eperm();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue