summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2014-11-07 10:43:47 +0100
committerJustus Winter <4winter@informatik.uni-hamburg.de>2014-11-21 05:55:41 +0100
commit25fe9cb62331d609b87b9d0b1db06d06ab825d16 (patch)
treeaa4c476f111b45e1f9ed72905755eb16ec8e4921
parent4e38225c4e3af1dede56b5df6f734faaa2b2469e (diff)
boot: improve the demuxer
Handle multiple request types as recommended by the Mach Server Writer's Guide section 4, subsection "Handling Multiple Request Types". This avoids initializing the reply message in every X_server function. * boot/boot.c (mig_reply_setup): Provide local version. (request_server): Rename to `boot_demuxer', and improve the dispatch.
-rw-r--r--boot/boot.c67
1 files changed, 49 insertions, 18 deletions
diff --git a/boot/boot.c b/boot/boot.c
index 747ab739..e2cb9075 100644
--- a/boot/boot.c
+++ b/boot/boot.c
@@ -169,22 +169,55 @@ useropen (const char *name, int flags, int mode)
return open (name, flags, mode);
}
-int
-request_server (mach_msg_header_t *inp,
- mach_msg_header_t *outp)
-{
- extern int io_server (mach_msg_header_t *, mach_msg_header_t *);
- extern int device_server (mach_msg_header_t *, mach_msg_header_t *);
- extern int notify_server (mach_msg_header_t *, mach_msg_header_t *);
- extern int term_server (mach_msg_header_t *, mach_msg_header_t *);
-/* extern int tioctl_server (mach_msg_header_t *, mach_msg_header_t *); */
- extern int bootstrap_server (mach_msg_header_t *, mach_msg_header_t *);
+/* XXX: glibc should provide mig_reply_setup but does not. */
+/* Fill in default response. */
+void
+mig_reply_setup (
+ const mach_msg_header_t *in,
+ mach_msg_header_t *out)
+{
+ static const mach_msg_type_t RetCodeType = {
+ /* msgt_name = */ MACH_MSG_TYPE_INTEGER_32,
+ /* msgt_size = */ 32,
+ /* msgt_number = */ 1,
+ /* msgt_inline = */ TRUE,
+ /* msgt_longform = */ FALSE,
+ /* msgt_deallocate = */ FALSE,
+ /* msgt_unused = */ 0
+ };
+
+#define InP (in)
+#define OutP ((mig_reply_header_t *) out)
+ OutP->Head.msgh_bits =
+ MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(InP->msgh_bits), 0);
+ OutP->Head.msgh_size = sizeof *OutP;
+ OutP->Head.msgh_remote_port = InP->msgh_remote_port;
+ OutP->Head.msgh_local_port = MACH_PORT_NULL;
+ OutP->Head.msgh_seqno = 0;
+ OutP->Head.msgh_id = InP->msgh_id + 100;
+ OutP->RetCodeType = RetCodeType;
+ OutP->RetCode = MIG_BAD_ID;
+#undef InP
+#undef OutP
+}
- return (io_server (inp, outp)
- || device_server (inp, outp)
- || notify_server (inp, outp)
- || term_server (inp, outp)
- /* || tioctl_server (inp, outp) */);
+int
+boot_demuxer (mach_msg_header_t *inp,
+ mach_msg_header_t *outp)
+{
+ mig_routine_t routine;
+ mig_reply_setup (inp, outp);
+ if ((routine = io_server_routine (inp)) ||
+ (routine = device_server_routine (inp)) ||
+ (routine = notify_server_routine (inp)) ||
+ (routine = term_server_routine (inp))
+ /* (routine = tioctl_server_routine (inp)) */)
+ {
+ (*routine) (inp, outp);
+ return TRUE;
+ }
+ else
+ return FALSE;
}
vm_address_t
@@ -710,15 +743,13 @@ main (int argc, char **argv, char **envp)
else /* We hosed */
error (5, errno, "select");
}
-
-/* mach_msg_server (request_server, __vm_page_size * 2, receive_set); */
}
void *
msg_thread (void *arg)
{
while (1)
- mach_msg_server (request_server, 0, receive_set);
+ mach_msg_server (boot_demuxer, 0, receive_set);
}