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 <jni.h>
18
19 #include <string.h>
20 #include <stdbool.h>
21
22 static bool sIsAttached = false;
23
24 jint
Agent_OnAttach(JavaVM * vm,char * options,void * reserved)25 Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
26 if (options != NULL && options[0] == 'a') {
27 sIsAttached = true;
28 return JNI_OK;
29 } else {
30 return JNI_ERR;
31 }
32 }
33
34 #ifndef AGENT_NR
35 #error "Missing AGENT_NR"
36 #endif
37 #define CONCAT(A,B) A ## B
38 #define EVAL(A,B) CONCAT(A,B)
39 #define NAME(BASE) EVAL(BASE,AGENT_NR)
40
NAME(Java_android_jvmti_attaching_cts_AttachingTest_isAttached)41 JNIEXPORT jboolean JNICALL NAME(Java_android_jvmti_attaching_cts_AttachingTest_isAttached) (
42 JNIEnv* env, jclass klass) {
43 if (sIsAttached) {
44 return JNI_TRUE;
45 } else {
46 return JNI_FALSE;
47 }
48 }
49