diff options
author | Roland McGrath <roland@gnu.org> | 1999-11-18 06:30:08 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1999-11-18 06:30:08 +0000 |
commit | 8ba58577a6646533ce0e8cf3b8f647651d82e247 (patch) | |
tree | 124d88d98ad0b8dc35e89974c6c1cb4e86800bd7 /mach-defpager | |
parent | 9e1a821ad8510ad57d547c68873276f3705215a6 (diff) |
1999-11-18 Roland McGrath <roland@baalperazim.frob.com>
* Makefile, main.c: New files for new this directory `mach-defpager'.
This is a standalone Hurd program version of the Mach default pager,
with the bulk of the source code coming from ../serverboot.
This program /hurd/mach-defpager is started like a normal daemon,
i.e. from rc or whatever, rather than being the first task.
* ChangeLog: New file, mentioning itself in this sentence.
Diffstat (limited to 'mach-defpager')
-rw-r--r-- | mach-defpager/ChangeLog | 8 | ||||
-rw-r--r-- | mach-defpager/Makefile | 46 | ||||
-rw-r--r-- | mach-defpager/main.c | 148 |
3 files changed, 202 insertions, 0 deletions
diff --git a/mach-defpager/ChangeLog b/mach-defpager/ChangeLog new file mode 100644 index 00000000..3b7445fe --- /dev/null +++ b/mach-defpager/ChangeLog @@ -0,0 +1,8 @@ +1999-11-18 Roland McGrath <roland@baalperazim.frob.com> + + * Makefile, main.c: New files for new this directory `mach-defpager'. + This is a standalone Hurd program version of the Mach default pager, + with the bulk of the source code coming from ../serverboot. + This program /hurd/mach-defpager is started like a normal daemon, + i.e. from rc or whatever, rather than being the first task. + * ChangeLog: New file, mentioning itself in this sentence. diff --git a/mach-defpager/Makefile b/mach-defpager/Makefile new file mode 100644 index 00000000..192106d6 --- /dev/null +++ b/mach-defpager/Makefile @@ -0,0 +1,46 @@ +# Makefile for mach-defpager subdirectory of hurd sources +# +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# This file is part of the GNU Hurd. +# +# The GNU Hurd is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2, or (at +# your option) any later version. +# +# The GNU Hurd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +dir := mach-defpager +makemode:= server +target := mach-defpager + +SRCS := default_pager.c def_pager_setup.c \ + kalloc.c wiring.c main.c \ + file_io.c strfcns.c \ + ext2_file_io.c ffs_file_io.c ffs_compat.c \ + minix_file_io.c minix_ffs_compat.c + +OBJS = $(SRCS:.c=.o) \ + $(addsuffix Server.o,memory_object default_pager memory_object_default \ + exc bootstrap) + +HURDLIBS:= threads +LDFLAGS += -static + +vpath %.c $(srcdir)/../serverboot +CPPFLAGS += -I$(srcdir)/../serverboot + +MIGSFLAGS = -DSEQNOS + +include ../Makeconf + +# Don't even bother. +CFLAGS := $(filter-out -Wall,$(CFLAGS)) diff --git a/mach-defpager/main.c b/mach-defpager/main.c new file mode 100644 index 00000000..203aad21 --- /dev/null +++ b/mach-defpager/main.c @@ -0,0 +1,148 @@ +/* Main program for standalone Hurd version of Mach default pager. + Copyright (C) 1999 Free Software Foundation, Inc. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + + + +#include <mach.h> +#include <hurd.h> +#include <cthreads.h> +#include <device/device.h> +#include <device/device_types.h> + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdarg.h> +#include <error.h> + +/* XXX */ +#include <fcntl.h> +#include <paths.h> +#include <errno.h> +#include <unistd.h> +#include <hurd.h> +#include <hurd/port.h> +#include <hurd/fd.h> +/* XXX */ + + +extern +vm_size_t cthread_wait_stack_size; + +mach_port_t bootstrap_master_device_port; /* local name */ +mach_port_t bootstrap_master_host_port; /* local name */ + +extern void default_pager(); +extern void default_pager_initialize(); +extern void default_pager_setup(); + +/* initialized in default_pager_initialize */ +extern mach_port_t default_pager_exception_port; +extern mach_port_t default_pager_bootstrap_port; + + +static void +printf_init (device_t master) +{ + mach_port_t cons; + kern_return_t rc; + rc = device_open (master, D_READ|D_WRITE, "console", &cons); + if (rc) + error (2, rc, "cannot open kernel console device"); + stdin = mach_open_devstream (cons, "r"); + stdout = stderr = mach_open_devstream (cons, "w"); + mach_port_deallocate (mach_task_self (), cons); + setbuf (stdout, 0); +} + + +int debug; + +int +main (int argc, char **argv) +{ + const task_t my_task = mach_task_self(); + error_t err; + memory_object_t defpager; + + /* + * Use 4Kbyte cthread wait stacks. + */ + cthread_wait_stack_size = 4 * 1024; + + err = get_privileged_ports (&bootstrap_master_host_port, + &bootstrap_master_device_port); + if (err) + error (1, err, "cannot get privileged ports"); + + defpager = MACH_PORT_NULL; + err = vm_set_default_memory_manager (bootstrap_master_host_port, &defpager); + if (err) + error (1, err, "cannot check current default memory manager"); + if (MACH_PORT_VALID (defpager)) + error (2, 0, "Another default memory manager is already running"); + + if (!(argc == 2 && !strcmp (argv[1], "-d")) && daemon (0, 0) < 0) + error (1, errno, "cannot become daemon"); + + printf_init(bootstrap_master_device_port); + + /* + * Set up the default pager. + */ + partition_init(); + + /* + * task_set_exception_port and task_set_bootstrap_port + * both require a send right. + */ + (void) mach_port_insert_right(my_task, default_pager_bootstrap_port, + default_pager_bootstrap_port, + MACH_MSG_TYPE_MAKE_SEND); + (void) mach_port_insert_right(my_task, default_pager_exception_port, + default_pager_exception_port, + MACH_MSG_TYPE_MAKE_SEND); + + /* + * Change our exception port. + */ + if (!debug) + (void) task_set_exception_port(my_task, default_pager_exception_port); + + default_pager_initialize (bootstrap_master_host_port); + + /* + * Become the default pager + */ + default_pager(); + /*NOTREACHED*/ + return -1; +} + + +void +panic (const char *fmt, ...) +{ + va_list ap; + fprintf (stderr, "%s: panic: ", program_invocation_name); + va_start (ap, fmt); + vfprintf (stderr, fmt, ap); + va_end (ap); + exit (3); +} |