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

fix #13 page fault #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions os/src/memory/memory_set/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ impl MemoryArea {
pub fn page_copy(&self, pt: &mut PageTableImpl, src: usize, length: usize) {
let mut l = length;
let mut s = src;
let mut offset = self.start % PAGE_SIZE;
for page in PageRange::new(self.start, self.end) {
let copy_size = PAGE_SIZE-offset;
self.handler
.page_copy(pt, page, s, if l < PAGE_SIZE { l } else { PAGE_SIZE });
s += PAGE_SIZE;
if l >= PAGE_SIZE {
l -= PAGE_SIZE;
.page_copy(pt, page, offset, s, if l < copy_size { l } else { copy_size });
offset = 0;
s += copy_size;
if l >= copy_size {
l -= copy_size;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions os/src/memory/memory_set/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait MemoryHandler: Debug + 'static {
fn box_clone(&self) -> Box<dyn MemoryHandler>;
fn map(&self, pt: &mut PageTableImpl, va: usize, attr: &MemoryAttr);
fn unmap(&self, pt: &mut PageTableImpl, va: usize);
fn page_copy(&self, pt: &mut PageTableImpl, va: usize, src: usize, length: usize);
fn page_copy(&self, pt: &mut PageTableImpl, va: usize, va_offset: usize, src: usize, length: usize);
}

impl Clone for Box<dyn MemoryHandler> {
Expand Down Expand Up @@ -39,12 +39,12 @@ impl MemoryHandler for Linear {
fn unmap(&self, pt: &mut PageTableImpl, va: usize) {
pt.unmap(va);
}
fn page_copy(&self, pt: &mut PageTableImpl, va: usize, src: usize, length: usize) {
fn page_copy(&self, pt: &mut PageTableImpl, va: usize, va_offset: usize, src: usize, length: usize) {
let pa = pt.get_entry(va).expect("get pa error!").0.addr().as_usize();
assert!(va == access_pa_via_va(pa));
assert!(va == pa + self.offset);
unsafe {
let dst = core::slice::from_raw_parts_mut(va as *mut u8, PAGE_SIZE);
let dst = core::slice::from_raw_parts_mut((va+va_offset) as *mut u8, PAGE_SIZE);
if length > 0 {
let src = core::slice::from_raw_parts(src as *const u8, PAGE_SIZE);
dst[..length].clone_from_slice(&src[..length]);
Expand Down Expand Up @@ -78,10 +78,10 @@ impl MemoryHandler for ByFrame {
fn unmap(&self, pt: &mut PageTableImpl, va: usize) {
pt.unmap(va);
}
fn page_copy(&self, pt: &mut PageTableImpl, va: usize, src: usize, length: usize) {
fn page_copy(&self, pt: &mut PageTableImpl, va: usize, va_offset: usize, src: usize, length: usize) {
let pa = pt.get_entry(va).expect("get pa error!").0.addr().as_usize();
unsafe {
let dst = core::slice::from_raw_parts_mut(access_pa_via_va(pa) as *mut u8, PAGE_SIZE);
let dst = core::slice::from_raw_parts_mut((access_pa_via_va(pa)+va_offset) as *mut u8, PAGE_SIZE);
if length > 0 {
let src = core::slice::from_raw_parts(src as *const u8, PAGE_SIZE);
dst[..length].clone_from_slice(&src[..length]);
Expand Down