]> git.saurik.com Git - apple/libc.git/blame - sys/crt_externs.c
Libc-391.5.21.tar.gz
[apple/libc.git] / sys / crt_externs.c
CommitLineData
e9ce8d39
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
734aad71
A
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
11 * file.
12 *
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
e9ce8d39
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
734aad71
A
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.
e9ce8d39
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24** This file contains interfaces to the symbols defined int the crt modules.
25** 3 April 1995
26** Matt Watson (mwatson@next.com)
27**
28*/
29
30#if defined(__DYNAMIC__)
31#include "mach-o/dyld.h" /* defines _dyld_lookup_and_bind() */
32#define STRINGIFY(a) # a
9385eb3d 33#define DECLARE_VAR(var, type) \
e9ce8d39 34 static type * var ## _pointer = 0
9385eb3d
A
35#define DECLARE_PROGNAME(var, type) \
36 static type * var ## _pointer = 0; \
37 static type _priv_ ## var = 0
e9ce8d39
A
38#define SETUP_VAR(var) \
39 if ( var ## _pointer == 0) { \
40 _dyld_lookup_and_bind( STRINGIFY(_ ## var), \
41 (unsigned long *) & var ## _pointer, 0); \
42 }
9385eb3d
A
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); \
48 else { \
49 char *progname = _dyld_get_image_name(0); \
50 if(_priv_ ## var = strrchr(progname, '/')) \
51 _priv_ ## var ++; \
52 else \
53 _priv_ ## var = progname; \
54 var ## _pointer = & _priv_ ## var; \
55 } \
56 }
e9ce8d39
A
57#define USE_VAR(var) (var ## _pointer)
58#else
59#define DECLARE_VAR(var, type) extern type var
9385eb3d 60#define DECLARE_PROGNAME(var, type) DECLARE_VAR(var, type)
e9ce8d39 61#define SETUP_VAR(var)
9385eb3d 62#define SETUP_PROGNAME(var) SETUP_VAR(var)
e9ce8d39
A
63#define USE_VAR(var) (& var)
64#endif
65
66char ***_NSGetArgv(void) {
67 DECLARE_VAR(NXArgv, char **);
68 SETUP_VAR(NXArgv);
69 return(USE_VAR(NXArgv));
70}
71
72int *_NSGetArgc(void) {
73 DECLARE_VAR(NXArgc, int);
74 SETUP_VAR(NXArgc);
75 return(USE_VAR(NXArgc));
76}
77
78char ***_NSGetEnviron(void) {
79 DECLARE_VAR(environ, char **);
80 SETUP_VAR(environ);
81 return(USE_VAR(environ));
82}
83
5b2abdfb 84char **_NSGetProgname(void) {
9385eb3d
A
85 DECLARE_PROGNAME(__progname, char *);
86 SETUP_PROGNAME(__progname);
5b2abdfb
A
87 return(USE_VAR(__progname));
88}
89
e9ce8d39
A
90struct 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));
94}
95
96/*
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.
105 *
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.
112 *
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
117 */
118
119void *__eh_pc_gcc_272 = (void *)0;
120void *__eh_type_gcc_272 = (void *)0;
121void *__eh_value_gcc_272 = (void *)0;
122
123/* This is what egcs uses for its global data pointer */
124void *__eh_global_dataptr = (void *)0;