[PATCH] uml: eliminate some globals

Stop using global variables to hold the file descriptor and offset used to map
the skas0 stubs.  Instead, calculate them using the page physical addresses.

Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Jeff Dike 2006-01-18 17:42:48 -08:00 committed by Linus Torvalds
parent abaf69773d
commit 09ee011eb3

View File

@ -151,8 +151,6 @@ static void handle_trap(int pid, union uml_pt_regs *regs, int local_using_sysemu
} }
extern int __syscall_stub_start; extern int __syscall_stub_start;
int stub_code_fd = -1;
__u64 stub_code_offset;
static int userspace_tramp(void *stack) static int userspace_tramp(void *stack)
{ {
@ -167,30 +165,30 @@ static int userspace_tramp(void *stack)
/* This has a pte, but it can't be mapped in with the usual /* This has a pte, but it can't be mapped in with the usual
* tlb_flush mechanism because this is part of that mechanism * tlb_flush mechanism because this is part of that mechanism
*/ */
int fd;
__u64 offset;
fd = phys_mapping(to_phys(&__syscall_stub_start), &offset);
addr = mmap64((void *) UML_CONFIG_STUB_CODE, page_size(), addr = mmap64((void *) UML_CONFIG_STUB_CODE, page_size(),
PROT_EXEC, MAP_FIXED | MAP_PRIVATE, PROT_EXEC, MAP_FIXED | MAP_PRIVATE, fd, offset);
stub_code_fd, stub_code_offset);
if(addr == MAP_FAILED){ if(addr == MAP_FAILED){
printk("mapping stub code failed, errno = %d\n", printk("mapping mmap stub failed, errno = %d\n",
errno); errno);
exit(1); exit(1);
} }
if(stack != NULL){ if(stack != NULL){
int fd;
__u64 offset;
fd = phys_mapping(to_phys(stack), &offset); fd = phys_mapping(to_phys(stack), &offset);
addr = mmap((void *) UML_CONFIG_STUB_DATA, page_size(), addr = mmap((void *) UML_CONFIG_STUB_DATA, page_size(),
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_SHARED, fd, offset); MAP_FIXED | MAP_SHARED, fd, offset);
if(addr == MAP_FAILED){ if(addr == MAP_FAILED){
printk("mapping stub stack failed, " printk("mapping segfault stack failed, "
"errno = %d\n", errno); "errno = %d\n", errno);
exit(1); exit(1);
} }
} }
} }
if(!ptrace_faultinfo){ if(!ptrace_faultinfo && (stack != NULL)){
unsigned long v = UML_CONFIG_STUB_CODE + unsigned long v = UML_CONFIG_STUB_CODE +
(unsigned long) stub_segv_handler - (unsigned long) stub_segv_handler -
(unsigned long) &__syscall_stub_start; (unsigned long) &__syscall_stub_start;
@ -216,10 +214,6 @@ int start_userspace(unsigned long stub_stack)
unsigned long sp; unsigned long sp;
int pid, status, n, flags; int pid, status, n, flags;
if ( stub_code_fd == -1 )
stub_code_fd = phys_mapping(to_phys(&__syscall_stub_start),
&stub_code_offset);
stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(stack == MAP_FAILED) if(stack == MAP_FAILED)
@ -306,7 +300,6 @@ void userspace(union uml_pt_regs *regs)
printk("userspace - child stopped with signal " printk("userspace - child stopped with signal "
"%d\n", WSTOPSIG(status)); "%d\n", WSTOPSIG(status));
} }
again:
pid = userspace_pid[0]; pid = userspace_pid[0];
interrupt_end(); interrupt_end();
@ -395,6 +388,9 @@ void map_stub_pages(int fd, unsigned long code,
{ {
struct proc_mm_op mmop; struct proc_mm_op mmop;
int n; int n;
__u64 code_offset;
int code_fd = phys_mapping(to_phys((void *) &__syscall_stub_start),
&code_offset);
mmop = ((struct proc_mm_op) { .op = MM_MMAP, mmop = ((struct proc_mm_op) { .op = MM_MMAP,
.u = .u =
@ -403,8 +399,8 @@ void map_stub_pages(int fd, unsigned long code,
.len = PAGE_SIZE, .len = PAGE_SIZE,
.prot = PROT_EXEC, .prot = PROT_EXEC,
.flags = MAP_FIXED | MAP_PRIVATE, .flags = MAP_FIXED | MAP_PRIVATE,
.fd = stub_code_fd, .fd = code_fd,
.offset = stub_code_offset .offset = code_offset
} } }); } } });
n = os_write_file(fd, &mmop, sizeof(mmop)); n = os_write_file(fd, &mmop, sizeof(mmop));
if(n != sizeof(mmop)) if(n != sizeof(mmop))