commit 644374f9cc9cd4ffc07af020ac9404c8d9d944ca
parent 99d13f7b5029b42901cf08b0f326fbf0a3be001b
Author: David Goulet <dgoulet@torproject.org>
Date: Tue, 28 Jan 2025 13:27:14 -0500
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 <dgoulet@torproject.org>
Diffstat:
1 file changed, 33 insertions(+), 32 deletions(-)
diff --git 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