Implement mapping from riscv to x86_64 syscall numbering

master
Jiajie Chen 6 years ago
parent cd23967f97
commit 8860f1e4a3

@ -6,6 +6,7 @@ pub mod memory;
pub mod compiler_rt;
pub mod consts;
pub mod cpu;
pub mod syscall;
use log::*;
#[no_mangle]

@ -0,0 +1,34 @@
pub fn translate(id: usize) -> usize {
match id {
17 => 79, // getcwd
25 => 72, // fcntl
29 => 16, // ioctl
49 => 80, // chdir
50 => 81, // fchdir
51 => 161, // chroot
59 => 293, // pipe2
61 => 217, // getdents64
62 => 8, // lseek
63 => 0, // read
64 => 1, // write
65 => 19, // readv
66 => 20, // writev
67 => 17, // pread64
68 => 18, // pwrite64
69 => 295, // preadv
70 => 296, // pwritev
124 => 24, // sched_yield
166 => 95, // umask
172 => 39, // getpid
173 => 110, // getppid
174 => 102, // getuid
175 => 107, // geteuid
176 => 104, // getgid
177 => 108, // getegid
214 => 12, // brk
220 => 56, // clone
221 => 59, // execve
260 => 61, // wait4
_ => panic!("riscv syscall id {} not found", id)
}
}

@ -12,6 +12,7 @@ pub mod memory;
pub mod io;
pub mod consts;
pub mod timer;
pub mod syscall;
static AP_CAN_INIT: AtomicBool = ATOMIC_BOOL_INIT;

@ -0,0 +1,4 @@
/// We use x86_64 syscall numbers
pub fn translate(id: usize) -> usize {
id
}

@ -99,7 +99,6 @@ impl Driver for VirtIOBlkDriver {
let interrupt = header.interrupt_status.read();
if interrupt != 0 {
header.interrupt_ack.write(interrupt);
debug!("Got interrupt {:?}", interrupt);
return true;
}
return false;

@ -345,7 +345,7 @@ pub fn virtio_probe(node: &Node) {
let device_id = header.device_id.read();
// only support legacy device
if magic == 0x74726976 && version == 1 && device_id != 0 { // "virt" magic
info!("Detected virtio net device with vendor id {:#X}", header.vendor_id.read());
info!("Detected virtio device with vendor id {:#X}", header.vendor_id.read());
info!("Device tree node {:?}", node);
// virtio 3.1.1 Device Initialization
header.status.write(0);

@ -324,13 +324,14 @@ impl Thread {
debug!("fork: temporary copy data!");
let kstack = KernelStack::new();
let iface = &*(NET_DRIVERS.read()[0]);
for iface in NET_DRIVERS.read().iter() {
let mut sockets = iface.sockets();
for (_fd, file) in files.iter() {
if let FileLike::Socket(wrapper) = file {
sockets.retain(wrapper.handle);
}
}
}
Box::new(Thread {

@ -13,6 +13,7 @@ use crate::process::*;
use crate::thread;
use crate::util;
use crate::arch::cpu;
use crate::arch::syscall;
use self::fs::*;
use self::mem::*;
@ -30,6 +31,7 @@ mod misc;
/// System call dispatcher
pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
let x86_64_id = syscall::translate(id);
let cid = cpu::id();
let pid = {
process().pid.clone()
@ -37,9 +39,13 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
let tid = processor().tid();
if !pid.is_init() {
// we trust pid 0 process
debug!("{}:{}:{} syscall id {} begin", cid, pid, tid, id);
debug!("{}:{}:{} syscall id {}->{} begin", cid, pid, tid, id, x86_64_id);
}
let ret = match id {
// use syscall numbers in Linux x86_64
// See https://filippo.io/linux-syscall-table/
// And https://fedora.juszkiewicz.com.pl/syscalls.html.
let ret = match x86_64_id {
// file
000 => sys_read(args[0], args[1] as *mut u8, args[2]),
001 => sys_write(args[0], args[1] as *const u8, args[2]),
@ -165,6 +171,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
warn!("sys_getuid is unimplemented");
Ok(0)
}
104 => {
warn!("sys_getgid is unimplemented");
Ok(0)
}
105 => {
warn!("sys_setuid is unimplemented");
Ok(0)
@ -210,13 +220,13 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
Ok(0)
}
_ => {
error!("unknown syscall id: {:#x?}, args: {:x?}", id, args);
error!("unknown syscall id: {}->{}, args: {:x?}", id, x86_64_id, args);
crate::trap::error(tf);
}
};
if !pid.is_init() {
// we trust pid 0 process
debug!("{}:{}:{} syscall id {} ret with {:x?}", cid, pid, tid, id, ret);
debug!("{}:{}:{} syscall id {}->{} ret with {:x?}", cid, pid, tid, id, x86_64_id, ret);
}
match ret {
Ok(code) => code as isize,

@ -18,6 +18,10 @@ pub fn sys_fork(tf: &TrapFrame) -> SysResult {
pub fn sys_clone(flags: usize, newsp: usize, parent_tid: *mut u32, child_tid: *mut u32, newtls: usize, tf: &TrapFrame) -> SysResult {
info!("clone: flags: {:#x}, newsp: {:#x}, parent_tid: {:?}, child_tid: {:?}, newtls: {:#x}",
flags, newsp, parent_tid, child_tid, newtls);
if flags == 0x4111 {
warn!("sys_clone is calling sys_fork instead, ignoring other args");
return sys_fork(tf);
}
if flags != 0x7d0f00 {
warn!("sys_clone only support musl pthread_create");
return Err(SysError::ENOSYS);

@ -1 +1 @@
Subproject commit 0029070acbbdb1c51f9ed5defda082a56c3a685b
Subproject commit 06084d9925a9f8e4234fefeabcbffc96cedf1e90
Loading…
Cancel
Save