Path: blob/master/arch/um/sys-x86_64/shared/sysdep/stub.h
10820 views
/*1* Copyright (C) 2004 Jeff Dike ([email protected])2* Licensed under the GPL3*/45#ifndef __SYSDEP_STUB_H6#define __SYSDEP_STUB_H78#include <sys/mman.h>9#include <asm/unistd.h>10#include <sysdep/ptrace_user.h>11#include "as-layout.h"12#include "stub-data.h"13#include "kern_constants.h"1415extern void stub_segv_handler(int sig);16extern void stub_clone_handler(void);1718#define STUB_SYSCALL_RET PT_INDEX(RAX)19#define STUB_MMAP_NR __NR_mmap20#define MMAP_OFFSET(o) (o)2122#define __syscall_clobber "r11","rcx","memory"23#define __syscall "syscall"2425static inline long stub_syscall0(long syscall)26{27long ret;2829__asm__ volatile (__syscall30: "=a" (ret)31: "0" (syscall) : __syscall_clobber );3233return ret;34}3536static inline long stub_syscall2(long syscall, long arg1, long arg2)37{38long ret;3940__asm__ volatile (__syscall41: "=a" (ret)42: "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );4344return ret;45}4647static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)48{49long ret;5051__asm__ volatile (__syscall52: "=a" (ret)53: "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)54: __syscall_clobber );5556return ret;57}5859static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,60long arg4)61{62long ret;6364__asm__ volatile ("movq %5,%%r10 ; " __syscall65: "=a" (ret)66: "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),67"g" (arg4)68: __syscall_clobber, "r10" );6970return ret;71}7273static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,74long arg4, long arg5)75{76long ret;7778__asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall79: "=a" (ret)80: "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),81"g" (arg4), "g" (arg5)82: __syscall_clobber, "r10", "r8" );8384return ret;85}8687static inline void trap_myself(void)88{89__asm("int3");90}9192static inline void remap_stack(long fd, unsigned long offset)93{94__asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; "95"movq %6, %%r9; " __syscall "; movq %7, %%rbx ; "96"movq %%rax, (%%rbx)":97: "a" (STUB_MMAP_NR), "D" (STUB_DATA),98"S" (UM_KERN_PAGE_SIZE),99"d" (PROT_READ | PROT_WRITE),100"g" (MAP_FIXED | MAP_SHARED), "g" (fd),101"g" (offset),102"i" (&((struct stub_data *) STUB_DATA)->err)103: __syscall_clobber, "r10", "r8", "r9" );104}105106#endif107108109