OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [gnu/] [gcj/] [runtime/] [natSharedLibLoader.cc] - Blame information for rev 22

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
// natSharedLibLoader.cc - Implementation of SharedLibHelper native methods.
2
 
3
/* Copyright (C) 2001, 2003, 2004, 2005  Free Software Foundation
4
 
5
   This file is part of libgcj.
6
 
7
This software is copyrighted work licensed under the terms of the
8
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9
details.  */
10
 
11
#include <config.h>
12
 
13
// If we're using the Boehm GC, then we need this include to override dlopen.
14
#ifdef HAVE_BOEHM_GC
15
#include <gc.h>
16
#endif /* HAVE_BOEHM_GC */
17
 
18
#include <gcj/cni.h>
19
#include <jvm.h>
20
#include <execution.h>
21
 
22
#include <gnu/gcj/runtime/SharedLibHelper.h>
23
#include <java/io/IOException.h>
24
#include <java/lang/UnsupportedOperationException.h>
25
#include <java/lang/UnknownError.h>
26
 
27
#ifdef HAVE_DLOPEN
28
#include <dlfcn.h>
29
 
30
/* Only used during dlopen, while having a lock on Class.class. */
31
static java::lang::ClassLoader *curLoader;
32
static gnu::gcj::runtime::SharedLibHelper *curHelper;
33
 
34
typedef void (*ClassHookFunc) (jclass);
35
typedef void (*CoreHookFunc) (_Jv_core_chain *);
36
 
37
void
38
_Jv_sharedlib_register_hook (jclass cls)
39
{
40
  cls->protectionDomain = curHelper->domain;
41
  cls->loader = curLoader;
42
  cls->engine = &_Jv_soleCompiledEngine;
43
  curHelper->registerClass(cls->getName(), cls);
44
}
45
 
46
static void
47
core_hook (_Jv_core_chain *chain)
48
{
49
  chain->next = (_Jv_core_chain *) curHelper->core_chain;
50
  curHelper->core_chain = (gnu::gcj::RawData *) chain;
51
}
52
 
53
struct SharedLibDummy
54
{
55
  ClassHookFunc saved;
56
  CoreHookFunc saved_core;
57
  SharedLibDummy()
58
  {
59
    saved = _Jv_RegisterClassHook;
60
    saved_core = _Jv_RegisterCoreHook;
61
  }
62
  ~SharedLibDummy()
63
  {
64
    _Jv_RegisterClassHook = saved;
65
    _Jv_RegisterCoreHook = saved_core;
66
    curLoader = NULL;
67
  }
68
};
69
#endif
70
 
71
void
72
gnu::gcj::runtime::SharedLibHelper::init(void)
73
{
74
#ifdef HAVE_DLOPEN
75
  char *lname = (char *) __builtin_alloca (JvGetStringUTFLength (baseName)
76
                                           + 1);
77
  jsize total = JvGetStringUTFRegion (baseName, 0, baseName->length(), lname);
78
  lname[total] = '\0';
79
 
80
  if (flags==0)
81
    flags = RTLD_GLOBAL | RTLD_LAZY;
82
  JvSynchronize dummy1(&java::lang::Class::class$);
83
  SharedLibDummy dummy2;
84
  curLoader = loader;
85
  curHelper = this;
86
  _Jv_RegisterClassHook = _Jv_sharedlib_register_hook;
87
  _Jv_RegisterCoreHook = core_hook;
88
  void *h = dlopen(lname, flags);
89
  if (h == NULL)
90
    {
91
      const char *msg = dlerror();
92
      throw new java::lang::UnknownError(JvNewStringLatin1(msg));
93
    }
94
  handler = (gnu::gcj::RawData*) h;
95
#else
96
  const char *msg
97
    = "shared library class loading is not supported on this platform";
98
  throw new java::lang::UnsupportedOperationException(JvNewStringLatin1(msg));
99
#endif
100
}
101
 
102
jboolean
103
gnu::gcj::runtime::SharedLibHelper::hasResource (jstring name)
104
{
105
#ifdef HAVE_DLOPEN
106
  _Jv_core_chain *node = _Jv_FindCore ((_Jv_core_chain *) core_chain, name);
107
  return node != NULL;
108
#else
109
  return false;
110
#endif
111
}
112
 
113
gnu::gcj::Core *
114
gnu::gcj::runtime::SharedLibHelper::findCore (jstring name)
115
{
116
#ifdef HAVE_DLOPEN
117
  extern gnu::gcj::Core *_Jv_create_core (_Jv_core_chain *node, jstring name);
118
  ensureInit();
119
  return _Jv_create_core ((_Jv_core_chain *) core_chain, name);
120
#else
121
  return NULL;
122
#endif
123
}
124
 
125
void
126
gnu::gcj::runtime::SharedLibHelper::finalize()
127
{
128
  _Jv_FreeCoreChain ((_Jv_core_chain *) core_chain);
129
#ifdef HAVE_DLOPEN
130
  if (handler)
131
    dlclose (handler);
132
#endif
133
}
134
 
135
void
136
gnu::gcj::runtime::SharedLibHelper::ensureSupersLinked(jclass k)
137
{
138
  _Jv_Linker::wait_for_state (k, JV_STATE_LOADING);
139
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.