nodejs / postject

Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.
Other
178 stars 13 forks source link

Signing a `darwin-x64` node executable on `darwin-arm64` leads to a segmentation fault when started [SOLVED] #97

Open mn4367 opened 5 months ago

mn4367 commented 5 months ago

macOS Ventura 13.6.4 (darwin-arm64) MacBook Air M1 Node v20.11.1 (darwin-arm64)

Exactly following these docs I tried to inject a 7MB JS blob into a darwin-x64 node executable on the platform described above. This works without showing any error. But if I start the generated executable it fails with Segmentation fault: 11. It doesn't matter if I sign the generated executable or not, the error remains the same.

Doing the exact same thing but with a darwin-arm64 node executable works without problems. Below is the full content from the error report dialog which appears afterwards and shows a lot of V8 related error messages (note: the original app name has been replaced with [REDACTED]). Is it a known problem, that this kind of cross-platform doesn't work?

Edit: the same is true vice versa: injecting into a darwin-arm64 node executable on darwin-x64 also works but leads to the same error.

Full error report:

``` ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Process: [REDACTED] [12252] Path: /Users/USER/Desktop/*/[REDACTED] Identifier: [REDACTED] Version: ??? Code Type: X86-64 (Translated) Parent Process: bash [32872] Responsible: Terminal [12207] User ID: 501 Date/Time: 2024-03-25 22:42:21.6204 +0100 OS Version: macOS 13.6.4 (22G513) Report Version: 12 Anonymous UUID: 3CABB938-C8EF-4CBE-71AF-3607E1507D8F Sleep/Wake UUID: 83FF30EA-4A13-45D7-9F61-B5DAF41335B4 Time Awake Since Boot: 1500000 seconds Time Since Wake: 1324 seconds System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000e18 Exception Codes: 0x0000000000000001, 0x0000000000000e18 VM Region Info: 0xe18 is not in any region. Bytes before following region: 140722841039336 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START ---> mapped file 7ffc96f3c000-7ffcaa4d0000 [309.6M] r-x/r-x SM=COW ...t_id=cb8ac79b Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 0x10deeca30 ??? 1 [REDACTED] 0x10540529d v8::internal::HashTable::Rehash(v8::internal::PtrComprCageBase) + 493 2 libsystem_platform.dylib 0x7ff808a7c603 _sigtramp + 51 3 [REDACTED] 0x105404b30 void v8::internal::HeapObject::RehashBasedOnMap(v8::internal::Isolate*) + 240 4 [REDACTED] 0x105585396 v8::internal::Deserializer::Rehash() + 70 5 [REDACTED] 0x1055909ee v8::internal::ObjectDeserializer::Deserialize() + 142 6 [REDACTED] 0x105590934 v8::internal::ObjectDeserializer::DeserializeSharedFunctionInfo(v8::internal::Isolate*, v8::internal::SerializedCodeData const*, v8::internal::Handle) + 116 7 [REDACTED] 0x105580490 v8::internal::CodeSerializer::Deserialize(v8::internal::Isolate*, v8::internal::AlignedCachedData*, v8::internal::Handle, v8::ScriptOriginOptions, v8::internal::MaybeHandle) + 576 8 [REDACTED] 0x104fd6fd1 v8::internal::Compiler::GetWrappedFunction(v8::internal::Handle, v8::internal::Handle, v8::internal::Handle, v8::internal::ScriptDetails const&, v8::internal::AlignedCachedData*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason) + 721 9 [REDACTED] 0x104f2047a v8::ScriptCompiler::CompileFunctionInternal(v8::Local, v8::ScriptCompiler::Source*, unsigned long, v8::Local*, unsigned long, v8::Local*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason, v8::Local*) + 778 10 [REDACTED] 0x104f20169 v8::ScriptCompiler::CompileFunction(v8::Local, v8::ScriptCompiler::Source*, unsigned long, v8::Local*, unsigned long, v8::Local*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason) + 25 11 [REDACTED] 0x104d57075 node::contextify::ContextifyContext::CompileFunctionAndCacheResult(node::Environment*, v8::Local, v8::ScriptCompiler::Source*, std::__1::vector, std::__1::allocator>>, std::__1::vector, std::__1::allocator>>, v8::ScriptCompiler::CompileOptions, bool, v8::Local, node::errors::TryCatchScope const&) + 101 12 [REDACTED] 0x104d543a6 node::contextify::ContextifyContext::CompileFunction(v8::FunctionCallbackInfo const&) + 2934 13 [REDACTED] 0x104f7eda8 v8::internal::MaybeHandle v8::internal::(anonymous namespace)::HandleApiCallHelper(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, v8::internal::Handle, unsigned long*, int) + 856 14 [REDACTED] 0x104f7e36a v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) + 186 15 [REDACTED] 0x10592b1b6 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit + 54 16 [REDACTED] 0x10589cc9c Builtins_InterpreterEntryTrampoline + 220 17 [REDACTED] 0x10589cc9c Builtins_InterpreterEntryTrampoline + 220 18 [REDACTED] 0x10589cc9c Builtins_InterpreterEntryTrampoline + 220 19 [REDACTED] 0x10589b05c Builtins_JSEntryTrampoline + 92 20 [REDACTED] 0x10589ad83 Builtins_JSEntry + 131 21 [REDACTED] 0x1050629df v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 3279 22 [REDACTED] 0x105061cf5 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, int, v8::internal::Handle*) + 213 23 [REDACTED] 0x104f30a76 v8::Function::Call(v8::Local, v8::Local, int, v8::Local*) + 502 24 [REDACTED] 0x104c803d9 std::__1::__function::__func>)::$_0, std::__1::allocator>)::$_0>, v8::MaybeLocal (node::StartExecutionCallbackInfo const&)>::operator()(node::StartExecutionCallbackInfo const&) + 153 25 [REDACTED] 0x104e06789 node::RunEmbedderEntryPoint(v8::FunctionCallbackInfo const&) + 249 26 [REDACTED] 0x104f7eda8 v8::internal::MaybeHandle v8::internal::(anonymous namespace)::HandleApiCallHelper(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, v8::internal::Handle, unsigned long*, int) + 856 27 [REDACTED] 0x104f7e36a v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) + 186 28 [REDACTED] 0x10592b1b6 Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit + 54 29 [REDACTED] 0x10589cc9c Builtins_InterpreterEntryTrampoline + 220 30 [REDACTED] 0x10589b05c Builtins_JSEntryTrampoline + 92 31 [REDACTED] 0x10589ad83 Builtins_JSEntry + 131 32 [REDACTED] 0x1050629df v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 3279 33 [REDACTED] 0x105061cf5 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, int, v8::internal::Handle*) + 213 34 [REDACTED] 0x104f30a76 v8::Function::Call(v8::Local, v8::Local, int, v8::Local*) + 502 35 [REDACTED] 0x104d44537 node::builtins::BuiltinLoader::CompileAndCall(v8::Local, char const*, node::Realm*) + 311 36 [REDACTED] 0x104de3ee0 node::Realm::ExecuteBootstrapper(char const*) + 64 37 [REDACTED] 0x104d257c6 node::StartExecution(node::Environment*, std::__1::function (node::StartExecutionCallbackInfo const&)>) + 534 38 [REDACTED] 0x104c7e846 node::LoadEnvironment(node::Environment*, std::__1::basic_string_view>) + 182 39 [REDACTED] 0x104dac933 node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) + 147 40 [REDACTED] 0x104dac6ac node::NodeMainInstance::Run() + 124 41 [REDACTED] 0x104d28b93 node::Start(int, char**) + 883 42 dyld 0x20ad0d41f start + 1903 Thread 1:: com.apple.rosetta.exceptionserver 0 runtime 0x7ff7ffd35634 0x7ff7ffd31000 + 17972 Thread 2: 0 ??? 0x7ff8986669a8 ??? 1 libsystem_kernel.dylib 0x7ff808a1518a kevent + 10 2 [REDACTED] 0x1058901b9 uv__io_poll + 985 3 [REDACTED] 0x10587cf36 uv_run + 566 4 [REDACTED] 0x104dd58b2 node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Run() + 338 5 libsystem_pthread.dylib 0x7ff808a4f1d3 _pthread_start + 125 6 libsystem_pthread.dylib 0x7ff808a4abd3 thread_start + 15 Thread 3: 0 ??? 0x7ff8986669a8 ??? 1 libsystem_kernel.dylib 0x7ff808a1308e __psynch_cvwait + 10 2 libsystem_pthread.dylib 0x7ff808a4f758 _pthread_cond_wait + 1242 3 [REDACTED] 0x10588b609 uv_cond_wait + 9 4 [REDACTED] 0x104dd5ae8 node::TaskQueue::BlockingPop() + 72 5 [REDACTED] 0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317 6 libsystem_pthread.dylib 0x7ff808a4f1d3 _pthread_start + 125 7 libsystem_pthread.dylib 0x7ff808a4abd3 thread_start + 15 Thread 4: 0 ??? 0x7ff8986669a8 ??? 1 libsystem_kernel.dylib 0x7ff808a1308e __psynch_cvwait + 10 2 libsystem_pthread.dylib 0x7ff808a4f758 _pthread_cond_wait + 1242 3 [REDACTED] 0x10588b609 uv_cond_wait + 9 4 [REDACTED] 0x104dd5ae8 node::TaskQueue::BlockingPop() + 72 5 [REDACTED] 0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317 6 libsystem_pthread.dylib 0x7ff808a4f1d3 _pthread_start + 125 7 libsystem_pthread.dylib 0x7ff808a4abd3 thread_start + 15 Thread 5: 0 ??? 0x7ff8986669a8 ??? 1 libsystem_kernel.dylib 0x7ff808a1308e __psynch_cvwait + 10 2 libsystem_pthread.dylib 0x7ff808a4f758 _pthread_cond_wait + 1242 3 [REDACTED] 0x10588b609 uv_cond_wait + 9 4 [REDACTED] 0x104dd5ae8 node::TaskQueue::BlockingPop() + 72 5 [REDACTED] 0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317 6 libsystem_pthread.dylib 0x7ff808a4f1d3 _pthread_start + 125 7 libsystem_pthread.dylib 0x7ff808a4abd3 thread_start + 15 Thread 6: 0 ??? 0x7ff8986669a8 ??? 1 libsystem_kernel.dylib 0x7ff808a1308e __psynch_cvwait + 10 2 libsystem_pthread.dylib 0x7ff808a4f758 _pthread_cond_wait + 1242 3 [REDACTED] 0x10588b609 uv_cond_wait + 9 4 [REDACTED] 0x104dd5ae8 node::TaskQueue::BlockingPop() + 72 5 [REDACTED] 0x104dd29fd node::(anonymous namespace)::PlatformWorkerThread(void*) + 317 6 libsystem_pthread.dylib 0x7ff808a4f1d3 _pthread_start + 125 7 libsystem_pthread.dylib 0x7ff808a4abd3 thread_start + 15 Thread 7: 0 ??? 0x7ff8986669a8 ??? 1 libsystem_kernel.dylib 0x7ff808a104ce semaphore_wait_trap + 10 2 [REDACTED] 0x10588b4b7 uv_sem_wait + 23 3 [REDACTED] 0x104e62653 node::inspector::(anonymous namespace)::StartIoThreadMain(void*) + 19 4 libsystem_pthread.dylib 0x7ff808a4f1d3 _pthread_start + 125 5 libsystem_pthread.dylib 0x7ff808a4abd3 thread_start + 15 Thread 0 crashed with X86 Thread State (64-bit): rax: 0x000000000ba20029 rbx: 0x00000000000000db rcx: 0x0000000000000000 rdx: 0x00003f51d935ae91 rdi: 0x0000000313a7b998 rsi: 0x00003f51d935ae91 rbp: 0x0000000313a7b980 rsp: 0x0000000313a7b930 r8: 0x0000000000001000 r9: 0x00007f9848218000 r10: 0x00000000000c7201 r11: 0x00000000000bd90e r12: 0x0000000000000015 r13: 0x0000000000000001 r14: 0x00007f9856813830 r15: 0x0000000313a7b998 rip: rfl: 0x0000000000000203 tmp0: 0x00003f51ba2005b9 tmp1: 0x000000010540529d tmp2: 0x000000010b66c2a0 Binary Images: 0x20ad07000 - 0x20ada2fff dyld (*) <8678e5e0-2643-3c19-8d09-b66e9040182c> /usr/lib/dyld 0x7ff7ffd31000 - 0x7ff7ffd60fff runtime (*) <2583ff4d-96e5-316e-b62f-d032f09c96c6> /usr/libexec/rosetta/runtime 0x115edc000 - 0x115f2ffff libRosettaRuntime (*) <429951a9-d91e-35d5-aaea-eecb0a38f677> /Library/Apple/*/libRosettaRuntime 0x104c77000 - 0x109032fff [REDACTED] (*) <3c689eeb-7883-3908-a086-542366b40dad> /Users/USER/Desktop/*/[REDACTED] 0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ??? 0x7ff808a79000 - 0x7ff808a82fef libsystem_platform.dylib (*) <982c4eec-b380-3c37-ab95-14150e14dd61> /usr/lib/system/libsystem_platform.dylib 0x7ff808a0f000 - 0x7ff808a48fff libsystem_kernel.dylib (*) <32a5f9a6-e115-35ca-a4a6-abee9ebfc910> /usr/lib/system/libsystem_kernel.dylib 0x7ff808a49000 - 0x7ff808a54fff libsystem_pthread.dylib (*) <60b15e1f-39ea-33a1-8616-3af57dc1094a> /usr/lib/system/libsystem_pthread.dylib External Modification Summary: Calls made by other processes targeting this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by all processes on this machine: task_for_pid: 0 thread_create: 0 thread_set_state: 0 VM Region Summary: ReadOnly portion of Libraries: Total=378.4M resident=0K(0%) swapped_out_or_unallocated=378.4M(100%) Writable regions: Total=1.0G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.0G(100%) VIRTUAL REGION REGION TYPE SIZE COUNT (non-coalesced) =========== ======= ======= Activity Tracing 256K 1 Kernel Alloc Once 8K 1 MALLOC 162.1M 15 MALLOC guard page 96K 4 MALLOC_MEDIUM (reserved) 240.0M 2 reserved VM address space (unallocated) MALLOC_NANO (reserved) 384.0M 1 reserved VM address space (unallocated) Memory Tag 255 530.6M 28 Memory Tag 255 (reserved) 16K 1 reserved VM address space (unallocated) NODE_SEA 7544K 1 Rosetta Arena 4096K 2 Rosetta Generic 760K 187 Rosetta IndirectBranch 64K 1 Rosetta JIT 128.0M 1 Rosetta Return Stack 140K 14 Rosetta Thread Context 140K 14 Stack 48.0M 7 Stack Guard 56.0M 7 VM_ALLOCATE 13.1M 7 __DATA 3452K 142 __DATA_CONST 6827K 98 __DATA_DIRTY 348K 57 __LINKEDIT 188.8M 8 __OBJC_RO 66.3M 1 __OBJC_RW 2011K 2 __TEXT 189.6M 153 dyld private memory 260K 2 mapped file 4.3G 1267 shared memory 32K 2 unshared pmap 2976K 2 =========== ======= ======= TOTAL 6.3G 2028 TOTAL, minus reserved VM space 5.7G 2028 ----------- Full Report ----------- {"app_name":"[REDACTED]","timestamp":"2024-03-25 22:42:23.00 +0100","app_version":"","slice_uuid":"3c689eeb-7883-3908-a086-542366b40dad","build_version":"","platform":1,"share_with_app_devs":1,"is_first_party":1,"bug_type":"309","os_version":"macOS 13.6.4 (22G513)","roots_installed":0,"incident_id":"D31B3AC9-075E-4F82-BD7B-151A5E4E1C1D","name":"[REDACTED]"} { "uptime" : 1500000, "procRole" : "Unspecified", "version" : 2, "userID" : 501, "deployVersion" : 210, "modelCode" : "MacBookAir10,1", "coalitionID" : 276958, "osVersion" : { "train" : "macOS 13.6.4", "build" : "22G513", "releaseType" : "User" }, "captureTime" : "2024-03-25 22:42:21.6204 +0100", "incident" : "D31B3AC9-075E-4F82-BD7B-151A5E4E1C1D", "pid" : 12252, "translated" : true, "cpuType" : "X86-64", "roots_installed" : 0, "bug_type" : "309", "procLaunch" : "2024-03-25 22:42:17.6789 +0100", "procStartAbsTime" : 36615977491776, "procExitAbsTime" : 36616071188928, "procName" : "[REDACTED]", "procPath" : "\/Users\/USER\/Desktop\/*\/[REDACTED]", "parentProc" : "bash", "parentPid" : 32872, "coalitionName" : "com.apple.Terminal", "crashReporterKey" : "3CABB938-C8EF-4CBE-71AF-3607E1507D8F", "responsiblePid" : 12207, "responsibleProc" : "Terminal", "codeSigningID" : "", "codeSigningTeamID" : "", "codeSigningValidationCategory" : 0, "codeSigningTrustLevel" : 0, "wakeTime" : 1324, "sleepWakeUUID" : "83FF30EA-4A13-45D7-9F61-B5DAF41335B4", "sip" : "enabled", "vmRegionInfo" : "0xe18 is not in any region. Bytes before following region: 140722841039336\n REGION TYPE START - END [ VSIZE] PRT\/MAX SHRMOD REGION DETAIL\n UNUSED SPACE AT START\n---> \n mapped file 7ffc96f3c000-7ffcaa4d0000 [309.6M] r-x\/r-x SM=COW ...t_id=cb8ac79b", "exception" : {"codes":"0x0000000000000001, 0x0000000000000e18","rawCodes":[1,3608],"type":"EXC_BAD_ACCESS","signal":"SIGSEGV","subtype":"KERN_INVALID_ADDRESS at 0x0000000000000e18"}, "vmregioninfo" : "0xe18 is not in any region. Bytes before following region: 140722841039336\n REGION TYPE START - END [ VSIZE] PRT\/MAX SHRMOD REGION DETAIL\n UNUSED SPACE AT START\n---> \n mapped file 7ffc96f3c000-7ffcaa4d0000 [309.6M] r-x\/r-x SM=COW ...t_id=cb8ac79b", "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0}, "faultingThread" : 0, "threads" : [{"triggered":true,"id":46093436,"threadState":{"flavor":"x86_THREAD_STATE","rbp":{"value":13214660992},"r12":{"value":21},"rosetta":{"tmp2":{"value":4486251168},"tmp1":{"value":4383068829},"tmp0":{"value":69620247561657}},"rbx":{"value":219},"r8":{"value":4096},"r15":{"value":13214661016},"r10":{"value":815617},"rdx":{"value":69620769074833},"rdi":{"value":13214661016},"r9":{"value":140292021911552},"r13":{"value":1},"rflags":{"value":515},"rax":{"value":195166249},"rsp":{"value":13214660912},"r11":{"value":776462},"rcx":{"value":0},"r14":{"value":140292263065648},"rsi":{"value":69620769074833}},"queue":"com.apple.main-thread","frames":[{"imageOffset":4528720432,"region":"","imageIndex":4},{"imageOffset":7922333,"symbol":"v8::internal::HashTable::Rehash(v8::internal::PtrComprCageBase)","symbolLocation":493,"imageIndex":3},{"imageOffset":13827,"symbol":"_sigtramp","symbolLocation":51,"imageIndex":5},{"imageOffset":7920432,"symbol":"void v8::internal::HeapObject::RehashBasedOnMap(v8::internal::Isolate*)","symbolLocation":240,"imageIndex":3},{"imageOffset":9495446,"symbol":"v8::internal::Deserializer::Rehash()","symbolLocation":70,"imageIndex":3},{"imageOffset":9542126,"symbol":"v8::internal::ObjectDeserializer::Deserialize()","symbolLocation":142,"imageIndex":3},{"imageOffset":9541940,"symbol":"v8::internal::ObjectDeserializer::DeserializeSharedFunctionInfo(v8::internal::Isolate*, v8::internal::SerializedCodeData const*, v8::internal::Handle)","symbolLocation":116,"imageIndex":3},{"imageOffset":9475216,"symbol":"v8::internal::CodeSerializer::Deserialize(v8::internal::Isolate*, v8::internal::AlignedCachedData*, v8::internal::Handle, v8::ScriptOriginOptions, v8::internal::MaybeHandle)","symbolLocation":576,"imageIndex":3},{"imageOffset":3538897,"symbol":"v8::internal::Compiler::GetWrappedFunction(v8::internal::Handle, v8::internal::Handle, v8::internal::Handle, v8::internal::ScriptDetails const&, v8::internal::AlignedCachedData*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason)","symbolLocation":721,"imageIndex":3},{"imageOffset":2790522,"symbol":"v8::ScriptCompiler::CompileFunctionInternal(v8::Local, v8::ScriptCompiler::Source*, unsigned long, v8::Local*, unsigned long, v8::Local*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason, v8::Local*)","symbolLocation":778,"imageIndex":3},{"imageOffset":2789737,"symbol":"v8::ScriptCompiler::CompileFunction(v8::Local, v8::ScriptCompiler::Source*, unsigned long, v8::Local*, unsigned long, v8::Local*, v8::ScriptCompiler::CompileOptions, v8::ScriptCompiler::NoCacheReason)","symbolLocation":25,"imageIndex":3},{"imageOffset":917621,"symbol":"node::contextify::ContextifyContext::CompileFunctionAndCacheResult(node::Environment*, v8::Local, v8::ScriptCompiler::Source*, std::__1::vector, std::__1::allocator>>, std::__1::vector, std::__1::allocator>>, v8::ScriptCompiler::CompileOptions, bool, v8::Local, node::errors::TryCatchScope const&)","symbolLocation":101,"imageIndex":3},{"imageOffset":906150,"symbol":"node::contextify::ContextifyContext::CompileFunction(v8::FunctionCallbackInfo const&)","symbolLocation":2934,"imageIndex":3},{"imageOffset":3177896,"symbol":"v8::internal::MaybeHandle v8::internal::(anonymous namespace)::HandleApiCallHelper(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, v8::internal::Handle, unsigned long*, int)","symbolLocation":856,"imageIndex":3},{"imageOffset":3175274,"symbol":"v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*)","symbolLocation":186,"imageIndex":3},{"imageOffset":13320630,"symbol":"Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit","symbolLocation":54,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12730460,"symbol":"Builtins_JSEntryTrampoline","symbolLocation":92,"imageIndex":3},{"imageOffset":12729731,"symbol":"Builtins_JSEntry","symbolLocation":131,"imageIndex":3},{"imageOffset":4110815,"symbol":"v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&)","symbolLocation":3279,"imageIndex":3},{"imageOffset":4107509,"symbol":"v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, int, v8::internal::Handle*)","symbolLocation":213,"imageIndex":3},{"imageOffset":2857590,"symbol":"v8::Function::Call(v8::Local, v8::Local, int, v8::Local*)","symbolLocation":502,"imageIndex":3},{"imageOffset":37849,"symbol":"std::__1::__function::__func>)::$_0, std::__1::allocator>)::$_0>, v8::MaybeLocal (node::StartExecutionCallbackInfo const&)>::operator()(node::StartExecutionCallbackInfo const&)","symbolLocation":153,"imageIndex":3},{"imageOffset":1636233,"symbol":"node::RunEmbedderEntryPoint(v8::FunctionCallbackInfo const&)","symbolLocation":249,"imageIndex":3},{"imageOffset":3177896,"symbol":"v8::internal::MaybeHandle v8::internal::(anonymous namespace)::HandleApiCallHelper(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, v8::internal::Handle, unsigned long*, int)","symbolLocation":856,"imageIndex":3},{"imageOffset":3175274,"symbol":"v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*)","symbolLocation":186,"imageIndex":3},{"imageOffset":13320630,"symbol":"Builtins_CEntry_Return1_ArgvOnStack_BuiltinExit","symbolLocation":54,"imageIndex":3},{"imageOffset":12737692,"symbol":"Builtins_InterpreterEntryTrampoline","symbolLocation":220,"imageIndex":3},{"imageOffset":12730460,"symbol":"Builtins_JSEntryTrampoline","symbolLocation":92,"imageIndex":3},{"imageOffset":12729731,"symbol":"Builtins_JSEntry","symbolLocation":131,"imageIndex":3},{"imageOffset":4110815,"symbol":"v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&)","symbolLocation":3279,"imageIndex":3},{"imageOffset":4107509,"symbol":"v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle, v8::internal::Handle, int, v8::internal::Handle*)","symbolLocation":213,"imageIndex":3},{"imageOffset":2857590,"symbol":"v8::Function::Call(v8::Local, v8::Local, int, v8::Local*)","symbolLocation":502,"imageIndex":3},{"imageOffset":841015,"symbol":"node::builtins::BuiltinLoader::CompileAndCall(v8::Local, char const*, node::Realm*)","symbolLocation":311,"imageIndex":3},{"imageOffset":1494752,"symbol":"node::Realm::ExecuteBootstrapper(char const*)","symbolLocation":64,"imageIndex":3},{"imageOffset":714694,"symbol":"node::StartExecution(node::Environment*, std::__1::function (node::StartExecutionCallbackInfo const&)>)","symbolLocation":534,"imageIndex":3},{"imageOffset":30790,"symbol":"node::LoadEnvironment(node::Environment*, std::__1::basic_string_view>)","symbolLocation":182,"imageIndex":3},{"imageOffset":1268019,"symbol":"node::NodeMainInstance::Run(node::ExitCode*, node::Environment*)","symbolLocation":147,"imageIndex":3},{"imageOffset":1267372,"symbol":"node::NodeMainInstance::Run()","symbolLocation":124,"imageIndex":3},{"imageOffset":727955,"symbol":"node::Start(int, char**)","symbolLocation":883,"imageIndex":3},{"imageOffset":25631,"symbol":"start","symbolLocation":1903,"imageIndex":0}]},{"id":46093488,"name":"com.apple.rosetta.exceptionserver","frames":[{"imageOffset":17972,"imageIndex":1}]},{"id":46093489,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":24970,"symbol":"kevent","symbolLocation":10,"imageIndex":6},{"imageOffset":12685753,"symbol":"uv__io_poll","symbolLocation":985,"imageIndex":3},{"imageOffset":12607286,"symbol":"uv_run","symbolLocation":566,"imageIndex":3},{"imageOffset":1435826,"symbol":"node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Run()","symbolLocation":338,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093490,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093491,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093492,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093493,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":16526,"symbol":"__psynch_cvwait","symbolLocation":10,"imageIndex":6},{"imageOffset":26456,"symbol":"_pthread_cond_wait","symbolLocation":1242,"imageIndex":7},{"imageOffset":12666377,"symbol":"uv_cond_wait","symbolLocation":9,"imageIndex":3},{"imageOffset":1436392,"symbol":"node::TaskQueue::BlockingPop()","symbolLocation":72,"imageIndex":3},{"imageOffset":1423869,"symbol":"node::(anonymous namespace)::PlatformWorkerThread(void*)","symbolLocation":317,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]},{"id":46093494,"frames":[{"imageOffset":140705685465512,"imageIndex":4},{"imageOffset":5326,"symbol":"semaphore_wait_trap","symbolLocation":10,"imageIndex":6},{"imageOffset":12666039,"symbol":"uv_sem_wait","symbolLocation":23,"imageIndex":3},{"imageOffset":2012755,"symbol":"node::inspector::(anonymous namespace)::StartIoThreadMain(void*)","symbolLocation":19,"imageIndex":3},{"imageOffset":25043,"symbol":"_pthread_start","symbolLocation":125,"imageIndex":7},{"imageOffset":7123,"symbol":"thread_start","symbolLocation":15,"imageIndex":7}]}], "usedImages" : [ { "source" : "P", "arch" : "x86_64", "base" : 8771366912, "size" : 638976, "uuid" : "8678e5e0-2643-3c19-8d09-b66e9040182c", "path" : "\/usr\/lib\/dyld", "name" : "dyld" }, { "source" : "P", "arch" : "arm64", "base" : 140703125671936, "size" : 196608, "uuid" : "2583ff4d-96e5-316e-b62f-d032f09c96c6", "path" : "\/usr\/libexec\/rosetta\/runtime", "name" : "runtime" }, { "source" : "P", "arch" : "arm64", "base" : 4662870016, "size" : 344064, "uuid" : "429951a9-d91e-35d5-aaea-eecb0a38f677", "path" : "\/Library\/Apple\/*\/libRosettaRuntime", "name" : "libRosettaRuntime" }, { "source" : "P", "arch" : "x86_64", "base" : 4375146496, "size" : 71024640, "uuid" : "3c689eeb-7883-3908-a086-542366b40dad", "path" : "\/Users\/USER\/Desktop\/*\/[REDACTED]", "name" : "[REDACTED]" }, { "size" : 0, "source" : "A", "base" : 0, "uuid" : "00000000-0000-0000-0000-000000000000" }, { "source" : "P", "arch" : "x86_64", "base" : 140703273816064, "size" : 40944, "uuid" : "982c4eec-b380-3c37-ab95-14150e14dd61", "path" : "\/usr\/lib\/system\/libsystem_platform.dylib", "name" : "libsystem_platform.dylib" }, { "source" : "P", "arch" : "x86_64", "base" : 140703273381888, "size" : 237568, "uuid" : "32a5f9a6-e115-35ca-a4a6-abee9ebfc910", "path" : "\/usr\/lib\/system\/libsystem_kernel.dylib", "name" : "libsystem_kernel.dylib" }, { "source" : "P", "arch" : "x86_64", "base" : 140703273619456, "size" : 49152, "uuid" : "60b15e1f-39ea-33a1-8616-3af57dc1094a", "path" : "\/usr\/lib\/system\/libsystem_pthread.dylib", "name" : "libsystem_pthread.dylib" } ], "sharedCache" : { "base" : 140703269486592, "size" : 21474836480, "uuid" : "f923a52e-db00-3075-b1a9-3fdae7809671" }, "vmSummary" : "ReadOnly portion of Libraries: Total=378.4M resident=0K(0%) swapped_out_or_unallocated=378.4M(100%)\nWritable regions: Total=1.0G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.0G(100%)\n\n VIRTUAL REGION \nREGION TYPE SIZE COUNT (non-coalesced) \n=========== ======= ======= \nActivity Tracing 256K 1 \nKernel Alloc Once 8K 1 \nMALLOC 162.1M 15 \nMALLOC guard page 96K 4 \nMALLOC_MEDIUM (reserved) 240.0M 2 reserved VM address space (unallocated)\nMALLOC_NANO (reserved) 384.0M 1 reserved VM address space (unallocated)\nMemory Tag 255 530.6M 28 \nMemory Tag 255 (reserved) 16K 1 reserved VM address space (unallocated)\nNODE_SEA 7544K 1 \nRosetta Arena 4096K 2 \nRosetta Generic 760K 187 \nRosetta IndirectBranch 64K 1 \nRosetta JIT 128.0M 1 \nRosetta Return Stack 140K 14 \nRosetta Thread Context 140K 14 \nStack 48.0M 7 \nStack Guard 56.0M 7 \nVM_ALLOCATE 13.1M 7 \n__DATA 3452K 142 \n__DATA_CONST 6827K 98 \n__DATA_DIRTY 348K 57 \n__LINKEDIT 188.8M 8 \n__OBJC_RO 66.3M 1 \n__OBJC_RW 2011K 2 \n__TEXT 189.6M 153 \ndyld private memory 260K 2 \nmapped file 4.3G 1267 \nshared memory 32K 2 \nunshared pmap 2976K 2 \n=========== ======= ======= \nTOTAL 6.3G 2028 \nTOTAL, minus reserved VM space 5.7G 2028 \n", "legacyInfo" : { "threadTriggered" : { "queue" : "com.apple.main-thread" } }, "logWritingSignature" : "33b38e69a85a97bad98f692555a076c7b41d047d", "trialInfo" : { "rollouts" : [ { "rolloutId" : "62fe74515312cd4599bd3c80", "factorPackIds" : { "MYRIAD_BOOSTS" : "62fe74805312cd4599bd3c81" }, "deploymentId" : 240000006 }, { "rolloutId" : "6425c75e4327780c10cc4252", "factorPackIds" : { "SIRI_HOME_AUTOMATION_INTENT_SELECTION_CACHE" : "642600a457e7664b1698eb32" }, "deploymentId" : 240000004 } ], "experiments" : [ { "treatmentId" : "5d51a80d-93ec-47e1-9027-675002e78e4a", "experimentId" : "6384d56b96e8d228551ec182", "deploymentId" : 400000031 }, { "treatmentId" : "a3f9ec09-b145-49f3-8142-da4a1f338456", "experimentId" : "65f21aa774b6f500a45abd7d", "deploymentId" : 400000002 } ] } } Model: MacBookAir10,1, BootROM 10151.81.1, proc 8:4:4 processors, 16 GB, SMC Graphics: Apple M1, Apple M1, Built-In Display: Retina-Display, 2560 x 1600 Retina, Main, MirrorOff, Online Memory Module: LPDDR4, Hynix AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x4378), wl0: May 13 2023 07:20:48 version 18.20.383.15.7.8.150 FWID 01-b37727a5 Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports Network Service: Wi-Fi, AirPort, en0 USB Device: USB31Bus USB Device: USB31Bus Thunderbolt Bus: MacBook Air, Apple Inc. Thunderbolt Bus: MacBook Air, Apple Inc. ```
mn4367 commented 5 months ago

I have found the reason for this problem. The problem is not the behavior of postject, but a 'misconfiguration' of the blob generation when used in the context of a Node.js SEA.

The configuration file I used looked like this:

{
    "main": "server.js",
    "output": "server.js.blob",
    "disableExperimentalSEAWarning": true,
    "useSnapshot": false,
    "useCodeCache": true <= Don't use this!
}

The only problem is that useCodeCache has been set to true. This seems to create a blob that is specific to the platform it is created on, which also explains all the stack trace messages related to V8 in my original problem report. When useCodeCache is set to false, everything works fine.

Since many people seem to use postject for creating Node SEAs, it might be worth including this note in the documentation.

So it is indeed possible to create Node.js SEAs on any platform for any platform supported by postject, which is really nice (thanks for this project!).

For the specific case of injecting resources into a darwin-* executable on a Windows or Linux platform, the Apple Codesign project is a gem: it provides pre-built signing tools that allow signing darwin-* executables on win32 and linux (and also darwin) platforms. Signing is necessary at least for darwin-arm64 executables, otherwise they will no longer run after injection.