From 34e2106021dd93e816de2203d3e972d61039f9e7 Mon Sep 17 00:00:00 2001 From: jmcneill Date: Tue, 20 Dec 2011 21:01:39 +0000 Subject: [PATCH] get rid of urkelvisor, and use same MD majors as the host --- .../usermode/conf/{GENERIC => GENERIC.common} | 7 +- sys/arch/usermode/conf/GENERIC.i386 | 17 ++ sys/arch/usermode/conf/GENERIC32 | 12 - sys/arch/usermode/conf/Makefile.usermode | 16 +- sys/arch/usermode/conf/files.usermode | 3 +- sys/arch/usermode/conf/majors.usermode | 15 +- sys/arch/usermode/conf/std.usermode | 5 +- sys/arch/usermode/include/urkelvisor.h | 34 --- sys/arch/usermode/usermode/machdep.c | 13 +- sys/arch/usermode/usermode/pmap.c | 11 +- sys/arch/usermode/usermode/urkelvisor.c | 212 ------------------ 11 files changed, 27 insertions(+), 318 deletions(-) rename sys/arch/usermode/conf/{GENERIC => GENERIC.common} (85%) create mode 100644 sys/arch/usermode/conf/GENERIC.i386 delete mode 100644 sys/arch/usermode/conf/GENERIC32 delete mode 100644 sys/arch/usermode/include/urkelvisor.h delete mode 100644 sys/arch/usermode/usermode/urkelvisor.c diff --git a/sys/arch/usermode/conf/GENERIC b/sys/arch/usermode/conf/GENERIC.common similarity index 85% rename from sys/arch/usermode/conf/GENERIC rename to sys/arch/usermode/conf/GENERIC.common index 904ddf97711c..2346241f3533 100644 --- a/sys/arch/usermode/conf/GENERIC +++ b/sys/arch/usermode/conf/GENERIC.common @@ -1,16 +1,13 @@ -# $NetBSD: GENERIC,v 1.24 2011/12/15 11:26:04 jmcneill Exp $ +# $NetBSD: GENERIC.common,v 1.1 2011/12/20 21:01:39 jmcneill Exp $ include "arch/usermode/conf/std.usermode" options INCLUDE_CONFIG_FILE -#ident "GENERIC-$Revision: 1.24 $" +#ident "GENERIC-$Revision: 1.1 $" maxusers 32 makeoptions DEBUG="-O1 -g3" -options TEXTADDR=0x0f000000 # 1.5 Gb? -options KVMSIZE=0x008000000 - options RTC_OFFSET=0 options KTRACE #options USERCONF diff --git a/sys/arch/usermode/conf/GENERIC.i386 b/sys/arch/usermode/conf/GENERIC.i386 new file mode 100644 index 000000000000..1458fc8226c4 --- /dev/null +++ b/sys/arch/usermode/conf/GENERIC.i386 @@ -0,0 +1,17 @@ +# $NetBSD: GENERIC.i386,v 1.1 2011/12/20 21:01:39 jmcneill Exp $ + +machine usermode +include "arch/usermode/conf/GENERIC.common" +include "arch/i386/conf/majors.i386" + +no options EXEC_ELF64 + +options TEXTADDR=0x0f000000 # 1.5 Gb? +options KVMSIZE=0x008000000 + +makeoptions COPTS+="-m32" +makeoptions LD="ld -melf_i386" + +#options INCLUDE_CONFIG_FILE +#ident "GENERIC32-$Revision: 1.1 $" + diff --git a/sys/arch/usermode/conf/GENERIC32 b/sys/arch/usermode/conf/GENERIC32 deleted file mode 100644 index 09ecb7d79329..000000000000 --- a/sys/arch/usermode/conf/GENERIC32 +++ /dev/null @@ -1,12 +0,0 @@ -# $NetBSD: GENERIC32,v 1.2 2011/08/12 11:22:11 jmcneill Exp $ - -include "arch/usermode/conf/GENERIC" - -no options EXEC_ELF64 - -makeoptions COPTS+="-m32" -makeoptions LD="ld -melf_i386" - -#options INCLUDE_CONFIG_FILE -#ident "GENERIC32-$Revision: 1.2 $" - diff --git a/sys/arch/usermode/conf/Makefile.usermode b/sys/arch/usermode/conf/Makefile.usermode index 2373c565ffd2..8d61274a3586 100644 --- a/sys/arch/usermode/conf/Makefile.usermode +++ b/sys/arch/usermode/conf/Makefile.usermode @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.usermode,v 1.24 2011/09/16 11:28:36 jmcneill Exp $ +# $NetBSD: Makefile.usermode,v 1.25 2011/12/20 21:01:39 jmcneill Exp $ OPT_CPU_HOST= %CPU_HOST% .if !empty(OPT_CPU_HOST) @@ -38,7 +38,6 @@ CPPFLAGS+= -Dusermode CPPFLAGS.init_main.c+= -Dmain=kernmain OPT_SDL= %SDL% -OPT_URKELVISOR= %URKELVISOR% .if !empty(OPT_SDL) SDL_CFLAGS!= sdl-config --cflags @@ -48,7 +47,6 @@ USERMODE_LIBS+= -Wl,-Bdynamic ${SDL_LIBS} CPPFLAGS.thunk.c+= ${USERMODE_CPPFLAGS} CPPFLAGS.thunk_sdl.c+= ${SDL_CFLAGS} ${USERMODE_CPPFLAGS} -CPPFLAGS.urkelvisor.c+= ${USERMODE_CPPFLAGS} ## ## (3) libkern and compat @@ -63,11 +61,6 @@ MD_OBJS= thunk.o MD_CFILES= ${USERMODE}/usermode/thunk.c MD_SFILES= -.if !empty(OPT_URKELVISOR) -MD_OBJS+= urkelvisor.o -MD_CFILES+= ${USERMODE}/usermode/urkelvisor.c -.endif - .if !empty(OPT_SDL) MD_OBJS+= thunk_sdl.o MD_CFILES+= ${USERMODE}/usermode/thunk_sdl.c @@ -112,13 +105,6 @@ thunk_sdl.d: ${USERMODE}/usermode/thunk.c thunk_sdl.o: ${USERMODE}/usermode/thunk_sdl.c ${CC} ${CPPFLAGS.thunk_sdl.c} -c -o $@ ${USERMODE}/usermode/thunk_sdl.c -urkelvisor.d: ${USERMODE}/usermode/urkelvisor.c - ${MKDEP} -f ${.TARGET} -- ${MKDEP_CFLAGS} \ - ${CPPFLAGS.urkelvisor.c} ${USERMODE}/usermode/urkelvisor.c - -urkelvisor.o: ${USERMODE}/usermode/urkelvisor.c - ${CC} ${CPPFLAGS.urkelvisor.c} -c -o $@ ${USERMODE}/usermode/urkelvisor.c - ## ## (7) misc settings ## diff --git a/sys/arch/usermode/conf/files.usermode b/sys/arch/usermode/conf/files.usermode index eb95b79e8f65..c1ffab89cc18 100644 --- a/sys/arch/usermode/conf/files.usermode +++ b/sys/arch/usermode/conf/files.usermode @@ -1,4 +1,4 @@ -# $NetBSD: files.usermode,v 1.11 2011/09/16 11:28:36 jmcneill Exp $ +# $NetBSD: files.usermode,v 1.12 2011/12/20 21:01:39 jmcneill Exp $ maxpartitions 8 maxusers 8 16 64 @@ -8,7 +8,6 @@ defflag opt_sdl.h SDL defflag opt_cpu.h CPU_DEBUG defparam opt_cpu.h CPU_HOST defparam opt_misc.h TEXTADDR -defflag opt_urkelvisor.h URKELVISOR define thunkbus { } diff --git a/sys/arch/usermode/conf/majors.usermode b/sys/arch/usermode/conf/majors.usermode index 8ed1ea21974d..e9f6a5c813b1 100644 --- a/sys/arch/usermode/conf/majors.usermode +++ b/sys/arch/usermode/conf/majors.usermode @@ -1,15 +1,2 @@ -# $NetBSD: majors.usermode,v 1.4 2011/12/11 22:34:42 jmcneill Exp $ - -device-major cons char 0 -device-major ctty char 1 -device-major mem char 2 -#device-major wd char 3 -device-major swap char 4 block 1 vmswap -device-major pts char 5 pty -device-major ptc char 6 pty -device-major log char 7 -device-major com char 8 com -device-major md char 24 block 17 md -device-major wsdisplay char 47 wsdisplay -device-major ld char 69 block 19 ld +# $NetBSD: majors.usermode,v 1.5 2011/12/20 21:01:39 jmcneill Exp $ device-major ttycons char 159 ttycons diff --git a/sys/arch/usermode/conf/std.usermode b/sys/arch/usermode/conf/std.usermode index 02567db49bbe..b36a16fc4c85 100644 --- a/sys/arch/usermode/conf/std.usermode +++ b/sys/arch/usermode/conf/std.usermode @@ -1,6 +1,5 @@ -# $NetBSD: std.usermode,v 1.8 2011/12/13 20:58:47 reinoud Exp $ +# $NetBSD: std.usermode,v 1.9 2011/12/20 21:01:39 jmcneill Exp $ -machine usermode include "conf/std" options HZ=100 @@ -8,8 +7,6 @@ options EXEC_ELF32 options EXEC_ELF64 options EXEC_SCRIPT -options URKELVISOR - # Defaults options NKMEMPAGES=4096 #options NKMEMPAGES_MAX_DEFAULT=2048 diff --git a/sys/arch/usermode/include/urkelvisor.h b/sys/arch/usermode/include/urkelvisor.h deleted file mode 100644 index bf1a1249aa07..000000000000 --- a/sys/arch/usermode/include/urkelvisor.h +++ /dev/null @@ -1,34 +0,0 @@ -/* $NetBSD: urkelvisor.h,v 1.1 2011/09/03 12:28:45 jmcneill Exp $ */ - -/*- - * Copyright (c) 2011 Jared D. McNeill - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _ARCH_USERMODE_INCLUDE_URKELVISOR_H -#define _ARCH_USERMODE_INCLUDE_URKELVISOR_H - -void urkelvisor_init(void); - -#endif /* !_ARCH_USERMODE_INCLUDE_URKELVISOR_H */ diff --git a/sys/arch/usermode/usermode/machdep.c b/sys/arch/usermode/usermode/machdep.c index a9daa8bb73ba..51cd3f174e3a 100644 --- a/sys/arch/usermode/usermode/machdep.c +++ b/sys/arch/usermode/usermode/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.38 2011/12/20 15:43:51 reinoud Exp $ */ +/* $NetBSD: machdep.c,v 1.39 2011/12/20 21:01:39 jmcneill Exp $ */ /*- * Copyright (c) 2011 Reinoud Zandijk @@ -29,10 +29,9 @@ #include "opt_memsize.h" #include "opt_sdl.h" -#include "opt_urkelvisor.h" #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.38 2011/12/20 15:43:51 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.39 2011/12/20 21:01:39 jmcneill Exp $"); #include #include @@ -51,10 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.38 2011/12/20 15:43:51 reinoud Exp $") #include #include -#if defined(URKELVISOR) -#include -#endif - char machine[] = "usermode"; char machine_arch[] = "usermode"; @@ -106,10 +101,6 @@ main(int argc, char *argv[]) pmap_bootstrap(); -#if defined(URKELVISOR) - urkelvisor_init(); -#endif - splinit(); splraise(IPL_HIGH); diff --git a/sys/arch/usermode/usermode/pmap.c b/sys/arch/usermode/usermode/pmap.c index d9f58cbb7c23..7dc347560a87 100644 --- a/sys/arch/usermode/usermode/pmap.c +++ b/sys/arch/usermode/usermode/pmap.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.80 2011/12/20 15:45:37 reinoud Exp $ */ +/* $NetBSD: pmap.c,v 1.81 2011/12/20 21:01:39 jmcneill Exp $ */ /*- * Copyright (c) 2011 Reinoud Zandijk @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.80 2011/12/20 15:45:37 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.81 2011/12/20 21:01:39 jmcneill Exp $"); #include "opt_memsize.h" #include "opt_kmempages.h" @@ -370,13 +370,6 @@ pmap_bootstrap(void) void pmap_init(void) { - /* - * XXX Work around a NetBSD fork() bug that doesn't copy the alternate - * signal stack to the child! so ensure signal stack is setup after - * urkelvisor fork - */ - - thunk_sigaltstack(usermode_signal_stack(), NULL); } /* return kernel space start and end (including growth) */ diff --git a/sys/arch/usermode/usermode/urkelvisor.c b/sys/arch/usermode/usermode/urkelvisor.c deleted file mode 100644 index 6fa3580c7639..000000000000 --- a/sys/arch/usermode/usermode/urkelvisor.c +++ /dev/null @@ -1,212 +0,0 @@ -/* $NetBSD: urkelvisor.c,v 1.9 2011/11/27 21:38:17 reinoud Exp $ */ - -/*- - * Copyright (c) 2011 Jared D. McNeill - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Usermode kernel supervisor - */ - -#include -#ifdef __NetBSD__ -__RCSID("$NetBSD: urkelvisor.c,v 1.9 2011/11/27 21:38:17 reinoud Exp $"); -#endif - -#include -#include -#include -#include -#include - -#ifdef __linux__ -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include - -#include "../include/urkelvisor.h" - -#if defined(__linux__) -#include -#define PT_SYSCALLEMU PTRACE_SYSEMU -typedef intptr_t vaddr_t; -#endif - -extern vaddr_t kmem_user_start, kmem_user_end; /* usermode/pmap.c */ - -#if defined(__linux__) -# define reg_struct user_regs_struct -# define R_SYSCALL(_regs) ((_regs)->orig_eax) -# define R_PC(_regs) ((_regs)->eip) -#else -# define reg_struct reg -# if defined(__i386__) -# define R_SYSCALL(_regs) ((_regs)->r_eax) -# define R_PC(_regs) ((_regs)->r_eip) -# elif defined(__x86_64__) -# define R_SYSCALL(_regs) ((_regs)->regs[_REG_RAX]) -# define R_PC(_regs) ((_regs)->regs[_REG_RIP]) -# else -# error port me -# endif -#endif - -static int -wait_urkel(pid_t urkel_pid) -{ - pid_t pid; - int status; - - pid = waitpid(urkel_pid, &status, 0); - if (pid == -1) - err(EXIT_FAILURE, "waitpid failed"); - - if (WIFEXITED(status)) - exit(WEXITSTATUS(status)); - - return status; -} - -static void -ptrace_getregs(pid_t urkel_pid, struct reg_struct *puregs) -{ - errno = 0; -#ifdef __linux__ - ptrace(PT_GETREGS, urkel_pid, NULL, puregs); -#else - ptrace(PT_GETREGS, urkel_pid, puregs, 0); -#endif - if (errno) - err(EXIT_FAILURE, "ptrace(PT_GETREGS, %d, &uregs, 0) failed", - urkel_pid); -} - -static int -handle_syscall(struct reg_struct *puregs, pid_t urkel_pid) -{ - vaddr_t pc; - int sig = 0; - int inkernel; - - pc = (vaddr_t)R_PC(puregs); - inkernel = !(pc >= kmem_user_start && pc < kmem_user_end); - -// fprintf(stderr, "%s: pid=%d pc=%p inkernel=%d\n", -// __func__, urkel_pid, (void *)R_PC(puregs), inkernel); - - if (!inkernel) { - fprintf(stderr, "caught syscall %d\n", (int)R_SYSCALL(puregs)); - errno = 0; - ptrace(PT_SYSCALLEMU, urkel_pid, NULL, 0); - if (errno) - err(EXIT_FAILURE, - "ptrace(PT_SYSCALLEMU, %d, NULL, 0) failed", - urkel_pid); - sig = SIGILL; - } - - return sig; -} - -static int -urkelvisor(pid_t urkel_pid) -{ - struct reg_struct uregs; - int status, insyscall, sig; - - insyscall = 0; - sig = 0; - - status = wait_urkel(urkel_pid); - - for (;;) { - errno = 0; - //fprintf(stderr, "sig = %d\n", sig); - ptrace(PT_SYSCALL, urkel_pid, (void *)1, sig); - if (errno) - err(EXIT_FAILURE, "ptrace(PT_SYSCALL, %d, 1, %d) failed", - urkel_pid, sig); - sig = 0; - status = wait_urkel(urkel_pid); - - //fprintf(stderr, "syscall insyscall=%d status=%x\n", - // insyscall, status); - if (WIFSTOPPED(status)) { - if (WSTOPSIG(status) == SIGTRAP) { - insyscall = !insyscall; - if (insyscall) { - ptrace_getregs(urkel_pid, &uregs); - sig = handle_syscall(&uregs, urkel_pid); - if (sig) - insyscall = !insyscall; - } - } else { - sig = WSTOPSIG(status); - } - } - } -} - -void -urkelvisor_init(void) -{ - char *enable; - pid_t child_pid; - int status; - - /* env URKELVISOR=0 disables the urkelvisor */ - enable = getenv("URKELVISOR"); - if (enable && *enable == '0') { - fprintf(stderr, "%s: disabled\n", __func__); - return; - } - - child_pid = fork(); - switch (child_pid) { - case -1: - err(EXIT_FAILURE, "fork() failed"); - /* NOTREACHED */ - case 0: - errno = 0; - ptrace(PT_TRACE_ME, 0, NULL, 0); - if (errno) - err(EXIT_FAILURE, - "ptrace(PT_TRACE_ME, 0, NULL, 0) failed"); - raise(SIGSTOP); - break; - default: - status = urkelvisor(child_pid); - exit(status); - } -} -