Skip to content

Commit

Permalink
i#6406: Import syscall_linux header file based on the target architec…
Browse files Browse the repository at this point in the history
…ture. (#6407)

raw2trace_t::is_maybe_blocking_syscall() depends on the definitions of
SYS_xxx to determine if the syscall may be blocking or not.

core/unix/include/syscall.h imports syscall_linux_xxx header file based
on the host architecture. For cross platform support, the
syscall_linux_xxx header file should be imported based on the target
architecture.

Fixes: i6406
  • Loading branch information
ivankyluk authored Nov 10, 2023
1 parent 73ce8ae commit 969e20d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
55 changes: 54 additions & 1 deletion clients/drcachesim/tests/raw2trace_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ class raw2trace_test_t : public raw2trace_t {
std::unique_ptr<module_mapper_t>(new test_multi_module_mapper_t(modules));
set_modmap_(module_mapper_.get());
}
// The public function to access the raw2trace_t protected function
// is_maybe_blocking_syscall.
bool
is_maybe_blocking_syscall(uintptr_t number) override
{
return raw2trace_t::is_maybe_blocking_syscall(number);
}
};

class archive_ostream_test_t : public archive_ostream_t {
Expand Down Expand Up @@ -2599,6 +2606,51 @@ test_stats_timestamp_instr_count(void *drcontext)
stats[RAW2TRACE_STAT_LATEST_TRACE_TIMESTAMP] == 789;
}

bool
test_is_maybe_blocking_syscall(void *drcontext)
{
std::cerr
<< "\n===============\nTesting raw2trace maybe blocking syscall function.\n";
#ifdef LINUX
# ifdef X86
# ifdef X64
const uintptr_t syscall_futex = 202;
const uintptr_t syscall_sendmsg = 46;
const uintptr_t syscall_write = 1;
# else
const uintptr_t syscall_futex = 240;
const uintptr_t syscall_sendmsg = 370;
const uintptr_t syscall_write = 4;
# endif
# elif defined(ARM)
const uintptr_t syscall_futex = 240;
const uintptr_t syscall_sendmsg = 296;
const uintptr_t syscall_write = 4;
# elif defined(AARCH64) || defined(RISCV64)
const uintptr_t syscall_futex = 98;
const uintptr_t syscall_sendmsg = 211;
const uintptr_t syscall_write = 64;
# else
# error Unsupported architecture.
# endif
std::vector<std::istream *> input;
std::vector<std::ostream *> output;
const std::vector<test_multi_module_mapper_t::bounds_t> modules;

raw2trace_test_t raw2trace(input, output, modules, drcontext);

for (const uintptr_t &syscall : { syscall_futex, syscall_sendmsg, syscall_write }) {
if (!raw2trace.is_maybe_blocking_syscall(syscall)) {
std::cerr << "Syscall " << syscall
<< " should be marked as maybe blocking.\n";
return false;
}
}
return true;
#endif
return true;
}

int
test_main(int argc, const char *argv[])
{
Expand All @@ -2616,7 +2668,8 @@ test_main(int argc, const char *argv[])
!test_rseq_side_exit_inverted_with_timestamp(drcontext) ||
!test_xfer_modoffs(drcontext) || !test_xfer_absolute(drcontext) ||
!test_branch_decoration(drcontext) ||
!test_stats_timestamp_instr_count(drcontext))
!test_stats_timestamp_instr_count(drcontext) ||
!test_is_maybe_blocking_syscall(drcontext))
return 1;
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion clients/drcachesim/tracer/raw2trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "utils.h"
#ifdef LINUX
// XXX: We should have the core export this to an include dir.
# include "../../core/unix/include/syscall.h"
# include "../../core/unix/include/syscall_target.h"
#endif
#ifdef BUILD_PT_POST_PROCESSOR
# include <unistd.h>
Expand Down
21 changes: 21 additions & 0 deletions core/unix/include/syscall_target.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _SYSCALL_TARGET_H_
#define _SYSCALL_TARGET_H_ 1

/* Do not include this on MacOS as you'll get the wrong numbers! */
#ifndef LINUX
# error Only use this file on Linux
#endif

#ifdef X86
# include "../../core/unix/include/syscall_linux_x86.h"
#elif defined(ARM)
# include "../../core/unix/include/syscall_linux_arm.h"
#elif defined(AARCH64)
# include "../../core/unix/include/syscall_linux_uapi.h"
#elif defined(RISCV64)
# include "../../core/unix/include/syscall_linux_riscv64.h"
#else
# error Unknown platform.
#endif

#endif /* _SYSCALL_TARGET_H_ */

0 comments on commit 969e20d

Please sign in to comment.