Implemented catchall in ::EntryPoint

This commit is contained in:
vegowotenks 2024-11-12 13:29:01 +01:00
parent 6b03cab14d
commit f5428c79b2
3 changed files with 109 additions and 8 deletions

View file

@ -391,6 +391,23 @@ impl JavaClassFile {
},
}
}
pub fn is_method_bytecode_protected(&self, method: &MethodInfo, instruction_pointer: u16, exception: crate::heap_area::ObjectReference) -> bool {
let code_attribute = method.get_code_attribute().unwrap();
for exception_entry in &code_attribute.exception_table {
if exception_entry.start_pc <= instruction_pointer && exception_entry.end_pc > instruction_pointer {
if exception_entry.catch_type == 0 {
return true;
} else {
// Check catch-type
todo!()
}
}
}
false
}
}
#[derive(Debug)]
@ -500,10 +517,10 @@ impl LineNumberTableAttributeData {
#[derive(Debug)]
pub struct ExceptionTableEntry {
start_pc: u16,
end_pc: u16,
handler_pc: u16,
catch_type: u16,
pub start_pc: u16,
pub end_pc: u16,
pub handler_pc: u16,
pub catch_type: u16,
}
impl ExceptionTableEntry {
@ -517,6 +534,10 @@ impl ExceptionTableEntry {
}
)
}
fn catches_in(&self, instruction_pointer: u16) -> bool {
return self.start_pc <= instruction_pointer && self.end_pc > instruction_pointer
}
}
#[derive(Debug)]
@ -1128,6 +1149,20 @@ impl MethodInfo {
None
};
}
pub fn is_native(&self) -> bool {
return self.access_flags & MethodAccessFlag::Native;
}
pub fn get_protected_handler_pc(&self, instruction_pointer: u16) -> Option<u16> {
for exception_entry in &self.get_code_attribute()?.exception_table {
if exception_entry.catches_in(instruction_pointer) {
return Some(exception_entry.handler_pc)
}
}
None
}
}