1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "asm_support_arm.S" 18#include "interpreter/cfi_asm_support.h" 19 20/* 21 * This file contains all native entrypoints that are called using the native ABI and do not 22 * transition to the quick ABI. For example: the switch interpreter (using the native ABI) directly 23 * calls ExecuteSwitchImplAsm and this code will always return back to the switch interpreter, 24 * again using the native ABI. Because of this behaviour ExecuteSwitchImplAsm should be included in 25 * this file. This is done so these native entrypoints can be compiled independently to quick 26 * entrypoints for cases when the kRuntimeISA and kRuntimeQuickCodeISA do not match. 27 * 28 * See comment on StackType (thread.h) for definitions and examples of quick ABI/code and 29 * native ABI/code. 30 */ 31 32// Wrap ExecuteSwitchImpl in assembly method which specifies DEX PC for unwinding. 33// Argument 0: r0: The context pointer for ExecuteSwitchImpl. 34// Argument 1: r1: Pointer to the templated ExecuteSwitchImpl to call. 35// Argument 2: r2: The value of DEX PC (memory address of the methods bytecode). 36ENTRY ExecuteSwitchImplAsm 37 push {r4, lr} // 2 words of callee saves. 38 .cfi_adjust_cfa_offset 8 39 .cfi_rel_offset r4, 0 40 .cfi_rel_offset lr, 4 41 mov r4, r2 // r4 = DEX PC 42 CFI_DEFINE_DEX_PC_WITH_OFFSET(0 /* r0 */, 4 /* r4 */, 0) 43 blx r1 // Call the wrapped method. 44 pop {r4, pc} 45END ExecuteSwitchImplAsm 46 47 /* 48 * Jni dlsym lookup stub. 49 */ 50 .extern artFindNativeMethod 51 .extern artFindNativeMethodRunnable 52ENTRY art_jni_dlsym_lookup_stub 53 push {r0, r1, r2, r3, lr} @ spill regs 54 .cfi_adjust_cfa_offset 20 55 .cfi_rel_offset lr, 16 56 sub sp, #12 @ pad stack pointer to align frame 57 .cfi_adjust_cfa_offset 12 58 59 mov r0, rSELF @ pass Thread::Current() 60 // Call artFindNativeMethod() for normal native and artFindNativeMethodRunnable() 61 // for @FastNative or @CriticalNative. 62 ldr ip, [r0, #THREAD_TOP_QUICK_FRAME_OFFSET] // uintptr_t tagged_quick_frame 63 bic ip, #TAGGED_JNI_SP_MASK // ArtMethod** sp 64 ldr ip, [ip] // ArtMethod* method 65 ldr ip, [ip, #ART_METHOD_ACCESS_FLAGS_OFFSET] // uint32_t access_flags 66 tst ip, #(ACCESS_FLAGS_METHOD_IS_FAST_NATIVE | ACCESS_FLAGS_METHOD_IS_CRITICAL_NATIVE) 67 bne .Llookup_stub_fast_or_critical_native 68 blx artFindNativeMethod 69 b .Llookup_stub_continue 70.Llookup_stub_fast_or_critical_native: 71 blx artFindNativeMethodRunnable 72.Llookup_stub_continue: 73 mov r12, r0 @ save result in r12 74 75 add sp, #12 @ restore stack pointer 76 .cfi_adjust_cfa_offset -12 77 CFI_REMEMBER_STATE 78 cbz r0, 1f @ is method code null? 79 pop {r0, r1, r2, r3, lr} @ restore regs 80 .cfi_adjust_cfa_offset -20 81 .cfi_restore lr 82 bx r12 @ if non-null, tail call to method's code 831: 84 CFI_RESTORE_STATE_AND_DEF_CFA sp, 20 85 pop {r0, r1, r2, r3, pc} @ restore regs and return to caller to handle exception 86END art_jni_dlsym_lookup_stub 87 88