mquire 1.2.7

Memory forensics and analysis tool for querying Linux kernel memory dumps using SQL
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
//
// Copyright (c) 2025-present, Trail of Bits, Inc.
// All rights reserved.
//
// This source code is licensed in accordance with the terms specified in
// the LICENSE file found in the root directory of this source tree.
//

use crate::{
    architecture::intel::page_table_entry::{
        PageTableEntry, PageTableLevel, SHIFT_PD_INDEX, SHIFT_PDPT_INDEX, SHIFT_PML4_INDEX,
        SHIFT_PT_INDEX,
    },
    core::{
        architecture::{Architecture, Bitness, Endianness, PhysicalAddressRange, Region},
        error::{Error, ErrorKind, Result},
    },
    memory::{
        primitives::{PhysicalAddress, RawVirtualAddress},
        readable::Readable,
        virtual_address::VirtualAddress,
    },
    utils::reader::Reader,
};

use std::sync::Arc;

/// The size, in bytes, of a page directory
const PAGE_DIRECTORY_SIZE: u64 = 4096;

/// Implements the Intel x86_64 architecture features for the Architecture trait
#[derive(Default)]
pub struct IntelArchitecture {}

impl IntelArchitecture {
    /// Creates a new IntelArchitecture instance
    pub fn new() -> Arc<Self> {
        Arc::new(Self {})
    }

    /// Returns the table entries for a given table offset
    fn get_table_entries(
        readable: &dyn Readable,
        mut table_offset: PhysicalAddress,
        table_level: PageTableLevel,
    ) -> Result<Vec<PageTableEntry>> {
        let reader = Reader::new(readable, true);
        let mut page_table = Vec::with_capacity(512);

        for _ in 0..512 {
            let qword = reader.read_u64(table_offset)?;
            page_table.push(PageTableEntry::new(table_level, qword)?);

            table_offset = table_offset + 8usize;
        }

        Ok(page_table)
    }

    /// Returns the physical address range for a given virtual address
    fn virtual_address_to_physical_address(
        readable: &dyn Readable,
        virtual_address: VirtualAddress,
    ) -> Result<PhysicalAddressRange> {
        let raw_virtual_addr = virtual_address.value();
        let decomposed_vaddr = PageTableEntry::decompose_virtual_address(raw_virtual_addr.value());

        let reader = Reader::new(readable, true);
        let raw_table_entry = reader.read_u64(
            virtual_address.root_page_table() + decomposed_vaddr.pml4.page_table_index * 8,
        )?;

        let page_directory = if let PageTableEntry::PageDirectory(page_directory) =
            PageTableEntry::new(PageTableLevel::Pml4, raw_table_entry)?
        {
            page_directory
        } else {
            return Err(Error::new(
                ErrorKind::InvalidPageTableEntry,
                "The PML4 table entry does not point to a page directory",
            ));
        };

        if !page_directory.present {
            return Err(Error::new(
                ErrorKind::MemoryNotMapped,
                "The page directory pointed to by the PML4 table is not mapped",
            ));
        }

        let directory_address: PhysicalAddress = page_directory.physical_address.into();
        let raw_table_entry =
            reader.read_u64(directory_address + decomposed_vaddr.pdpt.page_table_index * 8)?;

        let page_table_entry = PageTableEntry::new(PageTableLevel::Pdpt, raw_table_entry)?;
        if !page_table_entry.present() {
            return Err(Error::new(
                ErrorKind::MemoryNotMapped,
                "The page or page directory pointed to by the PDPT table is not mapped",
            ));
        }

        let raw_table_entry = match page_table_entry {
            PageTableEntry::Page(page) => {
                let page_section = decomposed_vaddr.pdpt.page_section.ok_or(Error::new(
                    ErrorKind::MemoryNotMapped,
                    "Missing page section data in the decomposed PDPT entry",
                ))?;

                let page_address: PhysicalAddress = page.physical_address.into();

                return Ok(PhysicalAddressRange::new(
                    page_address + page_section.offset,
                    page_section.size,
                ));
            }

            PageTableEntry::PageDirectory(directory) => {
                let directory_address: PhysicalAddress = directory.physical_address.into();
                reader.read_u64(directory_address + decomposed_vaddr.pd.page_table_index * 8)?
            }
        };

        let page_table_entry = PageTableEntry::new(PageTableLevel::Pd, raw_table_entry)?;
        if !page_table_entry.present() {
            return Err(Error::new(
                ErrorKind::MemoryNotMapped,
                "The page or page directory pointed to by the PD table is not mapped",
            ));
        }

        let raw_table_entry = match page_table_entry {
            PageTableEntry::Page(page) => {
                let page_section = decomposed_vaddr.pd.page_section.ok_or(Error::new(
                    ErrorKind::MemoryNotMapped,
                    "Missing page section data in the decomposed PD entry",
                ))?;

                let page_address: PhysicalAddress = page.physical_address.into();

                return Ok(PhysicalAddressRange::new(
                    page_address + page_section.offset,
                    page_section.size,
                ));
            }

            PageTableEntry::PageDirectory(directory) => {
                let directory_address: PhysicalAddress = directory.physical_address.into();
                reader.read_u64(directory_address + decomposed_vaddr.pt.page_table_index * 8)?
            }
        };

        let page_table_entry = PageTableEntry::new(PageTableLevel::Pt, raw_table_entry)?;
        if !page_table_entry.present() {
            return Err(Error::new(
                ErrorKind::MemoryNotMapped,
                "The page pointed to by the PT table is not mapped",
            ));
        }

        match page_table_entry {
            PageTableEntry::PageDirectory(_) => Err(Error::new(
                ErrorKind::InvalidPageTableEntry,
                "Unexpected page directory entry found in PT table",
            )),

            PageTableEntry::Page(page) => {
                let page_section = decomposed_vaddr.pt.page_section.ok_or(Error::new(
                    ErrorKind::MemoryNotMapped,
                    "Missing page section data in the decomposed PT entry",
                ))?;

                let page_address: PhysicalAddress = page.physical_address.into();

                Ok(PhysicalAddressRange::new(
                    page_address + page_section.offset,
                    page_section.size,
                ))
            }
        }
    }
}

