|
|
1.1 ! root 1: /* ! 2: * Mach Operating System ! 3: * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University ! 4: * All Rights Reserved. ! 5: * ! 6: * Permission to use, copy, modify and distribute this software and its ! 7: * documentation is hereby granted, provided that both the copyright ! 8: * notice and this permission notice appear in all copies of the ! 9: * software, derivative works or modified versions, and any portions ! 10: * thereof, and that both notices appear in supporting documentation. ! 11: * ! 12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 15: * ! 16: * Carnegie Mellon requests users of this software to return to ! 17: * ! 18: * Software Distribution Coordinator or [email protected] ! 19: * School of Computer Science ! 20: * Carnegie Mellon University ! 21: * Pittsburgh PA 15213-3890 ! 22: * ! 23: * any improvements or extensions that they make and grant Carnegie Mellon ! 24: * the rights to redistribute these changes. ! 25: */ ! 26: /* ! 27: * File: kern/server_loop.c ! 28: * ! 29: * A common server loop for builtin tasks. ! 30: */ ! 31: ! 32: /* ! 33: * Must define symbols for: ! 34: * SERVER_NAME String name of this module ! 35: * SERVER_LOOP Routine name for the loop ! 36: * SERVER_DISPATCH MiG function(s) to handle message ! 37: * ! 38: * Must redefine symbols for pager_server functions. ! 39: */ ! 40: ! 41: #include <mach/port.h> ! 42: #include <mach/message.h> ! 43: #include <vm/vm_kern.h> /* for kernel_map */ ! 44: ! 45: void SERVER_LOOP(rcv_set, max_size) ! 46: { ! 47: register mach_msg_header_t *in_msg; ! 48: register mach_msg_header_t *out_msg; ! 49: register mach_msg_header_t *tmp_msg; ! 50: vm_offset_t messages; ! 51: mach_msg_return_t r; ! 52: ! 53: /* ! 54: * Allocate our message buffers. ! 55: */ ! 56: ! 57: messages = kalloc(2 * max_size); ! 58: if (messages == 0) ! 59: panic(SERVER_NAME); ! 60: in_msg = (mach_msg_header_t *) messages; ! 61: out_msg = (mach_msg_header_t *) (messages + max_size); ! 62: ! 63: /* ! 64: * Service loop... receive messages and process them. ! 65: */ ! 66: ! 67: for (;;) { ! 68: /* receive first message */ ! 69: ! 70: receive_msg: ! 71: r = mach_msg(in_msg, MACH_RCV_MSG, 0, max_size, rcv_set, ! 72: MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); ! 73: if (r == MACH_MSG_SUCCESS) ! 74: break; ! 75: ! 76: printf("%s: receive failed, 0x%x.\n", SERVER_NAME, r); ! 77: } ! 78: ! 79: for (;;) { ! 80: /* process request message */ ! 81: ! 82: (void) SERVER_DISPATCH(in_msg, out_msg); ! 83: ! 84: /* send reply and receive next request */ ! 85: ! 86: if (out_msg->msgh_remote_port == MACH_PORT_NULL) ! 87: goto receive_msg; ! 88: ! 89: r = mach_msg(out_msg, MACH_SEND_MSG|MACH_RCV_MSG, ! 90: out_msg->msgh_size, max_size, rcv_set, ! 91: MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); ! 92: if (r != MACH_MSG_SUCCESS) { ! 93: printf("%s: send/receive failed, 0x%x.\n", ! 94: SERVER_NAME, r); ! 95: goto receive_msg; ! 96: } ! 97: ! 98: /* swap message buffers */ ! 99: ! 100: tmp_msg = in_msg; in_msg = out_msg; out_msg = tmp_msg; ! 101: } ! 102: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.