stub.h 2.3 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
 * Licensed under the GPL
 */

#ifndef __SYSDEP_STUB_H
#define __SYSDEP_STUB_H

J
Jeff Dike 已提交
9
#include <sys/mman.h>
10 11
#include <asm/unistd.h>
#include <sysdep/ptrace_user.h>
J
Jeff Dike 已提交
12
#include "as-layout.h"
J
Jeff Dike 已提交
13 14 15
#include "stub-data.h"
#include "kern_constants.h"
#include "uml-config.h"
16 17

extern void stub_segv_handler(int sig);
18
extern void stub_clone_handler(void);
19 20 21 22 23

#define STUB_SYSCALL_RET PT_INDEX(RAX)
#define STUB_MMAP_NR __NR_mmap
#define MMAP_OFFSET(o) (o)

24 25 26
#define __syscall_clobber "r11","rcx","memory"
#define __syscall "syscall"

27 28 29 30 31 32 33 34 35 36 37
static inline long stub_syscall0(long syscall)
{
	long ret;

	__asm__ volatile (__syscall
		: "=a" (ret)
		: "0" (syscall) : __syscall_clobber );

	return ret;
}

38 39 40 41
static inline long stub_syscall2(long syscall, long arg1, long arg2)
{
	long ret;

42 43 44 45 46
	__asm__ volatile (__syscall
		: "=a" (ret)
		: "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );

	return ret;
47 48 49 50
}

static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
{
51 52 53 54 55 56 57 58
	long ret;

	__asm__ volatile (__syscall
		: "=a" (ret)
		: "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
		: __syscall_clobber );

	return ret;
59 60 61 62 63
}

static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
				 long arg4)
{
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	long ret;

	__asm__ volatile ("movq %5,%%r10 ; " __syscall
		: "=a" (ret)
		: "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
		  "g" (arg4)
		: __syscall_clobber, "r10" );

	return ret;
}

static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
				 long arg4, long arg5)
{
	long ret;

	__asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
		: "=a" (ret)
		: "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
		  "g" (arg4), "g" (arg5)
		: __syscall_clobber, "r10", "r8" );

	return ret;
87 88
}

J
Jeff Dike 已提交
89
static inline void trap_myself(void)
90
{
J
Jeff Dike 已提交
91
	__asm("int3");
92 93
}

J
Jeff Dike 已提交
94
static inline void remap_stack(long fd, unsigned long offset)
95
{
J
Jeff Dike 已提交
96 97
	__asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; "
			  "movq %6, %%r9; " __syscall "; movq %7, %%rbx ; "
J
Jeff Dike 已提交
98 99 100 101 102
			  "movq %%rax, (%%rbx)":
			  : "a" (STUB_MMAP_NR), "D" (STUB_DATA),
			    "S" (UM_KERN_PAGE_SIZE),
			    "d" (PROT_READ | PROT_WRITE),
                            "g" (MAP_FIXED | MAP_SHARED), "g" (fd),
J
Jeff Dike 已提交
103
			    "g" (offset),
J
Jeff Dike 已提交
104
			    "i" (&((struct stub_data *) STUB_DATA)->err)
J
Jeff Dike 已提交
105
			  : __syscall_clobber, "r10", "r8", "r9" );
106 107
}

108
#endif