Skip to content

Commit 145f3cd

Browse files
committed
Add --disable-syscall.
This resolves jemalloc#517.
1 parent e1b2970 commit 145f3cd

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

INSTALL

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ any of the following arguments (not a definitive list) to 'configure':
206206
most extreme case increases physical memory usage for the 16 KiB size class
207207
to 20 KiB.
208208

209+
--disable-syscall
210+
Disable use of syscall(2) rather than {open,read,write,close}(2). This is
211+
intended as a workaround for systems that place security limitations on
212+
syscall(2).
213+
209214
--with-xslroot=<path>
210215
Specify where to find DocBook XSL stylesheets when building the
211216
documentation.

configure.ac

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,20 +1396,33 @@ if test "x${je_cv_mach_absolute_time}" = "xyes" ; then
13961396
AC_DEFINE([JEMALLOC_HAVE_MACH_ABSOLUTE_TIME])
13971397
fi
13981398

1399-
dnl Check if syscall(2) is usable. Treat warnings as errors, so that e.g. OS X
1400-
dnl 10.12's deprecation warning prevents use.
1401-
SAVED_CFLAGS="${CFLAGS}"
1402-
JE_CFLAGS_APPEND([-Werror])
1403-
JE_COMPILABLE([syscall(2)], [
1399+
dnl Use syscall(2) (if available) by default.
1400+
AC_ARG_ENABLE([syscall],
1401+
[AS_HELP_STRING([--disable-syscall], [Disable use of syscall(2)])],
1402+
[if test "x$enable_syscall" = "xno" ; then
1403+
enable_syscall="0"
1404+
else
1405+
enable_syscall="1"
1406+
fi
1407+
],
1408+
[enable_syscall="1"]
1409+
)
1410+
if test "x$enable_syscall" = "x1" ; then
1411+
dnl Check if syscall(2) is usable. Treat warnings as errors, so that e.g. OS
1412+
dnl X 10.12's deprecation warning prevents use.
1413+
SAVED_CFLAGS="${CFLAGS}"
1414+
JE_CFLAGS_APPEND([-Werror])
1415+
JE_COMPILABLE([syscall(2)], [
14041416
#include <sys/syscall.h>
14051417
#include <unistd.h>
14061418
], [
14071419
syscall(SYS_write, 2, "hello", 5);
14081420
],
1409-
[je_cv_syscall])
1410-
CFLAGS="${SAVED_CFLAGS}"
1411-
if test "x$je_cv_syscall" = "xyes" ; then
1412-
AC_DEFINE([JEMALLOC_HAVE_SYSCALL], [ ])
1421+
[je_cv_syscall])
1422+
CFLAGS="${SAVED_CFLAGS}"
1423+
if test "x$je_cv_syscall" = "xyes" ; then
1424+
AC_DEFINE([JEMALLOC_USE_SYSCALL], [ ])
1425+
fi
14131426
fi
14141427

14151428
dnl Check if the GNU-specific secure_getenv function exists.

include/jemalloc/internal/jemalloc_internal_defs.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
*/
6767
#undef JEMALLOC_OSSPIN
6868

69-
/* Defined if syscall(2) is available. */
70-
#undef JEMALLOC_HAVE_SYSCALL
69+
/* Defined if syscall(2) is usable. */
70+
#undef JEMALLOC_USE_SYSCALL
7171

7272
/*
7373
* Defined if secure_getenv(3) is available.

src/pages.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,21 @@ os_overcommits_proc(void)
248248
char buf[1];
249249
ssize_t nread;
250250

251-
#if defined(JEMALLOC_HAVE_SYSCALL) && defined(SYS_open)
251+
#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_open)
252252
fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY);
253253
#else
254254
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY);
255255
#endif
256256
if (fd == -1)
257257
return (false); /* Error. */
258258

259-
#if defined(JEMALLOC_HAVE_SYSCALL) && defined(SYS_read)
259+
#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_read)
260260
nread = (ssize_t)syscall(SYS_read, fd, &buf, sizeof(buf));
261261
#else
262262
nread = read(fd, &buf, sizeof(buf));
263263
#endif
264264

265-
#if defined(JEMALLOC_HAVE_SYSCALL) && defined(SYS_close)
265+
#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_close)
266266
syscall(SYS_close, fd);
267267
#else
268268
close(fd);

src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void
4949
wrtmessage(void *cbopaque, const char *s)
5050
{
5151

52-
#if defined(JEMALLOC_HAVE_SYSCALL) && defined(SYS_write)
52+
#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_write)
5353
/*
5454
* Use syscall(2) rather than write(2) when possible in order to avoid
5555
* the possibility of memory allocation within libc. This is necessary

0 commit comments

Comments
 (0)