1 // natCore -- C++ side of Core
3 /* Copyright (C) 2001, 2002, 2003, 2005, 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 /* Author: Anthony Green <green@redhat.com>. */
20 #include <java/lang/NullPointerException.h>
21 #include <java/io/IOException.h>
22 #include <gnu/gcj/Core.h>
24 // List of global core values.
25 static _Jv_core_chain
*root
;
28 default_register_resource (_Jv_core_chain
*node
)
34 // This is set only when a lock is held on java.lang.Class.
35 // This function is called to handle a new core node.
36 void (*_Jv_RegisterCoreHook
) (_Jv_core_chain
*) = default_register_resource
;
39 _Jv_RegisterResource (void *vptr
)
41 char *rptr
= (char *) vptr
;
43 _Jv_core_chain
*cc
= (_Jv_core_chain
*) _Jv_Malloc (sizeof (_Jv_core_chain
));
45 cc
->name_length
= ((int *)rptr
)[0];
46 cc
->data_length
= ((int *)rptr
)[1];
47 cc
->name
= rptr
+ 2 * sizeof (int);
48 cc
->data
= cc
->name
+ cc
->name_length
;
51 (*_Jv_RegisterCoreHook
) (cc
);
55 _Jv_FreeCoreChain (_Jv_core_chain
*chain
)
59 _Jv_core_chain
*next
= chain
->next
;
66 _Jv_FindCore (_Jv_core_chain
*node
, jstring name
)
68 char *buf
= (char *) __builtin_alloca (JvGetStringUTFLength (name
) + 1);
69 jsize total
= JvGetStringUTFRegion (name
, 0, name
->length(), buf
);
72 // Usually requests here end up as an absolute URL. We strip the
82 if (total
== node
->name_length
83 && strncmp (buf
, node
->name
, total
) == 0)
92 _Jv_create_core (_Jv_core_chain
*node
, jstring name
)
94 node
= _Jv_FindCore (node
, name
);
96 gnu::gcj::Core
*core
= NULL
;
99 core
= new gnu::gcj::Core ();
100 core
->ptr
= (gnu::gcj::RawData
*) node
->data
;
101 core
->length
= node
->data_length
;
107 gnu::gcj::Core::find (jstring name
)
109 gnu::gcj::Core
*core
= _Jv_create_core (root
, name
);
114 gnu::gcj::Core::create (jstring name
)
116 gnu::gcj::Core
*core
= _Jv_create_core (root
, name
);
118 throw new ::java::io::IOException (JvNewStringLatin1 ("can't open core"));