summaryrefslogtreecommitdiff
blob: 8ae522b7d4eb00698402fecea787096dab4b178c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
Stub out some functions that are not provided (and unneeded)

--- lib/malloc.c
+++ lib/malloc.c
@@ -64,6 +64,15 @@ void *malloc (unsigned int size)
     return caddr;
 }
 
+/* Calloc wrapper for malloc */
+void *memset(void *s, int c, size_t n);
+void *calloc(size_t nmemb, size_t size) {
+	void *caddr;
+	caddr = malloc(nmemb * size);
+	memset(caddr, 0, nmemb * size);
+	return caddr;
+}
+
 /* Do not fall back to the malloc above as posix_memalign is needed by
  * external libraries not yaboot */
 int posix_memalign(void **memptr, size_t alignment, size_t size)
--- lib/nonstd.c
+++ lib/nonstd.c
@@ -65,3 +65,208 @@
 {
 	return NULL;
 }
+
+int lseek(int fd, int offset, int whence) {
+	// XXX: This whence addition seems wrong ..
+	return prom_lseek((void *)fd, whence + offset);
+}
+
+int lseek64(int fd, int64_t offset, int whence) {
+	return lseek(fd, offset, whence);
+}
+
+int open(const char *pathname, int flags) {
+	return (int) prom_open((char *)pathname);
+}
+
+int open64(const char *pathname, int flags) {
+	return open(pathname, flags);
+}
+
+// Internal glibc fortify calls.
+int __open64_2(const char *path, int flags) {
+	return open64(path, flags);
+}
+
+int read(int fd, void *buf, size_t count) {
+	return prom_read((void *)fd, buf, count);
+}
+
+int write(int fd, const void *buf, size_t count) {
+	return prom_write((void *)fd, (void *)buf, count);
+}
+
+int close(int fd) {
+	prom_close((void *)fd);
+	return 0;
+}
+
+int pread(int fd, void *buf, size_t count, int32_t offset) {
+	int curr = lseek(fd, 0, 0 /*SEEK_CUR*/);
+	lseek(fd, offset, 0 /*SEEK_SET*/);
+	int ret = read(fd, buf, count);
+	lseek(fd, curr, 0 /*SEEK_SET*/);
+	return ret;
+}
+
+int pread64(int fd, void *buf, int64_t count, int64_t offset) {
+	return pread(fd, buf, count, offset);
+}
+
+int pwrite(int fd, const void *buf, size_t count, int32_t offset) {
+	int curr = lseek(fd, 0, 0 /*SEEK_CUR*/);
+	lseek(fd, offset, 0 /*SEEK_SET*/);
+	int ret = write(fd, buf, count);
+	lseek(fd, curr, 0 /*SEEK_SET*/);
+	return ret;
+}
+
+int pwrite64(int fd, const void *buf, int64_t count, int64_t offset) {
+	return pwrite(fd, buf, count, offset);
+}
+
+// No fsync, just assume we've sync'd
+int fsync(int fd) {
+	return 0;
+}
+
+// ext2 libs only use this to turn off caches currently
+int fcntl(int fd, int cmd, ...) {
+	return 0;
+}
+
+void exit(int status) {
+	prom_exit();
+}
+
+int __printf_chk(int flag, const char *format, ...) {
+	va_list ap;
+	va_start (ap, format);
+	prom_vfprintf (prom_stdout, format, ap);
+	va_end (ap);
+
+	return 0;
+}
+
+int __sprintf_chk(char * str, int flag, size_t strlen, const char * format, ...) {
+	va_list ap;
+	va_start(ap, format);
+	// No sprintf? :(
+	va_end(ap);
+	return 0;
+
+}
+
+int __fprintf_chk(FILE *stream, int flag, const char *format, ...) {
+	va_list ap;
+	va_start (ap, format);
+	prom_vfprintf (prom_stdout, format, ap);
+	va_end (ap);
+
+	return 0;
+}
+
+void *memcpy(void *dest, const void *src, size_t n);
+void *__memcpy_chk(void *dest, const void *src, size_t n, size_t destlen) {
+	return memcpy(dest, src, n);
+}
+
+// But these are all dummy functions
+int __xstat64 (int __ver, const char *__filename, void *__stat_buf) {
+	return 0;
+}
+
+int stat64(const char *path, void *stat_buf) {
+	return 0;
+}
+
+int fstat64(int fildes, void *stat_buf) {
+	return 0;
+}
+
+int __fxstat64 (int __ver, int __filedesc, void *__stat_buf) {
+	return 0;
+}
+
+signed int random(void) {
+	return 0;
+}
+
+void srandom(unsigned int seed) {
+	return;
+}
+
+int rand(void) {
+	return 0;
+}
+
+void srand(unsigned int seed) {
+	return;
+}
+
+unsigned int sleep(unsigned int seconds) {
+	return 0;
+}
+
+int gettimeofday(void *tv, void *tz) {
+	return 0;
+}
+
+long sysconf(int name) {
+	return 0;
+}
+
+int getpagesize(void) {
+	return 0;
+}
+
+int gethostname(char *name, size_t len) {
+	return 0;
+}
+
+int getpid(void) {
+	return 0;
+}
+
+int getuid(void) {
+	return 0;
+}
+
+void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) {
+	return;
+}
+
+int * __errno_location(void) {
+	return 0;
+}
+
+size_t fwrite(const void *ptr, size_t size, size_t nmemb, void *stream) {
+	return 0;
+}
+
+int ioctl(int d, int request, ...) {
+	return 0;
+}
+
+int fallocate(int fd, int mode, unsigned int offset, unsigned int len) {
+	return 0;
+}
+
+int uname(void *buf) {
+	return 0;
+}
+
+int setrlimit(int resource, void *rlim) {
+	return 0;
+}
+
+unsigned long long int strtoull(const char *nptr, char **endptr, int base) {
+	return 0;
+}
+
+int getrlimit(int resource, void *rlim) {
+	return 0;
+}
+
+int stderr = 0;
+int perror = 0;