Skip to content

Commit

Permalink
i#1569 AArch64: Enable syscall-mod test. (#2388)
Browse files Browse the repository at this point in the history
Port assembly for syscall-mod to AArch64 assembly and enable test.
  • Loading branch information
georges-arm authored May 2, 2017
1 parent 08b4f99 commit 5e98bc1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
5 changes: 4 additions & 1 deletion core/arch/aarch64/instr_create.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@
* \param i The source immediate integer opnd.
*/
#define XINST_CREATE_load_int(dc, r, i) \
INSTR_CREATE_movz((dc), (r), (i), OPND_CREATE_INT(0))
(opnd_get_immed_int(i) < 0 ? \
INSTR_CREATE_movn((dc), (r), OPND_CREATE_INT32(~opnd_get_immed_int(i)), \
OPND_CREATE_INT(0)) : \
INSTR_CREATE_movz((dc), (r), (i), OPND_CREATE_INT(0)))

/**
* This platform-independent macro creates an instr_t for a return instruction.
Expand Down
4 changes: 3 additions & 1 deletion suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1898,8 +1898,10 @@ if (CLIENT_INTERFACE)
tobuild_ci(client.nudge_test client-interface/nudge_test.runall "" "" "")
tobuild_ci(client.timer client-interface/timer.c "" "" "")
endif (NOT ARM)
if (X86) # FIXME i#1551, i#1569: port asm to ARM and AArch64
if (X86 OR AARCH64) # FIXME i#1551: port asm to AArch32
tobuild_ci(client.syscall-mod client-interface/syscall-mod.c "" "" "")
endif (X86 OR AARCH64)
if (X86) # FIXME i#1551, i#1569: port asm to ARM and AArch64
tobuild_ci(client.signal client-interface/signal.c "" "" "")
tobuild_ci(client.cbr-retarget client-interface/cbr-retarget.c "" "" "")
endif (X86)
Expand Down
18 changes: 13 additions & 5 deletions suite/tests/client-interface/syscall-mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
* DAMAGE.
*/

#include "configure.h"

#include <stdio.h>
#if defined(MACOS) || defined(ANDROID)
# include <sys/syscall.h>
Expand All @@ -45,16 +47,22 @@ int main()
{
int pid;
fprintf(stderr, "starting\n");
#if defined(AARCH64)
asm("movz x8, " STRINGIFY(SYS_getpid) ";"
"svc 0;"
"mov %0, x0" : "=r"(pid));
#elif defined(X64)
/* we don't want vsyscall since we rely on mov immed, eax being in same bb.
* plus, libc getpid might cache the pid value.
*/
asm("mov $" STRINGIFY(SYS_getpid) ", %eax");
#ifdef X64
asm("syscall");
asm("mov $" STRINGIFY(SYS_getpid) ", %%eax;"
"syscall;"
"mov %%eax, %0" : "=m"(pid));
#else
asm("int $0x80");
asm("mov $" STRINGIFY(SYS_getpid) ", %%eax;"
"int $0x80;"
"mov %%eax, %0" : "=m"(pid));
#endif
asm("mov %%eax, %0" : "=m"(pid));
fprintf(stderr, "pid = %d\n", pid);

return 0;
Expand Down
26 changes: 19 additions & 7 deletions suite/tests/client-interface/syscall-mod.dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,35 @@

#define MINSERT instrlist_meta_preinsert

#ifdef AARCH64
# define SYSCALL_ARG_REG DR_REG_X8
# define SYSCALL_RES_REG DR_REG_X0
#else
# define SYSCALL_ARG_REG REG_EAX
# define SYSCALL_RES_REG REG_EAX
#endif

static
dr_emit_flags_t bb_event(void* drcontext, void *tag, instrlist_t* bb,
bool for_trace, bool translating)
{
instr_t *instr;
instr_t *next_instr;
reg_t in_eax = -1;
ptr_int_t value;
reg_t in_reg = -1;

for (instr = instrlist_first(bb); instr != NULL; instr = next_instr) {
next_instr = instr_get_next(instr);
if (instr_get_opcode(instr) == OP_mov_imm &&
opnd_get_reg(instr_get_dst(instr, 0)) == REG_EAX)
in_eax = opnd_get_immed_int(instr_get_src(instr, 0));
if (instr_is_mov_constant(instr, &value) &&
opnd_is_reg(instr_get_dst(instr, 0)) &&
opnd_get_reg(instr_get_dst(instr, 0)) == SYSCALL_ARG_REG &&
opnd_is_immed_int(instr_get_src(instr, 0)))
in_reg = opnd_get_immed_int(instr_get_src(instr, 0));
if (instr_is_syscall(instr) &&
in_eax == SYS_getpid) {
instr_t *myval = INSTR_CREATE_mov_imm
(drcontext, opnd_create_reg(REG_EAX), OPND_CREATE_INT32(-7));
in_reg == SYS_getpid) {
instr_t *myval = XINST_CREATE_load_int
(drcontext, opnd_create_reg(SYSCALL_RES_REG),
OPND_CREATE_INT32(-7));
instr_set_translation(myval, instr_get_app_pc(instr));
instrlist_preinsert(bb, instr, myval);
instrlist_remove(bb, instr);
Expand Down

0 comments on commit 5e98bc1

Please sign in to comment.