From 99b709fea708db0400746b151d909aa91264fb6d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 15 Aug 2021 23:11:03 -0400 Subject: [PATCH] Fix Crash On ARM Systems --- VERSION | 2 +- dependencies/minecraft-pi/CMakeLists.txt | 1 - docs/CHANGELOG.md | 3 ++ launcher/src/bootstrap.c | 2 ++ launcher/src/client/launcher.cpp | 1 + libreborn/include/libreborn/elf.h | 16 +++++++---- libreborn/include/libreborn/exec.h | 35 +++++++++--------------- libreborn/src/libreborn.c | 3 +- 8 files changed, 33 insertions(+), 30 deletions(-) diff --git a/VERSION b/VERSION index 04b10b4f..ebf14b46 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.1.7 +2.1.8 diff --git a/dependencies/minecraft-pi/CMakeLists.txt b/dependencies/minecraft-pi/CMakeLists.txt index e9a8ee0a..9deea304 100644 --- a/dependencies/minecraft-pi/CMakeLists.txt +++ b/dependencies/minecraft-pi/CMakeLists.txt @@ -8,7 +8,6 @@ include(FetchContent) FetchContent_Declare( minecraft-pi URL "${CMAKE_CURRENT_SOURCE_DIR}/minecraft-pi-0.1.1.tar.gz" - URL_HASH "SHA256=e0d68918874cdd403de1fd399380ae2930913fcefdbf60a3fbfebb62e2cfacab" ) FetchContent_Populate(minecraft-pi) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e3eafaca..3fc226b9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**2.1.8** +* Fix Crash On ARM Systems + **2.1.7** * Fix On 64-Bit ARM Systems diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index fc7a653a..8a0cba3c 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -8,6 +8,7 @@ #include #include +#define FORCE_PROC_FOR_ROOT_PATH #include #include "bootstrap.h" @@ -129,6 +130,7 @@ void bootstrap(int argc, char *argv[]) { // Get Binary Directory char *binary_directory = get_binary_directory(); + setenv("MCPI_ROOT_PATH", binary_directory, 1); // Configure LD_LIBRARY_PATH { diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index 6bf366df..0de64cb4 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include diff --git a/libreborn/include/libreborn/elf.h b/libreborn/include/libreborn/elf.h index 2d4278f7..e6a94af0 100644 --- a/libreborn/include/libreborn/elf.h +++ b/libreborn/include/libreborn/elf.h @@ -1,18 +1,25 @@ #pragma once -#ifdef __arm__ #include #include #include #include #include "log.h" +#include "exec.h" // Find And Iterate Over All .text Sections In Current Binary -typedef void (*text_section_callback_t)(void *section, Elf32_Word size, void *data); +typedef void (*text_section_callback_t)(Elf32_Addr section, Elf32_Word size, void *data); static inline void iterate_text_sections(text_section_callback_t callback, void *data) { + // Find Main Binary + char *real_path = NULL; + { + char *binary_directory = get_binary_directory(); + safe_asprintf(&real_path, "%s/minecraft-pi", binary_directory); + free(binary_directory); + } + // Load Main Binary - char *real_path = realpath("/proc/self/exe", NULL); FILE *file_obj = fopen(real_path, "rb"); // Verify Binary @@ -47,7 +54,7 @@ static inline void iterate_text_sections(text_section_callback_t callback, void // Check Section Type if (strcmp(name, ".text") == 0) { // .text Section - (*callback)((void *) header.sh_addr, header.sh_size, data); + (*callback)(header.sh_addr, header.sh_size, data); text_sections++; } } @@ -64,4 +71,3 @@ static inline void iterate_text_sections(text_section_callback_t callback, void munmap(file_map, size); fclose(file_obj); } -#endif // #ifdef __arm__ diff --git a/libreborn/include/libreborn/exec.h b/libreborn/include/libreborn/exec.h index 34493b3e..81e5c81a 100644 --- a/libreborn/include/libreborn/exec.h +++ b/libreborn/include/libreborn/exec.h @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include "log.h" @@ -24,30 +22,23 @@ __attribute__((noreturn)) static inline void safe_execvpe(const char *pathname, // Get Binary Directory (Remember To Free) #define EXE_PATH "/proc/self/exe" static inline char *get_binary_directory() { +#ifndef FORCE_PROC_FOR_ROOT_PATH + { + // Check Environment + char *specified_root = getenv("MCPI_ROOT_PATH"); + if (specified_root != NULL) { + return strdup(specified_root); + } + } +#endif + // Get Path To Current Executable - // Get Symlink Path Size - struct stat sb; - if (lstat(EXE_PATH, &sb) == -1) { - ERR("Unable To Get " EXE_PATH " Symlink Size: %s", strerror(errno)); - } - ssize_t path_size = sb.st_size; - if (sb.st_size <= 0) { - path_size = PATH_MAX; - } - char *exe = (char *) malloc(path_size + 1); + char *exe = realpath("/proc/self/exe", NULL); ALLOC_CHECK(exe); - // Read Link - ssize_t r = readlink(EXE_PATH, exe, path_size); - if (r < 0) { - ERR("Unable To Read " EXE_PATH " Symlink: %s", strerror(errno)); - } - if (r > path_size) { - ERR("%s", "Size Of Symlink " EXE_PATH " Changed"); - } - exe[r + 1] = '\0'; // Chop Off Last Component - for (int i = r; i >= 0; i--) { + int length = strlen(exe); + for (int i = length - 1; i >= 0; i--) { if (exe[i] == '/') { exe[i] = '\0'; break; diff --git a/libreborn/src/libreborn.c b/libreborn/src/libreborn.c index 78402ae0..9b2fa658 100644 --- a/libreborn/src/libreborn.c +++ b/libreborn/src/libreborn.c @@ -44,8 +44,9 @@ struct overwrite_data { void *replacement; int found; }; -static void overwrite_calls_callback(void *section, Elf32_Word size, void *data) { +static void overwrite_calls_callback(Elf32_Addr section_addr, Elf32_Word size, void *data) { struct overwrite_data *args = (struct overwrite_data *) data; + void *section = (void *) section_addr; for (uint32_t i = 0; i < size; i = i + 4) { unsigned char *addr = ((unsigned char *) section) + i;