Commit 254a69a
refactor(memory): address crate 重构——拆分 span、重命名为 memory_types
重构 `crates/address` 为更准确的命名和更清晰的职责划分:
**结构变更:**
- 新建 `crates/span`:提取 `Span<A>` 通用半开区间为独立零依赖 crate
- `crates/address` → `crates/memory_types`:包名更准确反映内容
- `page_num.rs` → `page_frame.rs`:文件名覆盖 Frame 和 Page 两种类型
**类型重命名:**
- `AddrRange<A>` → `Span<A>`(通用术语,参考 Redox PageSpan)
- `FrameRange` → `FrameSpan`,`PageRange` → `PageSpan`
- 删除 `PhysPageNum`/`VirtPageNum` 别名,直接用 `Frame`/`Page`(默认类型参数)
**代码审阅修复:**
- 算术溢出:`debug_assert!` + 裸运算 → `checked_add/sub` + `expect`
- 避免软件除法:乘除法全部替换为位移(`NUM_4K_PAGES_SHIFT`)
- `From<*const T>` 和 `align_up_to` 结果经过 `Self::new()` 校验
- `Frame`/`Page` 加 `#[repr(transparent)]`、`const fn new/start_addr`
- `PageSize` trait:`NUM_4K_PAGES_SHIFT`/`SIZE_IN_BYTES` 改为自动派生
- Display 输出 `Frame<4K>(0x42)` 格式,包含页大小信息
- 删除无用的 `page_size::tests` 模块
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Niu Zhihong <zhihong@nzhnb.com>1 parent 62715a0 commit 254a69a
45 files changed
Lines changed: 658 additions & 698 deletions
File tree
- crates
- address
- src
- config
- frame_allocator
- src
- memory_types
- src
- memory
- src
- page_allocator
- src
- page_table_entry
- src
- paging
- src
- span
- src
- src
- arch
- aarch64
- riscv64
- tests/system
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | | - | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| |||
This file was deleted.
This file was deleted.
0 commit comments