From e2d32cad211fa473ac20b49b172a06a479defdfd Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 10 May 2024 18:58:39 -0400 Subject: [PATCH] Add QEMU Patch --- CMakeLists.txt | 8 +++-- dependencies/qemu/CMakeLists.txt | 15 ++++++--- dependencies/qemu/trampoline.patch | 52 ++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 dependencies/qemu/trampoline.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b5aceb00a..4e0ab89a31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,7 +152,7 @@ if(BUILD_NATIVE_COMPONENTS) set(ARM_OPTIONS "${MCPI_OPTIONS}") list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm") list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_MESSAGE:STRING=NEVER") - list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=/install") + list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=") if(NOT MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN) if(DEFINED CMAKE_TOOLCHAIN_FILE) list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}") @@ -166,7 +166,9 @@ if(BUILD_NATIVE_COMPONENTS) DOWNLOAD_COMMAND "" SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CMAKE_CACHE_ARGS ${ARM_OPTIONS} - INSTALL_COMMAND "${CMAKE_COMMAND}" "-E" "rm" "-rf" "/install" + INSTALL_COMMAND + "${CMAKE_COMMAND}" "-E" + "rm" "-rf" "/${MCPI_INSTALL_DIR}" COMMAND "${CMAKE_COMMAND}" "-E" "env" "DESTDIR=" @@ -178,5 +180,5 @@ if(BUILD_NATIVE_COMPONENTS) ) # Install ExternalProject_Get_Property(arm-components INSTALL_DIR) - install(DIRECTORY "${INSTALL_DIR}/install/${MCPI_INSTALL_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}") + install(DIRECTORY "${INSTALL_DIR}/${MCPI_INSTALL_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}") endif() diff --git a/dependencies/qemu/CMakeLists.txt b/dependencies/qemu/CMakeLists.txt index 08f3feb6a0..c7b048f200 100644 --- a/dependencies/qemu/CMakeLists.txt +++ b/dependencies/qemu/CMakeLists.txt @@ -6,9 +6,9 @@ project(qemu) set(QEMU_VERSION "8.2.1") # Flatpak Support -set(QEMU_PATCH "") +set(QEMU_FLATPAK_PATCH "") if(MCPI_IS_FLATPAK_BUILD) - set(QEMU_PATCH "sed" "-i" "s/libdrm/libdrm-dis/g" "/meson.build") + set(QEMU_FLATPAK_PATCH "sed" "-i" "s/libdrm/libdrm-dis/g" "/meson.build") endif() # Build @@ -19,6 +19,7 @@ if(DEFINED ENV{PKG_CONFIG_LIBDIR}) endif() ExternalProject_Add(qemu URL "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz" + # Configure Build CONFIGURE_COMMAND "${CMAKE_COMMAND}" "-E" "env" ${PKGCONFIG_ENV} @@ -33,12 +34,16 @@ ExternalProject_Add(qemu "--target-list=arm-linux-user" "--without-default-features" USES_TERMINAL_CONFIGURE TRUE - BUILD_COMMAND ninja "qemu-arm" + # Build Command + BUILD_COMMAND "ninja" "qemu-arm" + BUILD_BYPRODUCTS "/qemu-arm" USES_TERMINAL_BUILD TRUE + # Disable Install/Test Commands INSTALL_COMMAND "" TEST_COMMAND "" - PATCH_COMMAND ${QEMU_PATCH} - BUILD_BYPRODUCTS "/qemu-arm" + # Patch Command + PATCH_COMMAND "patch" "-p1" "<" "${CMAKE_CURRENT_SOURCE_DIR}/trampoline.patch" + COMMAND ${QEMU_FLATPAK_PATCH} ) # Install diff --git a/dependencies/qemu/trampoline.patch b/dependencies/qemu/trampoline.patch new file mode 100644 index 0000000000..d4ecfb94b8 --- /dev/null +++ b/dependencies/qemu/trampoline.patch @@ -0,0 +1,52 @@ +--- a/linux-user/syscall.c ++++ b/linux-user/syscall.c +@@ -17,6 +17,7 @@ + * along with this program; if not, see . + */ + #define _ATFILE_SOURCE ++#include + #include "qemu/osdep.h" + #include "qemu/cutils.h" + #include "qemu/path.h" +@@ -9070,6 +9071,14 @@ _syscall5(int, sys_move_mount, int, __from_dfd, const char *, __from_pathname, + int, __to_dfd, const char *, __to_pathname, unsigned int, flag) + #endif + ++// g2h For Trampoline ++static CPUState *_trampoline_g2h_cpu = NULL; ++static void *_trampoline_g2h(uint32_t guest_addr) { ++ return g2h(_trampoline_g2h_cpu, guest_addr); ++} ++// Trampoline Function ++typedef uint32_t (*_trampoline_t)(typeof(_trampoline_g2h) g2h, uint32_t id, uint32_t *args); ++ + /* This is an internal helper for do_syscall so that it is easier + * to have a single return point, so that actions, such as logging + * of syscall results, can be performed. +@@ -9095,6 +9104,26 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, + void *p; + + switch(num) { ++ case 0x1337: { ++ // Load Trampoline ++ static _trampoline_t _trampoline = NULL; ++ if (_trampoline == NULL) { ++ // Open Library ++ void *_trampoline_handle = dlopen("libmedia-layer-trampoline.so", RTLD_LAZY); ++ // Load Function ++ if (_trampoline_handle != NULL) { ++ _trampoline = dlsym(_trampoline_handle, "trampoline"); ++ } ++ } ++ if (_trampoline == NULL) { ++ // Failed To Load ++ qemu_log_mask(LOG_UNIMP, "Unable To Load Media Layer Trampoline: %s\n", dlerror()); ++ return -TARGET_ENOSYS; ++ } ++ // Call Trampoline ++ _trampoline_g2h_cpu = cpu; ++ return _trampoline(_trampoline_g2h, arg1, g2h(cpu, arg2)); ++ } + case TARGET_NR_exit: + /* In old applications this may be used to implement _exit(2). + However in threaded applications it is used for thread termination,