From 7515ce3fa8b30f7b7d67bc2a659e15276c0923d7 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 30 Aug 2016 04:46:47 -0500 Subject: Initial commit --- dlvsym.c | 14 ++++++++++++++ malloc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ math.c | 21 +++++++++++++++++++++ stdio.c | 3 +++ stdlib.c | 8 ++++++++ string.c | 32 ++++++++++++++++++++++++++++++++ version.c | 14 ++++++++++++++ 7 files changed, 138 insertions(+) create mode 100644 dlvsym.c create mode 100644 malloc.c create mode 100644 math.c create mode 100644 stdio.c create mode 100644 stdlib.c create mode 100644 string.c create mode 100644 version.c diff --git a/dlvsym.c b/dlvsym.c new file mode 100644 index 0000000..3d744ea --- /dev/null +++ b/dlvsym.c @@ -0,0 +1,14 @@ +#include // dlsym +#include // fprintf +#include // getenv + +void *dlvsym(void *handle, char *symbol, char *version) +{ + if(getenv("GLIBC_FAKE_DEBUG")) + { + fprintf(stderr, "symbol %s with version %s is being redirected", + symbol, version); + } + + return dlsym(handle, symbol); +} diff --git a/malloc.c b/malloc.c new file mode 100644 index 0000000..3a5818c --- /dev/null +++ b/malloc.c @@ -0,0 +1,46 @@ +/* struct mallinfo pulled from mallinfo.3: + * + * Copyright (c) 2012 by Michael Kerrisk + * + * Permission is granted to make and distribute verbatim copies of this + * manual provided the copyright notice and this permission notice are + * preserved on all copies. + * + * Permission is granted to copy and distribute modified versions of this + * manual under the conditions for verbatim copying, provided that the + * entire resulting derived work is distributed under the terms of a + * permission notice identical to this one. + * + * Since the Linux kernel and libraries are constantly changing, this + * manual page may be incorrect or out-of-date. The author(s) assume no + * responsibility for errors or omissions, or for damages resulting from + * the use of the information contained herein. The author(s) may not + * have taken the same level of care in the production of this manual, + * which is licensed free of charge, as they might when working + * professionally. + * + * Formatted or processed versions of this manual, if unaccompanied by + * the source, must acknowledge the copyright and authors of this work. + */ + +#include /* memset */ + +struct mallinfo { + int arena; /* Non-mmapped space allocated (bytes) */ + int ordblks; /* Number of free chunks */ + int smblks; /* Number of free fastbin blocks */ + int hblks; /* Number of mmapped regions */ + int hblkhd; /* Space allocated in mmapped regions (bytes) */ + int usmblks; /* Maximum total allocated space (bytes) */ + int fsmblks; /* Space in freed fastbin blocks (bytes) */ + int uordblks; /* Total allocated space (bytes) */ + int fordblks; /* Total free space (bytes) */ + int keepcost; /* Top-most, releasable space (bytes) */ +}; + +struct mallinfo mallinfo(void) +{ + struct mallinfo my_info; + memset(&my_info, 0, sizeof(struct mallinfo)); + return my_info; +} diff --git a/math.c b/math.c new file mode 100644 index 0000000..bacec36 --- /dev/null +++ b/math.c @@ -0,0 +1,21 @@ +#include // isinf, isnan + +int __isinff(float number) +{ + return isinf(number); +} + +int __isinf(double number) +{ + return isinf(number); +} + +int __isnanf(float number) +{ + return isnan(number); +} + +int __isnan(double number) +{ + return isnan(number); +} diff --git a/stdio.c b/stdio.c new file mode 100644 index 0000000..f26b69b --- /dev/null +++ b/stdio.c @@ -0,0 +1,3 @@ +#include + +asm(".equ __IO_2_1_stdout_, _stdout"); diff --git a/stdlib.c b/stdlib.c new file mode 100644 index 0000000..b81eb91 --- /dev/null +++ b/stdlib.c @@ -0,0 +1,8 @@ +#include // assert +#include // strtod + +double __strtod_internal(const char *__nptr, char **__endptr, int __group) +{ + assert(__group == 0); + return strtod(__nptr, __endptr); +} diff --git a/string.c b/string.c new file mode 100644 index 0000000..5bbb1b3 --- /dev/null +++ b/string.c @@ -0,0 +1,32 @@ +#include /* strndup */ + +/* Literally a useless __ alias. */ +char *__strndup(const char *str, size_t count) +{ + return strndup(str, count); +} + +/* The existance of this method, and the fact it is used in real code, gives + * me nightmares. */ +void *rawmemchr(const void *s, int c) +{ + const unsigned char *haystack = s; + unsigned char needle = (unsigned char)c; + while(*haystack++ != needle); + return (void *)haystack; +} + +extern __typeof(rawmemchr) __rawmemchr __attribute__((weak, alias("rawmemchr"))); + +/* Another useless __ alias */ +char *__strtok_r(char *str, const char *delim, char **saveptr) +{ + return strtok_r(str, delim, saveptr); +} + +/* The "global" definition of strsep in glibc, used when architecture dependent + * assembler versions aren't good enough. */ +char *__strsep_g(char **stringp, const char *delim) +{ + return strsep(stringp, delim); +} diff --git a/version.c b/version.c new file mode 100644 index 0000000..63146f8 --- /dev/null +++ b/version.c @@ -0,0 +1,14 @@ +#include // getenv + +const char *gnu_get_libc_version(void) +{ + char *ver = getenv("GLIBC_FAKE_VERSION"); + if(ver == NULL) ver = "2.8"; + + return ver; +} + +const char *gnu_get_libc_release(void) +{ + return "stable"; +} -- cgit v1.2.3-60-g2f50