2 * Copyright (c) 1999-2007 Apple 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 DECLARE_VAR(var, type) \
33 static type * var ## _pointer = 0
34 #define DECLARE_PROGNAME(var, type) \
35 static type * var ## _pointer = 0; \
36 static type _priv_ ## var = 0
37 #define USE_VAR(var) (var ## _pointer)
39 #define DECLARE_VAR(var, type) extern type var
40 #define DECLARE_PROGNAME(var, type) DECLARE_VAR(var, type)
41 #define USE_VAR(var) (& var)
44 DECLARE_VAR(NXArgv
, char **);
45 DECLARE_VAR(NXArgc
, int);
46 DECLARE_VAR(environ
, char **);
47 DECLARE_VAR(_mh_execute_header
, struct mach_header
);
48 DECLARE_PROGNAME(__progname
, char *);
50 char ***_NSGetArgv(void) {
51 return(USE_VAR(NXArgv
));
54 int *_NSGetArgc(void) {
55 return(USE_VAR(NXArgc
));
58 char ***_NSGetEnviron(void) {
59 return(USE_VAR(environ
));
62 char **_NSGetProgname(void) {
63 return(USE_VAR(__progname
));
66 struct mach_header
*_NSGetMachExecuteHeader(void) {
67 return(USE_VAR(_mh_execute_header
));
81 #define SUPPORT_PRE_GM_10_5_EXECUTABLES (__ppc__ || __i386__)
85 * dyld calls libSystem_initializer() and passes it a ProgramVars struct containing pointers to the
86 * main executable's NXArg* global variables. libSystem_initializer() calls __libc_init() which calls
87 * _program_vars_init() passing the ProgramVars parameter.
89 void __attribute__((visibility("hidden")))
90 _program_vars_init(const struct ProgramVars
* vars
) {
91 #if SUPPORT_PRE_GM_10_5_EXECUTABLES
92 // to support transitional 10.5 main executables that don't have extended __dyld section and instead call _NSSetProgramVars,
93 // don't overwrite values set by _NSSetProgramVars()
94 if ( NXArgv_pointer
!= NULL
)
97 NXArgv_pointer
= vars
->NXArgvPtr
;
98 NXArgc_pointer
= vars
->NXArgcPtr
;
99 environ_pointer
= vars
->environPtr
;
100 __progname_pointer
= vars
->__prognamePtr
;
101 _mh_execute_header_pointer
= vars
->mh
;
104 #if SUPPORT_PRE_GM_10_5_EXECUTABLES
106 * This is only called by main executables built with pre 10-5 GM crt1.10.5.o. In those programs,
107 * there is no extended __dyld section, dyld cannot tell _program_vars_init() where the real program
108 * variables are, so they get temp values and are set for real here.
110 void _NSSetProgramVars(int* crt_argc
, char*** crt_argv
, char*** crt_environ
, struct mach_header
* crt_mh
, char** crt_progname
) {
111 NXArgv_pointer
= crt_argv
;
112 NXArgc_pointer
= crt_argc
;
113 environ_pointer
= crt_environ
;
114 __progname_pointer
= crt_progname
;
115 _mh_execute_header_pointer
= crt_mh
;
118 #endif /* __DYNAMIC__ */
122 * Fix for Radar bug 2200596 --
123 * EH symbol definitions for gcc 2.7.2.x implementation of
124 * C++ exception handling. The problem: the EH implementation
125 * has "throw" store stuff into these pointers, and then as the
126 * stack is unwound, the code generated into each function (for
127 * checking whether this function contains a relevant "catch"
128 * clause and for calling destructors for local variables) looks
129 * at these globals to find the type and value thrown.
131 * The problem was that the compiler generated the symbols as
132 * "common" symbols, and common symbols cannot be placed in
133 * dynamic shared libraries. So we must put these guys as
134 * "data" symbols into crt0.o or the System Framework (library),
135 * and the compiler must generate code that defines the symbols
136 * as external references instead of common.
138 * I changed the symbol names (added the "_272") to be utterly
139 * paranoid about any possible future use of similar names by
140 * any future versions of gcc.
141 * -- D. Landauer, Jan. 1998
144 void *__eh_pc_gcc_272
= (void *)0;
145 void *__eh_type_gcc_272
= (void *)0;
146 void *__eh_value_gcc_272
= (void *)0;
148 /* This is what egcs uses for its global data pointer */
149 void *__eh_global_dataptr
= (void *)0;