Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ if (BUILD_TESTS)

# XXX i#3544 Make raw2trace_unit_tests compilable in RISCV64.
if (NOT RISCV64)
add_executable(tool.drcacheoff.raw2trace_unit_tests tests/raw2trace_unit_tests.cpp)
add_executable(tool.drcacheoff.raw2trace_unit_tests tests/raw2trace_unit_tests.cpp tests/test_helpers_syscall.cpp)
configure_DynamoRIO_standalone(tool.drcacheoff.raw2trace_unit_tests)
add_win32_flags(tool.drcacheoff.raw2trace_unit_tests ON)
target_link_libraries(tool.drcacheoff.raw2trace_unit_tests drmemtrace_raw2trace
Expand Down Expand Up @@ -1054,7 +1054,7 @@ if (BUILD_TESTS)
set_tests_properties(tool.drcachesim.miss_analyzer_unit_test PROPERTIES
TIMEOUT ${test_seconds})

add_executable(tool.drcachesim.invariant_checker_test tests/invariant_checker_test.cpp)
add_executable(tool.drcachesim.invariant_checker_test tests/invariant_checker_test.cpp tests/test_helpers_syscall.cpp)
configure_DynamoRIO_standalone(tool.drcachesim.invariant_checker_test)
add_win32_flags(tool.drcachesim.invariant_checker_test ON)
target_link_libraries(tool.drcachesim.invariant_checker_test
Expand Down
27 changes: 3 additions & 24 deletions clients/drcachesim/tests/invariant_checker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "../common/memref.h"
#include "memref_gen.h"
#include "trace_entry.h"
#include "test_helpers_syscall.h"

#ifdef LINUX
# include "../../core/unix/include/syscall_target.h"
Expand Down Expand Up @@ -1719,18 +1720,7 @@ check_syscalls()
// checks do not currently work properly there.
return true;
#else
// XXX: Just like raw2trace_unit_tests, we need to create a syscall instruction
// and it turns out there is no simple cross-platform way.
# ifdef X86
instr_t *sys = INSTR_CREATE_syscall(GLOBAL_DCONTEXT);
# elif defined(AARCHXX)
instr_t *sys =
INSTR_CREATE_svc(GLOBAL_DCONTEXT, opnd_create_immed_int((sbyte)0x0, OPSZ_1));
# elif defined(RISCV64)
instr_t *sys = INSTR_CREATE_ecall(GLOBAL_DCONTEXT);
# else
# error Unsupported architecture.
# endif
instr_t *sys = create_test_syscall(GLOBAL_DCONTEXT);
instr_t *move1 =
XINST_CREATE_move(GLOBAL_DCONTEXT, opnd_create_reg(REG1), opnd_create_reg(REG2));
instrlist_t *ilist = instrlist_create(GLOBAL_DCONTEXT);
Expand Down Expand Up @@ -3458,18 +3448,7 @@ check_kernel_syscall_trace(void)
// checks do not currently work properly there.
return true;
#else
// XXX: Just like raw2trace_unit_tests, we need to create a syscall instruction
// and it turns out there is no simple cross-platform way.
# ifdef X86
instr_t *sys = INSTR_CREATE_syscall(GLOBAL_DCONTEXT);
# elif defined(AARCHXX)
instr_t *sys =
INSTR_CREATE_svc(GLOBAL_DCONTEXT, opnd_create_immed_int((sbyte)0x0, OPSZ_1));
# elif defined(RISCV64)
instr_t *sys = INSTR_CREATE_ecall(GLOBAL_DCONTEXT);
# else
# error Unsupported architecture.
# endif
instr_t *sys = create_test_syscall(GLOBAL_DCONTEXT);
instr_t *sys_return;
# ifdef X86
sys_return = INSTR_CREATE_sysret(GLOBAL_DCONTEXT);
Expand Down
49 changes: 5 additions & 44 deletions clients/drcachesim/tests/raw2trace_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "tracer/raw2trace.h"
#include "tracer/raw2trace_directory.h"
#include "test_helpers.h"
#include "test_helpers_syscall.h"
#include <iostream>
#include <sstream>

Expand Down Expand Up @@ -1063,17 +1064,7 @@ test_duplicate_syscalls(void *drcontext)
instr_t *nop = XINST_CREATE_nop(drcontext);
instr_t *move1 =
XINST_CREATE_move(drcontext, opnd_create_reg(REG1), opnd_create_reg(REG2));
// XXX: Adding an XINST_CREATE_syscall macro will simplify this but there are
// complexities (xref create_syscall_instr()).
#ifdef X86
instr_t *sys = INSTR_CREATE_syscall(drcontext);
#elif defined(AARCHXX)
instr_t *sys = INSTR_CREATE_svc(drcontext, opnd_create_immed_int((sbyte)0x0, OPSZ_1));
#elif defined(RISCV64)
instr_t *sys = INSTR_CREATE_ecall(drcontext);
#else
# error Unsupported architecture.
#endif
instr_t *sys = create_test_syscall(drcontext);
#ifdef X86_32
unsigned short expected_syscall_instr_type = TRACE_TYPE_INSTR_SYSENTER;
#else
Expand Down Expand Up @@ -1170,17 +1161,7 @@ test_false_syscalls(void *drcontext)
instr_t *nop = XINST_CREATE_nop(drcontext);
instr_t *move1 =
XINST_CREATE_move(drcontext, opnd_create_reg(REG1), opnd_create_reg(REG2));
// XXX: Adding an XINST_CREATE_syscall macro will simplify this but there are
// complexities (xref create_syscall_instr()).
# ifdef X86
instr_t *sys = INSTR_CREATE_syscall(drcontext);
# elif defined(AARCHXX)
instr_t *sys = INSTR_CREATE_svc(drcontext, opnd_create_immed_int((sbyte)0x0, OPSZ_1));
# elif defined(RISCV64)
instr_t *sys = INSTR_CREATE_ecall(drcontext);
# else
# error Unsupported architecture.
# endif
instr_t *sys = create_test_syscall(drcontext);
# ifdef X86_32
unsigned short expected_syscall_instr_type = TRACE_TYPE_INSTR_SYSENTER;
# else
Expand Down Expand Up @@ -1285,17 +1266,7 @@ test_syscall_with_interleaving_markers(void *drcontext)
instr_t *nop = XINST_CREATE_nop(drcontext);
instr_t *move1 =
XINST_CREATE_move(drcontext, opnd_create_reg(REG1), opnd_create_reg(REG2));
// XXX: Adding an XINST_CREATE_syscall macro will simplify this but there are
// complexities (xref create_syscall_instr()).
# ifdef X86
instr_t *sys = INSTR_CREATE_syscall(drcontext);
# elif defined(AARCHXX)
instr_t *sys = INSTR_CREATE_svc(drcontext, opnd_create_immed_int((sbyte)0x0, OPSZ_1));
# elif defined(RISCV64)
instr_t *sys = INSTR_CREATE_ecall(drcontext);
# else
# error Unsupported architecture.
# endif
instr_t *sys = create_test_syscall(drcontext);
# ifdef X86_32
unsigned short expected_syscall_instr_type = TRACE_TYPE_INSTR_SYSENTER;
# else
Expand Down Expand Up @@ -3646,17 +3617,7 @@ test_syscall_injection(void *drcontext)
instr_t *nop = XINST_CREATE_nop(drcontext);
instr_t *move1 =
XINST_CREATE_move(drcontext, opnd_create_reg(REG1), opnd_create_reg(REG2));
// XXX: Adding an XINST_CREATE_syscall macro will simplify this but there are
// complexities (xref create_syscall_instr()).
#ifdef X86
instr_t *sys = INSTR_CREATE_syscall(drcontext);
#elif defined(AARCHXX)
instr_t *sys = INSTR_CREATE_svc(drcontext, opnd_create_immed_int((sbyte)0x0, OPSZ_1));
#elif defined(RISCV64)
instr_t *sys = INSTR_CREATE_ecall(drcontext);
#else
# error Unsupported architecture.
#endif
instr_t *sys = create_test_syscall(drcontext);
#ifdef X86_32
unsigned short expected_syscall_instr_type = TRACE_TYPE_INSTR_SYSENTER;
#else
Expand Down
55 changes: 55 additions & 0 deletions clients/drcachesim/tests/test_helpers_syscall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* **********************************************************
* Copyright (c) 2026 Google, Inc. All rights reserved.
* **********************************************************/
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Google, Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE, INC. OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/

#include "test_helpers_syscall.h"
#include "dr_api.h"

namespace dynamorio {
namespace drmemtrace {

instr_t *
create_test_syscall(void *drcontext)
{
// XXX: Adding an XINST_CREATE_syscall macro will simplify this but there are

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should just add XINST_CREATE_syscall in the ir instr_create_api files, with comments clearly explaining what it does and what its limitations are (maybe hardcode as sysenter for x86_32 define and syscall for x86_64 (though we want to get away from ifdefs in the IR for better cross-arch support: #1684); maybe no WOW64 support). That should help multiple other use cases outside of drmemtrace as well.

// complexities (xref create_syscall_instr()).
#ifdef X86
return INSTR_CREATE_syscall(drcontext);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OP_syscall is not supported on 32-bit Intel so this won't work for a test that needs to execute this instruction, which should be documented for a shared function. But, better to use sysenter I would think.

#elif defined(AARCHXX)
return INSTR_CREATE_svc(drcontext, opnd_create_immed_int((sbyte)0x0, OPSZ_1));
#elif defined(RISCV64)
return INSTR_CREATE_ecall(drcontext);
#else
# error Unsupported architecture.
#endif
}

} // namespace drmemtrace
} // namespace dynamorio
46 changes: 46 additions & 0 deletions clients/drcachesim/tests/test_helpers_syscall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* **********************************************************
* Copyright (c) 2026 Google, Inc. All rights reserved.
* **********************************************************/
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Google, Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE, INC. OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/

#ifndef _TEST_HELPERS_SYSCALL_H_
#define _TEST_HELPERS_SYSCALL_H_

#include "dr_api.h"

namespace dynamorio {
namespace drmemtrace {

instr_t *
create_test_syscall(void *drcontext);

} // namespace drmemtrace
} // namespace dynamorio

#endif /* _TEST_HELPERS_SYSCALL_H_ */
Loading