Update Runtime

This commit is contained in:
TheBrokenRail 2024-11-10 05:26:41 -05:00
parent b339b53f42
commit 23b3cbe72f
9 changed files with 44 additions and 58 deletions

View File

@ -3,16 +3,12 @@ project(runtime)
## Extra Runtime ## Extra Runtime
# QEMU # QEMU
set(QEMU_VERSION "9.0.2") set(QEMU_VERSION "9.1.1")
set(RUNTIME_QEMU_ARCHIVE "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz") file(REAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz" QEMU_PATH)
set(RUNTIME_QEMU_ARCHIVE "${QEMU_PATH}" CACHE FILEPATH "" FORCE)
if(NOT BUILD_NATIVE_COMPONENTS) if(NOT BUILD_NATIVE_COMPONENTS)
set(TRAMPOLINE_HEADERS_ONLY TRUE) set(TRAMPOLINE_HEADERS_ONLY TRUE CACHE BOOL "" FORCE)
endif() endif()
# Build # Build
add_subdirectory(src) add_subdirectory(src)
# Install
if(COMMAND install_runtime)
install_runtime("${MCPI_BIN_DIR}" "${MCPI_LEGAL_DIR}")
endif()

@ -1 +1 @@
Subproject commit 377f9ddbc4747ca3a640231d259c0e6fcc71b4b0 Subproject commit f8b56c50bab051f7f2a1fb47be4101f0e2099f2f

View File

@ -4,7 +4,6 @@
#include <vector> #include <vector>
#include <libreborn/libreborn.h> #include <libreborn/libreborn.h>
#include <trampoline/types.h>
#include "util.h" #include "util.h"
#include "bootstrap.h" #include "bootstrap.h"
@ -61,7 +60,7 @@ void bootstrap(const options_t &options) {
// Debug Information // Debug Information
print_debug_information(); print_debug_information();
// Check Page Size (Not Needed When Using QEMU) // Check Page Size
long page_size = sysconf(_SC_PAGESIZE); long page_size = sysconf(_SC_PAGESIZE);
if (page_size != REQUIRED_PAGE_SIZE) { if (page_size != REQUIRED_PAGE_SIZE) {
CONDITIONAL_ERR(!options.skip_pagesize_check, "Invalid page size! A page size of %ld bytes is required, but the system size is %ld bytes.", (long) REQUIRED_PAGE_SIZE, page_size); CONDITIONAL_ERR(!options.skip_pagesize_check, "Invalid page size! A page size of %ld bytes is required, but the system size is %ld bytes.", (long) REQUIRED_PAGE_SIZE, page_size);
@ -177,11 +176,6 @@ void bootstrap(const options_t &options) {
#ifdef MCPI_BUILD_RUNTIME #ifdef MCPI_BUILD_RUNTIME
args.push_back("runtime"); args.push_back("runtime");
#endif #endif
// Fix QEMU Bug
#ifdef MCPI_RUNTIME_IS_QEMU
args.push_back("-B");
args.push_back(std::to_string(QEMU_GUEST_BASE));
#endif
// Specify MCPI Binary // Specify MCPI Binary
args.push_back(new_mcpi_exe_path); args.push_back(new_mcpi_exe_path);

View File

@ -1,5 +1,6 @@
#include <argp.h> #include <argp.h>
#include <trampoline/types.h>
#include "parser.h" #include "parser.h"
// Globals // Globals
@ -17,6 +18,9 @@ static argp_option options_data[] = {
{nullptr, 0, nullptr, 0, "Environmental Variables:", 0}, {nullptr, 0, nullptr, 0, "Environmental Variables:", 0},
#define ENV(name, doc) {#name, env_key--, nullptr, OPTION_DOC | OPTION_NO_USAGE | (is_env_var_internal(name##_ENV) ? OPTION_HIDDEN : 0), doc, 0}, #define ENV(name, doc) {#name, env_key--, nullptr, OPTION_DOC | OPTION_NO_USAGE | (is_env_var_internal(name##_ENV) ? OPTION_HIDDEN : 0), doc, 0},
#include <libreborn/env-list.h> #include <libreborn/env-list.h>
#ifdef MCPI_BUILD_RUNTIME
#include <trampoline/env-list.h>
#endif
#undef ENV #undef ENV
{nullptr, 0, nullptr, 0, "Help Options:", -1}, {nullptr, 0, nullptr, 0, "Help Options:", -1},
{nullptr, 0, nullptr, 0, nullptr, 0} {nullptr, 0, nullptr, 0, nullptr, 0}

View File

@ -19,7 +19,7 @@ int reborn_get_debug_fd();
#define WARN(format, ...) fprintf(stderr, "[WARN]: " format "\n", ##__VA_ARGS__) #define WARN(format, ...) fprintf(stderr, "[WARN]: " format "\n", ##__VA_ARGS__)
#define RAW_DEBUG(tag, format, ...) dprintf(reborn_get_debug_fd(), "[DEBUG]: %s" format "\n", tag, ##__VA_ARGS__) #define RAW_DEBUG(tag, format, ...) dprintf(reborn_get_debug_fd(), "[DEBUG]: %s" format "\n", tag, ##__VA_ARGS__)
#define DEBUG(format, ...) RAW_DEBUG(reborn_debug_tag, format, ##__VA_ARGS__) #define DEBUG(format, ...) RAW_DEBUG(reborn_debug_tag, format, ##__VA_ARGS__)
#define ERR(format, ...) { fprintf(stderr, "[ERR]: (%s:%i): " format "\n", __FILE__, __LINE__, ##__VA_ARGS__); exit(EXIT_FAILURE); } #define ERR(format, ...) { fprintf(stderr, "[ERR]: (%s:%i): " format "\n", __FILE__, __LINE__, ##__VA_ARGS__); _exit(EXIT_FAILURE); }
#define IMPOSSIBLE() ERR("This Should Never Be Called") #define IMPOSSIBLE() ERR("This Should Never Be Called")
#define CONDITIONAL_ERR(is_error, ...) \ #define CONDITIONAL_ERR(is_error, ...) \
{ \ { \

View File

@ -201,25 +201,12 @@ CALL(17, media_glClear, void, (GLbitfield mask))
CALL(18, media_glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage)) CALL(18, media_glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage))
#ifdef MEDIA_LAYER_TRAMPOLINE_GUEST #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST
static bool use_syscall = getenv(TRAMPOLINE_ARGUMENTS_PIPE_ENV) == nullptr;
if (use_syscall) {
trampoline(false, gl_state.bound_array_buffer, target, int32_t(size), uint32_t(data), usage);
} else {
trampoline(true, gl_state.bound_array_buffer, target, int32_t(size), copy_array(size, (unsigned char *) data), usage); trampoline(true, gl_state.bound_array_buffer, target, int32_t(size), copy_array(size, (unsigned char *) data), usage);
}
#else #else
media_glBindBuffer(GL_ARRAY_BUFFER, args.next<GLuint>()); media_glBindBuffer(GL_ARRAY_BUFFER, args.next<GLuint>());
GLenum target = args.next<GLenum>(); GLenum target = args.next<GLenum>();
int32_t size = args.next<int32_t>(); int32_t size = args.next<int32_t>();
#ifdef MCPI_RUNTIME_IS_QEMU
const unsigned char *data = nullptr;
uint32_t data_addr = args.next<uint32_t>();
if (data_addr != 0) {
data = (const unsigned char *) (uintptr_t) (QEMU_GUEST_BASE + data_addr);
}
#else
const unsigned char *data = args.next_arr<unsigned char>(); const unsigned char *data = args.next_arr<unsigned char>();
#endif
GLenum usage = args.next<GLenum>(); GLenum usage = args.next<GLenum>();
func(target, size, data, usage); func(target, size, data, usage);
return 0; return 0;
@ -798,24 +785,13 @@ CALL(67, media_glGenBuffers, void, (GLsizei n, GLuint *buffers))
CALL(69, media_glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size, const void *data)) CALL(69, media_glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size, const void *data))
#ifdef MEDIA_LAYER_TRAMPOLINE_GUEST #ifdef MEDIA_LAYER_TRAMPOLINE_GUEST
static bool use_syscall = getenv(TRAMPOLINE_ARGUMENTS_PIPE_ENV) == nullptr;
if (use_syscall) {
trampoline(false, gl_state.bound_array_buffer, target, int32_t(offset), int32_t(size), uint32_t(data));
} else {
trampoline(true, gl_state.bound_array_buffer, target, int32_t(offset), copy_array(size, (unsigned char *) data)); trampoline(true, gl_state.bound_array_buffer, target, int32_t(offset), copy_array(size, (unsigned char *) data));
}
#else #else
media_glBindBuffer(GL_ARRAY_BUFFER, args.next<GLuint>()); media_glBindBuffer(GL_ARRAY_BUFFER, args.next<GLuint>());
GLenum target = args.next<GLenum>(); GLenum target = args.next<GLenum>();
int32_t offset = args.next<int32_t>(); int32_t offset = args.next<int32_t>();
#ifdef MCPI_RUNTIME_IS_QEMU
int32_t size = args.next<int32_t>();
uint32_t data_addr = args.next<uint32_t>();
const unsigned char *data = (const unsigned char *) (uintptr_t) (QEMU_GUEST_BASE + data_addr);
#else
uint32_t size; uint32_t size;
const unsigned char *data = args.next_arr<unsigned char>(&size); const unsigned char *data = args.next_arr<unsigned char>(&size);
#endif
func(target, offset, size, data); func(target, offset, size, data);
return 0; return 0;
#endif #endif

View File

@ -6,9 +6,9 @@
#include "guest.h" #include "guest.h"
// Syscall Method // Syscall Method
static uint32_t trampoline_syscall(const uint32_t id, const uint32_t length, const unsigned char *args) { static uint32_t trampoline_syscall(const uint32_t id, const unsigned char *args) {
// Make Syscall // Make Syscall
const long ret = syscall(TRAMPOLINE_SYSCALL, id, length, args); const long ret = syscall(TRAMPOLINE_SYSCALL, id, args);
if (ret == -1) { if (ret == -1) {
// Error // Error
ERR("Trampoline Error: %s", strerror(errno)); ERR("Trampoline Error: %s", strerror(errno));
@ -17,7 +17,7 @@ static uint32_t trampoline_syscall(const uint32_t id, const uint32_t length, con
return *(uint32_t *) args; return *(uint32_t *) args;
} }
// Pipe Method (Native Trampoline Only) // Pipe Method
static int get_pipe(const char *env) { static int get_pipe(const char *env) {
const char *value = getenv(env); const char *value = getenv(env);
if (value == nullptr) { if (value == nullptr) {
@ -31,8 +31,8 @@ static uint32_t trampoline_pipe(const uint32_t id, const bool allow_early_return
static int arguments_pipe = -1; static int arguments_pipe = -1;
static int return_value_pipe = -1; static int return_value_pipe = -1;
if (arguments_pipe == -1) { if (arguments_pipe == -1) {
arguments_pipe = get_pipe(TRAMPOLINE_ARGUMENTS_PIPE_ENV); arguments_pipe = get_pipe(_MCPI_TRAMPOLINE_ARGUMENTS_ENV);
return_value_pipe = get_pipe(TRAMPOLINE_RETURN_VALUE_PIPE_ENV); return_value_pipe = get_pipe(_MCPI_TRAMPOLINE_RETURN_VALUE_ENV);
} }
// Write Command // Write Command
const trampoline_pipe_arguments cmd = { const trampoline_pipe_arguments cmd = {
@ -66,11 +66,14 @@ static uint32_t trampoline_pipe(const uint32_t id, const bool allow_early_return
// Main Function // Main Function
uint32_t _raw_trampoline(const uint32_t id, const bool allow_early_return, const uint32_t length, const unsigned char *args) { uint32_t _raw_trampoline(const uint32_t id, const bool allow_early_return, const uint32_t length, const unsigned char *args) {
if (length > MAX_TRAMPOLINE_ARGS_SIZE) {
ERR("Command Too Big");
}
// Configure Method // Configure Method
static bool use_syscall = getenv(TRAMPOLINE_ARGUMENTS_PIPE_ENV) == nullptr; static bool use_syscall = getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) == nullptr;
// Use Correct Method // Use Correct Method
if (use_syscall) { if (use_syscall) {
return trampoline_syscall(id, length, args); return trampoline_syscall(id, args);
} else { } else {
return trampoline_pipe(id, allow_early_return, length, args); return trampoline_pipe(id, allow_early_return, length, args);
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <cstring> #include <cstring>
#include <cstdlib>
#include "../common/common.h" #include "../common/common.h"
@ -34,12 +35,18 @@ struct copy_array {
}; };
template <> template <>
inline void _handle_trampoline_arg<copy_array>(unsigned char *&out, const copy_array &arg) { inline void _handle_trampoline_arg<copy_array>(unsigned char *&out, const copy_array &arg) {
*(uint32_t *) out = arg.size; // Send Size
out += sizeof(uint32_t); _handle_trampoline_arg(out, arg.size);
// Send Data
if (arg.size > 0) { if (arg.size > 0) {
static bool just_send_pointer = getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) == nullptr;
if (just_send_pointer) {
_handle_trampoline_arg(out, uint32_t(arg.data));
} else {
memcpy(out, arg.data, arg.size); memcpy(out, arg.data, arg.size);
out += arg.size; out += arg.size;
} }
}
} }
// Variadic Templates // Variadic Templates
__attribute__((unused)) static void _add_to_trampoline_args(__attribute__((unused)) unsigned char *&out) { __attribute__((unused)) static void _add_to_trampoline_args(__attribute__((unused)) unsigned char *&out) {

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <cstdlib>
#include "../common/common.h" #include "../common/common.h"
// Trampoline Function // Trampoline Function
@ -38,13 +40,17 @@ struct TrampolineArguments {
if (length != nullptr) { if (length != nullptr) {
*length = size / sizeof(T); *length = size / sizeof(T);
} }
static bool just_read_pointer = getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) == nullptr;
if (size == 0) { if (size == 0) {
return nullptr; return nullptr;
} } else if (just_read_pointer) {
return (const T *) (uintptr_t) (QEMU_GUEST_BASE + next<uint32_t>());
} else {
const T *ret = (const T *) raw_args; const T *ret = (const T *) raw_args;
raw_args += size; raw_args += size;
return ret; return ret;
} }
}
private: private:
const unsigned char *raw_args; const unsigned char *raw_args;