From a0f32a15a7e7077c775474c37e784803d3a152f5 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 8 Jun 2024 16:30:39 -0400 Subject: [PATCH] Finally At A Nice Point --- .gitmodules | 6 ++--- cmake/options/extra-options.cmake | 6 ----- cmake/options/prebuilt-armhf-toolchain.cmake | 20 ++++++++------- dependencies/CMakeLists.txt | 4 +-- dependencies/runtime/CMakeLists.txt | 16 ++++++++++++ dependencies/runtime/src | 1 + dependencies/trampoline/CMakeLists.txt | 16 ------------ dependencies/trampoline/src | 1 - launcher/CMakeLists.txt | 5 +--- launcher/src/bootstrap.cpp | 17 +++--------- launcher/src/crash-report.c | 4 +++ launcher/src/main.cpp | 7 ----- launcher/src/mods.cpp | 8 ------ launcher/src/options/option-list.h | 3 --- libreborn/include/libreborn/config.h.in | 1 - media-layer/trampoline/src/GLESv1_CM.cpp | 27 ++++++++++++++++++++ media-layer/trampoline/src/guest/guest.cpp | 2 +- symbols/src/tile/StemTile.def | 2 +- 18 files changed, 71 insertions(+), 75 deletions(-) create mode 100644 dependencies/runtime/CMakeLists.txt create mode 160000 dependencies/runtime/src delete mode 100644 dependencies/trampoline/CMakeLists.txt delete mode 160000 dependencies/trampoline/src diff --git a/.gitmodules b/.gitmodules index bfb0ea3f..8393efc2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,6 +22,6 @@ [submodule "dependencies/symbol-processor/src"] path = dependencies/symbol-processor/src url = https://gitea.thebrokenrail.com/minecraft-pi-reborn/symbol-processor.git -[submodule "dependencies/trampoline/src"] - path = dependencies/trampoline/src - url = https://gitea.thebrokenrail.com/minecraft-pi-reborn/trampoline.git +[submodule "dependencies/runtime/src"] + path = dependencies/runtime/src + url = https://gitea.thebrokenrail.com/minecraft-pi-reborn/runtime.git diff --git a/cmake/options/extra-options.cmake b/cmake/options/extra-options.cmake index 5b3e70a4..c30049da 100644 --- a/cmake/options/extra-options.cmake +++ b/cmake/options/extra-options.cmake @@ -38,12 +38,6 @@ else() set(BUILD_MEDIA_LAYER_CORE "${BUILD_ARM_COMPONENTS}") endif() -# Trampoline Host -set(MCPI_USE_TRAMPOLINE_HOST FALSE) -if(BUILD_NATIVE_COMPONENTS AND (MCPI_USE_MEDIA_LAYER_TRAMPOLINE OR NOT IS_ARM_TARGETING)) - set(MCPI_USE_TRAMPOLINE_HOST TRUE) -endif() - # Specify Variant Name set(MCPI_VARIANT_NAME "minecraft-pi-reborn") if(MCPI_SERVER_MODE) diff --git a/cmake/options/prebuilt-armhf-toolchain.cmake b/cmake/options/prebuilt-armhf-toolchain.cmake index d1736fac..ae045e3b 100644 --- a/cmake/options/prebuilt-armhf-toolchain.cmake +++ b/cmake/options/prebuilt-armhf-toolchain.cmake @@ -49,15 +49,17 @@ if("${toolchain_dir}/bin/arm-none-linux-gnueabihf-gcc" IS_NEWER_THAN "${sysroot_ file(REMOVE_RECURSE "${sysroot_dir}/usr/lib/gconv") # Strip Files - file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir}/*") - foreach(file IN LISTS files) - execute_process(COMMAND "${toolchain_dir}/bin/arm-none-linux-gnueabihf-strip" "${file}" RESULT_VARIABLE ret) - # Check Result - if(NOT ret EQUAL 0) - # Delete Invalid Files - file(REMOVE "${file}") - endif() - endforeach() + if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir}/*") + foreach(file IN LISTS files) + execute_process(COMMAND "${toolchain_dir}/bin/arm-none-linux-gnueabihf-strip" "${file}" RESULT_VARIABLE ret) + # Check Result + if(NOT ret EQUAL 0) + # Delete Invalid Files + file(REMOVE "${file}") + endif() + endforeach() + endif() endif() # Install Sysroot (Skipping Empty Directories) diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index 70f1155a..2045929a 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -16,8 +16,8 @@ endif() if(BUILD_NATIVE_COMPONENTS OR (BUILD_MEDIA_LAYER_CORE AND NOT MCPI_HEADLESS_MODE)) add_subdirectory(LIEF) endif() -# Trampoline -add_subdirectory(trampoline) +# Extra Runtime +add_subdirectory(runtime) # GLFW if(BUILD_MEDIA_LAYER_CORE AND NOT MCPI_HEADLESS_MODE) add_subdirectory(glfw) diff --git a/dependencies/runtime/CMakeLists.txt b/dependencies/runtime/CMakeLists.txt new file mode 100644 index 00000000..ed56a32d --- /dev/null +++ b/dependencies/runtime/CMakeLists.txt @@ -0,0 +1,16 @@ +project(runtime) + +## Extra Runtime + +# QEMU +set(QEMU_VERSION "9.0.0") +set(RUNTIME_QEMU_ARCHIVE "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz") +if(NOT BUILD_NATIVE_COMPONENTS) + set(TRAMPOLINE_HEADERS_ONLY TRUE) +endif() + +# Build +add_subdirectory(src) + +# Install +install_runtime("${MCPI_BIN_DIR}" "${MCPI_LEGAL_DIR}") \ No newline at end of file diff --git a/dependencies/runtime/src b/dependencies/runtime/src new file mode 160000 index 00000000..e6839074 --- /dev/null +++ b/dependencies/runtime/src @@ -0,0 +1 @@ +Subproject commit e6839074fd2eec91c5bb2e08705f2f235a568f74 diff --git a/dependencies/trampoline/CMakeLists.txt b/dependencies/trampoline/CMakeLists.txt deleted file mode 100644 index 1b44c632..00000000 --- a/dependencies/trampoline/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -project(trampoline) - -## Trampoline Host - -# QEMU -set(QEMU_VERSION "9.0.0") -set(TRAMPOLINE_QEMU_ARCHIVE "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz") -if(NOT MCPI_USE_TRAMPOLINE_HOST) - set(TRAMPOLINE_HEADERS_ONLY TRUE) -endif() - -# Build -add_subdirectory(src) - -# Install -install_trampoline("${MCPI_BIN_DIR}" "${MCPI_LEGAL_DIR}") \ No newline at end of file diff --git a/dependencies/trampoline/src b/dependencies/trampoline/src deleted file mode 160000 index 50d94d52..00000000 --- a/dependencies/trampoline/src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 50d94d52998ba361c5d89d1b21f7eafd972f3f4e diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index e0625136..49c4360b 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -19,10 +19,7 @@ if(NOT MCPI_SERVER_MODE) src/client/available-feature-flags # Show In IDE ) endif() -target_link_libraries(launcher reborn-util LIB_LIEF) -if(MCPI_USE_TRAMPOLINE_HOST) - target_link_libraries(launcher trampoline-headers) -endif() +target_link_libraries(launcher reborn-util LIB_LIEF trampoline-headers) # RPath set_target_properties(launcher PROPERTIES INSTALL_RPATH "$ORIGIN/lib/native") target_link_options(launcher PRIVATE "LINKER:--disable-new-dtags") diff --git a/launcher/src/bootstrap.cpp b/launcher/src/bootstrap.cpp index 63fcc496..a80f47db 100644 --- a/launcher/src/bootstrap.cpp +++ b/launcher/src/bootstrap.cpp @@ -10,7 +10,6 @@ #include "patchelf.h" #define MCPI_BINARY "minecraft-pi" -#define QEMU_BINARY "qemu-arm" #define REQUIRED_PAGE_SIZE 4096 @@ -151,14 +150,6 @@ void bootstrap() { mcpi_ld_path += binary_directory + "/sysroot/usr/lib:"; mcpi_ld_path += binary_directory + "/sysroot/usr/lib/arm-linux-gnueabihf:"; #endif - - // Add Host LD_LIBRARY_PATH - { - char *value = getenv("LD_LIBRARY_PATH"); - if (value != nullptr && strlen(value) > 0) { - mcpi_ld_path += value; - } - } } } @@ -177,12 +168,12 @@ void bootstrap() { // Arguments std::vector args; - // Use Trampoline Host If Needed -#ifdef MCPI_USE_TRAMPOLINE_HOST - args.push_back("trampoline"); + // Use Extra If Needed +#ifdef MCPI_BUILD_RUNTIME + args.push_back("runtime"); #endif // Fix QEMU Bug -#ifdef MCPI_USE_QEMU +#ifdef MCPI_RUNTIME_IS_QEMU args.push_back("-B"); args.push_back("0x40000"); // Arbitrary Value (Aligns To 4k And 16k Page Sizes) #endif diff --git a/launcher/src/crash-report.c b/launcher/src/crash-report.c index 6608d187..04ba79ec 100644 --- a/launcher/src/crash-report.c +++ b/launcher/src/crash-report.c @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -110,6 +111,9 @@ void setup_crash_report() { // Create New Process Group setpgid(0, 0); + // Kill Child If Parent Exits First + prctl(PR_SET_PDEATHSIG, SIGKILL); + // Continue Execution } else { // Parent Process diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index fedad176..b48eb8ad 100644 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -2,10 +2,6 @@ #include #include -#ifdef MCPI_USE_NATIVE_TRAMPOLINE -#include -#endif - #include "bootstrap.h" #include "options/parser.h" #include "crash-report.h" @@ -28,9 +24,6 @@ static void setup_environment(const options_t &options) { #else bind_to_env("_MCPI_ONLY_GENERATE", options.only_generate); #endif -#ifdef MCPI_USE_NATIVE_TRAMPOLINE - bind_to_env(TRAMPOLINE_USE_PIPES_ENV, !options.use_ptrace_trampoline); -#endif // GTK Dark Mode #ifndef MCPI_HEADLESS_MODE diff --git a/launcher/src/mods.cpp b/launcher/src/mods.cpp index b576ce80..2ad3d396 100644 --- a/launcher/src/mods.cpp +++ b/launcher/src/mods.cpp @@ -73,14 +73,6 @@ std::string bootstrap_mods(const std::string &binary_directory) { load(preload, mods_folder); } - // Add LD_PRELOAD - { - const char *value = getenv("LD_PRELOAD"); - if (value != nullptr && strlen(value) > 0) { - preload += value; - } - } - // Return return preload; } diff --git a/launcher/src/options/option-list.h b/launcher/src/options/option-list.h index 6bd59203..b69d64e1 100644 --- a/launcher/src/options/option-list.h +++ b/launcher/src/options/option-list.h @@ -9,7 +9,4 @@ OPTION(print_available_feature_flags, "print-available-feature-flags", -6, "Prin OPTION(benchmark, "benchmark", -7, "Run Benchmark") #else OPTION(only_generate, "only-generate", -8, "Generate World And Exit") -#endif -#ifdef MCPI_USE_NATIVE_TRAMPOLINE -OPTION(use_ptrace_trampoline, "use-ptrace-trampoline", -9, "Use PTrace For Calling Host Functions Instead Of Pipes") #endif \ No newline at end of file diff --git a/libreborn/include/libreborn/config.h.in b/libreborn/include/libreborn/config.h.in index c5c90f03..dab2a3ee 100644 --- a/libreborn/include/libreborn/config.h.in +++ b/libreborn/include/libreborn/config.h.in @@ -13,6 +13,5 @@ #cmakedefine MCPI_VARIANT_NAME "@MCPI_VARIANT_NAME@" #cmakedefine MCPI_SDK_DIR "@MCPI_SDK_DIR@" #cmakedefine MCPI_SKIN_SERVER "@MCPI_SKIN_SERVER@" -#cmakedefine MCPI_USE_TRAMPOLINE_HOST #cmakedefine MCPI_DISCORD_INVITE "@MCPI_DISCORD_INVITE@" #cmakedefine MCPI_DOCUMENTATION "@MCPI_DOCUMENTATION@" diff --git a/media-layer/trampoline/src/GLESv1_CM.cpp b/media-layer/trampoline/src/GLESv1_CM.cpp index e0071543..68644394 100644 --- a/media-layer/trampoline/src/GLESv1_CM.cpp +++ b/media-layer/trampoline/src/GLESv1_CM.cpp @@ -319,6 +319,23 @@ CALL_GL_POINTER(41, glTexCoordPointer) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST void glDisableClientState(const GLenum array) { gl_state.get_array_enabled(array) = false; + // Not needed when using compatibility layer +#ifndef MCPI_USE_GLES1_COMPATIBILITY_LAYER + switch (array) { + case GL_VERTEX_ARRAY: { + gl_array_details.glVertexPointer.size = -1; + break; + } + case GL_COLOR_ARRAY: { + gl_array_details.glColorPointer.size = -1; + break; + } + case GL_TEXTURE_COORD_ARRAY: { + gl_array_details.glTexCoordPointer.size = -1; + break; + } + } +#endif } #endif @@ -349,6 +366,12 @@ void glBindBuffer(const GLenum target, const GLuint buffer) { } else { ERR("Unsupported Buffer Binding: %u", target); } + // Not needed when using compatibility layer +#ifndef MCPI_USE_GLES1_COMPATIBILITY_LAYER + gl_array_details.glVertexPointer.size = -1; + gl_array_details.glColorPointer.size = -1; + gl_array_details.glTexCoordPointer.size = -1; +#endif } #endif @@ -676,6 +699,10 @@ static int get_glGetIntegerv_params_size(GLenum pname) { #endif CALL(61, glGetIntegerv, void, (GLenum pname, GLint *params)) #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST + if (pname == GL_TEXTURE_BINDING_2D) { + params[0] = gl_state.bound_texture; + return; + } trampoline(false, pname, uint32_t(params)); #else GLenum pname = args.next(); diff --git a/media-layer/trampoline/src/guest/guest.cpp b/media-layer/trampoline/src/guest/guest.cpp index 3cfedf95..e48cadc9 100644 --- a/media-layer/trampoline/src/guest/guest.cpp +++ b/media-layer/trampoline/src/guest/guest.cpp @@ -69,7 +69,7 @@ uint32_t _raw_trampoline(const uint32_t id, const bool allow_early_return, const // Configure Method static int use_syscall = -1; if (use_syscall == -1) { - use_syscall = getenv(TRAMPOLINE_USE_PIPES_ENV) == nullptr; + use_syscall = getenv(TRAMPOLINE_ARGUMENTS_PIPE_ENV) == nullptr; } // Use Correct Method if (use_syscall) { diff --git a/symbols/src/tile/StemTile.def b/symbols/src/tile/StemTile.def index 7875784d..884295dd 100644 --- a/symbols/src/tile/StemTile.def +++ b/symbols/src/tile/StemTile.def @@ -1,3 +1,3 @@ extends Tile; -vtable 0x110fd0; +vtable 0x111ec0;