Commit ab2d71be authored by Jeff Dike's avatar Jeff Dike

Merge http://jdike.stearns.org:5000/skas-2.5

into hostme.bitkeeper.com:/ua/repos/u/uml/skas-2.5
parents e482449c cf46dde7
...@@ -30,6 +30,13 @@ config RWSEM_GENERIC_SPINLOCK ...@@ -30,6 +30,13 @@ config RWSEM_GENERIC_SPINLOCK
bool bool
default y default y
config MODE_TT
bool
default y
config MODE_SKAS
bool
default y
menu "Code maturity level options" menu "Code maturity level options"
...@@ -128,6 +135,7 @@ source "net/Kconfig" ...@@ -128,6 +135,7 @@ source "net/Kconfig"
source "fs/Kconfig" source "fs/Kconfig"
source "lib/Kconfig"
menu "SCSI support" menu "SCSI support"
......
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
ARCH_DIR = arch/um ARCH_DIR = arch/um
OS := $(shell uname -s) OS := $(shell uname -s)
...@@ -11,37 +16,31 @@ include/linux/version.h: arch/$(ARCH)/Makefile ...@@ -11,37 +16,31 @@ include/linux/version.h: arch/$(ARCH)/Makefile
# EXTRAVERSION... # EXTRAVERSION...
MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
MAKEBOOT = $(MAKE) -C $(ARCH_DIR)/boot
ifeq ($(CONFIG_DEBUGSYM),y) ifeq ($(CONFIG_DEBUGSYM),y)
DEBUG = -g
CFLAGS := $(subst -fomit-frame-pointer,,$(CFLAGS)) CFLAGS := $(subst -fomit-frame-pointer,,$(CFLAGS))
endif endif
ifeq ($(CONFIG_GCOV),y) CFLAGS-$(CONFIG_DEBUGSYM) += -g
CFLAGS += -fprofile-arcs -ftest-coverage CFLAGS-$(CONFIG_GCOV) += -fprofile-arcs -ftest-coverage
endif CFLAGS-$(CONFIG_GPROF) += $(PROFILE)
LINK-$(CONFIG_GPROF) += $(PROFILE) -Wl,--wrap,__monstartup
ifeq ($(CONFIG_GPROF), y)
PROFILE += -pg -DPROFILING
LINK_PROFILE = $(PROFILE) -Wl,--wrap,__monstartup
endif
core-y += $(ARCH_DIR)/kernel/ \ core-y += $(ARCH_DIR)/kernel/ \
$(ARCH_DIR)/drivers/ \ $(ARCH_DIR)/drivers/ \
$(ARCH_DIR)/sys-$(SUBARCH)/ $(ARCH_DIR)/sys-$(SUBARCH)/
core-$(CONFIG_PT_PROXY) += $(ARCH_DIR)/ptproxy/ ARCH_INCLUDE = -I$(ARCH_DIR)/include
MODE_INCLUDE = -I$(ARCH_DIR)/kernel/tt/include \
ARCH_INCLUDE = $(TOPDIR)/$(ARCH_DIR)/include -I$(ARCH_DIR)/kernel/skas/include
# -Derrno=kernel_errno - This turns all kernel references to errno into # -Derrno=kernel_errno - This turns all kernel references to errno into
# kernel_errno to separate them from the libc errno. This allows -fno-common # kernel_errno to separate them from the libc errno. This allows -fno-common
# in CFLAGS. Otherwise, it would cause ld to complain about the two different # in CFLAGS. Otherwise, it would cause ld to complain about the two different
# errnos. # errnos.
CFLAGS += $(DEBUG) $(PROFILE) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \ CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
-D_LARGEFILE64_SOURCE -I$(ARCH_INCLUDE) -Derrno=kernel_errno -D_LARGEFILE64_SOURCE $(ARCH_INCLUDE) -Derrno=kernel_errno \
$(MODE_INCLUDE)
LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
...@@ -51,10 +50,16 @@ SYMLINK_HEADERS = include/asm-um/archparam.h include/asm-um/system.h \ ...@@ -51,10 +50,16 @@ SYMLINK_HEADERS = include/asm-um/archparam.h include/asm-um/system.h \
include/asm-um/sigcontext.h include/asm-um/processor.h \ include/asm-um/sigcontext.h include/asm-um/processor.h \
include/asm-um/ptrace.h include/asm-um/arch-signal.h include/asm-um/ptrace.h include/asm-um/arch-signal.h
ARCH_SYMLINKS = include/asm-um/arch arch/um/include/sysdep arch/um/os \ ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
$(SYMLINK_HEADERS) $(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
ifeq ($(CONFIG_MODE_SKAS), y)
GEN_HEADERS = $(ARCH_DIR)/kernel/skas/include/skas_ptregs.h
GEN_HEADERS = $(ARCH_DIR)/include/task.h $(SYS_HEADERS) : $(ARCH_DIR)/kernel/skas/include/skas_ptregs.h
endif
GEN_HEADERS += $(ARCH_DIR)/include/task.h $(ARCH_DIR)/include/kern_constants.h
include $(ARCH_DIR)/Makefile-$(SUBARCH) include $(ARCH_DIR)/Makefile-$(SUBARCH)
include $(ARCH_DIR)/Makefile-os-$(OS) include $(ARCH_DIR)/Makefile-os-$(OS)
...@@ -62,9 +67,9 @@ include $(ARCH_DIR)/Makefile-os-$(OS) ...@@ -62,9 +67,9 @@ include $(ARCH_DIR)/Makefile-os-$(OS)
$(ARCH_DIR)/vmlinux.lds.S : $(ARCH_DIR)/vmlinux.lds.S :
touch $@ touch $@
prepare: $(ARCH_SYMLINKS) $(GEN_HEADERS) prepare: $(ARCH_SYMLINKS) $(SYS_HEADERS) $(GEN_HEADERS)
LDFLAGS_vmlinux = -r $(ARCH_DIR)/main.o LDFLAGS_vmlinux = -r
vmlinux: $(ARCH_DIR)/main.o vmlinux: $(ARCH_DIR)/main.o
...@@ -74,18 +79,21 @@ $(ARCH_DIR)/uml.lds.s : $(ARCH_DIR)/uml.lds.S scripts FORCE ...@@ -74,18 +79,21 @@ $(ARCH_DIR)/uml.lds.s : $(ARCH_DIR)/uml.lds.S scripts FORCE
AFLAGS_uml.lds.o = -U$(SUBARCH) -DSTART=$$(($(TOP_ADDR) - $(SIZE))) \ AFLAGS_uml.lds.o = -U$(SUBARCH) -DSTART=$$(($(TOP_ADDR) - $(SIZE))) \
-DELF_ARCH=$(ELF_ARCH) -DELF_FORMAT=\"$(ELF_FORMAT)\" -P -C -Uum -DELF_ARCH=$(ELF_ARCH) -DELF_FORMAT=\"$(ELF_FORMAT)\" -P -C -Uum
linux: arch/um/uml.lds.s vmlinux linux: $(ARCH_DIR)/uml.lds.s vmlinux
$(CC) -Wl,-T,arch/um/uml.lds.s -o $@ $(LINK_PROFILE) \ $(CC) -Wl,-T,$(ARCH_DIR)/uml.lds.s -static $(LINK-y) $(LINK_WRAPS) \
$(LINK_WRAPS) -static vmlinux -L/usr/lib -lutil -o linux $(ARCH_DIR)/main.o vmlinux -L/usr/lib -lutil
USER_CFLAGS := $(patsubst -I%,,$(CFLAGS)) USER_CFLAGS := $(patsubst -I%,,$(CFLAGS))
USER_CFLAGS := $(patsubst -Derrno=kernel_errno,,$(USER_CFLAGS)) USER_CFLAGS := $(patsubst -Derrno=kernel_errno,,$(USER_CFLAGS))
USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) -I$(ARCH_INCLUDE) USER_CFLAGS := $(patsubst -D__KERNEL__,,$(USER_CFLAGS)) $(ARCH_INCLUDE) \
$(MODE_INCLUDE)
# To get a definition of F_SETSIG # To get a definition of F_SETSIG
USER_CFLAGS += -D_GNU_SOURCE USER_CFLAGS += -D_GNU_SOURCE
CLEAN_FILES += linux x.i gmon.out $(ARCH_DIR)/link.ld $(GEN_HEADERS)
$(ARCH_DIR)/main.o: $(ARCH_DIR)/main.c $(ARCH_DIR)/main.o: $(ARCH_DIR)/main.c
$(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< $(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
...@@ -106,7 +114,6 @@ archclean: sysclean ...@@ -106,7 +114,6 @@ archclean: sysclean
find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \ find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
-o -name '*.gcov' \) -type f -print | xargs rm -f -o -name '*.gcov' \) -type f -print | xargs rm -f
rm -f linux x.i gmon.out $(ARCH_DIR)/link.ld $(GEN_HEADERS) rm -f linux x.i gmon.out $(ARCH_DIR)/link.ld $(GEN_HEADERS)
@$(MAKEBOOT) clean
archdep: archdep:
for d in $(ARCH_SUBDIRS); do $(MAKE) -C $$d fastdep; done for d in $(ARCH_SUBDIRS); do $(MAKE) -C $$d fastdep; done
...@@ -119,18 +126,28 @@ $(SYMLINK_HEADERS): ...@@ -119,18 +126,28 @@ $(SYMLINK_HEADERS):
include/asm-um/arch: include/asm-um/arch:
cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch cd $(TOPDIR)/include/asm-um && ln -sf ../asm-$(SUBARCH) arch
arch/um/include/sysdep: $(ARCH_DIR)/include/sysdep:
cd $(TOPDIR)/arch/um/include && ln -sf sysdep-$(SUBARCH) sysdep cd $(ARCH_DIR)/include && ln -sf sysdep-$(SUBARCH) sysdep
arch/um/os: $(ARCH_DIR)/os:
cd $(ARCH_DIR) && ln -sf os-$(OS) os cd $(ARCH_DIR) && ln -sf os-$(OS) os
$(ARCH_DIR)/include/uml-config.h :
ln -sf $(TOPDIR)/include/linux/autoconf.h $@
$(ARCH_DIR)/include/task.h : $(ARCH_DIR)/util/mk_task $(ARCH_DIR)/include/task.h : $(ARCH_DIR)/util/mk_task
$< > $@ $< > $@
$(ARCH_DIR)/util/mk_task : $(ARCH_DIR)/util FORCE ; $(ARCH_DIR)/include/kern_constants.h : $(ARCH_DIR)/util/mk_constants
$< > $@
$(ARCH_DIR)/util/mk_task : $(ARCH_DIR)/kernel/skas/include/skas_ptregs.h \
$(ARCH_DIR)/util FORCE ;
$(ARCH_DIR)/util: FORCE $(ARCH_DIR)/util: FORCE
@$(call descend,$@,) @$(call descend,$@,)
$(ARCH_DIR)/kernel/skas/include/skas_ptregs.h :
$(MAKE) -C $(ARCH_DIR)/kernel/skas include/skas_ptregs.h
export SUBARCH USER_CFLAGS OS export SUBARCH USER_CFLAGS OS
...@@ -21,13 +21,13 @@ prepare: $(SYS_HEADERS) ...@@ -21,13 +21,13 @@ prepare: $(SYS_HEADERS)
$(SYS_DIR)/sc.h: $(SYS_UTIL_DIR)/mk_sc $(SYS_DIR)/sc.h: $(SYS_UTIL_DIR)/mk_sc
$< > $@ $< > $@
$(SYS_DIR)/thread.h: $(SYS_UTIL_DIR)/mk_thread $(SYS_DIR)/thread.h: $(SYS_UTIL_DIR)/mk_thread
$< > $@ $< > $@
$(SYS_UTIL_DIR)/mk_sc: FORCE ; $(SYS_UTIL_DIR)/mk_sc: FORCE ;
@$(call descend,$(SYS_UTIL_DIR),$@) @$(call descend,$(SYS_UTIL_DIR),$@)
$(SYS_UTIL_DIR)/mk_thread: $(ARCH_SYMLINKS) FORCE ; $(SYS_UTIL_DIR)/mk_thread: $(ARCH_SYMLINKS) $(GEN_HEADERS) FORCE ;
@$(call descend,$(SYS_UTIL_DIR),$@) @$(call descend,$(SYS_UTIL_DIR),$@)
$(SYS_UTIL_DIR): include/asm FORCE $(SYS_UTIL_DIR): include/asm FORCE
......
...@@ -24,7 +24,8 @@ static void *not_configged_init(char *str, int device, struct chan_opts *opts) ...@@ -24,7 +24,8 @@ static void *not_configged_init(char *str, int device, struct chan_opts *opts)
return(NULL); return(NULL);
} }
static int not_configged_open(int input, int output, int primary, void *data) static int not_configged_open(int input, int output, int primary, void *data,
char **dev_out)
{ {
printk(KERN_ERR "Using a channel type which is configured out of " printk(KERN_ERR "Using a channel type which is configured out of "
"UML\n"); "UML\n");
...@@ -112,7 +113,8 @@ static int open_one_chan(struct chan *chan, int input, int output, int primary) ...@@ -112,7 +113,8 @@ static int open_one_chan(struct chan *chan, int input, int output, int primary)
if(chan->opened) return(0); if(chan->opened) return(0);
if(chan->ops->open == NULL) fd = 0; if(chan->ops->open == NULL) fd = 0;
else fd = (*chan->ops->open)(input, output, primary, chan->data); else fd = (*chan->ops->open)(input, output, primary, chan->data,
&chan->dev);
if(fd < 0) return(fd); if(fd < 0) return(fd);
chan->fd = fd; chan->fd = fd;
...@@ -258,6 +260,66 @@ void free_chan(struct list_head *chans) ...@@ -258,6 +260,66 @@ void free_chan(struct list_head *chans)
} }
} }
static int one_chan_config_string(struct chan *chan, char *str, int size,
char **error_out)
{
int n = 0;
CONFIG_CHUNK(str, size, n, chan->ops->type, 0);
if(chan->dev == NULL){
CONFIG_CHUNK(str, size, n, "", 1);
return(n);
}
CONFIG_CHUNK(str, size, n, ":", 0);
CONFIG_CHUNK(str, size, n, chan->dev, 0);
return(n);
}
static int chan_pair_config_string(struct chan *in, struct chan *out,
char *str, int size, char **error_out)
{
int n;
n = one_chan_config_string(in, str, size, error_out);
str += n;
size -= n;
if(in == out){
CONFIG_CHUNK(str, size, n, "", 1);
return(n);
}
CONFIG_CHUNK(str, size, n, ",", 1);
n = one_chan_config_string(out, str, size, error_out);
str += n;
size -= n;
CONFIG_CHUNK(str, size, n, "", 1);
return(n);
}
int chan_config_string(struct list_head *chans, char *str, int size,
char **error_out)
{
struct list_head *ele;
struct chan *chan, *in = NULL, *out = NULL;
list_for_each(ele, chans){
chan = list_entry(ele, struct chan, list);
if(!chan->primary)
continue;
if(chan->input)
in = chan;
if(chan->output)
out = chan;
}
return(chan_pair_config_string(in, out, str, size, error_out));
}
struct chan_type { struct chan_type {
char *key; char *key;
struct chan_ops *ops; struct chan_ops *ops;
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "user.h" #include "user.h"
#include "helper.h" #include "helper.h"
#include "os.h" #include "os.h"
#include "choose-mode.h"
#include "mode.h"
void generic_close(int fd, void *unused) void generic_close(int fd, void *unused)
{ {
...@@ -144,32 +146,6 @@ static int winch_thread(void *arg) ...@@ -144,32 +146,6 @@ static int winch_thread(void *arg)
} }
} }
static int tracer_winch[2];
static void tracer_winch_handler(int sig)
{
char c = 1;
if(write(tracer_winch[1], &c, sizeof(c)) != sizeof(c))
printk("tracer_winch_handler - write failed, errno = %d\n",
errno);
}
/* Called only by the tracing thread during initialization */
void setup_tracer_winch(void)
{
int err;
err = os_pipe(tracer_winch, 1, 1);
if(err){
printk("setup_tracer_winch : os_pipe failed, errno = %d\n",
-err);
return;
}
signal(SIGWINCH, tracer_winch_handler);
}
static int winch_tramp(int fd, void *device_data, int *fd_out) static int winch_tramp(int fd, void *device_data, int *fd_out)
{ {
struct winch_data data; struct winch_data data;
...@@ -212,9 +188,8 @@ void register_winch(int fd, void *device_data) ...@@ -212,9 +188,8 @@ void register_winch(int fd, void *device_data)
if(!isatty(fd)) return; if(!isatty(fd)) return;
pid = tcgetpgrp(fd); pid = tcgetpgrp(fd);
if(pid == tracing_pid) if(!CHOOSE_MODE(is_tracer_winch(pid, fd, device_data), 0) &&
register_winch_irq(tracer_winch[0], fd, -1, device_data); (pid == -1)){
else if(pid == -1){
thread = winch_tramp(fd, device_data, &thread_fd); thread = winch_tramp(fd, device_data, &thread_fd);
if(fd != -1){ if(fd != -1){
register_winch_irq(thread_fd, fd, thread, device_data); register_winch_irq(thread_fd, fd, thread, device_data);
......
...@@ -15,6 +15,7 @@ struct fd_chan { ...@@ -15,6 +15,7 @@ struct fd_chan {
int fd; int fd;
int raw; int raw;
struct termios tt; struct termios tt;
char str[sizeof("1234567890\0")];
}; };
void *fd_init(char *str, int device, struct chan_opts *opts) void *fd_init(char *str, int device, struct chan_opts *opts)
...@@ -40,7 +41,7 @@ void *fd_init(char *str, int device, struct chan_opts *opts) ...@@ -40,7 +41,7 @@ void *fd_init(char *str, int device, struct chan_opts *opts)
return(data); return(data);
} }
int fd_open(int input, int output, int primary, void *d) int fd_open(int input, int output, int primary, void *d, char **dev_out)
{ {
struct fd_chan *data = d; struct fd_chan *data = d;
...@@ -48,6 +49,8 @@ int fd_open(int input, int output, int primary, void *d) ...@@ -48,6 +49,8 @@ int fd_open(int input, int output, int primary, void *d)
tcgetattr(data->fd, &data->tt); tcgetattr(data->fd, &data->tt);
raw(data->fd, 0); raw(data->fd, 0);
} }
sprintf(data->str, "%d", data->fd);
*dev_out = data->str;
return(data->fd); return(data->fd);
} }
...@@ -69,6 +72,7 @@ int fd_console_write(int fd, const char *buf, int n, void *d) ...@@ -69,6 +72,7 @@ int fd_console_write(int fd, const char *buf, int n, void *d)
} }
struct chan_ops fd_ops = { struct chan_ops fd_ops = {
type: "fd",
init: fd_init, init: fd_init,
open: fd_open, open: fd_open,
close: fd_close, close: fd_close,
......
...@@ -8,11 +8,13 @@ ...@@ -8,11 +8,13 @@
#include "linux/list.h" #include "linux/list.h"
#include "linux/devfs_fs_kernel.h" #include "linux/devfs_fs_kernel.h"
#include "asm/irq.h" #include "asm/irq.h"
#include "asm/uaccess.h"
#include "chan_kern.h" #include "chan_kern.h"
#include "irq_user.h" #include "irq_user.h"
#include "line.h" #include "line.h"
#include "kern.h" #include "kern.h"
#include "user_util.h" #include "user_util.h"
#include "kern_util.h"
#include "os.h" #include "os.h"
#define LINE_BUFSIZE 4096 #define LINE_BUFSIZE 4096
...@@ -87,15 +89,26 @@ static int flush_buffer(struct line *line) ...@@ -87,15 +89,26 @@ static int flush_buffer(struct line *line)
return(line->head == line->tail); return(line->head == line->tail);
} }
int line_write(struct line *lines, struct tty_struct *tty, const char *buf, int line_write(struct line *lines, struct tty_struct *tty, int from_user,
int len) const char *buf, int len)
{ {
struct line *line; struct line *line;
char *new;
unsigned long flags; unsigned long flags;
int n, err, i; int n, err, i;
if(tty->stopped) return 0; if(tty->stopped) return 0;
if(from_user){
new = kmalloc(len, GFP_KERNEL);
if(new == NULL)
return(0);
n = copy_from_user(new, buf, len);
if(n == len)
return(-EFAULT);
buf = new;
}
i = minor(tty->device) - tty->driver.minor_start; i = minor(tty->device) - tty->driver.minor_start;
line = &lines[i]; line = &lines[i];
...@@ -281,7 +294,7 @@ void close_lines(struct line *lines, int nlines) ...@@ -281,7 +294,7 @@ void close_lines(struct line *lines, int nlines)
close_chan(&lines[i].chan_list); close_chan(&lines[i].chan_list);
} }
void line_setup(struct line *lines, int num, char *init) int line_setup(struct line *lines, int num, char *init, int all_allowed)
{ {
int i, n; int i, n;
char *end; char *end;
...@@ -292,12 +305,36 @@ void line_setup(struct line *lines, int num, char *init) ...@@ -292,12 +305,36 @@ void line_setup(struct line *lines, int num, char *init)
if(*end != '='){ if(*end != '='){
printk(KERN_ERR "line_setup failed to parse \"%s\"\n", printk(KERN_ERR "line_setup failed to parse \"%s\"\n",
init); init);
return; return(1);
} }
init = end; init = end;
} }
init++; init++;
if(n == -1){ if((n >= 0) && (n >= num)){
printk("line_setup - %d out of range ((0 ... %d) allowed)\n",
n, num);
return(1);
}
else if(n >= 0){
if(lines[n].count > 0){
printk("line_setup - device %d is open\n", n);
return(1);
}
if(lines[n].init_pri <= INIT_ONE){
lines[n].init_pri = INIT_ONE;
if(!strcmp(init, "none")) lines[n].valid = 0;
else {
lines[n].init_str = init;
lines[n].valid = 1;
}
}
}
else if(!all_allowed){
printk("line_setup - can't configure all devices from "
"mconsole\n");
return(1);
}
else {
for(i = 0; i < num; i++){ for(i = 0; i < num; i++){
if(lines[i].init_pri <= INIT_ALL){ if(lines[i].init_pri <= INIT_ALL){
lines[i].init_pri = INIT_ALL; lines[i].init_pri = INIT_ALL;
...@@ -309,14 +346,57 @@ void line_setup(struct line *lines, int num, char *init) ...@@ -309,14 +346,57 @@ void line_setup(struct line *lines, int num, char *init)
} }
} }
} }
else if(lines[n].init_pri <= INIT_ONE){ return(0);
lines[n].init_pri = INIT_ONE; }
if(!strcmp(init, "none")) lines[n].valid = 0;
else { int line_config(struct line *lines, int num, char *str)
lines[n].init_str = init; {
lines[n].valid = 1; char *new = uml_strdup(str);
}
if(new == NULL){
printk("line_config - uml_strdup failed\n");
return(-ENOMEM);
} }
return(line_setup(lines, num, new, 0));
}
int line_get_config(char *name, struct line *lines, int num, char *str,
int size, char **error_out)
{
struct line *line;
char *end;
int dev, n = 0;
dev = simple_strtoul(name, &end, 0);
if((*end != '\0') || (end == name)){
*error_out = "line_setup failed to parse device number";
return(0);
}
if((dev < 0) || (dev >= num)){
*error_out = "device number of of range";
return(0);
}
line = &lines[dev];
down(&line->sem);
if(!line->valid)
CONFIG_CHUNK(str, size, n, "none", 1);
else if(line->count == 0)
CONFIG_CHUNK(str, size, n, line->init_str, 1);
else n = chan_config_string(&line->chan_list, str, size, error_out);
up(&line->sem);
return(n);
}
int line_remove(struct line *lines, int num, char *str)
{
char config[sizeof("conxxxx=none\0")];
sprintf(config, "%s=none", str);
return(line_setup(lines, num, config, 0));
} }
void line_register_devfs(struct lines *set, struct line_driver *line_driver, void line_register_devfs(struct lines *set, struct line_driver *line_driver,
...@@ -366,6 +446,8 @@ void line_register_devfs(struct lines *set, struct line_driver *line_driver, ...@@ -366,6 +446,8 @@ void line_register_devfs(struct lines *set, struct line_driver *line_driver,
if(!lines[i].valid) if(!lines[i].valid)
tty_unregister_devfs(driver, driver->minor_start + i); tty_unregister_devfs(driver, driver->minor_start + i);
} }
mconsole_register_dev(&line_driver->mc);
} }
void lines_init(struct line *lines, int nlines) void lines_init(struct line *lines, int nlines)
...@@ -451,7 +533,7 @@ static void winch_cleanup(void) ...@@ -451,7 +533,7 @@ static void winch_cleanup(void)
list_for_each(ele, &winch_handlers){ list_for_each(ele, &winch_handlers){
winch = list_entry(ele, struct winch, list); winch = list_entry(ele, struct winch, list);
close(winch->fd); close(winch->fd);
if(winch->pid != -1) os_kill_process(winch->pid); if(winch->pid != -1) os_kill_process(winch->pid, 0);
} }
} }
......
...@@ -108,6 +108,7 @@ void mconsole_version(struct mc_request *req) ...@@ -108,6 +108,7 @@ void mconsole_version(struct mc_request *req)
reboot - Reboot UML reboot - Reboot UML
config <dev>=<config> - Add a new device to UML; config <dev>=<config> - Add a new device to UML;
same syntax as command line same syntax as command line
config <dev> - Query the configuration of a device
remove <dev> - Remove a device from UML remove <dev> - Remove a device from UML
sysrq <letter> - Performs the SysRq action controlled by the letter sysrq <letter> - Performs the SysRq action controlled by the letter
cad - invoke the Ctl-Alt-Del handler cad - invoke the Ctl-Alt-Del handler
...@@ -181,10 +182,56 @@ static struct mc_device *mconsole_find_dev(char *name) ...@@ -181,10 +182,56 @@ static struct mc_device *mconsole_find_dev(char *name)
return(NULL); return(NULL);
} }
#define CONFIG_BUF_SIZE 64
static void mconsole_get_config(int (*get_config)(char *, char *, int,
char **),
struct mc_request *req, char *name)
{
char default_buf[CONFIG_BUF_SIZE], *error, *buf;
int n, size;
if(get_config == NULL){
mconsole_reply(req, "No get_config routine defined", 1, 0);
return;
}
error = NULL;
size = sizeof(default_buf)/sizeof(default_buf[0]);
buf = default_buf;
while(1){
n = (*get_config)(name, buf, size, &error);
if(error != NULL){
mconsole_reply(req, error, 1, 0);
goto out;
}
if(n <= size){
mconsole_reply(req, buf, 0, 0);
goto out;
}
if(buf != default_buf)
kfree(buf);
size = n;
buf = kmalloc(size, GFP_KERNEL);
if(buf == NULL){
mconsole_reply(req, "Failed to allocate buffer", 1, 0);
return;
}
}
out:
if(buf != default_buf)
kfree(buf);
}
void mconsole_config(struct mc_request *req) void mconsole_config(struct mc_request *req)
{ {
struct mc_device *dev; struct mc_device *dev;
char *ptr = req->request.data; char *ptr = req->request.data, *name;
int err; int err;
ptr += strlen("config"); ptr += strlen("config");
...@@ -194,8 +241,17 @@ void mconsole_config(struct mc_request *req) ...@@ -194,8 +241,17 @@ void mconsole_config(struct mc_request *req)
mconsole_reply(req, "Bad configuration option", 1, 0); mconsole_reply(req, "Bad configuration option", 1, 0);
return; return;
} }
err = (*dev->config)(&ptr[strlen(dev->name)]);
mconsole_reply(req, "", err, 0); name = &ptr[strlen(dev->name)];
ptr = name;
while((*ptr != '=') && (*ptr != '\0'))
ptr++;
if(*ptr == '='){
err = (*dev->config)(name);
mconsole_reply(req, "", err, 0);
}
else mconsole_get_config(dev->get_config, req, name);
} }
void mconsole_remove(struct mc_request *req) void mconsole_remove(struct mc_request *req)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include "chan_user.h" #include "chan_user.h"
...@@ -15,8 +16,9 @@ void *null_init(char *str, int device, struct chan_opts *opts) ...@@ -15,8 +16,9 @@ void *null_init(char *str, int device, struct chan_opts *opts)
return(&null_chan); return(&null_chan);
} }
int null_open(int input, int output, int primary, void *d) int null_open(int input, int output, int primary, void *d, char **dev_out)
{ {
*dev_out = NULL;
return(os_open_file(DEV_NULL, of_rdwr(OPENFLAGS()), 0)); return(os_open_file(DEV_NULL, of_rdwr(OPENFLAGS()), 0));
} }
...@@ -30,6 +32,7 @@ void null_free(void *data) ...@@ -30,6 +32,7 @@ void null_free(void *data)
} }
struct chan_ops null_ops = { struct chan_ops null_ops = {
type: "null",
init: null_init, init: null_init,
open: null_open, open: null_open,
close: generic_close, close: generic_close,
......
...@@ -99,14 +99,13 @@ static int port_accept(struct port_list *port) ...@@ -99,14 +99,13 @@ static int port_accept(struct port_list *port)
} }
list_add(&conn->list, &port->pending); list_add(&conn->list, &port->pending);
ret = 1; return(1);
goto out;
out_free: out_free:
kfree(conn); kfree(conn);
out_close: out_close:
os_close_file(fd); os_close_file(fd);
if(pid != -1) os_kill_process(pid); if(pid != -1) os_kill_process(pid, 0);
out: out:
return(ret); return(ret);
} }
...@@ -210,9 +209,9 @@ void port_remove_dev(void *d) ...@@ -210,9 +209,9 @@ void port_remove_dev(void *d)
struct port_dev *dev = d; struct port_dev *dev = d;
if(dev->helper_pid != -1) if(dev->helper_pid != -1)
os_kill_process(dev->helper_pid); os_kill_process(dev->helper_pid, 0);
if(dev->telnetd_pid != -1) if(dev->telnetd_pid != -1)
os_kill_process(dev->telnetd_pid); os_kill_process(dev->telnetd_pid, 0);
dev->helper_pid = -1; dev->helper_pid = -1;
} }
...@@ -275,8 +274,8 @@ void port_kern_free(void *d) ...@@ -275,8 +274,8 @@ void port_kern_free(void *d)
{ {
struct port_dev *dev = d; struct port_dev *dev = d;
if(dev->helper_pid != -1) os_kill_process(dev->telnetd_pid); if(dev->helper_pid != -1) os_kill_process(dev->helper_pid, 0);
if(dev->telnetd_pid != -1) os_kill_process(dev->telnetd_pid); if(dev->telnetd_pid != -1) os_kill_process(dev->telnetd_pid, 0);
kfree(dev); kfree(dev);
} }
......
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdio.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <termios.h> #include <termios.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
...@@ -24,6 +25,7 @@ struct port_chan { ...@@ -24,6 +25,7 @@ struct port_chan {
int raw; int raw;
struct termios tt; struct termios tt;
void *kernel_data; void *kernel_data;
char dev[sizeof("32768\0")];
}; };
void *port_init(char *str, int device, struct chan_opts *opts) void *port_init(char *str, int device, struct chan_opts *opts)
...@@ -50,11 +52,12 @@ void *port_init(char *str, int device, struct chan_opts *opts) ...@@ -50,11 +52,12 @@ void *port_init(char *str, int device, struct chan_opts *opts)
if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL); if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL);
*data = ((struct port_chan) { raw : opts->raw, *data = ((struct port_chan) { raw : opts->raw,
kernel_data : kern_data }); kernel_data : kern_data });
sprintf(data->dev, "%d", port);
return(data); return(data);
} }
int port_open(int input, int output, int primary, void *d) int port_open(int input, int output, int primary, void *d, char **dev_out)
{ {
struct port_chan *data = d; struct port_chan *data = d;
int fd; int fd;
...@@ -64,6 +67,7 @@ int port_open(int input, int output, int primary, void *d) ...@@ -64,6 +67,7 @@ int port_open(int input, int output, int primary, void *d)
tcgetattr(fd, &data->tt); tcgetattr(fd, &data->tt);
raw(fd, 0); raw(fd, 0);
} }
*dev_out = data->dev;
return(fd); return(fd);
} }
...@@ -91,6 +95,7 @@ void port_free(void *d) ...@@ -91,6 +95,7 @@ void port_free(void *d)
} }
struct chan_ops port_ops = { struct chan_ops port_ops = {
type: "port",
init: port_init, init: port_init,
open: port_open, open: port_open,
close: port_close, close: port_close,
......
...@@ -19,6 +19,7 @@ struct pty_chan { ...@@ -19,6 +19,7 @@ struct pty_chan {
int dev; int dev;
int raw; int raw;
struct termios tt; struct termios tt;
char dev_name[sizeof("/dev/pts/0123456\0")];
}; };
void *pty_chan_init(char *str, int device, struct chan_opts *opts) void *pty_chan_init(char *str, int device, struct chan_opts *opts)
...@@ -32,9 +33,10 @@ void *pty_chan_init(char *str, int device, struct chan_opts *opts) ...@@ -32,9 +33,10 @@ void *pty_chan_init(char *str, int device, struct chan_opts *opts)
return(data); return(data);
} }
int pts_open(int input, int output, int primary, void *d) int pts_open(int input, int output, int primary, void *d, char **dev_out)
{ {
struct pty_chan *data = d; struct pty_chan *data = d;
char *dev;
int fd; int fd;
if((fd = get_pty()) < 0){ if((fd = get_pty()) < 0){
...@@ -45,7 +47,11 @@ int pts_open(int input, int output, int primary, void *d) ...@@ -45,7 +47,11 @@ int pts_open(int input, int output, int primary, void *d)
tcgetattr(fd, &data->tt); tcgetattr(fd, &data->tt);
raw(fd, 0); raw(fd, 0);
} }
if(data->announce) (*data->announce)(ptsname(fd), data->dev);
dev = ptsname(fd);
sprintf(data->dev_name, "%s", dev);
*dev_out = data->dev_name;
if(data->announce) (*data->announce)(dev, data->dev);
return(fd); return(fd);
} }
...@@ -94,7 +100,7 @@ static void grantpt_cb(void *arg) ...@@ -94,7 +100,7 @@ static void grantpt_cb(void *arg)
info->err = errno; info->err = errno;
} }
int pty_open(int input, int output, int primary, void *d) int pty_open(int input, int output, int primary, void *d, char **dev_out)
{ {
struct pty_chan *data = d; struct pty_chan *data = d;
int fd; int fd;
...@@ -105,11 +111,14 @@ int pty_open(int input, int output, int primary, void *d) ...@@ -105,11 +111,14 @@ int pty_open(int input, int output, int primary, void *d)
if(fd < 0) return(-errno); if(fd < 0) return(-errno);
info.fd = fd; info.fd = fd;
tracing_cb(grantpt_cb, &info); initial_thread_cb(grantpt_cb, &info);
unlockpt(fd); unlockpt(fd);
if(data->raw) raw(fd, 0); if(data->raw) raw(fd, 0);
if(data->announce) (*data->announce)(dev, data->dev); if(data->announce) (*data->announce)(dev, data->dev);
sprintf(data->dev_name, "%s", dev);
*dev_out = data->dev_name;
return(fd); return(fd);
} }
...@@ -121,6 +130,7 @@ int pty_console_write(int fd, const char *buf, int n, void *d) ...@@ -121,6 +130,7 @@ int pty_console_write(int fd, const char *buf, int n, void *d)
} }
struct chan_ops pty_ops = { struct chan_ops pty_ops = {
type: "pty",
init: pty_chan_init, init: pty_chan_init,
open: pty_open, open: pty_open,
close: generic_close, close: generic_close,
...@@ -133,6 +143,7 @@ struct chan_ops pty_ops = { ...@@ -133,6 +143,7 @@ struct chan_ops pty_ops = {
}; };
struct chan_ops pts_ops = { struct chan_ops pts_ops = {
type: "pts",
init: pty_chan_init, init: pty_chan_init,
open: pts_open, open: pts_open,
close: generic_close, close: generic_close,
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "kern.h" #include "kern.h"
#include "init.h" #include "init.h"
#include "irq_user.h" #include "irq_user.h"
#include "mconsole_kern.h"
#include "2_5compat.h" #include "2_5compat.h"
static int ssl_version = 1; static int ssl_version = 1;
...@@ -47,6 +48,10 @@ static struct chan_opts opts = { ...@@ -47,6 +48,10 @@ static struct chan_opts opts = {
in_kernel : 1, in_kernel : 1,
}; };
static int ssl_config(char *str);
static int ssl_get_config(char *dev, char *str, int size, char **error_out);
static int ssl_remove(char *str);
static struct line_driver driver = { static struct line_driver driver = {
name : "UML serial line", name : "UML serial line",
devfs_name : "tts/%d", devfs_name : "tts/%d",
...@@ -60,6 +65,12 @@ static struct line_driver driver = { ...@@ -60,6 +65,12 @@ static struct line_driver driver = {
write_irq_name : "ssl-write", write_irq_name : "ssl-write",
symlink_from : "serial", symlink_from : "serial",
symlink_to : "tts", symlink_to : "tts",
mc : {
name : "ssl",
config : ssl_config,
get_config : ssl_get_config,
remove : ssl_remove,
},
}; };
/* The array is initialized by line_init, which is an initcall. The /* The array is initialized by line_init, which is an initcall. The
...@@ -70,6 +81,25 @@ static struct line serial_lines[NR_PORTS] = ...@@ -70,6 +81,25 @@ static struct line serial_lines[NR_PORTS] =
static struct lines lines = LINES_INIT(NR_PORTS); static struct lines lines = LINES_INIT(NR_PORTS);
static int ssl_config(char *str)
{
return(line_config(serial_lines,
sizeof(serial_lines)/sizeof(serial_lines[0]), str));
}
static int ssl_get_config(char *dev, char *str, int size, char **error_out)
{
return(line_get_config(dev, serial_lines,
sizeof(serial_lines)/sizeof(serial_lines[0]),
str, size, error_out));
}
static int ssl_remove(char *str)
{
return(line_remove(serial_lines,
sizeof(serial_lines)/sizeof(serial_lines[0]), str));
}
int ssl_open(struct tty_struct *tty, struct file *filp) int ssl_open(struct tty_struct *tty, struct file *filp)
{ {
return(line_open(serial_lines, tty, &opts)); return(line_open(serial_lines, tty, &opts));
...@@ -83,12 +113,12 @@ static void ssl_close(struct tty_struct *tty, struct file * filp) ...@@ -83,12 +113,12 @@ static void ssl_close(struct tty_struct *tty, struct file * filp)
static int ssl_write(struct tty_struct * tty, int from_user, static int ssl_write(struct tty_struct * tty, int from_user,
const unsigned char *buf, int count) const unsigned char *buf, int count)
{ {
return(line_write(serial_lines, tty, buf, count)); return(line_write(serial_lines, tty, from_user, buf, count));
} }
static void ssl_put_char(struct tty_struct *tty, unsigned char ch) static void ssl_put_char(struct tty_struct *tty, unsigned char ch)
{ {
line_write(serial_lines, tty, &ch, sizeof(ch)); line_write(serial_lines, tty, 0, &ch, sizeof(ch));
} }
static void ssl_flush_chars(struct tty_struct *tty) static void ssl_flush_chars(struct tty_struct *tty)
...@@ -207,7 +237,7 @@ __initcall(ssl_init); ...@@ -207,7 +237,7 @@ __initcall(ssl_init);
static int ssl_chan_setup(char *str) static int ssl_chan_setup(char *str)
{ {
line_setup(serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]), line_setup(serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]),
str); str, 1);
return(1); return(1);
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "user_util.h" #include "user_util.h"
#include "kern_util.h" #include "kern_util.h"
#include "irq_user.h" #include "irq_user.h"
#include "mconsole_kern.h"
#include "init.h" #include "init.h"
#include "2_5compat.h" #include "2_5compat.h"
...@@ -41,6 +42,7 @@ static struct tty_driver console_driver; ...@@ -41,6 +42,7 @@ static struct tty_driver console_driver;
static int console_refcount = 0; static int console_refcount = 0;
static struct chan_ops init_console_ops = { static struct chan_ops init_console_ops = {
type: "you shouldn't see this",
init : NULL, init : NULL,
open : NULL, open : NULL,
close : NULL, close : NULL,
...@@ -78,6 +80,10 @@ static struct chan_opts opts = { ...@@ -78,6 +80,10 @@ static struct chan_opts opts = {
in_kernel : 1, in_kernel : 1,
}; };
static int con_config(char *str);
static int con_get_config(char *dev, char *str, int size, char **error_out);
static int con_remove(char *str);
static struct line_driver driver = { static struct line_driver driver = {
name : "UML console", name : "UML console",
devfs_name : "vc/%d", devfs_name : "vc/%d",
...@@ -91,6 +97,12 @@ static struct line_driver driver = { ...@@ -91,6 +97,12 @@ static struct line_driver driver = {
write_irq_name : "console-write", write_irq_name : "console-write",
symlink_from : "ttys", symlink_from : "ttys",
symlink_to : "vc", symlink_to : "vc",
mc : {
name : "con",
config : con_config,
get_config : con_get_config,
remove : con_remove,
},
}; };
static struct lines console_lines = LINES_INIT(MAX_TTYS); static struct lines console_lines = LINES_INIT(MAX_TTYS);
...@@ -102,6 +114,22 @@ struct line vts[MAX_TTYS] = { LINE_INIT(CONFIG_CON_ZERO_CHAN, &driver), ...@@ -102,6 +114,22 @@ struct line vts[MAX_TTYS] = { LINE_INIT(CONFIG_CON_ZERO_CHAN, &driver),
[ 1 ... MAX_TTYS - 1 ] = [ 1 ... MAX_TTYS - 1 ] =
LINE_INIT(CONFIG_CON_CHAN, &driver) }; LINE_INIT(CONFIG_CON_CHAN, &driver) };
static int con_config(char *str)
{
return(line_config(vts, sizeof(vts)/sizeof(vts[0]), str));
}
static int con_get_config(char *dev, char *str, int size, char **error_out)
{
return(line_get_config(dev, vts, sizeof(vts)/sizeof(vts[0]), str,
size, error_out));
}
static int con_remove(char *str)
{
return(line_remove(vts, sizeof(vts)/sizeof(vts[0]), str));
}
static int open_console(struct tty_struct *tty) static int open_console(struct tty_struct *tty)
{ {
return(line_open(vts, tty, &opts)); return(line_open(vts, tty, &opts));
...@@ -120,7 +148,7 @@ static void con_close(struct tty_struct *tty, struct file *filp) ...@@ -120,7 +148,7 @@ static void con_close(struct tty_struct *tty, struct file *filp)
static int con_write(struct tty_struct *tty, int from_user, static int con_write(struct tty_struct *tty, int from_user,
const unsigned char *buf, int count) const unsigned char *buf, int count)
{ {
return(line_write(vts, tty, buf, count)); return(line_write(vts, tty, from_user, buf, count));
} }
static void set_termios(struct tty_struct *tty, struct termios * old) static void set_termios(struct tty_struct *tty, struct termios * old)
...@@ -195,7 +223,7 @@ void stdio_console_init(void) ...@@ -195,7 +223,7 @@ void stdio_console_init(void)
static int console_chan_setup(char *str) static int console_chan_setup(char *str)
{ {
line_setup(vts, sizeof(vts)/sizeof(vts[0]), str); line_setup(vts, sizeof(vts)/sizeof(vts[0]), str, 1);
return(1); return(1);
} }
......
...@@ -30,14 +30,15 @@ void *tty_chan_init(char *str, int device, struct chan_opts *opts) ...@@ -30,14 +30,15 @@ void *tty_chan_init(char *str, int device, struct chan_opts *opts)
} }
str++; str++;
if((data = um_kmalloc(sizeof(*data))) == NULL) return(NULL); if((data = um_kmalloc(sizeof(*data))) == NULL)
return(NULL);
*data = ((struct tty_chan) { dev : str, *data = ((struct tty_chan) { dev : str,
raw : opts->raw }); raw : opts->raw });
return(data); return(data);
} }
int tty_open(int input, int output, int primary, void *d) int tty_open(int input, int output, int primary, void *d, char **dev_out)
{ {
struct tty_chan *data = d; struct tty_chan *data = d;
int fd; int fd;
...@@ -48,6 +49,8 @@ int tty_open(int input, int output, int primary, void *d) ...@@ -48,6 +49,8 @@ int tty_open(int input, int output, int primary, void *d)
tcgetattr(fd, &data->tt); tcgetattr(fd, &data->tt);
raw(fd, 0); raw(fd, 0);
} }
*dev_out = data->dev;
return(fd); return(fd);
} }
...@@ -59,6 +62,7 @@ int tty_console_write(int fd, const char *buf, int n, void *d) ...@@ -59,6 +62,7 @@ int tty_console_write(int fd, const char *buf, int n, void *d)
} }
struct chan_ops tty_ops = { struct chan_ops tty_ops = {
type: "tty",
init: tty_chan_init, init: tty_chan_init,
open: tty_open, open: tty_open,
close: generic_close, close: generic_close,
......
...@@ -574,6 +574,44 @@ static int ubd_config(char *str) ...@@ -574,6 +574,44 @@ static int ubd_config(char *str)
return(err); return(err);
} }
static int ubd_get_config(char *dev, char *str, int size, char **error_out)
{
struct ubd *ubd;
char *end;
int major, n = 0;
major = simple_strtoul(dev, &end, 0);
if((*end != '\0') || (end == dev)){
*error_out = "ubd_get_config : didn't parse major number";
return(-1);
}
if((major >= MAX_DEV) || (major < 0)){
*error_out = "ubd_get_config : major number out of range";
return(-1);
}
ubd = &ubd_dev[major];
spin_lock(&ubd_lock);
if(ubd->file == NULL){
CONFIG_CHUNK(str, size, n, "", 1);
goto out;
}
CONFIG_CHUNK(str, size, n, ubd->file, 0);
if(ubd->cow.file != NULL){
CONFIG_CHUNK(str, size, n, ",", 0);
CONFIG_CHUNK(str, size, n, ubd->cow.file, 1);
}
else CONFIG_CHUNK(str, size, n, "", 1);
out:
spin_unlock(&ubd_lock);
return(n);
}
static int ubd_remove(char *str) static int ubd_remove(char *str)
{ {
struct ubd *dev; struct ubd *dev;
...@@ -620,6 +658,7 @@ static int ubd_remove(char *str) ...@@ -620,6 +658,7 @@ static int ubd_remove(char *str)
static struct mc_device ubd_mc = { static struct mc_device ubd_mc = {
.name = "ubd", .name = "ubd",
.config = ubd_config, .config = ubd_config,
.get_config = ubd_get_config,
.remove = ubd_remove, .remove = ubd_remove,
}; };
......
...@@ -83,7 +83,7 @@ __uml_setup("xterm=", xterm_setup, ...@@ -83,7 +83,7 @@ __uml_setup("xterm=", xterm_setup,
" are 'xterm=gnome-terminal,-t,-x'.\n\n" " are 'xterm=gnome-terminal,-t,-x'.\n\n"
); );
int xterm_open(int input, int output, int primary, void *d) int xterm_open(int input, int output, int primary, void *d, char **dev_out)
{ {
struct xterm_chan *data = d; struct xterm_chan *data = d;
unsigned long stack; unsigned long stack;
...@@ -141,6 +141,7 @@ int xterm_open(int input, int output, int primary, void *d) ...@@ -141,6 +141,7 @@ int xterm_open(int input, int output, int primary, void *d)
if(data->raw) raw(new, 0); if(data->raw) raw(new, 0);
data->pid = pid; data->pid = pid;
*dev_out = NULL;
return(new); return(new);
} }
...@@ -168,6 +169,7 @@ int xterm_console_write(int fd, const char *buf, int n, void *d) ...@@ -168,6 +169,7 @@ int xterm_console_write(int fd, const char *buf, int n, void *d)
} }
struct chan_ops xterm_ops = { struct chan_ops xterm_ops = {
type: "xterm",
init: xterm_init, init: xterm_init,
open: xterm_open, open: xterm_open,
close: xterm_close, close: xterm_close,
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
struct chan { struct chan {
struct list_head list; struct list_head list;
char *dev;
unsigned int primary:1; unsigned int primary:1;
unsigned int input:1; unsigned int input:1;
unsigned int output:1; unsigned int output:1;
...@@ -38,6 +39,8 @@ extern int chan_window_size(struct list_head *chans, ...@@ -38,6 +39,8 @@ extern int chan_window_size(struct list_head *chans,
unsigned short *rows_out, unsigned short *rows_out,
unsigned short *cols_out); unsigned short *cols_out);
extern int chan_out_fd(struct list_head *chans); extern int chan_out_fd(struct list_head *chans);
extern int chan_config_string(struct list_head *chans, char *str, int size,
char **error_out);
#endif #endif
......
...@@ -19,8 +19,9 @@ struct chan_opts { ...@@ -19,8 +19,9 @@ struct chan_opts {
enum chan_init_pri { INIT_STATIC, INIT_ALL, INIT_ONE }; enum chan_init_pri { INIT_STATIC, INIT_ALL, INIT_ONE };
struct chan_ops { struct chan_ops {
char *type;
void *(*init)(char *, int, struct chan_opts *); void *(*init)(char *, int, struct chan_opts *);
int (*open)(int, int, int, void *); int (*open)(int, int, int, void *, char **);
void (*close)(int, void *); void (*close)(int, void *);
int (*read)(int, char *, void *); int (*read)(int, char *, void *);
int (*write)(int, const char *, int, void *); int (*write)(int, const char *, int, void *);
...@@ -43,7 +44,6 @@ extern void generic_free(void *data); ...@@ -43,7 +44,6 @@ extern void generic_free(void *data);
extern void register_winch(int fd, void *device_data); extern void register_winch(int fd, void *device_data);
extern void register_winch_irq(int fd, int tty_fd, int pid, void *line); extern void register_winch_irq(int fd, int tty_fd, int pid, void *line);
extern void setup_tracer_winch(void);
#define __channel_help(fn, prefix) \ #define __channel_help(fn, prefix) \
__uml_help(fn, prefix "[0-9]*=<channel description>\n" \ __uml_help(fn, prefix "[0-9]*=<channel description>\n" \
......
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __CHOOSE_MODE_H__
#define __CHOOSE_MODE_H__
#include "uml-config.h"
#if defined(CONFIG_MODE_TT) && defined(CONFIG_MODE_SKAS)
#define CHOOSE_MODE(tt, skas) (mode_tt ? (tt) : (skas))
#elif defined(CONFIG_MODE_SKAS)
#define CHOOSE_MODE(tt, skas) (skas)
#elif defined(CONFIG_MODE_TT)
#define CHOOSE_MODE(tt, skas) (tt)
#endif
#define CHOOSE_MODE_PROC(tt, skas, args...) \
CHOOSE_MODE(tt(args), skas(args))
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -8,34 +8,34 @@ ...@@ -8,34 +8,34 @@
#include "sysdep/frame.h" #include "sysdep/frame.h"
struct sc_frame { struct frame_common {
void *data; void *data;
int len; int len;
int sig_index; int sig_index;
int sc_index;
int sr_index; int sr_index;
int sr_relative; int sr_relative;
int sp_index; int sp_index;
};
struct sc_frame {
struct frame_common common;
int sc_index;
struct arch_frame_data arch; struct arch_frame_data arch;
}; };
extern struct sc_frame signal_frame_sc; extern struct sc_frame signal_frame_sc;
extern struct sc_frame signal_frame_sc_sr;
struct si_frame { struct si_frame {
void *data; struct frame_common common;
int len;
int sig_index;
int sip_index; int sip_index;
int si_index; int si_index;
int sr_index;
int sr_relative;
int sp_index;
}; };
extern struct si_frame signal_frame_si; extern struct si_frame signal_frame_si;
extern void capture_signal_stack(void); extern void capture_signal_stack(void);
extern void set_sc_ip_sp(void *sc_ptr, unsigned long ip, unsigned long sp);
#endif #endif
......
...@@ -25,7 +25,6 @@ extern void *sbrk(int increment); ...@@ -25,7 +25,6 @@ extern void *sbrk(int increment);
extern void *malloc(int size); extern void *malloc(int size);
extern void perror(char *err); extern void perror(char *err);
extern int kill(int pid, int sig); extern int kill(int pid, int sig);
extern int getpid(void);
extern int getuid(void); extern int getuid(void);
extern int pause(void); extern int pause(void);
extern int write(int, const void *, int); extern int write(int, const void *, int);
...@@ -34,6 +33,7 @@ extern int close(int); ...@@ -34,6 +33,7 @@ extern int close(int);
extern int read(unsigned int, char *, int); extern int read(unsigned int, char *, int);
extern int pipe(int *); extern int pipe(int *);
extern int sched_yield(void); extern int sched_yield(void);
extern int ptrace(int op, int pid, long addr, long data);
#endif #endif
/* /*
......
...@@ -15,23 +15,26 @@ extern char *gdb_init; ...@@ -15,23 +15,26 @@ extern char *gdb_init;
extern int kmalloc_ok; extern int kmalloc_ok;
extern int timer_irq_inited; extern int timer_irq_inited;
extern int jail; extern int jail;
extern int nsyscalls;
extern struct task_struct *idle_threads[NR_CPUS]; extern struct task_struct *idle_threads[NR_CPUS];
#define ROUND_DOWN(addr) ((void *)(((unsigned long) addr) & PAGE_MASK)) #define UML_ROUND_DOWN(addr) ((void *)(((unsigned long) addr) & PAGE_MASK))
#define ROUND_UP(addr) ROUND_DOWN(((unsigned long) addr) + PAGE_SIZE - 1) #define UML_ROUND_UP(addr) \
UML_ROUND_DOWN(((unsigned long) addr) + PAGE_SIZE - 1)
extern int kernel_fork(unsigned long flags, int (*fn)(void *), void * arg); extern int kernel_fork(unsigned long flags, int (*fn)(void *), void * arg);
extern unsigned long stack_sp(unsigned long page); extern unsigned long stack_sp(unsigned long page);
extern int kernel_thread_proc(void *data); extern int kernel_thread_proc(void *data);
extern void syscall_segv(int sig); extern void syscall_segv(int sig);
extern int current_pid(void); extern int current_pid(void);
extern void set_init_pid(int pid);
extern unsigned long alloc_stack(int order, int atomic); extern unsigned long alloc_stack(int order, int atomic);
extern int do_signal(int error); extern int do_signal(int error);
extern int is_stack_fault(unsigned long sp); extern int is_stack_fault(unsigned long sp);
extern unsigned long segv(unsigned long address, unsigned long ip, extern unsigned long segv(unsigned long address, unsigned long ip,
int is_write, int is_user, void *sc_ptr); int is_write, int is_user, void *sc);
extern int set_user_mode(void *task); extern int handle_page_fault(unsigned long address, unsigned long ip,
int is_write, int is_user, int *code_out);
extern void syscall_ready(void); extern void syscall_ready(void);
extern void set_tracing(void *t, int tracing); extern void set_tracing(void *t, int tracing);
extern int is_tracing(void *task); extern int is_tracing(void *task);
...@@ -40,7 +43,6 @@ extern void kern_finish_exec(void *task, int new_pid, unsigned long stack); ...@@ -40,7 +43,6 @@ extern void kern_finish_exec(void *task, int new_pid, unsigned long stack);
extern int page_size(void); extern int page_size(void);
extern int page_mask(void); extern int page_mask(void);
extern int need_finish_fork(void); extern int need_finish_fork(void);
extern int do_proc_op(void *t, int proc_id);
extern void free_stack(unsigned long stack, int order); extern void free_stack(unsigned long stack, int order);
extern void add_input_request(int op, void (*proc)(int), void *arg); extern void add_input_request(int op, void (*proc)(int), void *arg);
extern int sys_execve(char *file, char **argv, char **env); extern int sys_execve(char *file, char **argv, char **env);
...@@ -57,7 +59,6 @@ extern int next_trap_index(int max); ...@@ -57,7 +59,6 @@ extern int next_trap_index(int max);
extern void default_idle(void); extern void default_idle(void);
extern void finish_fork(void); extern void finish_fork(void);
extern void paging_init(void); extern void paging_init(void);
extern unsigned long um_virt_to_phys(void *t, unsigned long addr);
extern void init_flush_vm(void); extern void init_flush_vm(void);
extern void *syscall_sp(void *t); extern void *syscall_sp(void *t);
extern void syscall_trace(void); extern void syscall_trace(void);
...@@ -68,35 +69,28 @@ extern int external_pid(void *t); ...@@ -68,35 +69,28 @@ extern int external_pid(void *t);
extern int pid_to_processor_id(int pid); extern int pid_to_processor_id(int pid);
extern void boot_timer_handler(int sig); extern void boot_timer_handler(int sig);
extern void interrupt_end(void); extern void interrupt_end(void);
extern void tracing_reboot(void); extern void initial_thread_cb(void (*proc)(void *), void *arg);
extern void tracing_halt(void);
extern void tracing_cb(void (*proc)(void *), void *arg);
extern int debugger_signal(int status, int pid); extern int debugger_signal(int status, int pid);
extern void debugger_parent_signal(int status, int pid); extern void debugger_parent_signal(int status, int pid);
extern void child_signal(int pid, int status); extern void child_signal(int pid, int status);
extern int init_ptrace_proxy(int idle_pid, int startup, int stop); extern int init_ptrace_proxy(int idle_pid, int startup, int stop);
extern int init_parent_proxy(int pid); extern int init_parent_proxy(int pid);
extern int singlestepping(void *t);
extern void check_stack_overflow(void *ptr); extern void check_stack_overflow(void *ptr);
extern void relay_signal(int sig, struct uml_pt_regs *regs); extern void relay_signal(int sig, struct uml_pt_regs *regs);
extern int singlestepping(void *t);
extern void clear_singlestep(void *t);
extern void not_implemented(void); extern void not_implemented(void);
extern int user_context(unsigned long sp); extern int user_context(unsigned long sp);
extern void timer_irq(struct uml_pt_regs *regs); extern void timer_irq(struct uml_pt_regs *regs);
extern void unprotect_stack(unsigned long stack); extern void unprotect_stack(unsigned long stack);
extern void do_uml_exitcalls(void); extern void do_uml_exitcalls(void);
extern int attach_debugger(int idle_pid, int pid, int stop); extern int attach_debugger(int idle_pid, int pid, int stop);
extern void *round_up(unsigned long addr);
extern void *round_down(unsigned long addr);
extern void bad_segv(unsigned long address, unsigned long ip, int is_write); extern void bad_segv(unsigned long address, unsigned long ip, int is_write);
extern int config_gdb(char *str); extern int config_gdb(char *str);
extern int remove_gdb(void); extern int remove_gdb(void);
extern char *uml_strdup(char *string); extern char *uml_strdup(char *string);
extern void unprotect_kernel_mem(void); extern void unprotect_kernel_mem(void);
extern void protect_kernel_mem(void); extern void protect_kernel_mem(void);
extern unsigned long get_kmem_end(void);
extern void set_kmem_end(unsigned long); extern void set_kmem_end(unsigned long);
extern void set_task_sizes(int arg);
extern void uml_cleanup(void); extern void uml_cleanup(void);
extern int pid_to_processor_id(int pid); extern int pid_to_processor_id(int pid);
extern void set_current(void *t); extern void set_current(void *t);
...@@ -107,7 +101,6 @@ extern void *get_init_task(void); ...@@ -107,7 +101,6 @@ extern void *get_init_task(void);
extern int clear_user_proc(void *buf, int size); extern int clear_user_proc(void *buf, int size);
extern int copy_to_user_proc(void *to, void *from, int size); extern int copy_to_user_proc(void *to, void *from, int size);
extern int copy_from_user_proc(void *to, void *from, int size); extern int copy_from_user_proc(void *to, void *from, int size);
extern void set_thread_sc(void *sc);
extern void bus_handler(int sig, struct uml_pt_regs *regs); extern void bus_handler(int sig, struct uml_pt_regs *regs);
extern long execute_syscall(void *r); extern long execute_syscall(void *r);
extern int smp_sigio_handler(void); extern int smp_sigio_handler(void);
...@@ -116,7 +109,6 @@ extern struct task_struct *get_task(int pid, int require); ...@@ -116,7 +109,6 @@ extern struct task_struct *get_task(int pid, int require);
extern void machine_halt(void); extern void machine_halt(void);
extern int is_syscall(unsigned long addr); extern int is_syscall(unsigned long addr);
extern void arch_switch(void); extern void arch_switch(void);
extern int is_valid_pid(int pid);
extern void free_irq(unsigned int, void *); extern void free_irq(unsigned int, void *);
extern int um_in_interrupt(void); extern int um_in_interrupt(void);
extern int cpu(void); extern int cpu(void);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "linux/tty.h" #include "linux/tty.h"
#include "asm/semaphore.h" #include "asm/semaphore.h"
#include "chan_user.h" #include "chan_user.h"
#include "mconsole_kern.h"
struct line_driver { struct line_driver {
char *name; char *name;
...@@ -25,6 +26,7 @@ struct line_driver { ...@@ -25,6 +26,7 @@ struct line_driver {
char *write_irq_name; char *write_irq_name;
char *symlink_from; char *symlink_from;
char *symlink_to; char *symlink_to;
struct mc_device mc;
}; };
struct line { struct line {
...@@ -70,8 +72,9 @@ extern void line_write_interrupt(int irq, void *data, struct pt_regs *unused); ...@@ -70,8 +72,9 @@ extern void line_write_interrupt(int irq, void *data, struct pt_regs *unused);
extern void line_close(struct line *lines, struct tty_struct *tty); extern void line_close(struct line *lines, struct tty_struct *tty);
extern int line_open(struct line *lines, struct tty_struct *tty, extern int line_open(struct line *lines, struct tty_struct *tty,
struct chan_opts *opts); struct chan_opts *opts);
extern void line_setup(struct line *lines, int num, char *init); extern int line_setup(struct line *lines, int num, char *init,
extern int line_write(struct line *line, struct tty_struct *tty, int all_allowed);
extern int line_write(struct line *line, struct tty_struct *tty, int from_user,
const char *buf, int len); const char *buf, int len);
extern int line_write_room(struct tty_struct *tty); extern int line_write_room(struct tty_struct *tty);
extern char *add_xterm_umid(char *base); extern char *add_xterm_umid(char *base);
...@@ -84,6 +87,10 @@ extern void line_register_devfs(struct lines *set, ...@@ -84,6 +87,10 @@ extern void line_register_devfs(struct lines *set,
int nlines); int nlines);
extern void lines_init(struct line *lines, int nlines); extern void lines_init(struct line *lines, int nlines);
extern void close_lines(struct line *lines, int nlines); extern void close_lines(struct line *lines, int nlines);
extern int line_config(struct line *lines, int num, char *str);
extern int line_remove(struct line *lines, int num, char *str);
extern int line_get_config(char *dev, struct line *lines, int num, char *str,
int size, char **error_out);
#endif #endif
......
/* /*
* Copyright (C) 2001 Jeff Dike (jdike@karaya.com) * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
...@@ -19,9 +19,23 @@ struct mc_device { ...@@ -19,9 +19,23 @@ struct mc_device {
struct list_head list; struct list_head list;
char *name; char *name;
int (*config)(char *); int (*config)(char *);
int (*get_config)(char *, char *, int, char **);
int (*remove)(char *); int (*remove)(char *);
}; };
#define CONFIG_CHUNK(str, size, current, chunk, end) \
do { \
current += strlen(chunk); \
if(current >= size) \
str = NULL; \
if(str != NULL){ \
strcpy(str, chunk); \
str += strlen(chunk); \
} \
if(end) \
current++; \
} while(0)
#ifdef CONFIG_MCONSOLE #ifdef CONFIG_MCONSOLE
extern void mconsole_register_dev(struct mc_device *new); extern void mconsole_register_dev(struct mc_device *new);
......
...@@ -13,6 +13,7 @@ struct vm_reserved { ...@@ -13,6 +13,7 @@ struct vm_reserved {
}; };
extern void set_usable_vm(unsigned long start, unsigned long end); extern void set_usable_vm(unsigned long start, unsigned long end);
extern void set_kmem_end(unsigned long new);
#endif #endif
......
...@@ -54,11 +54,6 @@ extern int create_mem_file(unsigned long len); ...@@ -54,11 +54,6 @@ extern int create_mem_file(unsigned long len);
extern void setup_range(int fd, char *driver, unsigned long start, extern void setup_range(int fd, char *driver, unsigned long start,
unsigned long pfn, unsigned long total, int need_vm, unsigned long pfn, unsigned long total, int need_vm,
struct mem_region *region, void *reserved); struct mem_region *region, void *reserved);
extern void map(unsigned long virt, unsigned long p, unsigned long len,
int r, int w, int x);
extern int unmap(void *addr, int len);
extern int protect(unsigned long addr, unsigned long len, int r, int w,
int x, int must_succeed);
extern void setup_memory(void *entry); extern void setup_memory(void *entry);
extern unsigned long find_iomem(char *driver, unsigned long *len_out); extern unsigned long find_iomem(char *driver, unsigned long *len_out);
extern int init_maps(struct mem_region *region); extern int init_maps(struct mem_region *region);
...@@ -68,10 +63,15 @@ extern unsigned long get_vm(unsigned long len); ...@@ -68,10 +63,15 @@ extern unsigned long get_vm(unsigned long len);
extern void setup_physmem(unsigned long start, unsigned long usable, extern void setup_physmem(unsigned long start, unsigned long usable,
unsigned long len); unsigned long len);
extern int setup_region(struct mem_region *region, void *entry); extern int setup_region(struct mem_region *region, void *entry);
extern void add_iomem(char *name, int fd, int size); extern void add_iomem(char *name, int fd, unsigned long size);
extern struct mem_region *phys_region(unsigned long phys); extern struct mem_region *phys_region(unsigned long phys);
extern unsigned long phys_offset(unsigned long phys); extern unsigned long phys_offset(unsigned long phys);
extern void unmap_physmem(void); extern void unmap_physmem(void);
extern int map_memory(unsigned long virt, unsigned long phys,
unsigned long len, int r, int w, int x);
extern int protect_memory(unsigned long addr, unsigned long len,
int r, int w, int x, int must_succeed);
extern unsigned long get_kmem_end(void);
#endif #endif
......
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __MODE_H__
#define __MODE_H__
#include "uml-config.h"
#ifdef CONFIG_MODE_TT
#include "../kernel/tt/include/mode.h"
#endif
#ifdef CONFIG_MODE_SKAS
#include "../kernel/skas/include/mode.h"
#endif
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __MODE_KERN_H__
#define __MODE_KERN_H__
#include "linux/config.h"
#ifdef CONFIG_MODE_TT
#include "../kernel/tt/include/mode_kern.h"
#endif
#ifdef CONFIG_MODE_SKAS
#include "../kernel/skas/include/mode_kern.h"
#endif
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -103,10 +103,16 @@ extern int os_write_file(int fd, char *buf, int count); ...@@ -103,10 +103,16 @@ extern int os_write_file(int fd, char *buf, int count);
extern unsigned long os_process_pc(int pid); extern unsigned long os_process_pc(int pid);
extern int os_process_parent(int pid); extern int os_process_parent(int pid);
extern void os_stop_process(int pid); extern void os_stop_process(int pid);
extern void os_kill_process(int pid); extern void os_kill_process(int pid, int reap_child);
extern void os_usr1_process(int pid); extern void os_usr1_process(int pid);
extern int os_getpid(void); extern int os_getpid(void);
extern int os_map_memory(void *virt, int fd, unsigned long off,
unsigned long len, int r, int w, int x);
extern int os_protect_memory(void *addr, unsigned long len,
int r, int w, int x);
extern int os_unmap_memory(void *addr, int len);
#endif #endif
/* /*
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#include "sysdep/sigcontext.h" #include "sysdep/sigcontext.h"
extern int sc_size(void *data); extern int sc_size(void *data);
extern int copy_sc_to_user(void *to_ptr, void *from_ptr, void *data);
extern int copy_sc_from_user(void *to_ptr, void *from_ptr, void *data);
extern void sc_to_sc(void *to_ptr, void *from_ptr); extern void sc_to_sc(void *to_ptr, void *from_ptr);
#endif #endif
......
/* /*
* Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#ifndef __SYSCALL_USER_H__ #ifndef __SYSCALL_USER_H
#define __SYSCALL_USER_H__ #define __SYSCALL_USER_H
#include <asm/sigcontext.h> extern int record_syscall_start(int syscall);
extern void record_syscall_end(int index, int result);
extern void syscall_handler(int sig, struct uml_pt_regs *regs);
extern void exit_kernel(int pid, void *task);
extern int do_syscall(void *task, int pid);
#endif #endif
......
/*
* Licensed under the GPL
*/
#ifndef __UM_SYSDEP_CHECKSUM_H
#define __UM_SYSDEP_CHECKSUM_H
#include "linux/string.h"
/*
* computes the checksum of a memory block at buff, length len,
* and adds in "sum" (32-bit)
*
* returns a 32-bit number suitable for feeding into itself
* or csum_tcpudp_magic
*
* this function must be called with even lengths, except
* for the last fragment, which may be odd
*
* it's best to have buff aligned on a 32-bit boundary
*/
unsigned int csum_partial(const unsigned char * buff, int len,
unsigned int sum);
/*
* the same as csum_partial, but copies from src while it
* checksums, and handles user-space pointer exceptions correctly, when needed.
*
* here even more important to align src and dst on a 32-bit (or even
* better 64-bit) boundary
*/
unsigned int csum_partial_copy_to(const char *src, char *dst, int len,
int sum, int *err_ptr);
unsigned int csum_partial_copy_from(const char *src, char *dst, int len,
int sum, int *err_ptr);
/*
* Note: when you get a NULL pointer exception here this means someone
* passed in an incorrect kernel address to one of these functions.
*
* If you use these functions directly please don't forget the
* verify_area().
*/
static __inline__
unsigned int csum_partial_copy_nocheck(const char *src, char *dst,
int len, int sum)
{
memcpy(dst, src, len);
return(csum_partial(dst, len, sum));
}
static __inline__
unsigned int csum_partial_copy_from_user(const char *src, char *dst,
int len, int sum, int *err_ptr)
{
return csum_partial_copy_from(src, dst, len, sum, err_ptr);
}
/*
* These are the old (and unsafe) way of doing checksums, a warning message
* will be printed if they are used and an exeption occurs.
*
* these functions should go away after some time.
*/
#define csum_partial_copy_fromuser csum_partial_copy_from_user
unsigned int csum_partial_copy( const char *src, char *dst, int len, int sum);
/*
* This is a version of ip_compute_csum() optimized for IP headers,
* which always checksum on 4 octet boundaries.
*
* By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
* Arnt Gulbrandsen.
*/
static inline unsigned short ip_fast_csum(unsigned char * iph,
unsigned int ihl)
{
unsigned int sum;
__asm__ __volatile__(
"movl (%1), %0 ;\n"
"subl $4, %2 ;\n"
"jbe 2f ;\n"
"addl 4(%1), %0 ;\n"
"adcl 8(%1), %0 ;\n"
"adcl 12(%1), %0 ;\n"
"1: adcl 16(%1), %0 ;\n"
"lea 4(%1), %1 ;\n"
"decl %2 ;\n"
"jne 1b ;\n"
"adcl $0, %0 ;\n"
"movl %0, %2 ;\n"
"shrl $16, %0 ;\n"
"addw %w2, %w0 ;\n"
"adcl $0, %0 ;\n"
"notl %0 ;\n"
"2: ;\n"
/* Since the input registers which are loaded with iph and ipl
are modified, we must also specify them as outputs, or gcc
will assume they contain their original values. */
: "=r" (sum), "=r" (iph), "=r" (ihl)
: "1" (iph), "2" (ihl));
return(sum);
}
/*
* Fold a partial checksum
*/
static inline unsigned int csum_fold(unsigned int sum)
{
__asm__(
"addl %1, %0 ;\n"
"adcl $0xffff, %0 ;\n"
: "=r" (sum)
: "r" (sum << 16), "0" (sum & 0xffff0000)
);
return (~sum) >> 16;
}
static inline unsigned long csum_tcpudp_nofold(unsigned long saddr,
unsigned long daddr,
unsigned short len,
unsigned short proto,
unsigned int sum)
{
__asm__(
"addl %1, %0 ;\n"
"adcl %2, %0 ;\n"
"adcl %3, %0 ;\n"
"adcl $0, %0 ;\n"
: "=r" (sum)
: "g" (daddr), "g"(saddr), "g"((ntohs(len)<<16)+proto*256), "0"(sum));
return sum;
}
/*
* computes the checksum of the TCP/UDP pseudo-header
* returns a 16-bit checksum, already complemented
*/
static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
unsigned long daddr,
unsigned short len,
unsigned short proto,
unsigned int sum)
{
return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
}
/*
* this routine is used for miscellaneous IP-like checksums, mainly
* in icmp.c
*/
static inline unsigned short ip_compute_csum(unsigned char * buff, int len)
{
return csum_fold (csum_partial(buff, len, 0));
}
#define _HAVE_ARCH_IPV6_CSUM
static __inline__ unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
struct in6_addr *daddr,
__u32 len,
unsigned short proto,
unsigned int sum)
{
__asm__(
"addl 0(%1), %0 ;\n"
"adcl 4(%1), %0 ;\n"
"adcl 8(%1), %0 ;\n"
"adcl 12(%1), %0 ;\n"
"adcl 0(%2), %0 ;\n"
"adcl 4(%2), %0 ;\n"
"adcl 8(%2), %0 ;\n"
"adcl 12(%2), %0 ;\n"
"adcl %3, %0 ;\n"
"adcl %4, %0 ;\n"
"adcl $0, %0 ;\n"
: "=&r" (sum)
: "r" (saddr), "r" (daddr),
"r"(htonl(len)), "r"(htonl(proto)), "0"(sum));
return csum_fold(sum);
}
/*
* Copy and checksum to user
*/
#define HAVE_CSUM_COPY_USER
static __inline__ unsigned int csum_and_copy_to_user(const char *src,
char *dst, int len,
int sum, int *err_ptr)
{
if (access_ok(VERIFY_WRITE, dst, len))
return(csum_partial_copy_to(src, dst, len, sum, err_ptr));
if (len)
*err_ptr = -EFAULT;
return -1; /* invalid checksum */
}
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -20,7 +20,8 @@ static inline void *sp_to_rt_sc(unsigned long sp) ...@@ -20,7 +20,8 @@ static inline void *sp_to_rt_sc(unsigned long sp)
{ {
unsigned long sc; unsigned long sc;
sc = sp - signal_frame_si.sp_index + signal_frame_si.len - 4; sc = sp - signal_frame_si.common.sp_index +
signal_frame_si.common.len - 4;
return((void *) sc); return((void *) sc);
} }
...@@ -28,7 +29,8 @@ static inline void *sp_to_mask(unsigned long sp) ...@@ -28,7 +29,8 @@ static inline void *sp_to_mask(unsigned long sp)
{ {
unsigned long mask; unsigned long mask;
mask = sp - signal_frame_sc.sp_index + signal_frame_sc.len - 8; mask = sp - signal_frame_sc.common.sp_index +
signal_frame_sc.common.len - 8;
return((void *) mask); return((void *) mask);
} }
...@@ -38,7 +40,8 @@ static inline void *sp_to_rt_mask(unsigned long sp) ...@@ -38,7 +40,8 @@ static inline void *sp_to_rt_mask(unsigned long sp)
{ {
unsigned long mask; unsigned long mask;
mask = sp - signal_frame_si.sp_index + signal_frame_si.len + mask = sp - signal_frame_si.common.sp_index +
signal_frame_si.common.len +
sc_size(&signal_frame_sc.arch) - 4; sc_size(&signal_frame_sc.arch) - 4;
return((void *) mask); return((void *) mask);
} }
......
/* /*
* Copyright (C) 2000 Jeff Dike (jdike@karaya.com) * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#ifndef __SYSDEP_I386_PTRACE_H #ifndef __SYSDEP_I386_PTRACE_H
#define __SYSDEP_I386_PTRACE_H #define __SYSDEP_I386_PTRACE_H
#include "sysdep/sc.h" #include "uml-config.h"
#include "ptrace-tt.h"
#include "ptrace-skas.h"
#include "choose-mode.h"
struct uml_pt_regs { struct uml_pt_regs {
unsigned long args[6]; unsigned long args[6];
long syscall; long syscall;
int is_user; int is_user;
void *sc; union {
#ifdef CONFIG_MODE_TT
void *tt;
#endif
#ifdef CONFIG_MODE_SKAS
struct {
unsigned long regs[HOST_FRAME_SIZE];
unsigned long fp[HOST_FP_SIZE];
unsigned long xfp[HOST_XFP_SIZE];
unsigned long fault_addr;
unsigned long fault_type;
unsigned long trap_type;
} skas;
#endif
} mode;
}; };
#define EMPTY_UML_PT_REGS { \ #define EMPTY_UML_PT_REGS { \
syscall : -1, \ syscall : -1, \
args : { [0 ... 5] = 0 }, \ args : { [0 ... 5] = 0 }, \
is_user : 0, \ is_user : 0 }
sc : NULL }
extern int mode_tt;
#define UPT_IP(regs) SC_IP((regs)->sc)
#define UPT_SP(regs) SC_SP((regs)->sc) #define UPT_IP(r) \
#define UPT_EFLAGS(regs) SC_EFLAGS((regs)->sc) CHOOSE_MODE(SC_IP((r)->mode.tt), REGS_IP((r)->mode.skas.regs))
#define UPT_EAX(regs) SC_EAX((regs)->sc) #define UPT_SP(r) \
#define UPT_EBX(regs) SC_EBX((regs)->sc) CHOOSE_MODE(SC_SP((r)->mode.tt), REGS_SP((r)->mode.skas.regs))
#define UPT_ECX(regs) SC_ECX((regs)->sc) #define UPT_EFLAGS(r) \
#define UPT_EDX(regs) SC_EDX((regs)->sc) CHOOSE_MODE(SC_EFLAGS((r)->mode.tt), REGS_EFLAGS((r)->mode.skas.regs))
#define UPT_ESI(regs) SC_ESI((regs)->sc) #define UPT_EAX(r) \
#define UPT_EDI(regs) SC_EDI((regs)->sc) CHOOSE_MODE(SC_EAX((r)->mode.tt), REGS_EAX((r)->mode.skas.regs))
#define UPT_EBP(regs) SC_EBP((regs)->sc) #define UPT_EBX(r) \
#define UPT_ORIG_EAX(regs) ((regs)->syscall) CHOOSE_MODE(SC_EBX((r)->mode.tt), REGS_EBX((r)->mode.skas.regs))
#define UPT_CS(regs) SC_CS((regs)->sc) #define UPT_ECX(r) \
#define UPT_SS(regs) SC_SS((regs)->sc) CHOOSE_MODE(SC_ECX((r)->mode.tt), REGS_ECX((r)->mode.skas.regs))
#define UPT_DS(regs) SC_DS((regs)->sc) #define UPT_EDX(r) \
#define UPT_ES(regs) SC_ES((regs)->sc) CHOOSE_MODE(SC_EDX((r)->mode.tt), REGS_EDX((r)->mode.skas.regs))
#define UPT_FS(regs) SC_FS((regs)->sc) #define UPT_ESI(r) \
#define UPT_GS(regs) SC_GS((regs)->sc) CHOOSE_MODE(SC_ESI((r)->mode.tt), REGS_ESI((r)->mode.skas.regs))
#define UPT_SC(regs) ((regs)->sc) #define UPT_EDI(r) \
CHOOSE_MODE(SC_EDI((r)->mode.tt), REGS_EDI((r)->mode.skas.regs))
#define UPT_EBP(r) \
CHOOSE_MODE(SC_EBP((r)->mode.tt), REGS_EBP((r)->mode.skas.regs))
#define UPT_ORIG_EAX(r) ((r)->syscall)
#define UPT_CS(r) \
CHOOSE_MODE(SC_CS((r)->mode.tt), REGS_CS((r)->mode.skas.regs))
#define UPT_SS(r) \
CHOOSE_MODE(SC_SS((r)->mode.tt), REGS_SS((r)->mode.skas.regs))
#define UPT_DS(r) \
CHOOSE_MODE(SC_DS((r)->mode.tt), REGS_DS((r)->mode.skas.regs))
#define UPT_ES(r) \
CHOOSE_MODE(SC_ES((r)->mode.tt), REGS_ES((r)->mode.skas.regs))
#define UPT_FS(r) \
CHOOSE_MODE(SC_FS((r)->mode.tt), REGS_FS((r)->mode.skas.regs))
#define UPT_GS(r) \
CHOOSE_MODE(SC_GS((r)->mode.tt), REGS_GS((r)->mode.skas.regs))
#define UPT_SC(r) ((r)->mode.tt)
#define UPT_REG(regs, reg) \ #define UPT_REG(regs, reg) \
({ unsigned long val; \ ({ unsigned long val; \
...@@ -94,12 +128,29 @@ struct uml_pt_regs { ...@@ -94,12 +128,29 @@ struct uml_pt_regs {
} \ } \
} while (0) } while (0)
#define UPT_SET_SYSCALL_RETURN(regs, res) \ #define UPT_SET_SYSCALL_RETURN(r, res) \
SC_SET_SYSCALL_RETURN((regs)->sc, (res)) CHOOSE_MODE(SC_SET_SYSCALL_RETURN((r)->mode.tt, (res)), \
#define UPT_RESTART_SYSCALL(regs) SC_RESTART_SYSCALL((regs)->sc) REGS_SET_SYSCALL_RETURN((r)->mode.skas.regs, (res)))
#define UPT_ORIG_SYSCALL(regs) UPT_EAX(regs)
#define UPT_SYSCALL_NR(regs) ((regs)->syscall) #define UPT_RESTART_SYSCALL(r) \
#define UPT_SYSCALL_RET(regs) UPT_EAX(regs) CHOOSE_MODE(SC_RESTART_SYSCALL((r)->mode.tt), \
REGS_RESTART_SYSCALL((r)->mode.skas.regs))
#define UPT_ORIG_SYSCALL(r) UPT_EAX(r)
#define UPT_SYSCALL_NR(r) ((r)->syscall)
#define UPT_SYSCALL_RET(r) UPT_EAX(r)
#define UPT_SEGV_IS_FIXABLE(r) \
CHOOSE_MODE(SC_SEGV_IS_FIXABLE(r->mode.tt), \
REGS_SEGV_IS_FIXABLE(&r->mode.skas))
#define UPT_FAULT_ADDR(r) \
CHOOSE_MODE(SC_FAULT_ADDR(r->mode.tt), \
REGS_FAULT_ADDR(&r->mode.skas))
#define UPT_FAULT_WRITE(r) \
CHOOSE_MODE(SC_FAULT_WRITE(r->mode.tt), \
REGS_FAULT_WRITE(&r->mode.skas))
#endif #endif
......
...@@ -6,13 +6,22 @@ ...@@ -6,13 +6,22 @@
#ifndef __SYS_SIGCONTEXT_I386_H #ifndef __SYS_SIGCONTEXT_I386_H
#define __SYS_SIGCONTEXT_I386_H #define __SYS_SIGCONTEXT_I386_H
#include "sc.h"
#define IP_RESTART_SYSCALL(ip) ((ip) -= 2) #define IP_RESTART_SYSCALL(ip) ((ip) -= 2)
#define SC_RESTART_SYSCALL(sc) IP_RESTART_SYSCALL(SC_IP(sc)) #define SC_RESTART_SYSCALL(sc) IP_RESTART_SYSCALL(SC_IP(sc))
#define SC_SET_SYSCALL_RETURN(sc, result) do SC_EAX(sc) = (result) ; while(0) #define SC_SET_SYSCALL_RETURN(sc, result) SC_EAX(sc) = (result)
#define SC_FAULT_ADDR(sc) SC_CR2(sc) #define SC_FAULT_ADDR(sc) SC_CR2(sc)
#define SC_FAULT_WRITE(sc) (SC_ERR(sc) & 2) #define SC_FAULT_TYPE(sc) SC_ERR(sc)
#define FAULT_WRITE(err) (err & 2)
#define TO_SC_ERR(is_write) ((is_write) ? 2 : 0)
#define SC_FAULT_WRITE(sc) (FAULT_WRITE(SC_ERR(sc)))
#define SC_TRAP_TYPE(sc) SC_TRAPNO(sc)
/* ptrace expects that, at the start of a system call, %eax contains /* ptrace expects that, at the start of a system call, %eax contains
* -ENOSYS, so this makes it so. * -ENOSYS, so this makes it so.
...@@ -20,10 +29,12 @@ ...@@ -20,10 +29,12 @@
#define SC_START_SYSCALL(sc) do SC_EAX(sc) = -ENOSYS; while(0) #define SC_START_SYSCALL(sc) do SC_EAX(sc) = -ENOSYS; while(0)
/* These are General Protection and Page Fault */ /* These are General Protection and Page Fault */
#define SEGV_IS_FIXABLE(sc) ((SC_TRAPNO(sc) == 13) || (SC_TRAPNO(sc) == 14)) #define SEGV_IS_FIXABLE(trap) ((trap == 13) || (trap == 14))
/* XXX struct sigcontext needs declaring by now */ #define SC_SEGV_IS_FIXABLE(sc) (SEGV_IS_FIXABLE(SC_TRAPNO(sc)))
#ifdef CONFIG_MODE_TT
/* XXX struct sigcontext needs declaring by now */
static inline void sc_to_regs(struct uml_pt_regs *regs, struct sigcontext *sc, static inline void sc_to_regs(struct uml_pt_regs *regs, struct sigcontext *sc,
unsigned long syscall) unsigned long syscall)
{ {
...@@ -35,6 +46,20 @@ static inline void sc_to_regs(struct uml_pt_regs *regs, struct sigcontext *sc, ...@@ -35,6 +46,20 @@ static inline void sc_to_regs(struct uml_pt_regs *regs, struct sigcontext *sc,
regs->args[4] = SC_EDI(sc); regs->args[4] = SC_EDI(sc);
regs->args[5] = SC_EBP(sc); regs->args[5] = SC_EBP(sc);
} }
#endif
#ifdef CONFIG_MODE_SKAS
static inline void host_to_regs(struct uml_pt_regs *regs)
{
regs->syscall = UPT_ORIG_EAX(regs);
regs->args[0] = UPT_EBX(regs);
regs->args[1] = UPT_ECX(regs);
regs->args[2] = UPT_EDX(regs);
regs->args[3] = UPT_ESI(regs);
regs->args[4] = UPT_EDI(regs);
regs->args[5] = UPT_EBP(regs);
}
#endif
extern unsigned long *sc_sigmask(void *sc_ptr); extern unsigned long *sc_sigmask(void *sc_ptr);
extern int sc_get_fpregs(unsigned long buf, void *sc_ptr); extern int sc_get_fpregs(unsigned long buf, void *sc_ptr);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
extern void timer(void); extern void timer(void);
extern void switch_timers(int to_real); extern void switch_timers(int to_real);
extern void user_time_init(void); extern void set_interval(int timer_type);
extern void idle_sleep(int secs); extern void idle_sleep(int secs);
extern void enable_timer(void); extern void enable_timer(void);
extern void time_lock(void); extern void time_lock(void);
......
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __ARCH_UM_MMU_H
#define __ARCH_UM_MMU_H
#include "linux/config.h"
#include "choose-mode.h"
#ifdef CONFIG_MODE_TT
#include "../kernel/tt/include/mmu.h"
#endif
#ifdef CONFIG_MODE_SKAS
#include "../kernel/skas/include/mmu.h"
#endif
typedef union {
#ifdef CONFIG_MODE_TT
struct mmu_context_tt tt;
#endif
#ifdef CONFIG_MODE_SKAS
struct mmu_context_skas skas;
#endif
} mm_context_t;
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __ARCH_UM_UACCESS_H
#define __ARCH_UM_UACCESS_H
#include "linux/config.h"
#include "choose-mode.h"
#ifdef CONFIG_MODE_TT
#include "../kernel/tt/include/uaccess.h"
#endif
#ifdef CONFIG_MODE_SKAS
#include "../kernel/skas/include/uaccess.h"
#endif
#define access_ok(type, addr, size) \
CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size)
static inline int verify_area(int type, const void * addr, unsigned long size)
{
return(CHOOSE_MODE_PROC(verify_area_tt, verify_area_skas, type, addr,
size));
}
static inline int copy_from_user(void *to, const void *from, int n)
{
return(CHOOSE_MODE_PROC(copy_from_user_tt, copy_from_user_skas, to,
from, n));
}
static inline int copy_to_user(void *to, const void *from, int n)
{
return(CHOOSE_MODE_PROC(copy_to_user_tt, copy_to_user_skas, to,
from, n));
}
static inline int strncpy_from_user(char *dst, const char *src, int count)
{
return(CHOOSE_MODE_PROC(strncpy_from_user_tt, strncpy_from_user_skas,
dst, src, count));
}
static inline int __clear_user(void *mem, int len)
{
return(CHOOSE_MODE_PROC(__clear_user_tt, __clear_user_skas, mem, len));
}
static inline int clear_user(void *mem, int len)
{
return(CHOOSE_MODE_PROC(clear_user_tt, clear_user_skas, mem, len));
}
static inline int strnlen_user(const void *str, int len)
{
return(CHOOSE_MODE_PROC(strnlen_user_tt, strnlen_user_skas, str, len));
}
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "sysdep/ptrace.h" #include "sysdep/ptrace.h"
extern int mode_tt;
extern int grantpt(int __fd); extern int grantpt(int __fd);
extern int unlockpt(int __fd); extern int unlockpt(int __fd);
extern char *ptsname(int __fd); extern char *ptsname(int __fd);
...@@ -21,6 +23,13 @@ struct cpu_task { ...@@ -21,6 +23,13 @@ struct cpu_task {
extern struct cpu_task cpu_tasks[]; extern struct cpu_task cpu_tasks[];
struct signal_info {
void (*handler)(int, struct uml_pt_regs *);
int is_irq;
};
extern struct signal_info sig_info[];
extern unsigned long low_physmem; extern unsigned long low_physmem;
extern unsigned long high_physmem; extern unsigned long high_physmem;
extern unsigned long uml_physmem; extern unsigned long uml_physmem;
...@@ -29,16 +38,11 @@ extern unsigned long end_vm; ...@@ -29,16 +38,11 @@ extern unsigned long end_vm;
extern unsigned long start_vm; extern unsigned long start_vm;
extern unsigned long highmem; extern unsigned long highmem;
extern int tracing_pid;
extern int honeypot;
extern char host_info[]; extern char host_info[];
extern char saved_command_line[]; extern char saved_command_line[];
extern char command_line[]; extern char command_line[];
extern int gdb_pid;
extern char *tempdir; extern char *tempdir;
extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end; extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end;
...@@ -51,12 +55,10 @@ extern int pty_close_sigio; ...@@ -51,12 +55,10 @@ extern int pty_close_sigio;
extern void stop(void); extern void stop(void);
extern void stack_protections(unsigned long address); extern void stack_protections(unsigned long address);
extern void task_protections(unsigned long address); extern void task_protections(unsigned long address);
extern int signals(int (*init_proc)(void *), void *sp);
extern int wait_for_stop(int pid, int sig, int cont_type, void *relay); extern int wait_for_stop(int pid, int sig, int cont_type, void *relay);
extern void *add_signal_handler(int sig, void (*handler)(int)); extern void *add_signal_handler(int sig, void (*handler)(int));
extern int start_fork_tramp(void *arg, unsigned long temp_stack, extern int start_fork_tramp(void *arg, unsigned long temp_stack,
int clone_flags, int (*tramp)(void *)); int clone_flags, int (*tramp)(void *));
extern void trace_myself(void);
extern int clone_and_wait(int (*fn)(void *), void *arg, void *sp, int flags); extern int clone_and_wait(int (*fn)(void *), void *arg, void *sp, int flags);
extern int linux_main(int argc, char **argv); extern int linux_main(int argc, char **argv);
extern void remap_data(void *segment_start, void *segment_end, int w); extern void remap_data(void *segment_start, void *segment_end, int w);
...@@ -69,13 +71,12 @@ extern int switcheroo(int fd, int prot, void *from, void *to, int size); ...@@ -69,13 +71,12 @@ extern int switcheroo(int fd, int prot, void *from, void *to, int size);
extern void setup_machinename(char *machine_out); extern void setup_machinename(char *machine_out);
extern void setup_hostinfo(void); extern void setup_hostinfo(void);
extern void add_arg(char *cmd_line, char *arg); extern void add_arg(char *cmd_line, char *arg);
extern void init_new_thread(void *sig_stack, void (*usr1_handler)(int)); extern void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int));
extern void attach_process(int pid); extern void init_new_thread_signals(int altstack);
extern int fork_tramp(void *sig_stack);
extern void do_exec(int old_pid, int new_pid); extern void do_exec(int old_pid, int new_pid);
extern void tracer_panic(char *msg, ...); extern void tracer_panic(char *msg, ...);
extern char *get_umid(int only_if_set); extern char *get_umid(int only_if_set);
extern void do_longjmp(void *p); extern void do_longjmp(void *p, int val);
extern void suspend_new_thread(int fd); extern void suspend_new_thread(int fd);
extern int detach(int pid, int sig); extern int detach(int pid, int sig);
extern int attach(int pid); extern int attach(int pid);
...@@ -89,7 +90,8 @@ extern void arch_check_bugs(void); ...@@ -89,7 +90,8 @@ extern void arch_check_bugs(void);
extern int arch_handle_signal(int sig, struct uml_pt_regs *regs); extern int arch_handle_signal(int sig, struct uml_pt_regs *regs);
extern int arch_fixup(unsigned long address, void *sc_ptr); extern int arch_fixup(unsigned long address, void *sc_ptr);
extern void forward_pending_sigio(int target); extern void forward_pending_sigio(int target);
extern int can_do_skas(void);
#endif #endif
/* /*
......
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
EXTRA_TARGETS := unmap_fin.o EXTRA_TARGETS := unmap_fin.o
obj-y = config.o exec_kern.o exec_user.o exitcode.o frame_kern.o frame.o \ obj-y = checksum.o config.o exec_kern.o exitcode.o frame_kern.o frame.o \
helper.o init_task.o irq.o irq_user.o ksyms.o mem.o mem_user.o \ helper.o init_task.o irq.o irq_user.o ksyms.o mem.o mem_user.o \
process.o process_kern.o ptrace.o reboot.o resource.o sigio_user.o \ process.o process_kern.o ptrace.o reboot.o resource.o sigio_user.o \
sigio_kern.o signal_kern.o signal_user.o smp.o syscall_kern.o \ sigio_kern.o signal_kern.o signal_user.o smp.o syscall_kern.o \
syscall_user.o sysrq.o sys_call_table.o tempfile.o time.o \ syscall_user.o sysrq.o sys_call_table.o tempfile.o time.o \
time_kern.o tlb.o trap_kern.o trap_user.o uaccess_user.o um_arch.o \ time_kern.o tlb.o trap_kern.o trap_user.o um_arch.o \
umid.o user_util.o umid.o user_util.o
obj-$(CONFIG_BLK_DEV_INITRD) += initrd_kern.o initrd_user.o obj-$(CONFIG_BLK_DEV_INITRD) += initrd_kern.o initrd_user.o
obj-$(CONFIG_GPROF) += gprof_syms.o
obj-$(CONFIG_GCOV) += gmon_syms.o
obj-$(CONFIG_TTY_LOG) += tty_log.o
obj-$(CONFIG_MODE_TT) += tt/
obj-$(CONFIG_MODE_SKAS) += skas/
user-objs-$(CONFIG_TTY_LOG) += tty_log.o
# user_syms.o not included here because Rules.make has its own ideas about # user_syms.o not included here because Rules.make has its own ideas about
# building anything in export-objs # building anything in export-objs
USER_OBJS := $(filter %_user.o,$(obj-y)) config.o helper.o process.o \ USER_OBJS := $(filter %_user.o,$(obj-y)) $(user-objs-y) config.o helper.o \
tempfile.o time.o tty_log.o umid.o user_util.o user_syms.o process.o tempfile.o time.o tty_log.o umid.o user_util.o user_syms.o
USER_OBJS := $(foreach file,$(USER_OBJS),arch/um/kernel/$(file)) USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
export-objs := ksyms.o process_kern.o signal_kern.o gprof_syms.o gmon_syms.o
UNMAP_CFLAGS := $(patsubst -pg -DPROFILING,,$(USER_CFLAGS)) UNMAP_CFLAGS := $(patsubst -pg -DPROFILING,,$(USER_CFLAGS))
UNMAP_CFLAGS := $(patsubst -fprofile-arcs -ftest-coverage,,$(UNMAP_CFLAGS)) UNMAP_CFLAGS := $(patsubst -fprofile-arcs -ftest-coverage,,$(UNMAP_CFLAGS))
ifeq ($(CONFIG_MODULES), y) DMODULES-$(CONFIG_MODULES) = -D__CONFIG_MODULES__
DMODULES = -D__CONFIG_MODULES__ DMODVERSIONS-$(CONFIG_MODVERSIONS) = -D__CONFIG_MODVERSIONS__
endif
ifeq ($(CONFIG_MODVERSIONS), y) export-objs-$(CONFIG_GPROF) += gprof_syms.o
DMODVERSIONS = -D__CONFIG_MODVERSIONS__ export-objs-$(CONFIG_GCOV) += gmon_syms.o
endif
obj-$(CONFIG_GPROF) += gprof_syms.o export-objs := ksyms.o process_kern.o signal_kern.o $(export-objs-y)
obj-$(CONFIG_GCOV) += gmon_syms.o
obj-$(CONFIG_TTY_LOG) += tty_log.o
CFLAGS_user_syms.o = -D__AUTOCONF_INCLUDED__ $(DMODULES) $(DMODVERSIONS) \ CFLAGS_user_syms.o = -D__AUTOCONF_INCLUDED__ $(DMODULES-y) $(DMODVERSIONS-y) \
-I/usr/include -I../include -I/usr/include -I../include
CFLAGS_frame.o := $(patsubst -fomit-frame-pointer,,$(USER_CFLAGS)) CFLAGS_frame.o := $(patsubst -fomit-frame-pointer,,$(USER_CFLAGS))
...@@ -44,27 +51,28 @@ include $(TOPDIR)/Rules.make ...@@ -44,27 +51,28 @@ include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c $(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $< $(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $<
arch/um/kernel/unmap.o: arch/um/kernel/unmap.c $(obj)/unmap.o: $(src)/unmap.c
$(CC) $(UNMAP_CFLAGS) -c -o $@ $< $(CC) $(UNMAP_CFLAGS) -c -o $@ $<
arch/um/kernel/unmap_fin.o : arch/um/kernel/unmap.o $(obj)/unmap_fin.o : $(src)/unmap.o
ld -r -o $@ $< -lc -L/usr/lib ld -r -o $@ $< -lc -L/usr/lib
# This has to be separate because it needs be compiled with frame pointers # This has to be separate because it needs be compiled with frame pointers
# regardless of how the rest of the kernel is built. # regardless of how the rest of the kernel is built.
arch/um/kernel/frame.o: arch/um/kernel/frame.c $(obj)/frame.o: $(src)/frame.c
$(CC) $(CFLAGS_$(notdir $@)) -c -o $@ $< $(CC) $(CFLAGS_$(notdir $@)) -c -o $@ $<
QUOTE = 'my $$config=`cat $(TOPDIR)/.config`; $$config =~ s/"/\\"/g ; while(<STDIN>) { $$_ =~ s/CONFIG/$$config/; print $$_ }' QUOTE = 'my $$config=`cat $(TOPDIR)/.config`; $$config =~ s/"/\\"/g ; while(<STDIN>) { $$_ =~ s/CONFIG/$$config/; print $$_ }'
arch/um/kernel/config.c : arch/um/kernel/config.c.in $(TOPDIR)/.config $(obj)/config.c : $(src)/config.c.in $(TOPDIR)/.config
$(PERL) -e $(QUOTE) < arch/um/kernel/config.c.in > $@ $(PERL) -e $(QUOTE) < $(src)/config.c.in > $@
arch/um/kernel/config.o : arch/um/kernel/config.c $(obj)/config.o : $(obj)/config.c
clean: clean:
rm -f config.c rm -f config.c
for dir in $(subdir-y) ; do $(MAKE) -C $$dir clean; done
modules: modules:
......
#include "asm/uaccess.h"
#include "linux/errno.h"
extern unsigned int arch_csum_partial(const char *buff, int len, int sum);
extern unsigned int csum_partial(char *buff, int len, int sum)
{
return(arch_csum_partial(buff, len, sum));
}
unsigned int csum_partial_copy_to(const char *src, char *dst, int len,
int sum, int *err_ptr)
{
if(copy_to_user(dst, src, len)){
*err_ptr = -EFAULT;
return(-1);
}
return(arch_csum_partial(src, len, sum));
}
unsigned int csum_partial_copy_from(const char *src, char *dst, int len,
int sum, int *err_ptr)
{
if(copy_from_user(dst, src, len)){
*err_ptr = -EFAULT;
return(-1);
}
return(arch_csum_partial(dst, len, sum));
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -18,65 +18,17 @@ ...@@ -18,65 +18,17 @@
#include "2_5compat.h" #include "2_5compat.h"
#include "os.h" #include "os.h"
#include "time_user.h" #include "time_user.h"
#include "choose-mode.h"
/* See comment above fork_tramp for why sigstop is defined and used like #include "mode_kern.h"
* this
*/
static int sigstop = SIGSTOP;
static int exec_tramp(void *sig_stack)
{
int sig = sigstop;
init_new_thread(sig_stack, NULL);
kill(os_getpid(), sig);
return(0);
}
void flush_thread(void) void flush_thread(void)
{ {
unsigned long stack; CHOOSE_MODE(flush_thread_tt(), flush_thread_skas());
int new_pid;
stack = alloc_stack(0, 0);
if(stack == 0){
printk(KERN_ERR
"flush_thread : failed to allocate temporary stack\n");
do_exit(SIGKILL);
}
new_pid = start_fork_tramp((void *) current->thread.kernel_stack,
stack, 0, exec_tramp);
if(new_pid < 0){
printk(KERN_ERR
"flush_thread : new thread failed, errno = %d\n",
-new_pid);
do_exit(SIGKILL);
}
if(current->thread_info->cpu == 0)
forward_interrupts(new_pid);
current->thread.request.op = OP_EXEC;
current->thread.request.u.exec.pid = new_pid;
unprotect_stack((unsigned long) current->thread_info);
os_usr1_process(os_getpid());
enable_timer();
free_page(stack);
protect(uml_reserved, high_physmem - uml_reserved, 1, 1, 0, 1);
task_protections((unsigned long) current->thread_info);
force_flush_all();
unblock_signals();
} }
void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp) void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
{ {
set_fs(USER_DS); CHOOSE_MODE_PROC(start_thread_tt, start_thread_skas, regs, eip, esp);
flush_tlb_mm(current->mm);
PT_REGS_IP(regs) = eip;
PT_REGS_SP(regs) = esp;
PT_FIX_EXEC_STACK(esp);
} }
static int execve1(char *file, char **argv, char **env) static int execve1(char *file, char **argv, char **env)
...@@ -93,8 +45,12 @@ static int execve1(char *file, char **argv, char **env) ...@@ -93,8 +45,12 @@ static int execve1(char *file, char **argv, char **env)
int um_execve(char *file, char **argv, char **env) int um_execve(char *file, char **argv, char **env)
{ {
if(execve1(file, argv, env) == 0) do_longjmp(current->thread.jmp); int err;
return(-1);
err = execve1(file, argv, env);
if(!err)
do_longjmp(current->thread.exec_buf, 1);
return(err);
} }
int sys_execve(char *file, char **argv, char **env) int sys_execve(char *file, char **argv, char **env)
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <sys/syscall.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>
...@@ -84,8 +85,8 @@ static int capture_stack(int (*child)(void *arg), void *arg, void *sp, ...@@ -84,8 +85,8 @@ static int capture_stack(int (*child)(void *arg), void *arg, void *sp,
printf("capture_stack : waitpid failed - errno = %d\n", errno); printf("capture_stack : waitpid failed - errno = %d\n", errno);
exit(1); exit(1);
} }
if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0)){ if(!WIFSIGNALED(status) || (WTERMSIG(status) != 9)){
printf("capture_stack : Expected exit status 0, " printf("capture_stack : Expected exit signal 9, "
"got status = 0x%x\n", status); "got status = 0x%x\n", status);
exit(1); exit(1);
} }
...@@ -103,28 +104,61 @@ static int capture_stack(int (*child)(void *arg), void *arg, void *sp, ...@@ -103,28 +104,61 @@ static int capture_stack(int (*child)(void *arg), void *arg, void *sp,
return(len); return(len);
} }
static void child_common(void *sp, int size, sighandler_t handler, int flags) struct common_raw {
void *stack;
int size;
unsigned long sig;
unsigned long sr;
unsigned long sp;
};
#define SA_RESTORER (0x04000000)
typedef unsigned long old_sigset_t;
struct old_sigaction {
__sighandler_t handler;
old_sigset_t sa_mask;
unsigned long sa_flags;
void (*sa_restorer)(void);
};
static void child_common(struct common_raw *common, sighandler_t handler,
int restorer, int flags)
{ {
stack_t ss; stack_t ss = ((stack_t) { .ss_sp = common->stack,
struct sigaction sa; .ss_flags = 0,
.ss_size = common->size });
int err;
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){ if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){
printf("PTRACE_TRACEME failed, errno = %d\n", errno); printf("PTRACE_TRACEME failed, errno = %d\n", errno);
} }
ss.ss_sp = sp;
ss.ss_flags = 0;
ss.ss_size = size;
if(sigaltstack(&ss, NULL) < 0){ if(sigaltstack(&ss, NULL) < 0){
printf("sigaltstack failed - errno = %d\n", errno); printf("sigaltstack failed - errno = %d\n", errno);
_exit(1); kill(getpid(), SIGKILL);
} }
sa.sa_handler = handler; if(restorer){
sigemptyset(&sa.sa_mask); struct sigaction sa;
sa.sa_flags = SA_ONSTACK | flags;
if(sigaction(SIGUSR1, &sa, NULL) < 0){ sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_ONSTACK | flags;
err = sigaction(SIGUSR1, &sa, NULL);
}
else {
struct old_sigaction sa;
sa.handler = handler;
sa.sa_mask = 0;
sa.sa_flags = (SA_ONSTACK | flags) & ~SA_RESTORER;
err = syscall(__NR_sigaction, SIGUSR1, &sa, NULL);
}
if(err < 0){
printf("sigaction failed - errno = %d\n", errno); printf("sigaction failed - errno = %d\n", errno);
_exit(1); kill(getpid(), SIGKILL);
} }
os_stop_process(os_getpid()); os_stop_process(os_getpid());
...@@ -133,13 +167,12 @@ static void child_common(void *sp, int size, sighandler_t handler, int flags) ...@@ -133,13 +167,12 @@ static void child_common(void *sp, int size, sighandler_t handler, int flags)
/* Changed only during early boot */ /* Changed only during early boot */
struct sc_frame signal_frame_sc; struct sc_frame signal_frame_sc;
struct sc_frame signal_frame_sc_sr;
struct sc_frame_raw { struct sc_frame_raw {
void *stack; struct common_raw common;
int size;
unsigned long sig;
unsigned long sc; unsigned long sc;
unsigned long sr; int restorer;
unsigned long sp;
struct arch_frame_data_raw arch; struct arch_frame_data_raw arch;
}; };
...@@ -148,20 +181,20 @@ static struct sc_frame_raw *raw_sc = NULL; ...@@ -148,20 +181,20 @@ static struct sc_frame_raw *raw_sc = NULL;
static void sc_handler(int sig, struct sigcontext sc) static void sc_handler(int sig, struct sigcontext sc)
{ {
raw_sc->sig = (unsigned long) &sig; raw_sc->common.sig = (unsigned long) &sig;
raw_sc->common.sr = frame_restorer();
raw_sc->common.sp = frame_sp();
raw_sc->sc = (unsigned long) &sc; raw_sc->sc = (unsigned long) &sc;
raw_sc->sr = frame_restorer();
raw_sc->sp = frame_sp();
setup_arch_frame_raw(&raw_sc->arch, &sc); setup_arch_frame_raw(&raw_sc->arch, &sc);
os_stop_process(os_getpid()); os_stop_process(os_getpid());
_exit(0); kill(getpid(), SIGKILL);
} }
static int sc_child(void *arg) static int sc_child(void *arg)
{ {
raw_sc = arg; raw_sc = arg;
child_common(raw_sc->stack, raw_sc->size, (sighandler_t) sc_handler, child_common(&raw_sc->common, (sighandler_t) sc_handler,
0); raw_sc->restorer, 0);
return(-1); return(-1);
} }
...@@ -169,13 +202,9 @@ static int sc_child(void *arg) ...@@ -169,13 +202,9 @@ static int sc_child(void *arg)
struct si_frame signal_frame_si; struct si_frame signal_frame_si;
struct si_frame_raw { struct si_frame_raw {
void *stack; struct common_raw common;
int size;
unsigned long sig;
unsigned long sip; unsigned long sip;
unsigned long si; unsigned long si;
unsigned long sr;
unsigned long sp;
}; };
/* Changed only during early boot */ /* Changed only during early boot */
...@@ -183,23 +212,59 @@ static struct si_frame_raw *raw_si = NULL; ...@@ -183,23 +212,59 @@ static struct si_frame_raw *raw_si = NULL;
static void si_handler(int sig, siginfo_t *si) static void si_handler(int sig, siginfo_t *si)
{ {
raw_si->sig = (unsigned long) &sig; raw_si->common.sig = (unsigned long) &sig;
raw_si->common.sr = frame_restorer();
raw_si->common.sp = frame_sp();
raw_si->sip = (unsigned long) &si; raw_si->sip = (unsigned long) &si;
raw_si->si = (unsigned long) si; raw_si->si = (unsigned long) si;
raw_si->sr = frame_restorer();
raw_si->sp = frame_sp();
os_stop_process(os_getpid()); os_stop_process(os_getpid());
_exit(0); kill(getpid(), SIGKILL);
} }
static int si_child(void *arg) static int si_child(void *arg)
{ {
raw_si = arg; raw_si = arg;
child_common(raw_si->stack, raw_si->size, (sighandler_t) si_handler, child_common(&raw_si->common, (sighandler_t) si_handler, 1,
SA_SIGINFO); SA_SIGINFO);
return(-1); return(-1);
} }
static int relative_sr(unsigned long sr, int sr_index, void *stack,
void *framep)
{
unsigned long *srp = (unsigned long *) sr;
unsigned long frame = (unsigned long) framep;
if((*srp & PAGE_MASK) == (unsigned long) stack){
*srp -= sr;
*((unsigned long *) (frame + sr_index)) = *srp;
return(1);
}
else return(0);
}
static unsigned long capture_stack_common(int (*proc)(void *), void *arg,
struct common_raw *common_in,
void *top, void *sigstack,
int stack_len,
struct frame_common *common_out)
{
unsigned long sig_top = (unsigned long) sigstack + stack_len, base;
common_in->stack = (void *) sigstack;
common_in->size = stack_len;
common_out->len = capture_stack(proc, arg, top, sig_top,
&common_out->data);
base = sig_top - common_out->len;
common_out->sig_index = common_in->sig - base;
common_out->sp_index = common_in->sp - base;
common_out->sr_index = common_in->sr - base;
common_out->sr_relative = relative_sr(common_in->sr,
common_out->sr_index, sigstack,
common_out->data);
return(base);
}
void capture_signal_stack(void) void capture_signal_stack(void)
{ {
struct sc_frame_raw raw_sc; struct sc_frame_raw raw_sc;
...@@ -220,54 +285,29 @@ void capture_signal_stack(void) ...@@ -220,54 +285,29 @@ void capture_signal_stack(void)
top = (unsigned long) stack + PAGE_SIZE - sizeof(void *); top = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
sig_top = (unsigned long) sigstack + PAGE_SIZE; sig_top = (unsigned long) sigstack + PAGE_SIZE;
raw_sc.stack = sigstack; /* Get the sigcontext, no sigrestorer layout */
raw_sc.size = PAGE_SIZE; raw_sc.restorer = 0;
signal_frame_sc.len = capture_stack(sc_child, &raw_sc, (void *) top, base = capture_stack_common(sc_child, &raw_sc, &raw_sc.common,
sig_top, &signal_frame_sc.data); (void *) top, sigstack, PAGE_SIZE,
&signal_frame_sc.common);
/* These are the offsets within signal_frame_sc.data (counting from
* the bottom) of sig, sc, SA_RESTORER, and the initial sp.
*/
base = sig_top - signal_frame_sc.len;
signal_frame_sc.sig_index = raw_sc.sig - base;
signal_frame_sc.sc_index = raw_sc.sc - base; signal_frame_sc.sc_index = raw_sc.sc - base;
signal_frame_sc.sr_index = raw_sc.sr - base;
if((*((unsigned long *) raw_sc.sr) & PAGE_MASK) ==
(unsigned long) sigstack){
unsigned long *sr = (unsigned long *) raw_sc.sr;
unsigned long frame = (unsigned long) signal_frame_sc.data;
signal_frame_sc.sr_relative = 1;
*sr -= raw_sc.sr;
*((unsigned long *) (frame + signal_frame_sc.sr_index)) = *sr;
}
else signal_frame_sc.sr_relative = 0;
signal_frame_sc.sp_index = raw_sc.sp - base;
setup_arch_frame(&raw_sc.arch, &signal_frame_sc.arch); setup_arch_frame(&raw_sc.arch, &signal_frame_sc.arch);
/* Repeat for the siginfo variant */ /* Ditto for the sigcontext, sigrestorer layout */
raw_sc.restorer = 1;
base = capture_stack_common(sc_child, &raw_sc, &raw_sc.common,
(void *) top, sigstack, PAGE_SIZE,
&signal_frame_sc_sr.common);
signal_frame_sc_sr.sc_index = raw_sc.sc - base;
/* And the siginfo layout */
raw_si.stack = sigstack; base = capture_stack_common(si_child, &raw_si, &raw_si.common,
raw_si.size = PAGE_SIZE; (void *) top, sigstack, PAGE_SIZE,
signal_frame_si.len = capture_stack(si_child, &raw_si, (void *) top, &signal_frame_si.common);
sig_top, &signal_frame_si.data);
base = sig_top - signal_frame_si.len;
signal_frame_si.sig_index = raw_si.sig - base;
signal_frame_si.sip_index = raw_si.sip - base; signal_frame_si.sip_index = raw_si.sip - base;
signal_frame_si.si_index = raw_si.si - base; signal_frame_si.si_index = raw_si.si - base;
signal_frame_si.sr_index = raw_si.sr - base;
if((*((unsigned long *) raw_si.sr) & PAGE_MASK) ==
(unsigned long) sigstack){
unsigned long *sr = (unsigned long *) raw_si.sr;
unsigned long frame = (unsigned long) signal_frame_si.data;
signal_frame_sc.sr_relative = 1;
*sr -= raw_si.sr;
*((unsigned long *) (frame + signal_frame_si.sr_index)) = *sr;
}
else signal_frame_si.sr_relative = 0;
signal_frame_si.sp_index = raw_si.sp - base;
if((munmap(stack, PAGE_SIZE) < 0) || if((munmap(stack, PAGE_SIZE) < 0) ||
(munmap(sigstack, PAGE_SIZE) < 0)){ (munmap(sigstack, PAGE_SIZE) < 0)){
...@@ -277,14 +317,6 @@ void capture_signal_stack(void) ...@@ -277,14 +317,6 @@ void capture_signal_stack(void)
} }
} }
void set_sc_ip_sp(void *sc_ptr, unsigned long ip, unsigned long sp)
{
struct sigcontext *sc = sc_ptr;
SC_IP(sc) = ip;
SC_SP(sc) = sp;
}
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically * Emacs will notice this stuff at the end of the file and automatically
......
...@@ -9,20 +9,31 @@ ...@@ -9,20 +9,31 @@
#include "frame_kern.h" #include "frame_kern.h"
#include "sigcontext.h" #include "sigcontext.h"
#include "sysdep/ptrace.h" #include "sysdep/ptrace.h"
#include "choose-mode.h"
#include "mode.h"
static int copy_restorer(void (*restorer)(void), unsigned long start, static int copy_restorer(void (*restorer)(void), unsigned long start,
unsigned long sr_index, int sr_relative) unsigned long sr_index, int sr_relative)
{ {
if(restorer != 0){ unsigned long sr;
if(copy_to_user((void *) (start + sr_index), &restorer,
sizeof(restorer))) if(sr_relative){
return(1); sr = (unsigned long) restorer;
} sr += start + sr_index;
else if(sr_relative){ restorer = (void (*)(void)) sr;
unsigned long *sr = (unsigned long *) (start + sr_index);
*sr += (unsigned long) sr;
} }
return(0);
return(copy_to_user((void *) (start + sr_index), &restorer,
sizeof(restorer)));
}
static int copy_sc_to_user(void *to, struct pt_regs *from)
{
return(CHOOSE_MODE(copy_sc_to_user_tt(to, from->regs.mode.tt,
&signal_frame_sc_sr.arch),
copy_sc_to_user_skas(to, &from->regs,
current->thread.cr2,
current->thread.err)));
} }
int setup_signal_stack_si(unsigned long stack_top, int sig, int setup_signal_stack_si(unsigned long stack_top, int sig,
...@@ -34,27 +45,30 @@ int setup_signal_stack_si(unsigned long stack_top, int sig, ...@@ -34,27 +45,30 @@ int setup_signal_stack_si(unsigned long stack_top, int sig,
void *sip; void *sip;
int sig_size = _NSIG_WORDS * sizeof(unsigned long); int sig_size = _NSIG_WORDS * sizeof(unsigned long);
start = stack_top - signal_frame_si.len - start = stack_top - signal_frame_si.common.len -
sc_size(&signal_frame_sc.arch) - sig_size; sc_size(&signal_frame_sc.arch) - sig_size;
sip = (void *) (start + signal_frame_si.si_index); sip = (void *) (start + signal_frame_si.si_index);
sc = start + signal_frame_si.len; sc = start + signal_frame_si.common.len;
sigs = sc + sc_size(&signal_frame_sc.arch); sigs = sc + sc_size(&signal_frame_sc.arch);
if(copy_sc_to_user((void *) sc, regs->regs.sc,
&signal_frame_sc.arch) || if(restorer == NULL)
copy_to_user((void *) start, signal_frame_si.data, panic("setup_signal_stack_si - no restorer");
signal_frame_si.len) ||
copy_to_user((void *) (start + signal_frame_si.sig_index), &sig, if(copy_sc_to_user((void *) sc, regs) ||
sizeof(sig)) || copy_to_user((void *) start, signal_frame_si.common.data,
signal_frame_si.common.len) ||
copy_to_user((void *) (start + signal_frame_si.common.sig_index),
&sig, sizeof(sig)) ||
copy_siginfo_to_user(sip, info) || copy_siginfo_to_user(sip, info) ||
copy_to_user((void *) (start + signal_frame_si.sip_index), &sip, copy_to_user((void *) (start + signal_frame_si.sip_index), &sip,
sizeof(sip)) || sizeof(sip)) ||
copy_to_user((void *) sigs, mask, sig_size) || copy_to_user((void *) sigs, mask, sig_size) ||
copy_restorer(restorer, start, signal_frame_si.sr_index, copy_restorer(restorer, start, signal_frame_si.common.sr_index,
signal_frame_si.sr_relative)) signal_frame_si.common.sr_relative))
return(1); return(1);
PT_REGS_IP(regs) = handler; PT_REGS_IP(regs) = handler;
PT_REGS_SP(regs) = start + signal_frame_sc.sp_index; PT_REGS_SP(regs) = start + signal_frame_sc.common.sp_index;
return(0); return(0);
} }
...@@ -62,26 +76,35 @@ int setup_signal_stack_sc(unsigned long stack_top, int sig, ...@@ -62,26 +76,35 @@ int setup_signal_stack_sc(unsigned long stack_top, int sig,
unsigned long handler, void (*restorer)(void), unsigned long handler, void (*restorer)(void),
struct pt_regs *regs, sigset_t *mask) struct pt_regs *regs, sigset_t *mask)
{ {
struct frame_common *frame = &signal_frame_sc_sr.common;
void *user_sc;
int sig_size = (_NSIG_WORDS - 1) * sizeof(unsigned long); int sig_size = (_NSIG_WORDS - 1) * sizeof(unsigned long);
unsigned long sigs, start = stack_top - signal_frame_sc.len - sig_size; unsigned long sigs, sr;
void *user_sc = (void *) (start + signal_frame_sc.sc_index); unsigned long start = stack_top - frame->len - sig_size;
user_sc = (void *) (start + signal_frame_sc_sr.sc_index);
if(restorer == NULL){
frame = &signal_frame_sc.common;
user_sc = (void *) (start + signal_frame_sc.sc_index);
sr = (unsigned long) frame->data;
sr += frame->sr_index;
sr = *((unsigned long *) sr);
restorer = ((void (*)(void)) sr);
}
sigs = start + signal_frame_sc.len; sigs = start + frame->len;
if(copy_to_user((void *) start, signal_frame_sc.data, if(copy_to_user((void *) start, frame->data, frame->len) ||
signal_frame_sc.len) || copy_to_user((void *) (start + frame->sig_index), &sig,
copy_to_user((void *) (start + signal_frame_sc.sig_index), &sig,
sizeof(sig)) || sizeof(sig)) ||
copy_sc_to_user(user_sc, regs->regs.sc, &signal_frame_sc.arch) || copy_sc_to_user(user_sc, regs) ||
copy_to_user(sc_sigmask(user_sc), mask, sizeof(mask->sig[0])) || copy_to_user(sc_sigmask(user_sc), mask, sizeof(mask->sig[0])) ||
copy_to_user((void *) sigs, &mask->sig[1], sig_size) || copy_to_user((void *) sigs, &mask->sig[1], sig_size) ||
copy_restorer(restorer, start, signal_frame_sc.sr_index, copy_restorer(restorer, start, frame->sr_index, frame->sr_relative))
signal_frame_sc.sr_relative))
return(1); return(1);
PT_REGS_IP(regs) = handler; PT_REGS_IP(regs) = handler;
PT_REGS_SP(regs) = start + signal_frame_sc.sp_index; PT_REGS_SP(regs) = start + frame->sp_index;
set_sc_ip_sp(regs->regs.sc, handler, start + signal_frame_sc.sp_index);
return(0); return(0);
} }
......
...@@ -43,9 +43,12 @@ static int helper_child(void *arg) ...@@ -43,9 +43,12 @@ static int helper_child(void *arg)
execvp(argv[0], argv); execvp(argv[0], argv);
printk("execvp of '%s' failed - errno = %d\n", argv[0], errno); printk("execvp of '%s' failed - errno = %d\n", argv[0], errno);
write(data->fd, &errno, sizeof(errno)); write(data->fd, &errno, sizeof(errno));
_exit(1); os_kill_process(os_getpid(), 0);
return(0);
} }
/* XXX The alloc_stack here breaks if this is called in the tracing thread */
int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv, int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv,
unsigned long *stack_out) unsigned long *stack_out)
{ {
......
...@@ -47,7 +47,7 @@ struct task_struct *alloc_task_struct(void){ ...@@ -47,7 +47,7 @@ struct task_struct *alloc_task_struct(void){
void unprotect_stack(unsigned long stack) void unprotect_stack(unsigned long stack)
{ {
protect(stack, 4 * PAGE_SIZE, 1, 1, 0, 1); protect_memory(stack, 4 * PAGE_SIZE, 1, 1, 0, 1);
} }
void free_task_struct(struct task_struct *task) void free_task_struct(struct task_struct *task)
......
/*
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/config.h" #include "linux/config.h"
#include "linux/module.h" #include "linux/module.h"
#include "linux/string.h" #include "linux/string.h"
...@@ -19,17 +24,13 @@ ...@@ -19,17 +24,13 @@
EXPORT_SYMBOL(stop); EXPORT_SYMBOL(stop);
EXPORT_SYMBOL(uml_physmem); EXPORT_SYMBOL(uml_physmem);
EXPORT_SYMBOL(set_signals); EXPORT_SYMBOL(set_signals);
EXPORT_SYMBOL(get_signals);
EXPORT_SYMBOL(kernel_thread); EXPORT_SYMBOL(kernel_thread);
EXPORT_SYMBOL(__const_udelay); EXPORT_SYMBOL(__const_udelay);
EXPORT_SYMBOL(__udelay);
EXPORT_SYMBOL(sys_waitpid); EXPORT_SYMBOL(sys_waitpid);
EXPORT_SYMBOL(task_size); EXPORT_SYMBOL(task_size);
EXPORT_SYMBOL(__do_copy_from_user);
EXPORT_SYMBOL(__do_copy_to_user);
EXPORT_SYMBOL(__do_strncpy_from_user);
EXPORT_SYMBOL(__do_strnlen_user);
EXPORT_SYMBOL(flush_tlb_range); EXPORT_SYMBOL(flush_tlb_range);
EXPORT_SYMBOL(__do_clear_user);
EXPORT_SYMBOL(honeypot);
EXPORT_SYMBOL(host_task_size); EXPORT_SYMBOL(host_task_size);
EXPORT_SYMBOL(arch_validate); EXPORT_SYMBOL(arch_validate);
...@@ -37,10 +38,10 @@ EXPORT_SYMBOL(region_pa); ...@@ -37,10 +38,10 @@ EXPORT_SYMBOL(region_pa);
EXPORT_SYMBOL(region_va); EXPORT_SYMBOL(region_va);
EXPORT_SYMBOL(phys_mem_map); EXPORT_SYMBOL(phys_mem_map);
EXPORT_SYMBOL(page_mem_map); EXPORT_SYMBOL(page_mem_map);
EXPORT_SYMBOL(get_signals);
EXPORT_SYMBOL(page_to_phys); EXPORT_SYMBOL(page_to_phys);
EXPORT_SYMBOL(phys_to_page); EXPORT_SYMBOL(phys_to_page);
EXPORT_SYMBOL(high_physmem); EXPORT_SYMBOL(high_physmem);
EXPORT_SYMBOL(empty_zero_page);
EXPORT_SYMBOL(os_open_file); EXPORT_SYMBOL(os_open_file);
EXPORT_SYMBOL(os_read_file); EXPORT_SYMBOL(os_read_file);
...@@ -53,7 +54,6 @@ EXPORT_SYMBOL(helper_wait); ...@@ -53,7 +54,6 @@ EXPORT_SYMBOL(helper_wait);
EXPORT_SYMBOL(os_shutdown_socket); EXPORT_SYMBOL(os_shutdown_socket);
EXPORT_SYMBOL(os_connect_socket); EXPORT_SYMBOL(os_connect_socket);
EXPORT_SYMBOL(run_helper); EXPORT_SYMBOL(run_helper);
EXPORT_SYMBOL(tracing_pid);
EXPORT_SYMBOL(start_thread); EXPORT_SYMBOL(start_thread);
EXPORT_SYMBOL(dump_thread); EXPORT_SYMBOL(dump_thread);
...@@ -75,6 +75,7 @@ EXPORT_SYMBOL_NOVERS(__write_lock_failed); ...@@ -75,6 +75,7 @@ EXPORT_SYMBOL_NOVERS(__write_lock_failed);
extern void FASTCALL( __read_lock_failed(rwlock_t *rw)); extern void FASTCALL( __read_lock_failed(rwlock_t *rw));
EXPORT_SYMBOL_NOVERS(__read_lock_failed); EXPORT_SYMBOL_NOVERS(__read_lock_failed);
EXPORT_SYMBOL(smp_num_cpus);
#endif #endif
#ifdef CONFIG_HIGHMEM #ifdef CONFIG_HIGHMEM
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "mem.h" #include "mem.h"
#include "kern.h" #include "kern.h"
#include "init.h" #include "init.h"
#include "os.h"
#include "mode_kern.h"
/* Changed during early boot */ /* Changed during early boot */
pgd_t swapper_pg_dir[1024]; pgd_t swapper_pg_dir[1024];
...@@ -56,12 +58,12 @@ static unsigned long brk_end; ...@@ -56,12 +58,12 @@ static unsigned long brk_end;
static void map_cb(void *unused) static void map_cb(void *unused)
{ {
map(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0); map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0);
} }
void unmap_physmem(void) void unmap_physmem(void)
{ {
unmap((void *) brk_end, uml_reserved - brk_end); os_unmap_memory((void *) brk_end, uml_reserved - brk_end);
} }
extern char __binary_start; extern char __binary_start;
...@@ -81,17 +83,17 @@ void mem_init(void) ...@@ -81,17 +83,17 @@ void mem_init(void)
/* Map in the area just after the brk now that kmalloc is about /* Map in the area just after the brk now that kmalloc is about
* to be turned on. * to be turned on.
*/ */
brk_end = (unsigned long) ROUND_UP(sbrk(0)); brk_end = (unsigned long) UML_ROUND_UP(sbrk(0));
map_cb(NULL); map_cb(NULL);
tracing_cb(map_cb, NULL); initial_thread_cb(map_cb, NULL);
free_bootmem(__pa(brk_end), uml_reserved - brk_end); free_bootmem(__pa(brk_end), uml_reserved - brk_end);
uml_reserved = brk_end; uml_reserved = brk_end;
/* Fill in any hole at the start of the binary */ /* Fill in any hole at the start of the binary */
start = (unsigned long) &__binary_start; start = (unsigned long) &__binary_start;
if(uml_physmem != start){ if(uml_physmem != start){
map(uml_physmem, __pa(uml_physmem), start - uml_physmem, map_memory(uml_physmem, __pa(uml_physmem), start - uml_physmem,
1, 1, 0); 1, 1, 0);
} }
/* this will put all low memory onto the freelists */ /* this will put all low memory onto the freelists */
...@@ -106,6 +108,21 @@ void mem_init(void) ...@@ -106,6 +108,21 @@ void mem_init(void)
kmalloc_ok = 1; kmalloc_ok = 1;
} }
/* Changed during early boot */
static unsigned long kmem_top = 0;
unsigned long get_kmem_end(void)
{
if(kmem_top == 0)
kmem_top = CHOOSE_MODE(kmem_end_tt, kmem_end_skas);
return(kmem_top);
}
void set_kmem_end(unsigned long new)
{
kmem_top = new;
}
#if CONFIG_HIGHMEM #if CONFIG_HIGHMEM
/* Changed during early boot */ /* Changed during early boot */
pte_t *kmap_pte; pte_t *kmap_pte;
...@@ -379,20 +396,6 @@ void show_mem(void) ...@@ -379,20 +396,6 @@ void show_mem(void)
printk("%d pages swap cached\n", cached); printk("%d pages swap cached\n", cached);
} }
/* Changed during early boot */
static unsigned long kmem_top = 0;
unsigned long get_kmem_end(void)
{
if(kmem_top == 0) kmem_top = host_task_size - ABOVE_KMEM;
return(kmem_top);
}
void set_kmem_end(unsigned long new)
{
kmem_top = new;
}
static int __init uml_mem_setup(char *line, int *add) static int __init uml_mem_setup(char *line, int *add)
{ {
char *retptr; char *retptr;
...@@ -411,28 +414,8 @@ __uml_setup("mem=", uml_mem_setup, ...@@ -411,28 +414,8 @@ __uml_setup("mem=", uml_mem_setup,
struct page *arch_validate(struct page *page, int mask, int order) struct page *arch_validate(struct page *page, int mask, int order)
{ {
unsigned long addr, zero = 0; return(CHOOSE_MODE_PROC(arch_validate_tt, arch_validate_skas, page,
int i; mask, order));
again:
if(page == NULL) return(page);
if(PageHighMem(page)) return(page);
addr = (unsigned long) page_address(page);
for(i = 0; i < (1 << order); i++){
current->thread.fault_addr = (void *) addr;
if(__do_copy_to_user((void *) addr, &zero,
sizeof(zero),
&current->thread.fault_addr,
&current->thread.fault_catcher)){
if(!(mask & __GFP_WAIT)) return(NULL);
else break;
}
addr += PAGE_SIZE;
}
if(i == (1 << order)) return(page);
page = alloc_pages(mask, order);
goto again;
} }
DECLARE_MUTEX(vm_reserved_sem); DECLARE_MUTEX(vm_reserved_sem);
...@@ -513,7 +496,7 @@ unsigned long get_vm(unsigned long len) ...@@ -513,7 +496,7 @@ unsigned long get_vm(unsigned long len)
return(0); return(0);
found: found:
up(&vm_reserved_sem); up(&vm_reserved_sem);
start = (unsigned long) ROUND_UP(this->end) + PAGE_SIZE; start = (unsigned long) UML_ROUND_UP(this->end) + PAGE_SIZE;
err = reserve_vm(start, start + len, NULL); err = reserve_vm(start, start + len, NULL);
if(err) return(0); if(err) return(0);
return(start); return(start);
...@@ -562,7 +545,7 @@ struct iomem iomem_regions[NREGIONS] = { [ 0 ... NREGIONS - 1 ] = ...@@ -562,7 +545,7 @@ struct iomem iomem_regions[NREGIONS] = { [ 0 ... NREGIONS - 1 ] =
int num_iomem_regions = 0; int num_iomem_regions = 0;
void add_iomem(char *name, int fd, int size) void add_iomem(char *name, int fd, unsigned long size)
{ {
if(num_iomem_regions == sizeof(iomem_regions)/sizeof(iomem_regions[0])) if(num_iomem_regions == sizeof(iomem_regions)/sizeof(iomem_regions[0]))
return; return;
......
...@@ -181,44 +181,22 @@ void log(char *fmt, ...) ...@@ -181,44 +181,22 @@ void log(char *fmt, ...)
} }
#endif #endif
void map(unsigned long virt, unsigned long phys, unsigned long len, int map_memory(unsigned long virt, unsigned long phys, unsigned long len,
int r, int w, int x) int r, int w, int x)
{ {
struct mem_region *region; struct mem_region *region = phys_region(phys);
void *loc;
int prot;
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0);
region = phys_region(phys);
loc = mmap((void *) virt, len, prot, MAP_SHARED | MAP_FIXED,
region->fd, phys_offset(phys));
if(loc != (void *) virt){
panic("Error mapping a page - errno = %d", errno);
}
}
int unmap(void *addr, int len)
{
int err;
err = munmap(addr, len); return(os_map_memory((void *) virt, region->fd, phys_offset(phys), len,
if(err < 0) return(-errno); r, w, x));
else return(err);
} }
int protect(unsigned long addr, unsigned long len, int r, int w, int x, int protect_memory(unsigned long addr, unsigned long len, int r, int w, int x,
int must_succeed) int must_succeed)
{ {
int prot; if(os_protect_memory((void *) addr, len, r, w, x) < 0){
if(must_succeed)
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) | panic("protect failed, errno = %d", errno);
(x ? PROT_EXEC : 0); else return(-errno);
if(mprotect((void *) addr, len, prot) == -1){
if(must_succeed)
panic("protect failed, errno = %d", errno);
else return(-errno);
} }
return(0); return(0);
} }
......
...@@ -21,9 +21,6 @@ ...@@ -21,9 +21,6 @@
#include <asm/sigcontext.h> #include <asm/sigcontext.h>
#include <asm/unistd.h> #include <asm/unistd.h>
#include <asm/page.h> #include <asm/page.h>
#ifdef PROFILING
#include <sys/gmon.h>
#endif
#include "user_util.h" #include "user_util.h"
#include "kern_util.h" #include "kern_util.h"
#include "user.h" #include "user.h"
...@@ -33,13 +30,19 @@ ...@@ -33,13 +30,19 @@
#include "sysdep/ptrace.h" #include "sysdep/ptrace.h"
#include "sysdep/sigcontext.h" #include "sysdep/sigcontext.h"
#include "irq_user.h" #include "irq_user.h"
#include "syscall_user.h"
#include "ptrace_user.h" #include "ptrace_user.h"
#include "time_user.h" #include "time_user.h"
#include "init.h" #include "init.h"
#include "os.h" #include "os.h"
#include "uml-config.h"
#include "choose-mode.h"
#include "mode.h"
#ifdef CONFIG_MODE_SKAS
#include "skas_ptrace.h"
#include "skas.h"
#endif
void init_new_thread(void *sig_stack, void (*usr1_handler)(int)) void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int))
{ {
int flags = 0; int flags = 0;
...@@ -47,6 +50,13 @@ void init_new_thread(void *sig_stack, void (*usr1_handler)(int)) ...@@ -47,6 +50,13 @@ void init_new_thread(void *sig_stack, void (*usr1_handler)(int))
set_sigstack(sig_stack, 2 * page_size()); set_sigstack(sig_stack, 2 * page_size());
flags = SA_ONSTACK; flags = SA_ONSTACK;
} }
if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1);
}
void init_new_thread_signals(int altstack)
{
int flags = altstack ? SA_ONSTACK : 0;
set_handler(SIGSEGV, (__sighandler_t) sig_handler, flags, set_handler(SIGSEGV, (__sighandler_t) sig_handler, flags,
SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1);
set_handler(SIGTRAP, (__sighandler_t) sig_handler, flags, set_handler(SIGTRAP, (__sighandler_t) sig_handler, flags,
...@@ -61,11 +71,10 @@ void init_new_thread(void *sig_stack, void (*usr1_handler)(int)) ...@@ -61,11 +71,10 @@ void init_new_thread(void *sig_stack, void (*usr1_handler)(int))
SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1); SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1);
set_handler(SIGUSR2, (__sighandler_t) sig_handler, set_handler(SIGUSR2, (__sighandler_t) sig_handler,
SA_NOMASK | flags, -1); SA_NOMASK | flags, -1);
if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1); (void) CHOOSE_MODE(signal(SIGCHLD, SIG_IGN), (void *) 0);
signal(SIGCHLD, SIG_IGN);
signal(SIGHUP, SIG_IGN); signal(SIGHUP, SIG_IGN);
init_irq_signals(sig_stack != NULL); init_irq_signals(altstack);
} }
struct tramp { struct tramp {
...@@ -122,32 +131,6 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack, ...@@ -122,32 +131,6 @@ int start_fork_tramp(void *thread_arg, unsigned long temp_stack,
return(arg.pid); return(arg.pid);
} }
void trace_myself(void)
{
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0)
panic("ptrace failed in trace_myself");
}
void attach_process(int pid)
{
if((ptrace(PTRACE_ATTACH, pid, 0, 0) < 0) ||
(ptrace(PTRACE_CONT, pid, 0, 0) < 0))
tracer_panic("OP_FORK failed to attach pid");
wait_for_stop(pid, SIGSTOP, PTRACE_CONT, NULL);
if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
tracer_panic("OP_FORK failed to continue process");
}
void tracer_panic(char *format, ...)
{
va_list ap;
va_start(ap, format);
vprintf(format, ap);
printf("\n");
while(1) sleep(10);
}
void suspend_new_thread(int fd) void suspend_new_thread(int fd)
{ {
char c; char c;
...@@ -164,19 +147,18 @@ static int ptrace_child(void *arg) ...@@ -164,19 +147,18 @@ static int ptrace_child(void *arg)
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){ if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0){
perror("ptrace"); perror("ptrace");
_exit(1); os_kill_process(pid, 0);
} }
os_stop_process(pid); os_stop_process(pid);
_exit(os_getpid() == pid); _exit(os_getpid() == pid);
} }
void __init check_ptrace(void) static int start_ptraced_child(void **stack_out)
{ {
void *stack; void *stack;
unsigned long sp; unsigned long sp;
int status, pid, n, syscall; int pid, n, status;
printk("Checking that ptrace can change system call numbers...");
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)
...@@ -191,6 +173,33 @@ void __init check_ptrace(void) ...@@ -191,6 +173,33 @@ void __init check_ptrace(void)
if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)) if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP))
panic("check_ptrace : expected SIGSTOP, got status = %d", panic("check_ptrace : expected SIGSTOP, got status = %d",
status); status);
*stack_out = stack;
return(pid);
}
static void stop_ptraced_child(int pid, void *stack, int exitcode)
{
int status, n;
if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
panic("check_ptrace : ptrace failed, errno = %d", errno);
n = waitpid(pid, &status, 0);
if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode))
panic("check_ptrace : child exited with status 0x%x", status);
if(munmap(stack, PAGE_SIZE) < 0)
panic("check_ptrace : munmap failed, errno = %d", errno);
}
void __init check_ptrace(void)
{
void *stack;
int pid, syscall, n, status;
printk("Checking that ptrace can change system call numbers...");
pid = start_ptraced_child(&stack);
while(1){ while(1){
if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0) if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0)
panic("check_ptrace : ptrace failed, errno = %d", panic("check_ptrace : ptrace failed, errno = %d",
...@@ -213,23 +222,19 @@ void __init check_ptrace(void) ...@@ -213,23 +222,19 @@ void __init check_ptrace(void)
break; break;
} }
} }
if(ptrace(PTRACE_CONT, pid, 0, 0) < 0) stop_ptraced_child(pid, stack, 0);
panic("check_ptrace : ptrace failed, errno = %d", errno);
n = waitpid(pid, &status, 0);
if(!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
panic("check_ptrace : child exited with status 0x%x", status);
if(munmap(stack, PAGE_SIZE) < 0)
panic("check_ptrace : munmap failed, errno = %d", errno);
printk("OK\n"); printk("OK\n");
} }
int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr) int run_kernel_thread(int (*fn)(void *), void *arg, void **jmp_ptr)
{ {
jmp_buf buf; jmp_buf buf;
int n;
*jmp_ptr = &buf; *jmp_ptr = &buf;
if(setjmp(buf)) return(1); n = setjmp(buf);
if(n != 0)
return(n);
(*fn)(arg); (*fn)(arg);
return(0); return(0);
} }
...@@ -244,6 +249,41 @@ void forward_pending_sigio(int target) ...@@ -244,6 +249,41 @@ void forward_pending_sigio(int target)
kill(target, SIGIO); kill(target, SIGIO);
} }
int can_do_skas(void)
{
#ifdef CONFIG_MODE_SKAS
struct ptrace_faultinfo fi;
void *stack;
int pid, n, ret = 1;
printk("Checking for the skas3 patch in the host...");
pid = start_ptraced_child(&stack);
n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
if(n < 0){
if(errno == EIO)
printk("not found\n");
else printk("No (unexpected errno - %d)\n", errno);
ret = 0;
}
else printk("found\n");
init_registers(pid);
stop_ptraced_child(pid, stack, 1);
printk("Checking for /proc/mm...");
if(access("/proc/mm", W_OK)){
printk("not found\n");
ret = 0;
}
else printk("found\n");
return(ret);
#else
return(0);
#endif
}
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically * Emacs will notice this stuff at the end of the file and automatically
......
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
#include "sigcontext.h" #include "sigcontext.h"
#include "2_5compat.h" #include "2_5compat.h"
#include "os.h" #include "os.h"
#include "mode.h"
#include "mode_kern.h"
#include "choose-mode.h"
/* This is a per-cpu array. A processor only modifies its entry and it only /* This is a per-cpu array. A processor only modifies its entry and it only
* cares about its entry, so it's OK if another processor is modifying its * cares about its entry, so it's OK if another processor is modifying its
...@@ -64,26 +67,11 @@ struct task_struct *get_task(int pid, int require) ...@@ -64,26 +67,11 @@ struct task_struct *get_task(int pid, int require)
return(ret); return(ret);
} }
int is_valid_pid(int pid)
{
struct task_struct *task;
read_lock(&tasklist_lock);
for_each_process(task){
if(task->thread.extern_pid == pid){
read_unlock(&tasklist_lock);
return(1);
}
}
read_unlock(&tasklist_lock);
return(0);
}
int external_pid(void *t) int external_pid(void *t)
{ {
struct task_struct *task = t ? t : current; struct task_struct *task = t ? t : current;
return(task->thread.extern_pid); return(CHOOSE_MODE_PROC(external_pid_tt, external_pid_skas, task));
} }
int pid_to_processor_id(int pid) int pid_to_processor_id(int pid)
...@@ -101,37 +89,6 @@ void free_stack(unsigned long stack, int order) ...@@ -101,37 +89,6 @@ void free_stack(unsigned long stack, int order)
free_pages(stack, order); free_pages(stack, order);
} }
void set_init_pid(int pid)
{
int err;
init_task.thread.extern_pid = pid;
err = os_pipe(init_task.thread.switch_pipe, 1, 1);
if(err) panic("Can't create switch pipe for init_task, errno = %d",
err);
}
int set_user_mode(void *t)
{
struct task_struct *task;
task = t ? t : current;
if(task->thread.tracing) return(1);
task->thread.request.op = OP_TRACE_ON;
os_usr1_process(os_getpid());
return(0);
}
void set_tracing(void *task, int tracing)
{
((struct task_struct *) task)->thread.tracing = tracing;
}
int is_tracing(void *t)
{
return (((struct task_struct *) t)->thread.tracing);
}
unsigned long alloc_stack(int order, int atomic) unsigned long alloc_stack(int order, int atomic)
{ {
unsigned long page; unsigned long page;
...@@ -144,53 +101,13 @@ unsigned long alloc_stack(int order, int atomic) ...@@ -144,53 +101,13 @@ unsigned long alloc_stack(int order, int atomic)
return(page); return(page);
} }
extern void schedule_tail(struct task_struct *prev);
static void new_thread_handler(int sig)
{
int (*fn)(void *);
void *arg;
fn = current->thread.request.u.thread.proc;
arg = current->thread.request.u.thread.arg;
current->thread.regs.regs.sc = (void *) (&sig + 1);
suspend_new_thread(current->thread.switch_pipe[0]);
block_signals();
#ifdef CONFIG_SMP
schedule_tail(NULL);
#endif
enable_timer();
free_page(current->thread.temp_stack);
set_cmdline("(kernel thread)");
force_flush_all();
current->thread.prev_sched = NULL;
change_sig(SIGUSR1, 1);
change_sig(SIGVTALRM, 1);
change_sig(SIGPROF, 1);
unblock_signals();
if(!run_kernel_thread(fn, arg, &current->thread.jmp))
do_exit(0);
}
static int new_thread_proc(void *stack)
{
change_sig(SIGIO, 0);
change_sig(SIGVTALRM, 0);
change_sig(SIGPROF, 0);
init_new_thread(stack, new_thread_handler);
os_usr1_process(os_getpid());
return(0);
}
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{ {
struct task_struct *p; struct task_struct *p;
current->thread.request.u.thread.proc = fn; current->thread.request.u.thread.proc = fn;
current->thread.request.u.thread.arg = arg; current->thread.request.u.thread.arg = arg;
p = do_fork(CLONE_VM | flags, 0, NULL, 0, NULL); p = do_fork(CLONE_VM | flags, 0, NULL, 0, NULL, NULL);
if(IS_ERR(p)) panic("do_fork failed in kernel_thread"); if(IS_ERR(p)) panic("do_fork failed in kernel_thread");
return(p->pid); return(p->pid);
} }
...@@ -208,83 +125,13 @@ void set_current(void *t) ...@@ -208,83 +125,13 @@ void set_current(void *t)
struct task_struct *task = t; struct task_struct *task = t;
cpu_tasks[task->thread_info->cpu] = ((struct cpu_task) cpu_tasks[task->thread_info->cpu] = ((struct cpu_task)
{ task->thread.extern_pid, task }); { external_pid(task), task });
} }
void *switch_to(void *prev, void *next, void *last) void *switch_to(void *prev, void *next, void *last)
{ {
struct task_struct *from, *to; return(CHOOSE_MODE(switch_to_tt(prev, next),
unsigned long flags; switch_to_skas(prev, next)));
int vtalrm, alrm, prof, err, cpu;
char c;
/* jailing and SMP are incompatible, so this doesn't need to be
* made per-cpu
*/
static int reading;
from = prev;
to = next;
to->thread.prev_sched = from;
cpu = from->thread_info->cpu;
if(cpu == 0)
forward_interrupts(to->thread.extern_pid);
#ifdef CONFIG_SMP
forward_ipi(cpu_data[cpu].ipi_pipe[0], to->thread.extern_pid);
#endif
local_irq_save(flags);
vtalrm = change_sig(SIGVTALRM, 0);
alrm = change_sig(SIGALRM, 0);
prof = change_sig(SIGPROF, 0);
forward_pending_sigio(to->thread.extern_pid);
c = 0;
set_current(to);
reading = 0;
err = os_write_file(to->thread.switch_pipe[1], &c, sizeof(c));
if(err != sizeof(c))
panic("write of switch_pipe failed, errno = %d", -err);
reading = 1;
if((from->state == TASK_ZOMBIE) || (from->state == TASK_DEAD))
os_kill_process(os_getpid());
err = os_read_file(from->thread.switch_pipe[0], &c, sizeof(c));
if(err != sizeof(c))
panic("read of switch_pipe failed, errno = %d", -err);
/* This works around a nasty race with 'jail'. If we are switching
* between two threads of a threaded app and the incoming process
* runs before the outgoing process reaches the read, and it makes
* it all the way out to userspace, then it will have write-protected
* the outgoing process stack. Then, when the outgoing process
* returns from the write, it will segfault because it can no longer
* write its own stack. So, in order to avoid that, the incoming
* thread sits in a loop yielding until 'reading' is set. This
* isn't entirely safe, since there may be a reschedule from a timer
* happening between setting 'reading' and sleeping in read. But,
* it should get a whole quantum in which to reach the read and sleep,
* which should be enough.
*/
if(jail){
while(!reading) sched_yield();
}
change_sig(SIGVTALRM, vtalrm);
change_sig(SIGALRM, alrm);
change_sig(SIGPROF, prof);
arch_switch();
flush_tlb_all();
local_irq_restore(flags);
return(current->thread.prev_sched);
} }
void interrupt_end(void) void interrupt_end(void)
...@@ -295,193 +142,37 @@ void interrupt_end(void) ...@@ -295,193 +142,37 @@ void interrupt_end(void)
void release_thread(struct task_struct *task) void release_thread(struct task_struct *task)
{ {
os_kill_process(task->thread.extern_pid); CHOOSE_MODE(release_thread_tt(task), release_thread_skas(task));
} }
void exit_thread(void) void exit_thread(void)
{ {
close(current->thread.switch_pipe[0]); CHOOSE_MODE(exit_thread_tt(), exit_thread_skas());
close(current->thread.switch_pipe[1]);
unprotect_stack((unsigned long) current->thread_info); unprotect_stack((unsigned long) current->thread_info);
} }
/* Signal masking - signals are blocked at the start of fork_tramp. They
* are re-enabled when finish_fork_handler is entered by fork_tramp hitting
* itself with a SIGUSR1. set_user_mode has to be run with SIGUSR1 off,
* so it is blocked before it's called. They are re-enabled on sigreturn
* despite the fact that they were blocked when the SIGUSR1 was issued because
* copy_thread copies the parent's signcontext, including the signal mask
* onto the signal frame.
*/
void finish_fork_handler(int sig)
{
current->thread.regs.regs.sc = (void *) (&sig + 1);
suspend_new_thread(current->thread.switch_pipe[0]);
#ifdef CONFIG_SMP
schedule_tail(NULL);
#endif
enable_timer();
change_sig(SIGVTALRM, 1);
force_flush_all();
if(current->mm != current->parent->mm)
protect(uml_reserved, high_physmem - uml_reserved, 1, 1, 0, 1);
task_protections((unsigned long) current->thread_info);
current->thread.prev_sched = NULL;
free_page(current->thread.temp_stack);
change_sig(SIGUSR1, 0);
set_user_mode(current);
}
void *get_current(void) void *get_current(void)
{ {
return(current); return(current);
} }
/* This sigusr1 business works around a bug in gcc's -pg support.
* Normally a procedure's mcount call comes after esp has been copied to
* ebp and the new frame is constructed. With procedures with no locals,
* the mcount comes before, as the first thing that the procedure does.
* When that procedure is main for a thread, ebp comes in as NULL. So,
* when mcount dereferences it, it segfaults. So, UML works around this
* by adding a non-optimizable local to the various trampolines, fork_tramp
* and outer_tramp below, and exec_tramp.
*/
static int sigusr1 = SIGUSR1;
int fork_tramp(void *stack)
{
int sig = sigusr1;
change_sig(SIGIO, 0);
change_sig(SIGVTALRM, 0);
change_sig(SIGPROF, 0);
init_new_thread(stack, finish_fork_handler);
kill(os_getpid(), sig);
return(0);
}
int copy_thread(int nr, unsigned long clone_flags, unsigned long sp, int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
unsigned long stack_top, struct task_struct * p, unsigned long stack_top, struct task_struct * p,
struct pt_regs *regs) struct pt_regs *regs)
{ {
int new_pid, err;
unsigned long stack;
int (*tramp)(void *);
p->thread = (struct thread_struct) INIT_THREAD; p->thread = (struct thread_struct) INIT_THREAD;
p->thread.kernel_stack = p->thread.kernel_stack =
(unsigned long) p->thread_info + 2 * PAGE_SIZE; (unsigned long) p->thread_info + 2 * PAGE_SIZE;
return(CHOOSE_MODE_PROC(copy_thread_tt, copy_thread_skas, nr,
if(current->thread.forking) clone_flags, sp, stack_top, p, regs));
tramp = fork_tramp;
else {
tramp = new_thread_proc;
p->thread.request.u.thread = current->thread.request.u.thread;
}
err = os_pipe(p->thread.switch_pipe, 1, 1);
if(err){
printk("copy_thread : pipe failed, errno = %d\n", -err);
return(err);
}
stack = alloc_stack(0, 0);
if(stack == 0){
printk(KERN_ERR "copy_thread : failed to allocate "
"temporary stack\n");
return(-ENOMEM);
}
clone_flags &= CLONE_VM;
p->thread.temp_stack = stack;
new_pid = start_fork_tramp((void *) p->thread.kernel_stack, stack,
clone_flags, tramp);
if(new_pid < 0){
printk(KERN_ERR "copy_thread : clone failed - errno = %d\n",
-new_pid);
return(new_pid);
}
if(current->thread.forking){
sc_to_sc(p->thread.regs.regs.sc, current->thread.regs.regs.sc);
PT_REGS_SET_SYSCALL_RETURN(&p->thread.regs, 0);
if(sp != 0) PT_REGS_SP(&p->thread.regs) = sp;
}
p->thread.extern_pid = new_pid;
current->thread.request.op = OP_FORK;
current->thread.request.u.fork.pid = new_pid;
os_usr1_process(os_getpid());
return(0);
}
void tracing_reboot(void)
{
current->thread.request.op = OP_REBOOT;
os_usr1_process(os_getpid());
} }
void tracing_halt(void) void initial_thread_cb(void (*proc)(void *), void *arg)
{ {
current->thread.request.op = OP_HALT; CHOOSE_MODE_PROC(initial_thread_cb_tt, initial_thread_cb_skas, proc,
os_usr1_process(os_getpid()); arg);
} }
void tracing_cb(void (*proc)(void *), void *arg)
{
if(os_getpid() == tracing_pid){
(*proc)(arg);
}
else {
current->thread.request.op = OP_CB;
current->thread.request.u.cb.proc = proc;
current->thread.request.u.cb.arg = arg;
os_usr1_process(os_getpid());
}
}
int do_proc_op(void *t, int proc_id)
{
struct task_struct *task;
struct thread_struct *thread;
int op, pid;
task = t;
thread = &task->thread;
op = thread->request.op;
switch(op){
case OP_NONE:
case OP_TRACE_ON:
break;
case OP_EXEC:
pid = thread->request.u.exec.pid;
do_exec(thread->extern_pid, pid);
thread->extern_pid = pid;
cpu_tasks[task->thread_info->cpu].pid = pid;
break;
case OP_FORK:
attach_process(thread->request.u.fork.pid);
break;
case OP_CB:
(*thread->request.u.cb.proc)(thread->request.u.cb.arg);
break;
case OP_REBOOT:
case OP_HALT:
break;
default:
tracer_panic("Bad op in do_proc_op");
break;
}
thread->request.op = OP_NONE;
return(op);
}
unsigned long stack_sp(unsigned long page) unsigned long stack_sp(unsigned long page)
{ {
return(page + PAGE_SIZE - sizeof(void *)); return(page + PAGE_SIZE - sizeof(void *));
...@@ -518,7 +209,7 @@ void default_idle(void) ...@@ -518,7 +209,7 @@ void default_idle(void)
void cpu_idle(void) void cpu_idle(void)
{ {
default_idle(); CHOOSE_MODE(init_idle_tt(), init_idle_skas());
} }
int page_size(void) int page_size(void)
...@@ -531,21 +222,25 @@ int page_mask(void) ...@@ -531,21 +222,25 @@ int page_mask(void)
return(PAGE_MASK); return(PAGE_MASK);
} }
unsigned long um_virt_to_phys(void *t, unsigned long addr) void *um_virt_to_phys(struct task_struct *task, unsigned long addr,
pte_t *pte_out)
{ {
struct task_struct *task;
pgd_t *pgd; pgd_t *pgd;
pmd_t *pmd; pmd_t *pmd;
pte_t *pte; pte_t *pte;
task = t; if(task->mm == NULL)
if(task->mm == NULL) return(0xffffffff); return(ERR_PTR(-EINVAL));
pgd = pgd_offset(task->mm, addr); pgd = pgd_offset(task->mm, addr);
pmd = pmd_offset(pgd, addr); pmd = pmd_offset(pgd, addr);
if(!pmd_present(*pmd)) return(0xffffffff); if(!pmd_present(*pmd))
return(ERR_PTR(-EINVAL));
pte = pte_offset_kernel(pmd, addr); pte = pte_offset_kernel(pmd, addr);
if(!pte_present(*pte)) return(0xffffffff); if(!pte_present(*pte))
return((pte_val(*pte) & PAGE_MASK) + (addr & ~PAGE_MASK)); return(ERR_PTR(-EINVAL));
if(pte_out != NULL)
*pte_out = *pte;
return((void *) (pte_val(*pte) & PAGE_MASK) + (addr & ~PAGE_MASK));
} }
char *current_cmd(void) char *current_cmd(void)
...@@ -553,8 +248,8 @@ char *current_cmd(void) ...@@ -553,8 +248,8 @@ char *current_cmd(void)
#if defined(CONFIG_SMP) || defined(CONFIG_HIGHMEM) #if defined(CONFIG_SMP) || defined(CONFIG_HIGHMEM)
return("(Unknown)"); return("(Unknown)");
#else #else
unsigned long addr = um_virt_to_phys(current, current->mm->arg_start); void *addr = um_virt_to_phys(current, current->mm->arg_start, NULL);
return addr == 0xffffffff? "(Unknown)": __va(addr); return IS_ERR(addr) ? "(Unknown)": __va((unsigned long) addr);
#endif #endif
} }
...@@ -602,22 +297,6 @@ unsigned long get_fault_addr(void) ...@@ -602,22 +297,6 @@ unsigned long get_fault_addr(void)
EXPORT_SYMBOL(get_fault_addr); EXPORT_SYMBOL(get_fault_addr);
void clear_singlestep(void *t)
{
struct task_struct *task = (struct task_struct *) t;
task->ptrace &= ~PT_DTRACE;
}
int singlestepping(void *t)
{
struct task_struct *task = (struct task_struct *) t;
if(task->thread.singlestep_syscall)
return(0);
return(task->ptrace & PT_DTRACE);
}
void not_implemented(void) void not_implemented(void)
{ {
printk(KERN_DEBUG "Something isn't implemented in here\n"); printk(KERN_DEBUG "Something isn't implemented in here\n");
...@@ -631,6 +310,7 @@ int user_context(unsigned long sp) ...@@ -631,6 +310,7 @@ int user_context(unsigned long sp)
} }
extern void remove_umid_dir(void); extern void remove_umid_dir(void);
__uml_exitcall(remove_umid_dir); __uml_exitcall(remove_umid_dir);
extern exitcall_t __uml_exitcall_begin, __uml_exitcall_end; extern exitcall_t __uml_exitcall_begin, __uml_exitcall_end;
...@@ -644,16 +324,6 @@ void do_uml_exitcalls(void) ...@@ -644,16 +324,6 @@ void do_uml_exitcalls(void)
(*call)(); (*call)();
} }
void *round_up(unsigned long addr)
{
return(ROUND_UP(addr));
}
void *round_down(unsigned long addr)
{
return(ROUND_DOWN(addr));
}
char *uml_strdup(char *string) char *uml_strdup(char *string)
{ {
char *new; char *new;
...@@ -664,82 +334,6 @@ char *uml_strdup(char *string) ...@@ -664,82 +334,6 @@ char *uml_strdup(char *string)
return(new); return(new);
} }
/* Changed by jail_setup, which is a setup */
int jail = 0;
int __init jail_setup(char *line, int *add)
{
int ok = 1;
if(jail) return(0);
#ifdef CONFIG_SMP
printf("'jail' may not used used in a kernel with CONFIG_SMP "
"enabled\n");
ok = 0;
#endif
#ifdef CONFIG_HOSTFS
printf("'jail' may not used used in a kernel with CONFIG_HOSTFS "
"enabled\n");
ok = 0;
#endif
#ifdef CONFIG_MODULES
printf("'jail' may not used used in a kernel with CONFIG_MODULES "
"enabled\n");
ok = 0;
#endif
if(!ok) exit(1);
/* CAP_SYS_RAWIO controls the ability to open /dev/mem and /dev/kmem.
* Removing it from the bounding set eliminates the ability of anything
* to acquire it, and thus read or write kernel memory.
*/
cap_lower(cap_bset, CAP_SYS_RAWIO);
jail = 1;
return(0);
}
__uml_setup("jail", jail_setup,
"jail\n"
" Enables the protection of kernel memory from processes.\n\n"
);
static void mprotect_kernel_mem(int w)
{
unsigned long start, end;
if(!jail || (current == &init_task)) return;
start = (unsigned long) current->thread_info + PAGE_SIZE;
end = (unsigned long) current->thread_info + PAGE_SIZE * 4;
protect(uml_reserved, start - uml_reserved, 1, w, 1, 1);
protect(end, high_physmem - end, 1, w, 1, 1);
start = (unsigned long) ROUND_DOWN(&_stext);
end = (unsigned long) ROUND_UP(&_etext);
protect(start, end - start, 1, w, 1, 1);
start = (unsigned long) ROUND_DOWN(&_unprotected_end);
end = (unsigned long) ROUND_UP(&_edata);
protect(start, end - start, 1, w, 1, 1);
start = (unsigned long) ROUND_DOWN(&__bss_start);
end = (unsigned long) ROUND_UP(brk_start);
protect(start, end - start, 1, w, 1, 1);
mprotect_kernel_vm(w);
}
/* No SMP problems since jailing and SMP are incompatible */
void unprotect_kernel_mem(void)
{
mprotect_kernel_mem(1);
}
void protect_kernel_mem(void)
{
mprotect_kernel_mem(0);
}
void *get_init_task(void) void *get_init_task(void)
{ {
return(&init_thread_union.thread_info.task); return(&init_thread_union.thread_info.task);
...@@ -760,11 +354,6 @@ int clear_user_proc(void *buf, int size) ...@@ -760,11 +354,6 @@ int clear_user_proc(void *buf, int size)
return(clear_user(buf, size)); return(clear_user(buf, size));
} }
void set_thread_sc(void *sc)
{
current->thread.regs.regs.sc = sc;
}
int smp_sigio_handler(void) int smp_sigio_handler(void)
{ {
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "linux/smp_lock.h" #include "linux/smp_lock.h"
#include "linux/security.h" #include "linux/security.h"
#include "linux/ptrace.h" #include "linux/ptrace.h"
#include "linux/proc_mm.h"
#include "asm/ptrace.h" #include "asm/ptrace.h"
#include "asm/uaccess.h" #include "asm/uaccess.h"
#include "kern_util.h" #include "kern_util.h"
...@@ -21,6 +22,11 @@ void ptrace_disable(struct task_struct *child) ...@@ -21,6 +22,11 @@ void ptrace_disable(struct task_struct *child)
{ {
} }
extern long do_mmap2(struct task_struct *task, unsigned long addr,
unsigned long len, unsigned long prot,
unsigned long flags, unsigned long fd,
unsigned long pgoff);
int sys_ptrace(long request, long pid, long addr, long data) int sys_ptrace(long request, long pid, long addr, long data)
{ {
struct task_struct *child; struct task_struct *child;
...@@ -182,13 +188,13 @@ int sys_ptrace(long request, long pid, long addr, long data) ...@@ -182,13 +188,13 @@ int sys_ptrace(long request, long pid, long addr, long data)
#ifdef PTRACE_GETREGS #ifdef PTRACE_GETREGS
case PTRACE_GETREGS: { /* Get all gp regs from the child. */ case PTRACE_GETREGS: { /* Get all gp regs from the child. */
if (!access_ok(VERIFY_WRITE, (unsigned *)data, if (!access_ok(VERIFY_WRITE, (unsigned long *)data,
FRAME_SIZE_OFFSET)) { FRAME_SIZE_OFFSET)) {
ret = -EIO; ret = -EIO;
break; break;
} }
for ( i = 0; i < FRAME_SIZE_OFFSET; i += sizeof(long) ) { for ( i = 0; i < FRAME_SIZE_OFFSET; i += sizeof(long) ) {
__put_user(getreg(child, i),(unsigned long *) data); __put_user(getreg(child, i), (unsigned long *) data);
data += sizeof(long); data += sizeof(long);
} }
ret = 0; ret = 0;
...@@ -231,6 +237,57 @@ int sys_ptrace(long request, long pid, long addr, long data) ...@@ -231,6 +237,57 @@ int sys_ptrace(long request, long pid, long addr, long data)
case PTRACE_SETFPXREGS: /* Set the child FPU state. */ case PTRACE_SETFPXREGS: /* Set the child FPU state. */
ret = set_fpxregs(data, child); ret = set_fpxregs(data, child);
break; break;
#endif
case PTRACE_FAULTINFO: {
struct ptrace_faultinfo fault;
fault = ((struct ptrace_faultinfo)
{ .is_write = child->thread.err,
.addr = child->thread.cr2 });
ret = copy_to_user((unsigned long *) data, &fault,
sizeof(fault));
if(ret)
break;
break;
}
case PTRACE_SIGPENDING:
ret = copy_to_user((unsigned long *) data,
&child->pending.signal,
sizeof(child->pending.signal));
break;
case PTRACE_LDT: {
struct ptrace_ldt ldt;
if(copy_from_user(&ldt, (unsigned long *) data,
sizeof(ldt))){
ret = -EIO;
break;
}
/* This one is confusing, so just punt and return -EIO for
* now
*/
ret = -EIO;
break;
}
#ifdef CONFIG_PROC_MM
case PTRACE_SWITCH_MM: {
struct mm_struct *old = child->mm;
struct mm_struct *new = proc_mm_get_mm(data);
if(IS_ERR(new)){
ret = PTR_ERR(new);
break;
}
atomic_inc(&new->mm_users);
child->mm = new;
child->active_mm = new;
mmput(old);
ret = 0;
break;
}
#endif #endif
default: default:
ret = -EIO; ret = -EIO;
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "kern_util.h" #include "kern_util.h"
#include "kern.h" #include "kern.h"
#include "os.h" #include "os.h"
#include "mode.h"
#include "choose-mode.h"
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
static void kill_idlers(int me) static void kill_idlers(int me)
...@@ -17,26 +19,17 @@ static void kill_idlers(int me) ...@@ -17,26 +19,17 @@ static void kill_idlers(int me)
for(i = 0; i < sizeof(idle_threads)/sizeof(idle_threads[0]); i++){ for(i = 0; i < sizeof(idle_threads)/sizeof(idle_threads[0]); i++){
p = idle_threads[i]; p = idle_threads[i];
if((p != NULL) && (p->thread.extern_pid != me)) if((p != NULL) && (p->thread.mode.tt.extern_pid != me))
os_kill_process(p->thread.extern_pid); os_kill_process(p->thread.mode.tt.extern_pid, 0);
} }
} }
#endif #endif
static void kill_off_processes(void) static void kill_off_processes(void)
{ {
struct task_struct *p; CHOOSE_MODE(kill_off_processes_tt(), kill_off_processes_skas());
int me;
me = os_getpid();
for_each_process(p){
if(p->thread.extern_pid != me)
os_kill_process(p->thread.extern_pid);
}
if(init_task.thread.extern_pid != me)
os_kill_process(init_task.thread.extern_pid);
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
kill_idlers(me); kill_idlers(os_getpid());
#endif #endif
} }
...@@ -50,16 +43,14 @@ void machine_restart(char * __unused) ...@@ -50,16 +43,14 @@ void machine_restart(char * __unused)
{ {
do_uml_exitcalls(); do_uml_exitcalls();
kill_off_processes(); kill_off_processes();
tracing_reboot(); CHOOSE_MODE(reboot_tt(), reboot_skas());
os_kill_process(os_getpid());
} }
void machine_power_off(void) void machine_power_off(void)
{ {
do_uml_exitcalls(); do_uml_exitcalls();
kill_off_processes(); kill_off_processes();
tracing_halt(); CHOOSE_MODE(halt_tt(), halt_skas());
os_kill_process(os_getpid());
} }
void machine_halt(void) void machine_halt(void)
......
...@@ -39,14 +39,13 @@ struct openpty_arg { ...@@ -39,14 +39,13 @@ struct openpty_arg {
int err; int err;
}; };
static int openpty_cb(void *arg) static void openpty_cb(void *arg)
{ {
struct openpty_arg *info = arg; struct openpty_arg *info = arg;
info->err = 0; info->err = 0;
if(openpty(&info->master, &info->slave, NULL, NULL, NULL)) if(openpty(&info->master, &info->slave, NULL, NULL, NULL))
info->err = errno; info->err = errno;
return(0);
} }
void __init check_one_sigio(void (*proc)(int, int)) void __init check_one_sigio(void (*proc)(int, int))
...@@ -54,13 +53,9 @@ void __init check_one_sigio(void (*proc)(int, int)) ...@@ -54,13 +53,9 @@ void __init check_one_sigio(void (*proc)(int, int))
struct sigaction old, new; struct sigaction old, new;
struct termios tt; struct termios tt;
struct openpty_arg pty = { master : -1, slave : -1 }; struct openpty_arg pty = { master : -1, slave : -1 };
int master, slave, flags, err; int master, slave, flags;
err = run_helper_thread(openpty_cb, &pty, CLONE_FILES, NULL, 2); initial_thread_cb(openpty_cb, &pty);
if(err < 0){
printk("run_helper_thread failed, errno = %d\n", -err);
return;
}
if(pty.err){ if(pty.err){
printk("openpty failed, errno = %d\n", pty.err); printk("openpty failed, errno = %d\n", pty.err);
return; return;
...@@ -387,7 +382,7 @@ void write_sigio_workaround(void) ...@@ -387,7 +382,7 @@ void write_sigio_workaround(void)
goto out_close2; goto out_close2;
write_sigio_pid = run_helper_thread(write_sigio_thread, NULL, write_sigio_pid = run_helper_thread(write_sigio_thread, NULL,
CLONE_FILES, &stack, 0); CLONE_FILES | CLONE_VM, &stack, 0);
if(write_sigio_pid < 0) goto out_close2; if(write_sigio_pid < 0) goto out_close2;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "kern.h" #include "kern.h"
#include "frame_kern.h" #include "frame_kern.h"
#include "sigcontext.h" #include "sigcontext.h"
#include "mode.h"
EXPORT_SYMBOL(block_signals); EXPORT_SYMBOL(block_signals);
EXPORT_SYMBOL(unblock_signals); EXPORT_SYMBOL(unblock_signals);
...@@ -171,7 +172,7 @@ static int kern_do_signal(struct pt_regs *regs, sigset_t *oldset, int error) ...@@ -171,7 +172,7 @@ static int kern_do_signal(struct pt_regs *regs, sigset_t *oldset, int error)
*/ */
if((current->ptrace & PT_DTRACE) && if((current->ptrace & PT_DTRACE) &&
is_syscall(PT_REGS_IP(&current->thread.regs))) is_syscall(PT_REGS_IP(&current->thread.regs)))
current->thread.singlestep_syscall = 1; (void) CHOOSE_MODE(current->thread.mode.tt.singlestep_syscall = 1, 0);
return(0); return(0);
} }
...@@ -228,6 +229,16 @@ int sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize) ...@@ -228,6 +229,16 @@ int sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize)
} }
} }
static int copy_sc_from_user(struct pt_regs *to, void *from)
{
int ret;
ret = CHOOSE_MODE(copy_sc_from_user_tt(to->regs.mode.tt, from,
&signal_frame_sc.arch),
copy_sc_from_user_skas(&to->regs, from));
return(ret);
}
int sys_sigreturn(struct pt_regs regs) int sys_sigreturn(struct pt_regs regs)
{ {
void *sc = sp_to_sc(PT_REGS_SP(&regs)); void *sc = sp_to_sc(PT_REGS_SP(&regs));
...@@ -241,8 +252,7 @@ int sys_sigreturn(struct pt_regs regs) ...@@ -241,8 +252,7 @@ int sys_sigreturn(struct pt_regs regs)
sigdelsetmask(&current->blocked, ~_BLOCKABLE); sigdelsetmask(&current->blocked, ~_BLOCKABLE);
recalc_sigpending(); recalc_sigpending();
spin_unlock_irq(&current->sig->siglock); spin_unlock_irq(&current->sig->siglock);
copy_sc_from_user(current->thread.regs.regs.sc, sc, copy_sc_from_user(&current->thread.regs, sc);
&signal_frame_sc.arch);
return(PT_REGS_SYSCALL_RET(&current->thread.regs)); return(PT_REGS_SYSCALL_RET(&current->thread.regs));
} }
...@@ -257,8 +267,7 @@ int sys_rt_sigreturn(struct pt_regs regs) ...@@ -257,8 +267,7 @@ int sys_rt_sigreturn(struct pt_regs regs)
sigdelsetmask(&current->blocked, ~_BLOCKABLE); sigdelsetmask(&current->blocked, ~_BLOCKABLE);
recalc_sigpending(); recalc_sigpending();
spin_unlock_irq(&current->sig->siglock); spin_unlock_irq(&current->sig->siglock);
copy_sc_from_user(current->thread.regs.regs.sc, sc, copy_sc_from_user(&current->thread.regs, sc);
&signal_frame_sc.arch);
return(PT_REGS_SYSCALL_RET(&current->thread.regs)); return(PT_REGS_SYSCALL_RET(&current->thread.regs));
} }
......
...@@ -21,13 +21,12 @@ ...@@ -21,13 +21,12 @@
void set_sigstack(void *sig_stack, int size) void set_sigstack(void *sig_stack, int size)
{ {
stack_t stack; stack_t stack = ((stack_t) { .ss_flags = 0,
.ss_sp = (__ptr_t) sig_stack,
.ss_size = size - sizeof(void *) });
stack.ss_sp = (__ptr_t) sig_stack;
stack.ss_flags = 0;
stack.ss_size = size - sizeof(void *);
if(sigaltstack(&stack, NULL) != 0) if(sigaltstack(&stack, NULL) != 0)
panic("sigaltstack failed"); panic("enabling signal stack failed, errno = %d\n", errno);
} }
void set_handler(int sig, void (*handler)(int), int flags, ...) void set_handler(int sig, void (*handler)(int), int flags, ...)
......
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
obj-y = exec_kern.o exec_user.o mem.o mem_user.o mmu.o process.o \
process_kern.o syscall_kern.o syscall_user.o time.o tlb.o trap_user.o \
sys-$(SUBARCH)/
USER_OBJS = $(filter %_user.o,$(obj-y)) process.o time.o
USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
include $(TOPDIR)/Rules.make
include/skas_ptregs.h : util/mk_ptregs
util/mk_ptregs > $@
util/mk_ptregs :
$(MAKE) -C util
$(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
clean :
$(MAKE) -C util clean
$(RM) -f include/skas_ptregs.h
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/kernel.h"
#include "asm/current.h"
#include "asm/page.h"
#include "asm/signal.h"
#include "asm/ptrace.h"
#include "asm/uaccess.h"
#include "asm/mmu_context.h"
#include "tlb.h"
#include "skas.h"
#include "mmu.h"
#include "os.h"
void flush_thread_skas(void)
{
force_flush_all();
switch_mm_skas(current->mm->context.skas.mm_fd);
}
void start_thread_skas(struct pt_regs *regs, unsigned long eip,
unsigned long esp)
{
set_fs(USER_DS);
PT_REGS_IP(regs) = eip;
PT_REGS_SP(regs) = esp;
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <sched.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include "user.h"
#include "kern_util.h"
#include "os.h"
#include "time_user.h"
static int user_thread_tramp(void *arg)
{
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0)
panic("user_thread_tramp - PTRACE_TRACEME failed, "
"errno = %d\n", errno);
enable_timer();
os_stop_process(os_getpid());
return(0);
}
int user_thread(unsigned long stack, int flags)
{
int pid, status;
pid = clone(user_thread_tramp, (void *) stack_sp(stack),
flags | CLONE_FILES | SIGCHLD, NULL);
if(pid < 0){
printk("user_thread - clone failed, errno = %d\n", errno);
return(pid);
}
if(waitpid(pid, &status, WUNTRACED) < 0){
printk("user_thread - waitpid failed, errno = %d\n", errno);
return(-errno);
}
if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP)){
printk("user_thread - trampoline didn't stop, status = %d\n",
status);
return(-EINVAL);
}
return(pid);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SKAS_MMU_H
#define __SKAS_MMU_H
#include "linux/list.h"
#include "linux/spinlock.h"
struct mmu_context_skas {
int mm_fd;
};
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __MODE_SKAS_H__
#define __MODE_SKAS_H__
extern unsigned long exec_regs[];
extern unsigned long exec_fp_regs[];
extern unsigned long exec_fpx_regs[];
extern int have_fpx_regs;
extern void user_time_init_skas(void);
extern int copy_sc_from_user_skas(struct uml_pt_regs *regs, void *from_ptr);
extern int copy_sc_to_user_skas(void *to_ptr, struct uml_pt_regs *regs,
unsigned long fault_addr, int fault_type);
extern void sig_handler_common_skas(int sig, struct sigcontext *sc);
extern void halt_skas(void);
extern void reboot_skas(void);
extern void kill_off_processes_skas(void);
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SKAS_MODE_KERN_H__
#define __SKAS_MODE_KERN_H__
#include "linux/sched.h"
#include "asm/page.h"
#include "asm/ptrace.h"
extern void flush_thread_skas(void);
extern void *switch_to_skas(void *prev, void *next);
extern void start_thread_skas(struct pt_regs *regs, unsigned long eip,
unsigned long esp);
extern int copy_thread_skas(int nr, unsigned long clone_flags,
unsigned long sp, unsigned long stack_top,
struct task_struct *p, struct pt_regs *regs);
extern void release_thread_skas(struct task_struct *task);
extern void exit_thread_skas(void);
extern void initial_thread_cb_skas(void (*proc)(void *), void *arg);
extern void init_idle_skas(void);
extern void flush_tlb_kernel_vm_skas(void);
extern void __flush_tlb_one_skas(unsigned long addr);
extern void flush_tlb_range_skas(struct vm_area_struct *vma,
unsigned long start, unsigned long end);
extern void flush_tlb_mm_skas(struct mm_struct *mm);
extern void force_flush_all_skas(void);
extern long execute_syscall_skas(void *r);
extern void before_mem_skas(unsigned long unused);
extern unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out,
unsigned long *task_size_out);
extern int start_uml_skas(void);
extern struct page *arch_validate_skas(struct page *page, int mask, int order);
extern int external_pid_skas(struct task_struct *task);
extern int thread_pid_skas(struct task_struct *task);
#define kmem_end_skas (host_task_size)
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SKAS_PROC_MM_H
#define __SKAS_PROC_MM_H
#define MM_MMAP 54
#define MM_MUNMAP 55
#define MM_MPROTECT 56
#define MM_COPY_SEGMENTS 57
struct mm_mmap {
unsigned long addr;
unsigned long len;
unsigned long prot;
unsigned long flags;
unsigned long fd;
unsigned long offset;
};
struct mm_munmap {
unsigned long addr;
unsigned long len;
};
struct mm_mprotect {
unsigned long addr;
unsigned long len;
unsigned int prot;
};
struct proc_mm_op {
int op;
union {
struct mm_mmap mmap;
struct mm_munmap munmap;
struct mm_mprotect mprotect;
int copy_segments;
} u;
};
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __PTRACE_SKAS_H
#define __PTRACE_SKAS_H
#include "uml-config.h"
#ifdef CONFIG_MODE_SKAS
#include "skas_ptregs.h"
#define HOST_FRAME_SIZE 17
#define REGS_IP(r) ((r)[HOST_IP])
#define REGS_SP(r) ((r)[HOST_SP])
#define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
#define REGS_EAX(r) ((r)[HOST_EAX])
#define REGS_EBX(r) ((r)[HOST_EBX])
#define REGS_ECX(r) ((r)[HOST_ECX])
#define REGS_EDX(r) ((r)[HOST_EDX])
#define REGS_ESI(r) ((r)[HOST_ESI])
#define REGS_EDI(r) ((r)[HOST_EDI])
#define REGS_EBP(r) ((r)[HOST_EBP])
#define REGS_CS(r) ((r)[HOST_CS])
#define REGS_SS(r) ((r)[HOST_SS])
#define REGS_DS(r) ((r)[HOST_DS])
#define REGS_ES(r) ((r)[HOST_ES])
#define REGS_FS(r) ((r)[HOST_FS])
#define REGS_GS(r) ((r)[HOST_GS])
#define REGS_SET_SYSCALL_RETURN(r, res) REGS_EAX(r) = (res)
#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
#define REGS_SEGV_IS_FIXABLE(r) SEGV_IS_FIXABLE((r)->trap_type)
#define REGS_FAULT_ADDR(r) ((r)->fault_addr)
#define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)
#endif
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SKAS_H
#define __SKAS_H
#include "sysdep/ptrace.h"
extern int userspace_pid;
extern void switch_threads(void *me, void *next);
extern void thread_wait(void *sw, void *fb);
extern void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr,
void (*handler)(int));
extern int start_idle_thread(void *stack, void *switch_buf_ptr,
void **fork_buf_ptr);
extern int user_thread(unsigned long stack, int flags);
extern void userspace(struct uml_pt_regs *regs);
extern void new_thread_proc(void *stack, void (*handler)(int sig));
extern void remove_sigstack(void);
extern void new_thread_handler(int sig);
extern void handle_syscall(struct uml_pt_regs *regs);
extern void map(int fd, unsigned long virt, unsigned long phys,
unsigned long len, int r, int w, int x);
extern int unmap(int fd, void *addr, int len);
extern int protect(int fd, unsigned long addr, unsigned long len,
int r, int w, int x, int must_succeed);
extern void user_signal(int sig, struct uml_pt_regs *regs);
extern int singlestepping_skas(void);
extern int new_mm(int from);
extern void save_registers(struct uml_pt_regs *regs);
extern void restore_registers(struct uml_pt_regs *regs);
extern void start_userspace(void);
extern void init_registers(int pid);
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SKAS_PTRACE_H
#define __SKAS_PTRACE_H
struct ptrace_faultinfo {
int is_write;
unsigned long addr;
};
struct ptrace_ldt {
int func;
void *ptr;
unsigned long bytecount;
};
#define PTRACE_FAULTINFO 52
#define PTRACE_SIGPENDING 53
#define PTRACE_LDT 54
#define PTRACE_SWITCH_MM 55
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SKAS_UACCESS_H
#define __SKAS_UACCESS_H
#include "linux/string.h"
#include "linux/sched.h"
#include "linux/err.h"
#include "asm/processor.h"
#include "asm/pgtable.h"
#include "asm/errno.h"
#include "asm/current.h"
#include "asm/a.out.h"
#include "kern_util.h"
#define access_ok_skas(type, addr, size) \
((segment_eq(get_fs(), KERNEL_DS)) || \
(((unsigned long) (addr) < TASK_SIZE) && \
((unsigned long) (addr) + (size) < TASK_SIZE)))
static inline int verify_area_skas(int type, const void * addr,
unsigned long size)
{
return(access_ok_skas(type, addr, size) ? 0 : -EFAULT);
}
extern void *um_virt_to_phys(struct task_struct *task, unsigned long virt,
pte_t *pte_out);
static inline unsigned long maybe_map(unsigned long virt, int is_write)
{
pte_t pte;
void *phys = um_virt_to_phys(current, virt, &pte);
int dummy_code;
if(IS_ERR(phys) || (is_write && !pte_write(pte))){
if(handle_page_fault(virt, 0, is_write, 0, &dummy_code))
return(0);
phys = um_virt_to_phys(current, virt, NULL);
}
return((unsigned long) __va((unsigned long) phys));
}
static inline int buffer_op(unsigned long addr, int len,
int (*op)(unsigned long addr, int len, void *arg),
void *arg)
{
int size = min(PAGE_ALIGN(addr) - addr, (unsigned long) len);
int remain = len, n;
n = (*op)(addr, size, arg);
if(n != 0)
return(n < 0 ? remain : 0);
addr += size;
remain -= size;
if(remain == 0)
return(0);
while(addr < ((addr + remain) & PAGE_MASK)){
n = (*op)(addr, PAGE_SIZE, arg);
if(n != 0)
return(n < 0 ? remain : 0);
addr += PAGE_SIZE;
remain -= PAGE_SIZE;
}
if(remain == 0)
return(0);
n = (*op)(addr, remain, arg);
if(n != 0)
return(n < 0 ? remain : 0);
return(0);
}
static inline int copy_chunk_from_user(unsigned long from, int len, void *arg)
{
unsigned long *to_ptr = arg, to = *to_ptr;
from = maybe_map(from, 0);
if(from == 0)
return(-1);
memcpy((void *) to, (void *) from, len);
*to_ptr += len;
return(0);
}
static inline int copy_from_user_skas(void *to, const void *from, int n)
{
if(segment_eq(get_fs(), KERNEL_DS)){
memcpy(to, from, n);
return(0);
}
return(access_ok_skas(VERIFY_READ, from, n) ?
buffer_op((unsigned long) from, n, copy_chunk_from_user, &to) :
n);
}
static inline int copy_chunk_to_user(unsigned long to, int len, void *arg)
{
unsigned long *from_ptr = arg, from = *from_ptr;
to = maybe_map(to, 1);
if(to == 0)
return(-1);
memcpy((void *) to, (void *) from, len);
*from_ptr += len;
return(0);
}
static inline int copy_to_user_skas(void *to, const void *from, int n)
{
if(segment_eq(get_fs(), KERNEL_DS)){
memcpy(to, from, n);
return(0);
}
return(access_ok_skas(VERIFY_WRITE, to, n) ?
buffer_op((unsigned long) to, n, copy_chunk_to_user, &from) :
n);
}
static inline int strncpy_chunk_from_user(unsigned long from, int len,
void *arg)
{
char **to_ptr = arg, *to = *to_ptr;
int n;
from = maybe_map(from, 0);
if(from == 0)
return(-1);
strncpy(to, (void *) from, len);
n = strnlen(to, len);
*to_ptr += n;
if(n < len)
return(1);
return(0);
}
static inline int strncpy_from_user_skas(char *dst, const char *src, int count)
{
int n;
char *ptr = dst;
if(segment_eq(get_fs(), KERNEL_DS)){
strncpy(dst, src, count);
return(strnlen(dst, count));
}
if(!access_ok_skas(VERIFY_READ, src, 1))
return(-EFAULT);
n = buffer_op((unsigned long) src, count, strncpy_chunk_from_user,
&ptr);
if(n != 0)
return(-EFAULT);
return(strnlen(dst, count));
}
static inline int clear_chunk(unsigned long addr, int len, void *unused)
{
addr = maybe_map(addr, 1);
if(addr == 0)
return(-1);
memset((void *) addr, 0, len);
return(0);
}
static inline int __clear_user_skas(void *mem, int len)
{
return(buffer_op((unsigned long) mem, len, clear_chunk, NULL));
}
static inline int clear_user_skas(void *mem, int len)
{
if(segment_eq(get_fs(), KERNEL_DS)){
memset(mem, 0, len);
return(0);
}
return(access_ok_skas(VERIFY_WRITE, mem, len) ?
buffer_op((unsigned long) mem, len, clear_chunk, NULL) : len);
}
static inline int strnlen_chunk(unsigned long str, int len, void *arg)
{
int *len_ptr = arg, n;
str = maybe_map(str, 0);
if(str == 0)
return(-1);
n = strnlen((void *) str, len);
*len_ptr += n;
if(n < len)
return(1);
return(0);
}
static inline int strnlen_user_skas(const void *str, int len)
{
int count = 0, n;
if(segment_eq(get_fs(), KERNEL_DS))
return(strnlen(str, len) + 1);
n = buffer_op((unsigned long) str, len, strnlen_chunk, &count);
if(n == 0)
return(count + 1);
return(-EFAULT);
}
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/config.h"
#include "linux/mm.h"
#include "mem_user.h"
unsigned long set_task_sizes_skas(int arg, unsigned long *host_size_out,
unsigned long *task_size_out)
{
/* Round up to the nearest 4M */
unsigned long top = ROUND_4M((unsigned long) &arg);
*host_size_out = top;
*task_size_out = top;
return(((unsigned long) set_task_sizes_skas) & ~0xffffff);
}
struct page *arch_validate_skas(struct page *page, int mask, int order)
{
return(page);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <errno.h>
#include <sys/mman.h>
#include <sys/ptrace.h>
#include "mem_user.h"
#include "user.h"
#include "os.h"
#include "proc_mm.h"
void map(int fd, unsigned long virt, unsigned long phys, unsigned long len,
int r, int w, int x)
{
struct proc_mm_op map;
struct mem_region *region;
int prot, n;
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0);
region = phys_region(phys);
map = ((struct proc_mm_op) { .op = MM_MMAP,
.u =
{ .mmap =
{ .addr = virt,
.len = len,
.prot = prot,
.flags = MAP_SHARED |
MAP_FIXED,
.fd = region->fd,
.offset = phys_offset(phys)
} } } );
n = os_write_file(fd, (char *) &map, sizeof(map));
if(n != sizeof(map))
printk("map : /proc/mm map failed, errno = %d\n", errno);
}
int unmap(int fd, void *addr, int len)
{
struct proc_mm_op unmap;
int n;
unmap = ((struct proc_mm_op) { .op = MM_MUNMAP,
.u =
{ .munmap =
{ .addr = (unsigned long) addr,
.len = len } } } );
n = os_write_file(fd, (char *) &unmap, sizeof(unmap));
if((n != 0) && (n != sizeof(unmap)))
return(-errno);
return(0);
}
int protect(int fd, unsigned long addr, unsigned long len, int r, int w,
int x, int must_succeed)
{
struct proc_mm_op protect;
int prot, n;
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0);
protect = ((struct proc_mm_op) { .op = MM_MPROTECT,
.u =
{ .mprotect =
{ .addr = (unsigned long) addr,
.len = len,
.prot = prot } } } );
n = os_write_file(fd, (char *) &protect, sizeof(protect));
if((n != 0) && (n != sizeof(protect))){
if(must_succeed)
panic("protect failed, errno = %d", errno);
return(-errno);
}
return(0);
}
void before_mem_skas(unsigned long unused)
{
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/sched.h"
#include "linux/list.h"
#include "linux/spinlock.h"
#include "linux/slab.h"
#include "asm/current.h"
#include "asm/segment.h"
#include "asm/mmu.h"
#include "os.h"
#include "skas.h"
int init_new_context_skas(struct task_struct *task, struct mm_struct *mm)
{
int from;
if((current->mm != NULL) && (current->mm != &init_mm))
from = current->mm->context.skas.mm_fd;
else from = -1;
mm->context.skas.mm_fd = new_mm(from);
if(mm->context.skas.mm_fd < 0)
panic("init_new_context_skas - new_mm failed, errno = %d\n",
mm->context.skas.mm_fd);
return(0);
}
void destroy_context_skas(struct mm_struct *mm)
{
os_close_file(mm->context.skas.mm_fd);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <setjmp.h>
#include <sched.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <sys/mman.h>
#include <sys/user.h>
#include <asm/unistd.h>
#include "user.h"
#include "ptrace_user.h"
#include "time_user.h"
#include "sysdep/ptrace.h"
#include "user_util.h"
#include "kern_util.h"
#include "skas.h"
#include "skas_ptrace.h"
#include "sysdep/sigcontext.h"
#include "os.h"
#include "proc_mm.h"
unsigned long exec_regs[FRAME_SIZE];
unsigned long exec_fp_regs[HOST_FP_SIZE];
unsigned long exec_fpx_regs[HOST_XFP_SIZE];
int have_fpx_regs = 1;
static void handle_segv(int pid)
{
struct ptrace_faultinfo fault;
int err;
err = ptrace(PTRACE_FAULTINFO, pid, 0, &fault);
if(err)
panic("handle_segv - PTRACE_FAULTINFO failed, errno = %d\n",
errno);
segv(fault.addr, 0, FAULT_WRITE(fault.is_write), 1, NULL);
}
static void handle_trap(int pid, struct uml_pt_regs *regs)
{
int err, syscall_nr, status;
syscall_nr = PT_SYSCALL_NR(regs->mode.skas.regs);
if(syscall_nr < 1){
relay_signal(SIGTRAP, regs);
return;
}
UPT_SYSCALL_NR(regs) = syscall_nr;
err = ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET, __NR_getpid);
if(err < 0)
panic("handle_trap - nullifying syscall failed errno = %d\n",
errno);
err = ptrace(PTRACE_SYSCALL, pid, 0, 0);
if(err < 0)
panic("handle_trap - continuing to end of syscall failed, "
"errno = %d\n", errno);
err = waitpid(pid, &status, WUNTRACED);
if((err < 0) || !WIFSTOPPED(status) || (WSTOPSIG(status) != SIGTRAP))
panic("handle_trap - failed to wait at end of syscall, "
"errno = %d, status = %d\n", errno, status);
handle_syscall(regs);
}
int userspace_pid;
static int userspace_tramp(void *arg)
{
init_new_thread_signals(0);
enable_timer();
ptrace(PTRACE_TRACEME, 0, 0, 0);
os_stop_process(os_getpid());
}
void start_userspace(void)
{
void *stack;
unsigned long sp;
int pid, status, n;
stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(stack == MAP_FAILED)
panic("start_userspace : mmap failed, errno = %d", errno);
sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
pid = clone(userspace_tramp, (void *) sp,
CLONE_FILES | CLONE_VM | SIGCHLD, NULL);
if(pid < 0)
panic("start_userspace : clone failed, errno = %d", errno);
do {
n = waitpid(pid, &status, WUNTRACED);
if(n < 0)
panic("start_userspace : wait failed, errno = %d",
errno);
} while(WIFSTOPPED(status) && (WSTOPSIG(status) == SIGVTALRM));
if(!WIFSTOPPED(status) || (WSTOPSIG(status) != SIGSTOP))
panic("start_userspace : expected SIGSTOP, got status = %d",
status);
if(munmap(stack, PAGE_SIZE) < 0)
panic("start_userspace : munmap failed, errno = %d\n", errno);
userspace_pid = pid;
}
void userspace(struct uml_pt_regs *regs)
{
int err, status, op;
restore_registers(regs);
err = ptrace(PTRACE_SYSCALL, userspace_pid, 0, 0);
if(err)
panic("userspace - PTRACE_SYSCALL failed, errno = %d\n",
errno);
while(1){
err = waitpid(userspace_pid, &status, WUNTRACED);
if(err < 0)
panic("userspace - waitpid failed, errno = %d\n",
errno);
regs->is_user = 1;
save_registers(regs);
if(WIFSTOPPED(status)){
switch(WSTOPSIG(status)){
case SIGSEGV:
handle_segv(userspace_pid);
break;
case SIGTRAP:
handle_trap(userspace_pid, regs);
break;
case SIGIO:
case SIGVTALRM:
case SIGILL:
case SIGBUS:
case SIGFPE:
user_signal(WSTOPSIG(status), regs);
break;
default:
printk("userspace - child stopped with signal "
"%d\n", WSTOPSIG(status));
}
interrupt_end();
}
restore_registers(regs);
op = singlestepping_skas() ? PTRACE_SINGLESTEP :
PTRACE_SYSCALL;
err = ptrace(op, userspace_pid, 0, 0);
if(err)
panic("userspace - PTRACE_SYSCALL failed, "
"errno = %d\n", errno);
}
}
void new_thread(void *stack, void **switch_buf_ptr, void **fork_buf_ptr,
void (*handler)(int))
{
jmp_buf switch_buf, fork_buf;
*switch_buf_ptr = &switch_buf;
*fork_buf_ptr = &fork_buf;
if(setjmp(fork_buf) == 0)
new_thread_proc(stack, handler);
remove_sigstack();
}
void thread_wait(void *sw, void *fb)
{
jmp_buf buf, **switch_buf = sw, *fork_buf;
*switch_buf = &buf;
fork_buf = fb;
if(setjmp(buf) == 0)
longjmp(*fork_buf, 1);
}
static int move_registers(int int_op, int fp_op, struct uml_pt_regs *regs,
unsigned long *fp_regs)
{
if(ptrace(int_op, userspace_pid, 0, regs->mode.skas.regs) < 0)
return(-errno);
if(ptrace(fp_op, userspace_pid, 0, fp_regs) < 0)
return(-errno);
return(0);
}
void save_registers(struct uml_pt_regs *regs)
{
unsigned long *fp_regs;
int err, fp_op;
if(have_fpx_regs){
fp_op = PTRACE_GETFPXREGS;
fp_regs = regs->mode.skas.xfp;
}
else {
fp_op = PTRACE_GETFPREGS;
fp_regs = regs->mode.skas.fp;
}
err = move_registers(PTRACE_GETREGS, fp_op, regs, fp_regs);
if(err)
panic("save_registers - saving registers failed, errno = %d\n",
err);
}
void restore_registers(struct uml_pt_regs *regs)
{
unsigned long *fp_regs;
int err, fp_op;
if(have_fpx_regs){
fp_op = PTRACE_SETFPXREGS;
fp_regs = regs->mode.skas.xfp;
}
else {
fp_op = PTRACE_SETFPREGS;
fp_regs = regs->mode.skas.fp;
}
err = move_registers(PTRACE_SETREGS, fp_op, regs, fp_regs);
if(err)
panic("restore_registers - saving registers failed, "
"errno = %d\n", err);
}
void switch_threads(void *me, void *next)
{
jmp_buf my_buf, **me_ptr = me, *next_buf = next;
*me_ptr = &my_buf;
if(setjmp(my_buf) == 0)
longjmp(*next_buf, 1);
}
static jmp_buf initial_jmpbuf;
/* XXX Make these percpu */
static void (*cb_proc)(void *arg);
static void *cb_arg;
static jmp_buf *cb_back;
int start_idle_thread(void *stack, void *switch_buf_ptr, void **fork_buf_ptr)
{
jmp_buf **switch_buf = switch_buf_ptr;
int n;
*fork_buf_ptr = &initial_jmpbuf;
n = setjmp(initial_jmpbuf);
if(n == 0)
new_thread_proc((void *) stack, new_thread_handler);
else if(n == 1)
remove_sigstack();
else if(n == 2){
(*cb_proc)(cb_arg);
longjmp(*cb_back, 1);
}
else if(n == 3)
return(0);
else if(n == 4)
return(1);
longjmp(**switch_buf, 1);
}
void remove_sigstack(void)
{
stack_t stack = ((stack_t) { .ss_flags = SS_DISABLE,
.ss_sp = NULL,
.ss_size = 0 });
if(sigaltstack(&stack, NULL) != 0)
panic("disabling signal stack failed, errno = %d\n", errno);
}
void initial_thread_cb_skas(void (*proc)(void *), void *arg)
{
jmp_buf here;
cb_proc = proc;
cb_arg = arg;
cb_back = &here;
if(setjmp(here) == 0)
longjmp(initial_jmpbuf, 2);
cb_proc = NULL;
cb_arg = NULL;
cb_back = NULL;
}
void halt_skas(void)
{
block_signals();
longjmp(initial_jmpbuf, 3);
}
void reboot_skas(void)
{
block_signals();
longjmp(initial_jmpbuf, 4);
}
int new_mm(int from)
{
struct proc_mm_op copy;
int n, fd = os_open_file("/proc/mm", of_write(OPENFLAGS()), 0);
if(fd < 0)
return(-errno);
if(from != -1){
copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS,
.u =
{ .copy_segments = from } } );
n = os_write_file(fd, (char *) &copy, sizeof(copy));
if(n != sizeof(copy))
printk("new_mm : /proc/mm copy_segments failed, "
"errno = %d\n", errno);
}
return(fd);
}
void switch_mm_skas(int mm_fd)
{
int err;
err = ptrace(PTRACE_SWITCH_MM, userspace_pid, 0, mm_fd);
if(err)
panic("switch_mm_skas - PTRACE_SWITCH_MM failed, errno = %d\n",
errno);
}
void kill_off_processes_skas(void)
{
os_kill_process(userspace_pid, 1);
}
void init_registers(int pid)
{
int err;
if(ptrace(PTRACE_GETREGS, pid, 0, exec_regs) < 0)
panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
errno);
err = ptrace(PTRACE_GETFPXREGS, pid, 0, exec_fpx_regs);
if(!err)
return;
have_fpx_regs = 0;
if(errno != EIO)
panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
errno);
err = ptrace(PTRACE_GETFPREGS, pid, 0, exec_fp_regs);
if(err)
panic("check_ptrace : PTRACE_GETFPREGS failed, errno = %d",
errno);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/sched.h"
#include "linux/slab.h"
#include "kern_util.h"
#include "time_user.h"
#include "signal_user.h"
#include "skas.h"
#include "os.h"
#include "user_util.h"
#include "tlb.h"
#include "frame.h"
#include "kern.h"
#include "mode.h"
int singlestepping_skas(void)
{
int ret = current->ptrace & PT_DTRACE;
current->ptrace &= ~PT_DTRACE;
return(ret);
}
void *switch_to_skas(void *prev, void *next)
{
struct task_struct *from, *to;
from = prev;
to = next;
/* XXX need to check runqueues[cpu].idle */
if(current->pid == 0)
switch_timers(0);
to->thread.prev_sched = from;
set_current(to);
switch_threads(&from->thread.mode.skas.switch_buf,
to->thread.mode.skas.switch_buf);
if(current->pid == 0)
switch_timers(1);
return(current->thread.prev_sched);
}
extern void schedule_tail(struct task_struct *prev);
void new_thread_handler(int sig)
{
int (*fn)(void *), n;
void *arg;
fn = current->thread.request.u.thread.proc;
arg = current->thread.request.u.thread.arg;
change_sig(SIGUSR1, 1);
thread_wait(&current->thread.mode.skas.switch_buf,
current->thread.mode.skas.fork_buf);
#ifdef CONFIG_SMP
schedule_tail(NULL);
#endif
current->thread.prev_sched = NULL;
n = run_kernel_thread(fn, arg, &current->thread.exec_buf);
if(n == 1)
userspace(&current->thread.regs.regs);
else if(n == 2)
do_exit(0);
}
void new_thread_proc(void *stack, void (*handler)(int sig))
{
init_new_thread_stack(stack, handler);
os_usr1_process(os_getpid());
}
void release_thread_skas(struct task_struct *task)
{
}
void exit_thread_skas(void)
{
}
void fork_handler(int sig)
{
change_sig(SIGUSR1, 1);
thread_wait(&current->thread.mode.skas.switch_buf,
current->thread.mode.skas.fork_buf);
force_flush_all();
#ifdef CONFIG_SMP
schedule_tail(current->thread.prev_sched);
#endif
current->thread.prev_sched = NULL;
unblock_signals();
userspace(&current->thread.regs.regs);
}
int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
unsigned long stack_top, struct task_struct * p,
struct pt_regs *regs)
{
void (*handler)(int);
if(current->thread.forking){
memcpy(&p->thread.regs.regs.mode.skas,
&current->thread.regs.regs.mode.skas,
sizeof(p->thread.regs.regs.mode.skas));
REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.mode.skas.regs, 0);
if(sp != 0) REGS_SP(p->thread.regs.regs.mode.skas.regs) = sp;
handler = fork_handler;
}
else {
memcpy(p->thread.regs.regs.mode.skas.regs, exec_regs,
sizeof(p->thread.regs.regs.mode.skas.regs));
memcpy(p->thread.regs.regs.mode.skas.fp, exec_fp_regs,
sizeof(p->thread.regs.regs.mode.skas.fp));
memcpy(p->thread.regs.regs.mode.skas.xfp, exec_fpx_regs,
sizeof(p->thread.regs.regs.mode.skas.xfp));
p->thread.request.u.thread = current->thread.request.u.thread;
handler = new_thread_handler;
}
new_thread((void *) p->thread.kernel_stack,
&p->thread.mode.skas.switch_buf,
&p->thread.mode.skas.fork_buf, handler);
return(0);
}
void init_idle_skas(void)
{
cpu_tasks[current->thread_info->cpu].pid = os_getpid();
default_idle();
}
extern void start_kernel(void);
static int start_kernel_proc(void *unused)
{
int pid;
block_signals();
pid = os_getpid();
cpu_tasks[0].pid = pid;
cpu_tasks[0].task = current;
#ifdef CONFIG_SMP
cpu_online_map = 1;
#endif
start_kernel();
return(0);
}
int start_uml_skas(void)
{
start_userspace();
capture_signal_stack();
init_new_thread_signals(1);
idle_timer();
init_task.thread.request.u.thread.proc = start_kernel_proc;
init_task.thread.request.u.thread.arg = NULL;
return(start_idle_thread((void *) init_task.thread.kernel_stack,
&init_task.thread.mode.skas.switch_buf,
&init_task.thread.mode.skas.fork_buf));
}
int external_pid_skas(struct task_struct *task)
{
return(userspace_pid);
}
int thread_pid_skas(struct task_struct *task)
{
return(userspace_pid);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
obj-y = sigcontext.o
USER_OBJS = sigcontext.o
USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
clean :
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <errno.h>
#include <asm/sigcontext.h>
#include <sys/ptrace.h>
#include <linux/ptrace.h>
#include "sysdep/ptrace.h"
#include "sysdep/ptrace_user.h"
#include "kern_util.h"
#include "user.h"
#include "sigcontext.h"
extern int userspace_pid;
int copy_sc_from_user_skas(struct uml_pt_regs *regs, void *from_ptr)
{
struct sigcontext sc, *from = from_ptr;
unsigned long fpregs[FP_FRAME_SIZE];
int err;
err = copy_from_user_proc(&sc, from, sizeof(sc));
err |= copy_from_user_proc(fpregs, sc.fpstate, sizeof(fpregs));
if(err)
return(err);
regs->mode.skas.regs[GS] = sc.gs;
regs->mode.skas.regs[FS] = sc.fs;
regs->mode.skas.regs[ES] = sc.es;
regs->mode.skas.regs[DS] = sc.ds;
regs->mode.skas.regs[EDI] = sc.edi;
regs->mode.skas.regs[ESI] = sc.esi;
regs->mode.skas.regs[EBP] = sc.ebp;
regs->mode.skas.regs[UESP] = sc.esp;
regs->mode.skas.regs[EBX] = sc.ebx;
regs->mode.skas.regs[EDX] = sc.edx;
regs->mode.skas.regs[ECX] = sc.ecx;
regs->mode.skas.regs[EAX] = sc.eax;
regs->mode.skas.regs[EIP] = sc.eip;
regs->mode.skas.regs[CS] = sc.cs;
regs->mode.skas.regs[EFL] = sc.eflags;
regs->mode.skas.regs[UESP] = sc.esp_at_signal;
regs->mode.skas.regs[SS] = sc.ss;
regs->mode.skas.fault_addr = sc.cr2;
regs->mode.skas.fault_type = FAULT_WRITE(sc.err);
regs->mode.skas.trap_type = sc.trapno;
err = ptrace(PTRACE_SETFPREGS, userspace_pid, 0, fpregs);
if(err < 0){
printk("copy_sc_to_user - PTRACE_SETFPREGS failed, "
"errno = %d\n", errno);
return(1);
}
return(0);
}
int copy_sc_to_user_skas(void *to_ptr, struct uml_pt_regs *regs,
unsigned long fault_addr, int fault_type)
{
struct sigcontext sc, *to = to_ptr;
struct _fpstate *to_fp;
unsigned long fpregs[FP_FRAME_SIZE];
int err;
sc.gs = regs->mode.skas.regs[GS];
sc.fs = regs->mode.skas.regs[FS];
sc.es = regs->mode.skas.regs[ES];
sc.ds = regs->mode.skas.regs[DS];
sc.edi = regs->mode.skas.regs[EDI];
sc.esi = regs->mode.skas.regs[ESI];
sc.ebp = regs->mode.skas.regs[EBP];
sc.esp = regs->mode.skas.regs[UESP];
sc.ebx = regs->mode.skas.regs[EBX];
sc.edx = regs->mode.skas.regs[EDX];
sc.ecx = regs->mode.skas.regs[ECX];
sc.eax = regs->mode.skas.regs[EAX];
sc.eip = regs->mode.skas.regs[EIP];
sc.cs = regs->mode.skas.regs[CS];
sc.eflags = regs->mode.skas.regs[EFL];
sc.esp_at_signal = regs->mode.skas.regs[UESP];
sc.ss = regs->mode.skas.regs[SS];
sc.cr2 = fault_addr;
sc.err = TO_SC_ERR(fault_type);
sc.trapno = regs->mode.skas.trap_type;
err = ptrace(PTRACE_GETFPREGS, userspace_pid, 0, fpregs);
if(err < 0){
printk("copy_sc_to_user - PTRACE_GETFPREGS failed, "
"errno = %d\n", errno);
return(1);
}
to_fp = (struct _fpstate *)((unsigned long) to + sizeof(*to));
sc.fpstate = to_fp;
if(err)
return(err);
return(copy_to_user_proc(to, &sc, sizeof(sc)) ||
copy_to_user_proc(to_fp, fpregs, sizeof(fpregs)));
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/sys.h"
#include "asm/errno.h"
#include "asm/unistd.h"
#include "asm/ptrace.h"
#include "asm/current.h"
#include "sysdep/syscalls.h"
#include "kern_util.h"
extern syscall_handler_t *sys_call_table[];
long execute_syscall_skas(void *r)
{
struct pt_regs *regs = r;
long res;
int syscall;
current->thread.nsyscalls++;
nsyscalls++;
syscall = regs->regs.syscall;
if((syscall >= NR_syscalls) || (syscall < 0))
res = -ENOSYS;
else res = EXECUTE_SYSCALL(syscall, regs);
return(res);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdlib.h>
#include <signal.h>
#include "kern_util.h"
#include "syscall_user.h"
#include "sysdep/ptrace.h"
#include "sysdep/sigcontext.h"
/* XXX Bogus */
#define ERESTARTSYS 512
#define ERESTARTNOINTR 513
#define ERESTARTNOHAND 514
void handle_syscall(struct uml_pt_regs *regs)
{
long result;
int index;
host_to_regs(regs);
index = record_syscall_start(UPT_SYSCALL_NR(regs));
syscall_trace();
result = execute_syscall(regs);
REGS_SET_SYSCALL_RETURN(regs->mode.skas.regs, result);
if((result == -ERESTARTNOHAND) || (result == -ERESTARTSYS) ||
(result == -ERESTARTNOINTR))
do_signal(result);
syscall_trace();
record_syscall_end(index, result);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <sys/signal.h>
#include <sys/time.h>
#include "time_user.h"
#include "process.h"
#include "user.h"
void user_time_init_skas(void)
{
if(signal(SIGALRM, (__sighandler_t) alarm_handler) == SIG_ERR)
panic("Couldn't set SIGALRM handler");
if(signal(SIGVTALRM, (__sighandler_t) alarm_handler) == SIG_ERR)
panic("Couldn't set SIGVTALRM handler");
set_interval(ITIMER_VIRTUAL);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/stddef.h"
#include "linux/sched.h"
#include "linux/mm.h"
#include "asm/page.h"
#include "asm/pgtable.h"
#include "asm/mmu.h"
#include "user_util.h"
#include "mem_user.h"
#include "skas.h"
#include "os.h"
static void fix_range(struct mm_struct *mm, unsigned long start_addr,
unsigned long end_addr, int force)
{
pgd_t *npgd;
pmd_t *npmd;
pte_t *npte;
unsigned long addr;
int r, w, x, err, fd;
if(mm == NULL) return;
fd = mm->context.skas.mm_fd;
for(addr = start_addr; addr < end_addr;){
npgd = pgd_offset(mm, addr);
npmd = pmd_offset(npgd, addr);
if(pmd_present(*npmd)){
npte = pte_offset_kernel(npmd, addr);
r = pte_read(*npte);
w = pte_write(*npte);
x = pte_exec(*npte);
if(!pte_dirty(*npte)) w = 0;
if(!pte_young(*npte)){
r = 0;
w = 0;
}
if(force || pte_newpage(*npte)){
err = unmap(fd, (void *) addr, PAGE_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
if(pte_present(*npte))
map(fd, addr,
pte_val(*npte) & PAGE_MASK,
PAGE_SIZE, r, w, x);
}
else if(pte_newprot(*npte)){
protect(fd, addr, PAGE_SIZE, r, w, x, 1);
}
*npte = pte_mkuptodate(*npte);
addr += PAGE_SIZE;
}
else {
if(force || pmd_newpage(*npmd)){
err = unmap(fd, (void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
pmd_mkuptodate(*npmd);
}
addr += PMD_SIZE;
}
}
}
static void flush_kernel_vm_range(unsigned long start, unsigned long end)
{
struct mm_struct *mm;
pgd_t *pgd;
pmd_t *pmd;
pte_t *pte;
unsigned long addr;
int updated = 0, err;
mm = &init_mm;
for(addr = start_vm; addr < end_vm;){
pgd = pgd_offset(mm, addr);
pmd = pmd_offset(pgd, addr);
if(pmd_present(*pmd)){
pte = pte_offset_kernel(pmd, addr);
if(!pte_present(*pte) || pte_newpage(*pte)){
updated = 1;
err = os_unmap_memory((void *) addr,
PAGE_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
if(pte_present(*pte))
map_memory(addr,
pte_val(*pte) & PAGE_MASK,
PAGE_SIZE, 1, 1, 1);
}
else if(pte_newprot(*pte)){
updated = 1;
protect_memory(addr, PAGE_SIZE, 1, 1, 1, 1);
}
addr += PAGE_SIZE;
}
else {
if(pmd_newpage(*pmd)){
updated = 1;
err = os_unmap_memory((void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
}
addr += PMD_SIZE;
}
}
}
void flush_tlb_kernel_vm_skas(void)
{
flush_kernel_vm_range(start_vm, end_vm);
}
void __flush_tlb_one_skas(unsigned long addr)
{
flush_kernel_vm_range(addr, addr + PAGE_SIZE);
}
void flush_tlb_range_skas(struct vm_area_struct *vma, unsigned long start,
unsigned long end)
{
if(vma->vm_mm == NULL)
flush_kernel_vm_range(start, end);
else fix_range(vma->vm_mm, start, end, 0);
}
void flush_tlb_mm_skas(struct mm_struct *mm)
{
if(mm == NULL)
flush_tlb_kernel_vm_skas();
else fix_range(mm, 0, host_task_size, 0);
}
void force_flush_all_skas(void)
{
fix_range(current->mm, 0, host_task_size, 1);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <signal.h>
#include <errno.h>
#include <asm/sigcontext.h>
#include "sysdep/ptrace.h"
#include "signal_user.h"
#include "user_util.h"
#include "kern_util.h"
#include "task.h"
#include "sigcontext.h"
void sig_handler_common_skas(int sig, struct sigcontext *sc)
{
struct uml_pt_regs save_regs, *r;
struct signal_info *info;
int save_errno = errno;
r = (struct uml_pt_regs *) TASK_REGS(get_current());
save_regs = *r;
r->is_user = 0;
r->mode.skas.fault_addr = SC_FAULT_ADDR(sc);
r->mode.skas.fault_type = SC_FAULT_TYPE(sc);
r->mode.skas.trap_type = SC_TRAP_TYPE(sc);
change_sig(SIGUSR1, 1);
info = &sig_info[sig];
if(!info->is_irq) unblock_signals();
(*info->handler)(sig, r);
*r = save_regs;
errno = save_errno;
}
extern int missed_ticks[];
void user_signal(int sig, struct uml_pt_regs *regs)
{
struct signal_info *info;
if(sig == SIGVTALRM)
missed_ticks[cpu()]++;
regs->is_user = 1;
regs->mode.skas.fault_addr = 0;
regs->mode.skas.fault_type = 0;
regs->mode.skas.trap_type = 0;
info = &sig_info[sig];
(*info->handler)(sig, regs);
unblock_signals();
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
all: mk_ptregs
mk_ptregs : mk_ptregs.o
$(CC) -o mk_ptregs mk_ptregs.o
mk_ptregs.o : mk_ptregs.c
$(CC) -c $<
clean :
$(RM) -f mk_ptregs *.o *~
#include <asm/ptrace.h>
#include <asm/user.h>
#define PRINT_REG(name, val) printf("#define HOST_%s %d\n", (name), (val))
int main(int argc, char **argv)
{
printf("/* Automatically generated by "
"arch/um/kernel/skas/util/mk_ptregs */\n");
printf("\n");
printf("#ifndef __SKAS_PT_REGS_\n");
printf("#define __SKAS_PT_REGS_\n");
printf("\n");
printf("#define HOST_FRAME_SIZE %d\n", FRAME_SIZE);
printf("#define HOST_FP_SIZE %d\n",
sizeof(struct user_i387_struct) / sizeof(unsigned long));
printf("#define HOST_XFP_SIZE %d\n",
sizeof(struct user_fxsr_struct) / sizeof(unsigned long));
PRINT_REG("IP", EIP);
PRINT_REG("SP", UESP);
PRINT_REG("EFLAGS", EFL);
PRINT_REG("EAX", EAX);
PRINT_REG("EBX", EBX);
PRINT_REG("ECX", ECX);
PRINT_REG("EDX", EDX);
PRINT_REG("ESI", ESI);
PRINT_REG("EDI", EDI);
PRINT_REG("EBP", EBP);
PRINT_REG("CS", CS);
PRINT_REG("SS", SS);
PRINT_REG("DS", DS);
PRINT_REG("FS", FS);
PRINT_REG("ES", ES);
PRINT_REG("GS", GS);
printf("\n");
printf("#endif\n");
return(0);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -116,7 +116,8 @@ static int idle_proc(void *cpup) ...@@ -116,7 +116,8 @@ static int idle_proc(void *cpup)
panic("CPU#%d failed to create IPI pipe, errno = %d", cpu, panic("CPU#%d failed to create IPI pipe, errno = %d", cpu,
-err); -err);
activate_ipi(cpu_data[cpu].ipi_pipe[0], current->thread.extern_pid); activate_ipi(cpu_data[cpu].ipi_pipe[0],
current->thread.mode.tt.extern_pid);
wmb(); wmb();
if (test_and_set_bit(cpu, &smp_callin_map)) { if (test_and_set_bit(cpu, &smp_callin_map)) {
...@@ -143,10 +144,12 @@ static struct task_struct *idle_thread(int cpu) ...@@ -143,10 +144,12 @@ static struct task_struct *idle_thread(int cpu)
if(IS_ERR(new_task)) panic("do_fork failed in idle_thread"); if(IS_ERR(new_task)) panic("do_fork failed in idle_thread");
cpu_tasks[cpu] = ((struct cpu_task) cpu_tasks[cpu] = ((struct cpu_task)
{ .pid = new_task->thread.extern_pid, { .pid = new_task->thread.mode.tt.extern_pid,
.task = new_task } ); .task = new_task } );
idle_threads[cpu] = new_task; idle_threads[cpu] = new_task;
write(new_task->thread.switch_pipe[1], &c, sizeof(c)); CHOOSE_MODE(write(new_task->thread.mode.tt.switch_pipe[1], &c,
sizeof(c)),
({ panic("skas mode doesn't support SMP"); }));
return(new_task); return(new_task);
} }
...@@ -162,7 +165,8 @@ void smp_prepare_cpus(unsigned int maxcpus) ...@@ -162,7 +165,8 @@ void smp_prepare_cpus(unsigned int maxcpus)
err = os_pipe(cpu_data[0].ipi_pipe, 1, 1); err = os_pipe(cpu_data[0].ipi_pipe, 1, 1);
if(err) panic("CPU#0 failed to create IPI pipe, errno = %d", -err); if(err) panic("CPU#0 failed to create IPI pipe, errno = %d", -err);
activate_ipi(cpu_data[0].ipi_pipe[0], current->thread.extern_pid); activate_ipi(cpu_data[0].ipi_pipe[0],
current->thread.mode.tt.extern_pid);
for(cpu = 1; cpu < ncpus; cpu++){ for(cpu = 1; cpu < ncpus; cpu++){
printk("Booting processor %d...\n", cpu); printk("Booting processor %d...\n", cpu);
......
...@@ -125,10 +125,8 @@ extern syscall_handler_t sys_ni_syscall; ...@@ -125,10 +125,8 @@ extern syscall_handler_t sys_ni_syscall;
extern syscall_handler_t sys_adjtimex; extern syscall_handler_t sys_adjtimex;
extern syscall_handler_t sys_mprotect; extern syscall_handler_t sys_mprotect;
extern syscall_handler_t sys_sigprocmask; extern syscall_handler_t sys_sigprocmask;
extern syscall_handler_t sys_create_module;
extern syscall_handler_t sys_init_module; extern syscall_handler_t sys_init_module;
extern syscall_handler_t sys_delete_module; extern syscall_handler_t sys_delete_module;
extern syscall_handler_t sys_get_kernel_syms;
extern syscall_handler_t sys_quotactl; extern syscall_handler_t sys_quotactl;
extern syscall_handler_t sys_getpgid; extern syscall_handler_t sys_getpgid;
extern syscall_handler_t sys_fchdir; extern syscall_handler_t sys_fchdir;
...@@ -162,7 +160,6 @@ extern syscall_handler_t sys_mremap; ...@@ -162,7 +160,6 @@ extern syscall_handler_t sys_mremap;
extern syscall_handler_t sys_setresuid16; extern syscall_handler_t sys_setresuid16;
extern syscall_handler_t sys_getresuid16; extern syscall_handler_t sys_getresuid16;
extern syscall_handler_t sys_ni_syscall; extern syscall_handler_t sys_ni_syscall;
extern syscall_handler_t sys_query_module;
extern syscall_handler_t sys_poll; extern syscall_handler_t sys_poll;
extern syscall_handler_t sys_nfsservctl; extern syscall_handler_t sys_nfsservctl;
extern syscall_handler_t sys_setresgid16; extern syscall_handler_t sys_setresgid16;
...@@ -235,9 +232,10 @@ extern syscall_handler_t sys_epoll_create; ...@@ -235,9 +232,10 @@ extern syscall_handler_t sys_epoll_create;
extern syscall_handler_t sys_epoll_ctl; extern syscall_handler_t sys_epoll_ctl;
extern syscall_handler_t sys_epoll_wait; extern syscall_handler_t sys_epoll_wait;
extern syscall_handler_t sys_remap_file_pages; extern syscall_handler_t sys_remap_file_pages;
extern syscall_handler_t sys_set_tid_address;
#if CONFIG_NFSD #if CONFIG_NFSD
#define NFSSERVCTL sys_nfsserctl #define NFSSERVCTL sys_nfsservctl
#else #else
#define NFSSERVCTL sys_ni_syscall #define NFSSERVCTL sys_ni_syscall
#endif #endif
...@@ -246,7 +244,7 @@ extern syscall_handler_t um_mount; ...@@ -246,7 +244,7 @@ extern syscall_handler_t um_mount;
extern syscall_handler_t um_time; extern syscall_handler_t um_time;
extern syscall_handler_t um_stime; extern syscall_handler_t um_stime;
#define LAST_GENERIC_SYSCALL __NR_remap_file_pages #define LAST_GENERIC_SYSCALL __NR_set_tid_address
#if LAST_GENERIC_SYSCALL > LAST_ARCH_SYSCALL #if LAST_GENERIC_SYSCALL > LAST_ARCH_SYSCALL
#define LAST_SYSCALL LAST_GENERIC_SYSCALL #define LAST_SYSCALL LAST_GENERIC_SYSCALL
...@@ -384,10 +382,10 @@ syscall_handler_t *sys_call_table[] = { ...@@ -384,10 +382,10 @@ syscall_handler_t *sys_call_table[] = {
[ __NR_adjtimex ] = sys_adjtimex, [ __NR_adjtimex ] = sys_adjtimex,
[ __NR_mprotect ] = sys_mprotect, [ __NR_mprotect ] = sys_mprotect,
[ __NR_sigprocmask ] = sys_sigprocmask, [ __NR_sigprocmask ] = sys_sigprocmask,
[ __NR_create_module ] = sys_create_module, [ __NR_create_module ] = sys_ni_syscall,
[ __NR_init_module ] = sys_init_module, [ __NR_init_module ] = sys_init_module,
[ __NR_delete_module ] = sys_delete_module, [ __NR_delete_module ] = sys_delete_module,
[ __NR_get_kernel_syms ] = sys_get_kernel_syms, [ __NR_get_kernel_syms ] = sys_ni_syscall,
[ __NR_quotactl ] = sys_quotactl, [ __NR_quotactl ] = sys_quotactl,
[ __NR_getpgid ] = sys_getpgid, [ __NR_getpgid ] = sys_getpgid,
[ __NR_fchdir ] = sys_fchdir, [ __NR_fchdir ] = sys_fchdir,
...@@ -424,7 +422,7 @@ syscall_handler_t *sys_call_table[] = { ...@@ -424,7 +422,7 @@ syscall_handler_t *sys_call_table[] = {
[ __NR_setresuid ] = sys_setresuid16, [ __NR_setresuid ] = sys_setresuid16,
[ __NR_getresuid ] = sys_getresuid16, [ __NR_getresuid ] = sys_getresuid16,
[ __NR_vm86 ] = sys_ni_syscall, [ __NR_vm86 ] = sys_ni_syscall,
[ __NR_query_module ] = sys_query_module, [ __NR_query_module ] = sys_ni_syscall,
[ __NR_poll ] = sys_poll, [ __NR_poll ] = sys_poll,
[ __NR_nfsservctl ] = NFSSERVCTL, [ __NR_nfsservctl ] = NFSSERVCTL,
[ __NR_setresgid ] = sys_setresgid16, [ __NR_setresgid ] = sys_setresgid16,
...@@ -489,6 +487,7 @@ syscall_handler_t *sys_call_table[] = { ...@@ -489,6 +487,7 @@ syscall_handler_t *sys_call_table[] = {
[ __NR_sys_epoll_ctl ] = sys_epoll_ctl, [ __NR_sys_epoll_ctl ] = sys_epoll_ctl,
[ __NR_sys_epoll_wait ] = sys_epoll_wait, [ __NR_sys_epoll_wait ] = sys_epoll_wait,
[ __NR_remap_file_pages ] = sys_remap_file_pages, [ __NR_remap_file_pages ] = sys_remap_file_pages,
[ __NR_set_tid_address ] = sys_set_tid_address,
ARCH_SYSCALLS ARCH_SYSCALLS
[ LAST_SYSCALL + 1 ... NR_syscalls ] = [ LAST_SYSCALL + 1 ... NR_syscalls ] =
......
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
#include "kern_util.h" #include "kern_util.h"
#include "user_util.h" #include "user_util.h"
#include "sysdep/syscalls.h" #include "sysdep/syscalls.h"
#include "mode_kern.h"
#include "choose-mode.h"
/* Unlocked, I don't care if this is a bit off */
int nsyscalls = 0;
long um_mount(char * dev_name, char * dir_name, char * type, long um_mount(char * dev_name, char * dir_name, char * type,
unsigned long new_flags, void * data) unsigned long new_flags, void * data)
...@@ -33,7 +38,7 @@ long sys_fork(void) ...@@ -33,7 +38,7 @@ long sys_fork(void)
struct task_struct *p; struct task_struct *p;
current->thread.forking = 1; current->thread.forking = 1;
p = do_fork(SIGCHLD, 0, NULL, 0, NULL); p = do_fork(SIGCHLD, 0, NULL, 0, NULL, NULL);
current->thread.forking = 0; current->thread.forking = 0;
return(IS_ERR(p) ? PTR_ERR(p) : p->pid); return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
} }
...@@ -43,7 +48,7 @@ long sys_clone(unsigned long clone_flags, unsigned long newsp) ...@@ -43,7 +48,7 @@ long sys_clone(unsigned long clone_flags, unsigned long newsp)
struct task_struct *p; struct task_struct *p;
current->thread.forking = 1; current->thread.forking = 1;
p = do_fork(clone_flags, newsp, NULL, 0, NULL); p = do_fork(clone_flags, newsp, NULL, 0, NULL, NULL);
current->thread.forking = 0; current->thread.forking = 0;
return(IS_ERR(p) ? PTR_ERR(p) : p->pid); return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
} }
...@@ -53,7 +58,7 @@ long sys_vfork(void) ...@@ -53,7 +58,7 @@ long sys_vfork(void)
struct task_struct *p; struct task_struct *p;
current->thread.forking = 1; current->thread.forking = 1;
p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0, NULL); p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0, NULL, NULL);
current->thread.forking = 0; current->thread.forking = 0;
return(IS_ERR(p) ? PTR_ERR(p) : p->pid); return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
} }
...@@ -298,122 +303,9 @@ int sys_sigaltstack(const stack_t *uss, stack_t *uoss) ...@@ -298,122 +303,9 @@ int sys_sigaltstack(const stack_t *uss, stack_t *uoss)
return(do_sigaltstack(uss, uoss, PT_REGS_SP(&current->thread.regs))); return(do_sigaltstack(uss, uoss, PT_REGS_SP(&current->thread.regs)));
} }
static inline int check_area(void *ptr, int size)
{
return(verify_area(VERIFY_WRITE, ptr, size));
}
static int check_readlink(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1], regs->regs.args[2]));
}
static int check_utime(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1],
sizeof(struct utimbuf)));
}
static int check_oldstat(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1],
sizeof(struct __old_kernel_stat)));
}
static int check_stat(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1], sizeof(struct stat)));
}
static int check_stat64(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1], sizeof(struct stat64)));
}
struct bogus {
int kernel_ds;
int (*check_params)(struct pt_regs *);
};
struct bogus this_is_bogus[256] = {
[ __NR_mknod ] = { 1, NULL },
[ __NR_mkdir ] = { 1, NULL },
[ __NR_rmdir ] = { 1, NULL },
[ __NR_unlink ] = { 1, NULL },
[ __NR_symlink ] = { 1, NULL },
[ __NR_link ] = { 1, NULL },
[ __NR_rename ] = { 1, NULL },
[ __NR_umount ] = { 1, NULL },
[ __NR_mount ] = { 1, NULL },
[ __NR_pivot_root ] = { 1, NULL },
[ __NR_chdir ] = { 1, NULL },
[ __NR_chroot ] = { 1, NULL },
[ __NR_open ] = { 1, NULL },
[ __NR_quotactl ] = { 1, NULL },
[ __NR_sysfs ] = { 1, NULL },
[ __NR_readlink ] = { 1, check_readlink },
[ __NR_acct ] = { 1, NULL },
[ __NR_execve ] = { 1, NULL },
[ __NR_uselib ] = { 1, NULL },
[ __NR_statfs ] = { 1, NULL },
[ __NR_truncate ] = { 1, NULL },
[ __NR_access ] = { 1, NULL },
[ __NR_chmod ] = { 1, NULL },
[ __NR_chown ] = { 1, NULL },
[ __NR_lchown ] = { 1, NULL },
[ __NR_utime ] = { 1, check_utime },
[ __NR_oldlstat ] = { 1, check_oldstat },
[ __NR_oldstat ] = { 1, check_oldstat },
[ __NR_stat ] = { 1, check_stat },
[ __NR_lstat ] = { 1, check_stat },
[ __NR_stat64 ] = { 1, check_stat64 },
[ __NR_lstat64 ] = { 1, check_stat64 },
[ __NR_chown32 ] = { 1, NULL },
};
/* sys_utimes */
static int check_bogosity(struct pt_regs *regs)
{
struct bogus *bogon = &this_is_bogus[regs->regs.syscall];
if(!bogon->kernel_ds) return(0);
if(bogon->check_params && (*bogon->check_params)(regs))
return(-EFAULT);
set_fs(KERNEL_DS);
return(0);
}
/* Unlocked, I don't care if this is a bit off */
int nsyscalls = 0;
extern syscall_handler_t *sys_call_table[];
long execute_syscall(void *r) long execute_syscall(void *r)
{ {
struct pt_regs *regs = r; return(CHOOSE_MODE_PROC(execute_syscall_tt, execute_syscall_skas, r));
long res;
int syscall;
current->thread.nsyscalls++;
nsyscalls++;
syscall = regs->regs.syscall;
if((syscall >= NR_syscalls) || (syscall < 0))
res = -ENOSYS;
else if(honeypot && check_bogosity(regs))
res = -EFAULT;
else res = EXECUTE_SYSCALL(syscall, regs);
set_fs(USER_DS);
if(current->thread.singlestep_syscall){
current->thread.singlestep_syscall = 0;
current->ptrace &= ~PT_DTRACE;
force_sig(SIGTRAP, current);
}
return(res);
} }
spinlock_t syscall_lock = SPIN_LOCK_UNLOCKED; spinlock_t syscall_lock = SPIN_LOCK_UNLOCKED;
......
/* /*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com) * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
/* XXX FIXME : Ensure that SIGIO and SIGVTALRM can't happen immediately #include <stdlib.h>
* after setting up syscall stack
* block SIGVTALRM in any code that's under wait_for_stop
*/
#include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <signal.h>
#include <errno.h>
#include <sys/ptrace.h>
#include <asm/unistd.h>
#include "sysdep/ptrace.h"
#include "sigcontext.h"
#include "ptrace_user.h"
#include "task.h"
#include "user_util.h"
#include "kern_util.h" #include "kern_util.h"
#include "syscall_user.h"
/* XXX Bogus */
#define ERESTARTSYS 512
#define ERESTARTNOINTR 513
#define ERESTARTNOHAND 514
struct { struct {
int syscall; int syscall;
...@@ -34,67 +16,24 @@ struct { ...@@ -34,67 +16,24 @@ struct {
struct timeval end; struct timeval end;
} syscall_record[1024]; } syscall_record[1024];
void syscall_handler(int sig, struct uml_pt_regs *regs) int record_syscall_start(int syscall)
{ {
void *sc; int max, index;
long result;
int index, max, syscall;
max = sizeof(syscall_record)/sizeof(syscall_record[0]); max = sizeof(syscall_record)/sizeof(syscall_record[0]);
index = next_syscall_index(max); index = next_syscall_index(max);
syscall = regs->syscall;
sc = regs->sc;
sc_to_regs(regs, sc, syscall);
SC_START_SYSCALL(sc);
syscall_record[index].syscall = syscall; syscall_record[index].syscall = syscall;
syscall_record[index].pid = current_pid(); syscall_record[index].pid = current_pid();
syscall_record[index].result = 0xdeadbeef; syscall_record[index].result = 0xdeadbeef;
gettimeofday(&syscall_record[index].start, NULL); gettimeofday(&syscall_record[index].start, NULL);
syscall_trace(); return(index);
result = execute_syscall(regs);
/* regs->sc may have changed while the system call ran (there may
* have been an interrupt or segfault), so it needs to be refreshed.
*/
regs->sc = sc;
SC_SET_SYSCALL_RETURN(sc, result);
if((result == -ERESTARTNOHAND) || (result == -ERESTARTSYS) ||
(result == -ERESTARTNOINTR))
do_signal(result);
syscall_trace();
syscall_record[index].result = result;
gettimeofday(&syscall_record[index].end, NULL);
} }
int do_syscall(void *task, int pid) void record_syscall_end(int index, int result)
{ {
unsigned long proc_regs[FRAME_SIZE]; syscall_record[index].result = result;
struct uml_pt_regs *regs; gettimeofday(&syscall_record[index].end, NULL);
int syscall;
if(ptrace_getregs(pid, proc_regs) < 0)
tracer_panic("Couldn't read registers");
syscall = PT_SYSCALL_NR(proc_regs);
regs = TASK_REGS(task);
UPT_SYSCALL_NR(regs) = syscall;
if(syscall < 1) return(0);
if((syscall != __NR_sigreturn) &&
((unsigned long *) PT_IP(proc_regs) >= &_stext) &&
((unsigned long *) PT_IP(proc_regs) <= &_etext))
tracer_panic("I'm tracing myself and I can't get out");
if(ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET,
__NR_getpid) < 0)
tracer_panic("do_syscall : Nullifying syscall failed, "
"errno = %d", errno);
return(1);
} }
/* /*
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
extern struct module *module_list; /* FIXME: Accessed without a lock --RR */
extern struct module kernel_module; extern struct list_head modules;
static inline int kernel_text_address(unsigned long addr) static inline int kernel_text_address(unsigned long addr)
{ {
...@@ -31,11 +31,11 @@ static inline int kernel_text_address(unsigned long addr) ...@@ -31,11 +31,11 @@ static inline int kernel_text_address(unsigned long addr)
addr <= (unsigned long) &_etext) addr <= (unsigned long) &_etext)
return 1; return 1;
for (mod = module_list; mod != &kernel_module; mod = mod->next) { list_for_each_entry(mod, &modules, list) {
/* mod_bound tests for addr being inside the vmalloc'ed /* mod_bound tests for addr being inside the vmalloc'ed
* module area. Of course it'd be better to test only * module area. Of course it'd be better to test only
* for the .text subset... */ * for the .text subset... */
if (mod_bound(addr, 0, mod)) { if (mod_bound((void *) addr, 0, mod)) {
retval = 1; retval = 1;
break; break;
} }
......
...@@ -23,22 +23,21 @@ void timer(void) ...@@ -23,22 +23,21 @@ void timer(void)
gettimeofday(&xtime, NULL); gettimeofday(&xtime, NULL);
} }
static void set_interval(int timer_type) void set_interval(int timer_type)
{ {
struct itimerval interval; int usec = 1000000/hz();
struct itimerval interval = ((struct itimerval) { { 0, usec },
{ 0, usec } });
interval.it_interval.tv_sec = 0;
interval.it_interval.tv_usec = 1000000/hz();
interval.it_value.tv_sec = 0;
interval.it_value.tv_usec = 1000000/hz();
if(setitimer(timer_type, &interval, NULL) == -1) if(setitimer(timer_type, &interval, NULL) == -1)
panic("setitimer failed - errno = %d\n", errno); panic("setitimer failed - errno = %d\n", errno);
} }
void enable_timer(void) void enable_timer(void)
{ {
struct itimerval enable = ((struct itimerval) { { 0, 1000000/hz() }, int usec = 1000000/hz();
{ 0, 1000000/hz() }}); struct itimerval enable = ((struct itimerval) { { 0, usec },
{ 0, usec }});
if(setitimer(ITIMER_VIRTUAL, &enable, NULL)) if(setitimer(ITIMER_VIRTUAL, &enable, NULL))
printk("enable_timer - setitimer failed, errno = %d\n", printk("enable_timer - setitimer failed, errno = %d\n",
errno); errno);
...@@ -76,13 +75,6 @@ void idle_timer(void) ...@@ -76,13 +75,6 @@ void idle_timer(void)
set_interval(ITIMER_REAL); set_interval(ITIMER_REAL);
} }
void user_time_init(void)
{
if(signal(SIGVTALRM, (__sighandler_t) alarm_handler) == SIG_ERR)
panic("Couldn't set SIGVTALRM handler");
set_interval(ITIMER_VIRTUAL);
}
void time_init(void) void time_init(void)
{ {
if(signal(SIGVTALRM, boot_timer_handler) == SIG_ERR) if(signal(SIGVTALRM, boot_timer_handler) == SIG_ERR)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "kern_util.h" #include "kern_util.h"
#include "user_util.h" #include "user_util.h"
#include "time_user.h" #include "time_user.h"
#include "mode.h"
u64 jiffies_64; u64 jiffies_64;
...@@ -142,7 +143,7 @@ int __init timer_init(void) ...@@ -142,7 +143,7 @@ int __init timer_init(void)
{ {
int err; int err;
user_time_init(); CHOOSE_MODE(user_time_init_tt(), user_time_init_skas());
if((err = request_irq(TIMER_IRQ, um_timer, SA_INTERRUPT, "timer", if((err = request_irq(TIMER_IRQ, um_timer, SA_INTERRUPT, "timer",
NULL)) != 0) NULL)) != 0)
printk(KERN_ERR "timer_init : request_irq failed - " printk(KERN_ERR "timer_init : request_irq failed - "
......
/* /*
* Copyright (C) 2000 Jeff Dike (jdike@karaya.com) * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#include "linux/sched.h" #include "linux/mm.h"
#include "linux/slab.h" #include "asm/page.h"
#include "linux/bootmem.h"
#include "asm/pgalloc.h" #include "asm/pgalloc.h"
#include "asm-generic/tlb.h" #include "asm/tlbflush.h"
#include "asm/pgtable.h" #include "choose-mode.h"
#include "asm/a.out.h" #include "mode_kern.h"
#include "asm/processor.h"
#include "asm/mmu_context.h"
#include "asm/uaccess.h"
#include "asm/atomic.h"
#include "mem_user.h"
#include "user_util.h"
#include "kern_util.h"
#include "kern.h"
#include "tlb.h"
#include "os.h"
static void fix_range(struct mm_struct *mm, unsigned long start_addr, void flush_tlb_page(struct vm_area_struct *vma, unsigned long address)
unsigned long end_addr, int force)
{
pgd_t *npgd;
pmd_t *npmd;
pte_t *npte;
unsigned long addr;
int r, w, x, err;
if((current->thread.extern_pid != -1) &&
(current->thread.extern_pid != os_getpid()))
panic("fix_range fixing wrong address space, current = 0x%p",
current);
if(mm == NULL) return;
for(addr=start_addr;addr<end_addr;){
if(addr == TASK_SIZE){
/* Skip over kernel text, kernel data, and physical
* memory, which don't have ptes, plus kernel virtual
* memory, which is flushed separately, and remap
* the process stack. The only way to get here is
* if (end_addr == STACK_TOP) > TASK_SIZE, which is
* only true in the honeypot case.
*/
addr = STACK_TOP - ABOVE_KMEM;
continue;
}
npgd = pgd_offset(mm, addr);
npmd = pmd_offset(npgd, addr);
if(pmd_present(*npmd)){
npte = pte_offset_kernel(npmd, addr);
r = pte_read(*npte);
w = pte_write(*npte);
x = pte_exec(*npte);
if(!pte_dirty(*npte)) w = 0;
if(!pte_young(*npte)){
r = 0;
w = 0;
}
if(force || pte_newpage(*npte)){
err = unmap((void *) addr, PAGE_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
if(pte_present(*npte))
map(addr, pte_val(*npte) & PAGE_MASK,
PAGE_SIZE, r, w, x);
}
else if(pte_newprot(*npte)){
protect(addr, PAGE_SIZE, r, w, x, 1);
}
*npte = pte_mkuptodate(*npte);
addr += PAGE_SIZE;
}
else {
if(force || pmd_newpage(*npmd)){
err = unmap((void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
pmd_mkuptodate(*npmd);
}
addr += PMD_SIZE;
}
}
}
atomic_t vmchange_seq = ATOMIC_INIT(1);
void flush_kernel_range(unsigned long start, unsigned long end, int update_seq)
{
struct mm_struct *mm;
pgd_t *pgd;
pmd_t *pmd;
pte_t *pte;
unsigned long addr;
int updated = 0, err;
mm = &init_mm;
for(addr = start; addr < end;){
pgd = pgd_offset(mm, addr);
pmd = pmd_offset(pgd, addr);
if(pmd_present(*pmd)){
pte = pte_offset_kernel(pmd, addr);
if(!pte_present(*pte) || pte_newpage(*pte)){
updated = 1;
err = unmap((void *) addr, PAGE_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
if(pte_present(*pte))
map(addr, pte_val(*pte) & PAGE_MASK,
PAGE_SIZE, 1, 1, 1);
}
else if(pte_newprot(*pte)){
updated = 1;
protect(addr, PAGE_SIZE, 1, 1, 1, 1);
}
addr += PAGE_SIZE;
}
else {
if(pmd_newpage(*pmd)){
updated = 1;
err = unmap((void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
}
addr += PMD_SIZE;
}
}
if(updated && update_seq) atomic_inc(&vmchange_seq);
}
void flush_tlb_kernel_range(unsigned long start, unsigned long end)
{
flush_kernel_range(start, end, 1);
}
static void protect_vm_page(unsigned long addr, int w, int must_succeed)
{ {
int err; address &= PAGE_MASK;
flush_tlb_range(vma, address, address + PAGE_SIZE);
err = protect(addr, PAGE_SIZE, 1, w, 1, must_succeed);
if(err == 0) return;
else if((err == -EFAULT) || (err == -ENOMEM)){
flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
protect_vm_page(addr, w, 1);
}
else panic("protect_vm_page : protect failed, errno = %d\n", err);
} }
void mprotect_kernel_vm(int w) void flush_tlb_all(void)
{ {
struct mm_struct *mm; flush_tlb_mm(current->mm);
pgd_t *pgd;
pmd_t *pmd;
pte_t *pte;
unsigned long addr;
mm = &init_mm;
for(addr = start_vm; addr < end_vm;){
pgd = pgd_offset(mm, addr);
pmd = pmd_offset(pgd, addr);
if(pmd_present(*pmd)){
pte = pte_offset_kernel(pmd, addr);
if(pte_present(*pte)) protect_vm_page(addr, w, 0);
addr += PAGE_SIZE;
}
else addr += PMD_SIZE;
}
} }
void flush_tlb_kernel_vm(void) void flush_tlb_kernel_vm(void)
{ {
flush_tlb_kernel_range(start_vm, end_vm); CHOOSE_MODE(flush_tlb_kernel_vm_tt(), flush_tlb_kernel_vm_skas());
} }
void __flush_tlb_one(unsigned long addr) void __flush_tlb_one(unsigned long addr)
{ {
flush_tlb_kernel_range(addr, addr + PAGE_SIZE); CHOOSE_MODE_PROC(__flush_tlb_one_tt, __flush_tlb_one_skas, addr);
} }
void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
unsigned long end) unsigned long end)
{ {
if(vma->vm_mm != current->mm) CHOOSE_MODE_PROC(flush_tlb_range_tt, flush_tlb_range_skas, vma, start,
return; end);
/* Assumes that the range start ... end is entirely within
* either process memory or kernel vm
*/
if((start >= start_vm) && (start < end_vm))
flush_kernel_range(start, end, 1);
else fix_range(vma->vm_mm, start, end, 0);
} }
void flush_tlb_mm(struct mm_struct *mm) void flush_tlb_mm(struct mm_struct *mm)
{ {
unsigned long seq; CHOOSE_MODE_PROC(flush_tlb_mm_tt, flush_tlb_mm_skas, mm);
if(mm != current->mm)
return;
fix_range(mm, 0, STACK_TOP, 0);
seq = atomic_read(&vmchange_seq);
if(current->thread.vm_seq == seq) return;
current->thread.vm_seq = seq;
flush_kernel_range(start_vm, end_vm, 0);
}
void flush_tlb_page(struct vm_area_struct *vma, unsigned long address)
{
address &= PAGE_MASK;
flush_tlb_range(vma, address, address + PAGE_SIZE);
}
void flush_tlb_all(void)
{
flush_tlb_mm(current->mm);
} }
void force_flush_all(void) void force_flush_all(void)
{ {
fix_range(current->mm, 0, STACK_TOP, 1); CHOOSE_MODE(force_flush_all_tt(), force_flush_all_skas());
flush_kernel_range(start_vm, end_vm, 0);
} }
pgd_t *pgd_offset_proc(struct mm_struct *mm, unsigned long address) pgd_t *pgd_offset_proc(struct mm_struct *mm, unsigned long address)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
*/ */
#include "linux/kernel.h" #include "linux/kernel.h"
#include "asm/errno.h"
#include "linux/sched.h" #include "linux/sched.h"
#include "linux/mm.h" #include "linux/mm.h"
#include "linux/spinlock.h" #include "linux/spinlock.h"
...@@ -19,41 +20,36 @@ ...@@ -19,41 +20,36 @@
#include "kern_util.h" #include "kern_util.h"
#include "kern.h" #include "kern.h"
#include "chan_kern.h" #include "chan_kern.h"
#include "debug.h"
#include "mconsole_kern.h" #include "mconsole_kern.h"
#include "2_5compat.h" #include "2_5compat.h"
extern int nsyscalls; int handle_page_fault(unsigned long address, unsigned long ip,
int is_write, int is_user, int *code_out)
unsigned long segv(unsigned long address, unsigned long ip, int is_write,
int is_user, void *sc)
{ {
struct mm_struct *mm = current->mm; struct mm_struct *mm = current->mm;
struct vm_area_struct *vma; struct vm_area_struct *vma;
struct siginfo si;
void *catcher;
pgd_t *pgd; pgd_t *pgd;
pmd_t *pmd; pmd_t *pmd;
pte_t *pte; pte_t *pte;
unsigned long page; unsigned long page;
int err = -EFAULT;
if((address >= start_vm) && (address < end_vm)){ *code_out = SEGV_MAPERR;
flush_tlb_kernel_vm();
return(0);
}
if(mm == NULL) panic("Segfault with no mm");
catcher = current->thread.fault_catcher;
si.si_code = SEGV_MAPERR;
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
vma = find_vma(mm, address); vma = find_vma(mm, address);
if(!vma) goto bad; if(!vma)
else if(vma->vm_start <= address) goto good_area; goto out;
else if(!(vma->vm_flags & VM_GROWSDOWN)) goto bad; else if(vma->vm_start <= address)
else if(expand_stack(vma, address)) goto bad; goto good_area;
else if(!(vma->vm_flags & VM_GROWSDOWN))
goto out;
else if(expand_stack(vma, address))
goto out;
good_area: good_area:
si.si_code = SEGV_ACCERR; *code_out = SEGV_ACCERR;
if(is_write && !(vma->vm_flags & VM_WRITE)) goto bad; if(is_write && !(vma->vm_flags & VM_WRITE))
goto out;
page = address & PAGE_MASK; page = address & PAGE_MASK;
if(page == (unsigned long) current->thread_info + PAGE_SIZE) if(page == (unsigned long) current->thread_info + PAGE_SIZE)
panic("Kernel stack overflow"); panic("Kernel stack overflow");
...@@ -69,8 +65,10 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write, ...@@ -69,8 +65,10 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
current->maj_flt++; current->maj_flt++;
break; break;
case VM_FAULT_SIGBUS: case VM_FAULT_SIGBUS:
goto do_sigbus; err = -EACCES;
goto out;
case VM_FAULT_OOM: case VM_FAULT_OOM:
err = -ENOMEM;
goto out_of_memory; goto out_of_memory;
default: default:
BUG(); BUG();
...@@ -80,44 +78,46 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write, ...@@ -80,44 +78,46 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
*pte = pte_mkyoung(*pte); *pte = pte_mkyoung(*pte);
if(pte_write(*pte)) *pte = pte_mkdirty(*pte); if(pte_write(*pte)) *pte = pte_mkdirty(*pte);
flush_tlb_page(vma, page); flush_tlb_page(vma, page);
err = 0;
out:
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
return(0); return(err);
do_sigbus:
up_read(&mm->mmap_sem);
/*
* Send a sigbus, regardless of whether we were in kernel
* or user mode.
*/
si.si_signo = SIGBUS;
si.si_errno = 0;
si.si_code = BUS_ADRERR;
si.si_addr = (void *)address;
force_sig_info(SIGBUS, &si, current);
if(!is_user) goto bad;
return(0);
/* /*
* We ran out of memory, or some other thing happened to us that made * We ran out of memory, or some other thing happened to us that made
* us unable to handle the page fault gracefully. * us unable to handle the page fault gracefully.
*/ */
out_of_memory: out_of_memory:
up_read(&mm->mmap_sem);
if (current->pid == 1) { if (current->pid == 1) {
up_read(&mm->mmap_sem);
yield(); yield();
down_read(&mm->mmap_sem); down_read(&mm->mmap_sem);
goto survive; goto survive;
} }
printk("VM: killing process %s\n", current->comm); err = -ENOMEM;
if(is_user) goto out;
do_exit(SIGKILL); }
unsigned long segv(unsigned long address, unsigned long ip, int is_write,
int is_user, void *sc)
{
struct siginfo si;
void *catcher;
int err;
/* Fall through to bad */ if(!is_user && (address >= start_vm) && (address < end_vm)){
flush_tlb_kernel_vm();
return(0);
}
if(current->mm == NULL) panic("Segfault with no mm");
err = handle_page_fault(address, ip, is_write, is_user, &si.si_code);
bad: catcher = current->thread.fault_catcher;
if(catcher != NULL){ if(!err)
return(0);
else if(catcher != NULL){
current->thread.fault_addr = (void *) address; current->thread.fault_addr = (void *) address;
up_read(&mm->mmap_sem); do_longjmp(catcher, 1);
do_longjmp(catcher);
} }
else if(current->thread.fault_addr != NULL){ else if(current->thread.fault_addr != NULL){
panic("fault_addr set but no fault catcher"); panic("fault_addr set but no fault catcher");
...@@ -125,15 +125,28 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write, ...@@ -125,15 +125,28 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
else if(arch_fixup(ip, sc)) else if(arch_fixup(ip, sc))
return(0); return(0);
if(!is_user) if(!is_user)
panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", panic("Kernel mode fault at addr 0x%lx, ip 0x%lx",
address, ip); address, ip);
si.si_signo = SIGSEGV;
si.si_addr = (void *) address; if(err == -EACCES){
current->thread.cr2 = address; si.si_signo = SIGBUS;
current->thread.err = is_write; si.si_errno = 0;
force_sig_info(SIGSEGV, &si, current); si.si_code = BUS_ADRERR;
up_read(&mm->mmap_sem); si.si_addr = (void *)address;
force_sig_info(SIGBUS, &si, current);
}
else if(err == -ENOMEM){
printk("VM: killing process %s\n", current->comm);
do_exit(SIGKILL);
}
else {
si.si_signo = SIGSEGV;
si.si_addr = (void *) address;
current->thread.cr2 = address;
current->thread.err = is_write;
force_sig_info(SIGSEGV, &si, current);
}
return(0); return(0);
} }
...@@ -161,7 +174,7 @@ void relay_signal(int sig, struct uml_pt_regs *regs) ...@@ -161,7 +174,7 @@ void relay_signal(int sig, struct uml_pt_regs *regs)
void bus_handler(int sig, struct uml_pt_regs *regs) void bus_handler(int sig, struct uml_pt_regs *regs)
{ {
if(current->thread.fault_catcher != NULL) if(current->thread.fault_catcher != NULL)
do_longjmp(current->thread.fault_catcher); do_longjmp(current->thread.fault_catcher, 1);
else relay_signal(sig, regs); else relay_signal(sig, regs);
} }
...@@ -185,250 +198,6 @@ int next_trap_index(int limit) ...@@ -185,250 +198,6 @@ int next_trap_index(int limit)
return(ret); return(ret);
} }
extern int debugger_pid;
extern int debugger_fd;
extern int debugger_parent;
#ifdef CONFIG_PT_PROXY
int debugger_signal(int status, pid_t pid)
{
return(debugger_proxy(status, pid));
}
void child_signal(pid_t pid, int status)
{
child_proxy(pid, status);
}
static void gdb_announce(char *dev_name, int dev)
{
printf("gdb assigned device '%s'\n", dev_name);
}
static struct chan_opts opts = {
announce : gdb_announce,
xterm_title : "UML kernel debugger",
raw : 0,
tramp_stack : 0,
in_kernel : 0,
};
/* Accessed by the tracing thread, which automatically serializes access */
static void *xterm_data;
static int xterm_fd;
extern void *xterm_init(char *, int, struct chan_opts *);
extern int xterm_open(int, int, int, void *);
extern void xterm_close(int, void *);
int open_gdb_chan(void)
{
char stack[PAGE_SIZE];
opts.tramp_stack = (unsigned long) stack;
xterm_data = xterm_init("", 0, &opts);
xterm_fd = xterm_open(1, 1, 1, xterm_data);
return(xterm_fd);
}
static void exit_debugger_cb(void *unused)
{
if(debugger_pid != -1){
if(gdb_pid != -1){
fake_child_exit();
gdb_pid = -1;
}
else kill_child_dead(debugger_pid);
debugger_pid = -1;
if(debugger_parent != -1)
detach(debugger_parent, SIGINT);
}
if(xterm_data != NULL) xterm_close(xterm_fd, xterm_data);
}
static void exit_debugger(void)
{
tracing_cb(exit_debugger_cb, NULL);
}
__uml_exitcall(exit_debugger);
struct gdb_data {
char *str;
int err;
};
static void config_gdb_cb(void *arg)
{
struct gdb_data *data = arg;
struct task_struct *task;
int pid;
data->err = -1;
if(debugger_pid != -1) exit_debugger_cb(NULL);
if(!strncmp(data->str, "pid,", strlen("pid,"))){
data->str += strlen("pid,");
pid = simple_strtoul(data->str, NULL, 0);
task = cpu_tasks[0].task;
debugger_pid = attach_debugger(task->thread.extern_pid,
pid, 0);
if(debugger_pid != -1){
data->err = 0;
gdb_pid = pid;
}
return;
}
data->err = 0;
debugger_pid = start_debugger(linux_prog, 0, 0, &debugger_fd);
init_proxy(debugger_pid, 0, 0);
}
int gdb_config(char *str)
{
struct gdb_data data;
if(*str++ != '=') return(-1);
data.str = str;
tracing_cb(config_gdb_cb, &data);
return(data.err);
}
void remove_gdb_cb(void *unused)
{
exit_debugger_cb(NULL);
}
int gdb_remove(char *unused)
{
tracing_cb(remove_gdb_cb, NULL);
return(0);
}
#ifdef CONFIG_MCONSOLE
static struct mc_device gdb_mc = {
name: "gdb",
config: gdb_config,
remove: gdb_remove,
};
int gdb_mc_init(void)
{
mconsole_register_dev(&gdb_mc);
return(0);
}
__initcall(gdb_mc_init);
#endif
void signal_usr1(int sig)
{
if(debugger_pid != -1){
printk(KERN_ERR "The debugger is already running\n");
return;
}
debugger_pid = start_debugger(linux_prog, 0, 0, &debugger_fd);
init_proxy(debugger_pid, 0, 0);
}
int init_ptrace_proxy(int idle_pid, int startup, int stop)
{
int pid, status;
pid = start_debugger(linux_prog, startup, stop, &debugger_fd);
status = wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT, NULL);
if(pid < 0){
cont(idle_pid);
return(-1);
}
init_proxy(pid, 1, status);
return(pid);
}
int attach_debugger(int idle_pid, int pid, int stop)
{
int status = 0, err;
err = attach(pid);
if(err < 0){
printf("Failed to attach pid %d, errno = %d\n", pid, -err);
return(-1);
}
if(stop) status = wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT, NULL);
init_proxy(pid, 1, status);
return(pid);
}
#ifdef notdef /* Put this back in when it does something useful */
static int __init uml_gdb_init_setup(char *line, int *add)
{
gdb_init = uml_strdup(line);
return 0;
}
__uml_setup("gdb=", uml_gdb_init_setup,
"gdb=<channel description>\n\n"
);
#endif
static int __init uml_gdb_pid_setup(char *line, int *add)
{
gdb_pid = simple_strtoul(line, NULL, 0);
*add = 0;
return 0;
}
__uml_setup("gdb-pid=", uml_gdb_pid_setup,
"gdb-pid=<pid>\n"
" gdb-pid is used to attach an external debugger to UML. This may be\n"
" an already-running gdb or a debugger-like process like strace.\n\n"
);
#else
int debugger_signal(int status, pid_t pid){ return(0); }
void child_signal(pid_t pid, int status){ }
int init_ptrace_proxy(int idle_pid, int startup, int stop)
{
printk(KERN_ERR "debug requested when CONFIG_PT_PROXY is off\n");
kill_child_dead(idle_pid);
exit(1);
}
void signal_usr1(int sig)
{
printk(KERN_ERR "debug requested when CONFIG_PT_PROXY is off\n");
}
int attach_debugger(int idle_pid, int pid, int stop)
{
printk(KERN_ERR "attach_debugger called when CONFIG_PT_PROXY "
"is off\n");
return(-1);
}
int config_gdb(char *str)
{
return(-1);
}
int remove_gdb(void)
{
return(-1);
}
int init_parent_proxy(int pid)
{
return(-1);
}
void debugger_parent_signal(int status, int pid)
{
}
#endif
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically * Emacs will notice this stuff at the end of the file and automatically
......
...@@ -3,66 +3,33 @@ ...@@ -3,66 +3,33 @@
* Licensed under the GPL * Licensed under the GPL
*/ */
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h> #include <errno.h>
#include <sched.h>
#include <fcntl.h> #include <fcntl.h>
#include <setjmp.h> #include <setjmp.h>
#include <string.h> #include <signal.h>
#include <sys/ptrace.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <asm/page.h> #include <asm/page.h>
#include <asm/unistd.h> #include <asm/unistd.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>
#include "user_util.h" #include "init.h"
#include "kern_util.h" #include "sysdep/ptrace.h"
#include "signal_user.h"
#include "mem_user.h"
#include "user.h"
#include "process.h"
#include "sigcontext.h" #include "sigcontext.h"
#include "sysdep/sigcontext.h" #include "sysdep/sigcontext.h"
#include "init.h"
#include "chan_user.h"
#include "irq_user.h" #include "irq_user.h"
#include "frame_user.h" #include "frame_user.h"
#include "syscall_user.h" #include "signal_user.h"
#include "ptrace_user.h"
#include "time_user.h" #include "time_user.h"
#include "task.h" #include "task.h"
#include "mode.h"
#include "choose-mode.h"
#include "kern_util.h"
#include "user_util.h"
#include "os.h" #include "os.h"
static void signal_segv(int sig)
{
write(2, "Seg fault in signals\n", strlen("Seg fault in signals\n"));
for(;;) ;
}
int detach(int pid, int sig)
{
return(ptrace(PTRACE_DETACH, pid, 0, sig));
}
int attach(int pid)
{
int err;
err = ptrace(PTRACE_ATTACH, pid, 0, 0);
if(err < 0) return(-errno);
else return(err);
}
int cont(int pid)
{
return(ptrace(PTRACE_CONT, pid, 0, 0));
}
void kill_child_dead(int pid) void kill_child_dead(int pid)
{ {
kill(pid, SIGKILL); kill(pid, SIGKILL);
...@@ -70,336 +37,6 @@ void kill_child_dead(int pid) ...@@ -70,336 +37,6 @@ void kill_child_dead(int pid)
while(waitpid(pid, NULL, 0) > 0) kill(pid, SIGCONT); while(waitpid(pid, NULL, 0) > 0) kill(pid, SIGCONT);
} }
/* Changed early in boot, and then only read */
int debug = 0;
int debug_stop = 1;
int debug_parent = 0;
int honeypot = 0;
static int signal_tramp(void *arg)
{
int (*proc)(void *);
if(honeypot && munmap((void *) (host_task_size - 0x10000000),
0x10000000))
panic("Unmapping stack failed");
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0)
panic("ptrace PTRACE_TRACEME failed");
os_stop_process(os_getpid());
change_sig(SIGWINCH, 0);
signal(SIGUSR1, SIG_IGN);
change_sig(SIGCHLD, 0);
signal(SIGSEGV, (__sighandler_t) sig_handler);
set_cmdline("(idle thread)");
set_init_pid(os_getpid());
proc = arg;
return((*proc)(NULL));
}
static void last_ditch_exit(int sig)
{
kmalloc_ok = 0;
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
uml_cleanup();
exit(1);
}
static void sleeping_process_signal(int pid, int sig)
{
switch(sig){
/* These two result from UML being ^Z-ed and bg-ed. PTRACE_CONT is
* right because the process must be in the kernel already.
*/
case SIGCONT:
case SIGTSTP:
if(ptrace(PTRACE_CONT, pid, 0, sig) < 0)
tracer_panic("sleeping_process_signal : Failed to "
"continue pid %d, errno = %d\n", pid,
sig);
break;
/* This happens when the debugger (e.g. strace) is doing system call
* tracing on the kernel. During a context switch, the current task
* will be set to the incoming process and the outgoing process will
* hop into write and then read. Since it's not the current process
* any more, the trace of those will land here. So, we need to just
* PTRACE_SYSCALL it.
*/
case SIGTRAP:
if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0)
tracer_panic("sleeping_process_signal : Failed to "
"PTRACE_SYSCALL pid %d, errno = %d\n",
pid, sig);
break;
case SIGSTOP:
break;
default:
tracer_panic("sleeping process %d got unexpected "
"signal : %d\n", pid, sig);
break;
}
}
/* Accessed only by the tracing thread */
int debugger_pid = -1;
int debugger_parent = -1;
int debugger_fd = -1;
int gdb_pid = -1;
struct {
int pid;
int signal;
unsigned long addr;
struct timeval time;
} signal_record[1024][32];
int signal_index[32];
int nsignals = 0;
int debug_trace = 0;
extern int io_nsignals, io_count, intr_count;
extern void signal_usr1(int sig);
int tracing_pid = -1;
int signals(int (*init_proc)(void *), void *sp)
{
void *task = NULL;
unsigned long eip = 0;
int status, pid = 0, sig = 0, cont_type, tracing = 0, op = 0;
int last_index, proc_id = 0, n, err, old_tracing = 0, strace = 0;
capture_signal_stack();
signal(SIGPIPE, SIG_IGN);
setup_tracer_winch();
tracing_pid = os_getpid();
printf("tracing thread pid = %d\n", tracing_pid);
pid = clone(signal_tramp, sp, CLONE_FILES | SIGCHLD, init_proc);
n = waitpid(pid, &status, WUNTRACED);
if(n < 0){
printf("waitpid on idle thread failed, errno = %d\n", errno);
exit(1);
}
if((ptrace(PTRACE_CONT, pid, 0, 0) < 0)){
printf("Failed to continue idle thread, errno = %d\n", errno);
exit(1);
}
signal(SIGSEGV, signal_segv);
signal(SIGUSR1, signal_usr1);
set_handler(SIGINT, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGTERM, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGHUP, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
if(debug_trace){
printf("Tracing thread pausing to be attached\n");
stop();
}
if(debug){
if(gdb_pid != -1)
debugger_pid = attach_debugger(pid, gdb_pid, 1);
else debugger_pid = init_ptrace_proxy(pid, 1, debug_stop);
if(debug_parent){
debugger_parent = os_process_parent(debugger_pid);
init_parent_proxy(debugger_parent);
err = attach(debugger_parent);
if(err){
printf("Failed to attach debugger parent %d, "
"errno = %d\n", debugger_parent, err);
debugger_parent = -1;
}
else {
if(ptrace(PTRACE_SYSCALL, debugger_parent,
0, 0) < 0){
printf("Failed to continue debugger "
"parent, errno = %d\n", errno);
debugger_parent = -1;
}
}
}
}
set_cmdline("(tracing thread)");
while(1){
if((pid = waitpid(-1, &status, WUNTRACED)) <= 0){
if(errno != ECHILD){
printf("wait failed - errno = %d\n", errno);
}
continue;
}
if(pid == debugger_pid){
int cont = 0;
if(WIFEXITED(status) || WIFSIGNALED(status))
debugger_pid = -1;
/* XXX Figure out how to deal with gdb and SMP */
else cont = debugger_signal(status, cpu_tasks[0].pid);
if(cont == PTRACE_SYSCALL) strace = 1;
continue;
}
else if(pid == debugger_parent){
debugger_parent_signal(status, pid);
continue;
}
nsignals++;
if(WIFEXITED(status)) ;
#ifdef notdef
{
printf("Child %d exited with status %d\n", pid,
WEXITSTATUS(status));
}
#endif
else if(WIFSIGNALED(status)){
sig = WTERMSIG(status);
if(sig != 9){
printf("Child %d exited with signal %d\n", pid,
sig);
}
}
else if(WIFSTOPPED(status)){
proc_id = pid_to_processor_id(pid);
sig = WSTOPSIG(status);
if(signal_index[proc_id] == 1024){
signal_index[proc_id] = 0;
last_index = 1023;
}
else last_index = signal_index[proc_id] - 1;
if(((sig == SIGPROF) || (sig == SIGVTALRM) ||
(sig == SIGALRM)) &&
(signal_record[proc_id][last_index].signal == sig)&&
(signal_record[proc_id][last_index].pid == pid))
signal_index[proc_id] = last_index;
signal_record[proc_id][signal_index[proc_id]].pid = pid;
gettimeofday(&signal_record[proc_id][signal_index[proc_id]].time, NULL);
eip = ptrace(PTRACE_PEEKUSER, pid, PT_IP_OFFSET, 0);
signal_record[proc_id][signal_index[proc_id]].addr = eip;
signal_record[proc_id][signal_index[proc_id]++].signal = sig;
if(proc_id == -1){
sleeping_process_signal(pid, sig);
continue;
}
task = cpu_tasks[proc_id].task;
tracing = is_tracing(task);
old_tracing = tracing;
switch(sig){
case SIGUSR1:
sig = 0;
op = do_proc_op(task, proc_id);
switch(op){
case OP_TRACE_ON:
arch_leave_kernel(task, pid);
tracing = 1;
break;
case OP_REBOOT:
case OP_HALT:
unmap_physmem();
kmalloc_ok = 0;
ptrace(PTRACE_KILL, pid, 0, 0);
return(op == OP_REBOOT);
case OP_NONE:
printf("Detaching pid %d\n", pid);
detach(pid, SIGSTOP);
continue;
default:
break;
}
/* OP_EXEC switches host processes on us,
* we want to continue the new one.
*/
pid = cpu_tasks[proc_id].pid;
break;
case SIGTRAP:
if(!tracing && (debugger_pid != -1)){
child_signal(pid, status);
continue;
}
tracing = 0;
if(do_syscall(task, pid)) sig = SIGUSR2;
else clear_singlestep(task);
break;
case SIGPROF:
if(tracing) sig = 0;
break;
case SIGCHLD:
case SIGHUP:
sig = 0;
break;
case SIGSEGV:
case SIGIO:
case SIGALRM:
case SIGVTALRM:
case SIGFPE:
case SIGBUS:
case SIGILL:
case SIGWINCH:
default:
tracing = 0;
break;
}
set_tracing(task, tracing);
if(!tracing && old_tracing)
arch_enter_kernel(task, pid);
if(!tracing && (debugger_pid != -1) && (sig != 0) &&
(sig != SIGALRM) && (sig != SIGVTALRM) &&
(sig != SIGSEGV) && (sig != SIGTRAP) &&
(sig != SIGUSR2) && (sig != SIGIO)){
child_signal(pid, status);
continue;
}
if(tracing){
if(singlestepping(task))
cont_type = PTRACE_SINGLESTEP;
else cont_type = PTRACE_SYSCALL;
}
else cont_type = PTRACE_CONT;
if((cont_type == PTRACE_CONT) &&
(debugger_pid != -1) && strace)
cont_type = PTRACE_SYSCALL;
if(ptrace(cont_type, pid, 0, sig) != 0){
tracer_panic("ptrace failed to continue "
"process - errno = %d\n",
errno);
}
}
}
return(0);
}
static int __init uml_debugtrace_setup(char *line, int *add)
{
debug_trace = 1;
return 0;
}
__uml_setup("debugtrace", uml_debugtrace_setup,
"debugtrace\n"
" Causes the tracing thread to pause until it is attached by a\n"
" debugger and continued. This is mostly for debugging crashes\n"
" early during boot, and should be pretty much obsoleted by\n"
" the debug switch.\n\n"
);
static int __init uml_honeypot_setup(char *line, int *add)
{
jail_setup("", add);
honeypot = 1;
return 0;
}
__uml_setup("honeypot", uml_honeypot_setup,
"honeypot\n"
" This makes UML put process stacks in the same location as they are\n"
" on the host, allowing expoits such as stack smashes to work against\n"
" UML. This implies 'jail'.\n\n"
);
/* Unlocked - don't care if this is a bit off */ /* Unlocked - don't care if this is a bit off */
int nsegfaults = 0; int nsegfaults = 0;
...@@ -413,33 +50,32 @@ struct { ...@@ -413,33 +50,32 @@ struct {
void segv_handler(int sig, struct uml_pt_regs *regs) void segv_handler(int sig, struct uml_pt_regs *regs)
{ {
struct sigcontext *context = regs->sc;
int index, max; int index, max;
if(regs->is_user && !SEGV_IS_FIXABLE(context)){ if(regs->is_user && !UPT_SEGV_IS_FIXABLE(regs)){
bad_segv(SC_FAULT_ADDR(context), SC_IP(context), bad_segv(UPT_FAULT_ADDR(regs), UPT_IP(regs),
SC_FAULT_WRITE(context)); UPT_FAULT_WRITE(regs));
return; return;
} }
max = sizeof(segfault_record)/sizeof(segfault_record[0]); max = sizeof(segfault_record)/sizeof(segfault_record[0]);
index = next_trap_index(max); index = next_trap_index(max);
nsegfaults++; nsegfaults++;
segfault_record[index].address = SC_FAULT_ADDR(context); segfault_record[index].address = UPT_FAULT_ADDR(regs);
segfault_record[index].pid = os_getpid(); segfault_record[index].pid = os_getpid();
segfault_record[index].is_write = SC_FAULT_WRITE(context); segfault_record[index].is_write = UPT_FAULT_WRITE(regs);
segfault_record[index].sp = SC_SP(context); segfault_record[index].sp = UPT_SP(regs);
segfault_record[index].is_user = regs->is_user; segfault_record[index].is_user = regs->is_user;
segv(SC_FAULT_ADDR(context), SC_IP(context), SC_FAULT_WRITE(context), segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), UPT_FAULT_WRITE(regs),
regs->is_user, context); regs->is_user, regs);
} }
struct signal_info { void usr2_handler(int sig, struct uml_pt_regs *regs)
void (*handler)(int, struct uml_pt_regs *); {
int is_irq; CHOOSE_MODE(syscall_handler_tt(sig, regs), (void) 0);
}; }
static struct signal_info sig_info[] = { struct signal_info sig_info[] = {
[ SIGTRAP ] { handler : relay_signal, [ SIGTRAP ] { handler : relay_signal,
is_irq : 0 }, is_irq : 0 },
[ SIGFPE ] { handler : relay_signal, [ SIGFPE ] { handler : relay_signal,
...@@ -454,104 +90,42 @@ static struct signal_info sig_info[] = { ...@@ -454,104 +90,42 @@ static struct signal_info sig_info[] = {
is_irq : 1 }, is_irq : 1 },
[ SIGVTALRM ] { handler : timer_handler, [ SIGVTALRM ] { handler : timer_handler,
is_irq : 1 }, is_irq : 1 },
[ SIGALRM ] { handler : timer_handler, [ SIGALRM ] { handler : timer_handler,
is_irq : 1 }, is_irq : 1 },
[ SIGUSR2 ] { handler : syscall_handler, [ SIGUSR2 ] { handler : usr2_handler,
is_irq : 0 }, is_irq : 0 },
}; };
void sig_handler_common(int sig, struct sigcontext *sc)
{
struct uml_pt_regs save_regs, *r;
struct signal_info *info;
int save_errno = errno, is_user;
unprotect_kernel_mem();
r = (struct uml_pt_regs *) TASK_REGS(get_current());
save_regs = *r;
is_user = user_context(SC_SP(sc));
r->is_user = is_user;
r->sc = sc;
if(sig != SIGUSR2) r->syscall = -1;
change_sig(SIGUSR1, 1);
info = &sig_info[sig];
if(!info->is_irq) unblock_signals();
(*info->handler)(sig, r);
if(is_user){
interrupt_end();
block_signals();
change_sig(SIGUSR1, 0);
set_user_mode(NULL);
}
*r = save_regs;
errno = save_errno;
if(is_user) protect_kernel_mem();
}
void sig_handler(int sig, struct sigcontext sc) void sig_handler(int sig, struct sigcontext sc)
{ {
sig_handler_common(sig, &sc); CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
sig, &sc);
} }
extern int timer_irq_inited, missed_ticks[]; extern int timer_irq_inited, missed_ticks[];
void alarm_handler(int sig, struct sigcontext sc) void alarm_handler(int sig, struct sigcontext sc)
{ {
int user;
if(!timer_irq_inited) return; if(!timer_irq_inited) return;
missed_ticks[cpu()]++; missed_ticks[cpu()]++;
user = user_context(SC_SP(&sc));
if(sig == SIGALRM) if(sig == SIGALRM)
switch_timers(0); switch_timers(0);
sig_handler_common(sig, &sc); CHOOSE_MODE_PROC(sig_handler_common_tt, sig_handler_common_skas,
sig, &sc);
if(sig == SIGALRM) if(sig == SIGALRM)
switch_timers(1); switch_timers(1);
} }
void do_longjmp(void *p) void do_longjmp(void *b, int val)
{ {
jmp_buf *jbuf = (jmp_buf *) p; jmp_buf *buf = b;
longjmp(*jbuf, 1); longjmp(*buf, val);
} }
static int __init uml_debug_setup(char *line, int *add)
{
char *next;
debug = 1;
*add = 0;
if(*line != '=') return(0);
line++;
while(line != NULL){
next = strchr(line, ',');
if(next) *next++ = '\0';
if(!strcmp(line, "go")) debug_stop = 0;
else if(!strcmp(line, "parent")) debug_parent = 1;
else printk("Unknown debug option : '%s'\n", line);
line = next;
}
return(0);
}
__uml_setup("debug", uml_debug_setup,
"debug\n"
" Starts up the kernel under the control of gdb. See the \n"
" kernel debugging tutorial and the debugging session pages\n"
" at http://user-mode-linux.sourceforge.net/ for more information.\n\n"
);
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically * Emacs will notice this stuff at the end of the file and automatically
......
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
obj-y = exec_kern.o exec_user.o gdb.o gdb_kern.o ksyms.o mem.o process_kern.o \
syscall_kern.o syscall_user.o time.o tlb.o tracer.o trap_user.o \
uaccess_user.o sys-$(SUBARCH)/
obj-$(CONFIG_PT_PROXY) += ptproxy/
export-objs = ksyms.o
USER_OBJS := $(filter %_user.o,$(obj-y)) gdb.o time.o tracer.o
USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
clean :
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/kernel.h"
#include "linux/mm.h"
#include "asm/signal.h"
#include "asm/ptrace.h"
#include "asm/uaccess.h"
#include "asm/pgalloc.h"
#include "asm/tlbflush.h"
#include "user_util.h"
#include "kern_util.h"
#include "irq_user.h"
#include "time_user.h"
#include "mem_user.h"
#include "os.h"
#include "tlb.h"
static int exec_tramp(void *sig_stack)
{
init_new_thread_stack(sig_stack, NULL);
init_new_thread_signals(1);
os_stop_process(os_getpid());
return(0);
}
void flush_thread_tt(void)
{
unsigned long stack;
int new_pid;
stack = alloc_stack(0, 0);
if(stack == 0){
printk(KERN_ERR
"flush_thread : failed to allocate temporary stack\n");
do_exit(SIGKILL);
}
new_pid = start_fork_tramp((void *) current->thread.kernel_stack,
stack, 0, exec_tramp);
if(new_pid < 0){
printk(KERN_ERR
"flush_thread : new thread failed, errno = %d\n",
-new_pid);
do_exit(SIGKILL);
}
if(current->thread_info->cpu == 0)
forward_interrupts(new_pid);
current->thread.request.op = OP_EXEC;
current->thread.request.u.exec.pid = new_pid;
unprotect_stack((unsigned long) current->thread_info);
os_usr1_process(os_getpid());
enable_timer();
free_page(stack);
protect_memory(uml_reserved, high_physmem - uml_reserved, 1, 1, 0, 1);
task_protections((unsigned long) current->thread_info);
force_flush_all();
unblock_signals();
}
void start_thread_tt(struct pt_regs *regs, unsigned long eip,
unsigned long esp)
{
set_fs(USER_DS);
flush_tlb_mm(current->mm);
PT_REGS_IP(regs) = eip;
PT_REGS_SP(regs) = esp;
PT_FIX_EXEC_STACK(esp);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include "uml-config.h"
#include "kern_constants.h"
#include "chan_user.h"
#include "init.h"
#include "user.h"
#include "debug.h"
#include "kern_util.h"
#include "user_util.h"
#include "tt.h"
#include "sysdep/thread.h"
extern int debugger_pid;
extern int debugger_fd;
extern int debugger_parent;
int detach(int pid, int sig)
{
return(ptrace(PTRACE_DETACH, pid, 0, sig));
}
int attach(int pid)
{
int err;
err = ptrace(PTRACE_ATTACH, pid, 0, 0);
if(err < 0) return(-errno);
else return(err);
}
int cont(int pid)
{
return(ptrace(PTRACE_CONT, pid, 0, 0));
}
#ifdef CONFIG_PT_PROXY
int debugger_signal(int status, pid_t pid)
{
return(debugger_proxy(status, pid));
}
void child_signal(pid_t pid, int status)
{
child_proxy(pid, status);
}
static void gdb_announce(char *dev_name, int dev)
{
printf("gdb assigned device '%s'\n", dev_name);
}
static struct chan_opts opts = {
announce : gdb_announce,
xterm_title : "UML kernel debugger",
raw : 0,
tramp_stack : 0,
in_kernel : 0,
};
/* Accessed by the tracing thread, which automatically serializes access */
static void *xterm_data;
static int xterm_fd;
extern void *xterm_init(char *, int, struct chan_opts *);
extern int xterm_open(int, int, int, void *);
extern void xterm_close(int, void *);
int open_gdb_chan(void)
{
char stack[UM_KERN_PAGE_SIZE];
opts.tramp_stack = (unsigned long) stack;
xterm_data = xterm_init("", 0, &opts);
xterm_fd = xterm_open(1, 1, 1, xterm_data);
return(xterm_fd);
}
static void exit_debugger_cb(void *unused)
{
if(debugger_pid != -1){
if(gdb_pid != -1){
fake_child_exit();
gdb_pid = -1;
}
else kill_child_dead(debugger_pid);
debugger_pid = -1;
if(debugger_parent != -1)
detach(debugger_parent, SIGINT);
}
if(xterm_data != NULL) xterm_close(xterm_fd, xterm_data);
}
static void exit_debugger(void)
{
initial_thread_cb(exit_debugger_cb, NULL);
}
__uml_exitcall(exit_debugger);
struct gdb_data {
char *str;
int err;
};
static void config_gdb_cb(void *arg)
{
struct gdb_data *data = arg;
void *task;
int pid;
data->err = -1;
if(debugger_pid != -1) exit_debugger_cb(NULL);
if(!strncmp(data->str, "pid,", strlen("pid,"))){
data->str += strlen("pid,");
pid = strtoul(data->str, NULL, 0);
task = cpu_tasks[0].task;
debugger_pid = attach_debugger(TASK_EXTERN_PID(task), pid, 0);
if(debugger_pid != -1){
data->err = 0;
gdb_pid = pid;
}
return;
}
data->err = 0;
debugger_pid = start_debugger(linux_prog, 0, 0, &debugger_fd);
init_proxy(debugger_pid, 0, 0);
}
int gdb_config(char *str)
{
struct gdb_data data;
if(*str++ != '=') return(-1);
data.str = str;
initial_thread_cb(config_gdb_cb, &data);
return(data.err);
}
void remove_gdb_cb(void *unused)
{
exit_debugger_cb(NULL);
}
int gdb_remove(char *unused)
{
initial_thread_cb(remove_gdb_cb, NULL);
return(0);
}
void signal_usr1(int sig)
{
if(debugger_pid != -1){
printk(UM_KERN_ERR "The debugger is already running\n");
return;
}
debugger_pid = start_debugger(linux_prog, 0, 0, &debugger_fd);
init_proxy(debugger_pid, 0, 0);
}
int init_ptrace_proxy(int idle_pid, int startup, int stop)
{
int pid, status;
pid = start_debugger(linux_prog, startup, stop, &debugger_fd);
status = wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT, NULL);
if(pid < 0){
cont(idle_pid);
return(-1);
}
init_proxy(pid, 1, status);
return(pid);
}
int attach_debugger(int idle_pid, int pid, int stop)
{
int status = 0, err;
err = attach(pid);
if(err < 0){
printf("Failed to attach pid %d, errno = %d\n", pid, -err);
return(-1);
}
if(stop) status = wait_for_stop(idle_pid, SIGSTOP, PTRACE_CONT, NULL);
init_proxy(pid, 1, status);
return(pid);
}
#ifdef notdef /* Put this back in when it does something useful */
static int __init uml_gdb_init_setup(char *line, int *add)
{
gdb_init = uml_strdup(line);
return 0;
}
__uml_setup("gdb=", uml_gdb_init_setup,
"gdb=<channel description>\n\n"
);
#endif
static int __init uml_gdb_pid_setup(char *line, int *add)
{
gdb_pid = strtoul(line, NULL, 0);
*add = 0;
return 0;
}
__uml_setup("gdb-pid=", uml_gdb_pid_setup,
"gdb-pid=<pid>\n"
" gdb-pid is used to attach an external debugger to UML. This may be\n"
" an already-running gdb or a debugger-like process like strace.\n\n"
);
#else
int debugger_signal(int status, pid_t pid){ return(0); }
void child_signal(pid_t pid, int status){ }
int init_ptrace_proxy(int idle_pid, int startup, int stop)
{
printk(UM_KERN_ERR "debug requested when CONFIG_PT_PROXY is off\n");
kill_child_dead(idle_pid);
exit(1);
}
void signal_usr1(int sig)
{
printk(UM_KERN_ERR "debug requested when CONFIG_PT_PROXY is off\n");
}
int attach_debugger(int idle_pid, int pid, int stop)
{
printk(UM_KERN_ERR "attach_debugger called when CONFIG_PT_PROXY "
"is off\n");
return(-1);
}
int config_gdb(char *str)
{
return(-1);
}
int remove_gdb(void)
{
return(-1);
}
int init_parent_proxy(int pid)
{
return(-1);
}
void debugger_parent_signal(int status, int pid)
{
}
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/init.h"
#include "linux/config.h"
#include "mconsole_kern.h"
#ifdef CONFIG_MCONSOLE
extern int gdb_config(char *str);
extern int gdb_remove(char *unused);
static struct mc_device gdb_mc = {
name: "gdb",
config: gdb_config,
remove: gdb_remove,
};
int gdb_mc_init(void)
{
mconsole_register_dev(&gdb_mc);
return(0);
}
__initcall(gdb_mc_init);
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Lars Brinkhoff. * Lars Brinkhoff.
* Licensed under the GPL * Licensed under the GPL
*/ */
#ifndef __DEBUG_H #ifndef __DEBUG_H
#define __DEBUG_H #define __DEBUG_H
...@@ -11,6 +12,8 @@ extern void child_proxy(pid_t pid, int status); ...@@ -11,6 +12,8 @@ extern void child_proxy(pid_t pid, int status);
extern void init_proxy (pid_t pid, int waiting, int status); extern void init_proxy (pid_t pid, int waiting, int status);
extern int start_debugger(char *prog, int startup, int stop, int *debugger_fd); extern int start_debugger(char *prog, int startup, int stop, int *debugger_fd);
extern void fake_child_exit(void); extern void fake_child_exit(void);
extern int gdb_config(char *str);
extern int gdb_remove(char *unused);
#endif #endif
......
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __TT_MMU_H
#define __TT_MMU_H
struct mmu_context_tt {
};
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __MODE_TT_H__
#define __MODE_TT_H__
#include "sysdep/ptrace.h"
extern int tracing_pid;
extern int tracer(int (*init_proc)(void *), void *sp);
extern void user_time_init_tt(void);
extern int copy_sc_from_user_tt(void *to_ptr, void *from_ptr, void *data);
extern int copy_sc_to_user_tt(void *to_ptr, void *from_ptr, void *data);
extern void sig_handler_common_tt(int sig, struct sigcontext *sc);
extern void syscall_handler_tt(int sig, struct uml_pt_regs *regs);
extern void reboot_tt(void);
extern void halt_tt(void);
extern int is_tracer_winch(int pid, int fd, void *data);
extern void kill_off_processes_tt(void);
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __TT_MODE_KERN_H__
#define __TT_MODE_KERN_H__
#include "linux/sched.h"
#include "asm/page.h"
#include "asm/ptrace.h"
#include "asm/uaccess.h"
extern void *switch_to_tt(void *prev, void *next);
extern void flush_thread_tt(void);
extern void start_thread_tt(struct pt_regs *regs, unsigned long eip,
unsigned long esp);
extern int copy_thread_tt(int nr, unsigned long clone_flags, unsigned long sp,
unsigned long stack_top, struct task_struct *p,
struct pt_regs *regs);
extern void release_thread_tt(struct task_struct *task);
extern void exit_thread_tt(void);
extern void initial_thread_cb_tt(void (*proc)(void *), void *arg);
extern void init_idle_tt(void);
extern void flush_tlb_kernel_vm_tt(void);
extern void __flush_tlb_one_tt(unsigned long addr);
extern void flush_tlb_range_tt(struct vm_area_struct *vma,
unsigned long start, unsigned long end);
extern void flush_tlb_mm_tt(struct mm_struct *mm);
extern void force_flush_all_tt(void);
extern long execute_syscall_tt(void *r);
extern void before_mem_tt(unsigned long brk_start);
extern unsigned long set_task_sizes_tt(int arg, unsigned long *host_size_out,
unsigned long *task_size_out);
extern int start_uml_tt(void);
extern struct page *arch_validate_tt(struct page *page, int mask, int order);
extern int external_pid_tt(struct task_struct *task);
extern int thread_pid_tt(struct task_struct *task);
#define kmem_end_tt (host_task_size - ABOVE_KMEM)
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __PTRACE_TT_H
#define __PTRACE_TT_H
#include "uml-config.h"
#ifdef CONFIG_MODE_TT
#include "sysdep/sc.h"
#endif
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __TT_H__
#define __TT_H__
#include "sysdep/ptrace.h"
extern int gdb_pid;
extern int debug;
extern int debug_stop;
extern int debug_trace;
extern int honeypot;
extern int fork_tramp(void *sig_stack);
extern int do_proc_op(void *t, int proc_id);
extern int tracer(int (*init_proc)(void *), void *sp);
extern void attach_process(int pid);
extern void tracer_panic(char *format, ...);
extern void set_init_pid(int pid);
extern int set_user_mode(void *task);
extern void set_tracing(void *t, int tracing);
extern int is_tracing(void *task);
extern int singlestepping_tt(void *t);
extern void clear_singlestep(void *t);
extern void syscall_handler(int sig, struct uml_pt_regs *regs);
extern void exit_kernel(int pid, void *task);
extern int do_syscall(void *task, int pid);
extern int is_valid_pid(int pid);
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __TT_UACCESS_H
#define __TT_UACCESS_H
#include "linux/string.h"
#include "linux/sched.h"
#include "asm/processor.h"
#include "asm/errno.h"
#include "asm/current.h"
#include "asm/a.out.h"
#define ABOVE_KMEM (16 * 1024 * 1024)
extern unsigned long end_vm;
extern unsigned long uml_physmem;
#define under_task_size(addr, size) \
(((unsigned long) (addr) < TASK_SIZE) && \
(((unsigned long) (addr) + (size)) < TASK_SIZE))
#define is_stack(addr, size) \
(((unsigned long) (addr) < STACK_TOP) && \
((unsigned long) (addr) >= STACK_TOP - ABOVE_KMEM) && \
(((unsigned long) (addr) + (size)) <= STACK_TOP))
#define access_ok_tt(type, addr, size) \
((type == VERIFY_READ) || (segment_eq(get_fs(), KERNEL_DS)) || \
(((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) && \
(under_task_size(addr, size) || is_stack(addr, size))))
static inline int verify_area_tt(int type, const void * addr,
unsigned long size)
{
return(access_ok_tt(type, addr, size) ? 0 : -EFAULT);
}
extern unsigned long get_fault_addr(void);
extern int __do_copy_from_user(void *to, const void *from, int n,
void **fault_addr, void **fault_catcher);
static inline int copy_from_user_tt(void *to, const void *from, int n)
{
return(access_ok_tt(VERIFY_READ, from, n) ?
__do_copy_from_user(to, from, n,
&current->thread.fault_addr,
&current->thread.fault_catcher) : n);
}
extern int __do_copy_to_user(void *to, const void *from, int n,
void **fault_addr, void **fault_catcher);
static inline int copy_to_user_tt(void *to, const void *from, int n)
{
return(access_ok_tt(VERIFY_WRITE, to, n) ?
__do_copy_to_user(to, from, n,
&current->thread.fault_addr,
&current->thread.fault_catcher) : n);
}
extern int __do_strncpy_from_user(char *dst, const char *src, size_t n,
void **fault_addr, void **fault_catcher);
static inline int strncpy_from_user_tt(char *dst, const char *src, int count)
{
int n;
if(!access_ok_tt(VERIFY_READ, src, 1)) return(-EFAULT);
n = __do_strncpy_from_user(dst, src, count,
&current->thread.fault_addr,
&current->thread.fault_catcher);
if(n < 0) return(-EFAULT);
return(n);
}
extern int __do_clear_user(void *mem, size_t len, void **fault_addr,
void **fault_catcher);
static inline int __clear_user_tt(void *mem, int len)
{
return(__do_clear_user(mem, len,
&current->thread.fault_addr,
&current->thread.fault_catcher));
}
static inline int clear_user_tt(void *mem, int len)
{
return(access_ok_tt(VERIFY_WRITE, mem, len) ?
__do_clear_user(mem, len,
&current->thread.fault_addr,
&current->thread.fault_catcher) : len);
}
extern int __do_strnlen_user(const char *str, unsigned long n,
void **fault_addr, void **fault_catcher);
static inline int strnlen_user_tt(const void *str, int len)
{
return(__do_strnlen_user(str, len,
&current->thread.fault_addr,
&current->thread.fault_catcher));
}
#endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/module.h"
#include "asm/uaccess.h"
#include "mode.h"
EXPORT_SYMBOL(__do_copy_from_user);
EXPORT_SYMBOL(__do_copy_to_user);
EXPORT_SYMBOL(__do_strncpy_from_user);
EXPORT_SYMBOL(__do_strnlen_user);
EXPORT_SYMBOL(__do_clear_user);
EXPORT_SYMBOL(tracing_pid);
EXPORT_SYMBOL(honeypot);
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/stddef.h"
#include "linux/config.h"
#include "linux/mm.h"
#include "asm/uaccess.h"
#include "mem_user.h"
#include "kern_util.h"
#include "user_util.h"
#include "kern.h"
#include "tt.h"
void before_mem_tt(unsigned long brk_start)
{
if(!jail || debug)
remap_data(UML_ROUND_DOWN(&_stext), UML_ROUND_UP(&_etext), 1);
remap_data(UML_ROUND_DOWN(&_sdata), UML_ROUND_UP(&_edata), 1);
remap_data(UML_ROUND_DOWN(&__bss_start), UML_ROUND_UP(brk_start), 1);
}
#ifdef CONFIG_HOST_2G_2G
#define TOP 0x80000000
#else
#define TOP 0xc0000000
#endif
#define SIZE ((CONFIG_NEST_LEVEL + CONFIG_KERNEL_HALF_GIGS) * 0x20000000)
#define START (TOP - SIZE)
unsigned long set_task_sizes_tt(int arg, unsigned long *host_size_out,
unsigned long *task_size_out)
{
/* Round up to the nearest 4M */
*host_size_out = ROUND_4M((unsigned long) &arg);
*task_size_out = START;
return(START);
}
struct page *arch_validate_tt(struct page *page, int mask, int order)
{
unsigned long addr, zero = 0;
int i;
again:
if(page == NULL) return(page);
if(PageHighMem(page)) return(page);
addr = (unsigned long) page_address(page);
for(i = 0; i < (1 << order); i++){
current->thread.fault_addr = (void *) addr;
if(__do_copy_to_user((void *) addr, &zero,
sizeof(zero),
&current->thread.fault_addr,
&current->thread.fault_catcher)){
if(!(mask & __GFP_WAIT)) return(NULL);
else break;
}
addr += PAGE_SIZE;
}
if(i == (1 << order)) return(page);
page = alloc_pages(mask, order);
goto again;
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/sched.h"
#include "linux/signal.h"
#include "linux/kernel.h"
#include "asm/system.h"
#include "asm/pgalloc.h"
#include "asm/ptrace.h"
#include "asm/tlbflush.h"
#include "irq_user.h"
#include "signal_user.h"
#include "kern_util.h"
#include "user_util.h"
#include "os.h"
#include "kern.h"
#include "sigcontext.h"
#include "time_user.h"
#include "mem_user.h"
#include "tlb.h"
#include "mode.h"
#include "init.h"
#include "tt.h"
void *switch_to_tt(void *prev, void *next, void *last)
{
struct task_struct *from, *to;
unsigned long flags;
int err, vtalrm, alrm, prof, cpu;
char c;
/* jailing and SMP are incompatible, so this doesn't need to be
* made per-cpu
*/
static int reading;
from = prev;
to = next;
to->thread.prev_sched = from;
cpu = from->thread_info->cpu;
if(cpu == 0)
forward_interrupts(to->thread.mode.tt.extern_pid);
#ifdef CONFIG_SMP
forward_ipi(cpu_data[cpu].ipi_pipe[0], to->thread.mode.tt.extern_pid);
#endif
local_irq_save(flags);
vtalrm = change_sig(SIGVTALRM, 0);
alrm = change_sig(SIGALRM, 0);
prof = change_sig(SIGPROF, 0);
forward_pending_sigio(to->thread.mode.tt.extern_pid);
c = 0;
set_current(to);
reading = 0;
err = os_write_file(to->thread.mode.tt.switch_pipe[1], &c, sizeof(c));
if(err != sizeof(c))
panic("write of switch_pipe failed, errno = %d", -err);
reading = 1;
if((from->state == TASK_ZOMBIE) || (from->state == TASK_DEAD))
os_kill_process(os_getpid(), 0);
err = os_read_file(from->thread.mode.tt.switch_pipe[0], &c, sizeof(c));
if(err != sizeof(c))
panic("read of switch_pipe failed, errno = %d", -err);
/* This works around a nasty race with 'jail'. If we are switching
* between two threads of a threaded app and the incoming process
* runs before the outgoing process reaches the read, and it makes
* it all the way out to userspace, then it will have write-protected
* the outgoing process stack. Then, when the outgoing process
* returns from the write, it will segfault because it can no longer
* write its own stack. So, in order to avoid that, the incoming
* thread sits in a loop yielding until 'reading' is set. This
* isn't entirely safe, since there may be a reschedule from a timer
* happening between setting 'reading' and sleeping in read. But,
* it should get a whole quantum in which to reach the read and sleep,
* which should be enough.
*/
if(jail){
while(!reading) sched_yield();
}
change_sig(SIGVTALRM, vtalrm);
change_sig(SIGALRM, alrm);
change_sig(SIGPROF, prof);
arch_switch();
flush_tlb_all();
local_irq_restore(flags);
return(current->thread.prev_sched);
}
void release_thread_tt(struct task_struct *task)
{
os_kill_process(task->thread.mode.tt.extern_pid, 0);
}
void exit_thread_tt(void)
{
close(current->thread.mode.tt.switch_pipe[0]);
close(current->thread.mode.tt.switch_pipe[1]);
}
extern void schedule_tail(struct task_struct *prev);
static void new_thread_handler(int sig)
{
int (*fn)(void *);
void *arg;
fn = current->thread.request.u.thread.proc;
arg = current->thread.request.u.thread.arg;
current->thread.regs.regs.mode.tt = (void *) (&sig + 1);
suspend_new_thread(current->thread.mode.tt.switch_pipe[0]);
block_signals();
init_new_thread_signals(1);
#ifdef CONFIG_SMP
schedule_tail(NULL);
#endif
enable_timer();
free_page(current->thread.temp_stack);
set_cmdline("(kernel thread)");
force_flush_all();
current->thread.prev_sched = NULL;
change_sig(SIGUSR1, 1);
change_sig(SIGVTALRM, 1);
change_sig(SIGPROF, 1);
unblock_signals();
if(!run_kernel_thread(fn, arg, &current->thread.exec_buf))
do_exit(0);
}
static int new_thread_proc(void *stack)
{
init_new_thread_stack(stack, new_thread_handler);
os_usr1_process(os_getpid());
return(0);
}
/* Signal masking - signals are blocked at the start of fork_tramp. They
* are re-enabled when finish_fork_handler is entered by fork_tramp hitting
* itself with a SIGUSR1. set_user_mode has to be run with SIGUSR1 off,
* so it is blocked before it's called. They are re-enabled on sigreturn
* despite the fact that they were blocked when the SIGUSR1 was issued because
* copy_thread copies the parent's signcontext, including the signal mask
* onto the signal frame.
*/
void finish_fork_handler(int sig)
{
current->thread.regs.regs.mode.tt = (void *) (&sig + 1);
suspend_new_thread(current->thread.mode.tt.switch_pipe[0]);
#ifdef CONFIG_SMP
schedule_tail(NULL);
#endif
enable_timer();
change_sig(SIGVTALRM, 1);
force_flush_all();
if(current->mm != current->parent->mm)
protect_memory(uml_reserved, high_physmem - uml_reserved, 1,
1, 0, 1);
task_protections((unsigned long) current->thread_info);
current->thread.prev_sched = NULL;
free_page(current->thread.temp_stack);
change_sig(SIGUSR1, 0);
set_user_mode(current);
}
static int sigusr1 = SIGUSR1;
int fork_tramp(void *stack)
{
int sig = sigusr1;
init_new_thread_stack(stack, finish_fork_handler);
kill(os_getpid(), sig);
return(0);
}
int copy_thread_tt(int nr, unsigned long clone_flags, unsigned long sp,
unsigned long stack_top, struct task_struct * p,
struct pt_regs *regs)
{
int (*tramp)(void *);
int new_pid, err;
unsigned long stack;
if(current->thread.forking)
tramp = fork_tramp;
else {
tramp = new_thread_proc;
p->thread.request.u.thread = current->thread.request.u.thread;
}
err = os_pipe(p->thread.mode.tt.switch_pipe, 1, 1);
if(err){
printk("copy_thread : pipe failed, errno = %d\n", -err);
return(err);
}
stack = alloc_stack(0, 0);
if(stack == 0){
printk(KERN_ERR "copy_thread : failed to allocate "
"temporary stack\n");
return(-ENOMEM);
}
clone_flags &= CLONE_VM;
p->thread.temp_stack = stack;
new_pid = start_fork_tramp((void *) p->thread.kernel_stack, stack,
clone_flags, tramp);
if(new_pid < 0){
printk(KERN_ERR "copy_thread : clone failed - errno = %d\n",
-new_pid);
return(new_pid);
}
if(current->thread.forking){
sc_to_sc(p->thread.regs.regs.mode.tt,
current->thread.regs.regs.mode.tt);
SC_SET_SYSCALL_RETURN(p->thread.regs.regs.mode.tt, 0);
if(sp != 0) SC_SP(p->thread.regs.regs.mode.tt) = sp;
}
p->thread.mode.tt.extern_pid = new_pid;
current->thread.request.op = OP_FORK;
current->thread.request.u.fork.pid = new_pid;
os_usr1_process(os_getpid());
return(0);
}
void reboot_tt(void)
{
current->thread.request.op = OP_REBOOT;
os_usr1_process(os_getpid());
}
void halt_tt(void)
{
current->thread.request.op = OP_HALT;
os_usr1_process(os_getpid());
}
void kill_off_processes_tt(void)
{
struct task_struct *p;
int me;
me = os_getpid();
for_each_process(p){
if(p->thread.mode.tt.extern_pid != me)
os_kill_process(p->thread.mode.tt.extern_pid, 0);
}
if(init_task.thread.mode.tt.extern_pid != me)
os_kill_process(init_task.thread.mode.tt.extern_pid, 0);
}
void initial_thread_cb_tt(void (*proc)(void *), void *arg)
{
if(os_getpid() == tracing_pid){
(*proc)(arg);
}
else {
current->thread.request.op = OP_CB;
current->thread.request.u.cb.proc = proc;
current->thread.request.u.cb.arg = arg;
os_usr1_process(os_getpid());
}
}
int do_proc_op(void *t, int proc_id)
{
struct task_struct *task;
struct thread_struct *thread;
int op, pid;
task = t;
thread = &task->thread;
op = thread->request.op;
switch(op){
case OP_NONE:
case OP_TRACE_ON:
break;
case OP_EXEC:
pid = thread->request.u.exec.pid;
do_exec(thread->mode.tt.extern_pid, pid);
thread->mode.tt.extern_pid = pid;
cpu_tasks[task->thread_info->cpu].pid = pid;
break;
case OP_FORK:
attach_process(thread->request.u.fork.pid);
break;
case OP_CB:
(*thread->request.u.cb.proc)(thread->request.u.cb.arg);
break;
case OP_REBOOT:
case OP_HALT:
break;
default:
tracer_panic("Bad op in do_proc_op");
break;
}
thread->request.op = OP_NONE;
return(op);
}
void init_idle_tt(void)
{
default_idle();
}
/* Changed by jail_setup, which is a setup */
int jail = 0;
int __init jail_setup(char *line, int *add)
{
int ok = 1;
if(jail) return(0);
#ifdef CONFIG_SMP
printf("'jail' may not used used in a kernel with CONFIG_SMP "
"enabled\n");
ok = 0;
#endif
#ifdef CONFIG_HOSTFS
printf("'jail' may not used used in a kernel with CONFIG_HOSTFS "
"enabled\n");
ok = 0;
#endif
#ifdef CONFIG_MODULES
printf("'jail' may not used used in a kernel with CONFIG_MODULES "
"enabled\n");
ok = 0;
#endif
if(!ok) exit(1);
/* CAP_SYS_RAWIO controls the ability to open /dev/mem and /dev/kmem.
* Removing it from the bounding set eliminates the ability of anything
* to acquire it, and thus read or write kernel memory.
*/
cap_lower(cap_bset, CAP_SYS_RAWIO);
jail = 1;
return(0);
}
__uml_setup("jail", jail_setup,
"jail\n"
" Enables the protection of kernel memory from processes.\n\n"
);
static void mprotect_kernel_mem(int w)
{
unsigned long start, end;
if(!jail || (current == &init_task)) return;
start = (unsigned long) current->thread_info + PAGE_SIZE;
end = (unsigned long) current->thread_info + PAGE_SIZE * 4;
protect_memory(uml_reserved, start - uml_reserved, 1, w, 1, 1);
protect_memory(end, high_physmem - end, 1, w, 1, 1);
start = (unsigned long) UML_ROUND_DOWN(&_stext);
end = (unsigned long) UML_ROUND_UP(&_etext);
protect_memory(start, end - start, 1, w, 1, 1);
start = (unsigned long) UML_ROUND_DOWN(&_unprotected_end);
end = (unsigned long) UML_ROUND_UP(&_edata);
protect_memory(start, end - start, 1, w, 1, 1);
start = (unsigned long) UML_ROUND_DOWN(&__bss_start);
end = (unsigned long) UML_ROUND_UP(brk_start);
protect_memory(start, end - start, 1, w, 1, 1);
mprotect_kernel_vm(w);
}
void unprotect_kernel_mem(void)
{
mprotect_kernel_mem(1);
}
void protect_kernel_mem(void)
{
mprotect_kernel_mem(0);
}
extern void start_kernel(void);
static int start_kernel_proc(void *unused)
{
int pid;
block_signals();
pid = os_getpid();
cpu_tasks[0].pid = pid;
cpu_tasks[0].task = current;
#ifdef CONFIG_SMP
cpu_online_map = 1;
#endif
if(debug) os_stop_process(pid);
start_kernel();
return(0);
}
void set_tracing(void *task, int tracing)
{
((struct task_struct *) task)->thread.mode.tt.tracing = tracing;
}
int is_tracing(void *t)
{
return (((struct task_struct *) t)->thread.mode.tt.tracing);
}
int set_user_mode(void *t)
{
struct task_struct *task;
task = t ? t : current;
if(task->thread.mode.tt.tracing)
return(1);
task->thread.request.op = OP_TRACE_ON;
os_usr1_process(os_getpid());
return(0);
}
void set_init_pid(int pid)
{
int err;
init_task.thread.mode.tt.extern_pid = pid;
err = os_pipe(init_task.thread.mode.tt.switch_pipe, 1, 1);
if(err) panic("Can't create switch pipe for init_task, errno = %d",
err);
}
int singlestepping_tt(void *t)
{
struct task_struct *task = t;
if(task->thread.mode.tt.singlestep_syscall)
return(0);
return(task->ptrace & PT_DTRACE);
}
void clear_singlestep(void *t)
{
struct task_struct *task = t;
task->ptrace &= ~PT_DTRACE;
}
int start_uml_tt(void)
{
void *sp;
sp = (void *) init_task.thread.kernel_stack + 2 * PAGE_SIZE -
sizeof(unsigned long);
return(tracer(start_kernel_proc, sp));
}
int external_pid_tt(struct task_struct *task)
{
return(task->thread.mode.tt.extern_pid);
}
int thread_pid_tt(struct task_struct *task)
{
return(task->thread.mode.tt.extern_pid);
}
int is_valid_pid(int pid)
{
struct task_struct *task;
read_lock(&tasklist_lock);
for_each_process(task){
if(task->thread.mode.tt.extern_pid == pid){
read_unlock(&tasklist_lock);
return(1);
}
}
read_unlock(&tasklist_lock);
return(0);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
obj-y = proxy.o ptrace.o sysdep.o wait.o obj-y = proxy.o ptrace.o sysdep.o wait.o
USER_OBJS := $(foreach file,$(obj-y),arch/um/ptproxy/$(file)) USER_OBJS := $(foreach file,$(obj-y),$(src)/$(file))
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c $(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $< $(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
clean: clean:
rm -f *.o core child ptproxy
...@@ -21,6 +21,7 @@ Jeff Dike (jdike@karaya.com) : Modified for integration into uml ...@@ -21,6 +21,7 @@ Jeff Dike (jdike@karaya.com) : Modified for integration into uml
#include "user_util.h" #include "user_util.h"
#include "kern_util.h" #include "kern_util.h"
#include "ptrace_user.h" #include "ptrace_user.h"
#include "tt.h"
long proxy_ptrace(struct debugger *debugger, int arg1, pid_t arg2, long proxy_ptrace(struct debugger *debugger, int arg1, pid_t arg2,
long arg3, long arg4, pid_t child, int *ret) long arg3, long arg4, pid_t child, int *ret)
......
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
obj-y = sigcontext.o
USER_OBJS = sigcontext.o
USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
clean :
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdlib.h>
#include <asm/sigcontext.h>
#include "kern_util.h"
#include "sysdep/frame.h"
int copy_sc_from_user_tt(void *to_ptr, void *from_ptr, void *data)
{
struct arch_frame_data *arch = data;
struct sigcontext *to = to_ptr, *from = from_ptr;
struct _fpstate *to_fp, *from_fp;
unsigned long sigs;
int err;
to_fp = to->fpstate;
from_fp = from->fpstate;
sigs = to->oldmask;
err = copy_from_user_proc(to, from, sizeof(*to));
to->oldmask = sigs;
if(to_fp != NULL){
err |= copy_from_user_proc(&to->fpstate, &to_fp,
sizeof(to->fpstate));
err |= copy_from_user_proc(to_fp, from_fp, arch->fpstate_size);
}
return(err);
}
int copy_sc_to_user_tt(void *to_ptr, void *from_ptr, void *data)
{
struct arch_frame_data *arch = data;
struct sigcontext *to = to_ptr, *from = from_ptr;
struct _fpstate *to_fp, *from_fp;
int err;
to_fp = (struct _fpstate *)((unsigned long) to + sizeof(*to));
from_fp = from->fpstate;
err = copy_to_user_proc(to, from, sizeof(*to));
if(from_fp != NULL){
err |= copy_to_user_proc(&to->fpstate, &to_fp,
sizeof(to->fpstate));
err |= copy_to_user_proc(to_fp, from_fp, arch->fpstate_size);
}
return(err);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/types.h"
#include "linux/utime.h"
#include "linux/sys.h"
#include "asm/unistd.h"
#include "asm/ptrace.h"
#include "asm/uaccess.h"
#include "asm/stat.h"
#include "sysdep/syscalls.h"
#include "kern_util.h"
static inline int check_area(void *ptr, int size)
{
return(verify_area(VERIFY_WRITE, ptr, size));
}
static int check_readlink(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1], regs->regs.args[2]));
}
static int check_utime(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1],
sizeof(struct utimbuf)));
}
static int check_oldstat(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1],
sizeof(struct __old_kernel_stat)));
}
static int check_stat(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1], sizeof(struct stat)));
}
static int check_stat64(struct pt_regs *regs)
{
return(check_area((void *) regs->regs.args[1], sizeof(struct stat64)));
}
struct bogus {
int kernel_ds;
int (*check_params)(struct pt_regs *);
};
struct bogus this_is_bogus[256] = {
[ __NR_mknod ] = { 1, NULL },
[ __NR_mkdir ] = { 1, NULL },
[ __NR_rmdir ] = { 1, NULL },
[ __NR_unlink ] = { 1, NULL },
[ __NR_symlink ] = { 1, NULL },
[ __NR_link ] = { 1, NULL },
[ __NR_rename ] = { 1, NULL },
[ __NR_umount ] = { 1, NULL },
[ __NR_mount ] = { 1, NULL },
[ __NR_pivot_root ] = { 1, NULL },
[ __NR_chdir ] = { 1, NULL },
[ __NR_chroot ] = { 1, NULL },
[ __NR_open ] = { 1, NULL },
[ __NR_quotactl ] = { 1, NULL },
[ __NR_sysfs ] = { 1, NULL },
[ __NR_readlink ] = { 1, check_readlink },
[ __NR_acct ] = { 1, NULL },
[ __NR_execve ] = { 1, NULL },
[ __NR_uselib ] = { 1, NULL },
[ __NR_statfs ] = { 1, NULL },
[ __NR_truncate ] = { 1, NULL },
[ __NR_access ] = { 1, NULL },
[ __NR_chmod ] = { 1, NULL },
[ __NR_chown ] = { 1, NULL },
[ __NR_lchown ] = { 1, NULL },
[ __NR_utime ] = { 1, check_utime },
[ __NR_oldlstat ] = { 1, check_oldstat },
[ __NR_oldstat ] = { 1, check_oldstat },
[ __NR_stat ] = { 1, check_stat },
[ __NR_lstat ] = { 1, check_stat },
[ __NR_stat64 ] = { 1, check_stat64 },
[ __NR_lstat64 ] = { 1, check_stat64 },
[ __NR_chown32 ] = { 1, NULL },
};
/* sys_utimes */
static int check_bogosity(struct pt_regs *regs)
{
struct bogus *bogon = &this_is_bogus[regs->regs.syscall];
if(!bogon->kernel_ds) return(0);
if(bogon->check_params && (*bogon->check_params)(regs))
return(-EFAULT);
set_fs(KERNEL_DS);
return(0);
}
extern syscall_handler_t *sys_call_table[];
long execute_syscall_tt(void *r)
{
struct pt_regs *regs = r;
long res;
int syscall;
current->thread.nsyscalls++;
nsyscalls++;
syscall = regs->regs.syscall;
if((syscall >= NR_syscalls) || (syscall < 0))
res = -ENOSYS;
else if(honeypot && check_bogosity(regs))
res = -EFAULT;
else res = EXECUTE_SYSCALL(syscall, regs);
set_fs(USER_DS);
if(current->thread.mode.tt.singlestep_syscall){
current->thread.mode.tt.singlestep_syscall = 0;
current->ptrace &= ~PT_DTRACE;
force_sig(SIGTRAP, current);
}
return(res);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <sys/ptrace.h>
#include <asm/unistd.h>
#include "sysdep/ptrace.h"
#include "sigcontext.h"
#include "ptrace_user.h"
#include "task.h"
#include "user_util.h"
#include "kern_util.h"
#include "syscall_user.h"
#include "tt.h"
/* XXX Bogus */
#define ERESTARTSYS 512
#define ERESTARTNOINTR 513
#define ERESTARTNOHAND 514
void syscall_handler_tt(int sig, struct uml_pt_regs *regs)
{
void *sc;
long result;
int index, syscall;
syscall = regs->syscall;
sc = regs->mode.tt;
sc_to_regs(regs, sc, syscall);
SC_START_SYSCALL(sc);
index = record_syscall_start(syscall);
syscall_trace();
result = execute_syscall(regs);
/* regs->sc may have changed while the system call ran (there may
* have been an interrupt or segfault), so it needs to be refreshed.
*/
regs->mode.tt = sc;
SC_SET_SYSCALL_RETURN(sc, result);
if((result == -ERESTARTNOHAND) || (result == -ERESTARTSYS) ||
(result == -ERESTARTNOINTR))
do_signal(result);
syscall_trace();
record_syscall_end(index, result);
}
int do_syscall(void *task, int pid)
{
unsigned long proc_regs[FRAME_SIZE];
struct uml_pt_regs *regs;
int syscall;
if(ptrace_getregs(pid, proc_regs) < 0)
tracer_panic("Couldn't read registers");
syscall = PT_SYSCALL_NR(proc_regs);
regs = TASK_REGS(task);
UPT_SYSCALL_NR(regs) = syscall;
if(syscall < 1) return(0);
if((syscall != __NR_sigreturn) &&
((unsigned long *) PT_IP(proc_regs) >= &_stext) &&
((unsigned long *) PT_IP(proc_regs) <= &_etext))
tracer_panic("I'm tracing myself and I can't get out");
if(ptrace(PTRACE_POKEUSER, pid, PT_SYSCALL_NR_OFFSET,
__NR_getpid) < 0)
tracer_panic("do_syscall : Nullifying syscall failed, "
"errno = %d", errno);
return(1);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <signal.h>
#include <sys/time.h>
#include <time_user.h>
#include "process.h"
#include "user.h"
void user_time_init_tt(void)
{
if(signal(SIGVTALRM, (__sighandler_t) alarm_handler) == SIG_ERR)
panic("Couldn't set SIGVTALRM handler");
set_interval(ITIMER_VIRTUAL);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/stddef.h"
#include "linux/kernel.h"
#include "linux/sched.h"
#include "linux/mm.h"
#include "asm/page.h"
#include "asm/pgtable.h"
#include "asm/uaccess.h"
#include "user_util.h"
#include "mem_user.h"
#include "os.h"
static void fix_range(struct mm_struct *mm, unsigned long start_addr,
unsigned long end_addr, int force)
{
pgd_t *npgd;
pmd_t *npmd;
pte_t *npte;
unsigned long addr;
int r, w, x, err;
if((current->thread.mode.tt.extern_pid != -1) &&
(current->thread.mode.tt.extern_pid != os_getpid()))
panic("fix_range fixing wrong address space, current = 0x%p",
current);
if(mm == NULL) return;
for(addr=start_addr;addr<end_addr;){
if(addr == TASK_SIZE){
/* Skip over kernel text, kernel data, and physical
* memory, which don't have ptes, plus kernel virtual
* memory, which is flushed separately, and remap
* the process stack. The only way to get here is
* if (end_addr == STACK_TOP) > TASK_SIZE, which is
* only true in the honeypot case.
*/
addr = STACK_TOP - ABOVE_KMEM;
continue;
}
npgd = pgd_offset(mm, addr);
npmd = pmd_offset(npgd, addr);
if(pmd_present(*npmd)){
npte = pte_offset_kernel(npmd, addr);
r = pte_read(*npte);
w = pte_write(*npte);
x = pte_exec(*npte);
if(!pte_dirty(*npte)) w = 0;
if(!pte_young(*npte)){
r = 0;
w = 0;
}
if(force || pte_newpage(*npte)){
err = os_unmap_memory((void *) addr,
PAGE_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
if(pte_present(*npte))
map_memory(addr,
pte_val(*npte) & PAGE_MASK,
PAGE_SIZE, r, w, x);
}
else if(pte_newprot(*npte)){
protect_memory(addr, PAGE_SIZE, r, w, x, 1);
}
*npte = pte_mkuptodate(*npte);
addr += PAGE_SIZE;
}
else {
if(force || pmd_newpage(*npmd)){
err = os_unmap_memory((void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
pmd_mkuptodate(*npmd);
}
addr += PMD_SIZE;
}
}
}
atomic_t vmchange_seq = ATOMIC_INIT(1);
static void flush_kernel_vm_range(unsigned long start, unsigned long end,
int update_seq)
{
struct mm_struct *mm;
pgd_t *pgd;
pmd_t *pmd;
pte_t *pte;
unsigned long addr;
int updated = 0, err;
mm = &init_mm;
for(addr = start; addr < end;){
pgd = pgd_offset(mm, addr);
pmd = pmd_offset(pgd, addr);
if(pmd_present(*pmd)){
pte = pte_offset_kernel(pmd, addr);
if(!pte_present(*pte) || pte_newpage(*pte)){
updated = 1;
err = os_unmap_memory((void *) addr,
PAGE_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
if(pte_present(*pte))
map_memory(addr,
pte_val(*pte) & PAGE_MASK,
PAGE_SIZE, 1, 1, 1);
}
else if(pte_newprot(*pte)){
updated = 1;
protect_memory(addr, PAGE_SIZE, 1, 1, 1, 1);
}
addr += PAGE_SIZE;
}
else {
if(pmd_newpage(*pmd)){
updated = 1;
err = os_unmap_memory((void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
}
addr += PMD_SIZE;
}
}
if(updated && update_seq) atomic_inc(&vmchange_seq);
}
void flush_tlb_kernel_range(unsigned long start, unsigned long end)
{
flush_kernel_vm_range(start, end, 1);
}
static void protect_vm_page(unsigned long addr, int w, int must_succeed)
{
int err;
err = protect_memory(addr, PAGE_SIZE, 1, w, 1, must_succeed);
if(err == 0) return;
else if((err == -EFAULT) || (err == -ENOMEM)){
flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
protect_vm_page(addr, w, 1);
}
else panic("protect_vm_page : protect failed, errno = %d\n", err);
}
void mprotect_kernel_vm(int w)
{
struct mm_struct *mm;
pgd_t *pgd;
pmd_t *pmd;
pte_t *pte;
unsigned long addr;
mm = &init_mm;
for(addr = start_vm; addr < end_vm;){
pgd = pgd_offset(mm, addr);
pmd = pmd_offset(pgd, addr);
if(pmd_present(*pmd)){
pte = pte_offset_kernel(pmd, addr);
if(pte_present(*pte)) protect_vm_page(addr, w, 0);
addr += PAGE_SIZE;
}
else addr += PMD_SIZE;
}
}
void flush_tlb_kernel_vm_tt(void)
{
flush_tlb_kernel_range(start_vm, end_vm);
}
void __flush_tlb_one_tt(unsigned long addr)
{
flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
}
void flush_tlb_range_tt(struct vm_area_struct *vma, unsigned long start,
unsigned long end)
{
if(vma->vm_mm != current->mm) return;
/* Assumes that the range start ... end is entirely within
* either process memory or kernel vm
*/
if((start >= start_vm) && (start < end_vm))
flush_kernel_vm_range(start, end, 1);
else fix_range(vma->vm_mm, start, end, 0);
}
void flush_tlb_mm_tt(struct mm_struct *mm)
{
unsigned long seq;
if(mm != current->mm) return;
fix_range(mm, 0, STACK_TOP, 0);
seq = atomic_read(&vmchange_seq);
if(current->thread.mode.tt.vm_seq == seq) return;
current->thread.mode.tt.vm_seq = seq;
flush_kernel_vm_range(start_vm, end_vm, 0);
}
void force_flush_all_tt(void)
{
fix_range(current->mm, 0, STACK_TOP, 1);
flush_kernel_vm_range(start_vm, end_vm, 0);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <sched.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ptrace.h>
#include <sys/time.h>
#include <sys/wait.h>
#include "user.h"
#include "sysdep/ptrace.h"
#include "sigcontext.h"
#include "sysdep/sigcontext.h"
#include "os.h"
#include "signal_user.h"
#include "user_util.h"
#include "mem_user.h"
#include "process.h"
#include "kern_util.h"
#include "frame.h"
#include "chan_user.h"
#include "ptrace_user.h"
#include "mode.h"
#include "tt.h"
static int tracer_winch[2];
int is_tracer_winch(int pid, int fd, void *data)
{
if(pid != tracing_pid)
return(0);
register_winch_irq(tracer_winch[0], fd, -1, data);
return(0);
}
static void tracer_winch_handler(int sig)
{
char c = 1;
if(write(tracer_winch[1], &c, sizeof(c)) != sizeof(c))
printk("tracer_winch_handler - write failed, errno = %d\n",
errno);
}
/* Called only by the tracing thread during initialization */
static void setup_tracer_winch(void)
{
int err;
err = os_pipe(tracer_winch, 1, 1);
if(err){
printk("setup_tracer_winch : os_pipe failed, errno = %d\n",
-err);
return;
}
signal(SIGWINCH, tracer_winch_handler);
}
void attach_process(int pid)
{
if((ptrace(PTRACE_ATTACH, pid, 0, 0) < 0) ||
(ptrace(PTRACE_CONT, pid, 0, 0) < 0))
tracer_panic("OP_FORK failed to attach pid");
wait_for_stop(pid, SIGSTOP, PTRACE_CONT, NULL);
if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
tracer_panic("OP_FORK failed to continue process");
}
void tracer_panic(char *format, ...)
{
va_list ap;
va_start(ap, format);
vprintf(format, ap);
printf("\n");
while(1) pause();
}
static void tracer_segv(int sig, struct sigcontext sc)
{
printf("Tracing thread segfault at address 0x%lx, ip 0x%lx\n",
SC_FAULT_ADDR(&sc), SC_IP(&sc));
while(1)
pause();
}
/* Changed early in boot, and then only read */
int debug = 0;
int debug_stop = 1;
int debug_parent = 0;
int honeypot = 0;
static int signal_tramp(void *arg)
{
int (*proc)(void *);
if(honeypot && munmap((void *) (host_task_size - 0x10000000),
0x10000000))
panic("Unmapping stack failed");
if(ptrace(PTRACE_TRACEME, 0, 0, 0) < 0)
panic("ptrace PTRACE_TRACEME failed");
os_stop_process(os_getpid());
change_sig(SIGWINCH, 0);
signal(SIGUSR1, SIG_IGN);
change_sig(SIGCHLD, 0);
signal(SIGSEGV, (__sighandler_t) sig_handler);
set_cmdline("(idle thread)");
set_init_pid(os_getpid());
proc = arg;
return((*proc)(NULL));
}
static void last_ditch_exit(int sig)
{
kmalloc_ok = 0;
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
uml_cleanup();
exit(1);
}
static void sleeping_process_signal(int pid, int sig)
{
switch(sig){
/* These two result from UML being ^Z-ed and bg-ed. PTRACE_CONT is
* right because the process must be in the kernel already.
*/
case SIGCONT:
case SIGTSTP:
if(ptrace(PTRACE_CONT, pid, 0, sig) < 0)
tracer_panic("sleeping_process_signal : Failed to "
"continue pid %d, errno = %d\n", pid,
sig);
break;
/* This happens when the debugger (e.g. strace) is doing system call
* tracing on the kernel. During a context switch, the current task
* will be set to the incoming process and the outgoing process will
* hop into write and then read. Since it's not the current process
* any more, the trace of those will land here. So, we need to just
* PTRACE_SYSCALL it.
*/
case SIGTRAP:
if(ptrace(PTRACE_SYSCALL, pid, 0, 0) < 0)
tracer_panic("sleeping_process_signal : Failed to "
"PTRACE_SYSCALL pid %d, errno = %d\n",
pid, sig);
break;
case SIGSTOP:
break;
default:
tracer_panic("sleeping process %d got unexpected "
"signal : %d\n", pid, sig);
break;
}
}
/* Accessed only by the tracing thread */
int debugger_pid = -1;
int debugger_parent = -1;
int debugger_fd = -1;
int gdb_pid = -1;
struct {
int pid;
int signal;
unsigned long addr;
struct timeval time;
} signal_record[1024][32];
int signal_index[32];
int nsignals = 0;
int debug_trace = 0;
extern int io_nsignals, io_count, intr_count;
extern void signal_usr1(int sig);
int tracing_pid = -1;
int tracer(int (*init_proc)(void *), void *sp)
{
void *task = NULL;
unsigned long eip = 0;
int status, pid = 0, sig = 0, cont_type, tracing = 0, op = 0;
int last_index, proc_id = 0, n, err, old_tracing = 0, strace = 0;
capture_signal_stack();
signal(SIGPIPE, SIG_IGN);
setup_tracer_winch();
tracing_pid = os_getpid();
printf("tracing thread pid = %d\n", tracing_pid);
pid = clone(signal_tramp, sp, CLONE_FILES | SIGCHLD, init_proc);
n = waitpid(pid, &status, WUNTRACED);
if(n < 0){
printf("waitpid on idle thread failed, errno = %d\n", errno);
exit(1);
}
if((ptrace(PTRACE_CONT, pid, 0, 0) < 0)){
printf("Failed to continue idle thread, errno = %d\n", errno);
exit(1);
}
signal(SIGSEGV, (sighandler_t) tracer_segv);
signal(SIGUSR1, signal_usr1);
set_handler(SIGINT, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGTERM, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
set_handler(SIGHUP, last_ditch_exit, SA_ONESHOT | SA_NODEFER, -1);
if(debug_trace){
printf("Tracing thread pausing to be attached\n");
stop();
}
if(debug){
if(gdb_pid != -1)
debugger_pid = attach_debugger(pid, gdb_pid, 1);
else debugger_pid = init_ptrace_proxy(pid, 1, debug_stop);
if(debug_parent){
debugger_parent = os_process_parent(debugger_pid);
init_parent_proxy(debugger_parent);
err = attach(debugger_parent);
if(err){
printf("Failed to attach debugger parent %d, "
"errno = %d\n", debugger_parent, err);
debugger_parent = -1;
}
else {
if(ptrace(PTRACE_SYSCALL, debugger_parent,
0, 0) < 0){
printf("Failed to continue debugger "
"parent, errno = %d\n", errno);
debugger_parent = -1;
}
}
}
}
set_cmdline("(tracing thread)");
while(1){
if((pid = waitpid(-1, &status, WUNTRACED)) <= 0){
if(errno != ECHILD){
printf("wait failed - errno = %d\n", errno);
}
continue;
}
if(pid == debugger_pid){
int cont = 0;
if(WIFEXITED(status) || WIFSIGNALED(status))
debugger_pid = -1;
/* XXX Figure out how to deal with gdb and SMP */
else cont = debugger_signal(status, cpu_tasks[0].pid);
if(cont == PTRACE_SYSCALL) strace = 1;
continue;
}
else if(pid == debugger_parent){
debugger_parent_signal(status, pid);
continue;
}
nsignals++;
if(WIFEXITED(status)) ;
#ifdef notdef
{
printf("Child %d exited with status %d\n", pid,
WEXITSTATUS(status));
}
#endif
else if(WIFSIGNALED(status)){
sig = WTERMSIG(status);
if(sig != 9){
printf("Child %d exited with signal %d\n", pid,
sig);
}
}
else if(WIFSTOPPED(status)){
proc_id = pid_to_processor_id(pid);
sig = WSTOPSIG(status);
if(signal_index[proc_id] == 1024){
signal_index[proc_id] = 0;
last_index = 1023;
}
else last_index = signal_index[proc_id] - 1;
if(((sig == SIGPROF) || (sig == SIGVTALRM) ||
(sig == SIGALRM)) &&
(signal_record[proc_id][last_index].signal == sig)&&
(signal_record[proc_id][last_index].pid == pid))
signal_index[proc_id] = last_index;
signal_record[proc_id][signal_index[proc_id]].pid = pid;
gettimeofday(&signal_record[proc_id][signal_index[proc_id]].time, NULL);
eip = ptrace(PTRACE_PEEKUSER, pid, PT_IP_OFFSET, 0);
signal_record[proc_id][signal_index[proc_id]].addr = eip;
signal_record[proc_id][signal_index[proc_id]++].signal = sig;
if(proc_id == -1){
sleeping_process_signal(pid, sig);
continue;
}
task = cpu_tasks[proc_id].task;
tracing = is_tracing(task);
old_tracing = tracing;
switch(sig){
case SIGUSR1:
sig = 0;
op = do_proc_op(task, proc_id);
switch(op){
case OP_TRACE_ON:
arch_leave_kernel(task, pid);
tracing = 1;
break;
case OP_REBOOT:
case OP_HALT:
unmap_physmem();
kmalloc_ok = 0;
ptrace(PTRACE_KILL, pid, 0, 0);
return(op == OP_REBOOT);
case OP_NONE:
printf("Detaching pid %d\n", pid);
detach(pid, SIGSTOP);
continue;
default:
break;
}
/* OP_EXEC switches host processes on us,
* we want to continue the new one.
*/
pid = cpu_tasks[proc_id].pid;
break;
case SIGTRAP:
if(!tracing && (debugger_pid != -1)){
child_signal(pid, status);
continue;
}
tracing = 0;
if(do_syscall(task, pid)) sig = SIGUSR2;
else clear_singlestep(task);
break;
case SIGPROF:
if(tracing) sig = 0;
break;
case SIGCHLD:
case SIGHUP:
sig = 0;
break;
case SIGSEGV:
case SIGIO:
case SIGALRM:
case SIGVTALRM:
case SIGFPE:
case SIGBUS:
case SIGILL:
case SIGWINCH:
default:
tracing = 0;
break;
}
set_tracing(task, tracing);
if(!tracing && old_tracing)
arch_enter_kernel(task, pid);
if(!tracing && (debugger_pid != -1) && (sig != 0) &&
(sig != SIGALRM) && (sig != SIGVTALRM) &&
(sig != SIGSEGV) && (sig != SIGTRAP) &&
(sig != SIGUSR2) && (sig != SIGIO) &&
(sig != SIGFPE)){
child_signal(pid, status);
continue;
}
if(tracing){
if(singlestepping_tt(task))
cont_type = PTRACE_SINGLESTEP;
else cont_type = PTRACE_SYSCALL;
}
else cont_type = PTRACE_CONT;
if((cont_type == PTRACE_CONT) &&
(debugger_pid != -1) && strace)
cont_type = PTRACE_SYSCALL;
if(ptrace(cont_type, pid, 0, sig) != 0){
tracer_panic("ptrace failed to continue "
"process - errno = %d\n",
errno);
}
}
}
return(0);
}
static int __init uml_debug_setup(char *line, int *add)
{
char *next;
debug = 1;
*add = 0;
if(*line != '=') return(0);
line++;
while(line != NULL){
next = strchr(line, ',');
if(next) *next++ = '\0';
if(!strcmp(line, "go")) debug_stop = 0;
else if(!strcmp(line, "parent")) debug_parent = 1;
else printk("Unknown debug option : '%s'\n", line);
line = next;
}
return(0);
}
__uml_setup("debug", uml_debug_setup,
"debug\n"
" Starts up the kernel under the control of gdb. See the \n"
" kernel debugging tutorial and the debugging session pages\n"
" at http://user-mode-linux.sourceforge.net/ for more information.\n\n"
);
static int __init uml_debugtrace_setup(char *line, int *add)
{
debug_trace = 1;
return 0;
}
__uml_setup("debugtrace", uml_debugtrace_setup,
"debugtrace\n"
" Causes the tracing thread to pause until it is attached by a\n"
" debugger and continued. This is mostly for debugging crashes\n"
" early during boot, and should be pretty much obsoleted by\n"
" the debug switch.\n\n"
);
static int __init uml_honeypot_setup(char *line, int *add)
{
jail_setup("", add);
honeypot = 1;
return 0;
}
__uml_setup("honeypot", uml_honeypot_setup,
"honeypot\n"
" This makes UML put process stacks in the same location as they are\n"
" on the host, allowing expoits such as stack smashes to work against\n"
" UML. This implies 'jail'.\n\n"
);
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <asm/sigcontext.h>
#include "sysdep/ptrace.h"
#include "signal_user.h"
#include "user_util.h"
#include "kern_util.h"
#include "task.h"
#include "tt.h"
void sig_handler_common_tt(int sig, struct sigcontext *sc)
{
struct uml_pt_regs save_regs, *r;
struct signal_info *info;
int save_errno = errno, is_user;
unprotect_kernel_mem();
r = (struct uml_pt_regs *) TASK_REGS(get_current());
save_regs = *r;
is_user = user_context(SC_SP(sc));
r->is_user = is_user;
r->mode.tt = sc;
if(sig != SIGUSR2) r->syscall = -1;
change_sig(SIGUSR1, 1);
info = &sig_info[sig];
if(!info->is_irq) unblock_signals();
(*info->handler)(sig, r);
if(is_user){
interrupt_end();
block_signals();
change_sig(SIGUSR1, 0);
set_user_mode(NULL);
}
*r = save_regs;
errno = save_errno;
if(is_user) protect_kernel_mem();
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -34,17 +34,21 @@ ...@@ -34,17 +34,21 @@
#include "initrd.h" #include "initrd.h"
#include "init.h" #include "init.h"
#include "os.h" #include "os.h"
#include "choose-mode.h"
#include "mode_kern.h"
#include "mode.h"
#define DEFAULT_COMMAND_LINE "root=6200" #define DEFAULT_COMMAND_LINE "root=6200"
struct cpuinfo_um boot_cpu_data = { struct cpuinfo_um boot_cpu_data = {
.loops_per_jiffy = 0, .loops_per_jiffy = 0,
.ipi_pipe = { -1, -1 } .ipi_pipe = { -1, -1 }
}; };
unsigned long thread_saved_pc(struct task_struct *task) unsigned long thread_saved_pc(struct task_struct *task)
{ {
return(os_process_pc(task->thread.extern_pid)); return(os_process_pc(CHOOSE_MODE_PROC(thread_pid_tt, thread_pid_skas,
task)));
} }
static int show_cpuinfo(struct seq_file *m, void *v) static int show_cpuinfo(struct seq_file *m, void *v)
...@@ -93,47 +97,11 @@ pte_t * __bad_pagetable(void) ...@@ -93,47 +97,11 @@ pte_t * __bad_pagetable(void)
return(NULL); return(NULL);
} }
extern void start_kernel(void); /* Set in linux_main */
extern int debug;
extern int debug_stop;
static int start_kernel_proc(void *unused)
{
int pid;
block_signals();
pid = os_getpid();
cpu_tasks[0].pid = pid;
cpu_tasks[0].task = current;
#ifdef CONFIG_SMP
cpu_online_map = 1;
#endif
if(debug) os_stop_process(pid);
start_kernel();
return(0);
}
#ifdef CONFIG_HOST_2G_2G
#define TOP 0x80000000
#else
#define TOP 0xc0000000
#endif
#define SIZE ((CONFIG_NEST_LEVEL + CONFIG_KERNEL_HALF_GIGS) * 0x20000000)
#define START (TOP - SIZE)
/* Set in main */
unsigned long host_task_size; unsigned long host_task_size;
unsigned long task_size; unsigned long task_size;
void set_task_sizes(int arg) unsigned long uml_start;
{
/* Round up to the nearest 4M */
host_task_size = ROUND_4M((unsigned long) &arg);
task_size = START;
}
/* Set in early boot */ /* Set in early boot */
unsigned long uml_physmem; unsigned long uml_physmem;
...@@ -156,7 +124,8 @@ long physmem_size = 32 * 1024 * 1024; ...@@ -156,7 +124,8 @@ long physmem_size = 32 * 1024 * 1024;
void set_cmdline(char *cmd) void set_cmdline(char *cmd)
{ {
char *umid, *ptr; char *umid, *ptr;
if(honeypot) return;
if(CHOOSE_MODE(honeypot, 0)) return;
umid = get_umid(1); umid = get_umid(1);
if(umid != NULL){ if(umid != NULL){
...@@ -215,11 +184,48 @@ static int __init uml_ncpus_setup(char *line, int *add) ...@@ -215,11 +184,48 @@ static int __init uml_ncpus_setup(char *line, int *add)
__uml_setup("ncpus=", uml_ncpus_setup, __uml_setup("ncpus=", uml_ncpus_setup,
"ncpus=<# of desired CPUs>\n" "ncpus=<# of desired CPUs>\n"
" This tells an SMP kernel how many virtual processors to start.\n" " This tells an SMP kernel how many virtual processors to start.\n\n"
" Currently, this has no effect because SMP isn't enabled.\n\n"
); );
#endif #endif
int force_tt = 0;
#if defined(CONFIG_MODE_TT) && defined(CONFIG_MODE_SKAS)
#define DEFAULT_TT 0
static int __init mode_tt_setup(char *line, int *add)
{
force_tt = 1;
return(0);
}
__uml_setup("mode=tt", mode_tt_setup,
"mode=tt\n"
" When both CONFIG_MODE_TT and CONFIG_MODE_SKAS are enabled, this option\n"
" forces UML to run in tt (tracing thread) mode. It is not the default\n"
" because it's slower and less secure than skas mode.\n\n"
);
#else
#ifdef CONFIG_MODE_SKAS
#define DEFAULT_TT 0
#else
#ifdef CONFIG_MODE_TT
#define DEFAULT_TT 1
#else
#error Either CONFIG_MODE_TT or CONFIG_MODE_SKAS must be enabled
#endif
#endif
#endif
int mode_tt = DEFAULT_TT;
static int __init Usage(char *line, int *add) static int __init Usage(char *line, int *add)
{ {
const char **p; const char **p;
...@@ -267,8 +273,6 @@ static void __init uml_postsetup(void) ...@@ -267,8 +273,6 @@ static void __init uml_postsetup(void)
return; return;
} }
extern int debug_trace;
/* Set during early boot */ /* Set during early boot */
unsigned long brk_start; unsigned long brk_start;
static struct vm_reserved kernel_vm_reserved; static struct vm_reserved kernel_vm_reserved;
...@@ -280,7 +284,6 @@ int linux_main(int argc, char **argv) ...@@ -280,7 +284,6 @@ int linux_main(int argc, char **argv)
unsigned long avail; unsigned long avail;
unsigned long virtmem_size, max_physmem; unsigned long virtmem_size, max_physmem;
unsigned int i, add, err; unsigned int i, add, err;
void *sp;
for (i = 1; i < argc; i++){ for (i = 1; i < argc; i++){
if((i == 1) && (argv[i][0] == ' ')) continue; if((i == 1) && (argv[i][0] == ' ')) continue;
...@@ -290,13 +293,14 @@ int linux_main(int argc, char **argv) ...@@ -290,13 +293,14 @@ int linux_main(int argc, char **argv)
} }
if(have_root == 0) add_arg(saved_command_line, DEFAULT_COMMAND_LINE); if(have_root == 0) add_arg(saved_command_line, DEFAULT_COMMAND_LINE);
if(!jail || debug) mode_tt = force_tt ? 1 : !can_do_skas();
remap_data(ROUND_DOWN(&_stext), ROUND_UP(&_etext), 1); uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, 0,
remap_data(ROUND_DOWN(&_sdata), ROUND_UP(&_edata), 1); &host_task_size, &task_size);
brk_start = (unsigned long) sbrk(0); brk_start = (unsigned long) sbrk(0);
remap_data(ROUND_DOWN(&__bss_start), ROUND_UP(brk_start), 1); CHOOSE_MODE_PROC(before_mem_tt, before_mem_skas, brk_start);
uml_physmem = START; uml_physmem = uml_start;
/* Reserve up to 4M after the current brk */ /* Reserve up to 4M after the current brk */
uml_reserved = ROUND_4M(brk_start) + (1 << 22); uml_reserved = ROUND_4M(brk_start) + (1 << 22);
...@@ -331,8 +335,10 @@ int linux_main(int argc, char **argv) ...@@ -331,8 +335,10 @@ int linux_main(int argc, char **argv)
virtmem_size); virtmem_size);
err = reserve_vm(high_physmem, end_vm, &kernel_vm_reserved); err = reserve_vm(high_physmem, end_vm, &kernel_vm_reserved);
if(err) if(err){
tracer_panic("Failed to reserve VM area for kernel VM\n"); printf("Failed to reserve VM area for kernel VM\n");
exit(1);
}
uml_postsetup(); uml_postsetup();
...@@ -340,9 +346,8 @@ int linux_main(int argc, char **argv) ...@@ -340,9 +346,8 @@ int linux_main(int argc, char **argv)
2 * PAGE_SIZE; 2 * PAGE_SIZE;
task_protections((unsigned long) &init_thread_info); task_protections((unsigned long) &init_thread_info);
sp = (void *) init_task.thread.kernel_stack + 2 * PAGE_SIZE -
sizeof(unsigned long); return(CHOOSE_MODE(start_uml_tt(), start_uml_skas()));
return(signals(start_kernel_proc, sp));
} }
static int panic_exit(struct notifier_block *self, unsigned long unused1, static int panic_exit(struct notifier_block *self, unsigned long unused1,
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "umid.h" #include "umid.h"
#include "init.h" #include "init.h"
#include "os.h" #include "os.h"
#include "user_util.h"
#include "choose-mode.h"
#define UMID_LEN 64 #define UMID_LEN 64
#define UML_DIR "~/.uml/" #define UML_DIR "~/.uml/"
...@@ -91,7 +93,7 @@ static int __init create_pid_file(void) ...@@ -91,7 +93,7 @@ static int __init create_pid_file(void)
return 0; return 0;
} }
sprintf(pid, "%d\n", (tracing_pid == -1) ? os_getpid() : tracing_pid); sprintf(pid, "%d\n", os_getpid());
if(write(fd, pid, strlen(pid)) != strlen(pid)) if(write(fd, pid, strlen(pid)) != strlen(pid))
printk("Write of pid file failed - errno = %d\n", errno); printk("Write of pid file failed - errno = %d\n", errno);
close(fd); close(fd);
...@@ -179,7 +181,7 @@ int not_dead_yet(char *dir) ...@@ -179,7 +181,7 @@ int not_dead_yet(char *dir)
dead = 1; dead = 1;
} }
if(((kill(p, 0) < 0) && (errno == ESRCH)) || if(((kill(p, 0) < 0) && (errno == ESRCH)) ||
(p == tracing_pid)) (p == CHOOSE_MODE(tracing_pid, os_getpid())))
dead = 1; dead = 1;
} }
if(!dead) return(1); if(!dead) return(1);
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "mem_user.h" #include "mem_user.h"
#include "user.h" #include "user.h"
#include "init.h" #include "init.h"
#include "mode.h"
#include "choose-mode.h"
/* Set in set_stklim, which is called from main and __wrap_malloc. /* Set in set_stklim, which is called from main and __wrap_malloc.
* __wrap_malloc only calls it if main hasn't started. * __wrap_malloc only calls it if main hasn't started.
...@@ -97,9 +99,6 @@ int main(int argc, char **argv, char **envp) ...@@ -97,9 +99,6 @@ int main(int argc, char **argv, char **envp)
new_argv[i] = argv[i - 1]; new_argv[i] = argv[i - 1];
new_argv[argc + 1] = NULL; new_argv[argc + 1] = NULL;
#ifdef PROFILING
disable_profile_timer();
#endif
execvp(new_argv[0], new_argv); execvp(new_argv[0], new_argv);
perror("execing with extended args"); perror("execing with extended args");
exit(1); exit(1);
...@@ -108,7 +107,6 @@ int main(int argc, char **argv, char **envp) ...@@ -108,7 +107,6 @@ int main(int argc, char **argv, char **envp)
linux_prog = argv[0]; linux_prog = argv[0];
set_stklim(); set_stklim();
set_task_sizes(0);
if((new_argv = malloc((argc + 1) * sizeof(char *))) == NULL){ if((new_argv = malloc((argc + 1) * sizeof(char *))) == NULL){
perror("Mallocing argv"); perror("Mallocing argv");
...@@ -136,60 +134,14 @@ int main(int argc, char **argv, char **envp) ...@@ -136,60 +134,14 @@ int main(int argc, char **argv, char **envp)
return(uml_exitcode); return(uml_exitcode);
} }
/* Changed in __wrap___monstartup and __wrap_malloc very early */ #define CAN_KMALLOC() \
static int allocating_monbuf = 0; (kmalloc_ok && CHOOSE_MODE((getpid() != tracing_pid), 1))
#ifdef PROFILING
extern void __real___monstartup (unsigned long, unsigned long);
void __wrap___monstartup (unsigned long lowpc, unsigned long highpc)
{
allocating_monbuf = 1;
__real___monstartup(lowpc, highpc);
allocating_monbuf = 0;
get_profile_timer();
}
#endif
extern void *__real_malloc(int); extern void *__real_malloc(int);
extern unsigned long host_task_size;
/* Set in __wrap_malloc early */
static void *gmon_buf = NULL;
void *__wrap_malloc(int size) void *__wrap_malloc(int size)
{ {
if(allocating_monbuf){ if(CAN_KMALLOC()) return(um_kmalloc(size));
unsigned long start, end;
int fd;
/* Turn this off now in case create_mem_file tries allocating
* memory
*/
allocating_monbuf = 0;
fd = create_mem_file(size);
/* Calculate this here because linux_main hasn't run yet
* and host_task_size figures in STACK_TOP, which figures
* in kmem_end.
*/
set_task_sizes(0);
/* Same with stacksizelim */
set_stklim();
end = get_kmem_end();
start = (end - size) & PAGE_MASK;
gmon_buf = mmap((void *) start, size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_FIXED, fd, 0);
if(gmon_buf != (void *) start){
perror("Creating gprof buffer");
exit(1);
}
set_kmem_end(start);
return(gmon_buf);
}
if(kmalloc_ok) return(um_kmalloc(size));
else return(__real_malloc(size)); else return(__real_malloc(size));
} }
...@@ -206,11 +158,7 @@ extern void __real_free(void *); ...@@ -206,11 +158,7 @@ extern void __real_free(void *);
void __wrap_free(void *ptr) void __wrap_free(void *ptr)
{ {
/* Could maybe unmap the gmon buffer, but we're just about to if(CAN_KMALLOC()) kfree(ptr);
* exit anyway
*/
if(ptr == gmon_buf) return;
if(kmalloc_ok) kfree(ptr);
else __real_free(ptr); else __real_free(ptr);
} }
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
# Licensed under the GPL # Licensed under the GPL
# #
obj-y = file.o process.o tty.o obj-y = file.o process.o tty.o drivers/
USER_OBJS := $(foreach file,$(obj-y),arch/um/os-Linux/$(file)) USER_OBJS := $(foreach file,file.o process.o tty.o,$(obj)/$(file))
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c $(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $< $(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
clean : clean :
......
...@@ -13,8 +13,9 @@ obj-$(CONFIG_UML_NET_TUNTAP) += tuntap.o ...@@ -13,8 +13,9 @@ obj-$(CONFIG_UML_NET_TUNTAP) += tuntap.o
USER_SINGLE_OBJS = $(foreach f,$(patsubst %.o,%,$(obj-y)),$($(f)-objs)) USER_SINGLE_OBJS = $(foreach f,$(patsubst %.o,%,$(obj-y)),$($(f)-objs))
USER_OBJS = $(filter %_user.o,$(obj-y) $(USER_SINGLE_OBJS)) USER_OBJS = $(filter %_user.o,$(obj-y) $(USER_SINGLE_OBJS))
USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c $(USER_OBJS) : %.o: %.c
$(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $< $(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include "os.h" #include "os.h"
#include "user.h" #include "user.h"
...@@ -75,9 +77,12 @@ void os_stop_process(int pid) ...@@ -75,9 +77,12 @@ void os_stop_process(int pid)
kill(pid, SIGSTOP); kill(pid, SIGSTOP);
} }
void os_kill_process(int pid) void os_kill_process(int pid, int reap_child)
{ {
kill(pid, SIGKILL); kill(pid, SIGKILL);
if(reap_child)
waitpid(pid, NULL, 0);
} }
void os_usr1_process(int pid) void os_usr1_process(int pid)
...@@ -90,6 +95,41 @@ int os_getpid(void) ...@@ -90,6 +95,41 @@ int os_getpid(void)
return(getpid()); return(getpid());
} }
int os_map_memory(void *virt, int fd, unsigned long off, unsigned long len,
int r, int w, int x)
{
void *loc;
int prot;
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0);
loc = mmap((void *) virt, len, prot, MAP_SHARED | MAP_FIXED,
fd, off);
if(loc < 0)
return(-errno);
return(0);
}
int os_protect_memory(void *addr, unsigned long len, int r, int w, int x)
{
int prot = ((r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0));
if(mprotect(addr, len, prot) < 0)
return(-errno);
return(0);
}
int os_unmap_memory(void *addr, int len)
{
int err;
err = munmap(addr, len);
if(err < 0) return(-errno);
return(0);
}
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically * Emacs will notice this stuff at the end of the file and automatically
......
...@@ -35,7 +35,7 @@ int get_pty(void) ...@@ -35,7 +35,7 @@ int get_pty(void)
} }
info.fd = fd; info.fd = fd;
tracing_cb(grantpt_cb, &info); initial_thread_cb(grantpt_cb, &info);
if(info.res < 0){ if(info.res < 0){
printk("get_pty : Couldn't grant pty - errno = %d\n", printk("get_pty : Couldn't grant pty - errno = %d\n",
......
obj-y = bugs.o checksum.o extable.o fault.o ksyms.o ldt.o \ obj-y = bugs.o checksum.o extable.o fault.o ksyms.o ldt.o module.o \
ptrace.o ptrace_user.o semaphore.o sigcontext.o syscalls.o sysrq.o ptrace.o ptrace_user.o semaphore.o sigcontext.o syscalls.o sysrq.o
obj-$(CONFIG_HIGHMEM) += highmem.o obj-$(CONFIG_HIGHMEM) += highmem.o
...@@ -6,30 +6,28 @@ obj-$(CONFIG_HIGHMEM) += highmem.o ...@@ -6,30 +6,28 @@ obj-$(CONFIG_HIGHMEM) += highmem.o
export-objs = ksyms.o export-objs = ksyms.o
USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o USER_OBJS := bugs.o ptrace_user.o sigcontext.o fault.o
USER_OBJS := $(foreach file,$(USER_OBJS),arch/um/sys-i386/$(file)) USER_OBJS := $(foreach file,$(USER_OBJS),$(obj)/$(file))
SYMLINKS = semaphore.c checksum.S extable.c highmem.c SYMLINKS = semaphore.c extable.c highmem.c module.c
include $(TOPDIR)/Rules.make semaphore.c-dir = kernel
extable.c-dir = mm
highmem.c-dir = mm
module.c-dir = kernel
$(USER_OBJS) : %.o: %.c define make_link
$(CC) $(CFLAGS_$@) $(USER_CFLAGS) -c -o $@ $< -rm -f $1
ln -sf $(TOPDIR)/arch/i386/$($(notdir $1)-dir)/$(notdir $1) $1
endef
arch/um/sys-i386/checksum.S: include $(TOPDIR)/Rules.make
-rm -f $@
-ln -s $(TOPDIR)/arch/i386/lib/$(notdir $@) $@
arch/um/sys-i386/semaphore.c: $(USER_OBJS) : %.o: %.c
-rm -f $@ $(CC) $(CFLAGS_$(notdir $@)) $(USER_CFLAGS) -c -o $@ $<
-ln -s $(TOPDIR)/arch/i386/kernel/$(notdir $@) $@
arch/um/sys-i386/extable.c: $(foreach f,$(SYMLINKS),$(src)/$f):
-rm -f $@ $(call make_link,$@)
-ln -s $(TOPDIR)/arch/i386/mm/$(notdir $@) $@
arch/um/sys-i386/highmem.c:
-rm -f $@
-ln -s $(TOPDIR)/arch/i386/mm/$(notdir $@) $@
clean: clean:
$(MAKE) -C util clean $(MAKE) -C util clean
......
/*
* INET An implementation of the TCP/IP protocol suite for the LINUX
* operating system. INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* IP/TCP/UDP checksumming routines
*
* Authors: Jorge Cwik, <jorge@laser.satlink.net>
* Arnt Gulbrandsen, <agulbra@nvg.unit.no>
* Tom May, <ftom@netcom.com>
* Pentium Pro/II routines:
* Alexander Kjeldaas <astor@guardian.no>
* Finn Arne Gangstad <finnag@guardian.no>
* Lots of code moved from tcp.c and ip.c; see those files
* for more names.
*
* Changes: Ingo Molnar, converted csum_partial_copy() to 2.1 exception
* handling.
* Andi Kleen, add zeroing on error
* converted to pure assembler
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/config.h>
#include <asm/errno.h>
/*
* computes a partial checksum, e.g. for TCP/UDP fragments
*/
/*
unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
*/
.text
.align 4
.globl arch_csum_partial
#ifndef CONFIG_X86_USE_PPRO_CHECKSUM
/*
* Experiments with Ethernet and SLIP connections show that buff
* is aligned on either a 2-byte or 4-byte boundary. We get at
* least a twofold speedup on 486 and Pentium if it is 4-byte aligned.
* Fortunately, it is easy to convert 2-byte alignment to 4-byte
* alignment for the unrolled loop.
*/
arch_csum_partial:
pushl %esi
pushl %ebx
movl 20(%esp),%eax # Function arg: unsigned int sum
movl 16(%esp),%ecx # Function arg: int len
movl 12(%esp),%esi # Function arg: unsigned char *buff
testl $2, %esi # Check alignment.
jz 2f # Jump if alignment is ok.
subl $2, %ecx # Alignment uses up two bytes.
jae 1f # Jump if we had at least two bytes.
addl $2, %ecx # ecx was < 2. Deal with it.
jmp 4f
1: movw (%esi), %bx
addl $2, %esi
addw %bx, %ax
adcl $0, %eax
2:
movl %ecx, %edx
shrl $5, %ecx
jz 2f
testl %esi, %esi
1: movl (%esi), %ebx
adcl %ebx, %eax
movl 4(%esi), %ebx
adcl %ebx, %eax
movl 8(%esi), %ebx
adcl %ebx, %eax
movl 12(%esi), %ebx
adcl %ebx, %eax
movl 16(%esi), %ebx
adcl %ebx, %eax
movl 20(%esi), %ebx
adcl %ebx, %eax
movl 24(%esi), %ebx
adcl %ebx, %eax
movl 28(%esi), %ebx
adcl %ebx, %eax
lea 32(%esi), %esi
dec %ecx
jne 1b
adcl $0, %eax
2: movl %edx, %ecx
andl $0x1c, %edx
je 4f
shrl $2, %edx # This clears CF
3: adcl (%esi), %eax
lea 4(%esi), %esi
dec %edx
jne 3b
adcl $0, %eax
4: andl $3, %ecx
jz 7f
cmpl $2, %ecx
jb 5f
movw (%esi),%cx
leal 2(%esi),%esi
je 6f
shll $16,%ecx
5: movb (%esi),%cl
6: addl %ecx,%eax
adcl $0, %eax
7:
popl %ebx
popl %esi
ret
#else
/* Version for PentiumII/PPro */
arch_csum_partial:
pushl %esi
pushl %ebx
movl 20(%esp),%eax # Function arg: unsigned int sum
movl 16(%esp),%ecx # Function arg: int len
movl 12(%esp),%esi # Function arg: const unsigned char *buf
testl $2, %esi
jnz 30f
10:
movl %ecx, %edx
movl %ecx, %ebx
andl $0x7c, %ebx
shrl $7, %ecx
addl %ebx,%esi
shrl $2, %ebx
negl %ebx
lea 45f(%ebx,%ebx,2), %ebx
testl %esi, %esi
jmp *%ebx
# Handle 2-byte-aligned regions
20: addw (%esi), %ax
lea 2(%esi), %esi
adcl $0, %eax
jmp 10b
30: subl $2, %ecx
ja 20b
je 32f
movzbl (%esi),%ebx # csumming 1 byte, 2-aligned
addl %ebx, %eax
adcl $0, %eax
jmp 80f
32:
addw (%esi), %ax # csumming 2 bytes, 2-aligned
adcl $0, %eax
jmp 80f
40:
addl -128(%esi), %eax
adcl -124(%esi), %eax
adcl -120(%esi), %eax
adcl -116(%esi), %eax
adcl -112(%esi), %eax
adcl -108(%esi), %eax
adcl -104(%esi), %eax
adcl -100(%esi), %eax
adcl -96(%esi), %eax
adcl -92(%esi), %eax
adcl -88(%esi), %eax
adcl -84(%esi), %eax
adcl -80(%esi), %eax
adcl -76(%esi), %eax
adcl -72(%esi), %eax
adcl -68(%esi), %eax
adcl -64(%esi), %eax
adcl -60(%esi), %eax
adcl -56(%esi), %eax
adcl -52(%esi), %eax
adcl -48(%esi), %eax
adcl -44(%esi), %eax
adcl -40(%esi), %eax
adcl -36(%esi), %eax
adcl -32(%esi), %eax
adcl -28(%esi), %eax
adcl -24(%esi), %eax
adcl -20(%esi), %eax
adcl -16(%esi), %eax
adcl -12(%esi), %eax
adcl -8(%esi), %eax
adcl -4(%esi), %eax
45:
lea 128(%esi), %esi
adcl $0, %eax
dec %ecx
jge 40b
movl %edx, %ecx
50: andl $3, %ecx
jz 80f
# Handle the last 1-3 bytes without jumping
notl %ecx # 1->2, 2->1, 3->0, higher bits are masked
movl $0xffffff,%ebx # by the shll and shrl instructions
shll $3,%ecx
shrl %cl,%ebx
andl -128(%esi),%ebx # esi is 4-aligned so should be ok
addl %ebx,%eax
adcl $0,%eax
80:
popl %ebx
popl %esi
ret
#endif
/*
unsigned int csum_partial_copy_generic (const char *src, char *dst,
int len, int sum, int *src_err_ptr, int *dst_err_ptr)
*/
/*
* Copy from ds while checksumming, otherwise like csum_partial
*
* The macros SRC and DST specify the type of access for the instruction.
* thus we can call a custom exception handler for all access types.
*
* FIXME: could someone double-check whether I haven't mixed up some SRC and
* DST definitions? It's damn hard to trigger all cases. I hope I got
* them all but there's no guarantee.
*/
#define SRC(y...) \
9999: y; \
.section __ex_table, "a"; \
.long 9999b, 6001f ; \
.previous
#define DST(y...) \
9999: y; \
.section __ex_table, "a"; \
.long 9999b, 6002f ; \
.previous
.align 4
.globl csum_partial_copy_generic_i386
#ifndef CONFIG_X86_USE_PPRO_CHECKSUM
#define ARGBASE 16
#define FP 12
csum_partial_copy_generic_i386:
subl $4,%esp
pushl %edi
pushl %esi
pushl %ebx
movl ARGBASE+16(%esp),%eax # sum
movl ARGBASE+12(%esp),%ecx # len
movl ARGBASE+4(%esp),%esi # src
movl ARGBASE+8(%esp),%edi # dst
testl $2, %edi # Check alignment.
jz 2f # Jump if alignment is ok.
subl $2, %ecx # Alignment uses up two bytes.
jae 1f # Jump if we had at least two bytes.
addl $2, %ecx # ecx was < 2. Deal with it.
jmp 4f
SRC(1: movw (%esi), %bx )
addl $2, %esi
DST( movw %bx, (%edi) )
addl $2, %edi
addw %bx, %ax
adcl $0, %eax
2:
movl %ecx, FP(%esp)
shrl $5, %ecx
jz 2f
testl %esi, %esi
SRC(1: movl (%esi), %ebx )
SRC( movl 4(%esi), %edx )
adcl %ebx, %eax
DST( movl %ebx, (%edi) )
adcl %edx, %eax
DST( movl %edx, 4(%edi) )
SRC( movl 8(%esi), %ebx )
SRC( movl 12(%esi), %edx )
adcl %ebx, %eax
DST( movl %ebx, 8(%edi) )
adcl %edx, %eax
DST( movl %edx, 12(%edi) )
SRC( movl 16(%esi), %ebx )
SRC( movl 20(%esi), %edx )
adcl %ebx, %eax
DST( movl %ebx, 16(%edi) )
adcl %edx, %eax
DST( movl %edx, 20(%edi) )
SRC( movl 24(%esi), %ebx )
SRC( movl 28(%esi), %edx )
adcl %ebx, %eax
DST( movl %ebx, 24(%edi) )
adcl %edx, %eax
DST( movl %edx, 28(%edi) )
lea 32(%esi), %esi
lea 32(%edi), %edi
dec %ecx
jne 1b
adcl $0, %eax
2: movl FP(%esp), %edx
movl %edx, %ecx
andl $0x1c, %edx
je 4f
shrl $2, %edx # This clears CF
SRC(3: movl (%esi), %ebx )
adcl %ebx, %eax
DST( movl %ebx, (%edi) )
lea 4(%esi), %esi
lea 4(%edi), %edi
dec %edx
jne 3b
adcl $0, %eax
4: andl $3, %ecx
jz 7f
cmpl $2, %ecx
jb 5f
SRC( movw (%esi), %cx )
leal 2(%esi), %esi
DST( movw %cx, (%edi) )
leal 2(%edi), %edi
je 6f
shll $16,%ecx
SRC(5: movb (%esi), %cl )
DST( movb %cl, (%edi) )
6: addl %ecx, %eax
adcl $0, %eax
7:
5000:
# Exception handler:
.section .fixup, "ax"
6001:
movl ARGBASE+20(%esp), %ebx # src_err_ptr
movl $-EFAULT, (%ebx)
# zero the complete destination - computing the rest
# is too much work
movl ARGBASE+8(%esp), %edi # dst
movl ARGBASE+12(%esp), %ecx # len
xorl %eax,%eax
rep ; stosb
jmp 5000b
6002:
movl ARGBASE+24(%esp), %ebx # dst_err_ptr
movl $-EFAULT,(%ebx)
jmp 5000b
.previous
popl %ebx
popl %esi
popl %edi
popl %ecx # equivalent to addl $4,%esp
ret
#else
/* Version for PentiumII/PPro */
#define ROUND1(x) \
SRC(movl x(%esi), %ebx ) ; \
addl %ebx, %eax ; \
DST(movl %ebx, x(%edi) ) ;
#define ROUND(x) \
SRC(movl x(%esi), %ebx ) ; \
adcl %ebx, %eax ; \
DST(movl %ebx, x(%edi) ) ;
#define ARGBASE 12
csum_partial_copy_generic_i386:
pushl %ebx
pushl %edi
pushl %esi
movl ARGBASE+4(%esp),%esi #src
movl ARGBASE+8(%esp),%edi #dst
movl ARGBASE+12(%esp),%ecx #len
movl ARGBASE+16(%esp),%eax #sum
# movl %ecx, %edx
movl %ecx, %ebx
movl %esi, %edx
shrl $6, %ecx
andl $0x3c, %ebx
negl %ebx
subl %ebx, %esi
subl %ebx, %edi
lea -1(%esi),%edx
andl $-32,%edx
lea 3f(%ebx,%ebx), %ebx
testl %esi, %esi
jmp *%ebx
1: addl $64,%esi
addl $64,%edi
SRC(movb -32(%edx),%bl) ; SRC(movb (%edx),%bl)
ROUND1(-64) ROUND(-60) ROUND(-56) ROUND(-52)
ROUND (-48) ROUND(-44) ROUND(-40) ROUND(-36)
ROUND (-32) ROUND(-28) ROUND(-24) ROUND(-20)
ROUND (-16) ROUND(-12) ROUND(-8) ROUND(-4)
3: adcl $0,%eax
addl $64, %edx
dec %ecx
jge 1b
4: movl ARGBASE+12(%esp),%edx #len
andl $3, %edx
jz 7f
cmpl $2, %edx
jb 5f
SRC( movw (%esi), %dx )
leal 2(%esi), %esi
DST( movw %dx, (%edi) )
leal 2(%edi), %edi
je 6f
shll $16,%edx
5:
SRC( movb (%esi), %dl )
DST( movb %dl, (%edi) )
6: addl %edx, %eax
adcl $0, %eax
7:
.section .fixup, "ax"
6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
movl $-EFAULT, (%ebx)
# zero the complete destination (computing the rest is too much work)
movl ARGBASE+8(%esp),%edi # dst
movl ARGBASE+12(%esp),%ecx # len
xorl %eax,%eax
rep; stosb
jmp 7b
6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
movl $-EFAULT, (%ebx)
jmp 7b
.previous
popl %esi
popl %edi
popl %ebx
ret
#undef ROUND
#undef ROUND1
#endif
...@@ -13,4 +13,5 @@ EXPORT_SYMBOL(__down_failed_trylock); ...@@ -13,4 +13,5 @@ EXPORT_SYMBOL(__down_failed_trylock);
EXPORT_SYMBOL(__up_wakeup); EXPORT_SYMBOL(__up_wakeup);
/* Networking helper routines. */ /* Networking helper routines. */
EXPORT_SYMBOL(csum_partial_copy_generic); EXPORT_SYMBOL(csum_partial_copy_from);
EXPORT_SYMBOL(csum_partial_copy_to);
...@@ -3,15 +3,82 @@ ...@@ -3,15 +3,82 @@
* Licensed under the GPL * Licensed under the GPL
*/ */
#include "linux/config.h"
#include "linux/slab.h"
#include "asm/uaccess.h" #include "asm/uaccess.h"
#include "asm/ptrace.h"
#include "choose-mode.h"
#include "kern.h"
#ifdef CONFIG_MODE_TT
extern int modify_ldt(int func, void *ptr, unsigned long bytecount); extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
int sys_modify_ldt(int func, void *ptr, unsigned long bytecount) int sys_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
{ {
if(verify_area(VERIFY_READ, ptr, bytecount)) return(-EFAULT); if(verify_area(VERIFY_READ, ptr, bytecount)) return(-EFAULT);
return(modify_ldt(func, ptr, bytecount)); return(modify_ldt(func, ptr, bytecount));
} }
#endif
#ifdef CONFIG_MODE_SKAS
extern int userspace_pid;
int sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
{
struct ptrace_ldt ldt;
void *buf;
int res, n;
buf = kmalloc(bytecount, GFP_KERNEL);
if(buf == NULL)
return(-ENOMEM);
res = 0;
switch(func){
case 1:
case 0x11:
res = copy_from_user(buf, ptr, bytecount);
break;
}
if(res != 0){
res = -EFAULT;
goto out;
}
ldt = ((struct ptrace_ldt) { .func = func,
.ptr = buf,
.bytecount = bytecount });
res = ptrace(PTRACE_LDT, userspace_pid, 0, (unsigned long) &ldt);
if(res < 0)
goto out;
switch(func){
case 0:
case 2:
n = res;
res = copy_to_user(ptr, buf, n);
if(res != 0)
res = -EFAULT;
else
res = n;
break;
}
out:
kfree(buf);
return(res);
}
#endif
int sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
{
return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
ptr, bytecount));
}
/* /*
* Overrides for Emacs so that we follow Linus's tabbing style. * Overrides for Emacs so that we follow Linus's tabbing style.
......
...@@ -169,11 +169,12 @@ static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct *fxsave ...@@ -169,11 +169,12 @@ static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct *fxsave
} }
/* /*
b * FXSR floating point environment conversions. * FXSR floating point environment conversions.
*/ */
static inline int convert_fxsr_to_user(struct _fpstate *buf, #ifdef CONFIG_MODE_TT
struct pt_regs *regs) static inline int convert_fxsr_to_user_tt(struct _fpstate *buf,
struct pt_regs *regs)
{ {
struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs)); struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
unsigned long env[7]; unsigned long env[7];
...@@ -200,9 +201,17 @@ static inline int convert_fxsr_to_user(struct _fpstate *buf, ...@@ -200,9 +201,17 @@ static inline int convert_fxsr_to_user(struct _fpstate *buf,
} }
return 0; return 0;
} }
#endif
static inline int convert_fxsr_from_user(struct pt_regs *regs, static inline int convert_fxsr_to_user(struct _fpstate *buf,
struct _fpstate *buf) struct pt_regs *regs)
{
return(CHOOSE_MODE(convert_fxsr_to_user_tt(buf, regs), 0));
}
#ifdef CONFIG_MODE_TT
static inline int convert_fxsr_from_user_tt(struct pt_regs *regs,
struct _fpstate *buf)
{ {
struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs)); struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
unsigned long env[7]; unsigned long env[7];
...@@ -230,6 +239,13 @@ static inline int convert_fxsr_from_user(struct pt_regs *regs, ...@@ -230,6 +239,13 @@ static inline int convert_fxsr_from_user(struct pt_regs *regs,
} }
return 0; return 0;
} }
#endif
static inline int convert_fxsr_from_user(struct pt_regs *regs,
struct _fpstate *buf)
{
return(CHOOSE_MODE(convert_fxsr_from_user_tt(regs, buf), 0));
}
int get_fpregs(unsigned long buf, struct task_struct *child) int get_fpregs(unsigned long buf, struct task_struct *child)
{ {
...@@ -251,7 +267,8 @@ int set_fpregs(unsigned long buf, struct task_struct *child) ...@@ -251,7 +267,8 @@ int set_fpregs(unsigned long buf, struct task_struct *child)
else return(0); else return(0);
} }
int get_fpxregs(unsigned long buf, struct task_struct *tsk) #ifdef CONFIG_MODE_TT
int get_fpxregs_tt(unsigned long buf, struct task_struct *tsk)
{ {
struct pt_regs *regs = &tsk->thread.regs; struct pt_regs *regs = &tsk->thread.regs;
struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs)); struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
...@@ -262,8 +279,15 @@ int get_fpxregs(unsigned long buf, struct task_struct *tsk) ...@@ -262,8 +279,15 @@ int get_fpxregs(unsigned long buf, struct task_struct *tsk)
if(err) return -EFAULT; if(err) return -EFAULT;
else return 0; else return 0;
} }
#endif
int set_fpxregs(unsigned long buf, struct task_struct *tsk) int get_fpxregs(unsigned long buf, struct task_struct *tsk)
{
return(CHOOSE_MODE(get_fpxregs_tt(buf, tsk), 0));
}
#ifdef CONFIG_MODE_TT
int set_fpxregs_tt(unsigned long buf, struct task_struct *tsk)
{ {
struct pt_regs *regs = &tsk->thread.regs; struct pt_regs *regs = &tsk->thread.regs;
struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs)); struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
...@@ -274,6 +298,12 @@ int set_fpxregs(unsigned long buf, struct task_struct *tsk) ...@@ -274,6 +298,12 @@ int set_fpxregs(unsigned long buf, struct task_struct *tsk)
if(err) return -EFAULT; if(err) return -EFAULT;
else return 0; else return 0;
} }
#endif
int set_fpxregs(unsigned long buf, struct task_struct *tsk)
{
return(CHOOSE_MODE(set_fpxregs_tt(buf, tsk), 0));
}
#ifdef notdef #ifdef notdef
int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
...@@ -291,8 +321,10 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) ...@@ -291,8 +321,10 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
return(1); return(1);
} }
#endif #endif
static inline void copy_fpu_fxsave(struct pt_regs *regs,
struct user_i387_struct *buf) #ifdef CONFIG_MODE_TT
static inline void copy_fpu_fxsave_tt(struct pt_regs *regs,
struct user_i387_struct *buf)
{ {
struct i387_fxsave_struct *fpu = SC_FXSR_ENV(PT_REGS_SC(regs)); struct i387_fxsave_struct *fpu = SC_FXSR_ENV(PT_REGS_SC(regs));
unsigned short *to; unsigned short *to;
...@@ -307,6 +339,13 @@ static inline void copy_fpu_fxsave(struct pt_regs *regs, ...@@ -307,6 +339,13 @@ static inline void copy_fpu_fxsave(struct pt_regs *regs,
memcpy( to, from, 5 * sizeof(unsigned short) ); memcpy( to, from, 5 * sizeof(unsigned short) );
} }
} }
#endif
static inline void copy_fpu_fxsave(struct pt_regs *regs,
struct user_i387_struct *buf)
{
(void) CHOOSE_MODE(copy_fpu_fxsave_tt(regs, buf), 0);
}
int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu ) int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
{ {
......
...@@ -102,7 +102,7 @@ void update_debugregs(int seq) ...@@ -102,7 +102,7 @@ void update_debugregs(int seq)
if(seq == debugregs_seq) return; if(seq == debugregs_seq) return;
me = os_getpid(); me = os_getpid();
tracing_cb(update_debugregs_cb, &me); initial_thread_cb(update_debugregs_cb, &me);
} }
/* /*
......
...@@ -18,45 +18,6 @@ int sc_size(void *data) ...@@ -18,45 +18,6 @@ int sc_size(void *data)
return(sizeof(struct sigcontext) + arch->fpstate_size); return(sizeof(struct sigcontext) + arch->fpstate_size);
} }
int copy_sc_to_user(void *to_ptr, void *from_ptr, void *data)
{
struct arch_frame_data *arch = data;
struct sigcontext *to = to_ptr, *from = from_ptr;
struct _fpstate *to_fp, *from_fp;
int err;
to_fp = (struct _fpstate *)((unsigned long) to + sizeof(*to));
from_fp = from->fpstate;
err = copy_to_user_proc(to, from, sizeof(*to));
if(from_fp != NULL){
err |= copy_to_user_proc(&to->fpstate, &to_fp,
sizeof(to->fpstate));
err |= copy_to_user_proc(to_fp, from_fp, arch->fpstate_size);
}
return(err);
}
int copy_sc_from_user(void *to_ptr, void *from_ptr, void *data)
{
struct arch_frame_data *arch = data;
struct sigcontext *to = to_ptr, *from = from_ptr;
struct _fpstate *to_fp, *from_fp;
unsigned long sigs;
int err;
to_fp = to->fpstate;
from_fp = from->fpstate;
sigs = to->oldmask;
err = copy_from_user_proc(to, from, sizeof(*to));
to->oldmask = sigs;
if(to_fp != NULL){
err |= copy_from_user_proc(&to->fpstate, &to_fp,
sizeof(to->fpstate));
err |= copy_from_user_proc(to_fp, from_fp, arch->fpstate_size);
}
return(err);
}
void sc_to_sc(void *to_ptr, void *from_ptr) void sc_to_sc(void *to_ptr, void *from_ptr)
{ {
struct sigcontext *to = to_ptr, *from = from_ptr; struct sigcontext *to = to_ptr, *from = from_ptr;
......
#include "linux/stddef.h" #include "linux/stddef.h"
#include "linux/sched.h" #include "linux/sched.h"
int debugreg(void) extern void print_head(void);
extern void print_constant_ptr(char *name, int value);
extern void print_constant(char *name, char *type, int value);
extern void print_tail(void);
#define THREAD_OFFSET(field) offsetof(struct task_struct, thread.field)
int main(int argc, char **argv)
{ {
return(offsetof(struct task_struct, thread.arch.debugregs)); print_head();
print_constant_ptr("TASK_DEBUGREGS", THREAD_OFFSET(arch.debugregs));
print_constant("TASK_EXTERN_PID", "int", THREAD_OFFSET(mode.tt.extern_pid));
print_tail();
return(0);
} }
#include <stdio.h> #include <stdio.h>
#include <linux/stddef.h>
#include <asm/user.h>
extern int debugreg(void); void print_head(void)
{
printf("/*\n");
printf(" * Generated by mk_thread\n");
printf(" */\n");
printf("\n");
printf("#ifndef __UM_THREAD_H\n");
printf("#define __UM_THREAD_H\n");
printf("\n");
}
void print_constant_ptr(char *name, int value)
{
printf("#define %s(task) ((unsigned long *) "
"&(((char *) (task))[%d]))\n", name, value);
}
void print_constant(char *name, char *type, int value)
{
printf("#define %s(task) *((%s *) &(((char *) (task))[%d]))\n", name, type,
value);
}
int main(int argc, char **argv) void print_tail(void)
{ {
printf("#define TASK_DEBUGREGS(task) ((unsigned long *) " printf("\n");
"&(((char *) (task))[%d]))\n", debugreg()); printf("#endif\n");
return(0);
} }
...@@ -38,6 +38,7 @@ SECTIONS ...@@ -38,6 +38,7 @@ SECTIONS
__ex_table : { *(__ex_table) } __ex_table : { *(__ex_table) }
__stop___ex_table = .; __stop___ex_table = .;
. = ALIGN(64);
__start___ksymtab = .; /* Kernel symbol table */ __start___ksymtab = .; /* Kernel symbol table */
__ksymtab : { *(__ksymtab) } __ksymtab : { *(__ksymtab) }
__stop___ksymtab = .; __stop___ksymtab = .;
......
EXTRA_TARGETS := mk_task mk_task_kern.o EXTRA_TARGETS := mk_task mk_constants
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
...@@ -8,6 +8,15 @@ $(obj)/mk_task: $(obj)/mk_task_user.o $(obj)/mk_task_kern.o ...@@ -8,6 +8,15 @@ $(obj)/mk_task: $(obj)/mk_task_user.o $(obj)/mk_task_kern.o
$(obj)/mk_task_user.o: $(src)/mk_task_user.c $(obj)/mk_task_user.o: $(src)/mk_task_user.c
$(CC) -o $@ -c $< $(CC) -o $@ -c $<
$(obj)/mk_constants : $(obj)/mk_constants_user.o $(obj)/mk_constants_kern.o
$(CC) -o $@ $^
$(obj)/mk_constants_user.o : $(src)/mk_constants_user.c
$(CC) -c $< -o $@
$(obj)/mk_constants_kern.o : $(src)/mk_constants_kern.c
$(CC) $(CFLAGS) -c $< -o $@
clean: clean:
$(RM) $(EXTRA_TARGETS) $(RM) $(EXTRA_TARGETS)
......
#include "linux/kernel.h"
#include "linux/stringify.h"
#include "asm/page.h"
extern void print_head(void);
extern void print_constant_str(char *name, char *value);
extern void print_constant_int(char *name, int value);
extern void print_tail(void);
int main(int argc, char **argv)
{
print_head();
print_constant_int("UM_KERN_PAGE_SIZE", PAGE_SIZE);
print_constant_str("UM_KERN_EMERG", KERN_EMERG);
print_constant_str("UM_KERN_ALERT", KERN_ALERT);
print_constant_str("UM_KERN_CRIT", KERN_CRIT);
print_constant_str("UM_KERN_ERR", KERN_ERR);
print_constant_str("UM_KERN_WARNING", KERN_WARNING);
print_constant_str("UM_KERN_NOTICE", KERN_NOTICE);
print_constant_str("UM_KERN_INFO", KERN_INFO);
print_constant_str("UM_KERN_DEBUG", KERN_DEBUG);
print_tail();
return(0);
}
#include <stdio.h>
void print_head(void)
{
printf("/*\n");
printf(" * Generated by mk_constants\n");
printf(" */\n");
printf("\n");
printf("#ifndef __UM_CONSTANTS_H\n");
printf("#define __UM_CONSTANTS_H\n");
printf("\n");
}
void print_constant_str(char *name, char *value)
{
printf("#define %s \"%s\"\n", name, value);
}
void print_constant_int(char *name, int value)
{
printf("#define %s %d\n", name, value);
}
void print_tail(void)
{
printf("\n");
printf("#endif\n");
}
#ifndef __UM_A_OUT_H #ifndef __UM_A_OUT_H
#define __UM_A_OUT_H #define __UM_A_OUT_H
#include "linux/config.h"
#include "asm/arch/a.out.h" #include "asm/arch/a.out.h"
#include "choose-mode.h"
#undef STACK_TOP #undef STACK_TOP
...@@ -9,10 +11,10 @@ extern unsigned long stacksizelim; ...@@ -9,10 +11,10 @@ extern unsigned long stacksizelim;
extern unsigned long host_task_size; extern unsigned long host_task_size;
extern int honeypot;
#define STACK_ROOM (stacksizelim) #define STACK_ROOM (stacksizelim)
#define STACK_TOP (honeypot ? host_task_size : task_size) extern int honeypot;
#define STACK_TOP \
CHOOSE_MODE((honeypot ? host_task_size : task_size), task_size)
#endif #endif
#ifndef __UM_CHECKSUM_H #ifndef __UM_CHECKSUM_H
#define __UM_CHECKSUM_H #define __UM_CHECKSUM_H
#include "asm/arch/checksum.h" #include "sysdep/checksum.h"
#endif #endif
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __MMU_H #ifndef __MMU_H
#define __MMU_H #define __MMU_H
#include "asm/arch/mmu.h" #include "um_mmu.h"
#endif #endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __UM_MMU_CONTEXT_H #ifndef __UM_MMU_CONTEXT_H
#define __UM_MMU_CONTEXT_H #define __UM_MMU_CONTEXT_H
#include "linux/sched.h" #include "linux/sched.h"
#include "choose-mode.h"
#define init_new_context(task, mm) (0)
#define get_mmu_context(task) do ; while(0) #define get_mmu_context(task) do ; while(0)
#define activate_context(tsk) do ; while(0) #define activate_context(tsk) do ; while(0)
#define destroy_context(mm) do ; while(0)
static inline void activate_mm(struct mm_struct *old, struct mm_struct *new) static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
{ {
} }
extern void switch_mm_skas(int mm_fd);
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
struct task_struct *tsk, unsigned cpu) struct task_struct *tsk, unsigned cpu)
{ {
if(prev != next){
clear_bit(cpu, &prev->cpu_vm_mask);
set_bit(cpu, &next->cpu_vm_mask);
if(next != &init_mm)
CHOOSE_MODE((void) 0,
switch_mm_skas(next->context.skas.mm_fd));
}
} }
static inline void enter_lazy_tlb(struct mm_struct *mm, static inline void enter_lazy_tlb(struct mm_struct *mm,
...@@ -22,4 +35,38 @@ static inline void enter_lazy_tlb(struct mm_struct *mm, ...@@ -22,4 +35,38 @@ static inline void enter_lazy_tlb(struct mm_struct *mm,
{ {
} }
extern int init_new_context_skas(struct task_struct *task,
struct mm_struct *mm);
static inline int init_new_context_tt(struct task_struct *task,
struct mm_struct *mm)
{
return(0);
}
static inline int init_new_context(struct task_struct *task,
struct mm_struct *mm)
{
return(CHOOSE_MODE_PROC(init_new_context_tt, init_new_context_skas,
task, mm));
}
extern void destroy_context_skas(struct mm_struct *mm);
static inline void destroy_context(struct mm_struct *mm)
{
CHOOSE_MODE((void) 0, destroy_context_skas(mm));
}
#endif #endif
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
...@@ -18,6 +18,8 @@ struct page; ...@@ -18,6 +18,8 @@ struct page;
#undef PAGE_OFFSET #undef PAGE_OFFSET
#undef KERNELBASE #undef KERNELBASE
extern unsigned long uml_physmem;
#define PAGE_OFFSET (uml_physmem) #define PAGE_OFFSET (uml_physmem)
#define KERNELBASE PAGE_OFFSET #define KERNELBASE PAGE_OFFSET
......
...@@ -12,9 +12,9 @@ struct task_struct; ...@@ -12,9 +12,9 @@ struct task_struct;
#include "linux/config.h" #include "linux/config.h"
#include "linux/signal.h" #include "linux/signal.h"
#include "asm/segment.h"
#include "asm/ptrace.h" #include "asm/ptrace.h"
#include "asm/siginfo.h" #include "asm/siginfo.h"
#include "choose-mode.h"
struct mm_struct; struct mm_struct;
...@@ -22,9 +22,24 @@ struct mm_struct; ...@@ -22,9 +22,24 @@ struct mm_struct;
#define cpu_relax() do ; while (0) #define cpu_relax() do ; while (0)
struct thread_struct { #ifdef CONFIG_MODE_TT
struct proc_tt_mode {
int extern_pid; int extern_pid;
int tracing; int tracing;
int switch_pipe[2];
int singlestep_syscall;
int vm_seq;
};
#endif
#ifdef CONFIG_MODE_SKAS
struct proc_skas_mode {
void *switch_buf;
void *fork_buf;
};
#endif
struct thread_struct {
int forking; int forking;
unsigned long kernel_stack; unsigned long kernel_stack;
int nsyscalls; int nsyscalls;
...@@ -33,13 +48,18 @@ struct thread_struct { ...@@ -33,13 +48,18 @@ struct thread_struct {
int err; int err;
void *fault_addr; void *fault_addr;
void *fault_catcher; void *fault_catcher;
int vm_seq;
struct task_struct *prev_sched; struct task_struct *prev_sched;
unsigned long temp_stack; unsigned long temp_stack;
int switch_pipe[2]; void *exec_buf;
void *jmp;
struct arch_thread arch; struct arch_thread arch;
int singlestep_syscall; union {
#ifdef CONFIG_MODE_TT
struct proc_tt_mode tt;
#endif
#ifdef CONFIG_MODE_SKAS
struct proc_skas_mode skas;
#endif
} mode;
struct { struct {
int op; int op;
union { union {
...@@ -60,8 +80,6 @@ struct thread_struct { ...@@ -60,8 +80,6 @@ struct thread_struct {
#define INIT_THREAD \ #define INIT_THREAD \
{ \ { \
extern_pid: -1, \
tracing: 0, \
forking: 0, \ forking: 0, \
kernel_stack: 0, \ kernel_stack: 0, \
nsyscalls: 0, \ nsyscalls: 0, \
...@@ -69,13 +87,10 @@ struct thread_struct { ...@@ -69,13 +87,10 @@ struct thread_struct {
cr2: 0, \ cr2: 0, \
err: 0, \ err: 0, \
fault_addr: NULL, \ fault_addr: NULL, \
vm_seq: 0, \
prev_sched: NULL, \ prev_sched: NULL, \
temp_stack: 0, \ temp_stack: 0, \
switch_pipe: { -1, -1 }, \ exec_buf: NULL, \
jmp: NULL, \
arch: INIT_ARCH_THREAD, \ arch: INIT_ARCH_THREAD, \
singlestep_syscall: 0, \
request: { 0 } \ request: { 0 } \
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include "linux/config.h"
#include "skas_ptrace.h"
#include "asm/current.h" #include "asm/current.h"
#define pt_regs pt_regs_subarch #define pt_regs pt_regs_subarch
......
/* /*
* Copyright (C) 2000 Jeff Dike (jdike@karaya.com) * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL * Licensed under the GPL
*/ */
#ifndef __UM_UACCESS_H #ifndef __UM_UACCESS_H
#define __UM_UACCESS_H #define __UM_UACCESS_H
#include "linux/string.h"
#include "linux/sched.h"
#include "asm/processor.h"
#include "asm/errno.h"
#include "asm/current.h"
#include "asm/a.out.h"
#define VERIFY_READ 0 #define VERIFY_READ 0
#define VERIFY_WRITE 1 #define VERIFY_WRITE 1
...@@ -26,8 +19,6 @@ ...@@ -26,8 +19,6 @@
#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
#define ABOVE_KMEM (16 * 1024 * 1024)
#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
#define USER_DS MAKE_MM_SEG(TASK_SIZE) #define USER_DS MAKE_MM_SEG(TASK_SIZE)
...@@ -35,56 +26,12 @@ ...@@ -35,56 +26,12 @@
#define get_fs() (current_thread_info()->addr_limit) #define get_fs() (current_thread_info()->addr_limit)
#define set_fs(x) (current_thread_info()->addr_limit = (x)) #define set_fs(x) (current_thread_info()->addr_limit = (x))
extern unsigned long end_vm;
extern unsigned long uml_physmem;
#define under_task_size(addr, size) \
(((unsigned long) (addr) < TASK_SIZE) && \
(((unsigned long) (addr) + (size)) < TASK_SIZE))
#define is_stack(addr, size) \
(((unsigned long) (addr) < STACK_TOP) && \
((unsigned long) (addr) >= STACK_TOP - ABOVE_KMEM) && \
(((unsigned long) (addr) + (size)) <= STACK_TOP))
#define segment_eq(a, b) ((a).seg == (b).seg) #define segment_eq(a, b) ((a).seg == (b).seg)
#define access_ok(type, addr, size) \ #include "um_uaccess.h"
((type == VERIFY_READ) || (segment_eq(get_fs(), KERNEL_DS)) || \
(((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) && \
(under_task_size(addr, size) || is_stack(addr, size))))
static inline int verify_area(int type, const void * addr, unsigned long size)
{
return(access_ok(type, addr, size) ? 0 : -EFAULT);
}
extern unsigned long get_fault_addr(void);
extern int __do_copy_from_user(void *to, const void *from, int n,
void **fault_addr, void **fault_catcher);
static inline int copy_from_user(void *to, const void *from, int n)
{
return(access_ok(VERIFY_READ, from, n) ?
__do_copy_from_user(to, from, n,
&current->thread.fault_addr,
&current->thread.fault_catcher) : n);
}
#define __copy_from_user(to, from, n) copy_from_user(to, from, n) #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
extern int __do_copy_to_user(void *to, const void *from, int n,
void **fault_addr, void **fault_catcher);
static inline int copy_to_user(void *to, const void *from, int n)
{
return(access_ok(VERIFY_WRITE, to, n) ?
__do_copy_to_user(to, from, n,
&current->thread.fault_addr,
&current->thread.fault_catcher) : n);
}
#define __copy_to_user(to, from, n) copy_to_user(to, from, n) #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
#define __get_user(x, ptr) \ #define __get_user(x, ptr) \
...@@ -128,49 +75,6 @@ static inline int copy_to_user(void *to, const void *from, int n) ...@@ -128,49 +75,6 @@ static inline int copy_to_user(void *to, const void *from, int n)
__put_user(x, private_ptr) : -EFAULT); \ __put_user(x, private_ptr) : -EFAULT); \
}) })
extern int __do_strncpy_from_user(char *dst, const char *src, size_t n,
void **fault_addr, void **fault_catcher);
static inline int strncpy_from_user(char *dst, const char *src, int count)
{
int n;
if(!access_ok(VERIFY_READ, src, 1)) return(-EFAULT);
n = __do_strncpy_from_user(dst, src, count,
&current->thread.fault_addr,
&current->thread.fault_catcher);
if(n < 0) return(-EFAULT);
return(n);
}
extern int __do_clear_user(void *mem, size_t len, void **fault_addr,
void **fault_catcher);
static inline int __clear_user(void *mem, int len)
{
return(__do_clear_user(mem, len,
&current->thread.fault_addr,
&current->thread.fault_catcher));
}
static inline int clear_user(void *mem, int len)
{
return(access_ok(VERIFY_WRITE, mem, len) ?
__do_clear_user(mem, len,
&current->thread.fault_addr,
&current->thread.fault_catcher) : len);
}
extern int __do_strnlen_user(const char *str, unsigned long n,
void **fault_addr, void **fault_catcher);
static inline int strnlen_user(void *str, int len)
{
return(__do_strnlen_user(str, len,
&current->thread.fault_addr,
&current->thread.fault_catcher));
}
#define strlen_user(str) strnlen_user(str, ~0UL >> 1) #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
struct exception_table_entry struct exception_table_entry
......
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