ipc_table.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. */
  28. /*
  29. * File: ipc/ipc_table.h
  30. * Author: Rich Draves
  31. * Date: 1989
  32. *
  33. * Definitions for tables, used for IPC capabilities (ipc_entry_t)
  34. * and dead-name requests (ipc_port_request_t).
  35. */
  36. #ifndef _IPC_IPC_TABLE_H_
  37. #define _IPC_IPC_TABLE_H_
  38. #include <mach/boolean.h>
  39. #include <mach/vm_param.h>
  40. /*
  41. * The is_table_next field of an ipc_space_t points to
  42. * an ipc_table_size structure. These structures must
  43. * be elements of an array, ipc_table_entries.
  44. *
  45. * The array must end with two elements with the same its_size value.
  46. * Except for the terminating element, the its_size values must
  47. * be strictly increasing. The largest (last) its_size value
  48. * must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
  49. * This ensures that
  50. * 1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
  51. * in the table, so ipc_entry_get won't allocate it.
  52. * 2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
  53. * won't ever overflow.
  54. *
  55. *
  56. * The ipr_size field of the first element in a table of
  57. * dead-name requests (ipc_port_request_t) points to the
  58. * ipc_table_size structure. The structures must be elements
  59. * of ipc_table_dnrequests. ipc_table_dnrequests must end
  60. * with an element with zero its_size, and except for this last
  61. * element, the its_size values must be strictly increasing.
  62. *
  63. * The is_table_next field points to the ipc_table_size structure
  64. * for the next larger size of table, not the one currently in use.
  65. * The ipr_size field points to the currently used ipc_table_size.
  66. */
  67. typedef unsigned int ipc_table_index_t; /* index into tables */
  68. typedef unsigned int ipc_table_elems_t; /* size of tables */
  69. typedef struct ipc_table_size {
  70. ipc_table_elems_t its_size; /* number of elements in table */
  71. } *ipc_table_size_t;
  72. #define ITS_NULL ((ipc_table_size_t) 0)
  73. extern ipc_table_size_t ipc_table_entries;
  74. extern ipc_table_size_t ipc_table_dnrequests;
  75. extern void
  76. ipc_table_init(void);
  77. /*
  78. * Note that ipc_table_alloc, ipc_table_realloc, and ipc_table_free
  79. * all potentially use the VM system. Hence simple locks can't
  80. * be held across them.
  81. *
  82. * We can't use a copying realloc, because the realloc happens
  83. * with the data unlocked. ipc_table_realloc remaps the data,
  84. * so it is OK.
  85. */
  86. /* Allocate a table */
  87. extern vm_offset_t ipc_table_alloc(
  88. vm_size_t size);
  89. /* Reallocate a big table */
  90. extern vm_offset_t ipc_table_realloc(
  91. vm_size_t old_size,
  92. vm_offset_t old_table,
  93. vm_size_t new_size);
  94. /* Free a table */
  95. extern void ipc_table_free(
  96. vm_size_t size,
  97. vm_offset_t table);
  98. #define it_entries_alloc(its) \
  99. ((ipc_entry_t) \
  100. ipc_table_alloc((its)->its_size * sizeof(struct ipc_entry)))
  101. #define it_entries_reallocable(its) \
  102. (((its)->its_size * sizeof(struct ipc_entry)) >= PAGE_SIZE)
  103. #define it_entries_realloc(its, table, nits) \
  104. ((ipc_entry_t) \
  105. ipc_table_realloc((its)->its_size * sizeof(struct ipc_entry), \
  106. (vm_offset_t)(table), \
  107. (nits)->its_size * sizeof(struct ipc_entry)))
  108. #define it_entries_free(its, table) \
  109. ipc_table_free((its)->its_size * sizeof(struct ipc_entry), \
  110. (vm_offset_t)(table))
  111. #define it_dnrequests_alloc(its) \
  112. ((ipc_port_request_t) \
  113. ipc_table_alloc((its)->its_size * \
  114. sizeof(struct ipc_port_request)))
  115. #define it_dnrequests_free(its, table) \
  116. ipc_table_free((its)->its_size * \
  117. sizeof(struct ipc_port_request), \
  118. (vm_offset_t)(table))
  119. #endif /* _IPC_IPC_TABLE_H_ */