2019-01-19 21:35:46 +00:00
|
|
|
/** Allows to build programs with libc 2.27 and run on systems with at least libc 2.4,
|
|
|
|
* such as Ubuntu Hardy or CentOS 5.
|
2017-09-15 05:43:43 +00:00
|
|
|
*
|
|
|
|
* Also look at http://www.lightofdawn.org/wiki/wiki.cgi/NewAppsOnOldGlibc
|
|
|
|
*/
|
2017-09-15 05:27:09 +00:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-09-15 07:24:53 +00:00
|
|
|
#include <pthread.h>
|
2021-06-19 14:34:28 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
2017-09-15 07:24:53 +00:00
|
|
|
|
2021-06-19 14:34:28 +00:00
|
|
|
/// glibc __pthread_get_minstack() will take TLS into account for the minimal
|
|
|
|
/// stack size (since you cannot use stack less then TLS block size, otherwise
|
|
|
|
/// some variables may be overwritten)
|
|
|
|
///
|
|
|
|
/// So glibc implementation is:
|
|
|
|
///
|
|
|
|
/// sysconf(_SC_PAGESIZE) + __static_tls_size + PTHREAD_STACK_MIN;
|
|
|
|
///
|
|
|
|
/// But this helper cannot do this since:
|
|
|
|
/// - __pthread_get_minstack() is hidden in libc (note that rust tried to do
|
|
|
|
/// this but revert it to retry loop, for compatibility, while we cannot
|
|
|
|
/// use retry loop since this function is used for sigaltstack())
|
|
|
|
/// - __static_tls_size is not exported in glibc
|
|
|
|
/// - it is not used anywhere except for clickhouse itself (for sigaltstack(),
|
|
|
|
/// to handle SIGSEGV only) and using PTHREAD_STACK_MIN (16k) is enough right
|
|
|
|
/// now.
|
|
|
|
///
|
|
|
|
/// Also we cannot use getStackSize() (pthread_attr_getstack()) since it will
|
|
|
|
/// return 8MB, and this is too huge for signal stack.
|
2017-09-15 07:24:53 +00:00
|
|
|
size_t __pthread_get_minstack(const pthread_attr_t * attr)
|
|
|
|
{
|
2021-06-19 14:34:28 +00:00
|
|
|
_Static_assert(PTHREAD_STACK_MIN == 16<<10, "Too small return value of __pthread_get_minstack()");
|
|
|
|
return PTHREAD_STACK_MIN;
|
2017-09-15 07:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
|
|
|
long int syscall(long int __sysno, ...) __THROW;
|
|
|
|
|
|
|
|
int __gai_sigqueue(int sig, const union sigval val, pid_t caller_pid)
|
|
|
|
{
|
|
|
|
siginfo_t info;
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(siginfo_t));
|
|
|
|
info.si_signo = sig;
|
|
|
|
info.si_code = SI_ASYNCNL;
|
|
|
|
info.si_pid = caller_pid;
|
|
|
|
info.si_uid = getuid();
|
|
|
|
info.si_value = val;
|
|
|
|
|
|
|
|
return syscall(__NR_rt_sigqueueinfo, info.si_pid, sig, &info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-15 05:27:09 +00:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <stdlib.h>
|
2017-09-18 07:10:35 +00:00
|
|
|
#include <features.h>
|
2017-09-15 05:27:09 +00:00
|
|
|
|
2017-09-18 07:10:35 +00:00
|
|
|
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 16)
|
2017-09-15 05:27:09 +00:00
|
|
|
long int __fdelt_chk(long int d)
|
2017-09-26 20:29:34 +00:00
|
|
|
{
|
|
|
|
if (d < 0)
|
|
|
|
abort();
|
2017-09-18 07:10:35 +00:00
|
|
|
#else
|
|
|
|
unsigned long int __fdelt_chk(unsigned long int d)
|
2017-09-15 05:27:09 +00:00
|
|
|
{
|
2017-09-26 20:29:34 +00:00
|
|
|
#endif
|
|
|
|
if (d >= FD_SETSIZE)
|
2017-09-15 05:27:09 +00:00
|
|
|
abort();
|
|
|
|
return d / __NFDBITS;
|
|
|
|
}
|
|
|
|
|
2017-09-15 05:43:43 +00:00
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <stddef.h>
|
2017-09-15 05:27:09 +00:00
|
|
|
|
|
|
|
int __poll_chk(struct pollfd * fds, nfds_t nfds, int timeout, size_t fdslen)
|
|
|
|
{
|
|
|
|
if (fdslen / sizeof(*fds) < nfds)
|
|
|
|
abort();
|
|
|
|
return poll(fds, nfds, timeout);
|
|
|
|
}
|
|
|
|
|
2017-09-15 07:24:53 +00:00
|
|
|
#include <setjmp.h>
|
2017-09-15 05:27:09 +00:00
|
|
|
|
2017-10-07 17:44:17 +00:00
|
|
|
void musl_glibc_longjmp(jmp_buf env, int val);
|
2017-09-15 07:24:53 +00:00
|
|
|
|
2017-09-16 22:32:04 +00:00
|
|
|
/// NOTE This disables some of FORTIFY_SOURCE functionality.
|
|
|
|
|
2017-09-15 07:24:53 +00:00
|
|
|
void __longjmp_chk(jmp_buf env, int val)
|
2017-09-15 05:27:09 +00:00
|
|
|
{
|
2017-10-07 17:44:17 +00:00
|
|
|
musl_glibc_longjmp(env, val);
|
2017-09-15 05:27:09 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 07:29:03 +00:00
|
|
|
#include <stdarg.h>
|
2017-09-15 05:27:09 +00:00
|
|
|
|
2017-09-15 07:24:53 +00:00
|
|
|
int vasprintf(char **s, const char *fmt, va_list ap);
|
2017-09-15 05:27:09 +00:00
|
|
|
|
2017-11-21 00:30:06 +00:00
|
|
|
int __vasprintf_chk(char **s, int unused, const char *fmt, va_list ap)
|
2017-09-15 05:27:09 +00:00
|
|
|
{
|
2017-09-15 07:24:53 +00:00
|
|
|
return vasprintf(s, fmt, ap);
|
|
|
|
}
|
2017-09-15 05:27:09 +00:00
|
|
|
|
2019-01-19 21:35:46 +00:00
|
|
|
int __asprintf_chk(char **result_ptr, int unused, const char *format, ...)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, format);
|
|
|
|
ret = vasprintf(result_ptr, format, ap);
|
|
|
|
va_end (ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vdprintf(int fd, const char *format, va_list ap);
|
|
|
|
|
|
|
|
int __dprintf_chk (int d, int unused, const char *format, ...)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, format);
|
|
|
|
ret = vdprintf(d, format, ap);
|
|
|
|
va_end (ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-15 07:29:03 +00:00
|
|
|
size_t fread(void *ptr, size_t size, size_t nmemb, void *stream);
|
|
|
|
|
2017-11-21 00:30:06 +00:00
|
|
|
size_t __fread_chk(void *ptr, size_t unused, size_t size, size_t nmemb, void *stream)
|
2017-09-15 07:24:53 +00:00
|
|
|
{
|
|
|
|
return fread(ptr, size, nmemb, stream);
|
|
|
|
}
|
2017-09-15 05:27:09 +00:00
|
|
|
|
2017-09-15 07:24:53 +00:00
|
|
|
int vsscanf(const char *str, const char *format, va_list ap);
|
|
|
|
|
|
|
|
int __isoc99_vsscanf(const char *str, const char *format, va_list ap)
|
|
|
|
{
|
|
|
|
return vsscanf(str, format, ap);
|
2017-09-15 05:27:09 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 07:24:53 +00:00
|
|
|
int sscanf(const char *restrict s, const char *restrict fmt, ...)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ret = vsscanf(s, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-27 14:28:15 +00:00
|
|
|
int __isoc99_sscanf(const char *str, const char *format, ...) __attribute__((weak, nonnull, nothrow, alias("sscanf")));
|
2017-09-15 07:24:53 +00:00
|
|
|
|
2017-09-15 07:51:38 +00:00
|
|
|
int open(const char *path, int oflag);
|
|
|
|
|
|
|
|
int __open_2(const char *path, int oflag)
|
|
|
|
{
|
|
|
|
return open(path, oflag);
|
|
|
|
}
|
|
|
|
|
2017-09-15 07:24:53 +00:00
|
|
|
|
2017-11-12 12:58:40 +00:00
|
|
|
/// No-ops.
|
|
|
|
int pthread_setname_np(pthread_t thread, const char *name) { return 0; }
|
|
|
|
int pthread_getname_np(pthread_t thread, char *name, size_t len) { name[0] = '\0'; return 0; };
|
|
|
|
|
|
|
|
|
2018-01-11 11:44:30 +00:00
|
|
|
#define SHMDIR "/dev/shm/"
|
2018-01-11 13:25:10 +00:00
|
|
|
const char * __shm_directory(size_t * len)
|
2018-01-11 11:44:30 +00:00
|
|
|
{
|
2018-01-11 13:25:10 +00:00
|
|
|
*len = sizeof(SHMDIR) - 1;
|
|
|
|
return SHMDIR;
|
2018-01-11 11:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-05 23:47:31 +00:00
|
|
|
/// https://boringssl.googlesource.com/boringssl/+/ad1907fe73334d6c696c8539646c21b11178f20f%5E!/#F0
|
|
|
|
/* Copyright (c) 2015, Google Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2018-10-22 15:33:32 +00:00
|
|
|
void __attribute__((__weak__)) explicit_bzero(void * buf, size_t len)
|
2018-08-05 23:47:31 +00:00
|
|
|
{
|
|
|
|
memset(buf, 0, len);
|
|
|
|
__asm__ __volatile__("" :: "r"(buf) : "memory");
|
|
|
|
}
|
|
|
|
|
2018-08-06 00:19:33 +00:00
|
|
|
void __explicit_bzero_chk(void * buf, size_t len, size_t unused)
|
2018-08-05 23:59:18 +00:00
|
|
|
{
|
|
|
|
return explicit_bzero(buf, len);
|
|
|
|
}
|
|
|
|
|
2018-08-05 23:47:31 +00:00
|
|
|
|
2017-09-15 05:27:09 +00:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|