signature.rs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //! Command signatures: the record layout of indirect execution. Kept for
  2. //! translating it later.
  3. #![allow(clippy::not_unsafe_ptr_arg_deref)]
  4. use crate::object::{
  5. self, COMMAND_SIGNATURE, E_INVALIDARG, HRESULT, Iid, Object, Table, This, guid,
  6. };
  7. use crate::resource::PAGEABLE_IIDS;
  8. const SIGNATURE_IIDS: [Iid; 4] = [
  9. guid(
  10. 0xc36a797c,
  11. 0xec80,
  12. 0x4f0a,
  13. [0x89, 0x85, 0xa7, 0xb2, 0x47, 0x50, 0x82, 0xd1],
  14. ),
  15. PAGEABLE_IIDS[0],
  16. PAGEABLE_IIDS[1],
  17. PAGEABLE_IIDS[2],
  18. ];
  19. #[repr(C)]
  20. pub(crate) struct Desc {
  21. stride: u32,
  22. count: u32,
  23. /// Each a type and up to three 32-bit fields.
  24. arguments: *const [u32; 4],
  25. nodes: u32,
  26. }
  27. #[repr(C)]
  28. struct Signature {
  29. object: Object,
  30. stride: u32,
  31. arguments: Vec<[u32; 4]>,
  32. }
  33. /// Device method.
  34. pub(crate) extern "system" fn create(
  35. _: This,
  36. desc: *const Desc,
  37. _root: This,
  38. iid: *const Iid,
  39. out: *mut This,
  40. ) -> HRESULT {
  41. // SAFETY: the title passes a description (null is tolerated).
  42. let Some(desc) = (unsafe { desc.as_ref() }) else {
  43. return E_INVALIDARG;
  44. };
  45. if desc.arguments.is_null() && desc.count > 0 {
  46. return E_INVALIDARG;
  47. }
  48. let arguments = if desc.count == 0 {
  49. Vec::new()
  50. } else {
  51. // SAFETY: the title passes `count` argument descriptions.
  52. unsafe { std::slice::from_raw_parts(desc.arguments, desc.count as usize) }.to_vec()
  53. };
  54. tracing::debug!(stride = desc.stride, ?arguments, "command signature");
  55. let signature = Box::new(Signature {
  56. object: Object::new(&FUNCTIONS),
  57. stride: desc.stride,
  58. arguments,
  59. });
  60. object::hand_out(COMMAND_SIGNATURE, signature, iid, &SIGNATURE_IIDS, out)
  61. }
  62. /// A signature's record stride and arguments (type, then up to three
  63. /// fields each).
  64. pub(crate) fn layout<'a>(this: This) -> Option<(u32, &'a [[u32; 4]])> {
  65. if this.is_null() {
  66. return None;
  67. }
  68. // SAFETY: the title passes one of our signatures.
  69. let s = unsafe { &*this.cast::<Signature>() };
  70. Some((s.stride, &s.arguments))
  71. }
  72. extern "system" fn query(this: This, iid: *const Iid, out: *mut This) -> HRESULT {
  73. let found = object::is(iid, &SIGNATURE_IIDS).then_some(this);
  74. object::answer(COMMAND_SIGNATURE, iid, found, out)
  75. }
  76. extern "system" fn release(this: This) -> u32 {
  77. object::release_boxed::<Signature>(this)
  78. }
  79. /// IUnknown 3, object 4, device child 1.
  80. static FUNCTIONS: Table<24> = {
  81. let mut f = object::d3d12_object(object::missing_table::<COMMAND_SIGNATURE, 24>());
  82. f[0] = query as *const ();
  83. f[2] = release as *const ();
  84. f[7] = object::parent_device as *const (); // 0x38
  85. Table(f)
  86. };