Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions lib/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,11 @@ function _getArtMethodSpec (vm) {
const entrypointFieldSize = (apiLevel <= 21) ? 8 : pointerSize;

const expectedAccessFlags = kAccPublic | kAccStatic | kAccFinal | kAccNative;
const relevantAccessFlagsMask = ~(kAccFastInterpreterToInterpreterInvoke | kAccPublicApi | kAccNterpInvokeFastPathFlag) >>> 0;
// kAccNterpEntryPointFastPathFlag must be masked off too: on Android 17 the
// probe method (Process.getElapsedCpuTime) carries it, so leaving it set makes
// the offset-4 access_flags fail to match, and the scan latches onto the next
// ArtMethod's flags one stride over, corrupting every method's flag offset.
const relevantAccessFlagsMask = ~(kAccFastInterpreterToInterpreterInvoke | kAccPublicApi | kAccNterpInvokeFastPathFlag | kAccNterpEntryPointFastPathFlag) >>> 0;

let jniCodeOffset = null;
let accessFlagsOffset = null;
Expand Down Expand Up @@ -4866,15 +4870,23 @@ function recompileExceptionClearForArm64 (buffer, pc, exceptionClearImpl, nextFu

const writer = new Arm64Writer(buffer, { pc });

writer.putBLabel('performTransition');

// Emit the invokeCallback subroutine first and flush the literal pool right
// after it. putCallAddressWithArguments() loads `callback` through a
// PC-relative literal whose pool entry has only ±1 MiB of reach. The relocated
// ExceptionClear body that follows can exceed that on Android 17 (ExceptionClear
// and the next function sit ~2 MiB apart), so deferring the pool to dispose()
// leaves the load as an unresolved `ldr xN, #0` that reads its own bytes and
// branches to garbage (PC-alignment SIGBUS). Flushing here keeps the pool in
// range; it sits after a ret, so it is never executed, and the transition body
// that follows becomes the entrypoint.
const invokeCallback = pc.add(writer.offset);
writer.putPushAllXRegisters();
writer.putCallAddressWithArguments(callback, ['x0']);
writer.putPopAllXRegisters();
writer.putRet();
writer.flush();

writer.putLabel('performTransition');
const performEntry = pc.add(writer.offset);

let foundCore = false;
let threadReg = null;
Expand Down Expand Up @@ -5004,7 +5016,7 @@ function recompileExceptionClearForArm64 (buffer, pc, exceptionClearImpl, nextFu
throwThreadStateTransitionParseError();
}

return new NativeFunction(pc, 'void', ['pointer'], nativeFunctionOptions);
return new NativeFunction(performEntry, 'void', ['pointer'], nativeFunctionOptions);
}

function throwThreadStateTransitionParseError () {
Expand Down