Commit 5c08f794 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

[PATCH] uml: cleaning up

This patch is a whole lot of "obviously won't break anything" changes,
including
	renaming the UML console functions more consistently
	notes to myself
	code movement
	making some functions static
	error path cleanup
	printk fixes
Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent d4f558bc
...@@ -191,7 +191,7 @@ int stdio_init(void) ...@@ -191,7 +191,7 @@ int stdio_init(void)
late_initcall(stdio_init); late_initcall(stdio_init);
static void console_write(struct console *console, const char *string, static void uml_console_write(struct console *console, const char *string,
unsigned len) unsigned len)
{ {
struct line *line = &vts[console->index]; struct line *line = &vts[console->index];
...@@ -203,22 +203,22 @@ static void console_write(struct console *console, const char *string, ...@@ -203,22 +203,22 @@ static void console_write(struct console *console, const char *string,
up(&line->sem); up(&line->sem);
} }
static struct tty_driver *um_console_device(struct console *c, int *index) static struct tty_driver *uml_console_device(struct console *c, int *index)
{ {
*index = c->index; *index = c->index;
return console_driver; return console_driver;
} }
static int console_setup(struct console *co, char *options) static int uml_console_setup(struct console *co, char *options)
{ {
return(0); return(0);
} }
static struct console stdiocons = { static struct console stdiocons = {
name: "tty", name: "tty",
write: console_write, write: uml_console_write,
device: um_console_device, device: uml_console_device,
setup: console_setup, setup: uml_console_setup,
flags: CON_PRINTBUFFER, flags: CON_PRINTBUFFER,
index: -1, index: -1,
}; };
......
...@@ -83,6 +83,7 @@ __uml_setup("xterm=", xterm_setup, ...@@ -83,6 +83,7 @@ __uml_setup("xterm=", xterm_setup,
" are 'xterm=gnome-terminal,-t,-x'.\n\n" " are 'xterm=gnome-terminal,-t,-x'.\n\n"
); );
/* XXX This badly needs some cleaning up in the error paths */
int xterm_open(int input, int output, int primary, void *d, char **dev_out) int xterm_open(int input, int output, int primary, void *d, char **dev_out)
{ {
struct xterm_chan *data = d; struct xterm_chan *data = d;
......
...@@ -139,16 +139,6 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack, ...@@ -139,16 +139,6 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack,
return(arg.pid); return(arg.pid);
} }
void suspend_new_thread(int fd)
{
char c;
os_stop_process(os_getpid());
if(os_read_file(fd, &c, sizeof(c)) != sizeof(c))
panic("read failed in suspend_new_thread");
}
static int ptrace_child(void *arg) static int ptrace_child(void *arg)
{ {
int pid = os_getpid(); int pid = os_getpid();
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
/* Protected by sigio_lock() called from write_sigio_workaround */ /* Protected by sigio_lock() called from write_sigio_workaround */
static int sigio_irq_fd = -1; static int sigio_irq_fd = -1;
irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused) static irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused)
{ {
read_sigio_fd(sigio_irq_fd); read_sigio_fd(sigio_irq_fd);
reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ); reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ);
...@@ -25,10 +25,14 @@ irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused) ...@@ -25,10 +25,14 @@ irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused)
int write_sigio_irq(int fd) int write_sigio_irq(int fd)
{ {
if(um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt, int err;
err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
SA_INTERRUPT | SA_SAMPLE_RANDOM, "write sigio", SA_INTERRUPT | SA_SAMPLE_RANDOM, "write sigio",
NULL)){ NULL);
printk("write_sigio_irq : um_request_irq failed\n"); if(err){
printk("write_sigio_irq : um_request_irq failed, err = %d\n",
err);
return(-1); return(-1);
} }
sigio_irq_fd = fd; sigio_irq_fd = fd;
......
...@@ -375,28 +375,6 @@ void reboot_skas(void) ...@@ -375,28 +375,6 @@ void reboot_skas(void)
siglongjmp(initial_jmpbuf, 4); siglongjmp(initial_jmpbuf, 4);
} }
int new_mm(int from)
{
struct proc_mm_op copy;
int n, fd = os_open_file("/proc/mm",
of_cloexec(of_write(OPENFLAGS())), 0);
if(fd < 0)
return(fd);
if(from != -1){
copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS,
.u =
{ .copy_segments = from } } );
n = os_write_file(fd, &copy, sizeof(copy));
if(n != sizeof(copy))
printk("new_mm : /proc/mm copy_segments failed, "
"err = %d\n", -n);
}
return(fd);
}
void switch_mm_skas(int mm_fd) void switch_mm_skas(int mm_fd)
{ {
int err; int err;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "frame.h" #include "frame.h"
#include "kern.h" #include "kern.h"
#include "mode.h" #include "mode.h"
#include "proc_mm.h"
static atomic_t using_sysemu; static atomic_t using_sysemu;
int sysemu_supported; int sysemu_supported;
...@@ -196,6 +197,28 @@ int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp, ...@@ -196,6 +197,28 @@ int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
return(0); return(0);
} }
int new_mm(int from)
{
struct proc_mm_op copy;
int n, fd;
fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
if(fd < 0)
return(fd);
if(from != -1){
copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS,
.u =
{ .copy_segments = from } } );
n = os_write_file(fd, &copy, sizeof(copy));
if(n != sizeof(copy))
printk("new_mm : /proc/mm copy_segments failed, "
"err = %d\n", -n);
}
return(fd);
}
void init_idle_skas(void) void init_idle_skas(void)
{ {
cpu_tasks[current_thread->cpu].pid = os_getpid(); cpu_tasks[current_thread->cpu].pid = os_getpid();
......
...@@ -128,6 +128,17 @@ void exit_thread_tt(void) ...@@ -128,6 +128,17 @@ void exit_thread_tt(void)
os_close_file(current->thread.mode.tt.switch_pipe[1]); os_close_file(current->thread.mode.tt.switch_pipe[1]);
} }
void suspend_new_thread(int fd)
{
int err;
char c;
os_stop_process(os_getpid());
err = os_read_file(fd, &c, sizeof(c));
if(err != sizeof(c))
panic("read failed in suspend_new_thread, err = %d", -err);
}
void schedule_tail(task_t *prev); void schedule_tail(task_t *prev);
static void new_thread_handler(int sig) static void new_thread_handler(int sig)
...@@ -162,6 +173,12 @@ static void new_thread_handler(int sig) ...@@ -162,6 +173,12 @@ static void new_thread_handler(int sig)
local_irq_enable(); local_irq_enable();
if(!run_kernel_thread(fn, arg, &current->thread.exec_buf)) if(!run_kernel_thread(fn, arg, &current->thread.exec_buf))
do_exit(0); do_exit(0);
/* XXX No set_user_mode here because a newly execed process will
* immediately segfault on its non-existent IP, coming straight back
* to the signal handler, which will call set_user_mode on its way
* out. This should probably change since it's confusing.
*/
} }
static int new_thread_proc(void *stack) static int new_thread_proc(void *stack)
......
...@@ -330,7 +330,8 @@ int tracer(int (*init_proc)(void *), void *sp) ...@@ -330,7 +330,8 @@ int tracer(int (*init_proc)(void *), void *sp)
continue; continue;
} }
tracing = 0; tracing = 0;
if(do_syscall(task, pid)) sig = SIGUSR2; if(do_syscall(task, pid))
sig = SIGUSR2;
else clear_singlestep(task); else clear_singlestep(task);
break; break;
case SIGPROF: case SIGPROF:
......
...@@ -43,7 +43,7 @@ static int __init set_umid(char *name, int is_random, ...@@ -43,7 +43,7 @@ static int __init set_umid(char *name, int is_random,
} }
if(strlen(name) > UMID_LEN - 1) if(strlen(name) > UMID_LEN - 1)
(*printer)("Unique machine name is being truncated to %s " (*printer)("Unique machine name is being truncated to %d "
"characters\n", UMID_LEN); "characters\n", UMID_LEN);
strlcpy(umid, name, sizeof(umid)); strlcpy(umid, name, sizeof(umid));
...@@ -199,17 +199,20 @@ int not_dead_yet(char *dir) ...@@ -199,17 +199,20 @@ int not_dead_yet(char *dir)
static int __init set_uml_dir(char *name, int *add) static int __init set_uml_dir(char *name, int *add)
{ {
if((strlen(name) > 0) && (name[strlen(name) - 1] != '/')){ if((strlen(name) > 0) && (name[strlen(name) - 1] != '/')){
uml_dir = malloc(strlen(name) + 1); uml_dir = malloc(strlen(name) + 2);
if(uml_dir == NULL){ if(uml_dir == NULL){
printf("Failed to malloc uml_dir - error = %d\n", printf("Failed to malloc uml_dir - error = %d\n",
errno); errno);
uml_dir = name; uml_dir = name;
/* Return 0 here because do_initcalls doesn't look at
* the return value.
*/
return(0); return(0);
} }
sprintf(uml_dir, "%s/", name); sprintf(uml_dir, "%s/", name);
} }
else uml_dir = name; else uml_dir = name;
return 0; return(0);
} }
static int __init make_uml_dir(void) static int __init make_uml_dir(void)
......
...@@ -88,11 +88,11 @@ int wait_for_stop(int pid, int sig, int cont_type, void *relay) ...@@ -88,11 +88,11 @@ int wait_for_stop(int pid, int sig, int cont_type, void *relay)
errno); errno);
} }
else if(WIFEXITED(status)) else if(WIFEXITED(status))
printk("process exited with status %d\n", printk("process %d exited with status %d\n",
WEXITSTATUS(status)); pid, WEXITSTATUS(status));
else if(WIFSIGNALED(status)) else if(WIFSIGNALED(status))
printk("process exited with signal %d\n", printk("process %d exited with signal %d\n",
WTERMSIG(status)); pid, WTERMSIG(status));
else if((WSTOPSIG(status) == SIGVTALRM) || else if((WSTOPSIG(status) == SIGVTALRM) ||
(WSTOPSIG(status) == SIGALRM) || (WSTOPSIG(status) == SIGALRM) ||
(WSTOPSIG(status) == SIGIO) || (WSTOPSIG(status) == SIGIO) ||
...@@ -108,8 +108,8 @@ int wait_for_stop(int pid, int sig, int cont_type, void *relay) ...@@ -108,8 +108,8 @@ int wait_for_stop(int pid, int sig, int cont_type, void *relay)
ptrace(cont_type, pid, 0, WSTOPSIG(status)); ptrace(cont_type, pid, 0, WSTOPSIG(status));
continue; continue;
} }
else printk("process stopped with signal %d\n", else printk("process %d stopped with signal %d\n",
WSTOPSIG(status)); pid, WSTOPSIG(status));
panic("wait_for_stop failed to wait for %d to stop " panic("wait_for_stop failed to wait for %d to stop "
"with %d\n", pid, sig); "with %d\n", pid, sig);
} }
......
...@@ -187,7 +187,8 @@ int os_sigio_async(int master, int slave) ...@@ -187,7 +187,8 @@ int os_sigio_async(int master, int slave)
if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) ||
(fcntl(master, F_SETOWN, os_getpid()) < 0)){ (fcntl(master, F_SETOWN, os_getpid()) < 0)){
printk("fcntl F_SETFL or F_SETOWN failed, errno = %d\n", errno); printk("fcntl F_SETFL or F_SETOWN failed, errno = %d\n",
errno);
return(-errno); return(-errno);
} }
......
...@@ -42,9 +42,9 @@ unsigned long os_process_pc(int pid) ...@@ -42,9 +42,9 @@ unsigned long os_process_pc(int pid)
} }
os_close_file(fd); os_close_file(fd);
pc = ARBITRARY_ADDR; pc = ARBITRARY_ADDR;
if(sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d %*d " if(sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d "
"%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
"%*d %*d %*d %*d %lu", &pc) != 1){ "%*d %*d %*d %*d %*d %lu", &pc) != 1){
printk("os_process_pc - couldn't find pc in '%s'\n", buf); printk("os_process_pc - couldn't find pc in '%s'\n", buf);
} }
return(pc); return(pc);
......
...@@ -42,7 +42,8 @@ static void write_debugregs(int pid, unsigned long *regs) ...@@ -42,7 +42,8 @@ static void write_debugregs(int pid, unsigned long *regs)
if(ptrace(PTRACE_POKEUSER, pid, &dummy->u_debugreg[i], if(ptrace(PTRACE_POKEUSER, pid, &dummy->u_debugreg[i],
regs[i]) < 0) regs[i]) < 0)
printk("write_debugregs - ptrace failed on " printk("write_debugregs - ptrace failed on "
"register %d, errno = %d\n", errno); "register %d, value = 0x%x, errno = %d\n", i,
regs[i], errno);
} }
} }
......
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