]> git.saurik.com Git - apple/libc.git/blob - sys/crt_externs.c
Libc-262.2.12.tar.gz
[apple/libc.git] / sys / crt_externs.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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
35 #define DECLARE_VAR(var, type) \
36 static type * var ## _pointer = 0
37 #define SETUP_VAR(var) \
38 if ( var ## _pointer == 0) { \
39 _dyld_lookup_and_bind( STRINGIFY(_ ## var), \
40 (unsigned long *) & var ## _pointer, 0); \
41 }
42 #define USE_VAR(var) (var ## _pointer)
43 #else
44 #define DECLARE_VAR(var, type) extern type var
45 #define SETUP_VAR(var)
46 #define USE_VAR(var) (& var)
47 #endif
48
49 char ***_NSGetArgv(void) {
50 DECLARE_VAR(NXArgv, char **);
51 SETUP_VAR(NXArgv);
52 return(USE_VAR(NXArgv));
53 }
54
55 int *_NSGetArgc(void) {
56 DECLARE_VAR(NXArgc, int);
57 SETUP_VAR(NXArgc);
58 return(USE_VAR(NXArgc));
59 }
60
61 char ***_NSGetEnviron(void) {
62 DECLARE_VAR(environ, char **);
63 SETUP_VAR(environ);
64 return(USE_VAR(environ));
65 }
66
67 char **_NSGetProgname(void) {
68 DECLARE_VAR(__progname, char *);
69 SETUP_VAR(__progname);
70 return(USE_VAR(__progname));
71 }
72
73 struct mach_header *_NSGetMachExecuteHeader(void) {
74 DECLARE_VAR(_mh_execute_header, struct mach_header);
75 SETUP_VAR(_mh_execute_header);
76 return(USE_VAR(_mh_execute_header));
77 }
78
79 /*
80 * Fix for Radar bug 2200596 --
81 * EH symbol definitions for gcc 2.7.2.x implementation of
82 * C++ exception handling. The problem: the EH implementation
83 * has "throw" store stuff into these pointers, and then as the
84 * stack is unwound, the code generated into each function (for
85 * checking whether this function contains a relevant "catch"
86 * clause and for calling destructors for local variables) looks
87 * at these globals to find the type and value thrown.
88 *
89 * The problem was that the compiler generated the symbols as
90 * "common" symbols, and common symbols cannot be placed in
91 * dynamic shared libraries. So we must put these guys as
92 * "data" symbols into crt0.o or the System Framework (library),
93 * and the compiler must generate code that defines the symbols
94 * as external references instead of common.
95 *
96 * I changed the symbol names (added the "_272") to be utterly
97 * paranoid about any possible future use of similar names by
98 * any future versions of gcc.
99 * -- D. Landauer, Jan. 1998
100 */
101
102 void *__eh_pc_gcc_272 = (void *)0;
103 void *__eh_type_gcc_272 = (void *)0;
104 void *__eh_value_gcc_272 = (void *)0;
105
106 /* This is what egcs uses for its global data pointer */
107 void *__eh_global_dataptr = (void *)0;
108
109 void *__keymgr_global[3] = { (void *)0 };