Files
FEX-Emu--FEX/Source/Windows/Common/Priv.h
T
Billy Laws 0e069f1e97 Windows: Introduce a minimal CRT replacement
It is dangerous for FEX to rely on the system CRT as calls can have side
effects that are also visible to the running application, and if patches
are applied to any CRT exports used during compilation the call checker
would trigger a reentry into the JIT to compile the patch and hence
deadlock. Only functions that FEX actively uses are implemented, with
the rest triggering an abort.
2024-08-07 15:49:41 +00:00

66 lines
1.4 KiB
C++

#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(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) \
Ret Name Args; \
Ret(*__imp_##Name) Args = Name; \
Ret(*__imp_aux_##Name) Args = Name; \
Ret Name Args