diff options
Diffstat (limited to 'arch/um/include')
-rw-r--r-- | arch/um/include/chan_user.h | 4 | ||||
-rw-r--r-- | arch/um/include/sysdep-i386/stub.h | 38 | ||||
-rw-r--r-- | arch/um/include/sysdep-x86_64/stub.h | 42 | ||||
-rw-r--r-- | arch/um/include/um_uaccess.h | 21 |
4 files changed, 75 insertions, 30 deletions
diff --git a/arch/um/include/chan_user.h b/arch/um/include/chan_user.h index f77d9aa4c16..659bb3cac32 100644 --- a/arch/um/include/chan_user.h +++ b/arch/um/include/chan_user.h @@ -25,7 +25,7 @@ struct chan_ops { void (*close)(int, void *); int (*read)(int, char *, void *); int (*write)(int, const char *, int, void *); - int (*console_write)(int, const char *, int, void *); + int (*console_write)(int, const char *, int); int (*window_size)(int, void *, unsigned short *, unsigned short *); void (*free)(void *); int winch; @@ -37,7 +37,7 @@ extern struct chan_ops fd_ops, null_ops, port_ops, pts_ops, pty_ops, tty_ops, extern void generic_close(int fd, void *unused); extern int generic_read(int fd, char *c_out, void *unused); extern int generic_write(int fd, const char *buf, int n, void *unused); -extern int generic_console_write(int fd, const char *buf, int n, void *state); +extern int generic_console_write(int fd, const char *buf, int n); extern int generic_window_size(int fd, void *unused, unsigned short *rows_out, unsigned short *cols_out); extern void generic_free(void *data); diff --git a/arch/um/include/sysdep-i386/stub.h b/arch/um/include/sysdep-i386/stub.h index a49ceb199ee..b492b12b4a1 100644 --- a/arch/um/include/sysdep-i386/stub.h +++ b/arch/um/include/sysdep-i386/stub.h @@ -6,8 +6,12 @@ #ifndef __SYSDEP_STUB_H #define __SYSDEP_STUB_H +#include <sys/mman.h> #include <asm/ptrace.h> #include <asm/unistd.h> +#include "stub-data.h" +#include "kern_constants.h" +#include "uml-config.h" extern void stub_segv_handler(int sig); extern void stub_clone_handler(void); @@ -16,6 +20,15 @@ extern void stub_clone_handler(void); #define STUB_MMAP_NR __NR_mmap2 #define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT) +static inline long stub_syscall0(long syscall) +{ + long ret; + + __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall)); + + return ret; +} + static inline long stub_syscall1(long syscall, long arg1) { long ret; @@ -67,23 +80,22 @@ static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3, return ret; } -static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, - long arg4, long arg5, long arg6) +static inline void trap_myself(void) { - long ret; - - __asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; " - "int $0x80 ; pop %%ebp" - : "=a" (ret) - : "g" (syscall), "b" (arg1), "c" (arg2), "d" (arg3), - "S" (arg4), "D" (arg5), "0" (arg6)); - - return ret; + __asm("int3"); } -static inline void trap_myself(void) +static inline void remap_stack(int fd, unsigned long offset) { - __asm("int3"); + __asm__ volatile ("movl %%eax,%%ebp ; movl %0,%%eax ; int $0x80 ;" + "movl %7, %%ebx ; movl %%eax, (%%ebx)" + : : "g" (STUB_MMAP_NR), "b" (UML_CONFIG_STUB_DATA), + "c" (UM_KERN_PAGE_SIZE), + "d" (PROT_READ | PROT_WRITE), + "S" (MAP_FIXED | MAP_SHARED), "D" (fd), + "a" (offset), + "i" (&((struct stub_data *) UML_CONFIG_STUB_DATA)->err) + : "memory"); } #endif diff --git a/arch/um/include/sysdep-x86_64/stub.h b/arch/um/include/sysdep-x86_64/stub.h index 2bd6e7a9728..92e989f8176 100644 --- a/arch/um/include/sysdep-x86_64/stub.h +++ b/arch/um/include/sysdep-x86_64/stub.h @@ -6,9 +6,12 @@ #ifndef __SYSDEP_STUB_H #define __SYSDEP_STUB_H -#include <asm/ptrace.h> +#include <sys/mman.h> #include <asm/unistd.h> #include <sysdep/ptrace_user.h> +#include "stub-data.h" +#include "kern_constants.h" +#include "uml-config.h" extern void stub_segv_handler(int sig); extern void stub_clone_handler(void); @@ -20,6 +23,17 @@ extern void stub_clone_handler(void); #define __syscall_clobber "r11","rcx","memory" #define __syscall "syscall" +static inline long stub_syscall0(long syscall) +{ + long ret; + + __asm__ volatile (__syscall + : "=a" (ret) + : "0" (syscall) : __syscall_clobber ); + + return ret; +} + static inline long stub_syscall2(long syscall, long arg1, long arg2) { long ret; @@ -71,23 +85,23 @@ static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3, return ret; } -static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, - long arg4, long arg5, long arg6) +static inline void trap_myself(void) { - long ret; - - __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " - "movq %7, %%r9; " __syscall : "=a" (ret) - : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3), - "g" (arg4), "g" (arg5), "g" (arg6) - : __syscall_clobber, "r10", "r8", "r9" ); - - return ret; + __asm("int3"); } -static inline void trap_myself(void) +static inline void remap_stack(long fd, unsigned long offset) { - __asm("int3"); + __asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; " + "movq %6, %%r9; " __syscall "; movq %7, %%rbx ; " + "movq %%rax, (%%rbx)": + : "a" (STUB_MMAP_NR), "D" (UML_CONFIG_STUB_DATA), + "S" (UM_KERN_PAGE_SIZE), + "d" (PROT_READ | PROT_WRITE), + "g" (MAP_FIXED | MAP_SHARED), "g" (fd), + "g" (offset), + "i" (&((struct stub_data *) UML_CONFIG_STUB_DATA)->err) + : __syscall_clobber, "r10", "r8", "r9" ); } #endif diff --git a/arch/um/include/um_uaccess.h b/arch/um/include/um_uaccess.h index 84c0868cd56..4567f1eeb4a 100644 --- a/arch/um/include/um_uaccess.h +++ b/arch/um/include/um_uaccess.h @@ -17,8 +17,27 @@ #include "uaccess-skas.h" #endif +#include "asm/fixmap.h" + +#define __under_task_size(addr, size) \ + (((unsigned long) (addr) < TASK_SIZE) && \ + (((unsigned long) (addr) + (size)) < TASK_SIZE)) + +#define __access_ok_vsyscall(type, addr, size) \ + ((type == VERIFY_READ) && \ + ((unsigned long) (addr) >= FIXADDR_USER_START) && \ + ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \ + ((unsigned long) (addr) + (size) >= (unsigned long)(addr))) + +#define __addr_range_nowrap(addr, size) \ + ((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) + #define access_ok(type, addr, size) \ - CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size) + (__addr_range_nowrap(addr, size) && \ + (__under_task_size(addr, size) || \ + __access_ok_vsyscall(type, addr, size) || \ + segment_eq(get_fs(), KERNEL_DS) || \ + CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size))) static inline int copy_from_user(void *to, const void __user *from, int n) { |