Commit b7ed2cc
authored
fix(upgrade): use MAP_PRIVATE mmap to prevent macOS SIGKILL during delta upgrade (#339)
On macOS, `sentry cli upgrade` is killed with SIGKILL when the delta
upgrade
system tries to memory-map the running binary for patch application.
## Root Cause
`Bun.mmap()` defaults to `{ shared: true }` (MAP_SHARED with
PROT_WRITE).
macOS's code signing enforcement (AMFI) sends an uncatchable SIGKILL
when a
MAP_SHARED writable mapping targets a code-signed Mach-O binary — which
every
Bun-compiled binary is (ad-hoc signed). On Linux, ELF binaries have no
such
restriction.
Because SIGKILL terminates the process inside the `mmap(2)` syscall, the
`try/catch` fallback in `attemptDeltaUpgrade()` never executes — the
process is dead before JavaScript can run any error handling.
## Fix
Pass `{ shared: false }` to `Bun.mmap()` in `src/lib/bspatch.ts` to use
MAP_PRIVATE (copy-on-write). macOS allows MAP_PRIVATE on signed binaries
because writes go to private pages, not the file. Since we only read
from
the mapping, no COW pages are allocated — performance is identical.1 parent c8aa617 commit b7ed2cc
2 files changed
+10
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
665 | 665 | | |
666 | 666 | | |
667 | 667 | | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
668 | 671 | | |
669 | 672 | | |
670 | 673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
247 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
248 | 253 | | |
249 | 254 | | |
250 | 255 | | |
| |||
0 commit comments