Commit 46228a2b authored by Jeff Dike's avatar Jeff Dike

Merged most of the rest of the skas changes.

parent 721c1865
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
ARCH_DIR = arch/um
OS := $(shell uname -s)
......@@ -11,27 +16,20 @@ include/linux/version.h: arch/$(ARCH)/Makefile
# EXTRAVERSION...
MODLIB := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
MAKEBOOT = $(MAKE) -C $(ARCH_DIR)/boot
ifeq ($(CONFIG_DEBUGSYM),y)
DEBUG = -g
CFLAGS := $(subst -fomit-frame-pointer,,$(CFLAGS))
endif
ifeq ($(CONFIG_GCOV),y)
CFLAGS += -fprofile-arcs -ftest-coverage
endif
ifeq ($(CONFIG_GPROF), y)
PROFILE += -pg -DPROFILING
LINK_PROFILE = $(PROFILE) -Wl,--wrap,__monstartup
endif
CFLAGS-$(CONFIG_DEBUGSYM) += -g
CFLAGS-$(CONFIG_GCOV) += -fprofile-arcs -ftest-coverage
CFLAGS-$(CONFIG_GPROF) += $(PROFILE)
LINK-$(CONFIG_GPROF) += $(PROFILE) -Wl,--wrap,__monstartup
core-y += $(ARCH_DIR)/kernel/ \
$(ARCH_DIR)/drivers/ \
$(ARCH_DIR)/sys-$(SUBARCH)/
ARCH_INCLUDE = $(ARCH_DIR)/include
ARCH_INCLUDE = -I$(ARCH_DIR)/include
MODE_INCLUDE = -I$(ARCH_DIR)/kernel/tt/include \
-I$(ARCH_DIR)/kernel/skas/include
......@@ -40,8 +38,8 @@ MODE_INCLUDE = -I$(ARCH_DIR)/kernel/tt/include \
# in CFLAGS. Otherwise, it would cause ld to complain about the two different
# errnos.
CFLAGS += $(DEBUG) $(PROFILE) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
-D_LARGEFILE64_SOURCE -I$(ARCH_INCLUDE) -Derrno=kernel_errno \
CFLAGS += $(CFLAGS-y) -D__arch_um__ -DSUBARCH=\"$(SUBARCH)\" \
-D_LARGEFILE64_SOURCE $(ARCH_INCLUDE) -Derrno=kernel_errno \
$(MODE_INCLUDE)
LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
......@@ -55,7 +53,13 @@ SYMLINK_HEADERS = include/asm-um/archparam.h include/asm-um/system.h \
ARCH_SYMLINKS = include/asm-um/arch $(ARCH_DIR)/include/sysdep $(ARCH_DIR)/os \
$(SYMLINK_HEADERS) $(ARCH_DIR)/include/uml-config.h
GEN_HEADERS = $(ARCH_DIR)/include/task.h
ifeq ($(CONFIG_MODE_SKAS), y)
GEN_HEADERS = $(ARCH_DIR)/kernel/skas/include/skas_ptregs.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-os-$(OS)
......@@ -63,9 +67,9 @@ include $(ARCH_DIR)/Makefile-os-$(OS)
$(ARCH_DIR)/vmlinux.lds.S :
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
......@@ -76,18 +80,20 @@ AFLAGS_uml.lds.o = -U$(SUBARCH) -DSTART=$$(($(TOP_ADDR) - $(SIZE))) \
-DELF_ARCH=$(ELF_ARCH) -DELF_FORMAT=\"$(ELF_FORMAT)\" -P -C -Uum
linux: $(ARCH_DIR)/uml.lds.s vmlinux
$(CC) -Wl,-T,$(ARCH_DIR)/uml.lds.s -o $@ $(LINK_PROFILE) \
$(LINK_WRAPS) -static vmlinux -L/usr/lib -lutil
$(CC) -Wl,-T,$(ARCH_DIR)/uml.lds.s -static $(LINK-y) $(LINK_WRAPS) \
-o linux $(ARCH_DIR)/main.o vmlinux -L/usr/lib -lutil
USER_CFLAGS := $(patsubst -I%,,$(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
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
$(CC) $(USER_CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
......@@ -108,7 +114,6 @@ archclean: sysclean
find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
-o -name '*.gcov' \) -type f -print | xargs rm -f
rm -f linux x.i gmon.out $(ARCH_DIR)/link.ld $(GEN_HEADERS)
@$(MAKEBOOT) clean
archdep:
for d in $(ARCH_SUBDIRS); do $(MAKE) -C $$d fastdep; done
......@@ -133,9 +138,16 @@ $(ARCH_DIR)/include/uml-config.h :
$(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
@$(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
......@@ -27,7 +27,7 @@ $(SYS_DIR)/thread.h: $(SYS_UTIL_DIR)/mk_thread
$(SYS_UTIL_DIR)/mk_sc: FORCE ;
@$(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),$@)
$(SYS_UTIL_DIR): include/asm FORCE
......
......@@ -19,6 +19,8 @@
#include "user.h"
#include "helper.h"
#include "os.h"
#include "choose-mode.h"
#include "mode.h"
void generic_close(int fd, void *unused)
{
......@@ -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)
{
struct winch_data data;
......@@ -212,9 +188,8 @@ void register_winch(int fd, void *device_data)
if(!isatty(fd)) return;
pid = tcgetpgrp(fd);
if(pid == tracing_pid)
register_winch_irq(tracer_winch[0], fd, -1, device_data);
else if(pid == -1){
if(!CHOOSE_MODE(is_tracer_winch(pid, fd, device_data), 0) &&
(pid == -1)){
thread = winch_tramp(fd, device_data, &thread_fd);
if(fd != -1){
register_winch_irq(thread_fd, fd, thread, device_data);
......
......@@ -105,7 +105,7 @@ int pty_open(int input, int output, int primary, void *d)
if(fd < 0) return(-errno);
info.fd = fd;
tracing_cb(grantpt_cb, &info);
initial_thread_cb(grantpt_cb, &info);
unlockpt(fd);
if(data->raw) raw(fd, 0);
......
......@@ -15,23 +15,27 @@ extern char *gdb_init;
extern int kmalloc_ok;
extern int timer_irq_inited;
extern int jail;
extern int nsyscalls;
extern struct task_struct *idle_threads[NR_CPUS];
#define ROUND_DOWN(addr) ((void *)(((unsigned long) addr) & PAGE_MASK))
#define ROUND_UP(addr) ROUND_DOWN(((unsigned long) addr) + PAGE_SIZE - 1)
#define UML_ROUND_DOWN(addr) ((void *)(((unsigned long) addr) & PAGE_MASK))
#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 unsigned long stack_sp(unsigned long page);
extern int kernel_thread_proc(void *data);
extern void syscall_segv(int sig);
extern int current_pid(void);
extern void set_init_pid(int pid);
extern unsigned long alloc_stack(int order, int atomic);
extern int do_signal(int error);
extern int is_stack_fault(unsigned long sp);
extern unsigned long segv(unsigned long address, unsigned long ip,
int is_write, int is_user, void *sc_ptr);
extern int set_user_mode(void *task);
int is_write, int is_user, void *sc);
extern unsigned long 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 set_tracing(void *t, int tracing);
extern int is_tracing(void *task);
......@@ -40,7 +44,6 @@ extern void kern_finish_exec(void *task, int new_pid, unsigned long stack);
extern int page_size(void);
extern int page_mask(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 add_input_request(int op, void (*proc)(int), void *arg);
extern int sys_execve(char *file, char **argv, char **env);
......@@ -57,7 +60,6 @@ extern int next_trap_index(int max);
extern void default_idle(void);
extern void finish_fork(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 *syscall_sp(void *t);
extern void syscall_trace(void);
......@@ -68,9 +70,7 @@ extern int external_pid(void *t);
extern int pid_to_processor_id(int pid);
extern void boot_timer_handler(int sig);
extern void interrupt_end(void);
extern void tracing_reboot(void);
extern void tracing_halt(void);
extern void tracing_cb(void (*proc)(void *), void *arg);
extern void initial_thread_cb(void (*proc)(void *), void *arg);
extern int debugger_signal(int status, int pid);
extern void debugger_parent_signal(int status, int pid);
extern void child_signal(int pid, int status);
......@@ -78,25 +78,19 @@ extern int init_ptrace_proxy(int idle_pid, int startup, int stop);
extern int init_parent_proxy(int pid);
extern void check_stack_overflow(void *ptr);
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 int user_context(unsigned long sp);
extern void timer_irq(struct uml_pt_regs *regs);
extern void unprotect_stack(unsigned long stack);
extern void do_uml_exitcalls(void);
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 int config_gdb(char *str);
extern int remove_gdb(void);
extern char *uml_strdup(char *string);
extern void unprotect_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_task_sizes(int arg);
extern void uml_cleanup(void);
extern int pid_to_processor_id(int pid);
extern void set_current(void *t);
......@@ -107,7 +101,6 @@ extern void *get_init_task(void);
extern int clear_user_proc(void *buf, 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 void set_thread_sc(void *sc);
extern void bus_handler(int sig, struct uml_pt_regs *regs);
extern long execute_syscall(void *r);
extern int smp_sigio_handler(void);
......@@ -116,7 +109,6 @@ extern struct task_struct *get_task(int pid, int require);
extern void machine_halt(void);
extern int is_syscall(unsigned long addr);
extern void arch_switch(void);
extern int is_valid_pid(int pid);
extern void free_irq(unsigned int, void *);
extern int um_in_interrupt(void);
extern int cpu(void);
......
......@@ -54,11 +54,6 @@ extern int create_mem_file(unsigned long len);
extern void setup_range(int fd, char *driver, unsigned long start,
unsigned long pfn, unsigned long total, int need_vm,
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 unsigned long find_iomem(char *driver, unsigned long *len_out);
extern int init_maps(struct mem_region *region);
......@@ -68,10 +63,15 @@ extern unsigned long get_vm(unsigned long len);
extern void setup_physmem(unsigned long start, unsigned long usable,
unsigned long len);
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 unsigned long phys_offset(unsigned long phys);
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
......
/*
* Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __SYSCALL_USER_H__
#define __SYSCALL_USER_H__
#ifndef __SYSCALL_USER_H
#define __SYSCALL_USER_H
#include <asm/sigcontext.h>
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 record_syscall_start(int syscall);
extern void record_syscall_end(int index, int result);
#endif
......
/*
* Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __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 {
unsigned long args[6];
long syscall;
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 { \
syscall : -1, \
args : { [0 ... 5] = 0 }, \
is_user : 0, \
sc : NULL }
#define UPT_IP(regs) SC_IP((regs)->sc)
#define UPT_SP(regs) SC_SP((regs)->sc)
#define UPT_EFLAGS(regs) SC_EFLAGS((regs)->sc)
#define UPT_EAX(regs) SC_EAX((regs)->sc)
#define UPT_EBX(regs) SC_EBX((regs)->sc)
#define UPT_ECX(regs) SC_ECX((regs)->sc)
#define UPT_EDX(regs) SC_EDX((regs)->sc)
#define UPT_ESI(regs) SC_ESI((regs)->sc)
#define UPT_EDI(regs) SC_EDI((regs)->sc)
#define UPT_EBP(regs) SC_EBP((regs)->sc)
#define UPT_ORIG_EAX(regs) ((regs)->syscall)
#define UPT_CS(regs) SC_CS((regs)->sc)
#define UPT_SS(regs) SC_SS((regs)->sc)
#define UPT_DS(regs) SC_DS((regs)->sc)
#define UPT_ES(regs) SC_ES((regs)->sc)
#define UPT_FS(regs) SC_FS((regs)->sc)
#define UPT_GS(regs) SC_GS((regs)->sc)
#define UPT_SC(regs) ((regs)->sc)
is_user : 0 }
extern int mode_tt;
#define UPT_IP(r) \
CHOOSE_MODE(SC_IP((r)->mode.tt), REGS_IP((r)->mode.skas.regs))
#define UPT_SP(r) \
CHOOSE_MODE(SC_SP((r)->mode.tt), REGS_SP((r)->mode.skas.regs))
#define UPT_EFLAGS(r) \
CHOOSE_MODE(SC_EFLAGS((r)->mode.tt), REGS_EFLAGS((r)->mode.skas.regs))
#define UPT_EAX(r) \
CHOOSE_MODE(SC_EAX((r)->mode.tt), REGS_EAX((r)->mode.skas.regs))
#define UPT_EBX(r) \
CHOOSE_MODE(SC_EBX((r)->mode.tt), REGS_EBX((r)->mode.skas.regs))
#define UPT_ECX(r) \
CHOOSE_MODE(SC_ECX((r)->mode.tt), REGS_ECX((r)->mode.skas.regs))
#define UPT_EDX(r) \
CHOOSE_MODE(SC_EDX((r)->mode.tt), REGS_EDX((r)->mode.skas.regs))
#define UPT_ESI(r) \
CHOOSE_MODE(SC_ESI((r)->mode.tt), REGS_ESI((r)->mode.skas.regs))
#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) \
({ unsigned long val; \
......@@ -94,12 +128,29 @@ struct uml_pt_regs {
} \
} while (0)
#define UPT_SET_SYSCALL_RETURN(regs, res) \
SC_SET_SYSCALL_RETURN((regs)->sc, (res))
#define UPT_RESTART_SYSCALL(regs) SC_RESTART_SYSCALL((regs)->sc)
#define UPT_ORIG_SYSCALL(regs) UPT_EAX(regs)
#define UPT_SYSCALL_NR(regs) ((regs)->syscall)
#define UPT_SYSCALL_RET(regs) UPT_EAX(regs)
#define UPT_SET_SYSCALL_RETURN(r, res) \
CHOOSE_MODE(SC_SET_SYSCALL_RETURN((r)->mode.tt, (res)), \
REGS_SET_SYSCALL_RETURN((r)->mode.skas.regs, (res)))
#define UPT_RESTART_SYSCALL(r) \
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
......
......@@ -6,13 +6,22 @@
#ifndef __SYS_SIGCONTEXT_I386_H
#define __SYS_SIGCONTEXT_I386_H
#include "sc.h"
#define IP_RESTART_SYSCALL(ip) ((ip) -= 2)
#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_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
* -ENOSYS, so this makes it so.
......@@ -20,10 +29,12 @@
#define SC_START_SYSCALL(sc) do SC_EAX(sc) = -ENOSYS; while(0)
/* 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,
unsigned long syscall)
{
......@@ -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[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 int sc_get_fpregs(unsigned long buf, void *sc_ptr);
......
......@@ -23,6 +23,13 @@ struct cpu_task {
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 high_physmem;
extern unsigned long uml_physmem;
......@@ -31,16 +38,11 @@ extern unsigned long end_vm;
extern unsigned long start_vm;
extern unsigned long highmem;
extern int tracing_pid;
extern int honeypot;
extern char host_info[];
extern char saved_command_line[];
extern char command_line[];
extern int gdb_pid;
extern char *tempdir;
extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end;
......@@ -53,12 +55,10 @@ extern int pty_close_sigio;
extern void stop(void);
extern void stack_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 void *add_signal_handler(int sig, void (*handler)(int));
extern int start_fork_tramp(void *arg, unsigned long temp_stack,
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 linux_main(int argc, char **argv);
extern void remap_data(void *segment_start, void *segment_end, int w);
......@@ -71,13 +71,13 @@ extern int switcheroo(int fd, int prot, void *from, void *to, int size);
extern void setup_machinename(char *machine_out);
extern void setup_hostinfo(void);
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 init_new_thread_signals(int altstack);
extern void attach_process(int pid);
extern int fork_tramp(void *sig_stack);
extern void do_exec(int old_pid, int new_pid);
extern void tracer_panic(char *msg, ...);
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 int detach(int pid, int sig);
extern int attach(int pid);
......@@ -91,6 +91,7 @@ extern void arch_check_bugs(void);
extern int arch_handle_signal(int sig, struct uml_pt_regs *regs);
extern int arch_fixup(unsigned long address, void *sc_ptr);
extern void forward_pending_sigio(int target);
extern int can_do_skas(void);
#endif
......
......@@ -19,7 +19,7 @@ obj-$(CONFIG_GCOV) += gmon_syms.o
obj-$(CONFIG_TTY_LOG) += tty_log.o
obj-$(CONFIG_MODE_TT) += tt/
obj-$(CONFIG_MODE_SKAS) += tt/
obj-$(CONFIG_MODE_SKAS) += skas/
user-objs-$(CONFIG_TTY_LOG) += tty_log.o
......@@ -28,7 +28,7 @@ user-objs-$(CONFIG_TTY_LOG) += tty_log.o
USER_OBJS := $(filter %_user.o,$(obj-y)) $(user-objs-y) config.o helper.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))
UNMAP_CFLAGS := $(patsubst -pg -DPROFILING,,$(USER_CFLAGS))
UNMAP_CFLAGS := $(patsubst -fprofile-arcs -ftest-coverage,,$(UNMAP_CFLAGS))
......@@ -51,24 +51,24 @@ include $(TOPDIR)/Rules.make
$(USER_OBJS) : %.o: %.c
$(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 $@ $<
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
# This has to be separate because it needs be compiled with frame pointers
# 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 $@ $<
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
$(PERL) -e $(QUOTE) < arch/um/kernel/config.c.in > $@
$(obj)/config.c : $(src)/config.c.in $(TOPDIR)/.config
$(PERL) -e $(QUOTE) < $(src)/config.c.in > $@
arch/um/kernel/config.o : arch/um/kernel/config.c
$(obj)/config.o : $(obj)/config.c
clean:
rm -f config.c
......
......@@ -18,65 +18,17 @@
#include "2_5compat.h"
#include "os.h"
#include "time_user.h"
/* See comment above fork_tramp for why sigstop is defined and used like
* 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);
}
#include "choose-mode.h"
#include "mode_kern.h"
void flush_thread(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(uml_reserved, high_physmem - uml_reserved, 1, 1, 0, 1);
task_protections((unsigned long) current->thread_info);
force_flush_all();
unblock_signals();
CHOOSE_MODE(flush_thread_tt(), flush_thread_skas());
}
void start_thread(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);
CHOOSE_MODE_PROC(start_thread_tt, start_thread_skas, regs, eip, esp);
}
static int execve1(char *file, char **argv, char **env)
......
......@@ -43,7 +43,7 @@ int setup_signal_stack_si(unsigned long stack_top, int sig,
if(restorer == NULL)
panic("setup_signal_stack_si - no restorer");
if(copy_sc_to_user((void *) sc, regs->regs.sc,
if(copy_sc_to_user((void *) sc, regs->regs.mode.tt,
&signal_frame_sc.arch) ||
copy_to_user((void *) start, signal_frame_si.common.data,
signal_frame_si.common.len) ||
......@@ -86,7 +86,8 @@ int setup_signal_stack_sc(unsigned long stack_top, int sig,
if(copy_to_user((void *) start, frame->data, frame->len) ||
copy_to_user((void *) (start + frame->sig_index), &sig,
sizeof(sig)) ||
copy_sc_to_user(user_sc, regs->regs.sc, &signal_frame_sc.arch) ||
copy_sc_to_user(user_sc, regs->regs.mode.tt,
&signal_frame_sc.arch) ||
copy_to_user(sc_sigmask(user_sc), mask, sizeof(mask->sig[0])) ||
copy_to_user((void *) sigs, &mask->sig[1], sig_size) ||
copy_restorer(restorer, start, frame->sr_index, frame->sr_relative))
......
......@@ -47,7 +47,7 @@ struct task_struct *alloc_task_struct(void){
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)
......
/*
* Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include "linux/config.h"
#include "linux/module.h"
#include "linux/string.h"
......@@ -19,17 +24,13 @@
EXPORT_SYMBOL(stop);
EXPORT_SYMBOL(uml_physmem);
EXPORT_SYMBOL(set_signals);
EXPORT_SYMBOL(get_signals);
EXPORT_SYMBOL(kernel_thread);
EXPORT_SYMBOL(__const_udelay);
EXPORT_SYMBOL(__udelay);
EXPORT_SYMBOL(sys_waitpid);
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(__do_clear_user);
EXPORT_SYMBOL(honeypot);
EXPORT_SYMBOL(host_task_size);
EXPORT_SYMBOL(arch_validate);
......@@ -37,10 +38,10 @@ EXPORT_SYMBOL(region_pa);
EXPORT_SYMBOL(region_va);
EXPORT_SYMBOL(phys_mem_map);
EXPORT_SYMBOL(page_mem_map);
EXPORT_SYMBOL(get_signals);
EXPORT_SYMBOL(page_to_phys);
EXPORT_SYMBOL(phys_to_page);
EXPORT_SYMBOL(high_physmem);
EXPORT_SYMBOL(empty_zero_page);
EXPORT_SYMBOL(os_open_file);
EXPORT_SYMBOL(os_read_file);
......@@ -53,7 +54,6 @@ EXPORT_SYMBOL(helper_wait);
EXPORT_SYMBOL(os_shutdown_socket);
EXPORT_SYMBOL(os_connect_socket);
EXPORT_SYMBOL(run_helper);
EXPORT_SYMBOL(tracing_pid);
EXPORT_SYMBOL(start_thread);
EXPORT_SYMBOL(dump_thread);
......@@ -75,6 +75,7 @@ EXPORT_SYMBOL_NOVERS(__write_lock_failed);
extern void FASTCALL( __read_lock_failed(rwlock_t *rw));
EXPORT_SYMBOL_NOVERS(__read_lock_failed);
EXPORT_SYMBOL(smp_num_cpus);
#endif
#ifdef CONFIG_HIGHMEM
......
......@@ -25,6 +25,8 @@
#include "mem.h"
#include "kern.h"
#include "init.h"
#include "os.h"
#include "mode_kern.h"
/* Changed during early boot */
pgd_t swapper_pg_dir[1024];
......@@ -56,12 +58,12 @@ static unsigned long brk_end;
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)
{
unmap((void *) brk_end, uml_reserved - brk_end);
os_unmap_memory((void *) brk_end, uml_reserved - brk_end);
}
extern char __binary_start;
......@@ -81,16 +83,16 @@ void mem_init(void)
/* Map in the area just after the brk now that kmalloc is about
* to be turned on.
*/
brk_end = (unsigned long) ROUND_UP(sbrk(0));
brk_end = (unsigned long) UML_ROUND_UP(sbrk(0));
map_cb(NULL);
tracing_cb(map_cb, NULL);
initial_thread_cb(map_cb, NULL);
free_bootmem(__pa(brk_end), uml_reserved - brk_end);
uml_reserved = brk_end;
/* Fill in any hole at the start of the binary */
start = (unsigned long) &__binary_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);
}
......@@ -106,6 +108,21 @@ void mem_init(void)
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
/* Changed during early boot */
pte_t *kmap_pte;
......@@ -379,20 +396,6 @@ void show_mem(void)
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)
{
char *retptr;
......@@ -513,7 +516,7 @@ unsigned long get_vm(unsigned long len)
return(0);
found:
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);
if(err) return(0);
return(start);
......@@ -562,7 +565,7 @@ struct iomem iomem_regions[NREGIONS] = { [ 0 ... NREGIONS - 1 ] =
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]))
return;
......
......@@ -181,41 +181,19 @@ void log(char *fmt, ...)
}
#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)
{
struct mem_region *region;
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;
struct mem_region *region = phys_region(phys);
err = munmap(addr, len);
if(err < 0) return(-errno);
else return(err);
return(os_map_memory((void *) virt, region->fd, phys_offset(phys), len,
r, w, x));
}
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 prot;
prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
(x ? PROT_EXEC : 0);
if(mprotect((void *) addr, len, prot) == -1){
if(os_protect_memory((void *) addr, len, r, w, x) < 0){
if(must_succeed)
panic("protect failed, errno = %d", errno);
else return(-errno);
......
......@@ -21,9 +21,6 @@
#include <asm/sigcontext.h>
#include <asm/unistd.h>
#include <asm/page.h>
#ifdef PROFILING
#include <sys/gmon.h>
#endif
#include "user_util.h"
#include "kern_util.h"
#include "user.h"
......@@ -33,13 +30,18 @@
#include "sysdep/ptrace.h"
#include "sysdep/sigcontext.h"
#include "irq_user.h"
#include "syscall_user.h"
#include "ptrace_user.h"
#include "time_user.h"
#include "init.h"
#include "os.h"
#include "uml-config.h"
#include "choose-mode.h"
#include "mode.h"
#ifdef CONFIG_MODE_SKAS
#include "skas_ptrace.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;
......@@ -47,6 +49,13 @@ void init_new_thread(void *sig_stack, void (*usr1_handler)(int))
set_sigstack(sig_stack, 2 * page_size());
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,
SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1);
set_handler(SIGTRAP, (__sighandler_t) sig_handler, flags,
......@@ -61,11 +70,10 @@ void init_new_thread(void *sig_stack, void (*usr1_handler)(int))
SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1);
set_handler(SIGUSR2, (__sighandler_t) sig_handler,
SA_NOMASK | flags, -1);
if(usr1_handler) set_handler(SIGUSR1, usr1_handler, flags, -1);
signal(SIGCHLD, SIG_IGN);
(void) CHOOSE_MODE(signal(SIGCHLD, SIG_IGN), (void *) 0);
signal(SIGHUP, SIG_IGN);
init_irq_signals(sig_stack != NULL);
init_irq_signals(altstack);
}
struct tramp {
......@@ -128,26 +136,6 @@ void trace_myself(void)
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)
{
char c;
......
This diff is collapsed.
......@@ -8,6 +8,8 @@
#include "kern_util.h"
#include "kern.h"
#include "os.h"
#include "mode.h"
#include "choose-mode.h"
#ifdef CONFIG_SMP
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++){
p = idle_threads[i];
if((p != NULL) && (p->thread.extern_pid != me))
os_kill_process(p->thread.extern_pid, 0);
if((p != NULL) && (p->thread.mode.tt.extern_pid != me))
os_kill_process(p->thread.mode.tt.extern_pid, 0);
}
}
#endif
static void kill_off_processes(void)
{
struct task_struct *p;
int me;
me = os_getpid();
for_each_process(p){
if(p->thread.extern_pid != me)
os_kill_process(p->thread.extern_pid, 0);
}
if(init_task.thread.extern_pid != me)
os_kill_process(init_task.thread.extern_pid, 0);
CHOOSE_MODE(kill_off_processes_tt(), kill_off_processes_skas());
#ifdef CONFIG_SMP
kill_idlers(me);
kill_idlers(os_getpid());
#endif
}
......@@ -50,16 +43,14 @@ void machine_restart(char * __unused)
{
do_uml_exitcalls();
kill_off_processes();
tracing_reboot();
os_kill_process(os_getpid(), 0);
CHOOSE_MODE(reboot_tt(), reboot_skas());
}
void machine_power_off(void)
{
do_uml_exitcalls();
kill_off_processes();
tracing_halt();
os_kill_process(os_getpid(), 0);
CHOOSE_MODE(halt_tt(), halt_skas());
}
void machine_halt(void)
......
......@@ -171,7 +171,7 @@ static int kern_do_signal(struct pt_regs *regs, sigset_t *oldset, int error)
*/
if((current->ptrace & PT_DTRACE) &&
is_syscall(PT_REGS_IP(&current->thread.regs)))
current->thread.singlestep_syscall = 1;
current->thread.mode.tt.singlestep_syscall = 1;
return(0);
}
......@@ -241,7 +241,7 @@ int sys_sigreturn(struct pt_regs regs)
sigdelsetmask(&current->blocked, ~_BLOCKABLE);
recalc_sigpending();
spin_unlock_irq(&current->sig->siglock);
copy_sc_from_user(current->thread.regs.regs.sc, sc,
copy_sc_from_user(current->thread.regs.regs.mode.tt, sc,
&signal_frame_sc.arch);
return(PT_REGS_SYSCALL_RET(&current->thread.regs));
}
......@@ -257,7 +257,7 @@ int sys_rt_sigreturn(struct pt_regs regs)
sigdelsetmask(&current->blocked, ~_BLOCKABLE);
recalc_sigpending();
spin_unlock_irq(&current->sig->siglock);
copy_sc_from_user(current->thread.regs.regs.sc, sc,
copy_sc_from_user(current->thread.regs.regs.mode.tt, sc,
&signal_frame_sc.arch);
return(PT_REGS_SYSCALL_RET(&current->thread.regs));
}
......
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
obj-y = exec_kern.o exec_user.o mem_user.o mmu.o process.o process_kern.o \
syscall_user.o trap_user.o
obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
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
*/
#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 mm_struct *mm, 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 thread_struct *thread);
#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
*/
#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:
*/
......@@ -407,8 +407,8 @@ long execute_syscall(void *r)
set_fs(USER_DS);
if(current->thread.singlestep_syscall){
current->thread.singlestep_syscall = 0;
if(current->thread.mode.tt.singlestep_syscall){
current->thread.mode.tt.singlestep_syscall = 0;
current->ptrace &= ~PT_DTRACE;
force_sig(SIGTRAP, current);
}
......
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
/* XXX FIXME : Ensure that SIGIO and SIGVTALRM can't happen immediately
* after setting up syscall stack
* block SIGVTALRM in any code that's under wait_for_stop
*/
#include <unistd.h>
#include <stdlib.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"
/* XXX Bogus */
#define ERESTARTSYS 512
#define ERESTARTNOINTR 513
#define ERESTARTNOHAND 514
#include "syscall_user.h"
struct {
int syscall;
......@@ -34,67 +16,24 @@ struct {
struct timeval end;
} syscall_record[1024];
void syscall_handler(int sig, struct uml_pt_regs *regs)
int record_syscall_start(int syscall)
{
void *sc;
long result;
int index, max, syscall;
int max, index;
max = sizeof(syscall_record)/sizeof(syscall_record[0]);
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].pid = current_pid();
syscall_record[index].result = 0xdeadbeef;
gettimeofday(&syscall_record[index].start, NULL);
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->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);
return(index);
}
int do_syscall(void *task, int pid)
void record_syscall_end(int index, int result)
{
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);
syscall_record[index].result = result;
gettimeofday(&syscall_record[index].end, NULL);
}
/*
......
......@@ -30,8 +30,8 @@ static void fix_range(struct mm_struct *mm, unsigned long start_addr,
unsigned long addr;
int r, w, x, err;
if((current->thread.extern_pid != -1) &&
(current->thread.extern_pid != os_getpid()))
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;
......@@ -60,23 +60,25 @@ static void fix_range(struct mm_struct *mm, unsigned long start_addr,
w = 0;
}
if(force || pte_newpage(*npte)){
err = unmap((void *) addr, PAGE_SIZE);
err = os_unmap_memory((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,
map_memory(addr,
pte_val(*npte) & PAGE_MASK,
PAGE_SIZE, r, w, x);
}
else if(pte_newprot(*npte)){
protect(addr, PAGE_SIZE, r, w, x, 1);
protect_memory(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);
err = os_unmap_memory((void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
......@@ -106,24 +108,26 @@ void flush_kernel_range(unsigned long start, unsigned long end, int update_seq)
pte = pte_offset_kernel(pmd, addr);
if(!pte_present(*pte) || pte_newpage(*pte)){
updated = 1;
err = unmap((void *) addr, PAGE_SIZE);
err = os_unmap_memory((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,
map_memory(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);
protect_memory(addr, PAGE_SIZE, 1, 1, 1, 1);
}
addr += PAGE_SIZE;
}
else {
if(pmd_newpage(*pmd)){
updated = 1;
err = unmap((void *) addr, PMD_SIZE);
err = os_unmap_memory((void *) addr, PMD_SIZE);
if(err < 0)
panic("munmap failed, errno = %d\n",
-err);
......@@ -143,7 +147,7 @@ static void protect_vm_page(unsigned long addr, int w, int must_succeed)
{
int err;
err = protect(addr, PAGE_SIZE, 1, w, 1, must_succeed);
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);
......@@ -207,8 +211,8 @@ void flush_tlb_mm(struct mm_struct *mm)
fix_range(mm, 0, STACK_TOP, 0);
seq = atomic_read(&vmchange_seq);
if(current->thread.vm_seq == seq) return;
current->thread.vm_seq = seq;
if(current->thread.mode.tt.vm_seq == seq) return;
current->thread.mode.tt.vm_seq = seq;
flush_kernel_range(start_vm, end_vm, 0);
}
......
......@@ -117,7 +117,7 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
if(catcher != NULL){
current->thread.fault_addr = (void *) address;
up_read(&mm->mmap_sem);
do_longjmp(catcher);
do_longjmp(catcher, 1);
}
else if(current->thread.fault_addr != NULL){
panic("fault_addr set but no fault catcher");
......@@ -161,7 +161,7 @@ void relay_signal(int sig, struct uml_pt_regs *regs)
void bus_handler(int sig, struct uml_pt_regs *regs)
{
if(current->thread.fault_catcher != NULL)
do_longjmp(current->thread.fault_catcher);
do_longjmp(current->thread.fault_catcher, 1);
else relay_signal(sig, regs);
}
......@@ -185,250 +185,6 @@ int next_trap_index(int limit)
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.
* Emacs will notice this stuff at the end of the file and automatically
......
This diff is collapsed.
......@@ -3,11 +3,17 @@
# Licensed under the GPL
#
O_TARGET = tt.o
obj-y = exec_kern.o exec_user.o
obj-y = exec_kern.o exec_user.o gdb.o gdb_kern.o mem.o process_kern.o \
syscall_user.o tracer.o
obj-$(CONFIG_PT_PROXY) += ptproxy/
USER_OBJS := $(filter %_user.o,$(obj-y)) gdb.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 :
......@@ -46,17 +46,17 @@ void flush_thread_tt(void)
do_exit(SIGKILL);
}
if(current->processor == 0)
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);
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);
task_protections((unsigned long) current->thread_info);
force_flush_all();
unblock_signals();
}
......
/*
* 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:
*/
/*
* 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 mm_struct *mm, 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 thread_struct *thread);
#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) 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:
*/
This diff is collapsed.
......@@ -34,6 +34,9 @@
#include "initrd.h"
#include "init.h"
#include "os.h"
#include "choose-mode.h"
#include "mode_kern.h"
#include "mode.h"
#define DEFAULT_COMMAND_LINE "root=6200"
......@@ -44,7 +47,7 @@ struct cpuinfo_um boot_cpu_data = {
unsigned long thread_saved_pc(struct task_struct *task)
{
return(os_process_pc(task->thread.extern_pid));
return(os_process_pc(task->thread.mode.tt.extern_pid));
}
static int show_cpuinfo(struct seq_file *m, void *v)
......@@ -93,28 +96,6 @@ pte_t * __bad_pagetable(void)
return(NULL);
}
extern void start_kernel(void);
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
......@@ -128,12 +109,7 @@ static int start_kernel_proc(void *unused)
unsigned long host_task_size;
unsigned long task_size;
void set_task_sizes(int arg)
{
/* Round up to the nearest 4M */
host_task_size = ROUND_4M((unsigned long) &arg);
task_size = START;
}
unsigned long uml_start;
/* Set in early boot */
unsigned long uml_physmem;
......@@ -156,7 +132,8 @@ long physmem_size = 32 * 1024 * 1024;
void set_cmdline(char *cmd)
{
char *umid, *ptr;
if(honeypot) return;
if(CHOOSE_MODE(honeypot, 0)) return;
umid = get_umid(1);
if(umid != NULL){
......@@ -268,6 +245,7 @@ static void __init uml_postsetup(void)
}
extern int debug_trace;
int mode_tt = 1;
/* Set during early boot */
unsigned long brk_start;
......@@ -280,7 +258,6 @@ int linux_main(int argc, char **argv)
unsigned long avail;
unsigned long virtmem_size, max_physmem;
unsigned int i, add, err;
void *sp;
for (i = 1; i < argc; i++){
if((i == 1) && (argv[i][0] == ' ')) continue;
......@@ -290,16 +267,14 @@ int linux_main(int argc, char **argv)
}
if(have_root == 0) add_arg(saved_command_line, DEFAULT_COMMAND_LINE);
if(!jail || debug)
remap_data(ROUND_DOWN(&_stext), ROUND_UP(&_etext), 1);
remap_data(ROUND_DOWN(&_sdata), ROUND_UP(&_edata), 1);
mode_tt = 1;
uml_start = CHOOSE_MODE_PROC(set_task_sizes_tt, set_task_sizes_skas, 0,
&host_task_size, &task_size);
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 */
uml_reserved = ROUND_4M(brk_start) + (1 << 22);
......@@ -334,8 +309,10 @@ int linux_main(int argc, char **argv)
virtmem_size);
err = reserve_vm(high_physmem, end_vm, &kernel_vm_reserved);
if(err)
tracer_panic("Failed to reserve VM area for kernel VM\n");
if(err){
printf("Failed to reserve VM area for kernel VM\n");
exit(1);
}
uml_postsetup();
......@@ -343,9 +320,8 @@ int linux_main(int argc, char **argv)
2 * PAGE_SIZE;
task_protections((unsigned long) &init_thread_info);
sp = (void *) init_task.thread.kernel_stack + 2 * PAGE_SIZE -
sizeof(unsigned long);
return(signals(start_kernel_proc, sp));
return(CHOOSE_MODE(start_uml_tt(), start_uml_skas()));
}
static int panic_exit(struct notifier_block *self, unsigned long unused1,
......
......@@ -17,6 +17,8 @@
#include "mem_user.h"
#include "user.h"
#include "init.h"
#include "mode.h"
#include "choose-mode.h"
/* Set in set_stklim, which is called from main and __wrap_malloc.
* __wrap_malloc only calls it if main hasn't started.
......@@ -97,9 +99,6 @@ int main(int argc, char **argv, char **envp)
new_argv[i] = argv[i - 1];
new_argv[argc + 1] = NULL;
#ifdef PROFILING
disable_profile_timer();
#endif
execvp(new_argv[0], new_argv);
perror("execing with extended args");
exit(1);
......@@ -108,7 +107,6 @@ int main(int argc, char **argv, char **envp)
linux_prog = argv[0];
set_stklim();
set_task_sizes(0);
if((new_argv = malloc((argc + 1) * sizeof(char *))) == NULL){
perror("Mallocing argv");
......@@ -136,60 +134,14 @@ int main(int argc, char **argv, char **envp)
return(uml_exitcode);
}
/* Changed in __wrap___monstartup and __wrap_malloc very early */
static int allocating_monbuf = 0;
#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
#define CAN_KMALLOC() \
(kmalloc_ok && CHOOSE_MODE((getpid() != tracing_pid), 1))
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)
{
if(allocating_monbuf){
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));
if(CAN_KMALLOC()) return(um_kmalloc(size));
else return(__real_malloc(size));
}
......@@ -206,11 +158,7 @@ extern void __real_free(void *);
void __wrap_free(void *ptr)
{
/* Could maybe unmap the gmon buffer, but we're just about to
* exit anyway
*/
if(ptr == gmon_buf) return;
if(kmalloc_ok) kfree(ptr);
if(CAN_KMALLOC()) kfree(ptr);
else __real_free(ptr);
}
......
......@@ -95,6 +95,41 @@ int os_getpid(void)
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.
* Emacs will notice this stuff at the end of the file and automatically
......
......@@ -35,7 +35,7 @@ int get_pty(void)
}
info.fd = fd;
tracing_cb(grantpt_cb, &info);
initial_thread_cb(grantpt_cb, &info);
if(info.res < 0){
printk("get_pty : Couldn't grant pty - errno = %d\n",
......
......@@ -102,7 +102,7 @@ void update_debugregs(int seq)
if(seq == debugregs_seq) return;
me = os_getpid();
tracing_cb(update_debugregs_cb, &me);
initial_thread_cb(update_debugregs_cb, &me);
}
/*
......
#include "linux/stddef.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 <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 *) "
"&(((char *) (task))[%d]))\n", debugreg());
return(0);
printf("\n");
printf("#endif\n");
}
EXTRA_TARGETS := mk_task mk_task_kern.o
EXTRA_TARGETS := mk_task mk_constants
include $(TOPDIR)/Rules.make
......@@ -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
$(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:
$(RM) $(EXTRA_TARGETS)
......
#ifndef __UM_A_OUT_H
#define __UM_A_OUT_H
#include "linux/config.h"
#include "asm/arch/a.out.h"
#include "choose-mode.h"
#undef STACK_TOP
......@@ -9,10 +11,10 @@ extern unsigned long stacksizelim;
extern unsigned long host_task_size;
extern int honeypot;
#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
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#ifndef __MMU_H
#define __MMU_H
#include "asm/arch/mmu.h"
#include "um_mmu.h"
#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
#define __UM_MMU_CONTEXT_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 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)
{
}
extern void switch_mm_skas(int mm_fd);
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
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,
......@@ -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
/*
* 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:
*/
......@@ -12,9 +12,9 @@ struct task_struct;
#include "linux/config.h"
#include "linux/signal.h"
#include "asm/segment.h"
#include "asm/ptrace.h"
#include "asm/siginfo.h"
#include "choose-mode.h"
struct mm_struct;
......@@ -22,8 +22,24 @@ struct mm_struct;
#define cpu_relax() do ; while (0)
struct thread_struct {
#ifdef CONFIG_MODE_TT
struct proc_tt_mode {
int extern_pid;
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 tracing;
int forking;
unsigned long kernel_stack;
......@@ -33,13 +49,18 @@ struct thread_struct {
int err;
void *fault_addr;
void *fault_catcher;
int vm_seq;
struct task_struct *prev_sched;
unsigned long temp_stack;
int switch_pipe[2];
void *jmp;
void *exec_buf;
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 {
int op;
union {
......@@ -60,8 +81,6 @@ struct thread_struct {
#define INIT_THREAD \
{ \
extern_pid: -1, \
tracing: 0, \
forking: 0, \
kernel_stack: 0, \
nsyscalls: 0, \
......@@ -69,13 +88,10 @@ struct thread_struct {
cr2: 0, \
err: 0, \
fault_addr: NULL, \
vm_seq: 0, \
prev_sched: NULL, \
temp_stack: 0, \
switch_pipe: { -1, -1 }, \
jmp: NULL, \
exec_buf: NULL, \
arch: INIT_ARCH_THREAD, \
singlestep_syscall: 0, \
request: { 0 } \
}
......
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