From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 2D81C3857C51; Thu, 28 Jul 2022 14:44:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D81C3857C51 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Fix previous attempt to drop i386 targets from hookapi X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 5192d5ea51dee786ba1cb97b216bd40115dbbf20 X-Git-Newrev: 33395637a1515f1a66e723265d3be2156ff63b21 Message-Id: <20220728144458.2D81C3857C51@sourceware.org> Date: Thu, 28 Jul 2022 14:44:58 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jul 2022 14:44:58 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D33395637a15= 15f1a66e723265d3be2156ff63b21 commit 33395637a1515f1a66e723265d3be2156ff63b21 Author: Corinna Vinschen Date: Thu Jul 28 16:38:01 2022 +0200 Cygwin: Fix previous attempt to drop i386 targets from hookapi =20 Somehow this patch looks like it was pushed before having been finished. Let's try again... =20 Fixes: e46f15c2d168 ("Cygwin: hookapi: drop handling i386 targets") Signed-off-by: Corinna Vinschen 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 =20 /* 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 !=3D IMAGE_DOS_SIGNATURE) - pNTHeader =3D NULL; - else + return NULL; + + PIMAGE_NT_HEADERS pNTHeader =3D + PIMAGE_NT_HEADERS (PBYTE (hModule) + + PIMAGE_DOS_HEADER (hModule) ->e_lfanew); + if (pNTHeader->Signature !=3D IMAGE_NT_SIGNATURE) + return NULL; + + /* Return valid PIMAGE_NT_HEADERS only for supported architectures. */ + switch (pNTHeader->FileHeader.Machine) { - pNTHeader =3D PIMAGE_NT_HEADERS (PBYTE (hModule) - + PIMAGE_DOS_HEADER (hModule) ->e_lfanew); - if (pNTHeader->Signature =3D=3D IMAGE_NT_SIGNATURE) - pNTHeader =3D NULL; - else if (pNTHeader->FileHeader.Machine =3D=3D IMAGE_FILE_MACHINE_AMD= 64) - is_64bit =3D true; - else - pNTHeader =3D NULL; + case IMAGE_FILE_MACHINE_AMD64: + break; + default: + return NULL; } =20 return pNTHeader; @@ -273,10 +275,8 @@ find_first_notloaded_dll (path_conv& pc) if (!hm) goto out; =20 - bool is_64bit; - pExeNTHdr =3D PEHeaderFromHModule (hm, is_64bit); - - if (!pExeNTHdr || !is_64bit) + pExeNTHdr =3D PEHeaderFromHModule (hm); + if (!pExeNTHdr) goto out; =20 importRVA =3D pExeNTHdr->OptionalHeader.DataDirectory @@ -333,12 +333,11 @@ void * hook_or_detect_cygwin (const char *name, const void *fn, WORD& subsys, HAN= DLE h) { HMODULE hm =3D fn ? GetModuleHandle (NULL) : (HMODULE) name; - bool is_64bit; - PIMAGE_NT_HEADERS pExeNTHdr =3D PEHeaderFromHModule (hm, is_64bit); + PIMAGE_NT_HEADERS pExeNTHdr =3D PEHeaderFromHModule (hm); =20 /* 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; =20 DWORD importRVA, importRVASize;