From 5751a5a0c14c73f885c99721126642a628c18563 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 8 Jun 2024 14:45:39 -0400 Subject: [PATCH] Changes --- CMakeLists.txt | 30 ++++++++++++++++-------------- README.md | 12 +++++++++--- native/src/main.cpp | 2 -- native/src/pipe.cpp | 1 + native/src/trampoline.cpp | 5 +++++ 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a919cd4..820b898 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,20 +11,22 @@ target_include_directories(trampoline-headers INTERFACE include) if(NOT TRAMPOLINE_HEADERS_ONLY) # Check Architecture include(CheckSymbolExists) - check_symbol_exists("__aarch64__" "" USE_NATIVE_RUNTIME) - check_symbol_exists("__x86_64__" "" USE_QEMU_RUNTIME) - - # Include Correct Sub-Project - set(RUNTIME_RPATH "$ORIGIN/../lib/native") - set(RUNTIME_EXTRA_LINK_FLAG "--disable-new-dtags") - target_compile_definitions(trampoline-headers INTERFACE MCPI_BUILD_RUNTIME) - if(USE_NATIVE_RUNTIME) - add_subdirectory(native) - elseif(USE_QEMU_RUNTIME) - add_subdirectory(qemu) - target_compile_definitions(trampoline-headers INTERFACE MCPI_RUNTIME_IS_QEMU) - else() - message(FATAL_ERROR "Unsupported Architecture") + check_symbol_exists("__arm__" "" NO_RUNTIME_NEEDED) + if(NOT NO_RUNTIME_NEEDED) + check_symbol_exists("__aarch64__" "" USE_NATIVE_RUNTIME) + check_symbol_exists("__x86_64__" "" USE_QEMU_RUNTIME) + # Include Correct Sub-Project + set(RUNTIME_RPATH "$ORIGIN/../lib/native") + set(RUNTIME_EXTRA_LINK_FLAG "--disable-new-dtags") + target_compile_definitions(trampoline-headers INTERFACE MCPI_BUILD_RUNTIME) + if(USE_NATIVE_RUNTIME) + add_subdirectory(native) + elseif(USE_QEMU_RUNTIME) + add_subdirectory(qemu) + target_compile_definitions(trampoline-headers INTERFACE MCPI_RUNTIME_IS_QEMU) + else() + message(FATAL_ERROR "Unsupported Architecture") + endif() endif() else() # No-Op Install Function diff --git a/README.md b/README.md index c51167b..c6777ca 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# MCPI Runtime -**Fact:** MCPI is a 32-bit ARM binary. +# MCPI-Reborn Runtime +**Fact:** Minecraft: Pi Edition is a 32-bit ARM program. **Another fact:** Most modern computers do not use 32-bit ARM and therefore cannot run MCPI natively. @@ -16,4 +16,10 @@ QEMU emulates ARM code so MCPI can run on x86 hardware. And the patch adds a sys ### 64-Bit ARM Host QEMU is not necessary on this platform because it can already run 32-bit ARM code natively. -Instead, the runtime is implemented as two processes: a parent and a child. The child becomes MCPI and can send graphics commands to the parent. And because the parent is 64-bit, 32-bit drivers are not needed. \ No newline at end of file +Instead, the runtime is implemented as two processes: a parent and a child. The child becomes MCPI and can send graphics commands to the parent. And because the parent is 64-bit, 32-bit drivers are not needed. + +### 32-Bit ARM Host +This project is unnecessary on this platform. + +### Other Architectures +Any unlisted platforms are unsupported. diff --git a/native/src/main.cpp b/native/src/main.cpp index 778350e..6b4f331 100644 --- a/native/src/main.cpp +++ b/native/src/main.cpp @@ -6,7 +6,6 @@ #include "log.h" #include "memory.h" -#include "trampoline.h" #include "pipe.h" #include "signals.h" @@ -37,7 +36,6 @@ int main(__attribute__((unused)) int argc, char *argv[]) { // Setup Trampoline init_signals(pid); init_memory(pid); - init_trampoline(); // Start Pipes init_pipe_host(pid); diff --git a/native/src/pipe.cpp b/native/src/pipe.cpp index caf47a4..055867f 100644 --- a/native/src/pipe.cpp +++ b/native/src/pipe.cpp @@ -46,6 +46,7 @@ void init_pipe_host(pid_t guest_pid) { // Wait For Commands trampoline_pipe_arguments cmd = {}; while (read(arguments_pipe[PIPE_READ], &cmd, sizeof(trampoline_pipe_arguments)) > 0) { + init_trampoline(); // Only Init If Needed static unsigned char args[MAX_TRAMPOLINE_ARGS_SIZE]; size_t position = 0; while (position < cmd.length) { diff --git a/native/src/trampoline.cpp b/native/src/trampoline.cpp index 353c154..c31a525 100644 --- a/native/src/trampoline.cpp +++ b/native/src/trampoline.cpp @@ -13,6 +13,11 @@ uint32_t trampoline(uint32_t id, const unsigned char *args) { // Init void init_trampoline() { + static bool is_setup = false; + if (is_setup) { + return; + } + is_setup = true; // Open Library void *handle = dlopen("libmedia-layer-trampoline.so", RTLD_NOW); if (handle != nullptr) {