OSDN Git Service

* gcse.c (gcse_main): Do jump bypassing in CPROP2.
[pf3gnuchains/gcc-fork.git] / libjava / darwin.cc
1 /* darwin.cc - class loader stuff for Darwin.  */
2
3 /* Copyright (C) 2004  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 #include <jvm.h>
14
15 /* In theory, we should be able to do:
16    #include <mach-o/getsect.h>
17    #include <mach-o/dyld.h>
18
19    but all the types in these headers changed between Panther and Tiger,
20    so the only way to be avoid type mismatches is to declare the routines
21    ourself.  */
22
23 #include <stdint.h>
24 struct mach_header;
25 extern "C" void _dyld_register_func_for_add_image
26   (void (*func)(const struct mach_header *mh, intptr_t vmaddr_slide));
27 extern "C" void _dyld_register_func_for_remove_image
28   (void (*func)(const struct mach_header *mh, intptr_t vmaddr_slide));
29 extern "C" char *getsectdatafromheader
30 (const struct mach_header *mhp, const char *segname, const char *sectname,
31  uint32_t *size);
32
33 /* When a new image is loaded, look to see if it has a jcr section
34    and if so register the classes listed in it.  */
35
36 static void
37 darwin_java_register_dyld_add_image_hook (const struct mach_header *mh,
38                                           intptr_t slide)
39 {
40   char *fde;
41   uint32_t sz;
42
43   fde = getsectdatafromheader (mh, "__DATA", "jcr", &sz);
44   if (! fde)
45     return;
46   
47   /* As far as I can tell, you're only supposed to load shared
48      libraries while having a lock on java.lang.Class.  So there's
49      no need to synchronize on anything here.  (I'm not sure how exactly
50      you can ensure this given lazy library loading.  FIXME.)  */
51  
52   _Jv_RegisterClasses_Counted ((const jclass *) (fde + slide),
53                                sz / sizeof (jclass *));
54 }
55
56 static struct darwin_constructor_s{
57   darwin_constructor_s() 
58   {
59     _dyld_register_func_for_add_image 
60       (darwin_java_register_dyld_add_image_hook);
61     /* At present, you mustn't unload any java plugin.  */
62   };
63 } darwin_constructor;