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) 1993-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.15  93/11/17  16:57:43  dbg
   30  *      Added kmsg type for kernel reply messages.  Moved some more
   31  *      common type definitions to ipc/ipc_types.h, which replaces
   32  *      ipc/ipc_kmsg_queue.h.  Added ANSI function prototypes.
   33  *      [93/03/29            dbg]
   34  * 
   35  * Revision 2.14  93/01/27  09:30:16  danner
   36  *      Replaced include of kern/thread.h with ipc/ipc_kmsg_queue.h
   37  * 
   38  * Revision 2.13  93/01/14  17:32:55  danner
   39  *      64bit cleanup.
   40  *      [92/11/30            af]
   41  * 
   42  * Revision 2.12  92/03/10  16:25:58  jsb
   43  *      Added ikm_source_node to support norma_ipc_receive_rright.
   44  *      [91/12/28  08:38:53  jsb]
   45  * 
   46  * Revision 2.11  91/12/14  14:26:54  jsb
   47  *      NORMA_IPC: added ikm_copy to struct kmsg.
   48  * 
   49  * Revision 2.10  91/08/28  11:13:31  jsb
   50  *      Renamed IKM_SIZE_CLPORT to IKM_SIZE_NORMA.
   51  *      [91/08/15  08:12:02  jsb]
   52  * 
   53  * Revision 2.9  91/08/03  18:18:24  jsb
   54  *      NORMA_IPC: added ikm_page field to struct ipc_kmsg.
   55  *      [91/07/17  14:01:38  jsb]
   56  * 
   57  * Revision 2.8  91/06/17  15:46:15  jsb
   58  *      Renamed NORMA conditionals.
   59  *      [91/06/17  10:46:12  jsb]
   60  * 
   61  * Revision 2.7  91/05/14  16:33:21  mrt
   62  *      Correcting copyright
   63  * 
   64  * Revision 2.6  91/03/16  14:48:10  rpd
   65  *      Replaced ith_saved with ipc_kmsg_cache.
   66  *      [91/02/16            rpd]
   67  * 
   68  * Revision 2.5  91/02/05  17:22:08  mrt
   69  *      Changed to new Mach copyright
   70  *      [91/02/01  15:45:52  mrt]
   71  * 
   72  * Revision 2.4  91/01/08  15:14:04  rpd
   73  *      Added ipc_kmsg_free.  Generalized the notion of special message sizes.
   74  *      [91/01/05            rpd]
   75  *      Added declarations of ipc_kmsg_copyout_object, ipc_kmsg_copyout_body.
   76  *      [90/12/21            rpd]
   77  * 
   78  * Revision 2.3  90/09/28  16:54:48  jsb
   79  *      Added NORMA_IPC support (hack in ikm_free).
   80  *      [90/09/28  14:03:06  jsb]
   81  * 
   82  * Revision 2.2  90/06/02  14:50:24  rpd
   83  *      Increased IKM_SAVED_KMSG_SIZE from 128 to 256.
   84  *      [90/04/23            rpd]
   85  *      Created for new IPC.
   86  *      [90/03/26  20:56:16  rpd]
   87  * 
   88  */
   89 /*
   90  *      File:   ipc/ipc_kmsg.h
   91  *      Author: Rich Draves
   92  *      Date:   1989
   93  *
   94  *      Definitions for kernel messages.
   95  */
   96 
   97 #ifndef _IPC_IPC_KMSG_H_
   98 #define _IPC_IPC_KMSG_H_
   99 
  100 #include <cpus.h>
  101 #include <mach_ipc_compat.h>
  102 #include <norma_ipc.h>
  103 
  104 #include <mach/machine/vm_types.h>
  105 #include <mach/message.h>
  106 #include <kern/assert.h>
  107 #include <kern/cpu_number.h>
  108 #include <kern/macro_help.h>
  109 #include <kern/kalloc.h>
  110 #include <ipc/ipc_types.h>
  111 #include <ipc/ipc_marequest.h>
  112 #if     NORMA_IPC
  113 #include <vm/vm_page.h>
  114 #include <vm/vm_map.h>
  115 #endif  /* NORMA_IPC */
  116 
  117 /*
  118  *      This structure is only the header for a kmsg buffer;
  119  *      the actual buffer is normally larger.  The rest of the buffer
  120  *      holds the body of the message.
  121  *
  122  *      In a kmsg, the port fields hold pointers to ports instead
  123  *      of port names.  These pointers hold references.
  124  *
  125  *      The ikm_header.msgh_remote_port field is the destination
  126  *      of the message.
  127  */
  128 
  129 struct ipc_kmsg {
  130         struct ipc_kmsg *ikm_next, *ikm_prev;
  131         vm_size_t ikm_size;
  132         ipc_marequest_t ikm_marequest;
  133 #if     NORMA_IPC
  134         vm_page_t ikm_page;
  135         vm_map_copy_t ikm_copy;
  136         unsigned long ikm_source_node;
  137 #endif  /* NORMA_IPC */
  138         mach_msg_header_t ikm_header;
  139 };
  140 
  141 #define IKM_OVERHEAD                                                    \
  142                 (sizeof(struct ipc_kmsg) - sizeof(mach_msg_header_t))
  143 
  144 #define ikm_plus_overhead(size) ((vm_size_t)((size) + IKM_OVERHEAD))
  145 #define ikm_less_overhead(size) ((mach_msg_size_t)((size) - IKM_OVERHEAD))
  146 
  147 /*
  148  *      We keep a per-processor cache of kernel message buffers.
  149  *      The cache saves the overhead/locking of using kalloc/kfree.
  150  *      The per-processor cache seems to miss less than a per-thread cache,
  151  *      and it also uses less memory.  Access to the cache doesn't
  152  *      require locking.
  153  */
  154 
  155 extern ipc_kmsg_t ipc_kmsg_cache[NCPUS];
  156 
  157 #define ikm_cache()     ipc_kmsg_cache[cpu_number()]
  158 
  159 /*
  160  *      The size of the kernel message buffers that will be cached.
  161  *      IKM_SAVED_KMSG_SIZE includes overhead; IKM_SAVED_MSG_SIZE doesn't.
  162  */
  163 
  164 #define IKM_SAVED_KMSG_SIZE     ((vm_size_t) 256)
  165 #define IKM_SAVED_MSG_SIZE      ikm_less_overhead(IKM_SAVED_KMSG_SIZE)
  166 
  167 #define ikm_alloc(size)                                                 \
  168                 ((ipc_kmsg_t) kalloc(ikm_plus_overhead(size)))
  169 
  170 #define ikm_init(kmsg, size)                                            \
  171 MACRO_BEGIN                                                             \
  172         ikm_init_special((kmsg), ikm_plus_overhead(size));              \
  173 MACRO_END
  174 
  175 #define ikm_init_special(kmsg, size)                                    \
  176 MACRO_BEGIN                                                             \
  177         (kmsg)->ikm_size = (size);                                      \
  178         (kmsg)->ikm_marequest = IMAR_NULL;                              \
  179 MACRO_END
  180 
  181 #define ikm_check_initialized(kmsg, size)                               \
  182 MACRO_BEGIN                                                             \
  183         assert((kmsg)->ikm_size == (size));                             \
  184         assert((kmsg)->ikm_marequest == IMAR_NULL);                     \
  185 MACRO_END
  186 
  187 /*
  188  *      Non-positive message sizes are special.  They indicate that
  189  *      the message buffer doesn't come from ikm_alloc and
  190  *      requires some special handling to free.
  191  *
  192  *      ipc_kmsg_free is the non-macro form of ikm_free.
  193  *      It frees kmsgs of all varieties.
  194  */
  195 
  196 #define IKM_SIZE_NORMA          0
  197 #define IKM_SIZE_NETWORK        (-1)
  198 #define IKM_SIZE_KERN_REPLY     (-2)
  199 
  200 #define ikm_free(kmsg)                                                  \
  201 MACRO_BEGIN                                                             \
  202         register vm_size_t _size = (kmsg)->ikm_size;                    \
  203                                                                         \
  204         if ((integer_t)_size > 0)                                       \
  205                 kfree((vm_offset_t) (kmsg), _size);                     \
  206         else                                                            \
  207                 ipc_kmsg_free(kmsg);                                    \
  208 MACRO_END
  209 
  210 /*
  211  *      struct ipc_kmsg_queue is defined in ipc/ipc_types.h,
  212  *      instead of this file, so that kern/thread.h doesn`t have
  213  *      to include ipc/ipc_kmsg.h.
  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 /*
  284  *      Structure declarations needed for exported routines
  285  */
  286 struct ipc_object;
  287 struct vm_map;
  288 
  289 extern mach_msg_return_t
  290 ipc_kmsg_get(
  291         mach_msg_header_t       *msg,
  292         mach_msg_size_t         size,
  293         ipc_kmsg_t *            kmsgp);
  294 
  295 extern mach_msg_return_t
  296 ipc_kmsg_get_from_kernel(
  297         mach_msg_header_t       *msg,
  298         mach_msg_size_t         size,
  299         ipc_kmsg_t              *kmsgp);
  300 
  301 extern mach_msg_return_t
  302 ipc_kmsg_put(
  303         mach_msg_header_t       *msg,
  304         ipc_kmsg_t              kmsg,
  305         mach_msg_size_t         size);
  306 
  307 extern void
  308 ipc_kmsg_put_to_kernel(
  309         mach_msg_header_t       *msg,
  310         ipc_kmsg_t              kmsg,
  311         mach_msg_size_t         size);
  312 
  313 extern mach_msg_return_t
  314 ipc_kmsg_copyin_header(
  315         mach_msg_header_t       *msg,
  316         ipc_space_t             space,
  317         mach_port_t             notify);
  318 
  319 extern mach_msg_return_t
  320 ipc_kmsg_copyin(
  321         ipc_kmsg_t      kmsg,
  322         ipc_space_t     space,
  323         struct vm_map * map,
  324         mach_port_t     notify);
  325 
  326 extern void
  327 ipc_kmsg_copyin_from_kernel(ipc_kmsg_t);
  328 
  329 extern mach_msg_return_t
  330 ipc_kmsg_copyout_header(
  331         mach_msg_header_t       *msg,
  332         ipc_space_t             space,
  333         mach_port_t             notify);
  334 
  335 extern mach_msg_return_t
  336 ipc_kmsg_copyout_object(
  337         ipc_space_t             space,
  338         struct ipc_object *     object,
  339         mach_msg_type_name_t    msgt_name,
  340         mach_port_t             *namep);
  341 
  342 extern mach_msg_return_t
  343 ipc_kmsg_copyout_body(
  344         vm_offset_t     saddr,
  345         vm_offset_t     eaddr,
  346         ipc_space_t     space,
  347         struct vm_map * map);
  348 
  349 extern mach_msg_return_t
  350 ipc_kmsg_copyout(
  351         ipc_kmsg_t      kmsg,
  352         ipc_space_t     space,
  353         struct vm_map * map,
  354         mach_port_t     notify);
  355 
  356 extern mach_msg_return_t
  357 ipc_kmsg_copyout_pseudo(
  358         ipc_kmsg_t      kmsg,
  359         ipc_space_t     space,
  360         struct vm_map * map);
  361 
  362 extern void
  363 ipc_kmsg_copyout_dest(
  364         ipc_kmsg_t      kmsg,
  365         ipc_space_t     space);
  366 
  367 #if     MACH_IPC_COMPAT
  368 
  369 extern mach_msg_return_t
  370 ipc_kmsg_copyin_compat(ipc_kmsg_t, ipc_space_t, struct vm_map *);
  371 
  372 extern mach_msg_return_t
  373 ipc_kmsg_copyout_compat(ipc_kmsg_t, ipc_space_t, struct vm_map *);
  374 
  375 #endif  /* MACH_IPC_COMPAT */
  376 
  377 #endif  /* _IPC_IPC_KMSG_H_ */

Cache object: 4fa060ab9ca925a4bdeae8253611c602


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