2014-05-28 11:39:13 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_DECLS_H
|
2017-01-20 13:41:41 +08:00
|
|
|
#define JEMALLOC_INTERNAL_DECLS_H
|
2014-05-28 11:39:13 +08:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include <windows.h>
|
2015-07-24 04:56:25 +08:00
|
|
|
# include "msvc_compat/windows_extra.h"
|
2018-01-19 23:28:33 +08:00
|
|
|
# ifdef _WIN64
|
|
|
|
# if LG_VADDR <= 32
|
|
|
|
# error Generate the headers using x64 vcargs
|
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
# if LG_VADDR > 32
|
|
|
|
# undef LG_VADDR
|
|
|
|
# define LG_VADDR 32
|
|
|
|
# endif
|
|
|
|
# endif
|
2014-05-28 11:39:13 +08:00
|
|
|
#else
|
|
|
|
# include <sys/param.h>
|
|
|
|
# include <sys/mman.h>
|
2014-05-29 10:37:02 +08:00
|
|
|
# if !defined(__pnacl__) && !defined(__native_client__)
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
# if !defined(SYS_write) && defined(__NR_write)
|
|
|
|
# define SYS_write __NR_write
|
|
|
|
# endif
|
2017-04-20 03:22:10 +08:00
|
|
|
# if defined(SYS_open) && defined(__aarch64__)
|
|
|
|
/* Android headers may define SYS_open to __NR_open even though
|
|
|
|
* __NR_open may not exist on AArch64 (superseded by __NR_openat). */
|
|
|
|
# undef SYS_open
|
|
|
|
# endif
|
2014-05-29 10:37:02 +08:00
|
|
|
# include <sys/uio.h>
|
2014-05-28 11:39:13 +08:00
|
|
|
# endif
|
|
|
|
# include <pthread.h>
|
2018-10-06 23:43:07 +08:00
|
|
|
# ifdef __FreeBSD__
|
|
|
|
# include <pthread_np.h>
|
|
|
|
# endif
|
2017-06-20 11:35:33 +08:00
|
|
|
# include <signal.h>
|
2016-11-03 09:09:45 +08:00
|
|
|
# ifdef JEMALLOC_OS_UNFAIR_LOCK
|
|
|
|
# include <os/lock.h>
|
|
|
|
# endif
|
Support static linking of jemalloc with glibc
glibc defines its malloc implementation with several weak and strong
symbols:
strong_alias (__libc_calloc, __calloc) weak_alias (__libc_calloc, calloc)
strong_alias (__libc_free, __cfree) weak_alias (__libc_free, cfree)
strong_alias (__libc_free, __free) strong_alias (__libc_free, free)
strong_alias (__libc_malloc, __malloc) strong_alias (__libc_malloc, malloc)
The issue is not with the weak symbols, but that other parts of glibc
depend on __libc_malloc explicitly. Defining them in terms of jemalloc
API's allows the linker to drop glibc's malloc.o completely from the link,
and static linking no longer results in symbol collisions.
Another wrinkle: jemalloc during initialization calls sysconf to
get the number of CPU's. GLIBC allocates for the first time before
setting up isspace (and other related) tables, which are used by
sysconf. Instead, use the pthread API to get the number of
CPUs with GLIBC, which seems to work.
This resolves #442.
2016-10-29 04:51:52 +08:00
|
|
|
# ifdef JEMALLOC_GLIBC_MALLOC_HOOK
|
|
|
|
# include <sched.h>
|
|
|
|
# endif
|
2014-05-28 11:39:13 +08:00
|
|
|
# include <errno.h>
|
2016-02-24 03:39:02 +08:00
|
|
|
# include <sys/time.h>
|
2016-10-07 23:47:16 +08:00
|
|
|
# include <time.h>
|
|
|
|
# ifdef JEMALLOC_HAVE_MACH_ABSOLUTE_TIME
|
|
|
|
# include <mach/mach_time.h>
|
|
|
|
# endif
|
2014-05-28 11:39:13 +08:00
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#ifndef SIZE_T_MAX
|
|
|
|
# define SIZE_T_MAX SIZE_MAX
|
|
|
|
#endif
|
2017-05-18 01:47:00 +08:00
|
|
|
#ifndef SSIZE_MAX
|
|
|
|
# define SSIZE_MAX ((ssize_t)(SIZE_T_MAX >> 1))
|
|
|
|
#endif
|
2014-05-28 11:39:13 +08:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#ifndef offsetof
|
|
|
|
# define offsetof(type, member) ((size_t)&(((type *)NULL)->member))
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# include <io.h>
|
|
|
|
typedef intptr_t ssize_t;
|
|
|
|
# define PATH_MAX 1024
|
|
|
|
# define STDERR_FILENO 2
|
|
|
|
# define __func__ __FUNCTION__
|
2015-07-28 04:48:27 +08:00
|
|
|
# ifdef JEMALLOC_HAS_RESTRICT
|
|
|
|
# define restrict __restrict
|
|
|
|
# endif
|
2014-12-09 06:40:14 +08:00
|
|
|
/* Disable warnings about deprecated system functions. */
|
2014-05-28 11:39:13 +08:00
|
|
|
# pragma warning(disable: 4996)
|
2014-12-18 14:01:21 +08:00
|
|
|
#if _MSC_VER < 1800
|
|
|
|
static int
|
2017-01-16 08:56:30 +08:00
|
|
|
isblank(int c) {
|
2014-12-18 14:01:21 +08:00
|
|
|
return (c == '\t' || c == ' ');
|
|
|
|
}
|
|
|
|
#endif
|
2014-05-28 11:39:13 +08:00
|
|
|
#else
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#endif /* JEMALLOC_INTERNAL_H */
|