From dd9f552bb1fee66f3155bbbb81c677def861ada0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 1 Sep 2017 17:50:39 +0100 Subject: 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. --- win32/lazyload.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 win32/lazyload.h (limited to 'win32/lazyload.h') 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 @@ +#ifndef LAZYLOAD_H +#define LAZYLOAD_H + +/* simplify loading of DLL functions */ + +struct proc_addr { + const char *const dll; + const char *const function; + FARPROC pfunction; + unsigned initialized : 1; +}; + +/* Declares a function to be loaded dynamically from a DLL. */ +#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \ + static struct proc_addr proc_addr_##function = \ + { #dll, #function, NULL, 0 }; \ + static rettype (WINAPI *function)(__VA_ARGS__) + +/* + * Loads a function from a DLL (once-only). + * Returns non-NULL function pointer on success. + * Returns NULL + errno == ENOSYS on failure. + */ +#define INIT_PROC_ADDR(function) (function = get_proc_addr(&proc_addr_##function)) + +static inline void *get_proc_addr(struct proc_addr *proc) +{ + /* only do this once */ + if (!proc->initialized) { + HANDLE hnd; + proc->initialized = 1; + hnd = LoadLibraryExA(proc->dll, NULL, + LOAD_LIBRARY_SEARCH_SYSTEM32); + if (hnd) + proc->pfunction = GetProcAddress(hnd, proc->function); + } + /* set ENOSYS if DLL or function was not found */ + if (!proc->pfunction) + errno = ENOSYS; + return proc->pfunction; +} + +#endif -- cgit v1.2.3-55-g6feb