Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn combine(curr: ElfRange, next: ElfRange) -> Result<(Option<PageRange>, Option<PageRange>, ElfRange)> {
- validate_order(&curr, &next)?;
- let curr_block = curr.memory;
- let curr_aligned_block = curr.memory.enclosing();
- let next_block = next.memory;
- let next_aligned_block = next.memory.enclosing();
- if curr_block.start_address() > next_block.start_address() {
- return Err(Error::InvalidArgument);
- }
- if curr_aligned_block.is_disjoint(next_aligned_block) {
- return Ok((Some(PageRange{flags:curr.flags, memory:curr_aligned_block}), None, ElfRange{file_range: 0..0, flags:next.flags, memory:next.memory}))
- }
- let intersection = curr_aligned_block.intersection(next_aligned_block);
- let mut curr_minus_next_range= None;
- if curr_aligned_block.ne(&intersection) {
- curr_minus_next_range = Some(PageRange{flags: curr.flags, memory: Block::<Page>::from_index(curr_aligned_block.start(), intersection.start())?});
- }
- if next.memory.end_address()? >= intersection.end_address()? {
- return Ok(
- (
- curr_minus_next_range,
- Some(PageRange{flags: combine_flags(curr.flags, next.flags), memory:intersection}),
- ElfRange{file_range: 0..0, flags: next.flags, memory: Block::new(intersection.end_address()?, next.memory.end_address()?)?}
- )
- )
- } else {
- return Ok(
- (
- curr_minus_next_range,
- None,
- ElfRange{file_range: 0..0, flags: combine_flags(curr.flags, next.flags), memory: Block::new(intersection.start_address(), next.memory.end_address()?)?}
- )
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment