public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: Fix previous attempt to drop i386 targets from hookapi
Date: Thu, 28 Jul 2022 14:44:58 +0000 (GMT)	[thread overview]
Message-ID: <20220728144458.2D81C3857C51@sourceware.org> (raw)

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;


                 reply	other threads:[~2022-07-28 14:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728144458.2D81C3857C51@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).