zakhar_azg

Untitled

Nov 9th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. fn combine(curr: ElfRange, next: ElfRange) -> Result<(Option<PageRange>, Option<PageRange>, ElfRange)> {
  2. validate_order(&curr, &next)?;
  3.  
  4. let curr_block = curr.memory;
  5. let curr_aligned_block = curr.memory.enclosing();
  6.  
  7. let next_block = next.memory;
  8. let next_aligned_block = next.memory.enclosing();
  9.  
  10. if curr_block.start_address() > next_block.start_address() {
  11. return Err(Error::InvalidArgument);
  12. }
  13.  
  14. if curr_aligned_block.is_disjoint(next_aligned_block) {
  15. return Ok((Some(PageRange{flags:curr.flags, memory:curr_aligned_block}), None, ElfRange{file_range: 0..0, flags:next.flags, memory:next.memory}))
  16. }
  17.  
  18. let intersection = curr_aligned_block.intersection(next_aligned_block);
  19.  
  20. let mut curr_minus_next_range= None;
  21.  
  22. if curr_aligned_block.ne(&intersection) {
  23. curr_minus_next_range = Some(PageRange{flags: curr.flags, memory: Block::<Page>::from_index(curr_aligned_block.start(), intersection.start())?});
  24. }
  25.  
  26. if next.memory.end_address()? >= intersection.end_address()? {
  27. return Ok(
  28. (
  29. curr_minus_next_range,
  30. Some(PageRange{flags: combine_flags(curr.flags, next.flags), memory:intersection}),
  31. ElfRange{file_range: 0..0, flags: next.flags, memory: Block::new(intersection.end_address()?, next.memory.end_address()?)?}
  32. )
  33. )
  34. } else {
  35. return Ok(
  36. (
  37. curr_minus_next_range,
  38. None,
  39. ElfRange{file_range: 0..0, flags: combine_flags(curr.flags, next.flags), memory: Block::new(intersection.start_address(), next.memory.end_address()?)?}
  40. )
  41. )
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment