From: David Goulet Date: Tue, 28 Jan 2025 18:27:14 +0000 (-0500) Subject: hashx: Move Windows function within another ifdef X-Git-Tag: tor-0.4.8.14~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=644374f9cc9cd4ffc07af020ac9404c8d9d944ca;p=thirdparty%2Ftor.git hashx: Move Windows function within another ifdef Function only used within the hugepage ifdef for Windows so move it there so we avoid a unused function warning on our Windows CI: src/ext/equix/hashx/src/virtual_memory.c:30:13: error: 'set_privilege' defined but not used [-Werror=unused-function] 30 | static bool set_privilege(const char* pszPrivilege, BOOL bEnable) { | ^~~~~~~~~~~~~ Signed-off-by: David Goulet --- diff --git a/src/ext/equix/hashx/src/virtual_memory.c b/src/ext/equix/hashx/src/virtual_memory.c index 2dff6f7552..6cc70f8be1 100644 --- a/src/ext/equix/hashx/src/virtual_memory.c +++ b/src/ext/equix/hashx/src/virtual_memory.c @@ -25,38 +25,6 @@ #endif #endif -#ifdef HASHX_WIN - -static bool set_privilege(const char* pszPrivilege, BOOL bEnable) { - HANDLE hToken; - TOKEN_PRIVILEGES tp; - BOOL status; - DWORD error; - - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES - | TOKEN_QUERY, &hToken)) - return false; - - if (!LookupPrivilegeValue(NULL, pszPrivilege, &tp.Privileges[0].Luid)) - return false; - - tp.PrivilegeCount = 1; - - if (bEnable) - tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - else - tp.Privileges[0].Attributes = 0; - - status = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, - (PTOKEN_PRIVILEGES)NULL, 0); - error = GetLastError(); - - CloseHandle(hToken); - - return status && (error == ERROR_SUCCESS); -} -#endif - void* hashx_vm_alloc(size_t bytes) { void* mem; #ifdef HASHX_WIN @@ -91,6 +59,39 @@ bool hashx_vm_rx(void* ptr, size_t bytes) { } #ifdef EQUIX_SUPPORT_HUGEPAGES + +#ifdef HASHX_WIN + +static bool set_privilege(const char* pszPrivilege, BOOL bEnable) { + HANDLE hToken; + TOKEN_PRIVILEGES tp; + BOOL status; + DWORD error; + + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES + | TOKEN_QUERY, &hToken)) + return false; + + if (!LookupPrivilegeValue(NULL, pszPrivilege, &tp.Privileges[0].Luid)) + return false; + + tp.PrivilegeCount = 1; + + if (bEnable) + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + else + tp.Privileges[0].Attributes = 0; + + status = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, + (PTOKEN_PRIVILEGES)NULL, 0); + error = GetLastError(); + + CloseHandle(hToken); + + return status && (error == ERROR_SUCCESS); +} +#endif /* HASHX_WIN */ + void* hashx_vm_alloc_huge(size_t bytes) { void* mem; #ifdef HASHX_WIN