ipc_object.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * File: ipc/ipc_object.h
  28. * Author: Rich Draves
  29. * Date: 1989
  30. *
  31. * Definitions for IPC objects, for which tasks have capabilities.
  32. */
  33. #ifndef _IPC_IPC_OBJECT_H_
  34. #define _IPC_IPC_OBJECT_H_
  35. #include <mach/kern_return.h>
  36. #include <mach/message.h>
  37. #include <ipc/ipc_types.h>
  38. #include <kern/lock.h>
  39. #include <kern/macros.h>
  40. #include <kern/slab.h>
  41. typedef unsigned int ipc_object_refs_t;
  42. typedef unsigned int ipc_object_bits_t;
  43. typedef unsigned int ipc_object_type_t;
  44. typedef struct ipc_object {
  45. decl_simple_lock_data(,io_lock_data)
  46. ipc_object_refs_t io_references;
  47. ipc_object_bits_t io_bits;
  48. } *ipc_object_t;
  49. #define IO_NULL ((ipc_object_t) 0)
  50. #define IO_DEAD ((ipc_object_t) -1)
  51. #define IO_VALID(io) (((io) != IO_NULL) && ((io) != IO_DEAD))
  52. #define IO_BITS_KOTYPE 0x0000ffff /* used by the object */
  53. #define IO_BITS_OTYPE 0x3fff0000 /* determines a cache */
  54. /* The following masks are used to store attributes of ipc ports. */
  55. #define IO_BITS_PROTECTED_PAYLOAD 0x40000000 /* pp set? */
  56. #define IO_BITS_ACTIVE 0x80000000U /* is object alive? */
  57. #define io_active(io) ((int)(io)->io_bits < 0) /* hack */
  58. #define io_otype(io) (((io)->io_bits & IO_BITS_OTYPE) >> 16)
  59. #define io_kotype(io) ((io)->io_bits & IO_BITS_KOTYPE)
  60. #define io_makebits(active, otype, kotype) \
  61. (((active) ? IO_BITS_ACTIVE : 0) | ((otype) << 16) | (kotype))
  62. /*
  63. * Object types: ports, port sets, kernel-loaded ports
  64. */
  65. #define IOT_PORT 0
  66. #define IOT_PORT_SET 1
  67. #define IOT_NUMBER 2 /* number of types used */
  68. extern struct gnu_kmem_cache ipc_object_caches[IOT_NUMBER];
  69. #define io_alloc(otype) \
  70. ((ipc_object_t) gnu_kmem_cache_alloc(&ipc_object_caches[(otype)]))
  71. #define io_free(otype, io) \
  72. gnu_kmem_cache_free(&ipc_object_caches[(otype)], (vm_offset_t) (io))
  73. #define io_lock_init(io) simple_lock_init(&(io)->io_lock_data)
  74. #define io_lock(io) simple_lock(&(io)->io_lock_data)
  75. #define io_lock_try(io) simple_lock_try(&(io)->io_lock_data)
  76. #define io_unlock(io) simple_unlock(&(io)->io_lock_data)
  77. #define io_check_unlock(io) \
  78. MACRO_BEGIN \
  79. ipc_object_refs_t _refs = (io)->io_references; \
  80. \
  81. io_unlock(io); \
  82. if (_refs == 0) \
  83. io_free(io_otype(io), io); \
  84. MACRO_END
  85. #define io_reference(io) \
  86. MACRO_BEGIN \
  87. (io)->io_references++; \
  88. MACRO_END
  89. #define io_release(io) \
  90. MACRO_BEGIN \
  91. (io)->io_references--; \
  92. MACRO_END
  93. extern void
  94. ipc_object_reference(ipc_object_t);
  95. extern void
  96. ipc_object_release(ipc_object_t);
  97. extern kern_return_t
  98. ipc_object_translate(ipc_space_t, mach_port_t,
  99. mach_port_right_t, ipc_object_t *);
  100. extern kern_return_t
  101. ipc_object_alloc_dead(ipc_space_t, mach_port_t *);
  102. extern kern_return_t
  103. ipc_object_alloc_dead_name(ipc_space_t, mach_port_t);
  104. extern kern_return_t
  105. ipc_object_alloc(ipc_space_t, ipc_object_type_t,
  106. mach_port_type_t, mach_port_urefs_t,
  107. mach_port_t *, ipc_object_t *);
  108. extern kern_return_t
  109. ipc_object_alloc_name(ipc_space_t, ipc_object_type_t,
  110. mach_port_type_t, mach_port_urefs_t,
  111. mach_port_t, ipc_object_t *);
  112. extern mach_msg_type_name_t
  113. ipc_object_copyin_type(mach_msg_type_name_t);
  114. extern kern_return_t
  115. ipc_object_copyin(ipc_space_t, mach_port_t,
  116. mach_msg_type_name_t, ipc_object_t *);
  117. extern void
  118. ipc_object_copyin_from_kernel(ipc_object_t, mach_msg_type_name_t);
  119. extern void
  120. ipc_object_destroy(ipc_object_t, mach_msg_type_name_t);
  121. extern kern_return_t
  122. ipc_object_copyout(ipc_space_t, ipc_object_t,
  123. mach_msg_type_name_t, boolean_t, mach_port_t *);
  124. extern kern_return_t
  125. ipc_object_copyout_name(ipc_space_t, ipc_object_t,
  126. mach_msg_type_name_t, boolean_t, mach_port_t);
  127. extern void
  128. ipc_object_copyout_dest(ipc_space_t, ipc_object_t,
  129. mach_msg_type_name_t, mach_port_t *);
  130. extern kern_return_t
  131. ipc_object_rename(ipc_space_t, mach_port_t, mach_port_t);
  132. extern void
  133. ipc_object_print(ipc_object_t);
  134. #endif /* _IPC_IPC_OBJECT_H_ */