From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21693 invoked by alias); 14 Jan 2009 06:23:16 -0000 Received: (qmail 21680 invoked by uid 22791); 14 Jan 2009 06:23:15 -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, 14 Jan 2009 06:22:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 2D6F02A9649 for ; Wed, 14 Jan 2009 01:22:37 -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 yvffIJjEk85B for ; Wed, 14 Jan 2009 01:22:37 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 7E3792A963A for ; Wed, 14 Jan 2009 01:22:35 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 69308E7ACD; Wed, 14 Jan 2009 10:22:28 +0400 (RET) Date: Wed, 14 Jan 2009 06:23:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: Re: [RFA/win32] Avoid a couple of name collisions in win32-nat.c Message-ID: <20090114062228.GC24105@adacore.com> References: <20090107112422.GB1751@adacore.com> <20090107165734.GD31906@ednor.casa.cgf.cx> <20090109104140.GD24105@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="1giRMj6yz/+FOIRq" Content-Disposition: inline In-Reply-To: <20090109104140.GD24105@adacore.com> 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/msg00305.txt.bz2 --1giRMj6yz/+FOIRq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2084 > > >2009-01-07 Joel Brobecker > > > > > > * 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 * windows-nat.c (set_process_privilege): Rename OpenProcessToken, LookupPrivilegeValue and AdjustTokenPrivileges by prefixing them with "advapi32_". Adjust the code accordingly. -- Joel --1giRMj6yz/+FOIRq Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="advapi.diff" Content-length: 2909 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 --1giRMj6yz/+FOIRq--