@@ -42,6 +42,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242#include < spawn.h>
4343#include < fcntl.h>
4444#include < sys/wait.h>
45+ // POSIX: environ is the process environment, not always declared in headers.
46+ extern char **environ;
4547#ifdef __linux__
4648#include < sys/prctl.h>
4749#if defined(DAEMON_ARCH_armhf)
@@ -176,7 +178,7 @@ static void CheckMinAddressSysctlTooLarge()
176178}
177179
178180// Platform-specific code to load a module
179- static std::pair<Sys::OSHandle, IPC::Socket> InternalLoadModule (std::pair<IPC::Socket, IPC::Socket> pair, const char * const * args, bool reserve_mem, FS::File stderrRedirect = FS::File())
181+ static std::pair<Sys::OSHandle, IPC::Socket> InternalLoadModule (std::pair<IPC::Socket, IPC::Socket> pair, const char * const * args, bool reserve_mem, FS::File stderrRedirect = FS::File(), bool inheritEnvironment = false )
180182{
181183#ifdef _WIN32
182184 // Inherit the socket in the child process
@@ -261,6 +263,7 @@ static std::pair<Sys::OSHandle, IPC::Socket> InternalLoadModule(std::pair<IPC::S
261263 if (reserve_mem)
262264 VirtualAllocEx (processInfo.hProcess , nullptr , 1 << 30 , MEM_RESERVE, PAGE_NOACCESS);
263265#endif
266+ Q_UNUSED (inheritEnvironment);
264267
265268 ResumeThread (processInfo.hThread );
266269 CloseHandle (processInfo.hThread );
@@ -281,7 +284,13 @@ static std::pair<Sys::OSHandle, IPC::Socket> InternalLoadModule(std::pair<IPC::S
281284 }
282285
283286 pid_t pid;
284- int err = posix_spawn (&pid, args[0 ], &fileActions, nullptr , const_cast <char * const *>(args), nullptr );
287+ // By default, the child process gets an empty environment for sandboxing.
288+ // When Box64 emulation is used, the child needs to inherit the parent's
289+ // environment so Box64 can find its configuration (e.g. ~/.box64rc, HOME)
290+ // and honor settings like BOX64_DYNAREC_PERFMAP.
291+ char * emptyEnv[] = {nullptr };
292+ char ** envp = inheritEnvironment ? environ : emptyEnv;
293+ int err = posix_spawn (&pid, args[0 ], &fileActions, nullptr , const_cast <char * const *>(args), envp);
285294 posix_spawn_file_actions_destroy (&fileActions);
286295 if (err != 0 ) {
287296 Sys::Drop (" VM: Failed to spawn process: %s" , strerror (err));
@@ -305,6 +314,7 @@ static std::pair<Sys::OSHandle, IPC::Socket> CreateNaClVM(std::pair<IPC::Socket,
305314 FS::File stderrRedirect;
306315#if defined(DAEMON_NACL_BOX64_EMULATION)
307316 std::string box64Path;
317+ bool usingBox64 = false ;
308318#endif
309319#if !defined(_WIN32) || defined(_WIN64)
310320 constexpr bool win32Force64Bit = false ;
@@ -380,6 +390,7 @@ static std::pair<Sys::OSHandle, IPC::Socket> CreateNaClVM(std::pair<IPC::Socket,
380390 Log::Notice (" Using Box64 emulator: %s" , box64Path);
381391 args.push_back (box64Path.c_str ());
382392 args.push_back (nacl_loader.c_str ());
393+ usingBox64 = true ;
383394 }
384395#else
385396 if (vm_nacl_bootstrap.Get ()) {
@@ -517,7 +528,11 @@ static std::pair<Sys::OSHandle, IPC::Socket> CreateNaClVM(std::pair<IPC::Socket,
517528 Log::Notice (" Using loader args: %s" , commandLine.c_str ());
518529 }
519530
520- return InternalLoadModule (std::move (pair), args.data (), true , std::move (stderrRedirect));
531+ return InternalLoadModule (std::move (pair), args.data (), true , std::move (stderrRedirect)
532+ #if defined(DAEMON_NACL_BOX64_EMULATION)
533+ , usingBox64
534+ #endif
535+ );
521536}
522537
523538static std::pair<Sys::OSHandle, IPC::Socket> CreateNativeVM (std::pair<IPC::Socket, IPC::Socket> pair, Str::StringRef name, bool debug) {
0 commit comments