mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
Move DebugSettingsReader to a core dir
Related-To: NEO-3677 Change-Id: I3374abde6717be20c064ec6d65c0751a783f5138 Signed-off-by: Jobczyk, Lukasz <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
1ec794286f
commit
10795c716f
16
core/os_interface/windows/CMakeLists.txt
Normal file
16
core/os_interface/windows/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# Copyright (C) 2019 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(NEO_CORE_OS_INTERFACE_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug_registry_reader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug_registry_reader.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_WINDOWS ${NEO_CORE_OS_INTERFACE_WINDOWS})
|
||||
endif()
|
||||
130
core/os_interface/windows/debug_registry_reader.cpp
Normal file
130
core/os_interface/windows/debug_registry_reader.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/os_interface/windows/debug_registry_reader.h"
|
||||
|
||||
#include "core/os_interface/windows/windows_wrapper.h"
|
||||
#include "core/utilities/debug_settings_reader.h"
|
||||
#include "runtime/os_interface/debug_settings_manager.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
SettingsReader *SettingsReader::createOsReader(bool userScope) {
|
||||
return new RegistryReader(userScope);
|
||||
}
|
||||
SettingsReader *SettingsReader::createOsReader(const std::string ®Key) {
|
||||
return new RegistryReader("Software\\Intel\\IGFX\\OCL\\" + regKey);
|
||||
}
|
||||
|
||||
RegistryReader::RegistryReader(bool userScope) {
|
||||
igdrclHkeyType = userScope ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
|
||||
setUpProcessName();
|
||||
}
|
||||
RegistryReader::RegistryReader(const std::string ®Key) : registryReadRootKey(regKey) {
|
||||
setUpProcessName();
|
||||
}
|
||||
void RegistryReader::setUpProcessName() {
|
||||
char buff[MAX_PATH];
|
||||
GetModuleFileNameA(nullptr, buff, MAX_PATH);
|
||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||
processName = "";
|
||||
}
|
||||
processName.assign(buff);
|
||||
}
|
||||
const char *RegistryReader::appSpecificLocation(const std::string &name) {
|
||||
if (processName.length() > 0)
|
||||
return processName.c_str();
|
||||
return name.c_str();
|
||||
}
|
||||
|
||||
bool RegistryReader::getSetting(const char *settingName, bool defaultValue) {
|
||||
return getSetting(settingName, static_cast<int32_t>(defaultValue)) ? true : false;
|
||||
}
|
||||
|
||||
int32_t RegistryReader::getSetting(const char *settingName, int32_t defaultValue) {
|
||||
HKEY Key;
|
||||
DWORD value = defaultValue;
|
||||
DWORD success = ERROR_SUCCESS;
|
||||
|
||||
success = RegOpenKeyExA(igdrclHkeyType,
|
||||
registryReadRootKey.c_str(),
|
||||
0,
|
||||
KEY_READ,
|
||||
&Key);
|
||||
|
||||
if (ERROR_SUCCESS == success) {
|
||||
DWORD regType;
|
||||
DWORD size = sizeof(ULONG);
|
||||
|
||||
success = RegQueryValueExA(Key,
|
||||
settingName,
|
||||
NULL,
|
||||
®Type,
|
||||
(LPBYTE)&value,
|
||||
&size);
|
||||
RegCloseKey(Key);
|
||||
value = ERROR_SUCCESS == success ? value : defaultValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string RegistryReader::getSetting(const char *settingName, const std::string &value) {
|
||||
HKEY Key;
|
||||
DWORD success = ERROR_SUCCESS;
|
||||
std::string keyValue = value;
|
||||
|
||||
success = RegOpenKeyExA(igdrclHkeyType,
|
||||
registryReadRootKey.c_str(),
|
||||
0,
|
||||
KEY_READ,
|
||||
&Key);
|
||||
if (ERROR_SUCCESS == success) {
|
||||
DWORD regType = REG_NONE;
|
||||
DWORD regSize = 0;
|
||||
|
||||
success = RegQueryValueExA(Key,
|
||||
settingName,
|
||||
NULL,
|
||||
®Type,
|
||||
NULL,
|
||||
®Size);
|
||||
if (success == ERROR_SUCCESS && regType == REG_SZ) {
|
||||
char *regData = new char[regSize];
|
||||
success = RegQueryValueExA(Key,
|
||||
settingName,
|
||||
NULL,
|
||||
®Type,
|
||||
(LPBYTE)regData,
|
||||
®Size);
|
||||
keyValue.assign(regData);
|
||||
delete[] regData;
|
||||
} else if (success == ERROR_SUCCESS && regType == REG_BINARY) {
|
||||
std::unique_ptr<wchar_t[]> regData(new wchar_t[regSize]);
|
||||
success = RegQueryValueExA(Key,
|
||||
settingName,
|
||||
NULL,
|
||||
®Type,
|
||||
(LPBYTE)regData.get(),
|
||||
®Size);
|
||||
|
||||
size_t charsConverted = 0;
|
||||
std::unique_ptr<char[]> convertedData(new char[regSize]);
|
||||
|
||||
wcstombs_s(&charsConverted, convertedData.get(), regSize, regData.get(), regSize);
|
||||
|
||||
keyValue.assign(convertedData.get());
|
||||
}
|
||||
|
||||
RegCloseKey(Key);
|
||||
}
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
}; // namespace NEO
|
||||
34
core/os_interface/windows/debug_registry_reader.h
Normal file
34
core/os_interface/windows/debug_registry_reader.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/utilities/debug_settings_reader.h"
|
||||
|
||||
#include "os_inc.h"
|
||||
#include <Windows.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
namespace NEO {
|
||||
class RegistryReader : public SettingsReader {
|
||||
public:
|
||||
int32_t getSetting(const char *settingName, int32_t defaultValue) override;
|
||||
bool getSetting(const char *settingName, bool defaultValue) override;
|
||||
std::string getSetting(const char *settingName, const std::string &value) override;
|
||||
RegistryReader(bool userScope);
|
||||
RegistryReader(const std::string ®Key);
|
||||
const char *appSpecificLocation(const std::string &name) override;
|
||||
|
||||
protected:
|
||||
HKEY igdrclHkeyType = HKEY_LOCAL_MACHINE;
|
||||
std::string registryReadRootKey = "Software\\Intel\\IGFX\\OCL";
|
||||
void setUpProcessName();
|
||||
std::string processName;
|
||||
};
|
||||
} // namespace NEO
|
||||
32
core/os_interface/windows/windows_wrapper.h
Normal file
32
core/os_interface/windows/windows_wrapper.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4005)
|
||||
#include <ntstatus.h>
|
||||
#pragma warning(pop)
|
||||
// There is a conflict with max/min defined as macro in windows headers with std::max/std::min
|
||||
#undef min
|
||||
#undef max
|
||||
#undef RegOpenKeyExA
|
||||
#undef RegQueryValueExA
|
||||
#pragma warning(disable : 4273)
|
||||
LSTATUS APIENTRY RegOpenKeyExA(
|
||||
HKEY hKey,
|
||||
LPCSTR lpSubKey,
|
||||
DWORD ulOptions,
|
||||
REGSAM samDesired,
|
||||
PHKEY phkResult);
|
||||
LSTATUS APIENTRY RegQueryValueExA(
|
||||
HKEY hKey,
|
||||
LPCSTR lpValueName,
|
||||
LPDWORD lpReserved,
|
||||
LPDWORD lpType,
|
||||
LPBYTE lpData,
|
||||
LPDWORD lpcbData);
|
||||
Reference in New Issue
Block a user