Skip to content

Commit 652de3c

Browse files
mreastmanTaylor McNutt
andauthored
osx - Patch every matching PLT/lazy-bind entry, not just the first (#112)
plthook_replace() on macOS stopped at the first symbol match and returned immediately. On arm64 builds we observed duplicate lazy-bind entries for the same imported symbol (e.g. two separate _dlsym slots in UnityPlayer.dylib). Only patching the first left the second, actually-called slot unhooked, so Doorstop's dlsym interception (used to redirect mono_jit_init_version on modern Unity/Mono builds) never fired and Chainloader never started -- silently, with no error. Continue iterating and patch every matching entry instead. Verified against Valheim's dedicated server binary (Unity 6000.0.61f1, arm64 native, no Rosetta): before this fix, Doorstop's own verbose log showed no successful hook of dlsym/mono_jit_init_version and BepInEx.Preloader.dll was never invoked. After, the full chain (dlsym hook -> mono domain init -> Preloader.dll load and invoke) completes successfully. Co-authored-by: Taylor McNutt <mu-th-ur-6000@MU-TH-UR.local>
1 parent 1e6dee2 commit 652de3c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/nix/plthook/plthook_osx.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ int plthook_replace(plthook_t *plthook, const char *funcname, void *funcaddr, vo
985985
const char *name;
986986
void **addr;
987987
int rv;
988+
int matches = 0;
988989

989990
if (plthook == NULL) {
990991
set_errmsg("invalid argument: The first argument is null.");
@@ -1015,7 +1016,12 @@ int plthook_replace(plthook_t *plthook, const char *funcname, void *funcaddr, vo
10151016
}
10161017
continue;
10171018
matched:
1018-
if (oldfunc) {
1019+
/* A symbol can appear as more than one PLT/lazy-bind entry (observed
1020+
on arm64 builds where the classic-bind fallback produces duplicate
1021+
stub slots). Patch every matching entry instead of stopping at the
1022+
first, since the real call site may resolve through a later one. */
1023+
matches++;
1024+
if (oldfunc && matches == 1) {
10191025
*oldfunc = *addr;
10201026
}
10211027
if (plthook->readonly_segment) {
@@ -1030,6 +1036,8 @@ int plthook_replace(plthook_t *plthook, const char *funcname, void *funcaddr, vo
10301036
} else {
10311037
*addr = funcaddr;
10321038
}
1039+
}
1040+
if (matches > 0) {
10331041
return 0;
10341042
}
10351043
if (rv == EOF) {

0 commit comments

Comments
 (0)