From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA/win32] Problem storing result of GetProcAddress
Date: Wed, 07 Jan 2009 11:43:00 -0000 [thread overview]
Message-ID: <20090107114322.GD1751@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]
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 <brobecker@adacore.com>
* 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
[-- Attachment #2: farproc.diff --]
[-- Type: text/plain, Size: 1677 bytes --]
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;
next reply other threads:[~2009-01-07 11:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-07 11:43 Joel Brobecker [this message]
2009-01-07 17:04 ` Christopher Faylor
2009-01-09 10:49 ` Joel Brobecker
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=20090107114322.GD1751@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@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