Performs the out-of-bounds check and returns the heap address if the access criteria is in bounds.
(
masm: &mut M,
context: &mut CodeGenContext<Emission>,
ptr_size: OperandSize,
heap: &HeapData,
enable_spectre_mitigation: bool,
bounds: Bounds,
index: Index,
offset: I
| 153 | /// Performs the out-of-bounds check and returns the heap address if the access |
| 154 | /// criteria is in bounds. |
| 155 | pub(crate) fn load_heap_addr_checked<M, F>( |
| 156 | masm: &mut M, |
| 157 | context: &mut CodeGenContext<Emission>, |
| 158 | ptr_size: OperandSize, |
| 159 | heap: &HeapData, |
| 160 | enable_spectre_mitigation: bool, |
| 161 | bounds: Bounds, |
| 162 | index: Index, |
| 163 | offset: ImmOffset, |
| 164 | mut emit_check_condition: F, |
| 165 | ) -> Result<Reg> |
| 166 | where |
| 167 | M: MacroAssembler, |
| 168 | F: FnMut(&mut M, Bounds, Index) -> Result<IntCmpKind>, |
| 169 | { |
| 170 | let cmp_kind = emit_check_condition(masm, bounds, index)?; |
| 171 | |
| 172 | masm.trapif(cmp_kind, TrapCode::HEAP_OUT_OF_BOUNDS)?; |
| 173 | let addr = context.any_gpr(masm)?; |
| 174 | |
| 175 | load_heap_addr_unchecked(masm, heap, index, offset, addr, ptr_size)?; |
| 176 | if !enable_spectre_mitigation { |
| 177 | Ok(addr) |
| 178 | } else { |
| 179 | // Conditionally assign 0 to the register holding the base address if |
| 180 | // the comparison kind is met. |
| 181 | let tmp = context.any_gpr(masm)?; |
| 182 | masm.mov(writable!(tmp), RegImm::i64(0), ptr_size)?; |
| 183 | let cmp_kind = emit_check_condition(masm, bounds, index)?; |
| 184 | masm.cmov(writable!(addr), tmp, cmp_kind, ptr_size)?; |
| 185 | context.free_reg(tmp); |
| 186 | Ok(addr) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /// Load the requested heap address into the specified destination register. |
| 191 | /// This function doesn't perform any bounds checks and assumes the caller |
no test coverage detected