From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30116 invoked by alias); 7 Jan 2009 11:43:36 -0000 Received: (qmail 30090 invoked by uid 22791); 7 Jan 2009 11:43:36 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Jan 2009 11:43:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 8653F2A9620 for ; Wed, 7 Jan 2009 06:43:30 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3lBAsKSPDxCk for ; Wed, 7 Jan 2009 06:43:30 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 9E1F02A9618 for ; Wed, 7 Jan 2009 06:43:29 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 813F9E7ACD; Wed, 7 Jan 2009 15:43:22 +0400 (RET) Date: Wed, 07 Jan 2009 11:43:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/win32] Problem storing result of GetProcAddress Message-ID: <20090107114322.GD1751@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="EY/WZ/HvNxOox07X" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-01/txt/msg00084.txt.bz2 --EY/WZ/HvNxOox07X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1377 Hello, GetProcAddress returns a FARPROC, but the variables that we use to store the result that GetProcAddress returned is typically defined as: static BOOL WINAPI (*GetModuleFileNameExA) (HANDLE, HMODULE *, DWORD, LPDWORD); I cannot define GetModuleFileNameExA as a FARPROC, as FARPROC is a generic type that does not have the correct profile for our function. If the function was defined as a FARPROC, we'd have problems calling the functions, since the number of args and the return value would not match. For now, the laziest way of dealing the problem was to cast the resut to "void *", which shouldn't cause any problem on Windows. Alternatively, we can define a function pointer type for each of the functions we import and then cast the result to that type. 2009-01-07 Joel Brobecker * win32-nat.c (has_detach_ability, set_process_privilege): Cast the result of GetProcAddress to (void *) to avoid a compilation warning. Tested on x86-windows. Note that this depends on one of my previous patches that renames certain global variables: | * win32-nat.c (kernel32_DebugSetProcessKillOnExit): Renames | DebugSetProcessKillOnExit. Update all uses in this file. | (kernel32_DebugActiveProcessStop): Renames DebugActiveProcessStop. | Update all uses in this file. OK to apply? Thanks, -- Joel --EY/WZ/HvNxOox07X Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="farproc.diff" Content-length: 1677 diff --git a/gdb/win32-nat.c b/gdb/win32-nat.c index 1b15dfb..5300731 100644 --- a/gdb/win32-nat.c +++ b/gdb/win32-nat.c @@ -1600,11 +1600,11 @@ has_detach_ability (void) if (kernel32) { if (!kernel32_DebugSetProcessKillOnExit) - kernel32_DebugSetProcessKillOnExit = GetProcAddress (kernel32, - "DebugSetProcessKillOnExit"); + kernel32_DebugSetProcessKillOnExit = + (void *) GetProcAddress (kernel32, "DebugSetProcessKillOnExit"); if (!kernel32_DebugActiveProcessStop) - kernel32_DebugActiveProcessStop = GetProcAddress (kernel32, - "DebugActiveProcessStop"); + kernel32_DebugActiveProcessStop = + (void *) GetProcAddress (kernel32, "DebugActiveProcessStop"); if (kernel32_DebugSetProcessKillOnExit && kernel32_DebugActiveProcessStop) return 1; @@ -1641,13 +1641,14 @@ set_process_privilege (const char *privilege, BOOL enable) if (!(advapi32 = LoadLibrary ("advapi32.dll"))) goto out; if (!OpenProcessToken) - OpenProcessToken = GetProcAddress (advapi32, "OpenProcessToken"); + OpenProcessToken = + (void *) GetProcAddress (advapi32, "OpenProcessToken"); if (!LookupPrivilegeValue) - LookupPrivilegeValue = GetProcAddress (advapi32, - "LookupPrivilegeValueA"); + LookupPrivilegeValue = + (void *) GetProcAddress (advapi32, "LookupPrivilegeValueA"); if (!AdjustTokenPrivileges) - AdjustTokenPrivileges = GetProcAddress (advapi32, - "AdjustTokenPrivileges"); + AdjustTokenPrivileges = + (void *) GetProcAddress (advapi32, "AdjustTokenPrivileges"); if (!OpenProcessToken || !LookupPrivilegeValue || !AdjustTokenPrivileges) { advapi32 = NULL; --EY/WZ/HvNxOox07X--