Format code

toolchain_update
Jiajie Chen 6 years ago
parent 72efa797e5
commit e5894b652c

@ -12,8 +12,6 @@ use rcore_memory::paging::PageTable;
use rcore_memory::PAGE_SIZE; use rcore_memory::PAGE_SIZE;
use volatile::Volatile; use volatile::Volatile;
use rcore_fs::dev::BlockDevice;
use crate::drivers::BlockDriver; use crate::drivers::BlockDriver;
use crate::memory::active_table; use crate::memory::active_table;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;

@ -72,21 +72,21 @@ pub trait Driver: Send + Sync {
} }
// send an ethernet frame, only use it when necessary // send an ethernet frame, only use it when necessary
fn send(&self, data: &[u8]) -> Option<usize> { fn send(&self, _data: &[u8]) -> Option<usize> {
unimplemented!("not a net driver") unimplemented!("not a net driver")
} }
// get mac address from ip address in arp table // get mac address from ip address in arp table
fn get_arp(&self, ip: IpAddress) -> Option<EthernetAddress> { fn get_arp(&self, _ip: IpAddress) -> Option<EthernetAddress> {
unimplemented!("not a net driver") unimplemented!("not a net driver")
} }
// block related drivers should implement these // block related drivers should implement these
fn read_block(&self, block_id: usize, buf: &mut [u8]) -> bool { fn read_block(&self, _block_id: usize, _buf: &mut [u8]) -> bool {
unimplemented!("not a block driver") unimplemented!("not a block driver")
} }
fn write_block(&self, block_id: usize, buf: &[u8]) -> bool { fn write_block(&self, _block_id: usize, _buf: &[u8]) -> bool {
unimplemented!("not a block driver") unimplemented!("not a block driver")
} }
} }

@ -15,7 +15,6 @@ use smoltcp::wire::EthernetAddress;
use smoltcp::wire::*; use smoltcp::wire::*;
use smoltcp::Result; use smoltcp::Result;
use crate::memory::active_table;
use crate::net::SOCKETS; use crate::net::SOCKETS;
use crate::sync::FlagsGuard; use crate::sync::FlagsGuard;
use crate::sync::SpinNoIrqLock as Mutex; use crate::sync::SpinNoIrqLock as Mutex;

@ -2,7 +2,6 @@ use alloc::alloc::{GlobalAlloc, Layout};
use alloc::format; use alloc::format;
use alloc::string::String; use alloc::string::String;
use alloc::sync::Arc; use alloc::sync::Arc;
use alloc::vec::Vec;
use core::mem::size_of; use core::mem::size_of;
use core::slice; use core::slice;

