diff options
author | Ron Yorston <rmy@pobox.com> | 2019-02-27 11:28:43 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-02-27 11:28:43 +0000 |
commit | 41659f76804df94874469e7fa66ef5d1808753d5 (patch) | |
tree | 717749b18c210df94e5bd9258954cd75e4138bfe /win32 | |
parent | bf465dd5036d1f3f3fd3812f737579b1f795ca83 (diff) | |
download | busybox-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')
-rw-r--r-- | win32/mingw.c | 15 | ||||
-rw-r--r-- | win32/process.c | 22 |
2 files changed, 10 insertions, 27 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 378c4001f..f748d2d09 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -921,19 +921,14 @@ clock_t times(struct tms *buf) | |||
921 | 921 | ||
922 | int link(const char *oldpath, const char *newpath) | 922 | int link(const char *oldpath, const char *newpath) |
923 | { | 923 | { |
924 | typedef BOOL (WINAPI *T)(const char*, const char*, LPSECURITY_ATTRIBUTES); | 924 | DECLARE_PROC_ADDR(BOOL, CreateHardLinkA, LPCSTR, LPCSTR, |
925 | static T create_hard_link = NULL; | 925 | LPSECURITY_ATTRIBUTES); |
926 | if (!create_hard_link) { | 926 | |
927 | create_hard_link = (T) GetProcAddress( | 927 | if (!INIT_PROC_ADDR(kernel32.dll, CreateHardLinkA)) { |
928 | GetModuleHandle("kernel32.dll"), "CreateHardLinkA"); | ||
929 | if (!create_hard_link) | ||
930 | create_hard_link = (T)-1; | ||
931 | } | ||
932 | if (create_hard_link == (T)-1) { | ||
933 | errno = ENOSYS; | 928 | errno = ENOSYS; |
934 | return -1; | 929 | return -1; |
935 | } | 930 | } |
936 | if (!create_hard_link(newpath, oldpath, NULL)) { | 931 | if (!CreateHardLinkA(newpath, oldpath, NULL)) { |
937 | errno = err_win_to_posix(GetLastError()); | 932 | errno = err_win_to_posix(GetLastError()); |
938 | return -1; | 933 | return -1; |
939 | } | 934 | } |
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 | ||
5 | int waitpid(pid_t pid, int *status, int options) | 6 | int 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 | } |