1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 16:16:16 +04:00

impl custom syscall: sys_get_paddr

This commit is contained in:
WangRunji 2019-03-16 21:24:41 +08:00
parent 1c5effae04
commit c6c76147d6
4 changed files with 31 additions and 2 deletions

View File

@ -369,6 +369,19 @@ impl<T: InactivePageTable> MemorySet<T> {
areas.clear();
}
/// Get physical address of the page of given virtual `addr`
pub fn translate(&mut self, addr: VirtAddr) -> Option<PhysAddr> {
self.page_table.edit(|pt| {
pt.get_entry(addr).and_then(|entry| {
if entry.user() {
Some(entry.target())
} else {
None
}
})
})
}
/*
** @brief get the mutable reference for the inactive page table
** @retval: &mut T the mutable reference of the inactive page table

View File

@ -16,9 +16,9 @@ pub type MemorySet = rcore_memory::memory_set::MemorySet<InactivePageTable0>;
#[cfg(feature = "no_mmu")]
pub type MemorySet = rcore_memory::no_mmu::MemorySet<NoMMUSupportImpl>;
// x86_64 support up to 256M memory
// x86_64 support up to 64G memory
#[cfg(target_arch = "x86_64")]
pub type FrameAlloc = bit_allocator::BitAlloc64K;
pub type FrameAlloc = bit_allocator::BitAlloc16M;
// RISCV has 8M memory
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]

View File

@ -33,3 +33,18 @@ pub fn sys_map_pci_device(vendor: usize, product: usize) -> SysResult {
pub fn sys_map_pci_device(vendor: usize, product: usize) -> SysResult {
Err(SysError::ENOSYS)
}
/// Get start physical addresses of frames
/// mapped to a list of virtual addresses.
pub fn sys_get_paddr(vaddrs: *const u64, paddrs: *mut u64, count: usize) -> SysResult {
let mut proc = process();
proc.memory_set.check_array(vaddrs, count)?;
proc.memory_set.check_mut_array(paddrs, count)?;
let vaddrs = unsafe { slice::from_raw_parts(vaddrs, count) };
let paddrs = unsafe { slice::from_raw_parts_mut(paddrs, count) };
for i in 0..count {
let paddr = proc.memory_set.translate(vaddrs[i] as usize).unwrap_or(0);
paddrs[i] = paddr as u64;
}
Ok(0)
}

View File

@ -128,6 +128,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
288 => sys_accept(args[0], args[1] as *mut SockAddr, args[2] as *mut u32), // use accept for accept4
// custom temporary syscall
999 => sys_map_pci_device(args[0], args[1]),
998 => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]),
// 293 => sys_pipe(),
// for musl: empty impl