aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgary <>2006-08-07 13:48:59 +0000
committergary <>2006-08-07 13:48:59 +0000
commit3b1b20f2611054800a8d31ff2aedaa88da2fae04 (patch)
tree6cf536258c857420080043168abdc63d0bbff7e1
parenta1993b7b1d474b21eea6f5a1902cee192f42c236 (diff)
2006-08-07 Gary Benson <gbenson@redhat.com>
PR libgcj/28340: * java/lang/ClassLoader.java (clinit): Install a default security manager if java.security.manager is defined. (getParent, getSystemClassLoader): Use the correct stack frame during security checks. * java/net/URLClassLoader.java (findClass): Avoid calling this.toString() during VM initialization. (runtimeInitialized): New method. * java/net/natURLClassLoader.cc: New file. * Makefile.am (nat_source_files): Added the above. * Makefile.in: Rebuilt.
-rw-r--r--libjava/ChangeLog14
-rw-r--r--libjava/Makefile.am1
-rw-r--r--libjava/Makefile.in9
-rw-r--r--libjava/java/lang/ClassLoader.java38
-rw-r--r--libjava/java/net/URLClassLoader.java14
-rw-r--r--libjava/java/net/natURLClassLoader.cc22
6 files changed, 95 insertions, 3 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 9436ff9093a..7176d1b2102 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,4 +1,18 @@
2006-08-07 Gary Benson <gbenson@redhat.com>
+
+ PR libgcj/28340:
+ * java/lang/ClassLoader.java (clinit): Install a default
+ security manager if java.security.manager is defined.
+ (getParent, getSystemClassLoader): Use the correct stack
+ frame during security checks.
+ * java/net/URLClassLoader.java (findClass): Avoid calling
+ this.toString() during VM initialization.
+ (runtimeInitialized): New method.
+ * java/net/natURLClassLoader.cc: New file.
+ * Makefile.am (nat_source_files): Added the above.
+ * Makefile.in: Rebuilt.
+
+2006-08-07 Gary Benson <gbenson@redhat.com>
Casey Marshall <csm@gnu.org>
* java/lang/SecurityManager.java (getSecurityContext,
diff --git a/libjava/Makefile.am b/libjava/Makefile.am
index bf9f7a01a0e..83ef09485c8 100644
--- a/libjava/Makefile.am
+++ b/libjava/Makefile.am
@@ -825,6 +825,7 @@ java/lang/reflect/natField.cc \
java/lang/reflect/natMethod.cc \
java/net/natVMNetworkInterface.cc \
java/net/natInetAddress.cc \
+java/net/natURLClassLoader.cc \
java/nio/channels/natVMChannels.cc \
java/nio/natDirectByteBufferImpl.cc \
java/security/natVMAccessController.cc \
diff --git a/libjava/Makefile.in b/libjava/Makefile.in
index 57649f0875b..5818459b72c 100644
--- a/libjava/Makefile.in
+++ b/libjava/Makefile.in
@@ -289,6 +289,7 @@ am__libgcj_la_SOURCES_DIST = prims.cc jni.cc jvmti.cc exception.cc \
java/lang/reflect/natConstructor.cc \
java/lang/reflect/natField.cc java/lang/reflect/natMethod.cc \
java/net/natVMNetworkInterface.cc java/net/natInetAddress.cc \
+ java/net/natURLClassLoader.cc \
java/nio/channels/natVMChannels.cc \
java/nio/natDirectByteBufferImpl.cc \
java/security/natVMAccessController.cc \
@@ -334,6 +335,7 @@ am__objects_2 = gnu/classpath/natSystemProperties.lo \
java/lang/reflect/natConstructor.lo \
java/lang/reflect/natField.lo java/lang/reflect/natMethod.lo \
java/net/natVMNetworkInterface.lo java/net/natInetAddress.lo \
+ java/net/natURLClassLoader.lo \
java/nio/channels/natVMChannels.lo \
java/nio/natDirectByteBufferImpl.lo \
java/security/natVMAccessController.lo \
@@ -624,6 +626,7 @@ bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
+build_libsubdir = @build_libsubdir@
build_os = @build_os@
build_subdir = @build_subdir@
build_vendor = @build_vendor@
@@ -7144,6 +7147,7 @@ java/lang/reflect/natField.cc \
java/lang/reflect/natMethod.cc \
java/net/natVMNetworkInterface.cc \
java/net/natInetAddress.cc \
+java/net/natURLClassLoader.cc \
java/nio/channels/natVMChannels.cc \
java/nio/natDirectByteBufferImpl.cc \
java/security/natVMAccessController.cc \
@@ -7633,6 +7637,8 @@ java/net/natVMNetworkInterface.lo: java/net/$(am__dirstamp) \
java/net/$(DEPDIR)/$(am__dirstamp)
java/net/natInetAddress.lo: java/net/$(am__dirstamp) \
java/net/$(DEPDIR)/$(am__dirstamp)
+java/net/natURLClassLoader.lo: java/net/$(am__dirstamp) \
+ java/net/$(DEPDIR)/$(am__dirstamp)
java/nio/channels/$(am__dirstamp):
@$(mkdir_p) java/nio/channels
@: > java/nio/channels/$(am__dirstamp)
@@ -7958,6 +7964,8 @@ mostlyclean-compile:
-rm -f java/lang/reflect/natMethod.lo
-rm -f java/net/natInetAddress.$(OBJEXT)
-rm -f java/net/natInetAddress.lo
+ -rm -f java/net/natURLClassLoader.$(OBJEXT)
+ -rm -f java/net/natURLClassLoader.lo
-rm -f java/net/natVMNetworkInterface.$(OBJEXT)
-rm -f java/net/natVMNetworkInterface.lo
-rm -f java/nio/channels/natVMChannels.$(OBJEXT)
@@ -8082,6 +8090,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natField.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natMethod.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natInetAddress.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natURLClassLoader.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natVMNetworkInterface.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/natDirectByteBufferImpl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/natVMChannels.Plo@am__quote@
diff --git a/libjava/java/lang/ClassLoader.java b/libjava/java/lang/ClassLoader.java
index 13d8ca65e47..bcbfc298bd4 100644
--- a/libjava/java/lang/ClassLoader.java
+++ b/libjava/java/lang/ClassLoader.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.lang;
+import gnu.classpath.SystemProperties;
import gnu.java.util.DoubleEnumeration;
import gnu.java.util.EmptyEnumeration;
@@ -156,6 +157,39 @@ public abstract class ClassLoader
static final ClassLoader systemClassLoader =
VMClassLoader.getSystemClassLoader();
+ static
+ {
+ // Find out if we have to install a default security manager. Note
+ // that this is done here because we potentially need the system
+ // class loader to load the security manager and note also that we
+ // don't need the security manager until the system class loader
+ // is created. If the runtime chooses to use a class loader that
+ // doesn't have the system class loader as its parent, it is
+ // responsible for setting up a security manager before doing so.
+ String secman = SystemProperties.getProperty("java.security.manager");
+ if (secman != null && SecurityManager.current == null)
+ {
+ if (secman.equals("") || secman.equals("default"))
+ {
+ SecurityManager.current = new SecurityManager();
+ }
+ else
+ {
+ try
+ {
+ Class cl = Class.forName(secman, false, systemClassLoader);
+ SecurityManager.current = (SecurityManager) cl.newInstance();
+ }
+ catch (Exception x)
+ {
+ throw (InternalError)
+ new InternalError("Unable to create SecurityManager")
+ .initCause(x);
+ }
+ }
+ }
+ }
+
/**
* The default protection domain, used when defining a class with a null
* paramter for the domain.
@@ -496,7 +530,7 @@ public abstract class ClassLoader
SecurityManager sm = System.getSecurityManager();
if (sm != null)
{
- Class c = VMSecurityManager.getClassContext(ClassLoader.class)[1];
+ Class c = VMSecurityManager.getClassContext(ClassLoader.class)[0];
ClassLoader cl = c.getClassLoader();
if (cl != null && ! cl.isAncestorOf(this))
sm.checkPermission(new RuntimePermission("getClassLoader"));
@@ -739,7 +773,7 @@ public abstract class ClassLoader
SecurityManager sm = System.getSecurityManager();
if (sm != null)
{
- Class c = VMSecurityManager.getClassContext(ClassLoader.class)[1];
+ Class c = VMSecurityManager.getClassContext(ClassLoader.class)[0];
ClassLoader cl = c.getClassLoader();
if (cl != null && cl != systemClassLoader)
sm.checkPermission(new RuntimePermission("getClassLoader"));
diff --git a/libjava/java/net/URLClassLoader.java b/libjava/java/net/URLClassLoader.java
index ada4b637c32..06db7d58217 100644
--- a/libjava/java/net/URLClassLoader.java
+++ b/libjava/java/net/URLClassLoader.java
@@ -1078,7 +1078,12 @@ public class URLClassLoader extends SecureClassLoader
resource = loader.getResource(resourceName);
}
if (resource == null)
- throw new ClassNotFoundException(className + " not found in " + this);
+ {
+ String message = className + " not found";
+ if (runtimeInitialized())
+ message += " in " + this;
+ throw new ClassNotFoundException(message);
+ }
// Try to read the class data, create the CodeSource, Package and
// construct the class (and watch out for those nasty IOExceptions)
@@ -1437,4 +1442,11 @@ public class URLClassLoader extends SecureClassLoader
return loader;
}
}
+
+ /**
+ * Tell whether runtime initialization is complete.
+ *
+ * @return whether runtime initialization is complete.
+ */
+ private static native boolean runtimeInitialized();
}
diff --git a/libjava/java/net/natURLClassLoader.cc b/libjava/java/net/natURLClassLoader.cc
new file mode 100644
index 00000000000..ead0db44aff
--- /dev/null
+++ b/libjava/java/net/natURLClassLoader.cc
@@ -0,0 +1,22 @@
+// natURLClassLoader.cc -- Native part of the URLClassLoader class.
+
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+
+#include <gcj/cni.h>
+#include <jvm.h>
+
+#include <java/net/URLClassLoader.h>
+
+jboolean
+java::net::URLClassLoader::runtimeInitialized ()
+{
+ return gcj::runtimeInitialized;
+}