2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
#include "jni.h"
|
|
27 |
#include "jni_util.h"
|
|
28 |
#include "jvm.h"
|
|
29 |
|
|
30 |
#include "java_lang_SecurityManager.h"
|
|
31 |
#include "java_lang_ClassLoader.h"
|
|
32 |
|
|
33 |
/*
|
|
34 |
* Make sure a security manager instance is initialized.
|
|
35 |
* TRUE means OK, FALSE means not.
|
|
36 |
*/
|
|
37 |
static jboolean
|
|
38 |
check(JNIEnv *env, jobject this)
|
|
39 |
{
|
|
40 |
static jfieldID initField = 0;
|
|
41 |
jboolean initialized = JNI_FALSE;
|
|
42 |
|
|
43 |
if (initField == 0) {
|
|
44 |
jclass clazz = (*env)->FindClass(env, "java/lang/SecurityManager");
|
|
45 |
if (clazz == 0) {
|
|
46 |
(*env)->ExceptionClear(env);
|
|
47 |
return JNI_FALSE;
|
|
48 |
}
|
|
49 |
initField = (*env)->GetFieldID(env, clazz, "initialized", "Z");
|
|
50 |
if (initField == 0) {
|
|
51 |
(*env)->ExceptionClear(env);
|
|
52 |
return JNI_FALSE;
|
|
53 |
}
|
|
54 |
}
|
|
55 |
initialized = (*env)->GetBooleanField(env, this, initField);
|
|
56 |
|
|
57 |
if (initialized == JNI_TRUE) {
|
|
58 |
return JNI_TRUE;
|
|
59 |
} else {
|
|
60 |
jclass securityException =
|
|
61 |
(*env)->FindClass(env, "java/lang/SecurityException");
|
|
62 |
if (securityException != 0) {
|
|
63 |
(*env)->ThrowNew(env, securityException,
|
|
64 |
"security manager not initialized.");
|
|
65 |
}
|
|
66 |
return JNI_FALSE;
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
JNIEXPORT jobjectArray JNICALL
|
|
71 |
Java_java_lang_SecurityManager_getClassContext(JNIEnv *env, jobject this)
|
|
72 |
{
|
|
73 |
if (!check(env, this)) {
|
|
74 |
return NULL; /* exception */
|
|
75 |
}
|
|
76 |
|
|
77 |
return JVM_GetClassContext(env);
|
|
78 |
}
|
|
79 |
|
|
80 |
JNIEXPORT jclass JNICALL
|
|
81 |
Java_java_lang_SecurityManager_currentLoadedClass0(JNIEnv *env, jobject this)
|
|
82 |
{
|
|
83 |
/* Make sure the security manager instance is initialized */
|
|
84 |
if (!check(env, this)) {
|
|
85 |
return NULL; /* exception */
|
|
86 |
}
|
|
87 |
|
|
88 |
return JVM_CurrentLoadedClass(env);
|
|
89 |
}
|
|
90 |
|
|
91 |
JNIEXPORT jobject JNICALL
|
|
92 |
Java_java_lang_SecurityManager_currentClassLoader0(JNIEnv *env, jobject this)
|
|
93 |
{
|
|
94 |
/* Make sure the security manager instance is initialized */
|
|
95 |
if (!check(env, this)) {
|
|
96 |
return NULL; /* exception */
|
|
97 |
}
|
|
98 |
|
|
99 |
return JVM_CurrentClassLoader(env);
|
|
100 |
}
|
|
101 |
|
|
102 |
JNIEXPORT jint JNICALL
|
|
103 |
Java_java_lang_SecurityManager_classDepth(JNIEnv *env, jobject this,
|
|
104 |
jstring name)
|
|
105 |
{
|
|
106 |
/* Make sure the security manager instance is initialized */
|
|
107 |
if (!check(env, this)) {
|
|
108 |
return -1; /* exception */
|
|
109 |
}
|
|
110 |
|
|
111 |
if (name == NULL) {
|
|
112 |
JNU_ThrowNullPointerException(env, 0);
|
|
113 |
return -1;
|
|
114 |
}
|
|
115 |
|
|
116 |
return JVM_ClassDepth(env, name);
|
|
117 |
}
|
|
118 |
|
|
119 |
JNIEXPORT jint JNICALL
|
|
120 |
Java_java_lang_SecurityManager_classLoaderDepth0(JNIEnv *env, jobject this)
|
|
121 |
{
|
|
122 |
/* Make sure the security manager instance is initialized */
|
|
123 |
if (!check(env, this)) {
|
|
124 |
return -1; /* exception */
|
|
125 |
}
|
|
126 |
|
|
127 |
return JVM_ClassLoaderDepth(env);
|
|
128 |
}
|