Andreas Gampe | cefaa14 | 2017-01-23 15:04:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 "search_onload.h" |
| 18 | |
| 19 | #include <inttypes.h> |
| 20 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame^] | 21 | #include <android-base/macros.h> |
| 22 | #include <android-base/stringprintf.h> |
| 23 | |
Andreas Gampe | cefaa14 | 2017-01-23 15:04:59 -0800 | [diff] [blame] | 24 | #include "base/macros.h" |
| 25 | #include "jni.h" |
Andreas Gampe | 5e03a30 | 2017-03-13 13:10:00 -0700 | [diff] [blame] | 26 | #include "jvmti.h" |
Andreas Gampe | 027444b | 2017-03-31 12:49:07 -0700 | [diff] [blame] | 27 | #include "scoped_utf_chars.h" |
Andreas Gampe | cefaa14 | 2017-01-23 15:04:59 -0800 | [diff] [blame] | 28 | |
Andreas Gampe | 3f46c96 | 2017-03-30 10:26:59 -0700 | [diff] [blame] | 29 | // Test infrastructure |
| 30 | #include "jvmti_helper.h" |
| 31 | #include "test_env.h" |
Andreas Gampe | cefaa14 | 2017-01-23 15:04:59 -0800 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | namespace Test936SearchOnload { |
| 35 | |
| 36 | jint OnLoad(JavaVM* vm, |
| 37 | char* options ATTRIBUTE_UNUSED, |
| 38 | void* reserved ATTRIBUTE_UNUSED) { |
| 39 | if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) { |
| 40 | printf("Unable to get jvmti env!\n"); |
| 41 | return 1; |
| 42 | } |
Alex Light | 3d324fd | 2017-07-20 15:38:52 -0700 | [diff] [blame] | 43 | SetStandardCapabilities(jvmti_env); |
Andreas Gampe | cefaa14 | 2017-01-23 15:04:59 -0800 | [diff] [blame] | 44 | |
| 45 | char* dex_loc = getenv("DEX_LOCATION"); |
| 46 | std::string dex1 = android::base::StringPrintf("%s/936-search-onload.jar", dex_loc); |
| 47 | std::string dex2 = android::base::StringPrintf("%s/936-search-onload-ex.jar", dex_loc); |
| 48 | |
| 49 | jvmtiError result = jvmti_env->AddToBootstrapClassLoaderSearch(dex1.c_str()); |
| 50 | if (result != JVMTI_ERROR_NONE) { |
| 51 | printf("Could not add to bootstrap classloader.\n"); |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | result = jvmti_env->AddToSystemClassLoaderSearch(dex2.c_str()); |
| 56 | if (result != JVMTI_ERROR_NONE) { |
| 57 | printf("Could not add to system classloader.\n"); |
| 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | return JNI_OK; |
| 62 | } |
| 63 | |
| 64 | } // namespace Test936SearchOnload |
| 65 | } // namespace art |