mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
618c689246
Go 1.26 replaced the individual Darwin syscall entry points (syscall, syscallX, syscallPtr, syscall6, syscall6X) with two variadic functions: syscalln and rawsyscalln. The old wrappers now have Go bodies that call these, then use errno/errnoX/errnoPtr to interpret the result. This caused two bugs in our rawsyscalln implementation: 1. Return value truncation: We used call_syscall/call_syscall6 which return int32, truncating 64-bit results (pointers from fdopendir, offsets from lseek, addresses from mmap). For example, a DIR* pointer returned by fdopendir would lose its upper 32 bits on arm64, causing SIGSEGV when later accessed. 2. Lost 4th argument: The case 4/5/6 fallthrough had 'a3 = args[3]' instead of 'a4 = args[3]', and a3 was immediately overwritten by 'a1, a2, a3 = args[0], args[1], args[2]'. This lost the 4th syscall argument entirely, breaking pread (offset=0) and causing wrong data to be read from files. Fix by using call_syscallX/call_syscall6X (returning full uintptr), always reading errno (letting the Go wrappers decide what to do with it), and correcting the argument assignment.