Commit b9f42bb0 by Tom Tromey Committed by Tom Tromey

Proxy.java (generate): Uncomment protection domain code.

	* java/lang/reflect/Proxy.java (generate): Uncomment protection
	domain code.
	* java/lang/natClassLoader.cc (defineClass): Added `loader'
	argument.
	(linkClass0): Now in VMClassLoader.
	(markClassErrorState0): Likewise.
	(getSystemClassLoaderInternal): New method.
	* java/lang/natClass.cc (initializeClass): Use
	VMClassLoader::resolveClass.
	* java/lang/ClassLoader.java: New version, from Classpath.
	* java/lang/Class.java (getProtectionDomain):
	protectionDomainPermission and unknownProtectionDomain now in
	VMClassLoader.
	* java/lang/Class.h: VMClassLoader now a friend class.
	* gnu/gcj/runtime/VMClassLoader.java (instance): Now
	package-private.
	* gcj/javaprims.h: Regenerated class list.
	* resolve.cc (_Jv_PrepareClass): Use VMClassLoader::resolveClass.
	* java/lang/VMClassLoader.java: New version from Classpath;
	modified for libgcj use.

From-SVN: r71765
parent d70f15d2
2003-09-25 Tom Tromey <tromey@redhat.com>
* java/lang/reflect/Proxy.java (generate): Uncomment protection
domain code.
* java/lang/natClassLoader.cc (defineClass): Added `loader'
argument.
(linkClass0): Now in VMClassLoader.
(markClassErrorState0): Likewise.
(getSystemClassLoaderInternal): New method.
* java/lang/natClass.cc (initializeClass): Use
VMClassLoader::resolveClass.
* java/lang/ClassLoader.java: New version, from Classpath.
* java/lang/Class.java (getProtectionDomain):
protectionDomainPermission and unknownProtectionDomain now in
VMClassLoader.
* java/lang/Class.h: VMClassLoader now a friend class.
* gnu/gcj/runtime/VMClassLoader.java (instance): Now
package-private.
* gcj/javaprims.h: Regenerated class list.
* resolve.cc (_Jv_PrepareClass): Use VMClassLoader::resolveClass.
* java/lang/VMClassLoader.java: New version from Classpath;
modified for libgcj use.
2003-09-25 Michael Koch <konqueror@gmx.de> 2003-09-25 Michael Koch <konqueror@gmx.de>
* java/nio/ByteBufferHelper.java: * java/nio/ByteBufferHelper.java:
......
// javaprims.h - Main external header file for libgcj. -*- c++ -*- // javaprims.h - Main external header file for libgcj. -*- c++ -*-
/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -373,6 +373,39 @@ extern "Java" ...@@ -373,6 +373,39 @@ extern "Java"
class Manifest; class Manifest;
} }
namespace logging
{
class ConsoleHandler;
class ErrorManager;
class FileHandler;
class Filter;
class Formatter;
class Handler;
class Level;
class LogManager;
class LogRecord;
class Logger;
class LoggingPermission;
class MemoryHandler;
class SimpleFormatter;
class SocketHandler;
class StreamHandler;
class XMLFormatter;
}
namespace prefs
{
class AbstractPreferences;
class BackingStoreException;
class InvalidPreferencesFormatException;
class NodeChangeEvent;
class NodeChangeListener;
class PreferenceChangeEvent;
class PreferenceChangeListener;
class Preferences;
class PreferencesFactory;
}
namespace regex namespace regex
{ {
class Matcher; class Matcher;
......
...@@ -90,7 +90,7 @@ public final class VMClassLoader extends java.net.URLClassLoader ...@@ -90,7 +90,7 @@ public final class VMClassLoader extends java.net.URLClassLoader
private int lib_control; private int lib_control;
// The only VMClassLoader that can exist. // The only VMClassLoader that can exist.
public static VMClassLoader instance = new VMClassLoader(); static VMClassLoader instance = new VMClassLoader();
private static final int LIB_FULL = 0; private static final int LIB_FULL = 0;
private static final int LIB_CACHE = 1; private static final int LIB_CACHE = 1;
......
...@@ -290,6 +290,7 @@ private: ...@@ -290,6 +290,7 @@ private:
// Friends classes and functions to implement the ClassLoader // Friends classes and functions to implement the ClassLoader
friend class java::lang::ClassLoader; friend class java::lang::ClassLoader;
friend class java::lang::VMClassLoader;
friend class java::io::ObjectOutputStream; friend class java::io::ObjectOutputStream;
friend class java::io::ObjectInputStream; friend class java::io::ObjectInputStream;
......
...@@ -227,12 +227,12 @@ public final class Class implements Serializable ...@@ -227,12 +227,12 @@ public final class Class implements Serializable
{ {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) if (sm != null)
sm.checkPermission(ClassLoader.protectionDomainPermission); sm.checkPermission(VMClassLoader.protectionDomainPermission);
ProtectionDomain protectionDomain = getProtectionDomain0(); ProtectionDomain protectionDomain = getProtectionDomain0();
if (protectionDomain == null) if (protectionDomain == null)
return ClassLoader.unknownProtectionDomain; return VMClassLoader.unknownProtectionDomain;
else else
return protectionDomain; return protectionDomain;
} }
......
...@@ -48,6 +48,7 @@ details. */ ...@@ -48,6 +48,7 @@ details. */
#include <java/lang/System.h> #include <java/lang/System.h>
#include <java/lang/SecurityManager.h> #include <java/lang/SecurityManager.h>
#include <java/lang/StringBuffer.h> #include <java/lang/StringBuffer.h>
#include <java/lang/VMClassLoader.h>
#include <gnu/gcj/runtime/StackTrace.h> #include <gnu/gcj/runtime/StackTrace.h>
#include <gcj/method.h> #include <gcj/method.h>
#include <gnu/gcj/runtime/MethodRef.h> #include <gnu/gcj/runtime/MethodRef.h>
...@@ -758,7 +759,7 @@ java::lang::Class::initializeClass (void) ...@@ -758,7 +759,7 @@ java::lang::Class::initializeClass (void)
{ {
// this can throw exceptions, so exit the monitor as a precaution. // this can throw exceptions, so exit the monitor as a precaution.
_Jv_MonitorExit (this); _Jv_MonitorExit (this);
java::lang::ClassLoader::resolveClass0 (this); java::lang::VMClassLoader::resolveClass (this);
_Jv_MonitorEnter (this); _Jv_MonitorEnter (this);
} }
else else
......
// natClassLoader.cc - Implementation of java.lang.ClassLoader native methods. // natClassLoader.cc - Implementation of java.lang.ClassLoader native methods.
/* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation /* Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -44,11 +44,12 @@ details. */ ...@@ -44,11 +44,12 @@ details. */
/////////// java.lang.ClassLoader native methods //////////// /////////// java.lang.ClassLoader native methods ////////////
java::lang::Class * java::lang::Class *
java::lang::ClassLoader::defineClass0 (jstring name, java::lang::VMClassLoader::defineClass (java::lang::ClassLoader *loader,
jbyteArray data, jstring name,
jint offset, jbyteArray data,
jint length, jint offset,
java::security::ProtectionDomain *pd) jint length,
java::security::ProtectionDomain *pd)
{ {
#ifdef INTERPRETER #ifdef INTERPRETER
jclass klass; jclass klass;
...@@ -62,8 +63,8 @@ java::lang::ClassLoader::defineClass0 (jstring name, ...@@ -62,8 +63,8 @@ java::lang::ClassLoader::defineClass0 (jstring name,
// Record the defining loader. For the system class loader, we // Record the defining loader. For the system class loader, we
// record NULL. // record NULL.
if (this != java::lang::ClassLoader::getSystemClassLoader()) if (loader != java::lang::ClassLoader::getSystemClassLoader())
klass->loader = this; klass->loader = loader;
if (name != 0) if (name != 0)
{ {
...@@ -105,6 +106,36 @@ java::lang::ClassLoader::defineClass0 (jstring name, ...@@ -105,6 +106,36 @@ java::lang::ClassLoader::defineClass0 (jstring name,
#endif #endif
} }
// Finish linking a class. Only called from ClassLoader::resolveClass.
void
java::lang::VMClassLoader::linkClass0 (java::lang::Class *klass)
{
_Jv_WaitForState (klass, JV_STATE_LINKED);
}
void
java::lang::VMClassLoader::markClassErrorState0 (java::lang::Class *klass)
{
klass->state = JV_STATE_ERROR;
klass->notifyAll ();
}
java::lang::ClassLoader *
java::lang::VMClassLoader::getSystemClassLoaderInternal()
{
_Jv_InitClass (&gnu::gcj::runtime::VMClassLoader::class$);
return gnu::gcj::runtime::VMClassLoader::instance;
}
jclass
java::lang::VMClassLoader::getPrimitiveClass (jchar type)
{
char sig[2];
sig[0] = (char) type;
sig[1] = '\0';
return _Jv_FindClassFromSignature (sig, NULL);
}
void void
_Jv_WaitForState (jclass klass, int state) _Jv_WaitForState (jclass klass, int state)
{ {
...@@ -141,39 +172,6 @@ _Jv_WaitForState (jclass klass, int state) ...@@ -141,39 +172,6 @@ _Jv_WaitForState (jclass klass, int state)
throw new java::lang::LinkageError; throw new java::lang::LinkageError;
} }
// Finish linking a class. Only called from ClassLoader::resolveClass.
void
java::lang::ClassLoader::linkClass0 (java::lang::Class *klass)
{
_Jv_WaitForState (klass, JV_STATE_LINKED);
}
void
java::lang::ClassLoader::markClassErrorState0 (java::lang::Class *klass)
{
klass->state = JV_STATE_ERROR;
klass->notifyAll ();
}
jclass
java::lang::VMClassLoader::defineClass (java::lang::ClassLoader *cl,
jstring name,
jbyteArray data,
jint offset,
jint length)
{
return cl->defineClass (name, data, offset, length);
}
jclass
java::lang::VMClassLoader::getPrimitiveClass (jchar type)
{
char sig[2];
sig[0] = (char) type;
sig[1] = '\0';
return _Jv_FindClassFromSignature (sig, NULL);
}
typedef unsigned int uaddr __attribute__ ((mode (pointer))); typedef unsigned int uaddr __attribute__ ((mode (pointer)));
/** This function does class-preparation for compiled classes. /** This function does class-preparation for compiled classes.
...@@ -281,7 +279,7 @@ _Jv_PrepareCompiledClass (jclass klass) ...@@ -281,7 +279,7 @@ _Jv_PrepareCompiledClass (jclass klass)
// The set of initiating class loaders are used to ensure // The set of initiating class loaders are used to ensure
// safety of linking, and is maintained in the hash table // safety of linking, and is maintained in the hash table
// "initiated_classes". A defining classloader is by definition also // "initiated_classes". A defining classloader is by definition also
// initiating, so we only store classes in this table, if they have more // initiating, so we only store classes in this table if they have more
// than one class loader associated. // than one class loader associated.
// //
......
...@@ -1335,17 +1335,10 @@ public class Proxy implements Serializable ...@@ -1335,17 +1335,10 @@ public class Proxy implements Serializable
{ {
// XXX Do we require more native support here? // XXX Do we require more native support here?
// XXX Security hole - it is possible for another thread to grab the
// VMClassLoader.defineClass Method object, and abuse it while we
// have temporarily made it accessible. Do we need to add some
// synchronization lock to prevent user reflection while we use it?
// XXX This is waiting on VM support for protection domains.
Class vmClassLoader = Class.forName("java.lang.VMClassLoader"); Class vmClassLoader = Class.forName("java.lang.VMClassLoader");
Class[] types = {ClassLoader.class, String.class, Class[] types = {ClassLoader.class, String.class,
byte[].class, int.class, int.class, byte[].class, int.class, int.class,
/* ProtectionDomain.class */ }; ProtectionDomain.class };
Method m = vmClassLoader.getDeclaredMethod("defineClass", types); Method m = vmClassLoader.getDeclaredMethod("defineClass", types);
// Bypass the security check of setAccessible(true), since this // Bypass the security check of setAccessible(true), since this
...@@ -1354,7 +1347,7 @@ public class Proxy implements Serializable ...@@ -1354,7 +1347,7 @@ public class Proxy implements Serializable
m.flag = true; m.flag = true;
Object[] args = {loader, qualName, bytecode, new Integer(0), Object[] args = {loader, qualName, bytecode, new Integer(0),
new Integer(bytecode.length), new Integer(bytecode.length),
/* Object.class.getProtectionDomain() */ }; Object.class.getProtectionDomain() };
Class clazz = (Class) m.invoke(null, args); Class clazz = (Class) m.invoke(null, args);
m.flag = false; m.flag = false;
......
...@@ -32,6 +32,7 @@ details. */ ...@@ -32,6 +32,7 @@ details. */
#include <java/lang/AbstractMethodError.h> #include <java/lang/AbstractMethodError.h>
#include <java/lang/NoClassDefFoundError.h> #include <java/lang/NoClassDefFoundError.h>
#include <java/lang/IncompatibleClassChangeError.h> #include <java/lang/IncompatibleClassChangeError.h>
#include <java/lang/VMClassLoader.h>
#include <java/lang/reflect/Modifier.h> #include <java/lang/reflect/Modifier.h>
using namespace gcj; using namespace gcj;
...@@ -435,7 +436,7 @@ _Jv_PrepareClass(jclass klass) ...@@ -435,7 +436,7 @@ _Jv_PrepareClass(jclass klass)
// resolved. // resolved.
if (klass->superclass) if (klass->superclass)
java::lang::ClassLoader::resolveClass0 (klass->superclass); java::lang::VMClassLoader::resolveClass (klass->superclass);
_Jv_InterpClass *clz = (_Jv_InterpClass*)klass; _Jv_InterpClass *clz = (_Jv_InterpClass*)klass;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment