From fb5508e36954194c9924ef5a255b07ad1da2b5ac Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 8 Jun 2024 05:28:22 -0400 Subject: [PATCH] Rebrand! Rebrand! --- CMakeLists.txt | 20 ++++++++++---------- README.md | 19 +++++++++++++++++++ native/CMakeLists.txt | 18 ++++++++---------- native/src/log.h | 2 +- native/src/main.cpp | 3 +++ native/src/memory.cpp | 15 --------------- native/src/memory.h | 1 - qemu/CMakeLists.txt | 10 +++++----- 8 files changed, 46 insertions(+), 42 deletions(-) create mode 100644 README.md diff --git a/CMakeLists.txt b/CMakeLists.txt index f368f13..a919cd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.17.0) # Start Project -project(trampoline) +project(runtime) # Headers add_library(trampoline-headers INTERFACE) @@ -11,23 +11,23 @@ target_include_directories(trampoline-headers INTERFACE include) if(NOT TRAMPOLINE_HEADERS_ONLY) # Check Architecture include(CheckSymbolExists) - check_symbol_exists("__aarch64__" "" USE_NATIVE_TRAMPOLINE) - check_symbol_exists("__x86_64__" "" USE_QEMU_TRAMPOLINE) + check_symbol_exists("__aarch64__" "" USE_NATIVE_RUNTIME) + check_symbol_exists("__x86_64__" "" USE_QEMU_RUNTIME) # Include Correct Sub-Project - set(TRAMPOLINE_RPATH "$ORIGIN/../lib/native") - set(TRAMPOLINE_EXTRA_LINK_FLAG "--disable-new-dtags") - if(USE_NATIVE_TRAMPOLINE) + set(RUNTIME_RPATH "$ORIGIN/../lib/native") + set(RUNTIME_EXTRA_LINK_FLAG "--disable-new-dtags") + target_compile_definitions(trampoline-headers INTERFACE MCPI_BUILD_RUNTIME) + if(USE_NATIVE_RUNTIME) add_subdirectory(native) - target_compile_definitions(trampoline-headers INTERFACE MCPI_USE_NATIVE_TRAMPOLINE) - elseif(USE_QEMU_TRAMPOLINE) + elseif(USE_QEMU_RUNTIME) add_subdirectory(qemu) - target_compile_definitions(trampoline-headers INTERFACE MCPI_USE_QEMU) + target_compile_definitions(trampoline-headers INTERFACE MCPI_RUNTIME_IS_QEMU) else() message(FATAL_ERROR "Unsupported Architecture") endif() else() # No-Op Install Function - function(install_trampoline) + function(install_runtime) endfunction() endif() \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c51167b --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# MCPI Runtime +**Fact:** MCPI is a 32-bit ARM binary. + +**Another fact:** Most modern computers do not use 32-bit ARM and therefore cannot run MCPI natively. + +**Solution:** This project allows MCPI to run on modern computers. + +## How +This project works differently depending on the host system's architecture. + +### 64-Bit x86 Host +On this platform, a patched version of QEMU is used. + +QEMU emulates ARM code so MCPI can run on x86 hardware. And the patch adds a system-call which allows MCPI to run graphics code on the host. This prevents the need for emulated GPU drivers. + +### 64-Bit ARM Host +QEMU is not necessary on this platform because it can already run 32-bit ARM code natively. + +Instead, the runtime is implemented as two processes: a parent and a child. The child becomes MCPI and can send graphics commands to the parent. And because the parent is 64-bit, 32-bit drivers are not needed. \ No newline at end of file diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 1756e0d..12c0e96 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -1,27 +1,25 @@ -project(native-trampoline) +project(native-runtime) # Build -add_executable(trampoline +add_executable(runtime src/memory.cpp src/main.cpp src/trampoline.cpp - src/ptrace/loop.cpp - src/ptrace/init.cpp src/pipe.cpp src/signals.cpp ) # Warnings -target_compile_options(trampoline PRIVATE -Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference) +target_compile_options(runtime PRIVATE -Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference) # Link -target_link_libraries(trampoline dl rt trampoline-headers) +target_link_libraries(runtime dl rt trampoline-headers) # RPath -set_target_properties(trampoline PROPERTIES INSTALL_RPATH "${TRAMPOLINE_RPATH}") -target_link_options(trampoline PRIVATE "LINKER:${TRAMPOLINE_EXTRA_LINK_FLAG}") +set_target_properties(runtime PROPERTIES INSTALL_RPATH "${RUNTIME_RPATH}") +target_link_options(runtime PRIVATE "LINKER:${RUNTIME_EXTRA_LINK_FLAG}") # Install -function(install_trampoline bin_dir) - install(TARGETS trampoline DESTINATION "${bin_dir}") +function(install_runtime bin_dir) + install(TARGETS runtime DESTINATION "${bin_dir}") endfunction() diff --git a/native/src/log.h b/native/src/log.h index bbc5763..c08b19c 100644 --- a/native/src/log.h +++ b/native/src/log.h @@ -5,6 +5,6 @@ #define ERR(format, ...) \ { \ - fprintf(stderr, "TRAMPOLINE ERROR: " format "\n", ##__VA_ARGS__); \ + fprintf(stderr, "RUNTIME ERROR: " format "\n", ##__VA_ARGS__); \ exit(EXIT_FAILURE); \ } diff --git a/native/src/main.cpp b/native/src/main.cpp index 1b3d1b9..778350e 100644 --- a/native/src/main.cpp +++ b/native/src/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "log.h" #include "memory.h" @@ -25,6 +26,8 @@ int main(__attribute__((unused)) int argc, char *argv[]) { // Setup setpgid(0, 0); init_pipe_guest(); + // Kill Child If Parent Exits First + prctl(PR_SET_PDEATHSIG, SIGKILL); // Execute Program execvp(argv[1], (char *const *) &argv[1]); ERR("Unable To Execute Program: %s: %s", argv[1], strerror(errno)); diff --git a/native/src/memory.cpp b/native/src/memory.cpp index 2de0e24..0b1805c 100644 --- a/native/src/memory.cpp +++ b/native/src/memory.cpp @@ -10,21 +10,6 @@ static pid_t guest_pid; void init_memory(pid_t pid) { guest_pid = pid; } -void memory_reader(uint32_t guest_addr, void *data, uint32_t size) { - if (size == 0) { - return; - } - iovec local[1]; - local[0].iov_base = data; - local[0].iov_len = size; - iovec remote[1]; - remote[0].iov_base = (void *) (uint64_t) guest_addr; - remote[0].iov_len = size; - const ssize_t ret = process_vm_readv(guest_pid, local, 1, remote, 1, 0); - if (ret != size) { - ERR("Unable To Read Data: %s", strerror(errno)); - } -} void memory_writer(uint32_t guest_addr, const void *data, uint32_t size) { iovec local[1]; local[0].iov_base = (void *) data; diff --git a/native/src/memory.h b/native/src/memory.h index 2a6a9a2..15fc92b 100644 --- a/native/src/memory.h +++ b/native/src/memory.h @@ -4,6 +4,5 @@ #include // Read External Memory -void memory_reader(uint32_t guest_addr, void *data, uint32_t size); void memory_writer(uint32_t guest_addr, const void *data, uint32_t size); void init_memory(pid_t guest_pid); \ No newline at end of file diff --git a/qemu/CMakeLists.txt b/qemu/CMakeLists.txt index 3ec551c..26115e1 100644 --- a/qemu/CMakeLists.txt +++ b/qemu/CMakeLists.txt @@ -6,7 +6,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0) endif() # Archive -if(NOT DEFINED TRAMPOLINE_QEMU_ARCHIVE) +if(NOT DEFINED RUNTIME_QEMU_ARCHIVE) message(FATAL_ERROR "Missing QEMU Archive") endif() @@ -24,7 +24,7 @@ if(DEFINED ENV{PKG_CONFIG_LIBDIR}) endif() set(EXTRA_C_FLAGS "-s -I${CMAKE_CURRENT_SOURCE_DIR}/../include") ExternalProject_Add(qemu - URL "${TRAMPOLINE_QEMU_ARCHIVE}" + URL "${RUNTIME_QEMU_ARCHIVE}" # Configure Build CONFIGURE_COMMAND "${CMAKE_COMMAND}" "-E" "env" @@ -36,7 +36,7 @@ ExternalProject_Add(qemu "--cross-prefix=" "--cc=${CMAKE_C_COMPILER}" "--cxx=${CMAKE_CXX_COMPILER}" - "--extra-ldflags=-ldl -Wl,-rpath=${TRAMPOLINE_RPATH} -Wl,${TRAMPOLINE_EXTRA_LINK_FLAG}" + "--extra-ldflags=-ldl -Wl,-rpath=${RUNTIME_RPATH} -Wl,${RUNTIME_EXTRA_LINK_FLAG}" "--disable-debug-info" "--target-list=arm-linux-user" "--without-default-features" @@ -54,9 +54,9 @@ ExternalProject_Add(qemu ) # Install -function(install_trampoline bin_dir legal_dir) +function(install_runtime bin_dir legal_dir) ExternalProject_Get_property(qemu BINARY_DIR) - install(PROGRAMS "${BINARY_DIR}/qemu-arm" DESTINATION "${bin_dir}" RENAME "trampoline") + install(PROGRAMS "${BINARY_DIR}/qemu-arm" DESTINATION "${bin_dir}" RENAME "runtime") # License ExternalProject_Get_property(qemu SOURCE_DIR) install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${legal_dir}/qemu")