Add Back ~/.minecraft-pi/mods & Fix Segmentation Fault With Media Layer Proxy
This commit is contained in:
parent
c6983ac6c5
commit
1eb06b6b60
@ -181,6 +181,8 @@ void bootstrap(int argc, char *argv[]) {
|
|||||||
char *new_ld_preload = NULL;
|
char *new_ld_preload = NULL;
|
||||||
safe_asprintf(&new_ld_preload, "%s", get_env_safe("LD_PRELOAD"));
|
safe_asprintf(&new_ld_preload, "%s", get_env_safe("LD_PRELOAD"));
|
||||||
|
|
||||||
|
// Built-In Mods
|
||||||
|
{
|
||||||
// Get Mods Folder
|
// Get Mods Folder
|
||||||
char *mods_folder = NULL;
|
char *mods_folder = NULL;
|
||||||
safe_asprintf(&mods_folder, "%s/mods/", binary_directory);
|
safe_asprintf(&mods_folder, "%s/mods/", binary_directory);
|
||||||
@ -188,6 +190,18 @@ void bootstrap(int argc, char *argv[]) {
|
|||||||
load(&new_ld_preload, mods_folder);
|
load(&new_ld_preload, mods_folder);
|
||||||
// Free Mods Folder
|
// Free Mods Folder
|
||||||
free(mods_folder);
|
free(mods_folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ~/.minecraft-pi/mods
|
||||||
|
{
|
||||||
|
// Get Mods Folder
|
||||||
|
char *mods_folder = NULL;
|
||||||
|
safe_asprintf(&mods_folder, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA "/mods/", getenv("HOME"));
|
||||||
|
// Load Mods From ./mods
|
||||||
|
load(&new_ld_preload, mods_folder);
|
||||||
|
// Free Mods Folder
|
||||||
|
free(mods_folder);
|
||||||
|
}
|
||||||
|
|
||||||
// Set LD_PRELOAD
|
// Set LD_PRELOAD
|
||||||
set_and_print_env("LD_PRELOAD", new_ld_preload);
|
set_and_print_env("LD_PRELOAD", new_ld_preload);
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "../bootstrap.h"
|
#include "../bootstrap.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
// Set Home To Current Directory, So World Data Is Stored There
|
||||||
|
char *launch_directory = getcwd(NULL, 0);
|
||||||
|
setenv("HOME", launch_directory, 1);
|
||||||
|
free(launch_directory);
|
||||||
|
|
||||||
// Bootstrap
|
// Bootstrap
|
||||||
bootstrap(argc, argv);
|
bootstrap(argc, argv);
|
||||||
}
|
}
|
||||||
|
10
libreborn/include/libreborn/home.h
Normal file
10
libreborn/include/libreborn/home.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Minecraft Pi Game Data Root
|
||||||
|
#ifndef MCPI_SERVER_MODE
|
||||||
|
// Store Game Data In "~/.minecraft-pi" Instead Of "~/.minecraft" To Avoid Conflicts
|
||||||
|
#define HOME_SUBDIRECTORY_FOR_GAME_DATA "/.minecraft-pi"
|
||||||
|
#else
|
||||||
|
// Store Game Data In $HOME Root (In Server Mode, $HOME Is Changed To The Launch Directory)
|
||||||
|
#define HOME_SUBDIRECTORY_FOR_GAME_DATA ""
|
||||||
|
#endif
|
@ -1,36 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
#include "elf.h"
|
#include "elf.h"
|
||||||
|
#include "home.h"
|
||||||
#ifdef REBORN_HAS_COMPILED_CODE
|
#include "patch.h"
|
||||||
|
|
||||||
// Patching Functions
|
|
||||||
|
|
||||||
void _overwrite_call(const char *file, int line, void *start, void *target);
|
|
||||||
#define overwrite_call(start, target) _overwrite_call(__FILE__, __LINE__, start, target);
|
|
||||||
|
|
||||||
void _overwrite_calls(const char *file, int line, void *start, void *target);
|
|
||||||
#define overwrite_calls(start, target) _overwrite_calls(__FILE__, __LINE__, start, target);
|
|
||||||
|
|
||||||
void _overwrite(const char *file, int line, void *start, void *target);
|
|
||||||
#define overwrite(start, target) _overwrite(__FILE__, __LINE__, start, target);
|
|
||||||
|
|
||||||
void _patch(const char *file, int line, void *start, unsigned char patch[4]);
|
|
||||||
#define patch(start, patch) _patch(__FILE__, __LINE__, start, patch);
|
|
||||||
|
|
||||||
void _patch_address(const char *file, int line, void *start, void *target);
|
|
||||||
#define patch_address(start, target) _patch_address(__FILE__, __LINE__, start, target);
|
|
||||||
|
|
||||||
#endif // #ifdef __arm__
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
30
libreborn/include/libreborn/patch.h
Normal file
30
libreborn/include/libreborn/patch.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Patching Functions
|
||||||
|
|
||||||
|
#ifdef REBORN_HAS_COMPILED_CODE
|
||||||
|
|
||||||
|
void _overwrite_call(const char *file, int line, void *start, void *target);
|
||||||
|
#define overwrite_call(start, target) _overwrite_call(__FILE__, __LINE__, start, target);
|
||||||
|
|
||||||
|
void _overwrite_calls(const char *file, int line, void *start, void *target);
|
||||||
|
#define overwrite_calls(start, target) _overwrite_calls(__FILE__, __LINE__, start, target);
|
||||||
|
|
||||||
|
void _overwrite(const char *file, int line, void *start, void *target);
|
||||||
|
#define overwrite(start, target) _overwrite(__FILE__, __LINE__, start, target);
|
||||||
|
|
||||||
|
void _patch(const char *file, int line, void *start, unsigned char patch[4]);
|
||||||
|
#define patch(start, patch) _patch(__FILE__, __LINE__, start, patch);
|
||||||
|
|
||||||
|
void _patch_address(const char *file, int line, void *start, void *target);
|
||||||
|
#define patch_address(start, target) _patch_address(__FILE__, __LINE__, start, target);
|
||||||
|
|
||||||
|
#endif // #ifdef REBORN_HAS_COMPILED_CODE
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
@ -32,6 +32,7 @@ static void sigusr1_handler(__attribute__((unused)) int sig) {
|
|||||||
void _check_proxy_state() {
|
void _check_proxy_state() {
|
||||||
// Check Server State
|
// Check Server State
|
||||||
if (!parent_is_alive) {
|
if (!parent_is_alive) {
|
||||||
|
void_write_cache(); // Parent Is Dead, No Reason To Send A Dead Process Data
|
||||||
PROXY_ERR("%s", "Server Terminated");
|
PROXY_ERR("%s", "Server Terminated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
_check_proxy_state(); \
|
_check_proxy_state(); \
|
||||||
if (!is_connection_open()) { \
|
if (!is_connection_open()) { \
|
||||||
PROXY_ERR("%s", "Attempting To Access Closed Connection"); \
|
PROXY_ERR("%s", "Attempting To Access Closed Connection"); \
|
||||||
} else { \
|
|
||||||
_check_proxy_state(); \
|
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
void safe_read(void *buf, size_t len) {
|
void safe_read(void *buf, size_t len) {
|
||||||
@ -63,27 +61,30 @@ void safe_write(void *buf, size_t len) {
|
|||||||
}
|
}
|
||||||
// Flush Write Cache
|
// Flush Write Cache
|
||||||
void flush_write_cache() {
|
void flush_write_cache() {
|
||||||
// Check Connection
|
|
||||||
if (!is_connection_open()) {
|
|
||||||
// Connection Closed
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Check Cache
|
// Check Cache
|
||||||
if (_write_cache == NULL || _write_cache_position < 1) {
|
if (_write_cache == NULL || _write_cache_position < 1) {
|
||||||
// Nothing To Write
|
// Nothing To Write
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Write
|
// Check Connection
|
||||||
|
if (!is_connection_open()) {
|
||||||
|
// Connection Closed
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Write & Reset
|
||||||
size_t to_write = _write_cache_position;
|
size_t to_write = _write_cache_position;
|
||||||
|
size_t old_write_cache_position = _write_cache_position;
|
||||||
|
_write_cache_position = 0;
|
||||||
while (to_write > 0) {
|
while (to_write > 0) {
|
||||||
CHECK_CONNECTION();
|
CHECK_CONNECTION();
|
||||||
ssize_t x = write(get_connection_write(), (void *) (((unsigned char *) _write_cache) + (_write_cache_position - to_write)), to_write);
|
ssize_t x = write(get_connection_write(), (void *) (((unsigned char *) _write_cache) + (old_write_cache_position - to_write)), to_write);
|
||||||
if (x == -1 && errno != EINTR) {
|
if (x == -1 && errno != EINTR) {
|
||||||
PROXY_ERR("Failed Writing Data To Connection: %s", strerror(errno));
|
PROXY_ERR("Failed Writing Data To Connection: %s", strerror(errno));
|
||||||
}
|
}
|
||||||
to_write -= x;
|
to_write -= x;
|
||||||
}
|
}
|
||||||
// Reset
|
}
|
||||||
|
void void_write_cache() {
|
||||||
_write_cache_position = 0;
|
_write_cache_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ extern "C" {
|
|||||||
__attribute__((visibility("internal"))) void safe_read(void *buf, size_t len);
|
__attribute__((visibility("internal"))) void safe_read(void *buf, size_t len);
|
||||||
__attribute__((visibility("internal"))) void safe_write(void *buf, size_t len);
|
__attribute__((visibility("internal"))) void safe_write(void *buf, size_t len);
|
||||||
__attribute__((visibility("internal"))) void flush_write_cache();
|
__attribute__((visibility("internal"))) void flush_write_cache();
|
||||||
|
__attribute__((visibility("internal"))) void void_write_cache();
|
||||||
|
|
||||||
// Read/Write 32-Bit Integers
|
// Read/Write 32-Bit Integers
|
||||||
__attribute__((visibility("internal"))) uint32_t read_int();
|
__attribute__((visibility("internal"))) uint32_t read_int();
|
||||||
|
@ -25,6 +25,7 @@ static void update_client_state(int is_alive, int status) {
|
|||||||
void _check_proxy_state() {
|
void _check_proxy_state() {
|
||||||
// Check Client State
|
// Check Client State
|
||||||
if (!_client_is_alive) {
|
if (!_client_is_alive) {
|
||||||
|
void_write_cache(); // Child Is Dead, No Reason To Send A Dead Process Data
|
||||||
if (WIFEXITED(_client_status)) {
|
if (WIFEXITED(_client_status)) {
|
||||||
PROXY_ERR("Client Terminated: Exit Code: %i", WEXITSTATUS(_client_status));
|
PROXY_ERR("Client Terminated: Exit Code: %i", WEXITSTATUS(_client_status));
|
||||||
} else if (WIFSIGNALED(_client_status)) {
|
} else if (WIFSIGNALED(_client_status)) {
|
||||||
|
@ -6,43 +6,12 @@
|
|||||||
#include "home.h"
|
#include "home.h"
|
||||||
#include "../init/init.h"
|
#include "../init/init.h"
|
||||||
|
|
||||||
// Minecraft Pi User Data Root
|
|
||||||
#ifndef MCPI_SERVER_MODE
|
|
||||||
// Store Game Data In "~/.minecraft-pi" Instead Of "~/.minecraft" To Avoid Conflicts
|
|
||||||
#define NEW_PATH "/.minecraft-pi"
|
|
||||||
#else
|
|
||||||
// Store Game Data In Launch Directory
|
|
||||||
#define NEW_PATH ""
|
|
||||||
|
|
||||||
// Store Launch Directory
|
|
||||||
__attribute__((constructor)) static char *get_launch_directory() {
|
|
||||||
static char *launch_directory = NULL;
|
|
||||||
if (launch_directory == NULL) {
|
|
||||||
launch_directory = getcwd(NULL, 0);
|
|
||||||
}
|
|
||||||
return launch_directory;
|
|
||||||
}
|
|
||||||
__attribute__((destructor)) static void free_launch_directory() {
|
|
||||||
free(get_launch_directory());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretend $HOME Is Launch Directory
|
|
||||||
HOOK(getenv, char *, (const char *name)) {
|
|
||||||
if (strcmp(name, "HOME") == 0) {
|
|
||||||
return get_launch_directory();
|
|
||||||
} else {
|
|
||||||
ensure_getenv();
|
|
||||||
return (*real_getenv)(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Get MCPI Home Directory
|
// Get MCPI Home Directory
|
||||||
char *home_get() {
|
char *home_get() {
|
||||||
static char *dir = NULL;
|
static char *dir = NULL;
|
||||||
// Load
|
// Load
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
safe_asprintf(&dir, "%s" NEW_PATH, getenv("HOME"));
|
safe_asprintf(&dir, "%s" HOME_SUBDIRECTORY_FOR_GAME_DATA, getenv("HOME"));
|
||||||
}
|
}
|
||||||
// Return
|
// Return
|
||||||
return dir;
|
return dir;
|
||||||
@ -55,7 +24,7 @@ __attribute__((destructor)) static void _free_home() {
|
|||||||
// Init
|
// Init
|
||||||
void init_home() {
|
void init_home() {
|
||||||
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
|
// Store Data In ~/.minecraft-pi Instead Of ~/.minecraft
|
||||||
patch_address((void *) default_path, (void *) NEW_PATH);
|
patch_address((void *) default_path, (void *) HOME_SUBDIRECTORY_FOR_GAME_DATA);
|
||||||
|
|
||||||
// Change Directory To Binary Directory Manually
|
// Change Directory To Binary Directory Manually
|
||||||
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
unsigned char nop_patch[4] = {0x00, 0xf0, 0x20, 0xe3}; // "nop"
|
||||||
|
Loading…
Reference in New Issue
Block a user