Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions runtime/macos_host/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ compile_guest /MD /c "$FIX/tiny_game.cpp" /Fo"$OUT/tiny_game.obj"
"$LLD/lld-link" /nologo /winsysroot:"$XWIN_DIR" "$OUT/tiny_game.obj" "$OUT/xgameruntime.lib" /out:"$OUT/tiny_game.exe"
compile_guest /MD /c guest/eh_probe.cpp /Fo"$OUT/eh_probe.obj"
"$LLD/lld-link" /nologo /winsysroot:"$XWIN_DIR" "$OUT/eh_probe.obj" /out:"$OUT/eh_probe.exe"
compile_guest /MD /c guest/eh_dll.cpp /Fo"$OUT/eh_dll.obj"
"$LLD/lld-link" /nologo /dll /winsysroot:"$XWIN_DIR" "$OUT/eh_dll.obj" /out:"$OUT/eh_dll.dll"
compile_guest /MD /c guest/eh_module_probe.cpp /Fo"$OUT/eh_module_probe.obj" # run it: exit code 0
"$LLD/lld-link" /nologo /winsysroot:"$XWIN_DIR" "$OUT/eh_module_probe.obj" /out:"$OUT/eh_module_probe.exe"
compile_guest /MT /c guest/eh_probe.cpp /Fo"$OUT/eh_probe_mt.obj" # static CRT: throws go through RaiseException
"$LLD/lld-link" /nologo /winsysroot:"$XWIN_DIR" "$OUT/eh_probe_mt.obj" /out:"$OUT/eh_probe_mt.exe"
printf 'LIBRARY vulkan-1.dll\nEXPORTS\n vkGetInstanceProcAddr\n' > "$OUT/vulkan-1.def"
Expand Down
27 changes: 27 additions & 0 deletions runtime/macos_host/guest/eh_dll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// The DLL eh_module_probe loads: C++ exceptions thrown in a module other than the host's main image, as a game
// mapped by gta6rt's loader throws them.
#include <stdexcept>

static int g_dtors = 0;
struct Guard {
~Guard() { ++g_dtors; }
};
__declspec(noinline) static void deep(int n) {
Guard g;
if (n == 0) throw std::runtime_error("dll");
deep(n - 1);
}

extern "C" __declspec(dllexport) int catch_inside() { // thrown and caught in this DLL: 0
try {
deep(2);
} catch (const std::exception& e) {
return g_dtors == 3 && e.what()[0] == 'd' ? 0 : 1;
}
return 2;
}
extern "C" __declspec(dllexport) void throw_out(int v) { // caught by the caller, in another module
Guard g;
throw v;
}
extern "C" __declspec(dllexport) int dtors() { return g_dtors; }
20 changes: 20 additions & 0 deletions runtime/macos_host/guest/eh_module_probe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// C++ exceptions in a DLL the guest loads (eh_dll.dll): thrown and caught there, and thrown there and caught here.
// Exit code 0, or the number of the first check that failed.
#include <windows.h>

int main() {
HMODULE dll = LoadLibraryA("eh_dll.dll");
if (!dll) return 1;
auto catch_inside = reinterpret_cast<int (*)()>(GetProcAddress(dll, "catch_inside"));
auto throw_out = reinterpret_cast<void (*)(int)>(GetProcAddress(dll, "throw_out")); // C++ type: may throw
auto dtors = reinterpret_cast<int (*)()>(GetProcAddress(dll, "dtors"));
if (catch_inside() != 0) return 2;
int got = 0;
try {
throw_out(9);
} catch (int v) {
got = v;
}
if (got != 9 || dtors() != 4) return 3;
return 0;
}
Loading