ipc_space.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. */
  31. /*
  32. * File: ipc/ipc_space.h
  33. * Author: Rich Draves
  34. * Date: 1989
  35. *
  36. * Definitions for IPC spaces of capabilities.
  37. */
  38. #ifndef _IPC_IPC_SPACE_H_
  39. #define _IPC_IPC_SPACE_H_
  40. #include <mach/boolean.h>
  41. #include <mach/kern_return.h>
  42. #include <mach/mach_types.h>
  43. //#include <kern/macro_help.h>
  44. #include <kern/lock.h>
  45. #include <kern/slab.h>
  46. #include <ipc/ipc_splay.h>
  47. #include <ipc/ipc_types.h>
  48. /*
  49. * Every task has a space of IPC capabilities.
  50. * IPC operations like send and receive use this space.
  51. * IPC kernel calls manipulate the space of the target task.
  52. *
  53. * Every space has a non-NULL is_table with is_table_size entries.
  54. * A space may have a NULL is_tree. is_tree_small records the
  55. * number of entries in the tree that, if the table were to grow
  56. * to the next larger size, would move from the tree to the table.
  57. *
  58. * is_growing marks when the table is in the process of growing.
  59. * When the table is growing, it can't be freed or grown by another
  60. * thread, because of krealloc/kmem_realloc's requirements.
  61. */
  62. typedef unsigned int ipc_space_refs_t;
  63. struct ipc_space {
  64. decl_simple_lock_data(,is_ref_lock_data)
  65. ipc_space_refs_t is_references;
  66. decl_simple_lock_data(,is_lock_data)
  67. boolean_t is_active; /* is the space alive? */
  68. boolean_t is_growing; /* is the space growing? */
  69. ipc_entry_t is_table; /* an array of entries */
  70. ipc_entry_num_t is_table_size; /* current size of table */
  71. struct ipc_table_size *is_table_next; /* info for larger table */
  72. struct ipc_splay_tree is_tree; /* a splay tree of entries */
  73. ipc_entry_num_t is_tree_total; /* number of entries in the tree */
  74. ipc_entry_num_t is_tree_small; /* # of small entries in the tree */
  75. ipc_entry_num_t is_tree_hash; /* # of hashed entries in the tree */
  76. };
  77. #define IS_NULL ((ipc_space_t) 0)
  78. extern struct gnu_kmem_cache ipc_space_cache;
  79. #define is_alloc() ((ipc_space_t) gnu_kmem_cache_alloc(&ipc_space_cache))
  80. #define is_free(is) gnu_kmem_cache_free(&ipc_space_cache, (vm_offset_t) (is))
  81. extern struct ipc_space *ipc_space_kernel;
  82. extern struct ipc_space *ipc_space_reply;
  83. #define is_ref_lock_init(is) simple_lock_init(&(is)->is_ref_lock_data)
  84. #define ipc_space_reference_macro(is) \
  85. MACRO_BEGIN \
  86. simple_lock(&(is)->is_ref_lock_data); \
  87. assert((is)->is_references > 0); \
  88. (is)->is_references++; \
  89. simple_unlock(&(is)->is_ref_lock_data); \
  90. MACRO_END
  91. #define ipc_space_release_macro(is) \
  92. MACRO_BEGIN \
  93. ipc_space_refs_t _refs; \
  94. \
  95. simple_lock(&(is)->is_ref_lock_data); \
  96. assert((is)->is_references > 0); \
  97. _refs = --(is)->is_references; \
  98. simple_unlock(&(is)->is_ref_lock_data); \
  99. \
  100. if (_refs == 0) \
  101. is_free(is); \
  102. MACRO_END
  103. #define is_lock_init(is) simple_lock_init(&(is)->is_lock_data)
  104. #define is_read_lock(is) simple_lock(&(is)->is_lock_data)
  105. #define is_read_unlock(is) simple_unlock(&(is)->is_lock_data)
  106. #define is_write_lock(is) simple_lock(&(is)->is_lock_data)
  107. #define is_write_lock_try(is) simple_lock_try(&(is)->is_lock_data)
  108. #define is_write_unlock(is) simple_unlock(&(is)->is_lock_data)
  109. #define is_write_to_read_lock(is)
  110. extern void ipc_space_reference(struct ipc_space *space);
  111. extern void ipc_space_release(struct ipc_space *space);
  112. #define is_reference(is) ipc_space_reference(is)
  113. #define is_release(is) ipc_space_release(is)
  114. kern_return_t ipc_space_create(ipc_table_size_t, ipc_space_t *);
  115. kern_return_t ipc_space_create_special(struct ipc_space **);
  116. void ipc_space_destroy(struct ipc_space *);
  117. #endif /* _IPC_IPC_SPACE_H_ */