Home | History | Annotate | Download | only in 936-search-onload
      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 
     21 #include <android-base/macros.h>
     22 #include <android-base/stringprintf.h>
     23 
     24 #include "base/macros.h"
     25 #include "jni.h"
     26 #include "jvmti.h"
     27 #include "scoped_utf_chars.h"
     28 
     29 // Test infrastructure
     30 #include "jvmti_helper.h"
     31 #include "test_env.h"
     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   }
     43   SetStandardCapabilities(jvmti_env);
     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
     66