Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit a241afc

Browse files
Jim Chenarthurprs
authored andcommitted
Use openat syscall if available
Some architectures like AArch64 may not have the open syscall because it was superseded by the openat syscall, so check and use SYS_openat if SYS_open is not available. Additionally, Android headers for AArch64 define SYS_open to __NR_open, even though __NR_open is undefined. Undefine SYS_open in that case so SYS_openat is used.
1 parent 9986533 commit a241afc

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

include/jemalloc/internal/jemalloc_internal_decls.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
# if !defined(SYS_write) && defined(__NR_write)
1515
# define SYS_write __NR_write
1616
# endif
17+
# if defined(SYS_open) && defined(__aarch64__)
18+
/* Android headers may define SYS_open to __NR_open even though
19+
* __NR_open may not exist on AArch64 (superseded by __NR_openat). */
20+
# undef SYS_open
21+
# endif
1722
# include <sys/uio.h>
1823
# endif
1924
# include <pthread.h>

src/pages.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ os_overcommits_proc(void)
250250

251251
#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_open)
252252
fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY);
253+
#elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat)
254+
fd = (int)syscall(SYS_openat,
255+
AT_FDCWD, "/proc/sys/vm/overcommit_memory", O_RDONLY);
253256
#else
254257
fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY);
255258
#endif

0 commit comments

Comments
 (0)