1/** Allows to build programs with libc 2.27 and run on systems with at least libc 2.4,
2 * such as Ubuntu Hardy or CentOS 5.
3 *
4 * Also look at http://www.lightofdawn.org/wiki/wiki.cgi/NewAppsOnOldGlibc
5 */
6
7#if defined (__cplusplus)
8extern "C" {
9#endif
10
11#include <pthread.h>
12
13size_t __pthread_get_minstack(const pthread_attr_t * attr)
14{
15 return 1048576; /// This is a guess. Don't sure it is correct.
16}
17
18#include <signal.h>
19#include <unistd.h>
20#include <string.h>
21#include <sys/syscall.h>
22
23long int syscall(long int __sysno, ...) __THROW;
24
25int __gai_sigqueue(int sig, const union sigval val, pid_t caller_pid)
26{
27 siginfo_t info;
28
29 memset(&info, 0, sizeof(siginfo_t));
30 info.si_signo = sig;
31 info.si_code = SI_ASYNCNL;
32 info.si_pid = caller_pid;
33 info.si_uid = getuid();
34 info.si_value = val;
35
36 return syscall(__NR_rt_sigqueueinfo, info.si_pid, sig, &info);
37}
38
39
40#include <sys/select.h>
41#include <stdlib.h>
42#include <features.h>
43
44#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)
45long int __fdelt_chk(long int d)
46{
47 if (d < 0)
48 abort();
49#else
50unsigned long int __fdelt_chk(unsigned long int d)
51{
52#endif
53 if (d >= FD_SETSIZE)
54 abort();
55 return d / __NFDBITS;
56}
57
58#include <sys/poll.h>
59#include <stddef.h>
60
61int __poll_chk(struct pollfd * fds, nfds_t nfds, int timeout, size_t fdslen)
62{
63 if (fdslen / sizeof(*fds) < nfds)
64 abort();
65 return poll(fds, nfds, timeout);
66}
67
68#include <setjmp.h>
69
70void musl_glibc_longjmp(jmp_buf env, int val);
71
72/// NOTE This disables some of FORTIFY_SOURCE functionality.
73
74void __longjmp_chk(jmp_buf env, int val)
75{
76 musl_glibc_longjmp(env, val);
77}
78
79#include <stdarg.h>
80
81int vasprintf(char **s, const char *fmt, va_list ap);
82
83int __vasprintf_chk(char **s, int unused, const char *fmt, va_list ap)
84{
85 return vasprintf(s, fmt, ap);
86}
87
88int __asprintf_chk(char **result_ptr, int unused, const char *format, ...)
89{
90 int ret;
91 va_list ap;
92 va_start (ap, format);
93 ret = vasprintf(result_ptr, format, ap);
94 va_end (ap);
95 return ret;
96}
97
98int vdprintf(int fd, const char *format, va_list ap);
99
100int __dprintf_chk (int d, int unused, const char *format, ...)
101{
102 int ret;
103 va_list ap;
104 va_start (ap, format);
105 ret = vdprintf(d, format, ap);
106 va_end (ap);
107 return ret;
108}
109
110size_t fread(void *ptr, size_t size, size_t nmemb, void *stream);
111
112size_t __fread_chk(void *ptr, size_t unused, size_t size, size_t nmemb, void *stream)
113{
114 return fread(ptr, size, nmemb, stream);
115}
116
117int vsscanf(const char *str, const char *format, va_list ap);
118
119int __isoc99_vsscanf(const char *str, const char *format, va_list ap)
120{
121 return vsscanf(str, format, ap);
122}
123
124int sscanf(const char *restrict s, const char *restrict fmt, ...)
125{
126 int ret;
127 va_list ap;
128 va_start(ap, fmt);
129 ret = vsscanf(s, fmt, ap);
130 va_end(ap);
131 return ret;
132}
133
134int __isoc99_sscanf(const char *str, const char *format, ...) __attribute__((weak, nonnull, nothrow, alias("sscanf")));
135
136int open(const char *path, int oflag);
137
138int __open_2(const char *path, int oflag)
139{
140 return open(path, oflag);
141}
142
143
144/// No-ops.
145int pthread_setname_np(pthread_t thread, const char *name) { return 0; }
146int pthread_getname_np(pthread_t thread, char *name, size_t len) { name[0] = '\0'; return 0; };
147
148
149#define SHMDIR "/dev/shm/"
150const char * __shm_directory(size_t * len)
151{
152 *len = sizeof(SHMDIR) - 1;
153 return SHMDIR;
154}
155
156
157/// https://boringssl.googlesource.com/boringssl/+/ad1907fe73334d6c696c8539646c21b11178f20f%5E!/#F0
158/* Copyright (c) 2015, Google Inc.
159 *
160 * Permission to use, copy, modify, and/or distribute this software for any
161 * purpose with or without fee is hereby granted, provided that the above
162 * copyright notice and this permission notice appear in all copies.
163 *
164 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
165 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
166 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
167 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
168 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
169 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
170 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
171 */
172void __attribute__((__weak__)) explicit_bzero(void * buf, size_t len)
173{
174 memset(buf, 0, len);
175 __asm__ __volatile__("" :: "r"(buf) : "memory");
176}
177
178void __explicit_bzero_chk(void * buf, size_t len, size_t unused)
179{
180 return explicit_bzero(buf, len);
181}
182
183
184#if defined (__cplusplus)
185}
186#endif
187