impl Architecture for IntelArchitecture {
    fn endianness(&self) -> Endianness {
        Endianness::Little
    }

    fn bitness(&self) -> Bitness {
        Bitness::Bit64
    }

    fn iter_page_table_candidates<'a>(
        &'a self,
        readable: &'a dyn Readable,
        physical_address: PhysicalAddress,
        raw_virtual_address: RawVirtualAddress,
    ) -> Result<Box<dyn Iterator<Item = PhysicalAddress> + 'a>> {
        let decomposed_vaddr =
            PageTableEntry::decompose_virtual_address(raw_virtual_address.value());

        let regions = readable.regions()?;

        let iter = regions
            .into_iter()
            .flat_map(|region| {
                let start = region.start.aligned_to(PAGE_DIRECTORY_SIZE);
                start
                    .range_step(region.end, PAGE_DIRECTORY_SIZE)
                    .collect::<Vec<_>>()
            })
            .filter_map(move |page_table_offset| {
                let pml4_page_table =
                    Self::get_table_entries(readable, page_table_offset, PageTableLevel::Pml4)
                        .ok()?;

                let page_directory = if let Some(PageTableEntry::PageDirectory(page_directory)) =
                    pml4_page_table.get(decomposed_vaddr.pml4.page_table_index)
                {
                    page_directory
                } else {
                    return None;
                };

                if !page_directory.present {
                    return None;
                }

                let has_user_mode_entries =
                    pml4_page_table
                        .iter()
                        .enumerate()
                        .any(|(pml4_index, pml4_entry)| {
                            let present = match pml4_entry {
                                PageTableEntry::Page(page) => page.present,
                                PageTableEntry::PageDirectory(directory) => directory.present,
                            };

                            present && pml4_index <= 0xFF
                        });

                if has_user_mode_entries {
                    return None;
                }

                let virtual_address = VirtualAddress::new(page_table_offset, raw_virtual_address);

                let physical_address_range =
                    Self::virtual_address_to_physical_address(readable, virtual_address).ok()?;

                if physical_address_range.address().value() == physical_address.value() {
                    Some(page_table_offset)
                } else {
                    None
                }
            });

        Ok(Box::new(iter))
    }

    fn translate_virtual_address(
        &self,
        readable: &dyn Readable,
        virtual_address: VirtualAddress,
    ) -> Result<PhysicalAddressRange> {
        Self::virtual_address_to_physical_address(readable, virtual_address)
    }

    fn enumerate_page_table_regions(
        &self,
        readable: &dyn Readable,
        root_page_table: PhysicalAddress,
    ) -> Result<Vec<Region>> {
        let mut region_list = Vec::new();

        // Read the entire PML4 table (4096 bytes = 512 entries)
        let mut pml4_buffer = [0u8; 4096];
        let pml4_bytes_read = readable.read(&mut pml4_buffer, root_page_table)?;

        for (pml4_index, chunk) in pml4_buffer[..pml4_bytes_read].chunks_exact(8).enumerate() {
            let pml4_index = pml4_index as u64;
            let Ok(bytes) = <[u8; 8]>::try_from(chunk) else {
                continue;
            };
            let raw_table_entry = u64::from_le_bytes(bytes);

            let pml4_page_directory =
                match PageTableEntry::new(PageTableLevel::Pml4, raw_table_entry) {
                    Ok(PageTableEntry::PageDirectory(page_directory)) => {
                        if !page_directory.present {
                            continue;
                        }

                        page_directory
                    }

                    _ => continue,
                };

            // Read the entire PDPT table
            let mut pdpt_buffer = [0u8; 4096];
            let pdpt_bytes_read = match readable.read(
                &mut pdpt_buffer,
                PhysicalAddress::new(pml4_page_directory.physical_address),
            ) {
                Ok(bytes_read) => bytes_read,
                Err(_) => continue,
            };

            for (pdpt_index, chunk) in pdpt_buffer[..pdpt_bytes_read].chunks_exact(8).enumerate() {
                let pdpt_index = pdpt_index as u64;
                let Ok(bytes) = <[u8; 8]>::try_from(chunk) else {
                    continue;
                };
                let raw_table_entry = u64::from_le_bytes(bytes);

                let pdpt_page_directory =
                    match PageTableEntry::new(PageTableLevel::Pdpt, raw_table_entry) {
                        Ok(PageTableEntry::PageDirectory(page_directory)) => {
                            if !page_directory.present {
                                continue;
                            }

                            page_directory
                        }

                        Ok(PageTableEntry::Page(page)) => {
                            if page.present {
                                let raw_virtual_address = RawVirtualAddress::new(
                                    (pml4_index << SHIFT_PML4_INDEX)
                                        | (pdpt_index << SHIFT_PDPT_INDEX),
                                );

                                region_list.push(Region {
                                    virtual_address: VirtualAddress::new(
                                        root_page_table,
                                        raw_virtual_address,
                                    )
                                    .canonicalized(),
                                    physical_address: PhysicalAddress::new(page.physical_address),
                                    size: page.size,
                                });
                            }

                            continue;
                        }

                        _ => continue,
                    };

                // Read the entire PD table
                let mut pd_buffer = [0u8; 4096];
                let pd_bytes_read = match readable.read(
                    &mut pd_buffer,
                    PhysicalAddress::new(pdpt_page_directory.physical_address),
                ) {
                    Ok(bytes_read) => bytes_read,
                    Err(_) => continue,
                };

                for (pd_index, chunk) in pd_buffer[..pd_bytes_read].chunks_exact(8).enumerate() {
                    let pd_index = pd_index as u64;
                    let Ok(bytes) = <[u8; 8]>::try_from(chunk) else {
                        continue;
                    };
                    let raw_table_entry = u64::from_le_bytes(bytes);

                    let pd_page_directory =
                        match PageTableEntry::new(PageTableLevel::Pd, raw_table_entry) {
                            Ok(PageTableEntry::PageDirectory(page_directory)) => {
                                if !page_directory.present {
                                    continue;
                                }

                                page_directory
                            }

                            Ok(PageTableEntry::Page(page)) => {
                                if page.present {
                                    let raw_virtual_address = RawVirtualAddress::new(
                                        (pml4_index << SHIFT_PML4_INDEX)
                                            | (pdpt_index << SHIFT_PDPT_INDEX)
                                            | (pd_index << SHIFT_PD_INDEX),
                                    );

                                    region_list.push(Region {
                                        virtual_address: VirtualAddress::new(
                                            root_page_table,
                                            raw_virtual_address,
                                        )
                                        .canonicalized(),
                                        physical_address: PhysicalAddress::new(
                                            page.physical_address,
                                        ),
                                        size: page.size,
                                    });
                                }

                                continue;
                            }

                            _ => continue,
                        };

                    // Read the entire PT table
                    let mut pt_buffer = [0u8; 4096];
                    let pt_bytes_read = match readable.read(
                        &mut pt_buffer,
                        PhysicalAddress::new(pd_page_directory.physical_address),
                    ) {
                        Ok(bytes_read) => bytes_read,
                        Err(_) => continue,
                    };

                    for (pt_index, chunk) in pt_buffer[..pt_bytes_read].chunks_exact(8).enumerate()
                    {
                        let pt_index = pt_index as u64;
                        let Ok(bytes) = <[u8; 8]>::try_from(chunk) else {
                            continue;
                        };
                        let raw_table_entry = u64::from_le_bytes(bytes);

                        if let Ok(PageTableEntry::Page(page)) =
                            PageTableEntry::new(PageTableLevel::Pt, raw_table_entry)
                            && page.present
                        {
                            let raw_virtual_address = RawVirtualAddress::new(
                                (pml4_index << SHIFT_PML4_INDEX)
                                    | (pdpt_index << SHIFT_PDPT_INDEX)
                                    | (pd_index << SHIFT_PD_INDEX)
                                    | (pt_index << SHIFT_PT_INDEX),
                            );

                            region_list.push(Region {
                                virtual_address: VirtualAddress::new(
                                    root_page_table,
                                    raw_virtual_address,
                                )
                                .canonicalized(),
                                physical_address: PhysicalAddress::new(page.physical_address),
                                size: page.size,
                            });
                        }
                    }
                }
            }
        }

        Ok(region_list)
    }
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
    use crate::memory::error::Result as MemoryResult;

    use super::*;

    #[derive(Clone, Copy, Debug)]
    enum PageSize {
        Normal,
        Large2Mb,
        Large1Gb,
    }

    struct MockedPageTable {
        page_size: PageSize,
        unmapped: bool,
    }

    impl MockedPageTable {
        pub fn new(page_size: PageSize, unmapped: bool) -> Self {
            Self {
                page_size,
                unmapped,
            }
        }
    }

    impl Readable for MockedPageTable {
        fn read(&self, buffer: &mut [u8], offset: PhysicalAddress) -> MemoryResult<usize> {
            match self.page_size {
                PageSize::Normal => {
                    assert!(
                        offset.value() == 0x1008
                            || offset.value() == 0x2008
                            || offset.value() == 0x3008
                            || offset.value() == 0x4008
                    );

                    if offset.value() == 0x1008 {
                        buffer.copy_from_slice(&[0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                    } else if offset.value() == 0x2008 {
                        buffer.copy_from_slice(&[0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                    } else if offset.value() == 0x3008 {
                        buffer.copy_from_slice(&[0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                    } else if offset.value() == 0x4008 {
                        if self.unmapped {
                            buffer
                                .copy_from_slice(&[0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                        } else {
                            buffer
                                .copy_from_slice(&[0x01, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                        }
                    }

                    Ok(buffer.len())
                }

                PageSize::Large2Mb => {
                    assert!(
                        offset.value() == 0x1008
                            || offset.value() == 0x2008
                            || offset.value() == 0x3008
                    );

                    if offset.value() == 0x1008 {
                        buffer.copy_from_slice(&[0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                    } else if offset.value() == 0x2008 {
                        buffer.copy_from_slice(&[0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                    } else if offset.value() == 0x3008 {
                        if self.unmapped {
                            buffer
                                .copy_from_slice(&[0x80, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00]);
                        } else {
                            buffer
                                .copy_from_slice(&[0x81, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00]);
                        }
                    }

                    Ok(buffer.len())
                }

                PageSize::Large1Gb => {
                    assert!(offset.value() == 0x1008 || offset.value() == 0x2008);

                    if offset.value() == 0x1008 {
                        buffer.copy_from_slice(&[0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
                    } else if offset.value() == 0x2008 {
                        if self.unmapped {
                            buffer
                                .copy_from_slice(&[0x80, 0x30, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x00]);
                        } else {
                            buffer
                                .copy_from_slice(&[0x81, 0x30, 0x00, 0x00, 0xAA, 0x00, 0x00, 0x00]);
                        }
                    }

                    Ok(buffer.len())
                }
            }
        }

        fn len(&self) -> MemoryResult<u64> {
            Ok(0xFFFFFFFF)
        }
    }

    #[test]
    fn test_normal_page_size_vaddr_translation() {
        let mocked_page_table = MockedPageTable::new(PageSize::Normal, false);
        let virtual_address = VirtualAddress::new(
            PhysicalAddress::new(0x1000),
            RawVirtualAddress::new(0x0000008040201000),
        );

        let physical_address_range = IntelArchitecture::virtual_address_to_physical_address(
            &mocked_page_table,
            virtual_address,
        )
        .unwrap();

        assert_eq!(
            physical_address_range.address(),
            PhysicalAddress::new(0x5000)
        );

        assert_eq!(physical_address_range.len(), 0x1000);
    }

    #[test]
    fn test_huge_2mb_page_size_vaddr_translation() {
        let mocked_page_table = MockedPageTable::new(PageSize::Large2Mb, false);
        let virtual_address = VirtualAddress::new(
            PhysicalAddress::new(0x1000),
            RawVirtualAddress::new(0x0000008040201000),
        );

        let physical_address_range = IntelArchitecture::virtual_address_to_physical_address(
            &mocked_page_table,
            virtual_address,
        )
        .unwrap();

        assert_eq!(
            physical_address_range.address(),
            PhysicalAddress::new(0x201000)
        );

        assert_eq!(physical_address_range.len(), 0x1FF000);
    }

    #[test]
    fn test_huge_1gb_page_size_vaddr_translation() {
        let mocked_page_table = MockedPageTable::new(PageSize::Large1Gb, false);
        let virtual_address = VirtualAddress::new(
            PhysicalAddress::new(0x1000),
            RawVirtualAddress::new(0x0000008040201000),
        );

        let physical_address_range = IntelArchitecture::virtual_address_to_physical_address(
            &mocked_page_table,
            virtual_address,
        )
        .unwrap();

        assert_eq!(
            physical_address_range.address(),
            PhysicalAddress::new(0xAA00201000)
        );

        assert_eq!(physical_address_range.len(), 0x3FDFF000);
    }

    #[test]
    fn test_normal_page_size_vaddr_translation_with_page_fault() {
        let mocked_page_table = MockedPageTable::new(PageSize::Normal, true);
        let virtual_address = VirtualAddress::new(
            PhysicalAddress::new(0x1000),
            RawVirtualAddress::new(0x0000008040201000),
        );

        let physical_address_range_res = IntelArchitecture::virtual_address_to_physical_address(
            &mocked_page_table,
            virtual_address,
        );

        assert!(physical_address_range_res.is_err());
        assert_eq!(
            physical_address_range_res.unwrap_err().kind(),
            ErrorKind::MemoryNotMapped
        );
    }

    #[test]
    fn test_huge_2mb_page_size_vaddr_translation_with_page_fault() {
        let mocked_page_table = MockedPageTable::new(PageSize::Large2Mb, true);
        let virtual_address = VirtualAddress::new(
            PhysicalAddress::new(0x1000),
            RawVirtualAddress::new(0x0000008040201000),
        );

        let physical_address_range_res = IntelArchitecture::virtual_address_to_physical_address(
            &mocked_page_table,
            virtual_address,
        );

        assert!(physical_address_range_res.is_err());
        assert_eq!(
            physical_address_range_res.unwrap_err().kind(),
            ErrorKind::MemoryNotMapped
        );
    }

    #[test]
    fn test_huge_1gb_page_size_vaddr_translation_with_page_fault() {
        let mocked_page_table = MockedPageTable::new(PageSize::Large1Gb, true);
        let virtual_address = VirtualAddress::new(
            PhysicalAddress::new(0x1000),
            RawVirtualAddress::new(0x0000008040201000),
        );

        let physical_address_range_res = IntelArchitecture::virtual_address_to_physical_address(
            &mocked_page_table,
            virtual_address,
        );

        assert!(physical_address_range_res.is_err());
        assert_eq!(
            physical_address_range_res.unwrap_err().kind(),
            ErrorKind::MemoryNotMapped
        );
    }
}