Annotation of kernel/kern/server_loop.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /* 
        !            26:  * Mach Operating System
        !            27:  * Copyright (c) 1989 Carnegie-Mellon University
        !            28:  * Copyright (c) 1988 Carnegie-Mellon University
        !            29:  * Copyright (c) 1987 Carnegie-Mellon University
        !            30:  * All rights reserved.  The CMU software License Agreement specifies
        !            31:  * the terms and conditions for use and redistribution.
        !            32:  */
        !            33: 
        !            34: /*
        !            35:  *     File:   kern/server_loop.c
        !            36:  *
        !            37:  *     A common server loop for builtin pagers.
        !            38:  */
        !            39: 
        !            40: /*
        !            41:  *     Must define symbols for:
        !            42:  *             SERVER_NAME             String name of this module
        !            43:  *             TERMINATE_FUNCTION      How to handle port death
        !            44:  *             SERVER_LOOP             Routine name for the loop
        !            45:  *             SERVER_DISPATCH         MiG function(s) to handle message
        !            46:  *
        !            47:  *     May optionally define:
        !            48:  *             RECEIVE_OPTION          Receive option (default NONE)
        !            49:  *             RECEIVE_TIMEOUT         Receive timeout (default 0)
        !            50:  *             TIMEOUT_FUNCTION        Timeout handler (default null)
        !            51:  *
        !            52:  *     Must redefine symbols for pager_server functions.
        !            53:  */
        !            54: 
        !            55: #ifndef        RECEIVE_OPTION
        !            56: #define RECEIVE_OPTION MSG_OPTION_NONE
        !            57: #endif RECEIVE_OPTION
        !            58: 
        !            59: #ifndef        RECEIVE_TIMEOUT
        !            60: #define RECEIVE_TIMEOUT        0
        !            61: #endif RECEIVE_TIMEOUT
        !            62: 
        !            63: #ifndef        TIMEOUT_FUNCTION
        !            64: #define TIMEOUT_FUNCTION
        !            65: #endif TIMEOUT_FUNCTION
        !            66: 
        !            67: #import <mach/boolean.h>
        !            68: #import <mach/port.h>
        !            69: #import <mach/message.h>
        !            70: #import <mach/notify.h>
        !            71: 
        !            72: void           SERVER_LOOP(rcv_set, do_notify)
        !            73:        port_t          rcv_set;
        !            74:        boolean_t       do_notify;
        !            75: {
        !            76:        msg_return_t    r;
        !            77:        port_t          my_notify;
        !            78:        port_t          my_self;
        !            79:        vm_offset_t     messages;
        !            80:        register
        !            81:        msg_header_t    *in_msg;
        !            82:        msg_header_t    *out_msg;
        !            83: 
        !            84:        /*
        !            85:         *      Find out who we are.
        !            86:         */
        !            87: 
        !            88:        my_self = task_self();
        !            89: 
        !            90:        if (do_notify) {
        !            91:                my_notify = task_notify();
        !            92: 
        !            93:                if (port_set_add(my_self, rcv_set, my_notify)
        !            94:                                                != KERN_SUCCESS) {
        !            95:                        printf("%s: can't enable notify port", SERVER_NAME);
        !            96:                        panic(SERVER_NAME);
        !            97:                }
        !            98:        }
        !            99: 
        !           100:        /*
        !           101:         *      Allocate our message buffers.
        !           102:         *      [The buffers must reside in kernel space, since other
        !           103:         *      message buffers (in the mach_user_external module) are.]
        !           104:         */
        !           105: 
        !           106:        if ((messages = kmem_alloc(kernel_map, 2 * MSG_SIZE_MAX)) == 0) {
        !           107:                printf("%s: can't allocate message buffers", SERVER_NAME);
        !           108:                panic(SERVER_NAME);
        !           109:        }
        !           110:        in_msg = (msg_header_t *) messages;
        !           111:        out_msg = (msg_header_t *) (messages + MSG_SIZE_MAX);
        !           112: 
        !           113:        /*
        !           114:         *      Service loop... receive messages and process them.
        !           115:         */
        !           116: 
        !           117:        for (;;) {
        !           118:                in_msg->msg_local_port = rcv_set;
        !           119:                in_msg->msg_size = MSG_SIZE_MAX;
        !           120:                if ((r = msg_receive(in_msg, RECEIVE_OPTION, RECEIVE_TIMEOUT)) != RCV_SUCCESS) {
        !           121:                        if (r == RCV_TIMED_OUT) {
        !           122:                                TIMEOUT_FUNCTION ;
        !           123:                        } else {
        !           124:                                printf("%s: receive failed, 0x%x.\n", SERVER_NAME, r);
        !           125:                        }
        !           126:                        continue;
        !           127:                }
        !           128:                if (do_notify && (in_msg->msg_local_port == my_notify)) {
        !           129:                        notification_t  *n = (notification_t *) in_msg;
        !           130:                        switch(in_msg->msg_id) {
        !           131:                                case NOTIFY_PORT_DELETED:
        !           132:                                        TERMINATE_FUNCTION(n->notify_port);
        !           133:                                        break;
        !           134:                                default:
        !           135:                                        printf("%s: wierd notification (%d)\n", SERVER_NAME, in_msg->msg_id);
        !           136:                                        printf("port = 0x%x.\n", n->notify_port);
        !           137:                                        break;
        !           138:                        }
        !           139:                        continue;
        !           140:                }
        !           141:                if (SERVER_DISPATCH(in_msg, out_msg) &&
        !           142:                    (out_msg->msg_remote_port != PORT_NULL))
        !           143:                        msg_send(out_msg, MSG_OPTION_NONE, 0);
        !           144:        }
        !           145: }
        !           146: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.