Rebrand! Rebrand!
This commit is contained in:
parent
54b79db457
commit
fb5508e369
@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.17.0)
|
cmake_minimum_required(VERSION 3.17.0)
|
||||||
|
|
||||||
# Start Project
|
# Start Project
|
||||||
project(trampoline)
|
project(runtime)
|
||||||
|
|
||||||
# Headers
|
# Headers
|
||||||
add_library(trampoline-headers INTERFACE)
|
add_library(trampoline-headers INTERFACE)
|
||||||
@ -11,23 +11,23 @@ target_include_directories(trampoline-headers INTERFACE include)
|
|||||||
if(NOT TRAMPOLINE_HEADERS_ONLY)
|
if(NOT TRAMPOLINE_HEADERS_ONLY)
|
||||||
# Check Architecture
|
# Check Architecture
|
||||||
include(CheckSymbolExists)
|
include(CheckSymbolExists)
|
||||||
check_symbol_exists("__aarch64__" "" USE_NATIVE_TRAMPOLINE)
|
check_symbol_exists("__aarch64__" "" USE_NATIVE_RUNTIME)
|
||||||
check_symbol_exists("__x86_64__" "" USE_QEMU_TRAMPOLINE)
|
check_symbol_exists("__x86_64__" "" USE_QEMU_RUNTIME)
|
||||||
|
|
||||||
# Include Correct Sub-Project
|
# Include Correct Sub-Project
|
||||||
set(TRAMPOLINE_RPATH "$ORIGIN/../lib/native")
|
set(RUNTIME_RPATH "$ORIGIN/../lib/native")
|
||||||
set(TRAMPOLINE_EXTRA_LINK_FLAG "--disable-new-dtags")
|
set(RUNTIME_EXTRA_LINK_FLAG "--disable-new-dtags")
|
||||||
if(USE_NATIVE_TRAMPOLINE)
|
target_compile_definitions(trampoline-headers INTERFACE MCPI_BUILD_RUNTIME)
|
||||||
|
if(USE_NATIVE_RUNTIME)
|
||||||
add_subdirectory(native)
|
add_subdirectory(native)
|
||||||
target_compile_definitions(trampoline-headers INTERFACE MCPI_USE_NATIVE_TRAMPOLINE)
|
elseif(USE_QEMU_RUNTIME)
|
||||||
elseif(USE_QEMU_TRAMPOLINE)
|
|
||||||
add_subdirectory(qemu)
|
add_subdirectory(qemu)
|
||||||
target_compile_definitions(trampoline-headers INTERFACE MCPI_USE_QEMU)
|
target_compile_definitions(trampoline-headers INTERFACE MCPI_RUNTIME_IS_QEMU)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "Unsupported Architecture")
|
message(FATAL_ERROR "Unsupported Architecture")
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
# No-Op Install Function
|
# No-Op Install Function
|
||||||
function(install_trampoline)
|
function(install_runtime)
|
||||||
endfunction()
|
endfunction()
|
||||||
endif()
|
endif()
|
19
README.md
Normal file
19
README.md
Normal 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.
|
@ -1,27 +1,25 @@
|
|||||||
project(native-trampoline)
|
project(native-runtime)
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
add_executable(trampoline
|
add_executable(runtime
|
||||||
src/memory.cpp
|
src/memory.cpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/trampoline.cpp
|
src/trampoline.cpp
|
||||||
src/ptrace/loop.cpp
|
|
||||||
src/ptrace/init.cpp
|
|
||||||
src/pipe.cpp
|
src/pipe.cpp
|
||||||
src/signals.cpp
|
src/signals.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Warnings
|
# 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
|
# Link
|
||||||
target_link_libraries(trampoline dl rt trampoline-headers)
|
target_link_libraries(runtime dl rt trampoline-headers)
|
||||||
|
|
||||||
# RPath
|
# RPath
|
||||||
set_target_properties(trampoline PROPERTIES INSTALL_RPATH "${TRAMPOLINE_RPATH}")
|
set_target_properties(runtime PROPERTIES INSTALL_RPATH "${RUNTIME_RPATH}")
|
||||||
target_link_options(trampoline PRIVATE "LINKER:${TRAMPOLINE_EXTRA_LINK_FLAG}")
|
target_link_options(runtime PRIVATE "LINKER:${RUNTIME_EXTRA_LINK_FLAG}")
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
function(install_trampoline bin_dir)
|
function(install_runtime bin_dir)
|
||||||
install(TARGETS trampoline DESTINATION "${bin_dir}")
|
install(TARGETS runtime DESTINATION "${bin_dir}")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
#define ERR(format, ...) \
|
#define ERR(format, ...) \
|
||||||
{ \
|
{ \
|
||||||
fprintf(stderr, "TRAMPOLINE ERROR: " format "\n", ##__VA_ARGS__); \
|
fprintf(stderr, "RUNTIME ERROR: " format "\n", ##__VA_ARGS__); \
|
||||||
exit(EXIT_FAILURE); \
|
exit(EXIT_FAILURE); \
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
@ -25,6 +26,8 @@ int main(__attribute__((unused)) int argc, char *argv[]) {
|
|||||||
// Setup
|
// Setup
|
||||||
setpgid(0, 0);
|
setpgid(0, 0);
|
||||||
init_pipe_guest();
|
init_pipe_guest();
|
||||||
|
// Kill Child If Parent Exits First
|
||||||
|
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||||
// Execute Program
|
// Execute Program
|
||||||
execvp(argv[1], (char *const *) &argv[1]);
|
execvp(argv[1], (char *const *) &argv[1]);
|
||||||
ERR("Unable To Execute Program: %s: %s", argv[1], strerror(errno));
|
ERR("Unable To Execute Program: %s: %s", argv[1], strerror(errno));
|
||||||
|
@ -10,21 +10,6 @@ static pid_t guest_pid;
|
|||||||
void init_memory(pid_t pid) {
|
void init_memory(pid_t pid) {
|
||||||
guest_pid = 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) {
|
void memory_writer(uint32_t guest_addr, const void *data, uint32_t size) {
|
||||||
iovec local[1];
|
iovec local[1];
|
||||||
local[0].iov_base = (void *) data;
|
local[0].iov_base = (void *) data;
|
||||||
|
@ -4,6 +4,5 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
// Read External Memory
|
// 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 memory_writer(uint32_t guest_addr, const void *data, uint32_t size);
|
||||||
void init_memory(pid_t guest_pid);
|
void init_memory(pid_t guest_pid);
|
@ -6,7 +6,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Archive
|
# Archive
|
||||||
if(NOT DEFINED TRAMPOLINE_QEMU_ARCHIVE)
|
if(NOT DEFINED RUNTIME_QEMU_ARCHIVE)
|
||||||
message(FATAL_ERROR "Missing QEMU Archive")
|
message(FATAL_ERROR "Missing QEMU Archive")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ if(DEFINED ENV{PKG_CONFIG_LIBDIR})
|
|||||||
endif()
|
endif()
|
||||||
set(EXTRA_C_FLAGS "-s -I${CMAKE_CURRENT_SOURCE_DIR}/../include")
|
set(EXTRA_C_FLAGS "-s -I${CMAKE_CURRENT_SOURCE_DIR}/../include")
|
||||||
ExternalProject_Add(qemu
|
ExternalProject_Add(qemu
|
||||||
URL "${TRAMPOLINE_QEMU_ARCHIVE}"
|
URL "${RUNTIME_QEMU_ARCHIVE}"
|
||||||
# Configure Build
|
# Configure Build
|
||||||
CONFIGURE_COMMAND
|
CONFIGURE_COMMAND
|
||||||
"${CMAKE_COMMAND}" "-E" "env"
|
"${CMAKE_COMMAND}" "-E" "env"
|
||||||
@ -36,7 +36,7 @@ ExternalProject_Add(qemu
|
|||||||
"--cross-prefix="
|
"--cross-prefix="
|
||||||
"--cc=${CMAKE_C_COMPILER}"
|
"--cc=${CMAKE_C_COMPILER}"
|
||||||
"--cxx=${CMAKE_CXX_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"
|
"--disable-debug-info"
|
||||||
"--target-list=arm-linux-user"
|
"--target-list=arm-linux-user"
|
||||||
"--without-default-features"
|
"--without-default-features"
|
||||||
@ -54,9 +54,9 @@ ExternalProject_Add(qemu
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
function(install_trampoline bin_dir legal_dir)
|
function(install_runtime bin_dir legal_dir)
|
||||||
ExternalProject_Get_property(qemu BINARY_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
|
# License
|
||||||
ExternalProject_Get_property(qemu SOURCE_DIR)
|
ExternalProject_Get_property(qemu SOURCE_DIR)
|
||||||
install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${legal_dir}/qemu")
|
install(FILES "${SOURCE_DIR}/COPYING" DESTINATION "${legal_dir}/qemu")
|
||||||
|
Loading…
Reference in New Issue
Block a user