]> git.saurik.com Git - apple/dyld.git/blob - src/glue.c
dyld-43.tar.gz
[apple/dyld.git] / src / glue.c
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25 #include <stddef.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <notify.h>
30 #include <time.h>
31
32 //
33 // Stub functions needed for dyld to link with libc.a instead of libSystem.dylib
34 //
35 //
36 static char* dyld_progname = "dyld";
37
38 //
39 // libc has calls to _dyld_lookup_and_bind to find args and environment. Since
40 // dyld links with a staic copy of libc, those calls need to find dyld's args and env
41 // not the host process. We implement a special _dyld_lookup_and_bind() that
42 // just knows how to bind the few symbols needed by dyld.
43 //
44 void _dyld_lookup_and_bind(const char* symbolName, void** address, void* module)
45 {
46 if ( strcmp(symbolName, "_environ") == 0 ) {
47 // dummy up empty environment list
48 static char *p = NULL;
49 static char **pp = &p;
50 *address = &pp;
51 return;
52 }
53 else if ( strcmp(symbolName, "___progname") == 0 ) {
54 *address = &dyld_progname;
55 return;
56 }
57
58 fprintf(stderr, "dyld: internal error: unknown symbol '%s'\n", symbolName);
59 }
60
61
62 int NSIsSymbolNameDefined(const char* symbolName)
63 {
64 if ( strcmp(symbolName, "___progname") == 0 ) {
65 return 1;
66 }
67 fprintf(stderr, "dyld: internal error: unknown symbol '%s'\n", symbolName);
68 return 0;
69 }
70
71
72 /*
73 * To avoid linking in libm. These variables are defined as they are used in
74 * pthread_init() to put in place a fast sqrt().
75 */
76 size_t hw_sqrt_len = 0;
77
78 double
79 sqrt(double x)
80 {
81 return(0.0);
82 }
83 double
84 hw_sqrt(double x)
85 {
86 return(0.0);
87 }
88
89 /*
90 * More stubs to avoid linking in libm. This works as along as we don't use
91 * long doubles.
92 */
93 long
94 __fpclassifyd(double x)
95 {
96 return(0);
97 }
98
99 long
100 __fpclassify(long double x)
101 {
102 return(0);
103 }
104
105
106 char* __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve)
107 {
108 return NULL;
109 }
110
111 char* __hldtoa(/*long*/ double e, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve)
112 {
113 return NULL;
114 }
115
116 int __fegetfltrounds(void)
117 {
118 return 1; /* FE_NEAREST */
119 }
120
121 /*
122 * We have our own localtime() to avoid needing the notify API which is used
123 * by the code in libc.a for localtime() but is in libnotify.
124 */
125 struct tm* localtime(const time_t* t)
126 {
127 return (struct tm*)NULL;
128 }
129