1d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/******************************************************************************/
2d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifdef JEMALLOC_H_TYPES
3d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
4d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/* Size of stack-allocated buffer passed to buferror(). */
5d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#define	BUFERROR_BUF		64
6d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
7d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/*
8cd9a1346e96f71bdecdc654ea50fc62d76371e74Jason Evans * Size of stack-allocated buffer used by malloc_{,v,vc}printf().  This must be
9cd9a1346e96f71bdecdc654ea50fc62d76371e74Jason Evans * large enough for all possible uses within jemalloc.
10824d34e5b7f5cf00bf472ec79f7ec1c6e3474114Jason Evans */
11824d34e5b7f5cf00bf472ec79f7ec1c6e3474114Jason Evans#define	MALLOC_PRINTF_BUFSIZE	4096
12824d34e5b7f5cf00bf472ec79f7ec1c6e3474114Jason Evans
13824d34e5b7f5cf00bf472ec79f7ec1c6e3474114Jason Evans/*
14cd9a1346e96f71bdecdc654ea50fc62d76371e74Jason Evans * Wrap a cpp argument that contains commas such that it isn't broken up into
15cd9a1346e96f71bdecdc654ea50fc62d76371e74Jason Evans * multiple arguments.
16cd9a1346e96f71bdecdc654ea50fc62d76371e74Jason Evans */
17a4f124f59fa5f702231432a7e5fa45140ba81e2aJason Evans#define	JEMALLOC_ARG_CONCAT(...) __VA_ARGS__
18cd9a1346e96f71bdecdc654ea50fc62d76371e74Jason Evans
19cd9a1346e96f71bdecdc654ea50fc62d76371e74Jason Evans/*
209225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans * Silence compiler warnings due to uninitialized values.  This is used
219225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans * wherever the compiler fails to recognize that the variable is never used
229225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans * uninitialized.
239225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans */
249225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans#ifdef JEMALLOC_CC_SILENCE
259225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans#  define JEMALLOC_CC_SILENCE_INIT(v) = v
269225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans#else
279225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans#  define JEMALLOC_CC_SILENCE_INIT(v)
289225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans#endif
299225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans
309225a1991a58190207cca2ff3cdba966bb322dd5Jason Evans/*
31d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans * Define a custom assert() in order to reduce the chances of deadlock during
32d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans * assertion failure.
33d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans */
34d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifndef assert
35d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#define	assert(e) do {							\
36d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	if (config_debug && !(e)) {					\
37d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		malloc_printf(						\
38d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		    "<jemalloc>: %s:%d: Failed assertion: \"%s\"\n",	\
39d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		    __FILE__, __LINE__, #e);				\
40d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		abort();						\
41d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	}								\
42d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans} while (0)
43d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif
44d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
45d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifndef not_reached
46d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#define	not_reached() do {						\
47d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	if (config_debug) {						\
48d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		malloc_printf(						\
49d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		    "<jemalloc>: %s:%d: Unreachable code reached\n",	\
50d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		    __FILE__, __LINE__);				\
51d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		abort();						\
52d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	}								\
53d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans} while (0)
54d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif
55d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
56d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifndef not_implemented
57d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#define	not_implemented() do {						\
58d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	if (config_debug) {						\
59d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		malloc_printf("<jemalloc>: %s:%d: Not implemented\n",	\
60d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		    __FILE__, __LINE__);				\
61d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		abort();						\
62d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	}								\
63d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans} while (0)
64d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif
65d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
6686abd0dcd8e478759fe409d338d11558c4cec427Jason Evans#ifndef assert_not_implemented
67d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#define	assert_not_implemented(e) do {					\
68d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	if (config_debug && !(e))					\
69d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans		not_implemented();					\
70d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans} while (0)
7186abd0dcd8e478759fe409d338d11558c4cec427Jason Evans#endif
72d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
736556e28be15d9acd8f3835fb9fad90145e1edbffJason Evans/* Use to assert a particular configuration, e.g., cassert(config_debug). */
746556e28be15d9acd8f3835fb9fad90145e1edbffJason Evans#define	cassert(c) do {							\
756556e28be15d9acd8f3835fb9fad90145e1edbffJason Evans	if ((c) == false)						\
766556e28be15d9acd8f3835fb9fad90145e1edbffJason Evans		not_reached();						\
776556e28be15d9acd8f3835fb9fad90145e1edbffJason Evans} while (0)
786556e28be15d9acd8f3835fb9fad90145e1edbffJason Evans
79d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif /* JEMALLOC_H_TYPES */
80d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/******************************************************************************/
81d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifdef JEMALLOC_H_STRUCTS
82d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
83d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif /* JEMALLOC_H_STRUCTS */
84d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/******************************************************************************/
85d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifdef JEMALLOC_H_EXTERNS
86d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
872a83ed0284e92c7ba4bd4efe9df149ac724b2f26Jason Evansint	buferror(int err, char *buf, size_t buflen);
88e18c25d23de0e845f0ee7e11d02c1be044738a3cJason Evansuintmax_t	malloc_strtoumax(const char *restrict nptr,
89e18c25d23de0e845f0ee7e11d02c1be044738a3cJason Evans    char **restrict endptr, int base);
90889ec59bd3ae3190fb715e64d8d15b6a1b47314aJason Evansvoid	malloc_write(const char *s);
91d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
92d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/*
93d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans * malloc_vsnprintf() supports a subset of snprintf(3) that avoids floating
94d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans * point math.
95d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans */
96d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evansint	malloc_vsnprintf(char *str, size_t size, const char *format,
97d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans    va_list ap);
98d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evansint	malloc_snprintf(char *str, size_t size, const char *format, ...)
99d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans    JEMALLOC_ATTR(format(printf, 3, 4));
100d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evansvoid	malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
101d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans    const char *format, va_list ap);
102d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evansvoid malloc_cprintf(void (*write)(void *, const char *), void *cbopaque,
103d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans    const char *format, ...) JEMALLOC_ATTR(format(printf, 3, 4));
104d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evansvoid	malloc_printf(const char *format, ...)
105d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans    JEMALLOC_ATTR(format(printf, 1, 2));
106d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
107d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif /* JEMALLOC_H_EXTERNS */
108d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/******************************************************************************/
109d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifdef JEMALLOC_H_INLINES
110d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
111d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#ifndef JEMALLOC_ENABLE_INLINE
1122aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamondint	jemalloc_ffsl(long bitmap);
1132aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamondint	jemalloc_ffs(int bitmap);
114d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evanssize_t	pow2_ceil(size_t x);
1158d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evanssize_t	lg_floor(size_t x);
116a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommeyvoid	set_errno(int errnum);
117a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommeyint	get_errno(void);
118d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif
119d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
120d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_UTIL_C_))
1212aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond
1222aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond/* Sanity check: */
1232aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond#if !defined(JEMALLOC_INTERNAL_FFSL) || !defined(JEMALLOC_INTERNAL_FFS)
1242aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond#  error Both JEMALLOC_INTERNAL_FFSL && JEMALLOC_INTERNAL_FFS should have been defined by configure
1252aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond#endif
1262aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond
1272aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard DiamondJEMALLOC_ALWAYS_INLINE int
1282aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamondjemalloc_ffsl(long bitmap)
1292aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond{
1302aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond
1312aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond        return (JEMALLOC_INTERNAL_FFSL(bitmap));
1322aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond}
1332aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond
1342aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard DiamondJEMALLOC_ALWAYS_INLINE int
1352aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamondjemalloc_ffs(int bitmap)
1362aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond{
1372aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond
1382aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond        return (JEMALLOC_INTERNAL_FFS(bitmap));
1392aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond}
1402aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond
141d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/* Compute the smallest power of 2 that is >= x. */
142d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason EvansJEMALLOC_INLINE size_t
143d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evanspow2_ceil(size_t x)
144d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans{
145d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
146d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x--;
147d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x |= x >> 1;
148d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x |= x >> 2;
149d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x |= x >> 4;
150d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x |= x >> 8;
151d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x |= x >> 16;
152d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#if (LG_SIZEOF_PTR == 3)
153d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x |= x >> 32;
154d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif
155d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	x++;
156d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans	return (x);
157d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans}
158d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
1598d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#if (defined(__i386__) || defined(__amd64__) || defined(__x86_64__))
1608d8f9aeeaa77514d5732db5bd0111232af21fcfdJason EvansJEMALLOC_INLINE size_t
1618d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evanslg_floor(size_t x)
1628d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans{
1638d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans	size_t ret;
1648d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans
1658d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans	asm ("bsr %1, %0"
1668d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans	    : "=r"(ret) // Outputs.
1678d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans	    : "r"(x)    // Inputs.
1688d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans	    );
1698d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans	return (ret);
1708d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans}
1718d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#elif (defined(JEMALLOC_HAVE_BUILTIN_CLZ))
1728d8f9aeeaa77514d5732db5bd0111232af21fcfdJason EvansJEMALLOC_INLINE size_t
1738d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evanslg_floor(size_t x)
1748d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans{
1758d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans
1768d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#if (LG_SIZEOF_PTR == LG_SIZEOF_INT)
17715cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	return (((8 << LG_SIZEOF_PTR) - 1) - __builtin_clz(x));
1788d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#elif (LG_SIZEOF_PTR == LG_SIZEOF_LONG)
17915cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	return (((8 << LG_SIZEOF_PTR) - 1) - __builtin_clzl(x));
1808d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#else
1818d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#  error "Unsupported type sizes for lg_floor()"
1828d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#endif
1838d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans}
1848d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#else
1858d8f9aeeaa77514d5732db5bd0111232af21fcfdJason EvansJEMALLOC_INLINE size_t
1868d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evanslg_floor(size_t x)
1878d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans{
1888d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans
18915cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x |= (x >> 1);
19015cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x |= (x >> 2);
19115cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x |= (x >> 4);
19215cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x |= (x >> 8);
19315cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x |= (x >> 16);
1948d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#if (LG_SIZEOF_PTR == 3 && LG_SIZEOF_PTR == LG_SIZEOF_LONG)
19515cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x |= (x >> 32);
19615cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	if (x == KZU(0xffffffffffffffff))
19715cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans		return (63);
19815cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x++;
1992aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond	return (jemalloc_ffsl(x) - 2);
2008d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#elif (LG_SIZEOF_PTR == 2)
20115cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	if (x == KZU(0xffffffff))
20215cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans		return (31);
20315cb17e8aad6afb887ec15c162f357695658bdf6Jason Evans	x++;
2042aa7fed9c983d8dcde7c0cacf1b024c966758b88Richard Diamond	return (jemalloc_ffs(x) - 2);
2058d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#else
2068d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#  error "Unsupported type sizes for lg_floor()"
2078d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#endif
2088d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans}
2098d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans#endif
2108d8f9aeeaa77514d5732db5bd0111232af21fcfdJason Evans
211a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey/* Sets error code */
212a14bce85e885f83c96116cc5438ae52d740f3727Mike HommeyJEMALLOC_INLINE void
213a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommeyset_errno(int errnum)
214a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey{
215a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey
216a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey#ifdef _WIN32
217a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey	SetLastError(errnum);
218a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey#else
219a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey	errno = errnum;
220a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey#endif
221a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey}
222a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey
223a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey/* Get last error code */
224a14bce85e885f83c96116cc5438ae52d740f3727Mike HommeyJEMALLOC_INLINE int
225a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommeyget_errno(void)
226a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey{
227a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey
228a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey#ifdef _WIN32
2297cdea3973cab8640d1f44c7638ed5e30ed18be24Mike Hommey	return (GetLastError());
230a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey#else
2317cdea3973cab8640d1f44c7638ed5e30ed18be24Mike Hommey	return (errno);
232a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey#endif
233a14bce85e885f83c96116cc5438ae52d740f3727Mike Hommey}
234d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif
235d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans
236d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans#endif /* JEMALLOC_H_INLINES */
237d81e4bdd5c991bd5642c8b859ef1f752b51cd9beJason Evans/******************************************************************************/
238