2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2025-02-15 03:29:17 +08:00
|
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-09-25 15:19:30 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2024-10-17 03:53:07 +08:00
|
|
|
struct OsLibraryCreateProperties {
|
2025-02-15 03:29:17 +08:00
|
|
|
OsLibraryCreateProperties(const std::string &name) : libraryName(name) {}
|
2024-10-17 03:53:07 +08:00
|
|
|
std::string libraryName;
|
|
|
|
std::string *errorValue = nullptr;
|
|
|
|
bool performSelfLoad = false;
|
|
|
|
int *customLoadFlags = nullptr;
|
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class OsLibrary {
|
|
|
|
protected:
|
|
|
|
OsLibrary() = default;
|
2024-10-17 03:53:07 +08:00
|
|
|
static OsLibrary *load(const OsLibraryCreateProperties &properties);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~OsLibrary() = default;
|
|
|
|
|
2024-08-19 20:50:05 +08:00
|
|
|
static decltype(&OsLibrary::load) loadFunc;
|
2020-10-30 20:42:13 +08:00
|
|
|
static const std::string createFullSystemPath(const std::string &name);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-09-25 15:19:30 +08:00
|
|
|
ConvertibleProcAddr operator[](const std::string &name) {
|
|
|
|
return ConvertibleProcAddr{getProcAddress(name)};
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
virtual void *getProcAddress(const std::string &procName) = 0;
|
|
|
|
virtual bool isLoaded() = 0;
|
2023-08-21 20:00:06 +08:00
|
|
|
virtual std::string getFullPath() = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2024-12-20 00:56:46 +08:00
|
|
|
|
|
|
|
bool getLoadedLibVersion(const std::string &libName, const std::string ®exVersionPattern, std::string &outVersion, std::string &errReason);
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|