Commit f45d9fc9 authored by Gennady Sharapov's avatar Gennady Sharapov Committed by Linus Torvalds

[PATCH] uml: move libc-dependent skas memory mapping code

The serial UML OS-abstraction layer patch (um/kernel/skas dir).

This moves all systemcalls from skas/mem_user.c file under os-Linux dir and
join skas/mem_user.c and skas/mem.c files.
Signed-off-by: default avatarGennady Sharapov <gennady.v.sharapov@intel.com>
Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 4abfbf40
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "../os/include/file.h" #include "../os/include/file.h"
#include "sysdep/ptrace.h" #include "sysdep/ptrace.h"
#include "kern_util.h" #include "kern_util.h"
#include "skas/mm_id.h"
#define OS_TYPE_FILE 1 #define OS_TYPE_FILE 1
#define OS_TYPE_DIR 2 #define OS_TYPE_DIR 2
...@@ -255,4 +256,20 @@ extern void user_time_init(void); ...@@ -255,4 +256,20 @@ extern void user_time_init(void);
extern void uml_idle_timer(void); extern void uml_idle_timer(void);
extern unsigned long long os_nsecs(void); extern unsigned long long os_nsecs(void);
/* skas/mem.c */
extern long run_syscall_stub(struct mm_id * mm_idp,
int syscall, unsigned long *args, long expected,
void **addr, int done);
extern long syscall_stub_data(struct mm_id * mm_idp,
unsigned long *data, int data_count,
void **addr, void **stub_addr);
extern int map(struct mm_id * mm_idp, unsigned long virt,
unsigned long len, int r, int w, int x, int phys_fd,
unsigned long long offset, int done, void **data);
extern int unmap(struct mm_id * mm_idp, void *addr, unsigned long len,
int done, void **data);
extern int protect(struct mm_id * mm_idp, unsigned long addr,
unsigned long len, int r, int w, int x, int done,
void **data);
#endif #endif
...@@ -24,14 +24,6 @@ extern void userspace(union uml_pt_regs *regs); ...@@ -24,14 +24,6 @@ extern void userspace(union uml_pt_regs *regs);
extern void new_thread_proc(void *stack, void (*handler)(int sig)); extern void new_thread_proc(void *stack, void (*handler)(int sig));
extern void new_thread_handler(int sig); extern void new_thread_handler(int sig);
extern void handle_syscall(union uml_pt_regs *regs); extern void handle_syscall(union uml_pt_regs *regs);
extern int map(struct mm_id * mm_idp, unsigned long virt,
unsigned long len, int r, int w, int x, int phys_fd,
unsigned long long offset, int done, void **data);
extern int unmap(struct mm_id * mm_idp, void *addr, unsigned long len,
int done, void **data);
extern int protect(struct mm_id * mm_idp, unsigned long addr,
unsigned long len, int r, int w, int x, int done,
void **data);
extern void user_signal(int sig, union uml_pt_regs *regs, int pid); extern void user_signal(int sig, union uml_pt_regs *regs, int pid);
extern int new_mm(unsigned long stack); extern int new_mm(unsigned long stack);
extern int start_userspace(unsigned long stub_stack); extern int start_userspace(unsigned long stub_stack);
...@@ -39,11 +31,5 @@ extern int copy_context_skas0(unsigned long stack, int pid); ...@@ -39,11 +31,5 @@ extern int copy_context_skas0(unsigned long stack, int pid);
extern void get_skas_faultinfo(int pid, struct faultinfo * fi); extern void get_skas_faultinfo(int pid, struct faultinfo * fi);
extern long execute_syscall_skas(void *r); extern long execute_syscall_skas(void *r);
extern unsigned long current_stub_stack(void); extern unsigned long current_stub_stack(void);
extern long run_syscall_stub(struct mm_id * mm_idp,
int syscall, unsigned long *args, long expected,
void **addr, int done);
extern long syscall_stub_data(struct mm_id * mm_idp,
unsigned long *data, int data_count,
void **addr, void **stub_addr);
#endif #endif
# #
# Copyright (C) 2002 - 2004 Jeff Dike (jdike@addtoit.com) # Copyright (C) 2002 - 2004 Jeff Dike (jdike@addtoit.com)
# Licensed under the GPL # Licensed under the GPL
# #
obj-y := clone.o exec_kern.o mem.o mem_user.o mmu.o process.o process_kern.o \ obj-y := clone.o exec_kern.o mem.o mmu.o process.o process_kern.o \
syscall.o tlb.o uaccess.o syscall.o tlb.o uaccess.o
USER_OBJS := process.o clone.o USER_OBJS := process.o clone.o
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
# Licensed under the GPL # Licensed under the GPL
# #
obj-y := trap.o obj-y := mem.o trap.o
USER_OBJS := trap.o USER_OBJS := mem.o trap.o
include arch/um/scripts/Makefile.rules include arch/um/scripts/Makefile.rules
/* /*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com) * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
...@@ -32,7 +32,7 @@ extern void wait_stub_done(int pid, int sig, char * fname); ...@@ -32,7 +32,7 @@ extern void wait_stub_done(int pid, int sig, char * fname);
static inline unsigned long *check_init_stack(struct mm_id * mm_idp, static inline unsigned long *check_init_stack(struct mm_id * mm_idp,
unsigned long *stack) unsigned long *stack)
{ {
if(stack == NULL){ if(stack == NULL) {
stack = (unsigned long *) mm_idp->stack + 2; stack = (unsigned long *) mm_idp->stack + 2;
*stack = 0; *stack = 0;
} }
...@@ -45,13 +45,14 @@ int single_count = 0; ...@@ -45,13 +45,14 @@ int single_count = 0;
int multi_count = 0; int multi_count = 0;
int multi_op_count = 0; int multi_op_count = 0;
static long do_syscall_stub(struct mm_id *mm_idp, void **addr) static inline long do_syscall_stub(struct mm_id * mm_idp, void **addr)
{ {
unsigned long regs[MAX_REG_NR]; unsigned long regs[MAX_REG_NR];
unsigned long *data; int n;
unsigned long *syscall;
long ret, offset; long ret, offset;
int n, pid = mm_idp->u.pid; unsigned long * data;
unsigned long * syscall;
int pid = mm_idp->u.pid;
if(proc_mm) if(proc_mm)
#warning Need to look up userspace_pid by cpu #warning Need to look up userspace_pid by cpu
...@@ -59,10 +60,11 @@ static long do_syscall_stub(struct mm_id *mm_idp, void **addr) ...@@ -59,10 +60,11 @@ static long do_syscall_stub(struct mm_id *mm_idp, void **addr)
multi_count++; multi_count++;
get_safe_registers(regs); get_safe_registers(regs);
regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE + regs[REGS_IP_INDEX] = UML_CONFIG_STUB_CODE +
((unsigned long) &batch_syscall_stub - ((unsigned long) &batch_syscall_stub -
(unsigned long) &__syscall_stub_start); (unsigned long) &__syscall_stub_start);
n = ptrace_setregs(pid, regs); n = ptrace_setregs(pid, regs);
if(n < 0) if(n < 0)
panic("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n", panic("do_syscall_stub : PTRACE_SETREGS failed, errno = %d\n",
...@@ -80,6 +82,8 @@ static long do_syscall_stub(struct mm_id *mm_idp, void **addr) ...@@ -80,6 +82,8 @@ static long do_syscall_stub(struct mm_id *mm_idp, void **addr)
if (offset) { if (offset) {
data = (unsigned long *)(mm_idp->stack + data = (unsigned long *)(mm_idp->stack +
offset - UML_CONFIG_STUB_DATA); offset - UML_CONFIG_STUB_DATA);
printk("do_syscall_stub : ret = %d, offset = %d, "
"data = 0x%x\n", ret, offset, data);
syscall = (unsigned long *)((unsigned long)data + data[0]); syscall = (unsigned long *)((unsigned long)data + data[0]);
printk("do_syscall_stub: syscall %ld failed, return value = " printk("do_syscall_stub: syscall %ld failed, return value = "
"0x%lx, expected return value = 0x%lx\n", "0x%lx, expected return value = 0x%lx\n",
...@@ -107,32 +111,32 @@ static long do_syscall_stub(struct mm_id *mm_idp, void **addr) ...@@ -107,32 +111,32 @@ static long do_syscall_stub(struct mm_id *mm_idp, void **addr)
long run_syscall_stub(struct mm_id * mm_idp, int syscall, long run_syscall_stub(struct mm_id * mm_idp, int syscall,
unsigned long *args, long expected, void **addr, unsigned long *args, long expected, void **addr,
int done) int done)
{ {
unsigned long *stack = check_init_stack(mm_idp, *addr); unsigned long *stack = check_init_stack(mm_idp, *addr);
if(done && *addr == NULL) if(done && *addr == NULL)
single_count++; single_count++;
*stack += sizeof(long); *stack += sizeof(long);
stack += *stack / sizeof(long); stack += *stack / sizeof(long);
*stack++ = syscall; *stack++ = syscall;
*stack++ = args[0]; *stack++ = args[0];
*stack++ = args[1]; *stack++ = args[1];
*stack++ = args[2]; *stack++ = args[2];
*stack++ = args[3]; *stack++ = args[3];
*stack++ = args[4]; *stack++ = args[4];
*stack++ = args[5]; *stack++ = args[5];
*stack++ = expected; *stack++ = expected;
*stack = 0; *stack = 0;
multi_op_count++; multi_op_count++;
if(!done && ((((unsigned long) stack) & ~PAGE_MASK) < if(!done && ((((unsigned long) stack) & ~PAGE_MASK) <
PAGE_SIZE - 10 * sizeof(long))){ PAGE_SIZE - 10 * sizeof(long))){
*addr = stack; *addr = stack;
return 0; return 0;
} }
return do_syscall_stub(mm_idp, addr); return do_syscall_stub(mm_idp, addr);
} }
...@@ -150,7 +154,7 @@ long syscall_stub_data(struct mm_id * mm_idp, ...@@ -150,7 +154,7 @@ long syscall_stub_data(struct mm_id * mm_idp,
if((((unsigned long) *addr) & ~PAGE_MASK) >= if((((unsigned long) *addr) & ~PAGE_MASK) >=
PAGE_SIZE - (10 + data_count) * sizeof(long)) { PAGE_SIZE - (10 + data_count) * sizeof(long)) {
ret = do_syscall_stub(mm_idp, addr); ret = do_syscall_stub(mm_idp, addr);
/* in case of error, don't overwrite data on stack */ /* in case of error, don't overwrite data on stack */
if(ret) if(ret)
return ret; return ret;
} }
...@@ -172,39 +176,39 @@ int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, ...@@ -172,39 +176,39 @@ int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len,
int r, int w, int x, int phys_fd, unsigned long long offset, int r, int w, int x, int phys_fd, unsigned long long offset,
int done, void **data) int done, void **data)
{ {
int prot, ret; int prot, ret;
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0); (x ? PROT_EXEC : 0);
if(proc_mm){ if(proc_mm){
struct proc_mm_op map; struct proc_mm_op map;
int fd = mm_idp->u.mm_fd; int fd = mm_idp->u.mm_fd;
map = ((struct proc_mm_op) { .op = MM_MMAP, map = ((struct proc_mm_op) { .op = MM_MMAP,
.u = .u =
{ .mmap = { .mmap =
{ .addr = virt, { .addr = virt,
.len = len, .len = len,
.prot = prot, .prot = prot,
.flags = MAP_SHARED | .flags = MAP_SHARED |
MAP_FIXED, MAP_FIXED,
.fd = phys_fd, .fd = phys_fd,
.offset= offset .offset= offset
} } } ); } } } );
ret = os_write_file(fd, &map, sizeof(map)); ret = os_write_file(fd, &map, sizeof(map));
if(ret != sizeof(map)) if(ret != sizeof(map))
printk("map : /proc/mm map failed, err = %d\n", -ret); printk("map : /proc/mm map failed, err = %d\n", -ret);
else ret = 0; else ret = 0;
} }
else { else {
unsigned long args[] = { virt, len, prot, unsigned long args[] = { virt, len, prot,
MAP_SHARED | MAP_FIXED, phys_fd, MAP_SHARED | MAP_FIXED, phys_fd,
MMAP_OFFSET(offset) }; MMAP_OFFSET(offset) };
ret = run_syscall_stub(mm_idp, STUB_MMAP_NR, args, virt, ret = run_syscall_stub(mm_idp, STUB_MMAP_NR, args, virt,
data, done); data, done);
} }
return ret; return ret;
} }
...@@ -212,68 +216,66 @@ int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len, ...@@ -212,68 +216,66 @@ int map(struct mm_id * mm_idp, unsigned long virt, unsigned long len,
int unmap(struct mm_id * mm_idp, void *addr, unsigned long len, int done, int unmap(struct mm_id * mm_idp, void *addr, unsigned long len, int done,
void **data) void **data)
{ {
int ret; int ret;
if(proc_mm){ if(proc_mm){
struct proc_mm_op unmap; struct proc_mm_op unmap;
int fd = mm_idp->u.mm_fd; int fd = mm_idp->u.mm_fd;
unmap = ((struct proc_mm_op) { .op = MM_MUNMAP, unmap = ((struct proc_mm_op) { .op = MM_MUNMAP,
.u = .u =
{ .munmap = { .munmap =
{ .addr = { .addr =
(unsigned long) addr, (unsigned long) addr,
.len = len } } } ); .len = len } } } );
ret = os_write_file(fd, &unmap, sizeof(unmap)); ret = os_write_file(fd, &unmap, sizeof(unmap));
if(ret != sizeof(unmap)) if(ret != sizeof(unmap))
printk("unmap - proc_mm write returned %d\n", ret); printk("unmap - proc_mm write returned %d\n", ret);
else ret = 0; else ret = 0;
} }
else { else {
unsigned long args[] = { (unsigned long) addr, len, 0, 0, 0, unsigned long args[] = { (unsigned long) addr, len, 0, 0, 0,
0 }; 0 };
ret = run_syscall_stub(mm_idp, __NR_munmap, args, 0, ret = run_syscall_stub(mm_idp, __NR_munmap, args, 0,
data, done); data, done);
if(ret < 0) }
printk("munmap stub failed, errno = %d\n", ret);
}
return ret; return ret;
} }
int protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len, int protect(struct mm_id * mm_idp, unsigned long addr, unsigned long len,
int r, int w, int x, int done, void **data) int r, int w, int x, int done, void **data)
{ {
struct proc_mm_op protect; struct proc_mm_op protect;
int prot, ret; int prot, ret;
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0); (x ? PROT_EXEC : 0);
if(proc_mm){
if(proc_mm){ int fd = mm_idp->u.mm_fd;
int fd = mm_idp->u.mm_fd;
protect = ((struct proc_mm_op) { .op = MM_MPROTECT, protect = ((struct proc_mm_op) { .op = MM_MPROTECT,
.u = .u =
{ .mprotect = { .mprotect =
{ .addr = { .addr =
(unsigned long) addr, (unsigned long) addr,
.len = len, .len = len,
.prot = prot } } } ); .prot = prot } } } );
ret = os_write_file(fd, &protect, sizeof(protect)); ret = os_write_file(fd, &protect, sizeof(protect));
if(ret != sizeof(protect)) if(ret != sizeof(protect))
printk("protect failed, err = %d", -ret); printk("protect failed, err = %d", -ret);
else ret = 0; else ret = 0;
} }
else { else {
unsigned long args[] = { addr, len, prot, 0, 0, 0 }; unsigned long args[] = { addr, len, prot, 0, 0, 0 };
ret = run_syscall_stub(mm_idp, __NR_mprotect, args, 0, ret = run_syscall_stub(mm_idp, __NR_mprotect, args, 0,
data, done); data, done);
} }
return ret; return ret;
} }
void before_mem_skas(unsigned long unused) void before_mem_skas(unsigned long unused)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment