60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
|
|
#pragma once
|
|
|
|
#if !defined(MIJIN_UTIL_OS_HPP_INCLUDED)
|
|
#define MIJIN_UTIL_OS_HPP_INCLUDED 1
|
|
|
|
#include <csignal>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include "../detect.hpp"
|
|
|
|
namespace mijin
|
|
{
|
|
|
|
//
|
|
// public defines
|
|
//
|
|
|
|
//
|
|
// public constants
|
|
//
|
|
|
|
//
|
|
// public types
|
|
//
|
|
|
|
struct LibraryHandle
|
|
{
|
|
void* data = nullptr;
|
|
|
|
constexpr operator bool() const noexcept { return data != nullptr; }
|
|
constexpr bool operator!() const noexcept { return data == nullptr; }
|
|
};
|
|
|
|
//
|
|
// public functions
|
|
//
|
|
|
|
[[nodiscard]] LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept;
|
|
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept;
|
|
void setCurrentThreadName(const char* threadName) noexcept;
|
|
|
|
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept;
|
|
|
|
} // namespace mijin
|
|
|
|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX || MIJIN_TARGET_OS == MIJIN_OS_OSX
|
|
#if !defined(SIGTRAP)
|
|
static constexpr int SIGTRAP = 5;
|
|
#endif
|
|
#define _debugBreak() (void) std::raise(SIGTRAP)
|
|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
|
extern "C" __declspec(dllimport) void __stdcall DebugBreak();
|
|
#define _debugBreak() DebugBreak()
|
|
#else
|
|
#define _debugBreak() ((void)0)
|
|
#endif
|
|
|
|
#endif // !defined(MIJIN_UTIL_OS_HPP_INCLUDED)
|