diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f4a215413..5134e7291a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -983,12 +983,9 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER ${FULL_OUTPUT_DIR}/irt_core-${DAEMON_NACL_ARCH_NAME}.nexe ) - # Linux uses a bootstrap program to reserve address space + # Linux uses a bootstrap program to reserve address space for 32-bit runtimes if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY) if (YOKAI_TARGET_ARCH_ARM64) - add_executable(nacl_helper_bootstrap-armhf tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp) - add_dependencies(runtime_deps nacl_helper_bootstrap-armhf) - add_custom_command(TARGET runtime_deps PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${FULL_OUTPUT_DIR}/lib-armhf @@ -1001,11 +998,13 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER ) endif() - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${DEPS_DIR}/nacl_helper_bootstrap - ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap - ) + if (YOKAI_TARGET_ARCH_I686 OR YOKAI_TARGET_ARCH_ARMHF OR YOKAI_TARGET_ARCH_ARM64) + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${DEPS_DIR}/nacl_helper_bootstrap + ${FULL_OUTPUT_DIR}/nacl_helper_bootstrap + ) + endif() endif() # Win32 requires nacl_loader_amd64.exe in order to run on Win64 diff --git a/external_deps/build.sh b/external_deps/build.sh index e5e77cf91a..4bfd5c66c2 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -1106,7 +1106,6 @@ build_naclruntime() { cd "${dir_name}" env -i /usr/bin/env bash -l -c "python3 /usr/bin/scons --mode=opt-linux 'platform=${NACL_ARCH}' werror=0 sysinfo=0 sel_ldr" - cp "scons-out/opt-linux-${NACL_ARCH}/staging/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap" cp "scons-out/opt-linux-${NACL_ARCH}/staging/sel_ldr" "${PREFIX}/nacl_loader" } diff --git a/src/engine/framework/VirtualMachine.cpp b/src/engine/framework/VirtualMachine.cpp index df2739b9f3..9114c919ec 100644 --- a/src/engine/framework/VirtualMachine.cpp +++ b/src/engine/framework/VirtualMachine.cpp @@ -81,11 +81,6 @@ static Cvar::Cvar workaround_box64_disableQualification( "Disable platform qualification when running amd64 NaCl loader under Box64 emulation", Cvar::NONE, true); -static Cvar::Cvar workaround_box64_disableBootstrap( - "workaround.box64.disableBootstrap", - "Disable NaCl bootstrap helper when using Box64 emulation", - Cvar::NONE, true); - static Cvar::Cvar vm_box64_path( "vm.box64.path", "Path to the box64 binary for NaCl emulation (empty = search PATH)", @@ -128,11 +123,6 @@ static Cvar::Cvar vm_nacl_qualification( "Enable NaCl loader platform qualification", Cvar::INIT, true); -static Cvar::Cvar vm_nacl_bootstrap( - "vm.nacl.bootstrap", - "Use NaCl bootstrap helper", - Cvar::INIT, true); - static Cvar::Cvar vm_timeout( "vm.timeout", "Receive timeout in seconds", @@ -177,6 +167,22 @@ static void CheckMinAddressSysctlTooLarge() #endif // __linux__ } +#if defined(__linux__) && (defined(YOKAI_ARCH_ARM64) || defined(YOKAI_ARCH_ARMHF)) +static bool OnArm64() +{ +#if defined(YOKAI_ARCH_ARM64) + bool onArm64 = true; +#elif defined(YOKAI_ARCH_ARMHF) + bool onArm64 = false; + struct utsname buf; + if (!uname(&buf)) { + onArm64 = !strcmp(buf.machine, "aarch64"); + } +#endif + return onArm64; +} +#endif + // Platform-specific code to load a module static std::pair InternalLoadModule(std::pair pair, const char* const* args, bool reserve_mem, FS::File stderrRedirect = FS::File(), bool inheritEnvironment = false) { @@ -242,8 +248,12 @@ static std::pair InternalLoadModule(std::pair InternalLoadModule(std::pair InternalLoadModule(std::pair("LD_LIBRARY_PATH=lib-armhf"); + if (0 != posix_spawn_file_actions_addchdir_np(&fileActions, FS::GetLibPath().c_str())) { + Sys::Error("failed posix_spawn_file_actions_addchdir"); + } + } +#endif + // By default, the child process gets an empty environment for sandboxing. // When Box64 emulation is used, the child needs to inherit the parent's // environment so Box64 can find its configuration (e.g. ~/.box64rc, HOME) // and honor settings like BOX64_DYNAREC_PERFMAP. - char* emptyEnv[] = {nullptr}; char** envp = inheritEnvironment ? environ : emptyEnv; + pid_t pid; int err = posix_spawn(&pid, args[0], &fileActions, nullptr, const_cast(args), envp); posix_spawn_file_actions_destroy(&fileActions); if (err != 0) { @@ -312,9 +330,9 @@ static std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNaClVM(std::pair CreateNativeVM(std::pair pair, Str::StringRef name, bool debug) { diff --git a/tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp b/tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp deleted file mode 100644 index ec16447482..0000000000 --- a/tools/nacl_helper_bootstrap-armhf/nacl_helper_bootstrap-armhf.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -=========================================================================== -Daemon BSD Source Code -Copyright (c) 2022, Daemon Developers -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the Daemon developers nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -=========================================================================== -*/ - -#include -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) { - char *directory = dirname(strdup(argv[0])); - - int err = chdir(directory); - - if (err != 0) { - return err; - } - - err = putenv(strdup("LD_LIBRARY_PATH=lib-armhf")); - - if (err != 0) { - return err; - } - - char *helper = strdup("./nacl_helper_bootstrap"); - argv[0] = helper; - - execv(helper, argv); - - // The execv() function returns only if an error has occurred. - printf("nacl_helper_bootstrap-armhf: %s\n", strerror(errno)); - - return 1; -}