]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/i386-io-windows.h
libpci: i386-io-windows.h: Fix error code in ERROR_PRIVILEGE_NOT_HELD code path
[pciutils.git] / lib / i386-io-windows.h
index ac2a55dfb7ba337f41cf712de86c3dcfc69a167e..8089d19b3a28922bfe93d674b4a0a801dc3966cb 100644 (file)
@@ -5,7 +5,9 @@
  *     Copyright (c) 2006 Martin Mares <mj@ucw.cz>
  *     Copyright (c) 2021 Pali Rohár <pali@kernel.org>
  *
  *     Copyright (c) 2006 Martin Mares <mj@ucw.cz>
  *     Copyright (c) 2021 Pali Rohár <pali@kernel.org>
  *
- *     Can be freely distributed and used under the terms of the GNU GPL.
+ *     Can be freely distributed and used under the terms of the GNU GPL v2+
+ *
+ *     SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <io.h>
  */
 
 #include <io.h>
@@ -107,16 +109,13 @@ unsigned long _inpd(unsigned short port);
  * function conflicts with some MSVC intrinsic.
  * MSVC supports inline assembly via __asm keyword in 32-bit mode only.
  * GCC version 4.9.0 and higher provides __builtin_ia32_readeflags_uXX()
  * function conflicts with some MSVC intrinsic.
  * MSVC supports inline assembly via __asm keyword in 32-bit mode only.
  * GCC version 4.9.0 and higher provides __builtin_ia32_readeflags_uXX()
- * builtin for XX-mode.
+ * builtin for XX-mode. This builtin is also available as __readeflags()
+ * function indirectly via <x86intrin.h> header file.
  */
 #if defined(_MSC_VER) && (_MSC_VER >= 1500 || (_MSC_VER >= 1400 && defined(__BUILDMACHINE__)))
 #pragma intrinsic(__readeflags)
 #elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 9) || (__GNUC__ > 4))
  */
 #if defined(_MSC_VER) && (_MSC_VER >= 1500 || (_MSC_VER >= 1400 && defined(__BUILDMACHINE__)))
 #pragma intrinsic(__readeflags)
 #elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 9) || (__GNUC__ > 4))
-#ifdef __x86_64__
-#define __readeflags() __builtin_ia32_readeflags_u64()
-#else
-#define __readeflags() __builtin_ia32_readeflags_u32()
-#endif
+#include <x86intrin.h>
 #elif defined(_MSC_VER) && defined(_M_IX86)
 static inline unsigned int
 __readeflags(void)
 #elif defined(_MSC_VER) && defined(_M_IX86)
 static inline unsigned int
 __readeflags(void)
@@ -1144,7 +1143,7 @@ SetProcessUserModeIOPL(VOID)
    */
 
   if (!LookupPrivilegeValue(NULL, SE_TCB_NAME, &luid_tcb_privilege))
    */
 
   if (!LookupPrivilegeValue(NULL, SE_TCB_NAME, &luid_tcb_privilege))
-    goto err_not_implemented;
+    goto err_privilege_not_held;
 
   /*
    * If the current thread has already Tcb privilege enabled then there
 
   /*
    * If the current thread has already Tcb privilege enabled then there
@@ -1346,7 +1345,8 @@ intel_setup_io(struct pci_access *a)
   /* On NT-based systems issue ProcessUserModeIOPL syscall which changes IOPL to 3. */
   if (!SetProcessUserModeIOPL())
     {
   /* On NT-based systems issue ProcessUserModeIOPL syscall which changes IOPL to 3. */
   if (!SetProcessUserModeIOPL())
     {
-      a->warning("NT ProcessUserModeIOPL call failed with error: %lu.", (unsigned long int)GetLastError());
+      DWORD error = GetLastError();
+      a->debug("NT ProcessUserModeIOPL call failed: %s.", error == ERROR_INVALID_FUNCTION ? "Not Implemented" : error == ERROR_PRIVILEGE_NOT_HELD ? "Access Denied" : "Operation Failed");
       return 0;
     }
 
       return 0;
     }