@ -105,7 +105,7 @@ impl KernelStack {
pub fn new() -> Self { pub fn new() -> Self {
use alloc::alloc::{alloc, Layout}; use alloc::alloc::{alloc, Layout};
let bottom = let bottom =
unsafe { alloc(Layout::from_size_align(KSTACK_SIZE, KSTACK_SIZE).unwrap())} as usize; unsafe { alloc(Layout::from_size_align(KSTACK_SIZE, KSTACK_SIZE).unwrap()) } as usize;
KernelStack(bottom) KernelStack(bottom)
} }
pub fn top(&self) -> usize { pub fn top(&self) -> usize {

@ -55,7 +55,7 @@ pub trait Socket: Send + Sync {
fn write(&self, data: &[u8], sendto_endpoint: Option<Endpoint>) -> SysResult; fn write(&self, data: &[u8], sendto_endpoint: Option<Endpoint>) -> SysResult;
fn poll(&self) -> (bool, bool, bool); // (in, out, err) fn poll(&self) -> (bool, bool, bool); // (in, out, err)
fn connect(&mut self, endpoint: Endpoint) -> SysResult; fn connect(&mut self, endpoint: Endpoint) -> SysResult;
fn bind(&mut self, endpoint: Endpoint) -> SysResult { fn bind(&mut self, _endpoint: Endpoint) -> SysResult {
Err(SysError::EINVAL) Err(SysError::EINVAL)
} }
fn listen(&mut self) -> SysResult { fn listen(&mut self) -> SysResult {
@ -73,11 +73,11 @@ pub trait Socket: Send + Sync {
fn remote_endpoint(&self) -> Option<Endpoint> { fn remote_endpoint(&self) -> Option<Endpoint> {
None None
} }
fn setsockopt(&mut self, level: usize, opt: usize, data: &[u8]) -> SysResult { fn setsockopt(&mut self, _level: usize, _opt: usize, _data: &[u8]) -> SysResult {
warn!("setsockopt is unimplemented"); warn!("setsockopt is unimplemented");
Ok(0) Ok(0)
} }
fn ioctl(&mut self, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult { fn ioctl(&mut self, _request: usize, _arg1: usize, _arg2: usize, _arg3: usize) -> SysResult {
warn!("ioctl is unimplemented for this socket"); warn!("ioctl is unimplemented for this socket");
Ok(0) Ok(0)
} }

@ -15,7 +15,6 @@ use xmas_elf::{
use crate::arch::interrupt::{Context, TrapFrame}; use crate::arch::interrupt::{Context, TrapFrame};
use crate::fs::{FileHandle, FileLike, INodeExt, OpenOptions, FOLLOW_MAX_DEPTH}; use crate::fs::{FileHandle, FileLike, INodeExt, OpenOptions, FOLLOW_MAX_DEPTH};
use crate::memory::{ByFrame, GlobalFrameAlloc, KernelStack, MemoryAttr, MemorySet}; use crate::memory::{ByFrame, GlobalFrameAlloc, KernelStack, MemoryAttr, MemorySet};
use crate::net::SOCKETS;
use crate::sync::{Condvar, SpinNoIrqLock as Mutex}; use crate::sync::{Condvar, SpinNoIrqLock as Mutex};
use super::abi::{self, ProcInitInfo}; use super::abi::{self, ProcInitInfo};

@ -6,28 +6,28 @@ use crate::process::*;
use alloc::string::String; use alloc::string::String;
use alloc::vec::Vec; use alloc::vec::Vec;
#[cfg(not(feature = "run_cmdline"))] #[cfg(not(feature = "run_cmdline"))]
pub fn add_user_shell() { pub fn add_user_shell() {
/// the busybox of alpine linux can not transfer env vars into child process // the busybox of alpine linux can not transfer env vars into child process
/// Now we use busybox from // Now we use busybox from
/// https://raw.githubusercontent.com/docker-library/busybox/82bc0333a9ae148fbb4246bcbff1487b3fc0c510/musl/busybox.tar.xz -O busybox.tar.xz // https://raw.githubusercontent.com/docker-library/busybox/82bc0333a9ae148fbb4246bcbff1487b3fc0c510/musl/busybox.tar.xz -O busybox.tar.xz
/// This one can transfer env vars! // This one can transfer env vars!
/// Why??? // Why???
// #[cfg(target_arch = "x86_64")] // #[cfg(target_arch = "x86_64")]
// let init_shell="/bin/busybox"; // from alpine linux // let init_shell="/bin/busybox"; // from alpine linux
// //
// #[cfg(not(target_arch = "x86_64"))] // #[cfg(not(target_arch = "x86_64"))]
let init_shell="/busybox"; //from docker-library let init_shell = "/busybox"; //from docker-library
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
let init_envs=vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-alpine-linux-musl/bin".into()]; let init_envs =
vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-alpine-linux-musl/bin".into()];
#[cfg(not(target_arch = "x86_64"))] #[cfg(not(target_arch = "x86_64"))]
let init_envs=Vec::new(); let init_envs = Vec::new();
let init_args=vec!["busybox".into(), "ash".into()]; let init_args = vec!["busybox".into(), "ash".into()];
if let Ok(inode) = ROOT_INODE.lookup(init_shell) { if let Ok(inode) = ROOT_INODE.lookup(init_shell) {
let data = inode.read_as_vec().unwrap(); let data = inode.read_as_vec().unwrap();

@ -625,27 +625,23 @@ pub fn sys_pipe(fds: *mut u32) -> SysResult {
let fds = unsafe { proc.vm.check_write_array(fds, 2)? }; let fds = unsafe { proc.vm.check_write_array(fds, 2)? };
let (read, write) = Pipe::create_pair(); let (read, write) = Pipe::create_pair();
let read_fd = proc.add_file( let read_fd = proc.add_file(FileLike::File(FileHandle::new(
FileLike::File(FileHandle::new(
Arc::new(read), Arc::new(read),
OpenOptions { OpenOptions {
read: true, read: true,
write: false, write: false,
append: false, append: false,
}, },
)), )));
);
let write_fd = proc.add_file( let write_fd = proc.add_file(FileLike::File(FileHandle::new(
FileLike::File(FileHandle::new(
Arc::new(write), Arc::new(write),
OpenOptions { OpenOptions {
read: false, read: false,
write: true, write: true,
append: false, append: false,
}, },
)), )));
);
fds[0] = read_fd as u32; fds[0] = read_fd as u32;
fds[1] = write_fd as u32; fds[1] = write_fd as u32;
@ -678,9 +674,7 @@ pub fn sys_sendfile(
let mut buffer = [0u8; 1024]; let mut buffer = [0u8; 1024];
let mut read_offset = if !offset_ptr.is_null() { let mut read_offset = if !offset_ptr.is_null() {
unsafe { unsafe { *(*proc_cell.get()).vm.check_read_ptr(offset_ptr)? }
*(*proc_cell.get()).vm.check_read_ptr(offset_ptr)?
}
} else { } else {
in_file.seek(SeekFrom::Current(0))? as usize in_file.seek(SeekFrom::Current(0))? as usize
}; };
@ -700,7 +694,7 @@ pub fn sys_sendfile(
let mut bytes_written = 0; let mut bytes_written = 0;
let mut rlen = read_len; let mut rlen = read_len;
while bytes_written < read_len { while bytes_written < read_len {
let write_len = out_file.write(&buffer[bytes_written..(bytes_written+rlen)])?; let write_len = out_file.write(&buffer[bytes_written..(bytes_written + rlen)])?;
if write_len == 0 { if write_len == 0 {
info!( info!(
"sendfile:END_ERR out: {}, in: {}, offset_ptr: {:?}, count: {} = bytes_read {}, bytes_written {}, write_len {}", "sendfile:END_ERR out: {}, in: {}, offset_ptr: {:?}, count: {} = bytes_read {}, bytes_written {}, write_len {}",
@ -709,9 +703,9 @@ pub fn sys_sendfile(
return Err(SysError::EBADF); return Err(SysError::EBADF);
} }
bytes_written += write_len; bytes_written += write_len;
rlen-=write_len; rlen -= write_len;
} }
total_written+=bytes_written; total_written += bytes_written;
} }
if !offset_ptr.is_null() { if !offset_ptr.is_null() {

@ -46,15 +46,15 @@ pub fn sys_mmap(
addr, addr,
addr + len, addr + len,
prot.to_attr(), prot.to_attr(),
// ByFrame::new(GlobalFrameAlloc), //eagle mmap mode // ByFrame::new(GlobalFrameAlloc), //eagle mmap mode
Delay::new(GlobalFrameAlloc), Delay::new(GlobalFrameAlloc),
"mmap_anon", "mmap_anon",
); );
//init with zero for eagle mmap mode //init with zero for eagle mmap mode
// let data = unsafe { slice::from_raw_parts_mut(addr as *mut u8, len) }; // let data = unsafe { slice::from_raw_parts_mut(addr as *mut u8, len) };
// for x in data { // for x in data {
// *x = 0; // *x = 0;
// } // }
return Ok(addr); return Ok(addr);
} else { } else {
// only check // only check

@ -192,15 +192,16 @@ pub struct RLimit {
max: u64, // hard limit max: u64, // hard limit
} }
pub fn sys_getrandom( buf: *mut u8, len: usize, flag: u32) -> SysResult { pub fn sys_getrandom(buf: *mut u8, len: usize, flag: u32) -> SysResult {
//info!("getrandom: buf: {:?}, len: {:?}, falg {:?}", buf, len,flag); //info!("getrandom: buf: {:?}, len: {:?}, falg {:?}", buf, len,flag);
let mut proc = process(); let mut proc = process();
let slice = unsafe { proc.vm.check_write_array(buf, len)? }; let slice = unsafe { proc.vm.check_write_array(buf, len)? };
let mut i=0; let mut i = 0;
for elm in slice { for elm in slice {
unsafe{ *elm=i+ crate::trap::TICK as u8;} unsafe {
i+=1; *elm = i + crate::trap::TICK as u8;
}
i += 1;
} }
Ok(len) Ok(len)

@ -231,7 +231,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
SYS_MAP_PCI_DEVICE => sys_map_pci_device(args[0], args[1]), SYS_MAP_PCI_DEVICE => sys_map_pci_device(args[0], args[1]),
SYS_GET_PADDR => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]), SYS_GET_PADDR => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]),
//SYS_GETRANDOM => unimplemented("getrandom", Err(SysError::EINVAL)), //SYS_GETRANDOM => unimplemented("getrandom", Err(SysError::EINVAL)),
SYS_GETRANDOM =>sys_getrandom( args[0] as *mut u8, args[1] as usize, args[2] as u32), SYS_GETRANDOM => sys_getrandom(args[0] as *mut u8, args[1] as usize, args[2] as u32),
SYS_TKILL => unimplemented("tkill", Ok(0)), SYS_TKILL => unimplemented("tkill", Ok(0)),
_ => { _ => {
let ret = match () { let ret = match () {

@ -1 +1 @@
Subproject commit 8dbc0edb935a62d748aaac39258d4a985de0ae17 Subproject commit 05f0efd3fda084109e4b6da8ff30ecb1557a267f
Loading…
Cancel
Save