Skip to content

i#7835: Add a helper function for creating syscall instruction in tests#7862

Open
bin-wang wants to merge 8 commits intomasterfrom
i7835-syscall-test-helper
Open

i#7835: Add a helper function for creating syscall instruction in tests#7862
bin-wang wants to merge 8 commits intomasterfrom
i7835-syscall-test-helper

Conversation

@bin-wang
Copy link
Copy Markdown
Contributor

@bin-wang bin-wang commented Apr 17, 2026

This PR introduces a helper function (create_test_syscall()) to reduce repeated code for creating a simple syscall instruction in unit tests. I created new test_helpers_syscall.h/cpp to put this helper function in.

Alternatives considered:

  1. Put the declaration and definition of this help function in existing test_helpers.h/cpp. This way we don't need to add new files, however there are 2 drawbacks: 1). test_helpers (and therefore tests that use test_helpers) now need to be linked against drdecode. 2) We probably need to change the unsupported architecture error from a compile time error to runtime error, because we want be able to compile other tests on those architectures.

  2. Declare the helper function in test_helpers.h, define it in test_helpers_syscall.cpp. This is pretty much the same as what's currently implemented, just one less header file.

Fixes #7835

@bin-wang bin-wang requested a review from derekbruening April 18, 2026 08:07
// XXX: Adding an XINST_CREATE_syscall macro will simplify this but there are
// 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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor repeated code for creating syscalls in raw2trace and invariant checker tests.

2 participants