ipc_entry.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989 Carnegie Mellon University.
  4. * Copyright (c) 1993,1994 The University of Utah and
  5. * the Computer Systems Laboratory (CSL).
  6. * All rights reserved.
  7. *
  8. * Permission to use, copy, modify and distribute this software and its
  9. * documentation is hereby granted, provided that both the copyright
  10. * notice and this permission notice appear in all copies of the
  11. * software, derivative works or modified versions, and any portions
  12. * thereof, and that both notices appear in supporting documentation.
  13. *
  14. * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF
  15. * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
  16. * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
  17. * THIS SOFTWARE.
  18. *
  19. * Carnegie Mellon requests users of this software to return to
  20. *
  21. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  22. * School of Computer Science
  23. * Carnegie Mellon University
  24. * Pittsburgh PA 15213-3890
  25. *
  26. * any improvements or extensions that they make and grant Carnegie Mellon
  27. * the rights to redistribute these changes.
  28. */
  29. /*
  30. * File: ipc/ipc_entry.h
  31. * Author: Rich Draves
  32. * Date: 1989
  33. *
  34. * Definitions for translation entries, which represent
  35. * tasks' capabilities for ports and port sets.
  36. */
  37. #ifndef _IPC_IPC_ENTRY_H_
  38. #define _IPC_IPC_ENTRY_H_
  39. #include <mach/mach_types.h>
  40. #include <mach/port.h>
  41. #include <mach/kern_return.h>
  42. #include <kern/slab.h>
  43. #include <ipc/port.h>
  44. #include <ipc/ipc_table.h>
  45. #include <ipc/ipc_types.h>
  46. /*
  47. * Spaces hold capabilities for ipc_object_t's (ports and port sets).
  48. * Each ipc_entry_t records a capability. Most capabilities have
  49. * small names, and the entries are elements of a table.
  50. * Capabilities can have large names, and a splay tree holds
  51. * those entries. The cutoff point between the table and the tree
  52. * is adjusted dynamically to minimize memory consumption.
  53. *
  54. * The ie_index field of entries in the table implements
  55. * a ordered hash table with open addressing and linear probing.
  56. * This hash table converts (space, object) -> name.
  57. * It is used independently of the other fields.
  58. *
  59. * Free (unallocated) entries in the table have null ie_object
  60. * fields. The ie_bits field is zero except for IE_BITS_GEN.
  61. * The ie_next (ie_request) field links free entries into a free list.
  62. *
  63. * The first entry in the table (index 0) is always free.
  64. * It is used as the head of the free list.
  65. */
  66. typedef unsigned int ipc_entry_bits_t;
  67. typedef ipc_table_elems_t ipc_entry_num_t; /* number of entries */
  68. typedef struct ipc_entry {
  69. ipc_entry_bits_t ie_bits;
  70. struct ipc_object *ie_object;
  71. union {
  72. mach_port_index_t next;
  73. /*XXX ipc_port_request_index_t request;*/
  74. unsigned int request;
  75. } index;
  76. union {
  77. mach_port_index_t table;
  78. struct ipc_tree_entry *tree;
  79. } hash;
  80. } *ipc_entry_t;
  81. #define IE_NULL ((ipc_entry_t) 0)
  82. #define ie_request index.request
  83. #define ie_next index.next
  84. #define ie_index hash.table
  85. #define IE_BITS_UREFS_MASK 0x0000ffff /* 16 bits of user-reference */
  86. #define IE_BITS_UREFS(bits) ((bits) & IE_BITS_UREFS_MASK)
  87. #define IE_BITS_TYPE_MASK 0x001f0000 /* 5 bits of capability type */
  88. #define IE_BITS_TYPE(bits) ((bits) & IE_BITS_TYPE_MASK)
  89. #define IE_BITS_MAREQUEST 0x00200000 /* 1 bit for msg-accepted */
  90. #define IE_BITS_COMPAT 0x00400000 /* 1 bit for compatibility */
  91. #define IE_BITS_COLLISION 0x00800000 /* 1 bit for collisions */
  92. #define IE_BITS_RIGHT_MASK 0x007fffff /* relevant to the right */
  93. #if PORT_GENERATIONS
  94. #define IE_BITS_GEN_MASK 0xff000000U /* 8 bits for generation */
  95. #define IE_BITS_GEN(bits) ((bits) & IE_BITS_GEN_MASK)
  96. #define IE_BITS_GEN_ONE 0x01000000 /* low bit of generation */
  97. #else
  98. #define IE_BITS_GEN_MASK 0
  99. #define IE_BITS_GEN(bits) 0
  100. #define IE_BITS_GEN_ONE 0
  101. #endif
  102. typedef struct ipc_tree_entry {
  103. struct ipc_entry ite_entry;
  104. mach_port_t ite_name;
  105. struct ipc_space *ite_space;
  106. struct ipc_tree_entry *ite_lchild;
  107. struct ipc_tree_entry *ite_rchild;
  108. } *ipc_tree_entry_t;
  109. #define ITE_NULL ((ipc_tree_entry_t) 0)
  110. #define ite_bits ite_entry.ie_bits
  111. #define ite_object ite_entry.ie_object
  112. #define ite_request ite_entry.ie_request
  113. #define ite_next ite_entry.hash.tree
  114. extern struct gnu_kmem_cache ipc_tree_entry_cache;
  115. #define ite_alloc() ((ipc_tree_entry_t) gnu_kmem_cache_alloc(&ipc_tree_entry_cache))
  116. #define ite_free(ite) gnu_kmem_cache_free(&ipc_tree_entry_cache, (vm_offset_t) (ite))
  117. extern ipc_entry_t
  118. ipc_entry_lookup(ipc_space_t space, mach_port_t name);
  119. extern kern_return_t
  120. ipc_entry_get(ipc_space_t space, mach_port_t *namep, ipc_entry_t *entryp);
  121. extern kern_return_t
  122. ipc_entry_alloc(ipc_space_t space, mach_port_t *namep, ipc_entry_t *entryp);
  123. extern kern_return_t
  124. ipc_entry_alloc_name(ipc_space_t space, mach_port_t name, ipc_entry_t *entryp);
  125. extern void
  126. ipc_entry_dealloc(ipc_space_t space, mach_port_t name, ipc_entry_t entry);
  127. extern kern_return_t
  128. ipc_entry_grow_table(ipc_space_t space);
  129. #endif /* _IPC_IPC_ENTRY_H_ */