Skip to content

Commit aaac8e6

Browse files
dreamliner787-9Ivan-Velickovic
authored andcommitted
tool: fix memory ranges overlapping checks
Previously, ranges_overlap() returns true if two inclusive ranges overlap. But builder.rs was passing half-open ranges which caused the tool to report that two memory regions are overlapping when in reality they were not. This commit changed ranges_overlap() to work on half-open ranges instead Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
1 parent 1c2ad53 commit aaac8e6

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

tool/microkit/src/sdf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,11 +1845,11 @@ pub fn parse(filename: &str, xml: &str, config: &Config) -> Result<SystemDescrip
18451845
for pd in &pds {
18461846
for this_ioport in &pd.ioports {
18471847
for (seen_pd_name, seen_ioport) in &seen_ioports {
1848-
let left_range = this_ioport.addr..this_ioport.addr + this_ioport.size - 1;
1849-
let right_range = seen_ioport.addr..seen_ioport.addr + seen_ioport.size - 1;
1848+
let left_range = this_ioport.addr..this_ioport.addr + this_ioport.size;
1849+
let right_range = seen_ioport.addr..seen_ioport.addr + seen_ioport.size;
18501850
if ranges_overlap(&left_range, &right_range) {
18511851
return Err(format!(
1852-
"Error: I/O port id: {}, inclusive range: [{:#x}, {:#x}] in protection domain: '{}' @ {}:{}:{} overlaps with I/O port id: {}, inclusive range: [{:#x}, {:#x}] in protection domain: '{}' @ {}:{}:{}",
1852+
"Error: I/O port id: {}, half-open range: [{:#x}, {:#x}) in protection domain: '{}' @ {}:{}:{} overlaps with I/O port id: {}, half-open range: [{:#x}, {:#x}) in protection domain: '{}' @ {}:{}:{}",
18531853
this_ioport.id,
18541854
left_range.start,
18551855
left_range.end,

tool/microkit/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ pub fn mask(n: u64) -> u64 {
6868
(1 << n) - 1
6969
}
7070

71-
/// Returns true if two ranges overlap.
71+
/// Returns true if two [x..y) ranges overlap.
7272
pub fn ranges_overlap<T: PartialOrd>(left: &Range<T>, right: &Range<T>) -> bool {
73-
left.start <= right.end && right.start <= left.end
73+
!(left.end <= right.start || right.end <= left.start)
7474
}
7575

7676
/// Product a 'human readable' string for the size.

tool/microkit/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,15 @@ mod protection_domain {
533533
fn test_overlapping_x86_io_ports_1() {
534534
check_error(&DEFAULT_X86_64_KERNEL_CONFIG,
535535
"pd_overlapping_x86_io_ports_1.system",
536-
"Error: I/O port id: 1, inclusive range: [0x3ff, 0x406] in protection domain: 'test1' @ pd_overlapping_x86_io_ports_1.system:8:5 overlaps with I/O port id: 0, inclusive range: [0x3f8, 0x3ff] in protection domain: 'test1' @ pd_overlapping_x86_io_ports_1.system:8:5"
536+
"Error: I/O port id: 1, half-open range: [0x3ff, 0x407) in protection domain: 'test1' @ pd_overlapping_x86_io_ports_1.system:8:5 overlaps with I/O port id: 0, half-open range: [0x3f8, 0x400) in protection domain: 'test1' @ pd_overlapping_x86_io_ports_1.system:8:5"
537537
)
538538
}
539539

540540
#[test]
541541
fn test_overlapping_x86_io_ports_2() {
542542
check_error(&DEFAULT_X86_64_KERNEL_CONFIG,
543543
"pd_overlapping_x86_io_ports_2.system",
544-
"Error: I/O port id: 0, inclusive range: [0x3ff, 0x406] in protection domain: 'test2' @ pd_overlapping_x86_io_ports_2.system:13:5 overlaps with I/O port id: 0, inclusive range: [0x3f8, 0x3ff] in protection domain: 'test1' @ pd_overlapping_x86_io_ports_2.system:8:5"
544+
"Error: I/O port id: 0, half-open range: [0x3ff, 0x407) in protection domain: 'test2' @ pd_overlapping_x86_io_ports_2.system:13:5 overlaps with I/O port id: 0, half-open range: [0x3f8, 0x400) in protection domain: 'test1' @ pd_overlapping_x86_io_ports_2.system:8:5"
545545
)
546546
}
547547

0 commit comments

Comments
 (0)