diff --git a/dependencies/runtime/CMakeLists.txt b/dependencies/runtime/CMakeLists.txt index aec71c3867..3901601c0e 100644 --- a/dependencies/runtime/CMakeLists.txt +++ b/dependencies/runtime/CMakeLists.txt @@ -3,16 +3,12 @@ project(runtime) ## Extra Runtime # QEMU -set(QEMU_VERSION "9.0.2") -set(RUNTIME_QEMU_ARCHIVE "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz") +set(QEMU_VERSION "9.1.1") +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) - set(TRAMPOLINE_HEADERS_ONLY TRUE) + set(TRAMPOLINE_HEADERS_ONLY TRUE CACHE BOOL "" FORCE) endif() # Build -add_subdirectory(src) - -# Install -if(COMMAND install_runtime) - install_runtime("${MCPI_BIN_DIR}" "${MCPI_LEGAL_DIR}") -endif() \ No newline at end of file +add_subdirectory(src) \ No newline at end of file diff --git a/dependencies/runtime/src b/dependencies/runtime/src index 377f9ddbc4..f8b56c50ba 160000 --- a/dependencies/runtime/src +++ b/dependencies/runtime/src @@ -1 +1 @@ -Subproject commit 377f9ddbc4747ca3a640231d259c0e6fcc71b4b0 +Subproject commit f8b56c50bab051f7f2a1fb47be4101f0e2099f2f diff --git a/launcher/src/bootstrap.cpp b/launcher/src/bootstrap.cpp index 0238d6bfd0..12bb22eaf3 100644 --- a/launcher/src/bootstrap.cpp +++ b/launcher/src/bootstrap.cpp @@ -4,7 +4,6 @@ #include #include -#include #include "util.h" #include "bootstrap.h" @@ -61,7 +60,7 @@ void bootstrap(const options_t &options) { // Debug Information print_debug_information(); - // Check Page Size (Not Needed When Using QEMU) + // Check Page Size long page_size = sysconf(_SC_PAGESIZE); 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); @@ -177,11 +176,6 @@ void bootstrap(const options_t &options) { #ifdef MCPI_BUILD_RUNTIME args.push_back("runtime"); #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 args.push_back(new_mcpi_exe_path); diff --git a/launcher/src/options/parser.cpp b/launcher/src/options/parser.cpp index 4ff12238c0..a98c400e3a 100644 --- a/launcher/src/options/parser.cpp +++ b/launcher/src/options/parser.cpp @@ -1,5 +1,6 @@ #include +#include #include "parser.h" // Globals @@ -17,6 +18,9 @@ static argp_option options_data[] = { {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}, #include +#ifdef MCPI_BUILD_RUNTIME +#include +#endif #undef ENV {nullptr, 0, nullptr, 0, "Help Options:", -1}, {nullptr, 0, nullptr, 0, nullptr, 0} diff --git a/libreborn/include/libreborn/log.h b/libreborn/include/libreborn/log.h index 47419a02a8..27c57392d9 100644 --- a/libreborn/include/libreborn/log.h +++ b/libreborn/include/libreborn/log.h @@ -19,7 +19,7 @@ int reborn_get_debug_fd(); #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 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 CONDITIONAL_ERR(is_error, ...) \ { \ diff --git a/media-layer/trampoline/src/GLESv1_CM.cpp b/media-layer/trampoline/src/GLESv1_CM.cpp index d1d3548a37..9245c6b2d1 100644 --- a/media-layer/trampoline/src/GLESv1_CM.cpp +++ b/media-layer/trampoline/src/GLESv1_CM.cpp @@ -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)) #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 media_glBindBuffer(GL_ARRAY_BUFFER, args.next()); GLenum target = args.next(); int32_t size = args.next(); -#ifdef MCPI_RUNTIME_IS_QEMU - const unsigned char *data = nullptr; - uint32_t data_addr = args.next(); - if (data_addr != 0) { - data = (const unsigned char *) (uintptr_t) (QEMU_GUEST_BASE + data_addr); - } -#else const unsigned char *data = args.next_arr(); -#endif GLenum usage = args.next(); func(target, size, data, usage); 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)) #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 media_glBindBuffer(GL_ARRAY_BUFFER, args.next()); GLenum target = args.next(); int32_t offset = args.next(); -#ifdef MCPI_RUNTIME_IS_QEMU - int32_t size = args.next(); - uint32_t data_addr = args.next(); - const unsigned char *data = (const unsigned char *) (uintptr_t) (QEMU_GUEST_BASE + data_addr); -#else uint32_t size; const unsigned char *data = args.next_arr(&size); -#endif func(target, offset, size, data); return 0; #endif diff --git a/media-layer/trampoline/src/guest/guest.cpp b/media-layer/trampoline/src/guest/guest.cpp index 0270819040..cc1d324944 100644 --- a/media-layer/trampoline/src/guest/guest.cpp +++ b/media-layer/trampoline/src/guest/guest.cpp @@ -6,9 +6,9 @@ #include "guest.h" // 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 - const long ret = syscall(TRAMPOLINE_SYSCALL, id, length, args); + const long ret = syscall(TRAMPOLINE_SYSCALL, id, args); if (ret == -1) { // Error 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; } -// Pipe Method (Native Trampoline Only) +// Pipe Method static int get_pipe(const char *env) { const char *value = getenv(env); 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 return_value_pipe = -1; if (arguments_pipe == -1) { - arguments_pipe = get_pipe(TRAMPOLINE_ARGUMENTS_PIPE_ENV); - return_value_pipe = get_pipe(TRAMPOLINE_RETURN_VALUE_PIPE_ENV); + arguments_pipe = get_pipe(_MCPI_TRAMPOLINE_ARGUMENTS_ENV); + return_value_pipe = get_pipe(_MCPI_TRAMPOLINE_RETURN_VALUE_ENV); } // Write Command 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 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 - static bool use_syscall = getenv(TRAMPOLINE_ARGUMENTS_PIPE_ENV) == nullptr; + static bool use_syscall = getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) == nullptr; // Use Correct Method if (use_syscall) { - return trampoline_syscall(id, length, args); + return trampoline_syscall(id, args); } else { return trampoline_pipe(id, allow_early_return, length, args); } diff --git a/media-layer/trampoline/src/guest/guest.h b/media-layer/trampoline/src/guest/guest.h index 8cf3133fdd..00d75fc265 100644 --- a/media-layer/trampoline/src/guest/guest.h +++ b/media-layer/trampoline/src/guest/guest.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "../common/common.h" @@ -34,11 +35,17 @@ struct copy_array { }; template <> inline void _handle_trampoline_arg(unsigned char *&out, const copy_array &arg) { - *(uint32_t *) out = arg.size; - out += sizeof(uint32_t); + // Send Size + _handle_trampoline_arg(out, arg.size); + // Send Data if (arg.size > 0) { - memcpy(out, arg.data, arg.size); - out += arg.size; + 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); + out += arg.size; + } } } // Variadic Templates diff --git a/media-layer/trampoline/src/host/host.h b/media-layer/trampoline/src/host/host.h index 2ebefbffce..0c7b4165e1 100644 --- a/media-layer/trampoline/src/host/host.h +++ b/media-layer/trampoline/src/host/host.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "../common/common.h" // Trampoline Function @@ -38,12 +40,16 @@ struct TrampolineArguments { if (length != nullptr) { *length = size / sizeof(T); } + static bool just_read_pointer = getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) == nullptr; if (size == 0) { return nullptr; + } else if (just_read_pointer) { + return (const T *) (uintptr_t) (QEMU_GUEST_BASE + next()); + } else { + const T *ret = (const T *) raw_args; + raw_args += size; + return ret; } - const T *ret = (const T *) raw_args; - raw_args += size; - return ret; } private: