// K2251-K2255: virtio_input.pointer — Absolute pointer koordinatı // Invariant: Range dönüşümü ekran içinde kalır // Positive: Köşe ve orta koordinat // Counterexample: Min max ters veya taşan delta // Acceptance: İmleç sınırda clipped durur pub const VIRTIO_INPUT_POINTER_SCHEMA: &str = "turkos.os.virtio_input.pointer.v1"; pub const VIRTIO_INPUT_POINTER_INVARIANT: &str = "Range dönüşümü ekran içinde kalır"; pub const VIRTIO_INPUT_POINTER_POSITIVE: &str = "Köşe ve orta koordinat"; pub const VIRTIO_INPUT_POINTER_COUNTEREXAMPLE: &str = "Min max ters veya taşan delta"; pub const VIRTIO_INPUT_POINTER_ACCEPTANCE: &str = "İmleç sınırda clipped durur"; pub const POINTER_SCREEN_WIDTH: u32 = 1280; pub const POINTER_SCREEN_HEIGHT: u32 = 800; pub const EXPECTED_CORNER_AND_MID_SAMPLES: u32 = 5; pub const EXPECTED_CLIPPED_CURSOR_X: u32 = 1279; pub const EXPECTED_CLIPPED_CURSOR_Y: u32 = 799; pub const EXPECTED_MIDPOINT_X: u32 = 640; pub const EXPECTED_MIDPOINT_Y: u32 = 400; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum InputPointerError { InvertedAxisMinMax = 1, OverflowingRelativeDelta = 2, RangeTransformOutOfScreen = 3, ViewportDimensionMismatch = 4, CornerOrMidpointMismatch = 5, CursorNotClippedAtBoundary = 6, ZeroPointerEpoch = 7, NonMonotonicPointerEpoch = 8, ZeroPointerStreamDigest = 9, UnboundInputPointerDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct InputPointerRequest { pub inverted_axis_min_max: bool, pub overflowing_relative_delta: bool, pub range_within_screen: bool, pub screen_width: u32, pub screen_height: u32, pub corner_and_mid_samples: u32, pub midpoint_x: u32, pub midpoint_y: u32, pub clipped_cursor_x: u32, pub clipped_cursor_y: u32, pub pointer_epoch: u64, pub previous_pointer_epoch: u64, pub pointer_stream_digest: u64, pub pointer_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct InputPointerReceipt { pub screen_width: u32, pub screen_height: u32, pub corner_and_mid_samples: u32, pub midpoint_x: u32, pub midpoint_y: u32, pub clipped_cursor_x: u32, pub clipped_cursor_y: u32, pub cursor_clipped_at_boundary: bool, pub pointer_epoch: u64, pub pointer_stream_digest: u64, pub receipt_digest: u64, } pub const fn compute_input_pointer_binding_digest( screen_width: u32, screen_height: u32, corner_and_mid_samples: u32, midpoint_x: u32, midpoint_y: u32, clipped_cursor_x: u32, clipped_cursor_y: u32, pointer_epoch: u64, pointer_stream_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2255_5649_4e50_5054).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (screen_width as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (screen_height as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (corner_and_mid_samples as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (midpoint_x as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (midpoint_y as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (clipped_cursor_x as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (clipped_cursor_y as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ pointer_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ pointer_stream_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct VirtioInputPointerCoordinator { committed: bool, committed_total: u64, rejected_total: u64, axis_delta_refusals: u64, range_transform_refusals: u64, clipping_refusals: u64, committed_receipt: Option, } impl VirtioInputPointerCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, axis_delta_refusals: 0, range_transform_refusals: 0, clipping_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn axis_delta_refusals(&self) -> u64 { self.axis_delta_refusals } pub fn range_transform_refusals(&self) -> u64 { self.range_transform_refusals } pub fn clipping_refusals(&self) -> u64 { self.clipping_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_pointer_coordinates( &mut self, req: &InputPointerRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(InputPointerError::AlreadyCommitted); } if req.inverted_axis_min_max { self.rejected_total += 1; self.axis_delta_refusals += 1; return Err(InputPointerError::InvertedAxisMinMax); } if req.overflowing_relative_delta { self.rejected_total += 1; self.axis_delta_refusals += 1; return Err(InputPointerError::OverflowingRelativeDelta); } if !req.range_within_screen { self.rejected_total += 1; self.range_transform_refusals += 1; return Err(InputPointerError::RangeTransformOutOfScreen); } if req.screen_width != POINTER_SCREEN_WIDTH || req.screen_height != POINTER_SCREEN_HEIGHT { self.rejected_total += 1; self.range_transform_refusals += 1; return Err(InputPointerError::ViewportDimensionMismatch); } if req.corner_and_mid_samples != EXPECTED_CORNER_AND_MID_SAMPLES || req.midpoint_x != EXPECTED_MIDPOINT_X || req.midpoint_y != EXPECTED_MIDPOINT_Y { self.rejected_total += 1; self.range_transform_refusals += 1; return Err(InputPointerError::CornerOrMidpointMismatch); } if req.clipped_cursor_x != EXPECTED_CLIPPED_CURSOR_X || req.clipped_cursor_y != EXPECTED_CLIPPED_CURSOR_Y { self.rejected_total += 1; self.clipping_refusals += 1; return Err(InputPointerError::CursorNotClippedAtBoundary); } if req.pointer_epoch == 0 { self.rejected_total += 1; return Err(InputPointerError::ZeroPointerEpoch); } if req.pointer_epoch <= req.previous_pointer_epoch { self.rejected_total += 1; return Err(InputPointerError::NonMonotonicPointerEpoch); } if req.pointer_stream_digest == 0 { self.rejected_total += 1; return Err(InputPointerError::ZeroPointerStreamDigest); } let expected_binding = compute_input_pointer_binding_digest( req.screen_width, req.screen_height, req.corner_and_mid_samples, req.midpoint_x, req.midpoint_y, req.clipped_cursor_x, req.clipped_cursor_y, req.pointer_epoch, req.pointer_stream_digest, ); if req.pointer_binding_digest != expected_binding { self.rejected_total += 1; self.clipping_refusals += 1; return Err(InputPointerError::UnboundInputPointerDigest); } self.committed = true; self.committed_total += 1; let receipt = InputPointerReceipt { screen_width: req.screen_width, screen_height: req.screen_height, corner_and_mid_samples: req.corner_and_mid_samples, midpoint_x: req.midpoint_x, midpoint_y: req.midpoint_y, clipped_cursor_x: req.clipped_cursor_x, clipped_cursor_y: req.clipped_cursor_y, cursor_clipped_at_boundary: true, pointer_epoch: req.pointer_epoch, pointer_stream_digest: req.pointer_stream_digest, receipt_digest: expected_binding ^ 0x2255_ACE0_5054_5231, }; self.committed_receipt = Some(receipt); Ok(receipt) } }