Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 "base/logging.h" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 18 | #include "entrypoints/entrypoint_utils.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 19 | #include "mirror/art_method-inl.h" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 20 | #include "mirror/object-inl.h" |
| 21 | #include "object_utils.h" |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 22 | #include "scoped_thread_state_change.h" |
| 23 | #include "thread.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | // Used by the JNI dlsym stub to find the native method to invoke if none is registered. |
Ian Rogers | 04c31d2 | 2014-07-07 21:44:06 -0700 | [diff] [blame] | 28 | #if defined(__arm__) || defined(__aarch64__) |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 29 | extern "C" void* artFindNativeMethod() { |
| 30 | Thread* self = Thread::Current(); |
Ian Rogers | 04c31d2 | 2014-07-07 21:44:06 -0700 | [diff] [blame] | 31 | #else |
| 32 | extern "C" void* artFindNativeMethod(Thread* self) { |
| 33 | DCHECK_EQ(self, Thread::Current()); |
| 34 | #endif |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 35 | Locks::mutator_lock_->AssertNotHeld(self); // We come here as Native. |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 36 | ScopedObjectAccess soa(self); |
| 37 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 38 | mirror::ArtMethod* method = self->GetCurrentMethod(NULL); |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 39 | DCHECK(method != NULL); |
| 40 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 41 | // Lookup symbol address for method, on failure we'll return NULL with an exception set, |
| 42 | // otherwise we return the address of the method we found. |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 43 | void* native_code = soa.Vm()->FindCodeForNativeMethod(method); |
| 44 | if (native_code == NULL) { |
| 45 | DCHECK(self->IsExceptionPending()); |
| 46 | return NULL; |
| 47 | } else { |
| 48 | // Register so that future calls don't come here |
Ian Rogers | 1eb512d | 2013-10-18 15:42:20 -0700 | [diff] [blame] | 49 | method->RegisterNative(self, native_code, false); |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 50 | return native_code; |
| 51 | } |
| 52 | } |
| 53 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 54 | } // namespace art |