Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA/win32] Problem storing result of GetProcAddress
@ 2009-01-07 11:43 Joel Brobecker
  2009-01-07 17:04 ` Christopher Faylor
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2009-01-07 11:43 UTC (permalink / raw)
  To: gdb-patches

[-- 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;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA/win32] Problem storing result of GetProcAddress
  2009-01-07 11:43 [RFA/win32] Problem storing result of GetProcAddress Joel Brobecker
@ 2009-01-07 17:04 ` Christopher Faylor
  2009-01-09 10:49   ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Faylor @ 2009-01-07 17:04 UTC (permalink / raw)
  To: gdb-patches, Joel Brobecker

On Wed, Jan 07, 2009 at 03:43:22PM +0400, Joel Brobecker wrote:
>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?

Yes.  I guess that means that the rename to prefix kernel32_ is approved
too but I'd appreciate it if you would universally add the kernel32_ prefix
to everything that is dynamically derived from kernel32.

cgf


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA/win32] Problem storing result of GetProcAddress
  2009-01-07 17:04 ` Christopher Faylor
@ 2009-01-09 10:49   ` Joel Brobecker
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Brobecker @ 2009-01-09 10:49 UTC (permalink / raw)
  To: gdb-patches

> >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.
>
> Yes.

Thank you! Checked in.

-- 
Joel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-01-09 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-07 11:43 [RFA/win32] Problem storing result of GetProcAddress Joel Brobecker
2009-01-07 17:04 ` Christopher Faylor
2009-01-09 10:49   ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox