msg-header.lisp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ;; Different masks to the message header.
  2. (defconstant +msgh-bits-zero+ #x00000000)
  3. (defconstant +msgh-bits-remote-mask+ #x000000ff)
  4. (defconstant +msgh-bits-local-mask+ #x0000ff00)
  5. (defconstant +msgh-bits-complex+ #x80000000)
  6. (defconstant +msgh-bits-unused+ #x07ff0000)
  7. (defconstant +msgh-bits-ports-mask+
  8. (boole boole-ior
  9. +msgh-bits-remote-mask+
  10. +msgh-bits-local-mask+))
  11. ;; The message header structure as in C.
  12. (defcstruct msg-header
  13. (bits msg-bits)
  14. (size msg-size)
  15. (remote-port port)
  16. (local-port port)
  17. (seqno port-seqno)
  18. (id msg-id))
  19. (defconstant +msg-header-size+ (foreign-type-size msg-header) "Size in bytes of a message header.")
  20. ;; Be really sure.
  21. (assert (= 24 +msg-header-size+))
  22. (defun %set-header-value! (header what val)
  23. "Set a specific header slot."
  24. (setf (foreign-slot-value header msg-header what) val))
  25. (defun header-set-bits! (header val)
  26. "Set the bits header field."
  27. (%set-header-value! header 'bits val))
  28. (defun header-set-size! (header val)
  29. "Set the message size."
  30. (%set-header-value! header 'size val))
  31. (defun header-set-local-port! (header val)
  32. "Set the header local port."
  33. (%set-header-value! header 'local-port val))
  34. (defun header-set-remote-port! (header val)
  35. "Set the header remote port."
  36. (%set-header-value! header 'remote-port val))
  37. (defun header-set-id! (header val)
  38. "Set header message ID."
  39. (%set-header-value! header 'id val))
  40. (defun %header-get-value (header what)
  41. "Get a specific slot from a message header."
  42. (foreign-slot-value header msg-header what))
  43. (defun header-get-id (header)
  44. "Get message id of this message."
  45. (%header-get-value header 'id))
  46. (defun header-get-local-port (header)
  47. "Get local port of the message."
  48. (%header-get-value header 'local-port))
  49. (defun header-get-remote-port (header)
  50. "Get remove port of the message."
  51. (%header-get-value header 'remote-port))
  52. (defun header-get-size (header)
  53. "Get size of message."
  54. (%header-get-value header 'size))
  55. (defun msgh-bits-remote (type-name)
  56. "Same thing as MACH_MSGH_BITS_LOCAL."
  57. (boole boole-and
  58. +msgh-bits-remote-mask+
  59. (translate-msg-type-name-symbol type-name)))
  60. (defun msgh-bits-local (type-name)
  61. "Same thing as MACH_MSGH_BITS_LOCAL."
  62. (ash (boole boole-and +msgh-bits-local-mask+
  63. (translate-msg-type-name-symbol type-name))
  64. -8))
  65. (defun msgh-bits (remote local)
  66. "Same thing as MACH_MSGH_BITS."
  67. (boole boole-ior
  68. (msgh-bits-remote remote)
  69. (ash (msgh-bits-local local) 8)))