The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/server_loop.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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  Software.Distribution@CS.CMU.EDU
   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  * HISTORY
   28  * $Log:        server_loop.c,v $
   29  * Revision 2.6  91/05/18  14:33:22  rpd
   30  *      Made max_size an argument to the loop.
   31  *      Changed from kmem_alloc_wired to kalloc.
   32  *      [91/04/04            rpd]
   33  * 
   34  * Revision 2.5  91/05/14  16:46:48  mrt
   35  *      Correcting copyright
   36  * 
   37  * Revision 2.4  91/03/16  14:51:36  rpd
   38  *      Updated for new kmem_alloc interface.
   39  *      [91/03/03            rpd]
   40  * 
   41  * Revision 2.3  91/02/05  17:29:13  mrt
   42  *      Changed to new Mach copyright
   43  *      [91/02/01  16:17:32  mrt]
   44  * 
   45  * Revision 2.2  90/06/02  14:56:08  rpd
   46  *      Converted to new IPC.
   47  *      [90/03/26  22:18:09  rpd]
   48  * 
   49  * Revision 2.1  89/08/03  15:52:01  rwd
   50  * Created.
   51  * 
   52  * Revision 2.4  89/01/10  23:31:54  rpd
   53  *      Changed to require use of LOCAL_PORT to specify a port set.
   54  *      Changed xxx_port_enable to port_set_add.
   55  *      [89/01/10  13:33:38  rpd]
   56  * 
   57  * Revision 2.3  88/10/18  03:36:35  mwyoung
   58  *      Allow the local port (on which a message is to be received) to
   59  *      be redefined by this module's client.
   60  *      [88/10/01            mwyoung]
   61  * 
   62  * Revision 2.2  88/07/23  01:21:04  rpd
   63  * Changed port_enable to xxx_port_enable.
   64  * 
   65  * 11-Jan-88  Michael Young (mwyoung) at Carnegie-Mellon University
   66  *      Corrected error in timeout handling.
   67  *
   68  * 15-Dec-87  Michael Young (mwyoung) at Carnegie-Mellon University
   69  *      Created.
   70  */
   71 
   72 /*
   73  *      File:   kern/server_loop.c
   74  *
   75  *      A common server loop for builtin tasks.
   76  */
   77 
   78 /*
   79  *      Must define symbols for:
   80  *              SERVER_NAME             String name of this module
   81  *              SERVER_LOOP             Routine name for the loop
   82  *              SERVER_DISPATCH         MiG function(s) to handle message
   83  *
   84  *      Must redefine symbols for pager_server functions.
   85  */
   86 
   87 #include <mach/port.h>
   88 #include <mach/message.h>
   89 #include <vm/vm_kern.h>         /* for kernel_map */
   90 
   91 void SERVER_LOOP(rcv_set, max_size)
   92 {
   93         register mach_msg_header_t *in_msg;
   94         register mach_msg_header_t *out_msg;
   95         register mach_msg_header_t *tmp_msg;
   96         vm_offset_t messages;
   97         mach_msg_return_t r;
   98 
   99         /*
  100          *      Allocate our message buffers.
  101          */
  102 
  103         messages = kalloc(2 * max_size);
  104         if (messages == 0)
  105                 panic(SERVER_NAME);
  106         in_msg = (mach_msg_header_t *) messages;
  107         out_msg = (mach_msg_header_t *) (messages + max_size);
  108 
  109         /*
  110          *      Service loop... receive messages and process them.
  111          */
  112 
  113         for (;;) {
  114                 /* receive first message */
  115 
  116             receive_msg:
  117                 r = mach_msg(in_msg, MACH_RCV_MSG, 0, max_size, rcv_set,
  118                              MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
  119                 if (r == MACH_MSG_SUCCESS)
  120                         break;
  121 
  122                 printf("%s: receive failed, 0x%x.\n", SERVER_NAME, r);
  123         }
  124 
  125         for (;;) {
  126                 /* process request message */
  127 
  128                 (void) SERVER_DISPATCH(in_msg, out_msg);
  129 
  130                 /* send reply and receive next request */
  131 
  132                 if (out_msg->msgh_remote_port == MACH_PORT_NULL)
  133                         goto receive_msg;
  134 
  135                 r = mach_msg(out_msg, MACH_SEND_MSG|MACH_RCV_MSG,
  136                              out_msg->msgh_size, max_size, rcv_set,
  137                              MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
  138                 if (r != MACH_MSG_SUCCESS) {
  139                         printf("%s: send/receive failed, 0x%x.\n",
  140                                SERVER_NAME, r);
  141                         goto receive_msg;
  142                 }
  143 
  144                 /* swap message buffers */
  145 
  146                 tmp_msg = in_msg; in_msg = out_msg; out_msg = tmp_msg;
  147         }
  148 }

Cache object: ce2b35289281d580abba07755cbb6d14


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.