]> gcc.gnu.org Git - gcc.git/blame - libjava/darwin.cc
* gcc.c: Remove ancient comment about a bug in Sun cc.
[gcc.git] / libjava / darwin.cc
CommitLineData
f1a66265
GK
1/* darwin.cc - class loader stuff for Darwin. */
2
417e7bed 3/* Copyright (C) 2004, 2007 Free Software Foundation
f1a66265
GK
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
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>
417e7bed
AT
24#if !defined (__LP64__)
25 struct mach_header;
26# define JAVA_MACH_HEADER mach_header
27# define mh_size_t uint32_t
28 extern "C" void _dyld_register_func_for_add_image
29 (void (*func)(const struct mach_header *mh, intptr_t vmaddr_slide));
30 extern "C" void _dyld_register_func_for_remove_image
31 (void (*func)(const struct mach_header *mh, intptr_t vmaddr_slide));
32 extern "C" char *getsectdatafromheader
33 (const struct mach_header *mhp, const char *segname, const char *sectname,
34 uint32_t *size);
35# define GETSECTDATA getsectdatafromheader
36#else
37 struct mach_header_64;
38# define JAVA_MACH_HEADER mach_header_64
39# define mh_size_t uint64_t
40 extern "C" void _dyld_register_func_for_add_image
41 (void (*func)(const struct mach_header_64 *mh, intptr_t vmaddr_slide));
42 extern "C" void _dyld_register_func_for_remove_image
43 (void (*func)(const struct mach_header_64 *mh, intptr_t vmaddr_slide));
44 extern "C" char *getsectdatafromheader_64
45 (const struct mach_header_64 *mhp, const char *segname,
46 const char *sectname, uint64_t *size);
47# define GETSECTDATA getsectdatafromheader_64
48#endif
f1a66265
GK
49
50/* When a new image is loaded, look to see if it has a jcr section
51 and if so register the classes listed in it. */
52
53static void
417e7bed 54darwin_java_register_dyld_add_image_hook (const struct JAVA_MACH_HEADER *mh,
f1a66265
GK
55 intptr_t slide)
56{
57 char *fde;
417e7bed 58 mh_size_t sz;
f1a66265 59
417e7bed 60 fde = GETSECTDATA (mh, "__DATA", "jcr", &sz);
f1a66265
GK
61 if (! fde)
62 return;
63
64 /* As far as I can tell, you're only supposed to load shared
65 libraries while having a lock on java.lang.Class. So there's
66 no need to synchronize on anything here. (I'm not sure how exactly
67 you can ensure this given lazy library loading. FIXME.) */
68
69 _Jv_RegisterClasses_Counted ((const jclass *) (fde + slide),
70 sz / sizeof (jclass *));
71}
72
73static struct darwin_constructor_s{
74 darwin_constructor_s()
75 {
76 _dyld_register_func_for_add_image
77 (darwin_java_register_dyld_add_image_hook);
78 /* At present, you mustn't unload any java plugin. */
79 };
80} darwin_constructor;
This page took 0.330368 seconds and 5 git commands to generate.