The only remaining uses of loadlib.h are in cygcheck and strace, where it's used to load cygwin1.dll in both. Things could be further simplified, but it's probably worth keeping it around in it's present form since it's quite likely that LoadLibrary()/GetProcAddress() might be used again in future. Jon Turney (2): Cygwin: Drop pointless loadlib.h includes in utilities Cygwin: Drop use of loadlib.h in regtool winsup/utils/cygpath.cc | 1 - winsup/utils/module_info.cc | 1 - winsup/utils/path.cc | 1 - winsup/utils/ps.cc | 1 - winsup/utils/regtool.cc | 13 +------------ 5 files changed, 1 insertion(+), 16 deletions(-) -- 2.35.1
These utilities used to LoadLibrary()/GetProcAddress(), but don't anymore. --- winsup/utils/cygpath.cc | 1 - winsup/utils/module_info.cc | 1 - winsup/utils/path.cc | 1 - winsup/utils/ps.cc | 1 - 4 files changed, 4 deletions(-) diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc index 701c34998..9873e7b16 100644 --- a/winsup/utils/cygpath.cc +++ b/winsup/utils/cygpath.cc @@ -29,7 +29,6 @@ details. */ #include <ntdll.h> #include "wide_path.h" -#include "loadlib.h" static char *prog_name; static char *file_arg, *output_arg; diff --git a/winsup/utils/module_info.cc b/winsup/utils/module_info.cc index e0bd4b71a..3e2fc28e2 100644 --- a/winsup/utils/module_info.cc +++ b/winsup/utils/module_info.cc @@ -12,7 +12,6 @@ details. */ #include <windows.h> #define PSAPI_VERSION 1 #include <psapi.h> -#include "loadlib.h" /* Returns full name of Dll, which is loaded by hProcess at BaseAddress. Uses psapi.dll. */ diff --git a/winsup/utils/path.cc b/winsup/utils/path.cc index df0037c15..fe55a646d 100644 --- a/winsup/utils/path.cc +++ b/winsup/utils/path.cc @@ -28,7 +28,6 @@ details. */ #ifdef FSTAB_ONLY #include <sys/cygwin.h> #endif -#include "loadlib.h" #ifndef FSTAB_ONLY /* Used when treating / and \ as equivalent. */ diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc index b51657535..dbcacbab4 100644 --- a/winsup/utils/ps.cc +++ b/winsup/utils/ps.cc @@ -21,7 +21,6 @@ details. */ #include <cygwin/version.h> #include <ntdef.h> #include <ntdll.h> -#include "loadlib.h" /* Maximum possible path length under NT. There's no official define for that value. Note that PATH_MAX is only 4K. */ -- 2.35.1
Link directly with RegDeleteKeyExW(), available since Vista. (It's unclear the LoadLibrary wrapper was ever doing anything useful here, as (i) DLL lookup in PATH was avoided as advapi32 is already loaded into the process, and (ii) advapi32 is a 'known DLL' which is only ever loaded from system directory) --- winsup/utils/regtool.cc | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/winsup/utils/regtool.cc b/winsup/utils/regtool.cc index fd2dd0590..e919185ae 100644 --- a/winsup/utils/regtool.cc +++ b/winsup/utils/regtool.cc @@ -16,7 +16,6 @@ details. */ #include <windows.h> #include <sys/cygwin.h> #include <cygwin/version.h> -#include "loadlib.h" #define DEFAULT_KEY_SEPARATOR '\\' @@ -589,10 +588,6 @@ cmd_add () return 0; } -extern "C" { - LONG WINAPI (*regDeleteKeyEx)(HKEY, LPCWSTR, REGSAM, DWORD); -} - int cmd_remove () { @@ -600,13 +595,7 @@ cmd_remove () find_key (2, KEY_ALL_ACCESS); if (wow64) - { - HMODULE mod = LoadLibrary ("advapi32.dll"); - if (mod) - regDeleteKeyEx = (LONG WINAPI (*)(HKEY, LPCWSTR, REGSAM, DWORD)) GetProcAddress (mod, "RegDeleteKeyExW"); - } - if (regDeleteKeyEx) - rv = (*regDeleteKeyEx) (key, value, wow64, 0); + rv = RegDeleteKeyExW (key, value, wow64, 0); else rv = RegDeleteKeyW (key, value); if (rv != ERROR_SUCCESS) -- 2.35.1
On Feb 26 16:40, Jon Turney wrote: > The only remaining uses of loadlib.h are in cygcheck and strace, where it's > used to load cygwin1.dll in both. > > Things could be further simplified, but it's probably worth keeping it > around in it's present form since it's quite likely that > LoadLibrary()/GetProcAddress() might be used again in future. > > Jon Turney (2): > Cygwin: Drop pointless loadlib.h includes in utilities > Cygwin: Drop use of loadlib.h in regtool > > winsup/utils/cygpath.cc | 1 - > winsup/utils/module_info.cc | 1 - > winsup/utils/path.cc | 1 - > winsup/utils/ps.cc | 1 - > winsup/utils/regtool.cc | 13 +------------ > 5 files changed, 1 insertion(+), 16 deletions(-) > > -- > 2.35.1 Good idea! Shouldn't we actually remove loadlib.h as well? What this code does is to provide a safety measure to make sure the files are not stealthy loaded from another dir. This should not be necessary anymore, because Windows itself provides matching functionality. First of all, the system has an internal list of DLLs it always loads from the system32 dir. In Cygwin, see the content of /proc/sys/KnownDlls/ and /proc/sys/KnownDlls32/ And for all other cases we can use LoadLibraryEx flags introduced a couple of years ago, e. g. LOAD_LIBRARY_SEARCH_SYSTEM32. See https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa Thanks, Corinna
On Feb 26 16:40, Jon Turney wrote:
> Link directly with RegDeleteKeyExW(), available since Vista.
>
> (It's unclear the LoadLibrary wrapper was ever doing anything useful
> here, as (i) DLL lookup in PATH was avoided as advapi32 is already
> loaded into the process, and (ii) advapi32 is a 'known DLL' which is
> only ever loaded from system directory)
Ah, sorry for outlining this in my previous reply. You were aware
of that already, of course.
Corinna