diff options
author | Ron Yorston <rmy@pobox.com> | 2020-06-02 07:53:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-06-02 08:27:46 +0100 |
commit | 27c718aa1a4674587925adb543362cb8e60814c4 (patch) | |
tree | db22579586cede7cb0f3351ce66c36f98a9a5a7a /win32/lazyload.h | |
parent | 5ea460a32a9882906c7ee3656b8fb0dcdbce2abc (diff) | |
download | busybox-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/lazyload.h')
-rw-r--r-- | win32/lazyload.h | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/win32/lazyload.h b/win32/lazyload.h index a9fcff209..034bc7e45 100644 --- a/win32/lazyload.h +++ b/win32/lazyload.h | |||
@@ -21,19 +21,7 @@ struct proc_addr { | |||
21 | #define INIT_PROC_ADDR(dll, function) \ | 21 | #define INIT_PROC_ADDR(dll, function) \ |
22 | (function = get_proc_addr(#dll, #function, &proc_addr_##function)) | 22 | (function = get_proc_addr(#dll, #function, &proc_addr_##function)) |
23 | 23 | ||
24 | static inline void *get_proc_addr(const char *dll, const char *function, struct proc_addr *proc) | 24 | void *get_proc_addr(const char *dll, const char *function, |
25 | { | 25 | struct proc_addr *proc); |
26 | /* only do this once */ | ||
27 | if (!proc->initialized) { | ||
28 | HANDLE hnd = LoadLibraryExA(dll, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
29 | if (hnd) | ||
30 | proc->pfunction = GetProcAddress(hnd, function); | ||
31 | proc->initialized = 1; | ||
32 | } | ||
33 | /* set ENOSYS if DLL or function was not found */ | ||
34 | if (!proc->pfunction) | ||
35 | errno = ENOSYS; | ||
36 | return proc->pfunction; | ||
37 | } | ||
38 | 26 | ||
39 | #endif | 27 | #endif |