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