Move files to core

- OsLibrary class
- sku_info directory
- gmm_lib.h header

Change-Id: Ia86280e61cd2913c546afc40c3751b42e04ab137
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-11-19 11:49:19 +01:00
committed by sys_ocldev
parent e7ee6daaa0
commit 13921f698e
81 changed files with 135 additions and 109 deletions

View File

@@ -8,6 +8,7 @@ set(NEO_CORE_OS_INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/aub_memory_operations_handler.h
${CMAKE_CURRENT_SOURCE_DIR}/os_library.h
${CMAKE_CURRENT_SOURCE_DIR}/os_memory.h
)

View File

@@ -8,6 +8,8 @@ set(NEO_CORE_OS_INTERFACE_LINUX
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_env_reader.h
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_library_linux.h
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.h
)

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/os_interface/linux/os_library_linux.h"
#include "core/helpers/debug_helpers.h"
#include <dlfcn.h>
namespace NEO {
OsLibrary *OsLibrary::load(const std::string &name) {
auto ptr = new (std::nothrow) Linux::OsLibrary(name);
if (ptr == nullptr)
return nullptr;
if (!ptr->isLoaded()) {
delete ptr;
return nullptr;
}
return ptr;
}
namespace Linux {
OsLibrary::OsLibrary(const std::string &name) {
if (name.empty()) {
this->handle = dlopen(0, RTLD_LAZY);
} else {
#ifdef SANITIZER_BUILD
constexpr auto dlopenFlag = RTLD_LAZY;
#else
constexpr auto dlopenFlag = RTLD_LAZY | RTLD_DEEPBIND;
#endif
this->handle = dlopen(name.c_str(), dlopenFlag);
}
}
OsLibrary::~OsLibrary() {
if (this->handle != nullptr) {
dlclose(this->handle);
this->handle = nullptr;
}
}
bool OsLibrary::isLoaded() {
return this->handle != nullptr;
}
void *OsLibrary::getProcAddress(const std::string &procName) {
DEBUG_BREAK_IF(this->handle == nullptr);
return dlsym(this->handle, procName.c_str());
}
} // namespace Linux
} // namespace NEO

View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "core/os_interface/os_library.h"
namespace NEO {
namespace Linux {
class OsLibrary : public NEO::OsLibrary {
private:
void *handle;
public:
OsLibrary(const std::string &name);
~OsLibrary() override;
bool isLoaded() override;
void *getProcAddress(const std::string &procName) override;
};
} // namespace Linux
} // namespace NEO

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <string>
#include <type_traits>
namespace NEO {
struct ConvertibleProcAddr {
template <typename T>
operator T *() const {
static_assert(std::is_function<T>::value, "Cannot convert to non-function and non-void* type");
return reinterpret_cast<T *>(ptr);
}
operator void *() const {
return ptr;
}
void *ptr = nullptr;
};
class OsLibrary {
protected:
OsLibrary() = default;
public:
virtual ~OsLibrary() = default;
static OsLibrary *load(const std::string &name);
ConvertibleProcAddr operator[](const std::string &name) {
return ConvertibleProcAddr{getProcAddress(name)};
}
virtual void *getProcAddress(const std::string &procName) = 0;
virtual bool isLoaded() = 0;
};
} // namespace NEO

View File

@@ -8,6 +8,8 @@ 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}/os_library_win.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_library_win.h
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_win.cpp
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_win.h
${CMAKE_CURRENT_SOURCE_DIR}/windows_wrapper.h

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "core/os_interface/windows/os_library_win.h"
namespace NEO {
OsLibrary *OsLibrary::load(const std::string &name) {
Windows::OsLibrary *ptr = new Windows::OsLibrary(name);
if (!ptr->isLoaded()) {
delete ptr;
return nullptr;
}
return ptr;
}
namespace Windows {
decltype(&LoadLibraryExA) OsLibrary::loadLibraryExA = LoadLibraryExA;
decltype(&GetModuleFileNameA) OsLibrary::getModuleFileNameA = GetModuleFileNameA;
extern "C" IMAGE_DOS_HEADER __ImageBase;
__inline HINSTANCE GetModuleHINSTANCE() { return (HINSTANCE)&__ImageBase; }
HMODULE OsLibrary::loadDependency(const std::string &dependencyFileName) const {
char dllPath[MAX_PATH];
DWORD length = getModuleFileNameA(GetModuleHINSTANCE(), dllPath, MAX_PATH);
for (DWORD idx = length; idx > 0; idx--) {
if (dllPath[idx - 1] == '\\') {
dllPath[idx] = '\0';
break;
}
}
strcat_s(dllPath, MAX_PATH, dependencyFileName.c_str());
return loadLibraryExA(dllPath, NULL, 0);
}
OsLibrary::OsLibrary(const std::string &name) {
if (name.empty()) {
this->handle = GetModuleHandleA(nullptr);
} else {
this->handle = loadDependency(name);
if (this->handle == nullptr) {
this->handle = ::LoadLibraryA(name.c_str());
}
}
}
OsLibrary::~OsLibrary() {
if ((this->handle != nullptr) && (this->handle != GetModuleHandleA(nullptr))) {
::FreeLibrary(this->handle);
this->handle = nullptr;
}
}
bool OsLibrary::isLoaded() {
return this->handle != nullptr;
}
void *OsLibrary::getProcAddress(const std::string &procName) {
return ::GetProcAddress(this->handle, procName.c_str());
}
} // namespace Windows
} // namespace NEO

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "core/os_interface/os_library.h"
#define UMDF_USING_NTSTATUS
#include "core/os_interface/windows/windows_wrapper.h"
namespace NEO {
namespace Windows {
class OsLibrary : public NEO::OsLibrary {
private:
HMODULE handle;
public:
OsLibrary(const std::string &name);
~OsLibrary();
bool isLoaded();
void *getProcAddress(const std::string &procName);
protected:
HMODULE loadDependency(const std::string &dependencyFileName) const;
static decltype(&LoadLibraryExA) loadLibraryExA;
static decltype(&GetModuleFileNameA) getModuleFileNameA;
};
} // namespace Windows
} // namespace NEO