Rebrand! Rebrand!

This commit is contained in:
TheBrokenRail 2024-06-08 05:28:22 -04:00
parent 54b79db457
commit fb5508e369
8 changed files with 46 additions and 42 deletions

View File

@ -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()

19
README.md Normal file
View File

@ -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.

View File

@ -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()

View File

@ -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); \
}

View File

@ -2,6 +2,7 @@
#include <cstring>
#include <cerrno>
#include <sys/wait.h>
#include <sys/prctl.h>
#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));

View File

@ -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;

View File

@ -4,6 +4,5 @@
#include <sys/types.h>
// 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);

View File

@ -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")