aboutsummaryrefslogtreecommitdiff
path: root/win32/process.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-02-27 11:28:43 +0000
committerRon Yorston <rmy@pobox.com>2019-02-27 11:28:43 +0000
commit41659f76804df94874469e7fa66ef5d1808753d5 (patch)
tree717749b18c210df94e5bd9258954cd75e4138bfe /win32/process.c
parentbf465dd5036d1f3f3fd3812f737579b1f795ca83 (diff)
downloadbusybox-w32-41659f76804df94874469e7fa66ef5d1808753d5.tar.gz
busybox-w32-41659f76804df94874469e7fa66ef5d1808753d5.tar.bz2
busybox-w32-41659f76804df94874469e7fa66ef5d1808753d5.zip
win32: make more use of common lazy loading code
Diffstat (limited to 'win32/process.c')
-rw-r--r--win32/process.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/win32/process.c b/win32/process.c
index 46efdc160..33ae13ab4 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -1,6 +1,7 @@
1#include "libbb.h" 1#include "libbb.h"
2#include <tlhelp32.h> 2#include <tlhelp32.h>
3#include <psapi.h> 3#include <psapi.h>
4#include "lazyload.h"
4 5
5int waitpid(pid_t pid, int *status, int options) 6int waitpid(pid_t pid, int *status, int options)
6{ 7{
@@ -668,33 +669,20 @@ int kill_SIGTERM_by_handle(HANDLE process, int exit_code)
668 int ret = 0; 669 int ret = 0;
669 670
670 if (GetExitCodeProcess(process, &code) && code == STILL_ACTIVE) { 671 if (GetExitCodeProcess(process, &code) && code == STILL_ACTIVE) {
671 static int initialized; 672 DECLARE_PROC_ADDR(DWORD, ExitProcess, LPVOID);
672 static LPTHREAD_START_ROUTINE exit_process_address;
673 PVOID arg = (PVOID)(intptr_t)exit_code; 673 PVOID arg = (PVOID)(intptr_t)exit_code;
674 DWORD thread_id; 674 DWORD thread_id;
675 HANDLE thread; 675 HANDLE thread;
676 676
677 if (!initialized) { 677 if (!INIT_PROC_ADDR(kernel32, ExitProcess) ||
678 HINSTANCE kernel32 = GetModuleHandle("kernel32"); 678 !process_architecture_matches_current(process)) {
679 if (!kernel32) {
680 fprintf(stderr, "BUG: cannot find kernel32");
681 ret = -1;
682 goto finish;
683 }
684 exit_process_address = (LPTHREAD_START_ROUTINE)
685 GetProcAddress(kernel32, "ExitProcess");
686 initialized = 1;
687 }
688 if (!exit_process_address ||
689 !process_architecture_matches_current(process)) {
690 SetLastError(ERROR_ACCESS_DENIED); 679 SetLastError(ERROR_ACCESS_DENIED);
691 ret = -1; 680 ret = -1;
692 goto finish; 681 goto finish;
693 } 682 }
694 683
695 if ((thread = CreateRemoteThread(process, NULL, 0, 684 if ((thread = CreateRemoteThread(process, NULL, 0,
696 exit_process_address, 685 ExitProcess, arg, 0, &thread_id))) {
697 arg, 0, &thread_id))) {
698 CloseHandle(thread); 686 CloseHandle(thread);
699 } 687 }
700 } 688 }