MCPcopy Create free account
hub / github.com/MultiFuzz/MultiFuzz / resize_loads

Method resize_loads

hail-fuzz/src/load_resizer.rs:124–166  ·  view source on GitHub ↗

Applies resize operations to all loads where upper bits are unused. Note: this approach is unable to remove unused low bits from the operation, to allow the starting address to always remains the same.

(
        &mut self,
        cpu: &mut Cpu,
        code: &mut BlockTable,
        block: usize,
    )

Source from the content-addressed store, hash-verified

122 /// unable to remove unused low bits from the operation, to allow the starting address to
123 /// always remains the same.
124 pub fn resize_loads(
125 &mut self,
126 cpu: &mut Cpu,
127 code: &mut BlockTable,
128 block: usize,
129 ) -> Result<bool, Error> {
130 self.compute_load_usage(cpu, code, block)?;
131 let pcode = &mut code.blocks[block].pcode;
132
133 // Early exit if there are no loads to resize.
134 if !self
135 .state
136 .loads
137 .values()
138 .any(|x| x.required_bytes() < pcode.instructions[x.offset].output.size)
139 {
140 return Ok(false);
141 }
142
143 let mut new_block = pcode::Block::new();
144 pcode.recompute_next_tmp();
145 new_block.next_tmp = pcode.next_tmp;
146
147 let mut current_pc = 0;
148 for (idx, stmt) in pcode.instructions.iter().enumerate() {
149 if stmt.op == pcode::Op::InstructionMarker {
150 current_pc = stmt.inputs.first().as_u64();
151 }
152
153 let Some(metadata) = self.state.loads.values().find(|x| x.offset == idx)
154 else {
155 new_block.push(*stmt);
156 continue;
157 };
158
159 tracing::info!("[{current_pc:#x}] adjusting load",);
160 push_with_resize(&mut new_block, *stmt, *metadata);
161 }
162
163 *pcode = new_block;
164
165 Ok(true)
166 }
167
168 fn calculate_used_bits(
169 &mut self,

Callers 1

injectMethod · 0.80

Calls 3

push_with_resizeFunction · 0.85
compute_load_usageMethod · 0.80
required_bytesMethod · 0.45

Tested by

no test coverage detected