91edd042ff
* Makefile.in: Rebuilt. * Makefile.am (ordinary_java_source_files): Added new files. * java/lang/Class.h (_Jv_sharedlib_register_hook): Declare as friend. * java/net/URLClassLoader.java (findClass): Don't use findURLResource. Use loader's getClass method. (URLLoader.getClass): New method. (addURL): Handle `gcjlib' URLs. (SoURLLoader): New class. (SoResource): Likewise. * gnu/gcj/protocol/gcjlib/Connection.java: New file. * gnu/gcj/protocol/gcjlib/Handler.java: New file. * include/jvm.h (struct _Jv_core_chain): Moved from natCore.cc. (_Jv_RegisterCoreHook): Declare. (_Jv_FindCore): Declare. * gnu/gcj/runtime/SharedLibHelper.java: New file. * gnu/gcj/runtime/natSharedLibLoader.cc (CoreHookFunc): New typedef. (core_hook): New function. (struct SharedLibDummy) [saved_core]: New field. (init): Set _Jv_RegisterCoreHook. Throw exception on failure. (register_hook): Set protection domain and class loader on new class. (finalize): Free core chain. * gnu/gcj/Core.java (Core): New constructor. * gnu/gcj/runtime/SharedLibLoader.java: Rewrote to use SharedLibHelper. * gnu/gcj/natCore.cc (_Jv_RegisterResource): Indentation fixlet. (_Jv_create_core): New function. (create): Use it. (default_register_resource): New function. (_Jv_RegisterCoreHook): New global. (_Jv_RegisterResource): Use it. (core_chain_struct): Removed. (_Jv_FindCore): New function. (_Jv_FreeCoreChain): New function. From-SVN: r70892
115 lines
2.5 KiB
C++
115 lines
2.5 KiB
C++
// natCore -- C++ side of Core
|
|
|
|
/* Copyright (C) 2001, 2002, 2003 Free Software Foundation
|
|
|
|
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. */
|
|
|
|
/* Author: Anthony Green <green@redhat.com>. */
|
|
|
|
#include <config.h>
|
|
|
|
#include <gcj/cni.h>
|
|
#include <jvm.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <java/lang/NullPointerException.h>
|
|
#include <java/io/IOException.h>
|
|
#include <gnu/gcj/Core.h>
|
|
|
|
// List of global core values.
|
|
static _Jv_core_chain *root;
|
|
|
|
static void
|
|
default_register_resource (_Jv_core_chain *node)
|
|
{
|
|
node->next = root;
|
|
root = node;
|
|
}
|
|
|
|
// This is set only when a lock is held on java.lang.Class.
|
|
// This function is called to handle a new core node.
|
|
void (*_Jv_RegisterCoreHook) (_Jv_core_chain *) = default_register_resource;
|
|
|
|
void
|
|
_Jv_RegisterResource (void *vptr)
|
|
{
|
|
char *rptr = (char *) vptr;
|
|
|
|
_Jv_core_chain *cc = (_Jv_core_chain *) _Jv_Malloc (sizeof (_Jv_core_chain));
|
|
|
|
cc->name_length = ((int *)rptr)[0];
|
|
cc->data_length = ((int *)rptr)[1];
|
|
cc->name = rptr + 2 * sizeof (int);
|
|
cc->data = cc->name + cc->name_length;
|
|
cc->next = NULL;
|
|
|
|
(*_Jv_RegisterCoreHook) (cc);
|
|
}
|
|
|
|
void
|
|
_Jv_FreeCoreChain (_Jv_core_chain *chain)
|
|
{
|
|
while (chain != NULL)
|
|
{
|
|
_Jv_core_chain *next = chain->next;
|
|
_Jv_Free (chain);
|
|
chain = next;
|
|
}
|
|
}
|
|
|
|
_Jv_core_chain *
|
|
_Jv_FindCore (_Jv_core_chain *node, jstring name)
|
|
{
|
|
char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (name) + 1);
|
|
jsize total = JvGetStringUTFRegion (name, 0, name->length(), buf);
|
|
buf[total] = '\0';
|
|
|
|
// Usually requests here end up as an absolute URL. We strip the
|
|
// initial `/'.
|
|
if (buf[0] == '/')
|
|
{
|
|
++buf;
|
|
--total;
|
|
}
|
|
|
|
while (node)
|
|
{
|
|
if (total == node->name_length
|
|
&& strncmp (buf, node->name, total) == 0)
|
|
return node;
|
|
node = node->next;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
gnu::gcj::Core *
|
|
_Jv_create_core (_Jv_core_chain *node, jstring name)
|
|
{
|
|
node = _Jv_FindCore (node, name);
|
|
|
|
gnu::gcj::Core *core = NULL;
|
|
if (node)
|
|
{
|
|
core = (gnu::gcj::Core *) _Jv_AllocObject(&gnu::gcj::Core::class$,
|
|
sizeof (gnu::gcj::Core));
|
|
core->ptr = (gnu::gcj::RawData *) node->data;
|
|
core->length = node->data_length;
|
|
}
|
|
return core;
|
|
}
|
|
|
|
gnu::gcj::Core *
|
|
gnu::gcj::Core::create (jstring name)
|
|
{
|
|
gnu::gcj::Core *core = _Jv_create_core (root, name);
|
|
if (core == NULL)
|
|
throw new java::io::IOException (JvNewStringLatin1 ("can't open core"));
|
|
return core;
|
|
}
|