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/ipc/ipc_kmsg.h

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 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:        ipc_kmsg.h,v $
   29  * Revision 2.14  93/01/27  09:30:16  danner
   30  *      Replaced include of kern/thread.h with ipc/ipc_kmsg_queue.h
   31  * 
   32  * Revision 2.13  93/01/14  17:32:55  danner
   33  *      64bit cleanup.
   34  *      [92/11/30            af]
   35  * 
   36  * Revision 2.12  92/03/10  16:25:58  jsb
   37  *      Added ikm_source_node to support norma_ipc_receive_rright.
   38  *      [91/12/28  08:38:53  jsb]
   39  * 
   40  * Revision 2.11  91/12/14  14:26:54  jsb
   41  *      NORMA_IPC: added ikm_copy to struct kmsg.
   42  * 
   43  * Revision 2.10  91/08/28  11:13:31  jsb
   44  *      Renamed IKM_SIZE_CLPORT to IKM_SIZE_NORMA.
   45  *      [91/08/15  08:12:02  jsb]
   46  * 
   47  * Revision 2.9  91/08/03  18:18:24  jsb
   48  *      NORMA_IPC: added ikm_page field to struct ipc_kmsg.
   49  *      [91/07/17  14:01:38  jsb]
   50  * 
   51  * Revision 2.8  91/06/17  15:46:15  jsb
   52  *      Renamed NORMA conditionals.
   53  *      [91/06/17  10:46:12  jsb]
   54  * 
   55  * Revision 2.7  91/05/14  16:33:21  mrt
   56  *      Correcting copyright
   57  * 
   58  * Revision 2.6  91/03/16  14:48:10  rpd
   59  *      Replaced ith_saved with ipc_kmsg_cache.
   60  *      [91/02/16            rpd]
   61  * 
   62  * Revision 2.5  91/02/05  17:22:08  mrt
   63  *      Changed to new Mach copyright
   64  *      [91/02/01  15:45:52  mrt]
   65  * 
   66  * Revision 2.4  91/01/08  15:14:04  rpd
   67  *      Added ipc_kmsg_free.  Generalized the notion of special message sizes.
   68  *      [91/01/05            rpd]
   69  *      Added declarations of ipc_kmsg_copyout_object, ipc_kmsg_copyout_body.
   70  *      [90/12/21            rpd]
   71  * 
   72  * Revision 2.3  90/09/28  16:54:48  jsb
   73  *      Added NORMA_IPC support (hack in ikm_free).
   74  *      [90/09/28  14:03:06  jsb]
   75  * 
   76  * Revision 2.2  90/06/02  14:50:24  rpd
   77  *      Increased IKM_SAVED_KMSG_SIZE from 128 to 256.
   78  *      [90/04/23            rpd]
   79  *      Created for new IPC.
   80  *      [90/03/26  20:56:16  rpd]
   81  * 
   82  */
   83 /*
   84  *      File:   ipc/ipc_kmsg.h
   85  *      Author: Rich Draves
   86  *      Date:   1989
   87  *
   88  *      Definitions for kernel messages.
   89  */
   90 
   91 #ifndef _IPC_IPC_KMSG_H_
   92 #define _IPC_IPC_KMSG_H_
   93 
   94 #include <cpus.h>
   95 #include <mach_ipc_compat.h>
   96 #include <norma_ipc.h>
   97 
   98 #include <mach/machine/vm_types.h>
   99 #include <mach/message.h>
  100 #include <kern/assert.h>
  101 #include <kern/cpu_number.h>
  102 #include <kern/macro_help.h>
  103 #include <kern/kalloc.h>
  104 #include <ipc/ipc_marequest.h>
  105 #if     NORMA_IPC
  106 #include <vm/vm_page.h>
  107 #include <vm/vm_map.h>
  108 #endif  NORMA_IPC
  109 
  110 /*
  111  *      This structure is only the header for a kmsg buffer;
  112  *      the actual buffer is normally larger.  The rest of the buffer
  113  *      holds the body of the message.
  114  *
  115  *      In a kmsg, the port fields hold pointers to ports instead
  116  *      of port names.  These pointers hold references.
  117  *
  118  *      The ikm_header.msgh_remote_port field is the destination
  119  *      of the message.
  120  */
  121 
  122 typedef struct ipc_kmsg {
  123         struct ipc_kmsg *ikm_next, *ikm_prev;
  124         vm_size_t ikm_size;
  125         ipc_marequest_t ikm_marequest;
  126 #if     NORMA_IPC
  127         vm_page_t ikm_page;
  128         vm_map_copy_t ikm_copy;
  129         unsigned long ikm_source_node;
  130 #endif  NORMA_IPC
  131         mach_msg_header_t ikm_header;
  132 } *ipc_kmsg_t;
  133 
  134 #define IKM_NULL                ((ipc_kmsg_t) 0)
  135 
  136 #define IKM_OVERHEAD                                                    \
  137                 (sizeof(struct ipc_kmsg) - sizeof(mach_msg_header_t))
  138 
  139 #define ikm_plus_overhead(size) ((vm_size_t)((size) + IKM_OVERHEAD))
  140 #define ikm_less_overhead(size) ((mach_msg_size_t)((size) - IKM_OVERHEAD))
  141 
  142 /*
  143  *      We keep a per-processor cache of kernel message buffers.
  144  *      The cache saves the overhead/locking of using kalloc/kfree.
  145  *      The per-processor cache seems to miss less than a per-thread cache,
  146  *      and it also uses less memory.  Access to the cache doesn't
  147  *      require locking.
  148  */
  149 
  150 extern ipc_kmsg_t ipc_kmsg_cache[NCPUS];
  151 
  152 #define ikm_cache()     ipc_kmsg_cache[cpu_number()]
  153 
  154 /*
  155  *      The size of the kernel message buffers that will be cached.
  156  *      IKM_SAVED_KMSG_SIZE includes overhead; IKM_SAVED_MSG_SIZE doesn't.
  157  */
  158 
  159 #define IKM_SAVED_KMSG_SIZE     ((vm_size_t) 256)
  160 #define IKM_SAVED_MSG_SIZE      ikm_less_overhead(IKM_SAVED_KMSG_SIZE)
  161 
  162 #define ikm_alloc(size)                                                 \
  163                 ((ipc_kmsg_t) kalloc(ikm_plus_overhead(size)))
  164 
  165 #define ikm_init(kmsg, size)                                            \
  166 MACRO_BEGIN                                                             \
  167         ikm_init_special((kmsg), ikm_plus_overhead(size));              \
  168 MACRO_END
  169 
  170 #define ikm_init_special(kmsg, size)                                    \
  171 MACRO_BEGIN                                                             \
  172         (kmsg)->ikm_size = (size);                                      \
  173         (kmsg)->ikm_marequest = IMAR_NULL;                              \
  174 MACRO_END
  175 
  176 #define ikm_check_initialized(kmsg, size)                               \
  177 MACRO_BEGIN                                                             \
  178         assert((kmsg)->ikm_size == (size));                             \
  179         assert((kmsg)->ikm_marequest == IMAR_NULL);                     \
  180 MACRO_END
  181 
  182 /*
  183  *      Non-positive message sizes are special.  They indicate that
  184  *      the message buffer doesn't come from ikm_alloc and
  185  *      requires some special handling to free.
  186  *
  187  *      ipc_kmsg_free is the non-macro form of ikm_free.
  188  *      It frees kmsgs of all varieties.
  189  */
  190 
  191 #define IKM_SIZE_NORMA          0
  192 #define IKM_SIZE_NETWORK        -1
  193 
  194 #define ikm_free(kmsg)                                                  \
  195 MACRO_BEGIN                                                             \
  196         register vm_size_t _size = (kmsg)->ikm_size;                    \
  197                                                                         \
  198         if ((integer_t)_size > 0)                                       \
  199                 kfree((vm_offset_t) (kmsg), _size);                     \
  200         else                                                            \
  201                 ipc_kmsg_free(kmsg);                                    \
  202 MACRO_END
  203 
  204 /*
  205  *      struct ipc_kmsg_queue is defined in kern/thread.h instead of here,
  206  *      so that kern/thread.h doesn't have to include ipc/ipc_kmsg.h.
  207  */
  208 
  209 #include <ipc/ipc_kmsg_queue.h>
  210 
  211 typedef struct ipc_kmsg_queue *ipc_kmsg_queue_t;
  212 
  213 #define IKMQ_NULL               ((ipc_kmsg_queue_t) 0)
  214 
  215 
  216 #define ipc_kmsg_queue_init(queue)              \
  217 MACRO_BEGIN                                     \
  218         (queue)->ikmq_base = IKM_NULL;          \
  219 MACRO_END
  220 
  221 #define ipc_kmsg_queue_empty(queue)     ((queue)->ikmq_base == IKM_NULL)
  222 
  223 extern void
  224 ipc_kmsg_enqueue(/* ipc_kmsg_queue_t, ipc_kmsg_t */);
  225 
  226 extern ipc_kmsg_t
  227 ipc_kmsg_dequeue(/* ipc_kmsg_queue_t */);
  228 
  229 extern void
  230 ipc_kmsg_rmqueue(/* ipc_kmsg_queue_t, ipc_kmsg_t */);
  231 
  232 #define ipc_kmsg_queue_first(queue)             ((queue)->ikmq_base)
  233 
  234 extern ipc_kmsg_t
  235 ipc_kmsg_queue_next(/* ipc_kmsg_queue_t, ipc_kmsg_t */);
  236 
  237 #define ipc_kmsg_rmqueue_first_macro(queue, kmsg)                       \
  238 MACRO_BEGIN                                                             \
  239         register ipc_kmsg_t _next;                                      \
  240                                                                         \
  241         assert((queue)->ikmq_base == (kmsg));                           \
  242                                                                         \
  243         _next = (kmsg)->ikm_next;                                       \
  244         if (_next == (kmsg)) {                                          \
  245                 assert((kmsg)->ikm_prev == (kmsg));                     \
  246                 (queue)->ikmq_base = IKM_NULL;                          \
  247         } else {                                                        \
  248                 register ipc_kmsg_t _prev = (kmsg)->ikm_prev;           \
  249                                                                         \
  250                 (queue)->ikmq_base = _next;                             \
  251                 _next->ikm_prev = _prev;                                \
  252                 _prev->ikm_next = _next;                                \
  253         }                                                               \
  254 MACRO_END
  255 
  256 #define ipc_kmsg_enqueue_macro(queue, kmsg)                             \
  257 MACRO_BEGIN                                                             \
  258         register ipc_kmsg_t _first = (queue)->ikmq_base;                \
  259                                                                         \
  260         if (_first == IKM_NULL) {                                       \
  261                 (queue)->ikmq_base = (kmsg);                            \
  262                 (kmsg)->ikm_next = (kmsg);                              \
  263                 (kmsg)->ikm_prev = (kmsg);                              \
  264         } else {                                                        \
  265                 register ipc_kmsg_t _last = _first->ikm_prev;           \
  266                                                                         \
  267                 (kmsg)->ikm_next = _first;                              \
  268                 (kmsg)->ikm_prev = _last;                               \
  269                 _first->ikm_prev = (kmsg);                              \
  270                 _last->ikm_next = (kmsg);                               \
  271         }                                                               \
  272 MACRO_END
  273 
  274 extern void
  275 ipc_kmsg_destroy(/* ipc_kmsg_t */);
  276 
  277 extern void
  278 ipc_kmsg_clean(/* ipc_kmsg_t */);
  279 
  280 extern void
  281 ipc_kmsg_free(/* ipc_kmsg_t */);
  282 
  283 extern mach_msg_return_t
  284 ipc_kmsg_get(/* mach_msg_header_t *, mach_msg_size_t, ipc_kmsg_t * */);
  285 
  286 extern mach_msg_return_t
  287 ipc_kmsg_get_from_kernel(/* mach_msg_header_t *, mach_msg_size_t,
  288                             ipc_kmsg_t * */);
  289 
  290 extern mach_msg_return_t
  291 ipc_kmsg_put(/* mach_msg_header_t *, ipc_kmsg_t, mach_msg_size_t */);
  292 
  293 extern void
  294 ipc_kmsg_put_to_kernel(/* mach_msg_header_t *, ipc_kmsg_t, mach_msg_size_t */);
  295 
  296 extern mach_msg_return_t
  297 ipc_kmsg_copyin_header(/* mach_msg_header_t *, ipc_space_t, mach_port_t */);
  298 
  299 extern mach_msg_return_t
  300 ipc_kmsg_copyin(/* ipc_kmsg_t, ipc_space_t, vm_map_t, mach_port_t */);
  301 
  302 extern void
  303 ipc_kmsg_copyin_from_kernel(/* ipc_kmsg_t */);
  304 
  305 extern mach_msg_return_t
  306 ipc_kmsg_copyout_header(/* mach_msg_header_t *, ipc_space_t, mach_port_t */);
  307 
  308 extern mach_msg_return_t
  309 ipc_kmsg_copyout_object(/* ipc_space_t, ipc_object_t,
  310                            mach_msg_type_name_t, mach_port_t * */);
  311 
  312 extern mach_msg_return_t
  313 ipc_kmsg_copyout_body(/* vm_offset_t, vm_offset_t, ipc_space_t, vm_map_t */);
  314 
  315 extern mach_msg_return_t
  316 ipc_kmsg_copyout(/* ipc_kmsg_t, ipc_space_t, vm_map_t, mach_port_t */);
  317 
  318 extern mach_msg_return_t
  319 ipc_kmsg_copyout_pseudo(/* ipc_kmsg_t, ipc_space_t, vm_map_t */);
  320 
  321 extern void
  322 ipc_kmsg_copyout_dest(/* ipc_kmsg_t, ipc_space_t */);
  323 
  324 #if     MACH_IPC_COMPAT
  325 
  326 extern mach_msg_return_t
  327 ipc_kmsg_copyin_compat(/* ipc_kmsg_t, ipc_space_t, vm_map_t */);
  328 
  329 extern mach_msg_return_t
  330 ipc_kmsg_copyout_compat(/* ipc_kmsg_t, ipc_space_t, vm_map_t */);
  331 
  332 #endif  MACH_IPC_COMPAT
  333 #endif  _IPC_IPC_KMSG_H_

Cache object: 41344d6c91c94423befbf7e59569ccde


[ 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.