Add QEMU Patch

This commit is contained in:
TheBrokenRail 2024-05-10 18:58:39 -04:00
parent eeef63d9ef
commit e2d32cad21
3 changed files with 67 additions and 8 deletions

View File

@ -152,7 +152,7 @@ if(BUILD_NATIVE_COMPONENTS)
set(ARM_OPTIONS "${MCPI_OPTIONS}") set(ARM_OPTIONS "${MCPI_OPTIONS}")
list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm") list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm")
list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_MESSAGE:STRING=NEVER") list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_MESSAGE:STRING=NEVER")
list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>/install") list(APPEND ARM_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>")
if(NOT MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN) if(NOT MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN)
if(DEFINED CMAKE_TOOLCHAIN_FILE) if(DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}") list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}")
@ -166,7 +166,9 @@ if(BUILD_NATIVE_COMPONENTS)
DOWNLOAD_COMMAND "" DOWNLOAD_COMMAND ""
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
CMAKE_CACHE_ARGS ${ARM_OPTIONS} CMAKE_CACHE_ARGS ${ARM_OPTIONS}
INSTALL_COMMAND "${CMAKE_COMMAND}" "-E" "rm" "-rf" "<INSTALL_DIR>/install" INSTALL_COMMAND
"${CMAKE_COMMAND}" "-E"
"rm" "-rf" "<INSTALL_DIR>/${MCPI_INSTALL_DIR}"
COMMAND COMMAND
"${CMAKE_COMMAND}" "-E" "env" "${CMAKE_COMMAND}" "-E" "env"
"DESTDIR=" "DESTDIR="
@ -178,5 +180,5 @@ if(BUILD_NATIVE_COMPONENTS)
) )
# Install # Install
ExternalProject_Get_Property(arm-components INSTALL_DIR) 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() endif()

View File

@ -6,9 +6,9 @@ project(qemu)
set(QEMU_VERSION "8.2.1") set(QEMU_VERSION "8.2.1")
# Flatpak Support # Flatpak Support
set(QEMU_PATCH "") set(QEMU_FLATPAK_PATCH "")
if(MCPI_IS_FLATPAK_BUILD) if(MCPI_IS_FLATPAK_BUILD)
set(QEMU_PATCH "sed" "-i" "s/libdrm/libdrm-dis/g" "<SOURCE_DIR>/meson.build") set(QEMU_FLATPAK_PATCH "sed" "-i" "s/libdrm/libdrm-dis/g" "<SOURCE_DIR>/meson.build")
endif() endif()
# Build # Build
@ -19,6 +19,7 @@ if(DEFINED ENV{PKG_CONFIG_LIBDIR})
endif() endif()
ExternalProject_Add(qemu ExternalProject_Add(qemu
URL "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz" URL "${CMAKE_CURRENT_SOURCE_DIR}/../../archives/qemu-${QEMU_VERSION}.tar.xz"
# Configure Build
CONFIGURE_COMMAND CONFIGURE_COMMAND
"${CMAKE_COMMAND}" "-E" "env" "${CMAKE_COMMAND}" "-E" "env"
${PKGCONFIG_ENV} ${PKGCONFIG_ENV}
@ -33,12 +34,16 @@ ExternalProject_Add(qemu
"--target-list=arm-linux-user" "--target-list=arm-linux-user"
"--without-default-features" "--without-default-features"
USES_TERMINAL_CONFIGURE TRUE USES_TERMINAL_CONFIGURE TRUE
BUILD_COMMAND ninja "qemu-arm" # Build Command
BUILD_COMMAND "ninja" "qemu-arm"
BUILD_BYPRODUCTS "<BINARY_DIR>/qemu-arm"
USES_TERMINAL_BUILD TRUE USES_TERMINAL_BUILD TRUE
# Disable Install/Test Commands
INSTALL_COMMAND "" INSTALL_COMMAND ""
TEST_COMMAND "" TEST_COMMAND ""
PATCH_COMMAND ${QEMU_PATCH} # Patch Command
BUILD_BYPRODUCTS "<BINARY_DIR>/qemu-arm" PATCH_COMMAND "patch" "-p1" "<" "${CMAKE_CURRENT_SOURCE_DIR}/trampoline.patch"
COMMAND ${QEMU_FLATPAK_PATCH}
) )
# Install # Install

52
dependencies/qemu/trampoline.patch vendored Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#define _ATFILE_SOURCE
+#include <dlfcn.h>
#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,