aboutsummaryrefslogtreecommitdiff
path: root/win32/process.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-06-02 07:53:10 +0100
committerRon Yorston <rmy@pobox.com>2020-06-02 08:27:46 +0100
commit27c718aa1a4674587925adb543362cb8e60814c4 (patch)
treedb22579586cede7cb0f3351ce66c36f98a9a5a7a /win32/process.c
parent5ea460a32a9882906c7ee3656b8fb0dcdbce2abc (diff)
downloadbusybox-w32-27c718aa1a4674587925adb543362cb8e60814c4.tar.gz
busybox-w32-27c718aa1a4674587925adb543362cb8e60814c4.tar.bz2
busybox-w32-27c718aa1a4674587925adb543362cb8e60814c4.zip
win32: use lazy loading for certain DLLs
Only a handful of functions are used from shell32.dll, userenv.dll and psapi.dll. Mostly these functions are in out of the way places. By loading the functions only when required we can avoid the startup cost of linking the three DLLs in the common case that they aren't needed.
Diffstat (limited to 'win32/process.c')
-rw-r--r--win32/process.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/win32/process.c b/win32/process.c
index 04775100b..5833a0323 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -446,6 +446,17 @@ static char *get_bb_string(DWORD pid, const char *exe, char *string)
446 char exepath[PATH_MAX]; 446 char exepath[PATH_MAX];
447 char *name = NULL; 447 char *name = NULL;
448 int i; 448 int i;
449 DECLARE_PROC_ADDR(DWORD, GetProcessImageFileNameA, HANDLE,
450 LPSTR, DWORD);
451 DECLARE_PROC_ADDR(BOOL, EnumProcessModules, HANDLE, HMODULE *,
452 DWORD, LPDWORD);
453 DECLARE_PROC_ADDR(DWORD, GetModuleFileNameExA, HANDLE, HMODULE,
454 LPSTR, DWORD);
455
456 if (!INIT_PROC_ADDR(psapi.dll, GetProcessImageFileNameA) ||
457 !INIT_PROC_ADDR(psapi.dll, EnumProcessModules) ||
458 !INIT_PROC_ADDR(psapi.dll, GetModuleFileNameExA))
459 return NULL;
449 460
450 if (!(proc=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, 461 if (!(proc=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
451 FALSE, pid))) { 462 FALSE, pid))) {
@@ -453,7 +464,7 @@ static char *get_bb_string(DWORD pid, const char *exe, char *string)
453 } 464 }
454 465
455 if (exe == NULL) { 466 if (exe == NULL) {
456 if (GetProcessImageFileName(proc, exepath, PATH_MAX) != 0) { 467 if (GetProcessImageFileNameA(proc, exepath, PATH_MAX) != 0) {
457 exe = bb_basename(exepath); 468 exe = bb_basename(exepath);
458 } 469 }
459 } 470 }
@@ -470,7 +481,7 @@ static char *get_bb_string(DWORD pid, const char *exe, char *string)
470 481
471 for (i=0; exe != NULL && i<needed/sizeof(HMODULE); ++i) { 482 for (i=0; exe != NULL && i<needed/sizeof(HMODULE); ++i) {
472 char modname[MAX_PATH]; 483 char modname[MAX_PATH];
473 if (GetModuleFileNameEx(proc, mlist[i], modname, sizeof(modname))) { 484 if (GetModuleFileNameExA(proc, mlist[i], modname, sizeof(modname))) {
474 if (strcasecmp(bb_basename(modname), exe) == 0) { 485 if (strcasecmp(bb_basename(modname), exe) == 0) {
475 break; 486 break;
476 } 487 }