mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-09 00:00:17 +02:00
Fixes cases where _assert is pulled in by libc++, but is missing dllimport, causing the linker to expect the symbol definition itself to be available.
70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
// SPDX-License-Identifier: MIT
|
|
#pragma once
|
|
|
|
#include <exception>
|
|
#include <winternl.h>
|
|
|
|
static inline __TEB* GetCurrentTEB() {
|
|
return reinterpret_cast<__TEB*>(NtCurrentTeb());
|
|
}
|
|
|
|
static inline __PEB* GetCurrentPEB() {
|
|
return GetCurrentTEB()->Peb;
|
|
}
|
|
|
|
static inline bool WinAPIReturn(NTSTATUS Status) {
|
|
if (!Status) {
|
|
return true;
|
|
}
|
|
GetCurrentTEB()->LastErrorValue = RtlNtStatusToDosError(Status);
|
|
return false;
|
|
}
|
|
|
|
static inline UNICODE_STRING InitUnicodeString(const wchar_t* String) {
|
|
UNICODE_STRING StringDesc;
|
|
RtlInitUnicodeString(&StringDesc, String);
|
|
return StringDesc;
|
|
}
|
|
|
|
static inline STRING InitAnsiString(const char* String) {
|
|
STRING StringDesc;
|
|
RtlInitAnsiString(&StringDesc, String);
|
|
return StringDesc;
|
|
}
|
|
|
|
class ScopedUnicodeString {
|
|
private:
|
|
UNICODE_STRING Str {};
|
|
public:
|
|
ScopedUnicodeString() = default;
|
|
|
|
ScopedUnicodeString(const char* AStr) {
|
|
RtlCreateUnicodeStringFromAsciiz(&Str, AStr);
|
|
}
|
|
|
|
~ScopedUnicodeString() {
|
|
RtlFreeUnicodeString(&Str);
|
|
}
|
|
|
|
UNICODE_STRING* operator->() {
|
|
return &Str;
|
|
}
|
|
|
|
UNICODE_STRING& operator*() {
|
|
return Str;
|
|
}
|
|
};
|
|
|
|
|
|
#define UNIMPLEMENTED() \
|
|
do { \
|
|
NtTerminateProcess(NtCurrentProcess(), 0); \
|
|
__fastfail(0); \
|
|
} while (0)
|
|
|
|
#define DLLEXPORT_FUNC(Ret, Name, Args) \
|
|
extern "C" Ret Name Args; \
|
|
Ret(*__imp_##Name) Args = Name; \
|
|
Ret(*__imp_aux_##Name) Args = Name; \
|
|
Ret Name Args
|