1 /**
2  * Copyright (C) 2018 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 <dirent.h>
18 #include <errno.h>
19 #include <jni.h>
20 #include <linux/limits.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <string.h>
25 #include <sys/ioctl.h>
26 #include <sys/syscall.h>
27 #include <unistd.h>
28 
android_os_cts_SPMITest_leakPointer(JNIEnv * env,jobject thiz)29 jboolean android_os_cts_SPMITest_leakPointer(JNIEnv *env, jobject thiz) {
30   jboolean result = true;
31   struct dirent **namelist = NULL;
32   char *path = (char*)"/sys/kernel/debug";
33   int n = scandir(path, &namelist, NULL, NULL);
34   if (n <= 0) {
35     printf("scandir %s failed %s\n", path, strerror(errno));
36     return true;
37   }
38   int i = 0;
39   for (i = 0; i < n; ++i) {
40     if (strstr(namelist[i]->d_name, "ffffffc") != NULL) {
41       result = false;
42     }
43   }
44   while (n--) {
45     free(namelist[n]);
46   }
47   free(namelist);
48   return result;
49 }
50 
51 static JNINativeMethod gMethods[] = {
52     {"leakPointer", "()Z", (void *)android_os_cts_SPMITest_leakPointer},
53 };
54 
register_android_os_cts_SPMITest(JNIEnv * env)55 int register_android_os_cts_SPMITest(JNIEnv *env) {
56   jclass clazz = env->FindClass("android/os/cts/SPMITest");
57 
58   return env->RegisterNatives(clazz, gMethods,
59                               sizeof(gMethods) / sizeof(JNINativeMethod));
60 }
61