public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH 0/2] Drop pointless loadlib.h use in utilities
@ 2022-02-26 16:40 Jon Turney
  2022-02-26 16:40 ` [PATCH 1/2] Cygwin: Drop pointless loadlib.h includes " Jon Turney
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jon Turney @ 2022-02-26 16:40 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Jon Turney

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] Cygwin: Drop pointless loadlib.h includes in utilities
  2022-02-26 16:40 [PATCH 0/2] Drop pointless loadlib.h use in utilities Jon Turney
@ 2022-02-26 16:40 ` Jon Turney
  2022-02-26 16:40 ` [PATCH 2/2] Cygwin: Drop use of loadlib.h in regtool Jon Turney
  2022-02-28  9:39 ` [PATCH 0/2] Drop pointless loadlib.h use in utilities Corinna Vinschen
  2 siblings, 0 replies; 5+ messages in thread
From: Jon Turney @ 2022-02-26 16:40 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Jon Turney

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] Cygwin: Drop use of loadlib.h in regtool
  2022-02-26 16:40 [PATCH 0/2] Drop pointless loadlib.h use in utilities Jon Turney
  2022-02-26 16:40 ` [PATCH 1/2] Cygwin: Drop pointless loadlib.h includes " Jon Turney
@ 2022-02-26 16:40 ` Jon Turney
  2022-02-28  9:44   ` Corinna Vinschen
  2022-02-28  9:39 ` [PATCH 0/2] Drop pointless loadlib.h use in utilities Corinna Vinschen
  2 siblings, 1 reply; 5+ messages in thread
From: Jon Turney @ 2022-02-26 16:40 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Jon Turney

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] Drop pointless loadlib.h use in utilities
  2022-02-26 16:40 [PATCH 0/2] Drop pointless loadlib.h use in utilities Jon Turney
  2022-02-26 16:40 ` [PATCH 1/2] Cygwin: Drop pointless loadlib.h includes " Jon Turney
  2022-02-26 16:40 ` [PATCH 2/2] Cygwin: Drop use of loadlib.h in regtool Jon Turney
@ 2022-02-28  9:39 ` Corinna Vinschen
  2 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2022-02-28  9:39 UTC (permalink / raw)
  To: cygwin-patches

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Cygwin: Drop use of loadlib.h in regtool
  2022-02-26 16:40 ` [PATCH 2/2] Cygwin: Drop use of loadlib.h in regtool Jon Turney
@ 2022-02-28  9:44   ` Corinna Vinschen
  0 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2022-02-28  9:44 UTC (permalink / raw)
  To: cygwin-patches

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-28  9:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-26 16:40 [PATCH 0/2] Drop pointless loadlib.h use in utilities Jon Turney
2022-02-26 16:40 ` [PATCH 1/2] Cygwin: Drop pointless loadlib.h includes " Jon Turney
2022-02-26 16:40 ` [PATCH 2/2] Cygwin: Drop use of loadlib.h in regtool Jon Turney
2022-02-28  9:44   ` Corinna Vinschen
2022-02-28  9:39 ` [PATCH 0/2] Drop pointless loadlib.h use in utilities Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).