Fix Crash On ARM Systems
This commit is contained in:
parent
578bb1c89f
commit
99b709fea7
1
dependencies/minecraft-pi/CMakeLists.txt
vendored
1
dependencies/minecraft-pi/CMakeLists.txt
vendored
@ -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)
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
**2.1.8**
|
||||
* Fix Crash On ARM Systems
|
||||
|
||||
**2.1.7**
|
||||
* Fix On 64-Bit ARM Systems
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define FORCE_PROC_FOR_ROOT_PATH
|
||||
#include <libreborn/libreborn.h>
|
||||
|
||||
#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
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
|
@ -1,18 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __arm__
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <elf.h>
|
||||
|
||||
#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__
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user