Add stack guard and fix early exceptions
All checks were successful
Build / build (push) Successful in 2m43s
All checks were successful
Build / build (push) Successful in 2m43s
This commit is contained in:
parent
bb7c9b6bfa
commit
bb6de0ce8d
4 changed files with 15 additions and 4 deletions
|
@ -17,6 +17,8 @@ _start:
|
||||||
.global __stack_chk_guard
|
.global __stack_chk_guard
|
||||||
__stack_chk_guard:
|
__stack_chk_guard:
|
||||||
.skip 8
|
.skip 8
|
||||||
.align 16
|
.align 0x1000
|
||||||
|
.global _stack_guard
|
||||||
|
_stack_guard:
|
||||||
.skip 0x10000
|
.skip 0x10000
|
||||||
stack:
|
stack:
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
sys::{
|
sys::{
|
||||||
lapic::{get_current_lapic_id, send_eoi},
|
lapic::{get_current_lapic_id, send_eoi},
|
||||||
locks::Spinlock,
|
locks::Spinlock,
|
||||||
|
madt::INTERRUPTS_SETUP,
|
||||||
scheduler::scheduler,
|
scheduler::scheduler,
|
||||||
sync::{IN_ISR_HANDLER, LOCKS_HELD},
|
sync::{IN_ISR_HANDLER, LOCKS_HELD},
|
||||||
task::{TaskState, CURRENT_TASKS},
|
task::{TaskState, CURRENT_TASKS},
|
||||||
|
@ -109,8 +110,11 @@ extern "C" fn isr_handler(state: &mut ISRState) {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let lapic_id = get_current_lapic_id();
|
let mut lapic_id = 0;
|
||||||
IN_ISR_HANDLER[lapic_id].store(true, Ordering::SeqCst);
|
if INTERRUPTS_SETUP.load(Ordering::SeqCst) {
|
||||||
|
lapic_id = get_current_lapic_id();
|
||||||
|
IN_ISR_HANDLER[lapic_id].store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
if state.isr < 32 {
|
if state.isr < 32 {
|
||||||
if state.cs == 0x23 && state.isr != 2 && state.isr != 8 && state.isr != 18 {
|
if state.cs == 0x23 && state.isr != 2 && state.isr != 8 && state.isr != 18 {
|
||||||
debug!("Exception in usermode: {}", EXCEPTIONS[state.isr as usize]);
|
debug!("Exception in usermode: {}", EXCEPTIONS[state.isr as usize]);
|
||||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
||||||
static _data_end: u8;
|
static _data_end: u8;
|
||||||
static _bss_start: u8;
|
static _bss_start: u8;
|
||||||
static _bss_end: u8;
|
static _bss_end: u8;
|
||||||
|
static _stack_guard: u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AddressSpace {
|
pub struct AddressSpace {
|
||||||
|
@ -82,6 +83,7 @@ impl AddressSpace {
|
||||||
fn map(&mut self, virt: u64, phys: u64, user: bool, write: bool, exec: bool, cache_disable: bool, only_flags: bool) {
|
fn map(&mut self, virt: u64, phys: u64, user: bool, write: bool, exec: bool, cache_disable: bool, only_flags: bool) {
|
||||||
assert!(virt >= 0x1000, "First page shouldn't be mapped");
|
assert!(virt >= 0x1000, "First page shouldn't be mapped");
|
||||||
assert!(!write || !exec || virt == 0x1000);
|
assert!(!write || !exec || virt == 0x1000);
|
||||||
|
assert!(user == (virt < USER_END) || virt == 0x1000);
|
||||||
{
|
{
|
||||||
let mut frames_vec = PHYSICAL_FRAMES.lock();
|
let mut frames_vec = PHYSICAL_FRAMES.lock();
|
||||||
let frame = phys as usize / 0x1000;
|
let frame = phys as usize / 0x1000;
|
||||||
|
@ -249,6 +251,7 @@ pub fn setup_paging(loader_struct: &LoaderStruct, phys_start: u64, heap_start: u
|
||||||
assert!(!frames_vec.get(1).unwrap());
|
assert!(!frames_vec.get(1).unwrap());
|
||||||
frames_vec.set(1, true);
|
frames_vec.set(1, true);
|
||||||
}
|
}
|
||||||
|
let stack_guard;
|
||||||
let text_start;
|
let text_start;
|
||||||
let text_end;
|
let text_end;
|
||||||
let rodata_start;
|
let rodata_start;
|
||||||
|
@ -258,6 +261,7 @@ pub fn setup_paging(loader_struct: &LoaderStruct, phys_start: u64, heap_start: u
|
||||||
let bss_start;
|
let bss_start;
|
||||||
let bss_end;
|
let bss_end;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
stack_guard = &_stack_guard as *const u8 as u64;
|
||||||
text_start = &_text_start as *const u8 as u64 / 0x1000;
|
text_start = &_text_start as *const u8 as u64 / 0x1000;
|
||||||
text_end = (&_text_end as *const u8 as u64 + 0xfff) / 0x1000;
|
text_end = (&_text_end as *const u8 as u64 + 0xfff) / 0x1000;
|
||||||
rodata_start = &_rodata_start as *const u8 as u64 / 0x1000;
|
rodata_start = &_rodata_start as *const u8 as u64 / 0x1000;
|
||||||
|
@ -304,6 +308,7 @@ pub fn setup_paging(loader_struct: &LoaderStruct, phys_start: u64, heap_start: u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
|
address_space.update_flags_range(stack_guard, 0x1000, false, false, false);
|
||||||
address_space.switch();
|
address_space.switch();
|
||||||
}
|
}
|
||||||
PAGING_ACTIVE.store(true, Ordering::SeqCst);
|
PAGING_ACTIVE.store(true, Ordering::SeqCst);
|
||||||
|
|
|
@ -39,7 +39,7 @@ fn copy_from_user(start: u64, size: usize) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
let mut process = process.lock();
|
let mut process = process.lock();
|
||||||
for i in start / 0x1000..(end + 0xfff) / 0x1000 {
|
for i in start / 0x1000..(end + 0xfff) / 0x1000 {
|
||||||
let page = process.address_space.get_page(i * 0x1000);
|
let page = process.address_space.get_page(i * 0x1000);
|
||||||
if page.is_none() || page.unwrap().present() == 0 {
|
if page.is_none() {
|
||||||
return Err("Invalid copy requested".into());
|
return Err("Invalid copy requested".into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue