get rid of urkelvisor, and use same MD majors as the host

This commit is contained in:
jmcneill 2011-12-20 21:01:39 +00:00
parent 39568060d0
commit 34e2106021
11 changed files with 27 additions and 318 deletions

View File

@ -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

View File

@ -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 $"

View File

@ -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 $"

View File

@ -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
##

View File

@ -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 { }

View File

@ -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

View File

@ -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

View File

@ -1,34 +0,0 @@
/* $NetBSD: urkelvisor.h,v 1.1 2011/09/03 12:28:45 jmcneill Exp $ */
/*-
* Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
* 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 */

View File

@ -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 <reinoud@netbsd.org>
@ -29,10 +29,9 @@
#include "opt_memsize.h"
#include "opt_sdl.h"
#include "opt_urkelvisor.h"
#include <sys/cdefs.h>
__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 <sys/types.h>
#include <sys/param.h>
@ -51,10 +50,6 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.38 2011/12/20 15:43:51 reinoud Exp $")
#include <machine/machdep.h>
#include <machine/thunk.h>
#if defined(URKELVISOR)
#include <machine/urkelvisor.h>
#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);

View File

@ -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 <reinoud@NetBSD.org>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__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) */

View File

@ -1,212 +0,0 @@
/* $NetBSD: urkelvisor.c,v 1.9 2011/11/27 21:38:17 reinoud Exp $ */
/*-
* Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
* 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 <sys/cdefs.h>
#ifdef __NetBSD__
__RCSID("$NetBSD: urkelvisor.c,v 1.9 2011/11/27 21:38:17 reinoud Exp $");
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#ifdef __linux__
#include <sys/user.h>
#else
#include <machine/reg.h>
#endif
#include <err.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include "../include/urkelvisor.h"
#if defined(__linux__)
#include <linux/ptrace.h>
#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);
}
}