port.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/port.h
  33. * Author: Rich Draves
  34. * Date: 1989
  35. *
  36. * Implementation specific complement to mach/port.h.
  37. */
  38. #ifndef _IPC_PORT_H_
  39. #define _IPC_PORT_H_
  40. #include <mach/port.h>
  41. /*
  42. * mach_port_t must be an unsigned type. Port values
  43. * have two parts, a generation number and an index.
  44. * These macros encapsulate all knowledge of how
  45. * a mach_port_t is laid out.
  46. *
  47. * If the size of generation numbers changes,
  48. * be sure to update IE_BITS_GEN_MASK and friends
  49. * in ipc/ipc_entry.h.
  50. */
  51. #if PORT_GENERATIONS
  52. #define MACH_PORT_INDEX(name) ((name) >> 8)
  53. #define MACH_PORT_GEN(name) (((name) & 0xff) << 24)
  54. #define MACH_PORT_MAKE(index, gen) (((index) << 8) | ((gen) >> 24))
  55. #else
  56. #define MACH_PORT_INDEX(name) (name)
  57. #define MACH_PORT_GEN(name) 0
  58. #define MACH_PORT_MAKE(index, gen) (index)
  59. #endif
  60. #define MACH_PORT_NGEN(name) MACH_PORT_MAKE(0, MACH_PORT_GEN(name))
  61. #define MACH_PORT_MAKEB(index, bits) MACH_PORT_MAKE(index, IE_BITS_GEN(bits))
  62. /*
  63. * Typedefs for code cleanliness. These must all have
  64. * the same (unsigned) type as mach_port_t.
  65. */
  66. typedef mach_port_t mach_port_index_t; /* index values */
  67. typedef mach_port_t mach_port_gen_t; /* generation numbers */
  68. #define MACH_PORT_UREFS_MAX ((mach_port_urefs_t) ((1 << 16) - 1))
  69. #define MACH_PORT_UREFS_OVERFLOW(urefs, delta) \
  70. (((delta) > 0) && \
  71. ((((urefs) + (delta)) <= (urefs)) || \
  72. (((urefs) + (delta)) > MACH_PORT_UREFS_MAX)))
  73. #define MACH_PORT_UREFS_UNDERFLOW(urefs, delta) \
  74. (((delta) < 0) && (-(delta) > (urefs)))
  75. #endif /* _IPC_PORT_H_ */