From c6582a1ce567ae3e1f6061448ab6d8431c0c83ac Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 16 Aug 2024 18:34:45 -0700 Subject: [PATCH] binfmt_misc: Support systemd binfmt_misc Adds support for binfmt_misc through systemd configuration paths. Their configuration files are basically the raw kernel interface description in a .conf file, quite a bit more simple than the legacy debian path. Default enable this path since systemd is the expected default arrangement these days. Fixes #2417 --- CMakeLists.txt | 1 + Data/binfmts/CMakeLists.txt | 13 +- Data/binfmts/FEX-x86.conf.in | 1 + Data/binfmts/FEX-x86_64.conf.in | 1 + Source/Tools/FEXLoader/CMakeLists.txt | 165 ++++++++++++++------------ 5 files changed, 100 insertions(+), 81 deletions(-) create mode 100644 Data/binfmts/FEX-x86.conf.in create mode 100644 Data/binfmts/FEX-x86_64.conf.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c9c47b83..09b1906f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ option(ENABLE_LIBCXX "Enables LLVM libc++" FALSE) option(ENABLE_CCACHE "Enables ccache for compile caching" TRUE) option(ENABLE_VIXL_SIMULATOR "Forces the FEX JIT to use the VIXL simulator" FALSE) option(ENABLE_VIXL_DISASSEMBLER "Enables debug disassembler output with VIXL" FALSE) +option(USE_LEGACY_BINFMTMISC "Uses legacy method of setting up binfmt_misc" FALSE) option(COMPILE_VIXL_DISASSEMBLER "Compiles the vixl disassembler in to vixl" FALSE) option(ENABLE_FEXCORE_PROFILER "Enables use of the FEXCore timeline profiling capabilities" FALSE) set (FEXCORE_PROFILER_BACKEND "gpuvis" CACHE STRING "Set which backend you want to use for the FEXCore profiler") diff --git a/Data/binfmts/CMakeLists.txt b/Data/binfmts/CMakeLists.txt index bd46383c0..0410dce7d 100644 --- a/Data/binfmts/CMakeLists.txt +++ b/Data/binfmts/CMakeLists.txt @@ -13,5 +13,14 @@ function(GenBinFmt Name) DESTINATION ${CMAKE_INSTALL_PREFIX}/share/binfmts/) endfunction() -GenBinFmt(FEX-x86.in) -GenBinFmt(FEX-x86_64.in) +if (NOT USE_LEGACY_BINFMTMISC) + configure_file(FEX-x86.conf.in ${CMAKE_BINARY_DIR}/Data/binfmts/FEX-x86.conf) + configure_file(FEX-x86_64.conf.in ${CMAKE_BINARY_DIR}/Data/binfmts/FEX-x86_64.conf) + + install( + FILES ${CMAKE_BINARY_DIR}/Data/binfmts/FEX-x86.conf ${CMAKE_BINARY_DIR}/Data/binfmts/FEX-x86_64.conf + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/binfmt.d/) +else() + GenBinFmt(FEX-x86.in) + GenBinFmt(FEX-x86_64.in) +endif() diff --git a/Data/binfmts/FEX-x86.conf.in b/Data/binfmts/FEX-x86.conf.in new file mode 100644 index 000000000..7459953b8 --- /dev/null +++ b/Data/binfmts/FEX-x86.conf.in @@ -0,0 +1 @@ +:FEX-x86:M:0:\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\x00\x00\x00\xff\xff\xff\xff\xff\xfe\xff\xff\xff:@CMAKE_INSTALL_PREFIX@/bin/FEXInterpreter:POCF diff --git a/Data/binfmts/FEX-x86_64.conf.in b/Data/binfmts/FEX-x86_64.conf.in new file mode 100644 index 000000000..6c4ad882c --- /dev/null +++ b/Data/binfmts/FEX-x86_64.conf.in @@ -0,0 +1 @@ +:FEX-x86_64:M:0:\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\x00\x00\x00\xff\xff\xff\xff\xff\xfe\xff\xff\xff:@CMAKE_INSTALL_PREFIX@/bin/FEXInterpreter:POCF diff --git a/Source/Tools/FEXLoader/CMakeLists.txt b/Source/Tools/FEXLoader/CMakeLists.txt index 43bab066a..3998fb912 100644 --- a/Source/Tools/FEXLoader/CMakeLists.txt +++ b/Source/Tools/FEXLoader/CMakeLists.txt @@ -51,100 +51,107 @@ GenerateInterpreter(FEXLoader 0) GenerateInterpreter(FEXInterpreter 1) if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") - # Check for conflicting binfmt before installing - set (CONFLICTING_BINFMTS_32 - ${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-i386 - ${CMAKE_INSTALL_PREFIX}/share/binfmts/box86) - set (CONFLICTING_BINFMTS_64 - ${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-x86_64 - ${CMAKE_INSTALL_PREFIX}/share/binfmts/box64) - - find_program(UPDATE_BINFMTS_PROGRAM update-binfmts) - if (UPDATE_BINFMTS_PROGRAM) - add_custom_target(binfmt_misc_32 - echo "Attempting to install FEX-x86 misc now." - COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_32} - COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86" - COMMAND ${CMAKE_COMMAND} -E - echo "binfmt_misc FEX-x86 installed" + if (NOT USE_LEGACY_BINFMTMISC) + # Just restart the systemd service + add_custom_target(binfmt_misc + echo "Restarting systemd service now." + COMMAND "service" "systemd-binfmt" "restart" ) - - add_custom_target(binfmt_misc_64 - COMMAND ${CMAKE_COMMAND} -E - echo "Attempting to install FEX-x86_64 misc now." - COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_64} - COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86_64" - COMMAND ${CMAKE_COMMAND} -E - echo "binfmt_misc FEX-x86_64 installed" - ) - if(TARGET uninstall) - add_custom_target(uninstall_binfmt_misc_32 - COMMAND update-binfmts --unimport FEX-x86 || (exit 0) - ) - add_custom_target(uninstall_binfmt_misc_64 - COMMAND update-binfmts --unimport FEX-x86_64 || (exit 0) - ) - - add_dependencies(uninstall uninstall_binfmt_misc_32) - add_dependencies(uninstall uninstall_binfmt_misc_64) - endif() else() - set (SUPPORTED_BINFMT_MISC_FLAGS "POCF") - execute_process(COMMAND uname -r OUTPUT_VARIABLE UNAME_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX MATCH "[0-9]+.[0-9]+" KERNEL_VERSION ${UNAME_VERSION}) - message(STATUS "Kernel version: ${KERNEL_VERSION}") + # Check for conflicting binfmt before installing + set (CONFLICTING_BINFMTS_32 + ${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-i386 + ${CMAKE_INSTALL_PREFIX}/share/binfmts/box86) + set (CONFLICTING_BINFMTS_64 + ${CMAKE_INSTALL_PREFIX}/share/binfmts/qemu-x86_64 + ${CMAKE_INSTALL_PREFIX}/share/binfmts/box64) - if (KERNEL_VERSION VERSION_GREATER_EQUAL 9999.0) - # New binfmt_misc flag for exposing the interpreter was added in version '9999.0' - # Only enable it if the host kernel is at least that. - set (SUPPORTED_BINFMT_MISC_FLAGS "POCFI") - endif() - - # In the case of update-binfmts not being available (Arch for example) then we need to install manually - add_custom_target(binfmt_misc_32 - COMMAND ${CMAKE_COMMAND} -E - echo "Attempting to remove FEX-x86 misc prior to install. Ignore permission denied" - COMMAND ${CMAKE_COMMAND} -E - echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86 || (exit 0) - COMMAND ${CMAKE_COMMAND} -E + find_program(UPDATE_BINFMTS_PROGRAM update-binfmts) + if (UPDATE_BINFMTS_PROGRAM) + add_custom_target(binfmt_misc_32 echo "Attempting to install FEX-x86 misc now." - COMMAND ${CMAKE_COMMAND} -E - echo - ':FEX-x86:M:0:\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x03\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:${SUPPORTED_BINFMT_MISC_FLAGS}' > /proc/sys/fs/binfmt_misc/register - COMMAND ${CMAKE_COMMAND} -E + COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_32} + COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86" + COMMAND ${CMAKE_COMMAND} -E echo "binfmt_misc FEX-x86 installed" ) - add_custom_target(binfmt_misc_64 - COMMAND ${CMAKE_COMMAND} -E - echo "Attempting to remove FEX-x86_64 misc prior to install. Ignore permission denied" - COMMAND ${CMAKE_COMMAND} -E - echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86_64 || (exit 0) - COMMAND ${CMAKE_COMMAND} -E + + add_custom_target(binfmt_misc_64 + COMMAND ${CMAKE_COMMAND} -E echo "Attempting to install FEX-x86_64 misc now." - COMMAND ${CMAKE_COMMAND} -E - echo - ':FEX-x86_64:M:0:\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x3e\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:${SUPPORTED_BINFMT_MISC_FLAGS}' > /proc/sys/fs/binfmt_misc/register - COMMAND ${CMAKE_COMMAND} -E + COMMAND "${CMAKE_SOURCE_DIR}/Scripts/CheckBinfmtNotInstall.sh" ${CONFLICTING_BINFMTS_64} + COMMAND "update-binfmts" "--importdir=${CMAKE_INSTALL_PREFIX}/share/binfmts/" "--import" "FEX-x86_64" + COMMAND ${CMAKE_COMMAND} -E echo "binfmt_misc FEX-x86_64 installed" ) + if(TARGET uninstall) + add_custom_target(uninstall_binfmt_misc_32 + COMMAND update-binfmts --unimport FEX-x86 || (exit 0) + ) + add_custom_target(uninstall_binfmt_misc_64 + COMMAND update-binfmts --unimport FEX-x86_64 || (exit 0) + ) - if(TARGET uninstall) - add_custom_target(uninstall_binfmt_misc_32 + add_dependencies(uninstall uninstall_binfmt_misc_32) + add_dependencies(uninstall uninstall_binfmt_misc_64) + endif() + else() + set (SUPPORTED_BINFMT_MISC_FLAGS "POCF") + execute_process(COMMAND uname -r OUTPUT_VARIABLE UNAME_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX MATCH "[0-9]+.[0-9]+" KERNEL_VERSION ${UNAME_VERSION}) + message(STATUS "Kernel version: ${KERNEL_VERSION}") + + if (KERNEL_VERSION VERSION_GREATER_EQUAL 9999.0) + # New binfmt_misc flag for exposing the interpreter was added in version '9999.0' + # Only enable it if the host kernel is at least that. + set (SUPPORTED_BINFMT_MISC_FLAGS "POCFI") + endif() + + # In the case of update-binfmts not being available (Arch for example) then we need to install manually + add_custom_target(binfmt_misc_32 + COMMAND ${CMAKE_COMMAND} -E + echo "Attempting to remove FEX-x86 misc prior to install. Ignore permission denied" COMMAND ${CMAKE_COMMAND} -E echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86 || (exit 0) - ) - add_custom_target(uninstall_binfmt_misc_64 + COMMAND ${CMAKE_COMMAND} -E + echo "Attempting to install FEX-x86 misc now." + COMMAND ${CMAKE_COMMAND} -E + echo + ':FEX-x86:M:0:\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x03\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:${SUPPORTED_BINFMT_MISC_FLAGS}' > /proc/sys/fs/binfmt_misc/register + COMMAND ${CMAKE_COMMAND} -E + echo "binfmt_misc FEX-x86 installed" + ) + add_custom_target(binfmt_misc_64 + COMMAND ${CMAKE_COMMAND} -E + echo "Attempting to remove FEX-x86_64 misc prior to install. Ignore permission denied" COMMAND ${CMAKE_COMMAND} -E echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86_64 || (exit 0) - ) + COMMAND ${CMAKE_COMMAND} -E + echo "Attempting to install FEX-x86_64 misc now." + COMMAND ${CMAKE_COMMAND} -E + echo + ':FEX-x86_64:M:0:\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x3e\\x00:\\xff\\xff\\xff\\xff\\xff\\xfe\\xfe\\x00\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:${CMAKE_INSTALL_PREFIX}/bin/FEXInterpreter:${SUPPORTED_BINFMT_MISC_FLAGS}' > /proc/sys/fs/binfmt_misc/register + COMMAND ${CMAKE_COMMAND} -E + echo "binfmt_misc FEX-x86_64 installed" + ) - add_dependencies(uninstall uninstall_binfmt_misc_32) - add_dependencies(uninstall uninstall_binfmt_misc_64) + if(TARGET uninstall) + add_custom_target(uninstall_binfmt_misc_32 + COMMAND ${CMAKE_COMMAND} -E + echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86 || (exit 0) + ) + add_custom_target(uninstall_binfmt_misc_64 + COMMAND ${CMAKE_COMMAND} -E + echo -1 > /proc/sys/fs/binfmt_misc/FEX-x86_64 || (exit 0) + ) + + add_dependencies(uninstall uninstall_binfmt_misc_32) + add_dependencies(uninstall uninstall_binfmt_misc_64) + endif() endif() + add_custom_target(binfmt_misc + DEPENDS binfmt_misc_32 + DEPENDS binfmt_misc_64 + ) endif() - - add_custom_target(binfmt_misc - DEPENDS binfmt_misc_32 - DEPENDS binfmt_misc_64 - ) endif()