From a7bfe1232a3611d73e70dedd755f6369d83db35b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 14 Nov 2016 11:04:31 -0700 Subject: [PATCH] Implement more test arch features --- lib.rs | 1 - scheme/initfs.rs | 7 +++++++ syscall/process.rs | 41 ++++++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/lib.rs b/lib.rs index 5a90e4e..b1daafc 100644 --- a/lib.rs +++ b/lib.rs @@ -48,7 +48,6 @@ use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; pub mod context; /// ELF file parsing -#[cfg(all(not(test), target_arch = "x86_64"))] pub mod elf; /// Schemes, filesystem handlers diff --git a/scheme/initfs.rs b/scheme/initfs.rs index 99f1f7d..4857426 100644 --- a/scheme/initfs.rs +++ b/scheme/initfs.rs @@ -8,6 +8,13 @@ use syscall::error::*; use syscall::flag::{MODE_DIR, MODE_FILE, SEEK_SET, SEEK_CUR, SEEK_END}; use syscall::scheme::Scheme; +#[cfg(test)] +mod gen { + use collections::BTreeMap; + pub fn gen() -> BTreeMap<&'static [u8], (&'static [u8], bool)> { BTreeMap::new() } +} + +#[cfg(not(test))] #[path="../../build/userspace/initfs.rs"] mod gen; diff --git a/syscall/process.rs b/syscall/process.rs index 87053af..ba623a4 100644 --- a/syscall/process.rs +++ b/syscall/process.rs @@ -2,12 +2,11 @@ use alloc::arc::Arc; use alloc::boxed::Box; use collections::{BTreeMap, Vec}; -use core::{mem, str}; +use core::{intrinsics, mem, str}; use core::ops::DerefMut; use spin::Mutex; use arch; -use arch::externs::memcpy; use arch::memory::{allocate_frame, allocate_frames, deallocate_frames, Frame}; use arch::paging::{ActivePageTable, InactivePageTable, Page, PhysicalAddress, VirtualAddress, entry}; use arch::paging::temporary_page::TemporaryPage; @@ -136,9 +135,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { ); unsafe { - arch::externs::memcpy(new_memory.start_address().get() as *mut u8, - memory.start_address().get() as *const u8, - memory.size()); + intrinsics::copy(memory.start_address().get() as *const u8, + new_memory.start_address().get() as *mut u8, + memory.size()); } new_memory.remap(memory.flags(), true); @@ -157,9 +156,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { ); unsafe { - arch::externs::memcpy(new_heap.start_address().get() as *mut u8, - heap.start_address().get() as *const u8, - heap.size()); + intrinsics::copy(heap.start_address().get() as *const u8, + new_heap.start_address().get() as *mut u8, + heap.size()); } new_heap.remap(heap.flags(), true); @@ -178,9 +177,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { ); unsafe { - arch::externs::memcpy(new_stack.start_address().get() as *mut u8, - stack.start_address().get() as *const u8, - stack.size()); + intrinsics::copy(stack.start_address().get() as *const u8, + new_stack.start_address().get() as *mut u8, + stack.size()); } new_stack.remap(stack.flags(), true); @@ -201,9 +200,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { }; unsafe { - arch::externs::memcpy(new_tls.mem.start_address().get() as *mut u8, - tls.master.get() as *const u8, - tls.file_size); + intrinsics::copy(tls.master.get() as *const u8, + new_tls.mem.start_address().get() as *mut u8, + tls.file_size); } new_tls.mem.remap(tls.mem.flags(), true); @@ -533,9 +532,9 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { unsafe { // Copy file data - memcpy(segment.p_vaddr as *mut u8, - (elf.data.as_ptr() as usize + segment.p_offset as usize) as *const u8, - segment.p_filesz as usize); + intrinsics::copy((elf.data.as_ptr() as usize + segment.p_offset as usize) as *const u8, + segment.p_vaddr as *mut u8, + segment.p_filesz as usize); } let mut flags = entry::NO_EXECUTE | entry::USER_ACCESSIBLE; @@ -609,8 +608,8 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { unsafe { // Copy file data - memcpy(tls.mem.start_address().get() as *mut u8, - master.get() as *const u8, + intrinsics::copy(master.get() as *const u8, + tls.mem.start_address().get() as *mut u8, file_size); } @@ -643,8 +642,8 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result { let mut arg_offset = 0; for arg in args.iter().rev() { unsafe { - memcpy((arch::USER_ARG_OFFSET + arg_offset) as *mut u8, - arg.as_ptr(), + intrinsics::copy(arg.as_ptr(), + (arch::USER_ARG_OFFSET + arg_offset) as *mut u8, arg.len()); }