From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: Re: [RFA/win32] Avoid a couple of name collisions in win32-nat.c
Date: Wed, 14 Jan 2009 06:23:00 -0000 [thread overview]
Message-ID: <20090114062228.GC24105@adacore.com> (raw)
In-Reply-To: <20090109104140.GD24105@adacore.com>
[-- Attachment #1: Type: text/plain, Size: 2084 bytes --]
> > >2009-01-07 Joel Brobecker <brobecker@adacore.com>
> > >
> > > * win32-nat.c (kernel32_DebugSetProcessKillOnExit): Renames
> > > DebugSetProcessKillOnExit. Update all uses in this file.
> > > (kernel32_DebugActiveProcessStop): Renames DebugActiveProcessStop.
> > > Update all uses in this file.
>
> This one is now in. I will review ASAP all the names we are using
> when importing routines from DLLs, to see if there are others that
> might need an adjustment.
Just for the record, Chris asked:
| 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.
I double-checked every call to GetProcAddress, and the kernel32_
prefix is already added to all the function pointers related to
kernel32 routines.
There are a bunch of function pointers whose name is still identical
to the function name:
static BOOL WINAPI (*OpenProcessToken)(HANDLE, DWORD, PHANDLE);
static BOOL WINAPI (*LookupPrivilegeValue)(LPCSTR, LPCSTR, PLUID);
static BOOL WINAPI (*AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES,
DWORD, PTOKEN_PRIVILEGES, PDWORD);
But these routines are from advapi32.dll, and are declared inside
a function (set_process_priviledge).
I don't think you really wanted me to rename this variables too,
since local variables should not cause a collision (they should just
hide the global names, if any). And because everything is local,
the addition of the advapi32_ prefix does make the reading of the
code a little harder, IMO. But just in case, here is the corresponding
patch. It's untested for now, but I can test it before checking in.
It does compile, though.
2009-01-14 Joel Brobecker <brobecker@adacore.com>
* windows-nat.c (set_process_privilege): Rename OpenProcessToken,
LookupPrivilegeValue and AdjustTokenPrivileges by prefixing them
with "advapi32_". Adjust the code accordingly.
--
Joel
[-- Attachment #2: advapi.diff --]
[-- Type: text/plain, Size: 2909 bytes --]
Index: windows-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/windows-nat.c,v
retrieving revision 1.178
diff -u -p -r1.178 windows-nat.c
--- windows-nat.c 14 Jan 2009 05:27:48 -0000 1.178
+++ windows-nat.c 14 Jan 2009 06:12:23 -0000
@@ -1588,10 +1588,10 @@ static int
set_process_privilege (const char *privilege, BOOL enable)
{
static HMODULE advapi32 = NULL;
- static BOOL WINAPI (*OpenProcessToken)(HANDLE, DWORD, PHANDLE);
- static BOOL WINAPI (*LookupPrivilegeValue)(LPCSTR, LPCSTR, PLUID);
- static BOOL WINAPI (*AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES,
- DWORD, PTOKEN_PRIVILEGES, PDWORD);
+ static BOOL WINAPI (*advapi32_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
+ static BOOL WINAPI (*advapi32_LookupPrivilegeValue)(LPCSTR, LPCSTR, PLUID);
+ static BOOL WINAPI (*advapi32_AdjustTokenPrivileges)
+ (HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
HANDLE token_hdl = NULL;
LUID restore_priv;
@@ -1606,36 +1606,38 @@ set_process_privilege (const char *privi
{
if (!(advapi32 = LoadLibrary ("advapi32.dll")))
goto out;
- if (!OpenProcessToken)
- OpenProcessToken =
+ if (!advapi32_OpenProcessToken)
+ advapi32_OpenProcessToken =
(void *) GetProcAddress (advapi32, "OpenProcessToken");
- if (!LookupPrivilegeValue)
- LookupPrivilegeValue =
+ if (!advapi32_LookupPrivilegeValue)
+ advapi32_LookupPrivilegeValue =
(void *) GetProcAddress (advapi32, "LookupPrivilegeValueA");
- if (!AdjustTokenPrivileges)
- AdjustTokenPrivileges =
+ if (!advapi32_AdjustTokenPrivileges)
+ advapi32_AdjustTokenPrivileges =
(void *) GetProcAddress (advapi32, "AdjustTokenPrivileges");
- if (!OpenProcessToken || !LookupPrivilegeValue || !AdjustTokenPrivileges)
+ if (!advapi32_OpenProcessToken
+ || !advapi32_LookupPrivilegeValue
+ || !advapi32_AdjustTokenPrivileges)
{
advapi32 = NULL;
goto out;
}
}
- if (!OpenProcessToken (GetCurrentProcess (),
- TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
- &token_hdl))
+ if (!advapi32_OpenProcessToken (GetCurrentProcess (),
+ TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
+ &token_hdl))
goto out;
- if (!LookupPrivilegeValue (NULL, privilege, &restore_priv))
+ if (!advapi32_LookupPrivilegeValue (NULL, privilege, &restore_priv))
goto out;
new_priv.PrivilegeCount = 1;
new_priv.Privileges[0].Luid = restore_priv;
new_priv.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0;
- if (!AdjustTokenPrivileges (token_hdl, FALSE, &new_priv,
- sizeof orig_priv, &orig_priv, &size))
+ if (!advapi32_AdjustTokenPrivileges (token_hdl, FALSE, &new_priv,
+ sizeof orig_priv, &orig_priv, &size))
goto out;
#if 0
/* Disabled, otherwise every `attach' in an unprivileged user session
next prev parent reply other threads:[~2009-01-14 6:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-07 11:24 Joel Brobecker
2009-01-07 16:57 ` Christopher Faylor
2009-01-08 12:53 ` Joel Brobecker
2009-01-09 10:42 ` Joel Brobecker
2009-01-14 6:23 ` Joel Brobecker [this message]
2009-01-14 15:08 ` Christopher Faylor
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=20090114062228.GC24105@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