⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

bounds_mask

Function bounds_mask 

Source
pub fn bounds_mask(index: usize, size: usize) -> usize
Expand description

Branchless bounds mask for Spectre v1 mitigation.

Returns a mask that is all-ones if index < size and all-zeros otherwise. The comparison is performed without a branch, so mis-speculation cannot bypass the bounds check.

§Usage

let safe_idx = index & bounds_mask(index, arr.len());
let value = arr[safe_idx]; // safe even under mis-speculation