Find exception handler for given instruction offset.
(table: &[u8], offset: u32)
| 80 | |
| 81 | /// Find exception handler for given instruction offset. |
| 82 | pub fn find_exception_handler(table: &[u8], offset: u32) -> Option<ExceptionTableEntry> { |
| 83 | let mut pos = 0; |
| 84 | while pos < table.len() { |
| 85 | let start = read_varint_with_start(table, &mut pos)?; |
| 86 | let size = read_varint(table, &mut pos)?; |
| 87 | let target = read_varint(table, &mut pos)?; |
| 88 | let depth_lasti = read_varint(table, &mut pos)?; |
| 89 | |
| 90 | let end = start + size; |
| 91 | let depth = (depth_lasti >> 1) as u16; |
| 92 | let push_lasti = (depth_lasti & 1) != 0; |
| 93 | |
| 94 | if offset >= start && offset < end { |
| 95 | return Some(ExceptionTableEntry { |
| 96 | start, |
| 97 | end, |
| 98 | target, |
| 99 | depth, |
| 100 | push_lasti, |
| 101 | }); |
| 102 | } |
| 103 | } |
| 104 | None |
| 105 | } |
| 106 | |
| 107 | /// Decode all exception table entries. |
| 108 | pub fn decode_exception_table(table: &[u8]) -> Vec<ExceptionTableEntry> { |