From 6b72dd82231c8e35c3c90bbc941d02fc771a9121 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 26 Nov 2015 10:14:04 +0100 Subject: [PATCH] Remove `Lock` structure again as we changed design --- posts/DRAFT-paging.md | 14 -------------- src/memory/paging/mod.rs | 8 -------- 2 files changed, 22 deletions(-) diff --git a/posts/DRAFT-paging.md b/posts/DRAFT-paging.md index 9d9e627c..46f57507 100644 --- a/posts/DRAFT-paging.md +++ b/posts/DRAFT-paging.md @@ -14,22 +14,8 @@ When accessing a `P2` table, we only loop two times and then choose entries that The math checks out, too. If all page tables are used, there is 1 `P4` table, 511 `P3` tables (the last entry is used for the recursive mapping), `511*512` `P2` tables, and `511*512*512` `P1` tables. So there are `134217728` page tables altogether. Each page table occupies 4KiB, so we need `134217728 * 4KiB = 512GiB` to store them. That's exactly the amount of memory that can be accessed through one `P4` entry since `4KiB per page * 512 P1 entries * 512 P2 entries * 512 P3 entries = 512GiB`. -## A Safe Module -We need to make sure that the page tables can't be modified concurrently. So we must ensure exclusive access for all functions that modify the page table. For a normal struct, Rust would handle it at compile time through the `&` and `&mut` rules. But since we have some magic memory address instead, we must do some manual work. -To ensure exclusivity, we introduce a `Lock` struct. All operations that modify the current page table borrow it exclusively (`&mut`) and all operations that just read the table borrow it through `&`. That way, we benefit from Rust's aliasing rules. -The `Lock` struct looks like this (in a new `memory/paging/mod.rs` module): - -```rust -pub struct Lock { - _private: (), -} - -impl !Send for Lock {} -impl !Sync for Lock {} -``` -The `_private` field is needed to forbid construction from outside. The `!Send` and `!Sync` ## Switching Page Tables diff --git a/src/memory/paging/mod.rs b/src/memory/paging/mod.rs index 3f7d97ae..e69de29b 100644 --- a/src/memory/paging/mod.rs +++ b/src/memory/paging/mod.rs @@ -1,8 +0,0 @@ -/// The paging lock must be unique. It is required for all page table operations and thus -/// guarantees exclusive page table access. -pub struct Lock { - _private: (), -} - -impl !Send for Lock {} -impl !Sync for Lock {}