]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
hashx: Move Windows function within another ifdef
authorDavid Goulet <dgoulet@torproject.org>
Tue, 28 Jan 2025 18:27:14 +0000 (13:27 -0500)
committerDavid Goulet <dgoulet@torproject.org>
Tue, 28 Jan 2025 18:28:29 +0000 (13:28 -0500)
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>
src/ext/equix/hashx/src/virtual_memory.c

index 2dff6f7552e69cff95b8b5b7576c355eb7ca224d..6cc70f8be13ce67c3931b31f487336dc8659947e 100644 (file)
 #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