18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com) 38c2ecf20Sopenharmony_ci * Licensed under the GPL 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __SYSDEP_STUB_H 78c2ecf20Sopenharmony_ci#define __SYSDEP_STUB_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <sysdep/ptrace_user.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define STUB_SYSCALL_RET PT_INDEX(RAX) 128c2ecf20Sopenharmony_ci#define STUB_MMAP_NR __NR_mmap 138c2ecf20Sopenharmony_ci#define MMAP_OFFSET(o) (o) 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define __syscall_clobber "r11","rcx","memory" 168c2ecf20Sopenharmony_ci#define __syscall "syscall" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistatic inline long stub_syscall0(long syscall) 198c2ecf20Sopenharmony_ci{ 208c2ecf20Sopenharmony_ci long ret; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci __asm__ volatile (__syscall 238c2ecf20Sopenharmony_ci : "=a" (ret) 248c2ecf20Sopenharmony_ci : "0" (syscall) : __syscall_clobber ); 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci return ret; 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistatic inline long stub_syscall2(long syscall, long arg1, long arg2) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci long ret; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci __asm__ volatile (__syscall 348c2ecf20Sopenharmony_ci : "=a" (ret) 358c2ecf20Sopenharmony_ci : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber ); 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci return ret; 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci long ret; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci __asm__ volatile (__syscall 458c2ecf20Sopenharmony_ci : "=a" (ret) 468c2ecf20Sopenharmony_ci : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3) 478c2ecf20Sopenharmony_ci : __syscall_clobber ); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci return ret; 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, 538c2ecf20Sopenharmony_ci long arg4) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci long ret; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci __asm__ volatile ("movq %5,%%r10 ; " __syscall 588c2ecf20Sopenharmony_ci : "=a" (ret) 598c2ecf20Sopenharmony_ci : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3), 608c2ecf20Sopenharmony_ci "g" (arg4) 618c2ecf20Sopenharmony_ci : __syscall_clobber, "r10" ); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci return ret; 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3, 678c2ecf20Sopenharmony_ci long arg4, long arg5) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci long ret; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall 728c2ecf20Sopenharmony_ci : "=a" (ret) 738c2ecf20Sopenharmony_ci : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3), 748c2ecf20Sopenharmony_ci "g" (arg4), "g" (arg5) 758c2ecf20Sopenharmony_ci : __syscall_clobber, "r10", "r8" ); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci return ret; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic inline void trap_myself(void) 818c2ecf20Sopenharmony_ci{ 828c2ecf20Sopenharmony_ci __asm("int3"); 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistatic inline void remap_stack(long fd, unsigned long offset) 868c2ecf20Sopenharmony_ci{ 878c2ecf20Sopenharmony_ci __asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; " 888c2ecf20Sopenharmony_ci "movq %6, %%r9; " __syscall "; movq %7, %%rbx ; " 898c2ecf20Sopenharmony_ci "movq %%rax, (%%rbx)": 908c2ecf20Sopenharmony_ci : "a" (STUB_MMAP_NR), "D" (STUB_DATA), 918c2ecf20Sopenharmony_ci "S" (UM_KERN_PAGE_SIZE), 928c2ecf20Sopenharmony_ci "d" (PROT_READ | PROT_WRITE), 938c2ecf20Sopenharmony_ci "g" (MAP_FIXED | MAP_SHARED), "g" (fd), 948c2ecf20Sopenharmony_ci "g" (offset), 958c2ecf20Sopenharmony_ci "i" (&((struct stub_data *) STUB_DATA)->err) 968c2ecf20Sopenharmony_ci : __syscall_clobber, "r10", "r8", "r9" ); 978c2ecf20Sopenharmony_ci} 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#endif 100