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_table.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 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_table.c,v $
   29  * Revision 2.8  92/08/03  17:35:46  jfriedl
   30  *      removed silly prototypes
   31  *      [92/08/02            jfriedl]
   32  * 
   33  * Revision 2.7  92/05/21  17:11:57  jfriedl
   34  *      tried prototypes.
   35  *      [92/05/20            jfriedl]
   36  * 
   37  * Revision 2.6  91/10/09  16:11:08  af
   38  *       Revision 2.5.2.1  91/09/16  10:16:06  rpd
   39  *              Removed unused variables.
   40  *              [91/09/02            rpd]
   41  * 
   42  * Revision 2.5.2.1  91/09/16  10:16:06  rpd
   43  *      Removed unused variables.
   44  *      [91/09/02            rpd]
   45  * 
   46  * Revision 2.5  91/05/14  16:37:35  mrt
   47  *      Correcting copyright
   48  * 
   49  * Revision 2.4  91/03/16  14:48:52  rpd
   50  *      Added ipc_table_realloc and ipc_table_reallocable.
   51  *      [91/03/04            rpd]
   52  * 
   53  * Revision 2.3  91/02/05  17:24:15  mrt
   54  *      Changed to new Mach copyright
   55  *      [91/02/01  15:52:05  mrt]
   56  * 
   57  * Revision 2.2  90/06/02  14:51:58  rpd
   58  *      Created for new IPC.
   59  *      [90/03/26  21:04:20  rpd]
   60  * 
   61  */
   62 /*
   63  *      File:   ipc/ipc_table.c
   64  *      Author: Rich Draves
   65  *      Date:   1989
   66  *
   67  *      Functions to manipulate tables of IPC capabilities.
   68  */
   69 
   70 #include <mach/kern_return.h>
   71 #include <mach/vm_param.h>
   72 #include <ipc/ipc_table.h>
   73 #include <ipc/ipc_port.h>
   74 #include <ipc/ipc_entry.h>
   75 #include <kern/kalloc.h>
   76 #include <vm/vm_kern.h>
   77 
   78 
   79 
   80 /*
   81  *      We borrow the kalloc map, rather than creating
   82  *      yet another submap of the kernel map.
   83  */
   84 
   85 extern vm_map_t kalloc_map;
   86 
   87 ipc_table_size_t ipc_table_entries;
   88 unsigned int ipc_table_entries_size = 128;
   89 
   90 ipc_table_size_t ipc_table_dnrequests;
   91 unsigned int ipc_table_dnrequests_size = 64;
   92 
   93 void
   94 ipc_table_fill(its, num, min, elemsize)
   95         ipc_table_size_t its;   /* array to fill */
   96         unsigned int num;       /* size of array */
   97         unsigned int min;       /* at least this many elements */
   98         vm_size_t elemsize;     /* size of elements */
   99 {
  100         unsigned int index;
  101         vm_size_t minsize = min * elemsize;
  102         vm_size_t size;
  103         vm_size_t incrsize;
  104 
  105         /* first use powers of two, up to the page size */
  106 
  107         for (index = 0, size = 1;
  108              (index < num) && (size < PAGE_SIZE);
  109              size <<= 1) {
  110                 if (size >= minsize) {
  111                         its[index].its_size = size / elemsize;
  112                         index++;
  113                 }
  114         }
  115 
  116         /* then increments of a page, then two pages, etc. */
  117 
  118         for (incrsize = PAGE_SIZE; index < num; incrsize <<= 1) {
  119                 unsigned int period;
  120 
  121                 for (period = 0;
  122                      (period < 15) && (index < num);
  123                      period++, size += incrsize) {
  124                         if (size >= minsize) {
  125                                 its[index].its_size = size / elemsize;
  126                                 index++;
  127                         }
  128                 }
  129         }
  130 }
  131 
  132 void
  133 ipc_table_init()
  134 {
  135         ipc_table_entries = (ipc_table_size_t)
  136                 kalloc(sizeof(struct ipc_table_size) *
  137                        ipc_table_entries_size);
  138         assert(ipc_table_entries != ITS_NULL);
  139 
  140         ipc_table_fill(ipc_table_entries, ipc_table_entries_size - 1,
  141                        4, sizeof(struct ipc_entry));
  142 
  143         /* the last two elements should have the same size */
  144 
  145         ipc_table_entries[ipc_table_entries_size - 1].its_size =
  146                 ipc_table_entries[ipc_table_entries_size - 2].its_size;
  147 
  148 
  149         ipc_table_dnrequests = (ipc_table_size_t)
  150                 kalloc(sizeof(struct ipc_table_size) *
  151                        ipc_table_dnrequests_size);
  152         assert(ipc_table_dnrequests != ITS_NULL);
  153 
  154         ipc_table_fill(ipc_table_dnrequests, ipc_table_dnrequests_size - 1,
  155                        2, sizeof(struct ipc_port_request));
  156 
  157         /* the last element should have zero size */
  158 
  159         ipc_table_dnrequests[ipc_table_dnrequests_size - 1].its_size = 0;
  160 }
  161 
  162 /*
  163  *      Routine:        ipc_table_alloc
  164  *      Purpose:
  165  *              Allocate a table.
  166  *      Conditions:
  167  *              May block.
  168  */
  169 
  170 vm_offset_t
  171 ipc_table_alloc(size)
  172         vm_size_t size;
  173 {
  174         vm_offset_t table;
  175 
  176         if (size < PAGE_SIZE)
  177                 table = kalloc(size);
  178         else
  179                 if (kmem_alloc(kalloc_map, &table, size) != KERN_SUCCESS)
  180                         table = 0;
  181 
  182         return table;
  183 }
  184 
  185 /*
  186  *      Routine:        ipc_table_realloc
  187  *      Purpose:
  188  *              Reallocate a big table.
  189  *
  190  *              The new table remaps the old table,
  191  *              so copying is not necessary.
  192  *      Conditions:
  193  *              Only works for page-size or bigger tables.
  194  *              May block.
  195  */
  196 
  197 vm_offset_t
  198 ipc_table_realloc(old_size, old_table, new_size)
  199         vm_size_t old_size;
  200         vm_offset_t old_table;
  201         vm_size_t new_size;
  202 {
  203         vm_offset_t new_table;
  204 
  205         if (kmem_realloc(kalloc_map, old_table, old_size,
  206                          &new_table, new_size) != KERN_SUCCESS)
  207                 new_table = 0;
  208 
  209         return new_table;
  210 }
  211 
  212 /*
  213  *      Routine:        ipc_table_free
  214  *      Purpose:
  215  *              Free a table allocated with ipc_table_alloc or
  216  *              ipc_table_realloc.
  217  *      Conditions:
  218  *              May block.
  219  */
  220 
  221 void
  222 ipc_table_free(size, table)
  223         vm_size_t size;
  224         vm_offset_t table;
  225 {
  226         if (size < PAGE_SIZE)
  227                 kfree(table, size);
  228         else
  229                 kmem_free(kalloc_map, table, size);
  230 }

Cache object: 8bb60f1293b68cb170df4f43e7dc1fde


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