From 7883c7749fd7df96c6cc0f9bfdb83554d7b0606c Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Wed, 19 Apr 2017 15:40:29 -0400 Subject: [PATCH] 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. --- include/jemalloc/internal/jemalloc_internal_decls.h | 5 +++++ src/arena.c | 3 +++ src/pages.c | 3 +++ 3 files changed, 11 insertions(+) diff --git a/include/jemalloc/internal/jemalloc_internal_decls.h b/include/jemalloc/internal/jemalloc_internal_decls.h index c907d910..2366cc07 100644 --- a/include/jemalloc/internal/jemalloc_internal_decls.h +++ b/include/jemalloc/internal/jemalloc_internal_decls.h @@ -14,6 +14,11 @@ # if !defined(SYS_write) && defined(__NR_write) # define SYS_write __NR_write # endif +# 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 # include # endif # include diff --git a/src/arena.c b/src/arena.c index bfaa604c..145542f3 100644 --- a/src/arena.c +++ b/src/arena.c @@ -3842,6 +3842,9 @@ init_thp_initially_huge(void) { #if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_open) fd = (int)syscall(SYS_open, "/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY); +#elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat) + fd = (int)syscall(SYS_openat, + AT_FDCWD, "/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY); #else fd = open("/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY); #endif diff --git a/src/pages.c b/src/pages.c index 7698e49b..b88d14ac 100644 --- a/src/pages.c +++ b/src/pages.c @@ -250,6 +250,9 @@ os_overcommits_proc(void) #if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_open) fd = (int)syscall(SYS_open, "/proc/sys/vm/overcommit_memory", O_RDONLY); +#elif defined(JEMALLOC_USE_SYSCALL) && defined(SYS_openat) + fd = (int)syscall(SYS_openat, + AT_FDCWD, "/proc/sys/vm/overcommit_memory", O_RDONLY); #else fd = open("/proc/sys/vm/overcommit_memory", O_RDONLY); #endif