ntoseye 0.19.0

Windows kernel debugger for Linux hosts running Windows under KVM/QEMU
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
use tabled::builder::Builder;

use owo_colors::OwoColorize;

use crate::backend::MemoryOps;
use crate::error::Result;
use crate::expr::Expr;
use crate::symbols::{FieldValue, ParsedType};
use crate::types::{Value, VirtAddr};
use crate::ui;
use crate::unwind::{format_symbol, resolve_thread_trace_context, try_format_symbol};

use crate::repl::*;

repl_command! {
    cmd_db;
    names: ["db"],
    usage: "db <address> [length or end]",
    summary: "Display memory as bytes.",
    completion: Expression,
}

repl_command! {
    cmd_dd;
    names: ["dd"],
    usage: "dd <address> [length or end]",
    summary: "Display memory as doublewords (4 bytes).",
    completion: Expression,
}

repl_command! {
    cmd_dq;
    names: ["dq"],
    usage: "dq <address> [length or end]",
    summary: "Display memory as quadwords (8 bytes).",
    completion: Expression,
}

repl_command! {
    cmd_dqs;
    names: ["dqs", "dps"],
    usage: "dqs <address> [count or end]",
    summary: "Display memory as quadwords, annotating values that resolve to symbols.",
    details: "raw stack triage: dqs @rsp scrapes return addresses when the unwinder can't",
    completion: Expression,
}

repl_command! {
    cmd_da;
    names: ["da"],
    usage: "da <address> [max-chars]",
    summary: "Display a NUL-terminated ASCII string.",
    completion: Expression,
}

repl_command! {
    cmd_du;
    names: ["du"],
    usage: "du <address> [max-chars]",
    summary: "Display a NUL-terminated UTF-16 string (e.g. a UNICODE_STRING Buffer).",
    completion: Expression,
}

repl_command! {
    cmd_disasm;
    names: ["disasm", "u"],
    usage: "disasm <address> [length or end]",
    summary: "Disassemble memory at a symbol or address.",
    completion: Expression,
}

repl_command! {
    cmd_dt;
    names: ["dt"],
    usage: "dt <type> [address] [field]",
    summary: "Display type definition.",
    completion: [Type, Expression],
}

repl_command! {
    cmd_eb;
    names: ["eb"],
    usage: "eb <address> <expr>",
    summary: "Write a byte to memory.",
    completion: Expression,
}

repl_command! {
    cmd_ed;
    names: ["ed"],
    usage: "ed <address> <expr>",
    summary: "Write a doubleword (4 bytes) to memory.",
    completion: Expression,
}

repl_command! {
    cmd_eq;
    names: ["eq"],
    usage: "eq <address> <expr>",
    summary: "Write a quadword (8 bytes) to memory.",
    completion: Expression,
}

repl_command! {
    cmd_f;
    names: ["f"],
    usage: "f <address> <hex bytes> [length or end]",
    summary: "Fill memory with a repeated byte pattern.",
    details: "hex bytes: 90, 4883792000740a, or \\x90\\x90",
    completion: [Expression, None, Expression],
}

repl_command! {
    cmd_s;
    names: ["s"],
    usage: "s <address> <hex bytes> [length]",
    summary: "Search memory for a byte pattern.",
    details: "hex bytes: 4883792000740a or \\x48\\x83\\x79\\x20\\x00\\x74\\x0a",
    completion: [Expression, None, Expression],
}

fn page_bounded_unit_read_len(
    address: VirtAddr,
    remaining_units: usize,
    unit_size: usize,
) -> usize {
    debug_assert!(remaining_units > 0);
    debug_assert!(unit_size > 0);

    let page_remaining = (0x1000 - (address.0 & 0xfff)) as usize;
    let bounded = remaining_units
        .saturating_mul(unit_size)
        .min(page_remaining);
    let whole_units = bounded - bounded % unit_size;
    // A unit beginning at the final byte of a page must be read whole across
    // the boundary; otherwise every read ends on a unit boundary.
    if whole_units == 0 {
        unit_size
    } else {
        whole_units
    }
}

impl ReplState<'_> {
    /// Read guest memory in the current process context for *display*, masking
    /// out our own breakpoint int3 bytes so listings never show them.
    fn read_for_display(&self, addr: VirtAddr, buf: &mut [u8]) -> Result<()> {
        let process = self.ctx.target.current_process();
        process.memory().read_bytes(addr, buf)?;
        self.ctx
            .breakpoints
            .mask_breakpoint_bytes(addr, buf, process.dtb());
        Ok(())
    }

    fn display_memory_command(
        &self,
        invocation: &CommandInvocation<'_>,
        default_count: u64,
        item_size: u64,
        mode: MemoryDisplayMode,
    ) -> Result<()> {
        let range =
            match AddressRange::parse(invocation, &self.ctx.target, default_count, item_size) {
                Ok(r) => r,
                Err(e) => {
                    error!("{}", e);
                    return Ok(());
                }
            };

        let mut data: Vec<u8> = vec![0u8; range.len()];
        if let Err(e) = self.read_for_display(range.start, &mut data) {
            println!("{e}\n");
            return Ok(());
        }

        display_memory(range.start, &data, &mode);

        Ok(())
    }

    fn write_scalar_command(
        &mut self,
        invocation: &CommandInvocation<'_>,
        command: &str,
        noun: &str,
        encode: impl FnOnce(u64) -> Vec<u8>,
        display_value: impl FnOnce(u64) -> String,
    ) -> Result<()> {
        if invocation.argv.len() < 2 {
            println!("{}\n", command_help(command));
            return Ok(());
        }

        let address = match Expr::eval(invocation.arg(0).unwrap(), &self.ctx.target) {
            Ok(a) => a,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };

        let expr_str = invocation.join_args(1);
        let value = match Expr::eval(&expr_str, &self.ctx.target) {
            Ok(v) => v.0,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };

        let bytes = encode(value);
        let formatted_value = display_value(value);
        let mem = self.ctx.target.current_process().memory();
        if let Err(e) = mem.write_bytes(address, &bytes) {
            error!("failed to write {}: {}", noun, e);
        } else {
            println!(
                "{} {} -> {}\n",
                "wrote".green(),
                formatted_value,
                ui::addr(address.0)
            );
        }

        Ok(())
    }

    fn cmd_db(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.display_memory_command(&invocation, 128, 1, MemoryDisplayMode::bytes())
    }

    fn cmd_dd(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.display_memory_command(&invocation, 16, 4, MemoryDisplayMode::dwords())
    }

    fn cmd_dq(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.display_memory_command(&invocation, 8, 8, MemoryDisplayMode::qwords())
    }

    fn cmd_dqs(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        let range = match AddressRange::parse(&invocation, &self.ctx.target, 16, 8) {
            Ok(r) => r,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };

        let mut data: Vec<u8> = vec![0u8; range.len()];
        if let Err(e) = self.read_for_display(range.start, &mut data) {
            println!("{e}\n");
            return Ok(());
        }

        let dtb = self.ctx.target.current_process().dtb();
        let trace = resolve_thread_trace_context(&self.ctx.target, dtb);
        for (i, chunk) in data.chunks_exact(8).enumerate() {
            let value = u64::from_le_bytes(chunk.try_into().unwrap());
            let addr = (range.start + (i as u64) * 8).0;
            match try_format_symbol(&self.ctx.target, &trace, value) {
                Some(symbol) => println!(
                    "{}  {:016x}  {}",
                    ui::addr(addr),
                    value,
                    ui::symbol(&symbol)
                ),
                None => println!("{}  {:016x}", ui::addr(addr), value),
            }
        }
        println!();

        Ok(())
    }

    fn cmd_da(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.display_string_command(&invocation, "da", 1)
    }

    fn cmd_du(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.display_string_command(&invocation, "du", 2)
    }

    /// Shared `da`/`du` body: read a NUL-terminated string of `char_size`-wide
    /// units, chunking reads at page boundaries so a string ending near an
    /// unmapped page still displays up to the readable part.
    fn display_string_command(
        &mut self,
        invocation: &CommandInvocation<'_>,
        command: &str,
        char_size: usize,
    ) -> Result<()> {
        let Some(start_arg) = invocation.arg(0) else {
            println!("{}\n", command_help(command));
            return Ok(());
        };
        let start = match Expr::eval(start_arg, &self.ctx.target) {
            Ok(a) => a,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };
        let max_chars = match invocation.arg(1) {
            Some(arg) => match Expr::eval(arg, &self.ctx.target) {
                Ok(v) if v.0 > 0 => v.0 as usize,
                Ok(_) => {
                    error!("invalid max-chars: {}", arg);
                    return Ok(());
                }
                Err(e) => {
                    error!("{}", e);
                    return Ok(());
                }
            },
            None => 256,
        };

        let mut units: Vec<u16> = Vec::new();
        let mut terminated = false;
        let mut failed_at = None;
        let mut addr = start;
        while units.len() < max_chars && !terminated {
            // End each ordinary read at both a page boundary and a whole-unit
            // boundary. If one UTF-16 unit itself straddles pages, read that
            // unit whole so neither byte is discarded.
            let want = page_bounded_unit_read_len(addr, max_chars - units.len(), char_size);
            let mut buf = vec![0u8; want];
            if let Err(e) = self.read_for_display(addr, &mut buf) {
                failed_at = Some((addr, e));
                break;
            }
            terminated = push_string_units(&buf, char_size, max_chars, &mut units);
            addr += want as u64;
        }

        if units.is_empty()
            && let Some((addr, e)) = failed_at
        {
            error!("failed to read string at {:#x}: {}", addr, e);
            return Ok(());
        }

        let text: String = if char_size == 1 {
            units.iter().map(|&u| u as u8 as char).collect()
        } else {
            String::from_utf16_lossy(&units)
        };
        let suffix = if failed_at.is_some() {
            " <unreadable>".red().to_string()
        } else if !terminated {
            "...".bright_black().to_string()
        } else {
            String::new()
        };
        println!(
            "{}  \"{}\"{}\n",
            ui::addr(start.0),
            text.escape_debug(),
            suffix
        );

        Ok(())
    }

    fn cmd_disasm(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        let range = match AddressRange::parse(&invocation, &self.ctx.target, 32, 1) {
            Ok(r) => r,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };

        let start_addr = range.start;
        let mut bytes: Vec<u8> = vec![0u8; range.len()];
        if let Err(e) = self.read_for_display(start_addr, &mut bytes) {
            println!("{e}\n");
            return Ok(());
        }

        // resolve branch / rip-relative targets the same way the break/status
        // view does, so the `disasm` command's comments read identically
        let dtb = self.ctx.target.current_process().dtb();
        let trace = resolve_thread_trace_context(&self.ctx.target, dtb);
        let resolve = |target: u64| format_symbol(&self.ctx.target, &trace, target);

        // TODO dont hardcode 64-bit for WOW64 process? / support other formats?
        let mut formatter = disasm_formatter();
        let rows = decode_rows(&bytes, start_addr.0, None, &mut formatter, resolve);
        render_rows(&rows, |_| None);
        println!();

        Ok(())
    }

    fn cmd_eb(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.write_scalar_command(
            &invocation,
            "eb",
            "byte",
            |value| vec![value as u8],
            |value| format!("{:02x}", value as u8),
        )
    }

    fn cmd_ed(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.write_scalar_command(
            &invocation,
            "ed",
            "dword",
            |value| (value as u32).to_le_bytes().to_vec(),
            |value| format!("{:#x}", value as u32),
        )
    }

    fn cmd_eq(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        self.write_scalar_command(
            &invocation,
            "eq",
            "qword",
            |value| value.to_le_bytes().to_vec(),
            |value| format!("{:#x}", value),
        )
    }

    fn cmd_f(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        if invocation.argv.len() < 2 {
            println!("{}\n", command_help("f"));
            return Ok(());
        }

        let address = match Expr::eval(invocation.arg(0).unwrap(), &self.ctx.target) {
            Ok(a) => a,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };

        let pattern_str = invocation.arg(1).unwrap();
        let pattern = match parse_byte_pattern(pattern_str) {
            Some(pattern) => pattern,
            None => {
                error!("invalid pattern: {}", pattern_str);
                return Ok(());
            }
        };

        let length = match invocation.arg(2) {
            Some(length_arg) => match Expr::eval(length_arg, &self.ctx.target) {
                Ok(value) => match resolve_length_or_end(address, value) {
                    Some(length) => length,
                    None => {
                        error!("invalid length or end: {}", length_arg);
                        return Ok(());
                    }
                },
                Err(e) => {
                    error!("{}", e);
                    return Ok(());
                }
            },
            None => pattern.len(),
        };

        let data = repeat_pattern(&pattern, length);
        let mem = self.ctx.target.current_process().memory();

        if let Err(e) = mem.write_bytes(address, &data) {
            error!("failed to fill memory: {}", e);
        } else {
            println!(
                "{} {:#x} bytes at {} with {}\n",
                "filled".green(),
                length,
                ui::addr(address.0),
                format!("[{}]", pattern_str).green()
            );
        }

        Ok(())
    }

    fn cmd_s(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        if invocation.argv.len() < 2 {
            println!("{}\n", command_help("s"));
            return Ok(());
        }

        let pattern_str = invocation.arg(1).unwrap();

        let start_addr = match Expr::eval(invocation.arg(0).unwrap(), &self.ctx.target) {
            Ok(a) => a,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };

        let pattern = match parse_byte_pattern(pattern_str) {
            Some(pattern) => pattern,
            None => {
                error!("invalid pattern: {}", pattern_str);
                return Ok(());
            }
        };

        let length = match invocation.arg(2) {
            Some(length_arg) => match Expr::eval(length_arg, &self.ctx.target) {
                Ok(value) => match usize::try_from(value.0) {
                    Ok(length) => length,
                    Err(_) => {
                        error!("invalid length: {}", length_arg);
                        return Ok(());
                    }
                },
                Err(e) => {
                    error!("{}", e);
                    return Ok(());
                }
            },
            None => 0x100,
        };

        // The scan itself is the shared core primitive (`Target::search`), the
        // same one the SDK and MCP `search` use; the REPL only adds the
        // per-hit symbol line and the $0..$N result slots.
        let hits = match self.ctx.target.search(start_addr, &pattern, length) {
            Ok(hits) => hits,
            Err(e) => {
                error!("failed to read memory: {}", e);
                return Ok(());
            }
        };
        for &addr in &hits {
            let sym = self
                .ctx
                .target
                .guest
                .ntoskrnl
                .closest_symbol(VirtAddr(addr))
                .map(|(s, o)| {
                    if o == 0 {
                        s.to_string()
                    } else {
                        format!("{}+{:#x}", s, o)
                    }
                })
                .unwrap_or_default();

            println!("{}  {}", ui::addr(addr), ui::symbol(&sym));
        }

        if hits.is_empty() {
            println!(
                "{} (searched {:#x} bytes at {})",
                "no matches found".bright_black(),
                length,
                ui::addr(start_addr.0)
            );
        } else {
            println!(
                "\n{} {} (in $0..${})",
                hits.len(),
                if hits.len() == 1 { "match" } else { "matches" },
                hits.len() - 1
            );
        }
        self.ctx.target.set_results(hits, self.line.clone());
        println!();

        Ok(())
    }

    fn cmd_dt(&mut self, invocation: CommandInvocation<'_>) -> Result<()> {
        let arg = require_arg!(invocation, 0, "dt");

        let address = match Expr::eval(invocation.arg(1).unwrap_or("0"), &self.ctx.target) {
            Ok(a) => a,
            Err(e) => {
                error!("{}", e);
                return Ok(());
            }
        };

        let field_name = invocation.arg(2);

        match self
            .ctx
            .target
            .symbols
            .find_type_across_modules(self.ctx.target.current_dtb(), arg)
        {
            Some(type_info) => {
                let mut builder = Builder::default();
                builder.push_record(vec![format!(
                    "{} ({} bytes)",
                    type_info.name,
                    Value(type_info.size)
                )]);

                // Decode via the shared `decode_fields` (the path `read_struct`
                // uses in the SDK/MCP) so `dt` and a struct read can't disagree.
                // One whole-struct read, rendered from the decoded leaves; the
                // offset/type columns and bitfield Y/N styling stay dt-specific.
                let decoded: std::collections::HashMap<String, FieldValue> = if address.0 != 0 {
                    // NOTE: one whole-struct read, not page-tolerant; fine for the
                    // non-paged kernel structs dt targets, but a partially-resident
                    // pageable struct with a paged-out tail would fail the read here
                    let mut buf = vec![0u8; type_info.size];
                    match self
                        .ctx
                        .target
                        .current_process()
                        .memory()
                        .read_bytes(address, &mut buf)
                    {
                        Ok(()) => type_info.decode_fields(&buf).into_iter().collect(),
                        Err(e) => {
                            error!("failed to read struct memory: {}", e);
                            return Ok(());
                        }
                    }
                } else {
                    std::collections::HashMap::new()
                };

                let mut sorted_fields: Vec<_> = type_info.fields.iter().collect();
                sorted_fields.sort_by_key(|(_, info)| {
                    let bitfield_pos = match &info.type_data {
                        ParsedType::Bitfield { pos, .. } => *pos,
                        _ => 0,
                    };
                    (info.offset, bitfield_pos)
                });

                for (name, info) in sorted_fields {
                    let value = match decoded.get(name) {
                        // A len-1 bitfield renders as a Y/N flag (the value is
                        // already masked/shifted by decode_fields); wider
                        // bitfields show the decimal value.
                        Some(FieldValue::Bitfield(val)) => {
                            let single_bit = matches!(
                                &info.type_data,
                                ParsedType::Bitfield { len, .. } if *len == 1
                            );
                            if single_bit {
                                if *val == 1 {
                                    format!(" = {}", "Y".green())
                                } else {
                                    format!(" = {}", "N".red())
                                }
                            } else {
                                format!(" = {}", Value(*val))
                            }
                        }
                        Some(FieldValue::Int(val)) | Some(FieldValue::Pointer(val)) => {
                            format!(" = {:#x}", Value(*val))
                        }
                        // Aggregates (Bytes) and fields decode_fields skips
                        // (nested structs / past the buffer) show no inline value.
                        Some(FieldValue::Bytes(_)) | None => String::new(),
                    };

                    if field_name.is_none_or(|field| field == name.as_str()) {
                        builder.push_record(vec![
                            format!(
                                "  {} {:-12}",
                                format!("+ {:#06x}", info.offset).bright_black(),
                                name
                            ),
                            format!("  : {}", info.type_data.green()),
                            format!("  {}", value),
                        ]);
                    }
                }

                print_plain_table(builder);
            }
            None => {
                // Not a struct/union; it may be an enum (enums aren't in the
                // struct type index, so find_type misses them).
                match self
                    .ctx
                    .target
                    .symbols
                    .find_enum_across_modules(self.ctx.target.current_dtb(), arg)
                {
                    Some(variants) => {
                        // Header as its own line; a one-cell header row in the
                        // table would stretch the value column. The value/name
                        // table then sizes both columns to content.
                        println!("enum {} ({} values)", arg, variants.len());
                        let mut builder = Builder::default();
                        for (name, value) in &variants {
                            builder.push_record(vec![format!("  {:#x}  ", value), name.clone()]);
                        }
                        print_plain_table(builder);
                        println!();
                    }
                    None => {
                        error!("failed to get type information: type `{}` not found\n", arg);
                    }
                }
            }
        }

        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::page_bounded_unit_read_len;
    use crate::types::VirtAddr;

    #[test]
    fn utf16_page_chunks_never_drop_an_unaligned_unit_byte() {
        // An unaligned string with three bytes left in the page reads one full
        // unit, then reads the straddling unit whole across the boundary.
        assert_eq!(page_bounded_unit_read_len(VirtAddr(0xffd), 8, 2), 2);
        assert_eq!(page_bounded_unit_read_len(VirtAddr(0xfff), 7, 2), 2);
    }

    #[test]
    fn string_page_chunks_respect_unit_budget() {
        assert_eq!(page_bounded_unit_read_len(VirtAddr(0x100), 3, 2), 6);
        assert_eq!(page_bounded_unit_read_len(VirtAddr(0x100), 3, 1), 3);
        assert_eq!(page_bounded_unit_read_len(VirtAddr(0xffe), 1, 2), 2);
    }
}