summaryrefslogtreecommitdiff
path: root/mach-defpager/main.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1999-11-18 06:30:08 +0000
committerRoland McGrath <roland@gnu.org>1999-11-18 06:30:08 +0000
commit8ba58577a6646533ce0e8cf3b8f647651d82e247 (patch)
tree124d88d98ad0b8dc35e89974c6c1cb4e86800bd7 /mach-defpager/main.c
parent9e1a821ad8510ad57d547c68873276f3705215a6 (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/main.c')
-rw-r--r--mach-defpager/main.c148
1 files changed, 148 insertions, 0 deletions
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);
+}