| 63 | } |
| 64 | |
| 65 | fn find_runtime_function(addr: u32, function_list: &[RUNTIME_FUNCTION]) -> Option<&RUNTIME_FUNCTION> { |
| 66 | let index = function_list.binary_search_by(|func| func.BeginAddress.cmp(&addr)); |
| 67 | |
| 68 | match index { |
| 69 | // Exact match |
| 70 | Ok(pos) => function_list.get(pos), |
| 71 | // Inexact match |
| 72 | Err(pos) => { |
| 73 | if pos > 0 && function_list.get(pos - 1).map_or(false, |func| func.BeginAddress <= addr && addr < func.EndAddress) { |
| 74 | function_list.get(pos - 1) |
| 75 | } else if pos < function_list.len() && function_list.get(pos).map_or(false, |func| func.BeginAddress <= addr && addr < func.EndAddress) { |
| 76 | function_list.get(pos) |
| 77 | } else { |
| 78 | None |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Splits an integer up that represents bitfields so that each field can be stored in a tuple. Specify the |
| 85 | // size of the fields from low bits to high bits. For instance, let (x, y, z) = split_up!(q => 3, 6, 7) will put the low 3 bits into x |