Newer
Older
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <exception>
#include <libintl.h>
#include <cxxabi.h>
#include <sys/mman.h>
#include <unistd.h>
#include <libunwind.h>
#include <link.h>
#include <stdio.h>
#include <sys/poll.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/uio.h>
#include <wchar.h>
#include <locale.h>
#include <libintl.h>
#include <ctype.h>
#include <wctype.h>
#include <langinfo.h>
#include <stdarg.h>
extern "C" {
void __cxa_pure_virtual(void);
void abort(void);
void _Unwind_Resume(void);
void *malloc(size_t size);
void free(void *);
int tdep_get_elf_image(struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen);
int _Uelf64_get_proc_name(unw_addr_space_t as, int pid, unw_word_t ip,
char *buf, size_t buf_len, unw_word_t *offp);
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
int __fxstat(int ver, int fd, struct stat *buf);
int __fxstat64(int ver, int fd, struct stat64 *buf);
void __stack_chk_fail(void);
void __assert_fail(const char * assertion, const char * file, unsigned int line, const char * function);
void __freelocale(__locale_t __dataset) __THROW;
__locale_t __duplocale(__locale_t __dataset) __THROW;
__locale_t __newlocale(int __category_mask, __const char *__locale,
__locale_t __base) __THROW;
__locale_t __uselocale(__locale_t __dataset) __THROW;
char *__setlocale(int category, const char *locale);
char *setlocale(int category, const char *locale) __alias("__setlocale");
double __strtod_l(__const char *__restrict __nptr,
char **__restrict __endptr, __locale_t __loc)
__THROW __nonnull ((1, 3));
int __iswctype_l(wint_t __wc, wctype_t __desc, __locale_t __locale)
__THROW;
wctype_t __wctype_l(__const char *__property, __locale_t __locale)
__THROW;
float __strtof_l(__const char *__restrict __nptr,
char **__restrict __endptr, __locale_t __loc)
__THROW __nonnull((1, 3)) __wur;
char *__nl_langinfo_l(nl_item __item, __locale_t __l);
wint_t __towlower_l(wint_t __wc, __locale_t __locale) __THROW;
wint_t __towupper_l(wint_t __wc, __locale_t __locale) __THROW;
int __wcscoll_l(__const wchar_t *__s1, __const wchar_t *__s2,
__locale_t __loc) __THROW;
int __strcoll_l(__const char *__s1, __const char *__s2, __locale_t __l)
__THROW __attribute_pure__ __nonnull((1, 2, 3));
size_t __wcsftime_l(wchar_t *__restrict __s, size_t __maxsize,
__const wchar_t *__restrict __format,
__const struct tm *__restrict __tp,
__locale_t __loc) __THROW;
size_t __strftime_l(char *__restrict __s, size_t __maxsize,
__const char *__restrict __format,
__const struct tm *__restrict __tp,
__locale_t __loc) __THROW;
size_t __strxfrm_l(char *__dest, __const char *__src, size_t __n,
__locale_t __l) __THROW __nonnull ((2, 4));
size_t __wcsxfrm_l(wchar_t *__s1, __const wchar_t *__s2,
size_t __n, __locale_t __loc) __THROW;
void *__dso_handle;
void ignore_debug_write(const char *msg)
void (*debug_write)(const char *msg) = ignore_debug_write;
#define UNIMPLEMENTED(msg) do { \
static bool _x; \
if (!_x) { \
_x = true; \
debug_write("WARNING: unimplemented " msg); \
} \
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
static char malloc_buffer[1 << 24], *malloc_ptr = malloc_buffer;
void *malloc(size_t size)
{
size = (size + 7) & ~(size_t)7;
void* ret = malloc_ptr;
malloc_ptr += size;
return ret;
}
void free(void* ptr)
{
}
void *memcpy(void *dest, const void *src, size_t n)
{
char* p = reinterpret_cast<char*>(dest);
const char* q = reinterpret_cast<const char*>(src);
while (n--) {
*p++ = *q++;
}
return dest;
}
void *memmove(void *dest, const void *src, size_t n)
{
char* p = reinterpret_cast<char*>(dest);
const char* q = reinterpret_cast<const char*>(src);
if (p < q) {
while (n--) {
*p++ = *q++;
}
} else {
p += n;
q += n;
while (n--) {
*--p = *--q;
}
}
return dest;
}
void *memset(void *s, int c, size_t n)
{
char* p = reinterpret_cast<char*>(s);
while (n--) {
*p++ = c;
}
return s;
}
int memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char* p1 = reinterpret_cast<const unsigned char*>(s1);
const unsigned char* p2 = reinterpret_cast<const unsigned char*>(s2);
while (n) {
if (*p1 != *p2) {
return int(*p1) - int(*p2);
}
++p1;
++p2;
--n;
}
return 0;
}
const void* memchr(const void *s, int c, size_t n)
{
const unsigned char* p = reinterpret_cast<const unsigned char*>(s);
while (n--) {
if (*p == c) {
return p;
}
++p;
}
return NULL;
}
size_t strlen(const char *s)
{
size_t ret = 0;
while (*s++) {
++ret;
}
return ret;
}
char* strncpy(char* dest, const char* src, size_t n)
{
char* p = dest;
while (n--) {
*p = *src;
if (!*src) {
break;
}
++p;
++src;
}
return dest;
}
char* gettext (const char* msgid)
{
return const_cast<char*>(msgid);
}
char* strerror(int err)
{
return const_cast<char*>("strerror");
}
namespace __cxxabiv1 {
std::terminate_handler __terminate_handler = abort;
int __cxa_guard_acquire(__guard*)
{
return 0;
}
void __cxa_guard_release(__guard*) _GLIBCXX_NOTHROW
{
}
void __cxa_guard_abort(__guard*) _GLIBCXX_NOTHROW
{
abort();
}
int __cxa_atexit(void (*destructor)(void *), void *arg, void *dso)
{
return 0;
}
int __cxa_finalize(void *f)
{
return 0;
}
}
void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset)
{
if (fd != -1) {
abort();
}
return malloc(length);
}
int munmap(void *addr, size_t length)
{
return 0;
}
int getpagesize()
{
return 4096;
}
int
tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
unsigned long *segbase, unsigned long *mapoff,
char *path, size_t pathlen)
{
return 0;
}
int getpid()
{
return 0;
}
int mincore(void *addr, size_t length, unsigned char *vec)
{
memset(vec, 0x01, (length + getpagesize() - 1) / getpagesize());
return 0;
}
int dl_iterate_phdr(int (*callback)(struct dl_phdr_info *info,
size_t size, void *data),
void *data)
{
return 0;
}
int _Uelf64_get_proc_name(unw_addr_space_t as, int pid, unw_word_t ip,
char *buf, size_t buf_len, unw_word_t *offp)
{
return 0;
}
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
FILE* stdin;
FILE* stdout;
FILE* stderr;
const wchar_t* wmemchr(const wchar_t *s, wchar_t c, size_t n)
{
UNIMPLEMENTED("wmemchr");
}
int ioctl(int fd, unsigned long request, ...)
{
UNIMPLEMENTED("ioctl");
}
off64_t lseek64(int fd, off64_t offset, int whence)
{
UNIMPLEMENTED("lseek64");
}
int poll(struct pollfd *fds, nfds_t nfds, int timeout)
{
UNIMPLEMENTED("poll");
}
int __fxstat(int ver, int fd, struct stat *buf)
{
UNIMPLEMENTED("__fxstat");
}
int __fxstat64(int ver, int fd, struct stat64 *buf)
{
UNIMPLEMENTED("__fxstat");
}
int *__errno_location()
{
UNIMPLEMENTED("__errno_location");
}
ssize_t readv(int fd, const struct iovec *iov, int iovcnt)
{
UNIMPLEMENTED("readv");
}
ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
{
UNIMPLEMENTED("writev");
}
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
{
UNIMPLEMENTED("preadv");
}
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
{
UNIMPLEMENTED("pwritev");
}
ssize_t read(int fd, void *buf, size_t count)
{
UNIMPLEMENTED("read");
}
int fclose(FILE *fp)
{
UNIMPLEMENTED("fclose");
}
int fileno(FILE *fp)
{
UNIMPLEMENTED("fileno");
}
FILE *fdopen(int fd, const char *mode)
{
UNIMPLEMENTED("fdopen");
}
int fflush(FILE *fp)
{
UNIMPLEMENTED("fflush");
}
ssize_t write(int fd, const void *buf, size_t count)
{
UNIMPLEMENTED("write");
}
int fgetc(FILE *stream)
{
UNIMPLEMENTED("fgetc");
}
char *fgets(char *s, int size, FILE *stream)
{
UNIMPLEMENTED("fgets");
}
#undef getc
int getc(FILE *stream)
{
UNIMPLEMENTED("getc");
}
int getchar(void)
{
UNIMPLEMENTED("getchar");
}
char *gets(char *s)
{
UNIMPLEMENTED("gets");
}
int ungetc(int c, FILE *stream)
{
UNIMPLEMENTED("ungetc");
}
UNIMPL(int fputc(int c, FILE *stream))
UNIMPL(int fputs(const char *s, FILE *stream))
#undef putc
UNIMPL(int putc(int c, FILE *stream))
UNIMPL(int putchar(int c))
UNIMPL(int puts(const char *s))
UNIMPL(size_t wcslen(const wchar_t *s))
UNIMPL(int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n))
UNIMPL(wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t n))
UNIMPL(int setvbuf(FILE *stream, char *buf, int mode, size_t size))
UNIMPL(size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream))
UNIMPL(size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream))
UNIMPL(wint_t fgetwc(FILE *stream))
UNIMPL(wint_t getwc(FILE *stream))
UNIMPL(wint_t ungetwc(wint_t wc, FILE *stream))
UNIMPL(int fseeko64(FILE *stream, off64_t offset, int whence))
UNIMPL(wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t n))
UNIMPL(size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps))
UNIMPL(wchar_t *wmemset(wchar_t *wcs, wchar_t wc, size_t n))
UNIMPL(off64_t ftell(FILE *stream))
UNIMPL(FILE *fopen64(const char *path, const char *mode))
UNIMPL(off64_t ftello64(FILE *stream))
UNIMPL(wint_t fputwc(wchar_t wc, FILE *stream))
UNIMPL(wint_t putwc(wchar_t wc, FILE *stream))
UNIMPL(int wctob(wint_t c))
UNIMPL(size_t wcsnrtombs(char *dest, const wchar_t **src, size_t nwc,
size_t len, mbstate_t *ps))
UNIMPL(wint_t btowc(int c))
UNIMPL(size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps))
UNIMPL(void __stack_chk_fail(void))
UNIMPL(void __assert_fail(const char * assertion, const char * file, unsigned int line, const char * function))
UNIMPL(void __freelocale(__locale_t __dataset) __THROW)
UNIMPL(__locale_t __duplocale(__locale_t __dataset) __THROW)
UNIMPL(__locale_t __newlocale(int __category_mask, __const char *__locale,
__locale_t __base) __THROW)
UNIMPL(long double strtold_l(__const char *__restrict __nptr,
char **__restrict __endptr, __locale_t __loc))
UNIMPL(double __strtod_l(__const char *__restrict __nptr,
char **__restrict __endptr, __locale_t __loc)
__THROW)
UNIMPL(size_t mbsnrtowcs(wchar_t *dest, const char **src,
size_t nms, size_t len, mbstate_t *ps))
UNIMPL(size_t mbsrtowcs(wchar_t *dest, const char **src,
size_t len, mbstate_t *ps))
UNIMPL(__locale_t __uselocale (__locale_t __dataset) __THROW)
UNIMPL(char *__setlocale(int category, const char *locale))
UNIMPL(char* textdomain (const char* domainname))
UNIMPL(char* bindtextdomain (const char * domainname, const char * dirname))
UNIMPL(int __iswctype_l(wint_t __wc, wctype_t __desc, __locale_t __locale)
__THROW)
UNIMPL(float __strtof_l(__const char *__restrict __nptr,
char **__restrict __endptr, __locale_t __loc)
__THROW)
UNIMPL(char *__nl_langinfo_l(nl_item __item, __locale_t __l))
UNIMPL(int vsnprintf(char *str, size_t size, const char *format, va_list ap))
UNIMPL(wctype_t __wctype_l(__const char *__property, __locale_t __locale)
__THROW)
UNIMPL(size_t __ctype_get_mb_cur_max (void) __THROW)
UNIMPL(wint_t __towlower_l(wint_t __wc, __locale_t __locale) __THROW)
UNIMPL(int __wcscoll_l(__const wchar_t *__s1, __const wchar_t *__s2,
__locale_t __loc) __THROW)
UNIMPL(wint_t __towupper_l(wint_t __wc, __locale_t __locale) __THROW)
UNIMPL(int __strcoll_l(__const char *__s1, __const char *__s2, __locale_t __l)
__THROW)
UNIMPL(size_t __wcsftime_l (wchar_t *__restrict __s, size_t __maxsize,
__const wchar_t *__restrict __format,
__const struct tm *__restrict __tp,
__locale_t __loc) __THROW)
UNIMPL(size_t __strftime_l (char *__restrict __s, size_t __maxsize,
__const char *__restrict __format,
__const struct tm *__restrict __tp,
__locale_t __loc) __THROW)
UNIMPL(size_t __strxfrm_l (char *__dest, __const char *__src, size_t __n,
__locale_t __l) __THROW)
UNIMPL(size_t __wcsxfrm_l(wchar_t *__s1, __const wchar_t *__s2,
size_t __n, __locale_t __loc) __THROW)
UNIMPL(int wcscmp(const wchar_t *s1, const wchar_t *s2))