From d78ddec5f8eaf1f27e9043f6f42be90149ccb966 Mon Sep 17 00:00:00 2001 From: Alex Light Date: Tue, 18 Apr 2017 15:20:38 -0700 Subject: Implement can_generate_native_method_bind capability This capability lets one observe and even replace the implementations of native methods when they are bound. Test: ./test.py --host -j40 Bug: 37432636 Change-Id: I2432a8e4da1a677e8011ce495296f4ab9f42eb3e --- runtime/runtime_callbacks.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'runtime/runtime_callbacks.cc') diff --git a/runtime/runtime_callbacks.cc b/runtime/runtime_callbacks.cc index 25324b52d1..16d6c13722 100644 --- a/runtime/runtime_callbacks.cc +++ b/runtime/runtime_callbacks.cc @@ -18,6 +18,7 @@ #include +#include "art_method.h" #include "base/macros.h" #include "class_linker.h" #include "thread.h" @@ -131,4 +132,25 @@ void RuntimeCallbacks::NextRuntimePhase(RuntimePhaseCallback::RuntimePhase phase } } +void RuntimeCallbacks::AddMethodCallback(MethodCallback* cb) { + method_callbacks_.push_back(cb); +} + +void RuntimeCallbacks::RemoveMethodCallback(MethodCallback* cb) { + Remove(cb, &method_callbacks_); +} + +void RuntimeCallbacks::RegisterNativeMethod(ArtMethod* method, + const void* in_cur_method, + /*out*/void** new_method) { + void* cur_method = const_cast(in_cur_method); + *new_method = cur_method; + for (MethodCallback* cb : method_callbacks_) { + cb->RegisterNativeMethod(method, cur_method, new_method); + if (*new_method != nullptr) { + cur_method = *new_method; + } + } +} + } // namespace art -- cgit v1.2.3-59-g8ed1b