diff options
author | Ron Yorston <rmy@pobox.com> | 2017-09-01 17:50:39 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-09-01 18:00:01 +0100 |
commit | dd9f552bb1fee66f3155bbbb81c677def861ada0 (patch) | |
tree | 21c7f1f333a2a58361c813311188b286ea803c9c /win32/lazyload.h | |
parent | ec3ecac715b299766c101be92caf8b7cffb2a8b5 (diff) | |
download | busybox-w32-dd9f552bb1fee66f3155bbbb81c677def861ada0.tar.gz busybox-w32-dd9f552bb1fee66f3155bbbb81c677def861ada0.tar.bz2 busybox-w32-dd9f552bb1fee66f3155bbbb81c677def861ada0.zip |
ps: add support for CPU and elapsed time columns
It may be necessary to run ps as administrator to get information
about processes belonging to other users.
The code to detect GetTickCount64 at run-time was imported from
Git for Windows.
Diffstat (limited to 'win32/lazyload.h')
-rw-r--r-- | win32/lazyload.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/win32/lazyload.h b/win32/lazyload.h new file mode 100644 index 000000000..9d1a05550 --- /dev/null +++ b/win32/lazyload.h | |||
@@ -0,0 +1,43 @@ | |||
1 | #ifndef LAZYLOAD_H | ||
2 | #define LAZYLOAD_H | ||
3 | |||
4 | /* simplify loading of DLL functions */ | ||
5 | |||
6 | struct proc_addr { | ||
7 | const char *const dll; | ||
8 | const char *const function; | ||
9 | FARPROC pfunction; | ||
10 | unsigned initialized : 1; | ||
11 | }; | ||
12 | |||
13 | /* Declares a function to be loaded dynamically from a DLL. */ | ||
14 | #define DECLARE_PROC_ADDR(dll, rettype, function, ...) \ | ||
15 | static struct proc_addr proc_addr_##function = \ | ||
16 | { #dll, #function, NULL, 0 }; \ | ||
17 | static rettype (WINAPI *function)(__VA_ARGS__) | ||
18 | |||
19 | /* | ||
20 | * Loads a function from a DLL (once-only). | ||
21 | * Returns non-NULL function pointer on success. | ||
22 | * Returns NULL + errno == ENOSYS on failure. | ||
23 | */ | ||
24 | #define INIT_PROC_ADDR(function) (function = get_proc_addr(&proc_addr_##function)) | ||
25 | |||
26 | static inline void *get_proc_addr(struct proc_addr *proc) | ||
27 | { | ||
28 | /* only do this once */ | ||
29 | if (!proc->initialized) { | ||
30 | HANDLE hnd; | ||
31 | proc->initialized = 1; | ||
32 | hnd = LoadLibraryExA(proc->dll, NULL, | ||
33 | LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
34 | if (hnd) | ||
35 | proc->pfunction = GetProcAddress(hnd, proc->function); | ||
36 | } | ||
37 | /* set ENOSYS if DLL or function was not found */ | ||
38 | if (!proc->pfunction) | ||
39 | errno = ENOSYS; | ||
40 | return proc->pfunction; | ||
41 | } | ||
42 | |||
43 | #endif | ||