From 3a6d3153a49970939f86fb3e09647723d9e226e7 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 4 Feb 2020 09:47:39 +0100 Subject: [PATCH 01/10] Don't panic on overflow in allocator; return null pointer instead (#738) --- src/allocator/bump.rs | 5 ++++- src/allocator/linked_list.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/allocator/bump.rs b/src/allocator/bump.rs index 7d104eff..37031254 100644 --- a/src/allocator/bump.rs +++ b/src/allocator/bump.rs @@ -36,7 +36,10 @@ unsafe impl GlobalAlloc for Locked { let mut bump = self.lock(); // get a mutable reference let alloc_start = align_up(bump.next, layout.align()); - let alloc_end = alloc_start.checked_add(layout.size()).expect("overflow"); + let alloc_end = match alloc_start.checked_add(layout.size()) { + Some(end) => end, + None => return ptr::null_mut(), + }; if alloc_end > bump.heap_end { ptr::null_mut() // out of memory diff --git a/src/allocator/linked_list.rs b/src/allocator/linked_list.rs index a03b6f34..c2d1958d 100644 --- a/src/allocator/linked_list.rs +++ b/src/allocator/linked_list.rs @@ -86,7 +86,7 @@ impl LinkedListAllocator { /// Returns the allocation start address on success. fn alloc_from_region(region: &ListNode, size: usize, align: usize) -> Result { let alloc_start = align_up(region.start_addr(), align); - let alloc_end = alloc_start.checked_add(size).expect("overflow"); + let alloc_end = alloc_start.checked_add(size).ok_or(())?; if alloc_end > region.end_addr() { // region too small From 2634bb2d37a6f053608bc4d51042a9a71db6240a Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Sat, 22 Feb 2020 18:55:21 -0600 Subject: [PATCH 02/10] Updated pc-keyboard to `0.5.0` --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/interrupts.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1066076e..b96e1270 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,9 +73,9 @@ checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" [[package]] name = "pc-keyboard" -version = "0.3.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff50ab09ba31bcebc0669f4e64c0952fae1acdca9e6e0587e68e4e8443808ac" +checksum = "c48392db76c4e9a69e0b3be356c5f97ebb7b14413c5e4fd0af4755dbf86e2fce" [[package]] name = "pic8259_simple" diff --git a/Cargo.toml b/Cargo.toml index cc7e49e2..685e6662 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ spin = "0.5.2" x86_64 = "0.8.1" uart_16550 = "0.2.0" pic8259_simple = "0.1.1" -pc-keyboard = "0.3.1" +pc-keyboard = "0.5.0" [dependencies.lazy_static] version = "1.0" diff --git a/src/interrupts.rs b/src/interrupts.rs index 025eec43..cd6aa741 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -66,13 +66,13 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut InterruptSt } extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut InterruptStackFrame) { - use pc_keyboard::{layouts, DecodedKey, Keyboard, ScancodeSet1}; + use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1}; use spin::Mutex; use x86_64::instructions::port::Port; lazy_static! { static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1)); + Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::MapLettersToUnicode)); } let mut keyboard = KEYBOARD.lock(); From 2a8f499f7357b54ec35b6c5d9d20f917c17af31b Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Sat, 22 Feb 2020 19:02:57 -0600 Subject: [PATCH 03/10] Might help if I use cargo fmt --- src/interrupts.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interrupts.rs b/src/interrupts.rs index cd6aa741..a5083f77 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -72,7 +72,11 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut Interrup lazy_static! { static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::MapLettersToUnicode)); + Mutex::new(Keyboard::new( + layouts::Us104Key, + ScancodeSet1, + HandleControl::MapLettersToUnicode + )); } let mut keyboard = KEYBOARD.lock(); From de509e058fe1e970f3827577cb8b3a447fdcceba Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Tue, 25 Feb 2020 10:32:39 -0600 Subject: [PATCH 04/10] Switched to HandleControl::Ignore --- src/interrupts.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/interrupts.rs b/src/interrupts.rs index a5083f77..ceb82cd1 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -71,12 +71,9 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut Interrup use x86_64::instructions::port::Port; lazy_static! { - static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new( - layouts::Us104Key, - ScancodeSet1, - HandleControl::MapLettersToUnicode - )); + static ref KEYBOARD: Mutex> = Mutex::new( + Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore) + ); } let mut keyboard = KEYBOARD.lock(); From 46264d08ca53f8c8b276cc0245727918cc069c92 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Feb 2020 12:43:51 +0100 Subject: [PATCH 05/10] Run cargo update --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a3417609..257b57ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,6 @@ dependencies = [ [[package]] name = "bootloader" -version = "0.8.3" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d596849a47f28abdea62d7a6a25c4f6e69c3d9b09b0a2877db6e9cda004ca993" +checksum = "c3ed4f735c4e455ba86a3d2939b1c0729414153642106c9d035693355630a42c" From ebb862de2ad63adb735484563023f60ac5a5698d Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Feb 2020 12:46:04 +0100 Subject: [PATCH 06/10] Run cargo update for post-04 --- Cargo.lock | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eed32fad..a5457572 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,14 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "array-init" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" -dependencies = [ - "nodrop", -] - [[package]] name = "bit_field" version = "0.9.0" @@ -30,7 +21,7 @@ dependencies = [ "spin", "uart_16550", "volatile", - "x86_64 0.8.1", + "x86_64 0.8.3", ] [[package]] @@ -57,12 +48,6 @@ dependencies = [ "spin", ] -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - [[package]] name = "rustc_version" version = "0.2.3" @@ -95,20 +80,14 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "uart_16550" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "803ea8cb602dbb32c1a657a866d2dd79fe7dbeab0fb2ac667cb4dcc7de12a58b" +checksum = "d44b0f30cb82b0fbc15b78ade1064226529ad52028bc8cb8accb98ff6f3d7131" dependencies = [ "bitflags", - "x86_64 0.7.7", + "x86_64 0.9.5", ] -[[package]] -name = "ux" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88dfeb711b61ce620c0cb6fd9f8e3e678622f0c971da2a63c4b3e25e88ed012f" - [[package]] name = "volatile" version = "0.2.6" @@ -117,25 +96,21 @@ checksum = "6af0edf5b4faacc31fc51159244d78d65ec580f021afcef7bd53c04aeabc7f29" [[package]] name = "x86_64" -version = "0.7.7" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f27d9168654aee1b0c1b73746caeb4aa33248f8b8c8f6e100e697fcc2a794b2" +checksum = "5d9e3e26fcb51976eafa310e8f2b7a5a83ae8c185443efe50cbc6534a4fffa0d" dependencies = [ - "array-init", "bit_field", "bitflags", "cast", - "ux", ] [[package]] name = "x86_64" -version = "0.8.1" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f21672dcbed52bc09eea030d189600c0189c66c97bc5b31779eb780e064a201f" +checksum = "4e6a3f047ad0844d3b4794f34d1095aefb918241064663d4163db8c7d4a76edf" dependencies = [ - "array-init", "bit_field", "bitflags", - "cast", ] From dd1daf2652b47194045f863366191ef8b032d2d2 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 6 Mar 2020 11:47:49 +0100 Subject: [PATCH 07/10] Update linked_list_allocator to v0.8.0 --- Cargo.lock | 30 +++++++++++++++++++++++++++--- Cargo.toml | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b9d56664..12acd7d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,11 +59,20 @@ dependencies = [ [[package]] name = "linked_list_allocator" -version = "0.6.6" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47de1a43fad0250ee197e9e124e5b5deab3d7b39d4428ae8a6d741ceb340c362" +checksum = "18c618c431dfe4419afbe22852f6aceffbc17bd82ba0a18b982def291000824c" dependencies = [ - "spin", + "spinning_top", +] + +[[package]] +name = "lock_api" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79b2de95ecb4691949fea4716ca53cdbcfccb2c612e19644a8bad05edcf9f47b" +dependencies = [ + "scopeguard", ] [[package]] @@ -90,6 +99,12 @@ dependencies = [ "semver", ] +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "semver" version = "0.9.0" @@ -111,6 +126,15 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spinning_top" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d801a3a53bcf5071f85fef8d5cab9e5f638fc5580a37e6eb7aba4b37438d24" +dependencies = [ + "lock_api", +] + [[package]] name = "uart_16550" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index bf32acbf..2ec2355e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ x86_64 = "0.8.1" uart_16550 = "0.2.0" pic8259_simple = "0.1.1" pc-keyboard = "0.5.0" -linked_list_allocator = "0.6.4" +linked_list_allocator = "0.8.0" [dependencies.lazy_static] version = "1.0" From 2039cd7a64e0d9eee2e4b588c0df539b58c5c23c Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 8 Mar 2020 14:27:36 +0100 Subject: [PATCH 08/10] Update x86_64 to version 0.9.5 --- Cargo.lock | 48 ++---------------------------------------------- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5457572..a9e36504 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,7 +21,7 @@ dependencies = [ "spin", "uart_16550", "volatile", - "x86_64 0.8.3", + "x86_64", ] [[package]] @@ -30,15 +30,6 @@ version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ed4f735c4e455ba86a3d2939b1c0729414153642106c9d035693355630a42c" -[[package]] -name = "cast" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" -dependencies = [ - "rustc_version", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -48,30 +39,6 @@ dependencies = [ "spin", ] -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "spin" version = "0.5.2" @@ -85,7 +52,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d44b0f30cb82b0fbc15b78ade1064226529ad52028bc8cb8accb98ff6f3d7131" dependencies = [ "bitflags", - "x86_64 0.9.5", + "x86_64", ] [[package]] @@ -94,17 +61,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6af0edf5b4faacc31fc51159244d78d65ec580f021afcef7bd53c04aeabc7f29" -[[package]] -name = "x86_64" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d9e3e26fcb51976eafa310e8f2b7a5a83ae8c185443efe50cbc6534a4fffa0d" -dependencies = [ - "bit_field", - "bitflags", - "cast", -] - [[package]] name = "x86_64" version = "0.9.5" diff --git a/Cargo.toml b/Cargo.toml index 30dd4ba4..a4fda487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ harness = false bootloader = "0.8.0" volatile = "0.2.6" spin = "0.5.2" -x86_64 = "0.8.1" +x86_64 = "0.9.5" uart_16550 = "0.2.0" [dependencies.lazy_static] From 7b0d8f05baa68ff74078b8df847fb2a1d3e21858 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 8 Mar 2020 14:30:33 +0100 Subject: [PATCH 09/10] Fix code for x86_64 v0.9.5 update --- src/allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index f77fef9d..955ddc76 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -17,7 +17,7 @@ static ALLOCATOR: LockedHeap = LockedHeap::empty(); pub fn init_heap( mapper: &mut impl Mapper, frame_allocator: &mut impl FrameAllocator, -) -> Result<(), MapToError> { +) -> Result<(), MapToError> { let page_range = { let heap_start = VirtAddr::new(HEAP_START as u64); let heap_end = heap_start + HEAP_SIZE - 1u64; From d7e505da9e5c229d85030984814aea37786c3f85 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 8 Mar 2020 14:39:27 +0100 Subject: [PATCH 10/10] Update x86_64 dependency to version 0.9.6 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9e36504..81482a7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,9 +63,9 @@ checksum = "6af0edf5b4faacc31fc51159244d78d65ec580f021afcef7bd53c04aeabc7f29" [[package]] name = "x86_64" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e6a3f047ad0844d3b4794f34d1095aefb918241064663d4163db8c7d4a76edf" +checksum = "4206b60c9f99766329b66962aa8ddc01df6c7edd02edc046b7a69d5df9fcdbcf" dependencies = [ "bit_field", "bitflags", diff --git a/Cargo.toml b/Cargo.toml index a4fda487..55993afa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ harness = false bootloader = "0.8.0" volatile = "0.2.6" spin = "0.5.2" -x86_64 = "0.9.5" +x86_64 = "0.9.6" uart_16550 = "0.2.0" [dependencies.lazy_static]