DPC++ Runtime
Runtime libraries for oneAPI DPC++
windows_os_utils.hpp
Go to the documentation of this file.
1 //==-- windows_os_utils.hpp - Header file with common utils for Windows --==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===--------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <shlwapi.h>
12 
13 using OSModuleHandle = intptr_t;
15 inline OSModuleHandle getOSModuleHandle(const void *VirtAddr) {
16  HMODULE PhModule;
17  DWORD Flag = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
18  GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
19  auto LpModuleAddr = reinterpret_cast<LPCSTR>(VirtAddr);
20  if (!GetModuleHandleExA(Flag, LpModuleAddr, &PhModule)) {
21  // Expect the caller to check for zero and take
22  // necessary action
23  return 0;
24  }
25  if (PhModule == GetModuleHandleA(nullptr))
26  return ExeModuleHandle;
27  return reinterpret_cast<OSModuleHandle>(PhModule);
28 }
OSModuleHandle getOSModuleHandle(const void *VirtAddr)
constexpr OSModuleHandle ExeModuleHandle
intptr_t OSModuleHandle