From 6a04b0abd728da5211e6702b1d42aef95c02d8da Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 18 Jun 2017 18:56:08 +0000 Subject: Fix intercept of SYS_open on platforms that only have SYS_openat (e.g. arm64) --- lib/intercept/intercept.cpp | 6 ++++++ lib/intercept/intercept.h | 9 +++++++++ 2 files changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/intercept/intercept.cpp b/lib/intercept/intercept.cpp index ac8c4431..72bd8d4e 100644 --- a/lib/intercept/intercept.cpp +++ b/lib/intercept/intercept.cpp @@ -242,6 +242,10 @@ extern "C" int open(const char *path, int flags, ...) #endif // DEFINE_ONLY_OPEN64 { + // Some newer architectures don't have an open() syscall, but use openat() instead. + // In these cases we will need to call sys_openat() instead of sys_open(). + // https://chromium.googlesource.com/linux-syscall-support/ + if(intercept_count > 0) { if(intercept_filename != NULL && @@ -264,6 +268,8 @@ extern "C" int #ifdef PLATFORM_NO_SYSCALL int r = TEST_open(path, flags, mode); +#elif HAVE_DECL_SYS_OPENAT && !HAVE_DECL_SYS_OPEN + int r = syscall(SYS_openat, AT_FDCWD, path, flags, mode); #else int r = syscall(SYS_open, path, flags, mode); #endif diff --git a/lib/intercept/intercept.h b/lib/intercept/intercept.h index c0d61638..4de5f9f2 100644 --- a/lib/intercept/intercept.h +++ b/lib/intercept/intercept.h @@ -62,5 +62,14 @@ void intercept_setup_stat_post_hook (lstat_post_hook_t hookfn); void intercept_clear_setup(); +// Some newer architectures don't have an open() syscall, but use openat() instead. +// In these cases we define SYS_open (which is otherwise undefined) to equal SYS_openat +// (which is defined) so that everywhere else we can call intercept_setup_error(SYS_open) +// without caring about the difference. +// https://chromium.googlesource.com/linux-syscall-support/ +#if !HAVE_DECL_SYS_OPEN && HAVE_DECL_SYS_OPENAT +# define SYS_open SYS_openat +#endif + #endif // !PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE #endif // !INTERCEPT_H -- cgit v1.2.3