Skip to content

Commit

Permalink
Fix intercept of SYS_open on platforms that only have SYS_openat (e.g…
Browse files Browse the repository at this point in the history
…. arm64)
  • Loading branch information
qris committed Jun 19, 2017
1 parent 1f29bc6 commit bd4a300
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions infrastructure/m4/boxbackup_tests.m4
Expand Up @@ -230,6 +230,7 @@ AC_CHECK_DECLS([INFTIM],,, [[#include <poll.h>]])
AC_CHECK_DECLS([SO_PEERCRED],,, [[#include <sys/socket.h>]])
AC_CHECK_DECLS([SOL_TCP],,, [[#include <netinet/tcp.h>]])
AC_CHECK_DECLS([TCP_INFO],,, [[#include <netinet/tcp.h>]])
AC_CHECK_DECLS([SYS_open, SYS_openat],,, [[#include <sys/syscall.h>]])

if test -n "$have_sys_socket_h"; then
AC_CHECK_DECLS([SO_SNDBUF],,, [[#include <sys/socket.h>]])
Expand Down
6 changes: 6 additions & 0 deletions lib/intercept/intercept.cpp
Expand Up @@ -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 &&
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/intercept/intercept.h
Expand Up @@ -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
9 changes: 1 addition & 8 deletions test/raidfile/testraidfile.cpp
Expand Up @@ -25,6 +25,7 @@
#include "RaidFileException.h"
#include "RaidFileRead.h"
#include "Guards.h"
#include "intercept.h"

#include "MemLeakFindOn.h"

Expand All @@ -37,14 +38,6 @@
#define TRF_CAN_INTERCEPT
#endif


#ifdef TRF_CAN_INTERCEPT
// function in intercept.cpp for setting up errors
void intercept_setup_error(const char *filename, unsigned int errorafter, int errortoreturn, int syscalltoerror);
bool intercept_triggered();
void intercept_clear_setup();
#endif

// Nice random data for testing written files
class R250 {
public:
Expand Down

0 comments on commit bd4a300

Please sign in to comment.