public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: Fix previous attempt to drop i386 targets from hookapi
@ 2022-07-28 14:44 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2022-07-28 14:44 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=33395637a1515f1a66e723265d3be2156ff63b21
commit 33395637a1515f1a66e723265d3be2156ff63b21
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Thu Jul 28 16:38:01 2022 +0200
Cygwin: Fix previous attempt to drop i386 targets from hookapi
Somehow this patch looks like it was pushed before having been
finished. Let's try again...
Fixes: e46f15c2d168 ("Cygwin: hookapi: drop handling i386 targets")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/hookapi.cc | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/winsup/cygwin/hookapi.cc b/winsup/cygwin/hookapi.cc
index 3ce1e0fb2..ee2edbafe 100644
--- a/winsup/cygwin/hookapi.cc
+++ b/winsup/cygwin/hookapi.cc
@@ -29,22 +29,24 @@ struct function_hook
/* Given an HMODULE, returns a pointer to the PE header. */
static PIMAGE_NT_HEADERS
-PEHeaderFromHModule (HMODULE hModule, bool &is_64bit)
+PEHeaderFromHModule (HMODULE hModule)
{
- PIMAGE_NT_HEADERS pNTHeader;
-
if (PIMAGE_DOS_HEADER (hModule) ->e_magic != IMAGE_DOS_SIGNATURE)
- pNTHeader = NULL;
- else
+ return NULL;
+
+ PIMAGE_NT_HEADERS pNTHeader =
+ PIMAGE_NT_HEADERS (PBYTE (hModule)
+ + PIMAGE_DOS_HEADER (hModule) ->e_lfanew);
+ if (pNTHeader->Signature != IMAGE_NT_SIGNATURE)
+ return NULL;
+
+ /* Return valid PIMAGE_NT_HEADERS only for supported architectures. */
+ switch (pNTHeader->FileHeader.Machine)
{
- pNTHeader = PIMAGE_NT_HEADERS (PBYTE (hModule)
- + PIMAGE_DOS_HEADER (hModule) ->e_lfanew);
- if (pNTHeader->Signature == IMAGE_NT_SIGNATURE)
- pNTHeader = NULL;
- else if (pNTHeader->FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64)
- is_64bit = true;
- else
- pNTHeader = NULL;
+ case IMAGE_FILE_MACHINE_AMD64:
+ break;
+ default:
+ return NULL;
}
return pNTHeader;
@@ -273,10 +275,8 @@ find_first_notloaded_dll (path_conv& pc)
if (!hm)
goto out;
- bool is_64bit;
- pExeNTHdr = PEHeaderFromHModule (hm, is_64bit);
-
- if (!pExeNTHdr || !is_64bit)
+ pExeNTHdr = PEHeaderFromHModule (hm);
+ if (!pExeNTHdr)
goto out;
importRVA = pExeNTHdr->OptionalHeader.DataDirectory
@@ -333,12 +333,11 @@ void *
hook_or_detect_cygwin (const char *name, const void *fn, WORD& subsys, HANDLE h)
{
HMODULE hm = fn ? GetModuleHandle (NULL) : (HMODULE) name;
- bool is_64bit;
- PIMAGE_NT_HEADERS pExeNTHdr = PEHeaderFromHModule (hm, is_64bit);
+ PIMAGE_NT_HEADERS pExeNTHdr = PEHeaderFromHModule (hm);
/* Shortcut. We don't have to do anything further from here, if the
executable's architecture doesn't match. */
- if (!pExeNTHdr || !is_64bit)
+ if (!pExeNTHdr)
return NULL;
DWORD importRVA, importRVASize;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-28 14:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-28 14:44 [newlib-cygwin] Cygwin: Fix previous attempt to drop i386 targets from hookapi 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).