Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel mapping #594

Merged
merged 6 commits into from
Mar 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/orbital/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ fn main() {
let status_mutex = Arc::new(Mutex::new(Status::Starting));

let status_daemon = status_mutex.clone();
let daemon_thread = thread::spawn(move || {
thread::spawn(move || {
match Socket::create(":orbital").map(|socket| Arc::new(socket)) {
Ok(socket) => match Socket::open("display:manager").map(|display| Arc::new(display)) {
Ok(display) => {
Expand Down Expand Up @@ -504,14 +504,12 @@ fn main() {
match *status_mutex.lock().unwrap() {
Status::Starting => (),
Status::Running => {
Command::new("launcher").spawn().unwrap().wait().unwrap();
Command::new("launcher").spawn().unwrap();
break 'waiting;
},
Status::Stopping => break 'waiting,
}

thread::sleep_ms(30);
}

daemon_thread.join().unwrap();
}
59 changes: 54 additions & 5 deletions kernel/alloc_system.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,68 @@
use arch::memory::*;
use arch::paging::Page;

const LOGICAL_OFFSET: usize = 0x80000000;

#[allocator]
#[no_mangle]
pub extern "C" fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
unsafe { alloc_aligned(size, align) as *mut u8 }
unsafe {
let address = alloc_aligned(size, align);
if address > 0 {
for page in 0..(size + CLUSTER_SIZE - 1)/CLUSTER_SIZE {
let physical_address = address + page * CLUSTER_SIZE;
let virtual_address = physical_address + LOGICAL_OFFSET;
Page::new(virtual_address).map_kernel_write(physical_address);
}

(address + LOGICAL_OFFSET) as *mut u8
} else {
address as *mut u8
}
}
}

#[no_mangle]
pub extern "C" fn __rust_deallocate(ptr: *mut u8, _old_size: usize, _align: usize) {
unsafe { unalloc(ptr as usize) }
pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, _align: usize) {
unsafe {
let address = ptr as usize - LOGICAL_OFFSET;

unalloc(address);

for page in 0..(old_size + CLUSTER_SIZE - 1)/CLUSTER_SIZE {
let physical_address = address + page * CLUSTER_SIZE;
let virtual_address = physical_address + LOGICAL_OFFSET;
Page::new(virtual_address).unmap();
}
}
}

#[no_mangle]
pub extern "C" fn __rust_reallocate(ptr: *mut u8, _old_size: usize, size: usize, align: usize) -> *mut u8 {
unsafe { realloc_aligned(ptr as usize, size, align) as *mut u8 }
pub extern "C" fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
unsafe {
let old_address = ptr as usize - LOGICAL_OFFSET;
let address = realloc_aligned(old_address, size, align);

if address > 0 {
if address != old_address {
for page in 0..(old_size + CLUSTER_SIZE - 1)/CLUSTER_SIZE {
let physical_address = old_address + page * CLUSTER_SIZE;
let virtual_address = physical_address + LOGICAL_OFFSET;
Page::new(virtual_address).unmap();
}

for page in 0..(size + CLUSTER_SIZE - 1)/CLUSTER_SIZE {
let physical_address = address + page * CLUSTER_SIZE;
let virtual_address = physical_address + LOGICAL_OFFSET;
Page::new(virtual_address).map_kernel_write(physical_address);
}
}

(address + LOGICAL_OFFSET) as *mut u8
} else {
address as *mut u8
}
}
}

#[no_mangle]
Expand Down