]>
Commit | Line | Data |
---|---|---|
e9ce8d39 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
734aad71 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
e9ce8d39 | 7 | * |
734aad71 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
e9ce8d39 A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
734aad71 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
e9ce8d39 A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | ** This file contains interfaces to the symbols defined int the crt modules. | |
27 | ** 3 April 1995 | |
28 | ** Matt Watson (mwatson@next.com) | |
29 | ** | |
30 | */ | |
31 | ||
32 | #if defined(__DYNAMIC__) | |
33 | #include "mach-o/dyld.h" /* defines _dyld_lookup_and_bind() */ | |
34 | #define STRINGIFY(a) # a | |
9385eb3d | 35 | #define DECLARE_VAR(var, type) \ |
e9ce8d39 | 36 | static type * var ## _pointer = 0 |
9385eb3d A |
37 | #define DECLARE_PROGNAME(var, type) \ |
38 | static type * var ## _pointer = 0; \ | |
39 | static type _priv_ ## var = 0 | |
e9ce8d39 A |
40 | #define SETUP_VAR(var) \ |
41 | if ( var ## _pointer == 0) { \ | |
42 | _dyld_lookup_and_bind( STRINGIFY(_ ## var), \ | |
43 | (unsigned long *) & var ## _pointer, 0); \ | |
44 | } | |
9385eb3d A |
45 | #define SETUP_PROGNAME(var) \ |
46 | if ( var ## _pointer == 0) { \ | |
47 | if(NSIsSymbolNameDefined( STRINGIFY(_ ## var) )) \ | |
48 | _dyld_lookup_and_bind( STRINGIFY(_ ## var), \ | |
49 | (unsigned long *) & var ## _pointer, 0); \ | |
50 | else { \ | |
51 | char *progname = _dyld_get_image_name(0); \ | |
52 | if(_priv_ ## var = strrchr(progname, '/')) \ | |
53 | _priv_ ## var ++; \ | |
54 | else \ | |
55 | _priv_ ## var = progname; \ | |
56 | var ## _pointer = & _priv_ ## var; \ | |
57 | } \ | |
58 | } | |
e9ce8d39 A |
59 | #define USE_VAR(var) (var ## _pointer) |
60 | #else | |
61 | #define DECLARE_VAR(var, type) extern type var | |
9385eb3d | 62 | #define DECLARE_PROGNAME(var, type) DECLARE_VAR(var, type) |
e9ce8d39 | 63 | #define SETUP_VAR(var) |
9385eb3d | 64 | #define SETUP_PROGNAME(var) SETUP_VAR(var) |
e9ce8d39 A |
65 | #define USE_VAR(var) (& var) |
66 | #endif | |
67 | ||
68 | char ***_NSGetArgv(void) { | |
69 | DECLARE_VAR(NXArgv, char **); | |
70 | SETUP_VAR(NXArgv); | |
71 | return(USE_VAR(NXArgv)); | |
72 | } | |
73 | ||
74 | int *_NSGetArgc(void) { | |
75 | DECLARE_VAR(NXArgc, int); | |
76 | SETUP_VAR(NXArgc); | |
77 | return(USE_VAR(NXArgc)); | |
78 | } | |
79 | ||
80 | char ***_NSGetEnviron(void) { | |
81 | DECLARE_VAR(environ, char **); | |
82 | SETUP_VAR(environ); | |
83 | return(USE_VAR(environ)); | |
84 | } | |
85 | ||
5b2abdfb | 86 | char **_NSGetProgname(void) { |
9385eb3d A |
87 | DECLARE_PROGNAME(__progname, char *); |
88 | SETUP_PROGNAME(__progname); | |
5b2abdfb A |
89 | return(USE_VAR(__progname)); |
90 | } | |
91 | ||
e9ce8d39 A |
92 | struct mach_header *_NSGetMachExecuteHeader(void) { |
93 | DECLARE_VAR(_mh_execute_header, struct mach_header); | |
94 | SETUP_VAR(_mh_execute_header); | |
95 | return(USE_VAR(_mh_execute_header)); | |
96 | } | |
97 | ||
98 | /* | |
99 | * Fix for Radar bug 2200596 -- | |
100 | * EH symbol definitions for gcc 2.7.2.x implementation of | |
101 | * C++ exception handling. The problem: the EH implementation | |
102 | * has "throw" store stuff into these pointers, and then as the | |
103 | * stack is unwound, the code generated into each function (for | |
104 | * checking whether this function contains a relevant "catch" | |
105 | * clause and for calling destructors for local variables) looks | |
106 | * at these globals to find the type and value thrown. | |
107 | * | |
108 | * The problem was that the compiler generated the symbols as | |
109 | * "common" symbols, and common symbols cannot be placed in | |
110 | * dynamic shared libraries. So we must put these guys as | |
111 | * "data" symbols into crt0.o or the System Framework (library), | |
112 | * and the compiler must generate code that defines the symbols | |
113 | * as external references instead of common. | |
114 | * | |
115 | * I changed the symbol names (added the "_272") to be utterly | |
116 | * paranoid about any possible future use of similar names by | |
117 | * any future versions of gcc. | |
118 | * -- D. Landauer, Jan. 1998 | |
119 | */ | |
120 | ||
121 | void *__eh_pc_gcc_272 = (void *)0; | |
122 | void *__eh_type_gcc_272 = (void *)0; | |
123 | void *__eh_value_gcc_272 = (void *)0; | |
124 | ||
125 | /* This is what egcs uses for its global data pointer */ | |
126 | void *__eh_global_dataptr = (void *)0; |