From 4c07d614e25ff57fc21cf69a99b4bfda1c392f64 Mon Sep 17 00:00:00 2001 From: yyy Date: Fri, 4 Apr 2025 11:41:04 +0800 Subject: [PATCH 1/3] add sys_lseek, sys_unlink and sys_gettid --- api/src/imp/fs/ctl.rs | 5 +++++ api/src/imp/fs/io.rs | 4 ++++ api/src/imp/task/thread.rs | 5 +++++ apps/oscomp/judge_libctest.py | 10 +++++++++- core/src/task.rs | 12 +++++++----- scripts/oscomp_test.sh | 11 ++++++++--- src/syscall.rs | 8 ++++++++ 7 files changed, 46 insertions(+), 9 deletions(-) diff --git a/api/src/imp/fs/ctl.rs b/api/src/imp/fs/ctl.rs index 37dce1f3f..f81689c39 100644 --- a/api/src/imp/fs/ctl.rs +++ b/api/src/imp/fs/ctl.rs @@ -256,6 +256,11 @@ pub fn sys_linkat( .map_err(|err| err.into()) } +#[cfg(target_arch = "x86_64")] +pub fn sys_unlink(path: UserConstPtr) -> LinuxResult { + sys_unlinkat(AT_FDCWD, path, 0) +} + /// remove link of specific file (can be used to delete file) /// dir_fd: the directory of link to be removed /// path: the name of link to be removed diff --git a/api/src/imp/fs/io.rs b/api/src/imp/fs/io.rs index 8be57b4b9..68e18b171 100644 --- a/api/src/imp/fs/io.rs +++ b/api/src/imp/fs/io.rs @@ -34,6 +34,10 @@ pub fn sys_openat( Ok(api::sys_openat(dirfd, path.as_ptr(), flags, modes) as _) } +pub fn sys_lseek(fd: i32, offset: i32, whence: i32) -> LinuxResult { + Ok(api::sys_lseek(fd, offset.into(), whence) as _) +} + pub fn sys_open(path: UserConstPtr, flags: i32, modes: mode_t) -> LinuxResult { use arceos_posix_api::AT_FDCWD; sys_openat(AT_FDCWD as _, path, flags, modes) diff --git a/api/src/imp/task/thread.rs b/api/src/imp/task/thread.rs index 990e07f14..01c2b18d7 100644 --- a/api/src/imp/task/thread.rs +++ b/api/src/imp/task/thread.rs @@ -46,6 +46,11 @@ pub fn sys_getppid() -> LinuxResult { Ok(axtask::current().task_ext().get_parent() as _) } +#[apply(syscall_instrument)] +pub fn sys_gettid() -> LinuxResult { + Ok(current().id().as_u64() as _) +} + pub fn sys_exit(status: i32) -> ! { let curr = current(); let clear_child_tid = curr.task_ext().clear_child_tid() as *mut i32; diff --git a/apps/oscomp/judge_libctest.py b/apps/oscomp/judge_libctest.py index fcc36d7fd..35a8dfe32 100644 --- a/apps/oscomp/judge_libctest.py +++ b/apps/oscomp/judge_libctest.py @@ -2,12 +2,20 @@ import sys # TODO: Add more commands to test here -libctest_baseline = """""" +libctest_baseline = """ +========== START entry-static.exe argv ========== +Pass! +========== END entry-static.exe argv ========== +========== START entry-static.exe fdopen ========== +Pass! +========== END entry-static.exe fdopen ========== +""" def parse_libctest(output): ans = {} key = "" for line in output.split("\n"): + line = line.replace('\n', '').replace('\r', '') if "START entry-static.exe" in line: key = "libctest static " + line.split(" ")[3] elif "START entry-dynamic.exe" in line: diff --git a/core/src/task.rs b/core/src/task.rs index ce71f5592..e5ba846d3 100644 --- a/core/src/task.rs +++ b/core/src/task.rs @@ -93,8 +93,8 @@ impl TaskExt { let kstack_top = curr.kernel_stack_top().unwrap(); info!( "Enter user space: entry={:#x}, ustack={:#x}, kstack={:#x}", - curr.task_ext().uctx.get_ip(), - curr.task_ext().uctx.get_sp(), + curr.task_ext().uctx.ip(), + curr.task_ext().uctx.sp(), kstack_top, ); unsafe { curr.task_ext().uctx.enter_uspace(kstack_top) }; @@ -110,7 +110,9 @@ impl TaskExt { new_task .ctx_mut() .set_page_table_root(new_aspace.page_table_root()); - + new_task + .ctx_mut() + .set_tls(axhal::arch::read_thread_pointer().into()); let trap_frame = read_trapframe_from_kstack(current_task.get_kernel_stack_top().unwrap()); let mut new_uctx = UspaceContext::from(&trap_frame); if let Some(stack) = stack { @@ -248,8 +250,8 @@ pub fn spawn_user_task( let kstack_top = curr.kernel_stack_top().unwrap(); info!( "Enter user space: entry={:#x}, ustack={:#x}, kstack={:#x}", - curr.task_ext().uctx.get_ip(), - curr.task_ext().uctx.get_sp(), + curr.task_ext().uctx.ip(), + curr.task_ext().uctx.sp(), kstack_top, ); unsafe { curr.task_ext().uctx.enter_uspace(kstack_top) }; diff --git a/scripts/oscomp_test.sh b/scripts/oscomp_test.sh index 2e810dda4..6314ad7ac 100755 --- a/scripts/oscomp_test.sh +++ b/scripts/oscomp_test.sh @@ -1,6 +1,6 @@ #!/bin/bash -TIMEOUT=60s +TIMEOUT=600s EXIT_STATUS=0 ROOT=$(realpath $(dirname $0))/../ AX_ROOT=$ROOT/.arceos @@ -25,7 +25,9 @@ if [ "$ARCH" != "x86_64" ] && [ "$ARCH" != "riscv64" ] && [ "$ARCH" != "aarch64" fi LIBC=musl - +if [ -z "$LIBC" ]; then + LIBC=musl +fi if [ "$LIBC" != "musl" ] && [ "$LIBC" != "glibc" ]; then echo "Unknown libc: $LIBC" exit $S_FAILED @@ -68,7 +70,10 @@ basic_testlist=( busybox_testlist=("/$LIBC/busybox sh /$LIBC/busybox_testcode.sh") iozone_testlist=("/$LIBC/busybox sh /$LIBC/iozone_testcode.sh") lua_testlist=("/$LIBC/busybox sh /$LIBC/lua_testcode.sh") -libctest_testlist=("/$LIBC/busybox sh /$LIBC/libctest_testcode.sh") +libctest_testlist=( + "/$LIBC/runtest.exe -w entry-static.exe argv" + "/$LIBC/runtest.exe -w entry-static.exe fdopen" +) testcases_type=( "basic" diff --git a/src/syscall.rs b/src/syscall.rs index 1a946a8f2..1b674538b 100644 --- a/src/syscall.rs +++ b/src/syscall.rs @@ -24,6 +24,8 @@ fn handle_syscall(tf: &TrapFrame, syscall_num: usize) -> isize { ), Sysno::ioctl => sys_ioctl(tf.arg0() as _, tf.arg1() as _, tf.arg2().into()), Sysno::writev => sys_writev(tf.arg0() as _, tf.arg1().into(), tf.arg2() as _), + Sysno::prlimit64 => Ok(0), + Sysno::rt_sigtimedwait => Ok(0), Sysno::sched_yield => sys_sched_yield(), Sysno::nanosleep => sys_nanosleep(tf.arg0().into(), tf.arg1().into()), Sysno::getpid => sys_getpid(), @@ -34,6 +36,8 @@ fn handle_syscall(tf: &TrapFrame, syscall_num: usize) -> isize { Sysno::dup => sys_dup(tf.arg0() as _), Sysno::dup3 => sys_dup3(tf.arg0() as _, tf.arg1() as _), Sysno::fcntl => sys_fcntl(tf.arg0() as _, tf.arg1() as _, tf.arg2() as _), + #[cfg(target_arch = "x86_64")] + Sysno::fork => sys_clone(17 /* SIGCHLD */, 0, 0, 0, 0), Sysno::clone => sys_clone( tf.arg0() as _, tf.arg1() as _, @@ -53,6 +57,7 @@ fn handle_syscall(tf: &TrapFrame, syscall_num: usize) -> isize { tf.arg2() as _, tf.arg3() as _, ), + Sysno::lseek => sys_lseek(tf.arg0() as _, tf.arg1() as _, tf.arg2() as _), #[cfg(target_arch = "x86_64")] Sysno::open => sys_open(tf.arg0().into(), tf.arg1() as _, tf.arg2() as _), Sysno::getdents64 => sys_getdents64(tf.arg0() as _, tf.arg1().into(), tf.arg2() as _), @@ -63,6 +68,8 @@ fn handle_syscall(tf: &TrapFrame, syscall_num: usize) -> isize { tf.arg3().into(), tf.arg4() as _, ), + #[cfg(target_arch = "x86_64")] + Sysno::unlink => sys_unlink(tf.arg0().into()), Sysno::unlinkat => sys_unlinkat(tf.arg0() as _, tf.arg1().into(), tf.arg2() as _), Sysno::uname => sys_uname(tf.arg0().into()), Sysno::fstat => sys_fstat(tf.arg0() as _, tf.arg1().into()), @@ -105,6 +112,7 @@ fn handle_syscall(tf: &TrapFrame, syscall_num: usize) -> isize { Sysno::clock_gettime => sys_clock_gettime(tf.arg0() as _, tf.arg1().into()), Sysno::exit_group => sys_exit_group(tf.arg0() as _), Sysno::getuid => sys_getuid(), + Sysno::gettid => sys_gettid(), Sysno::rt_sigprocmask => sys_rt_sigprocmask( tf.arg0() as _, tf.arg1().into(), From 542f631ccc726c209db504df4242dbe12f8de755 Mon Sep 17 00:00:00 2001 From: yyy Date: Fri, 4 Apr 2025 11:44:25 +0800 Subject: [PATCH 2/3] fix clippy --- core/src/task.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/task.rs b/core/src/task.rs index e5ba846d3..15b8f8284 100644 --- a/core/src/task.rs +++ b/core/src/task.rs @@ -120,7 +120,10 @@ impl TaskExt { } // Skip current instruction #[cfg(any(target_arch = "riscv64", target_arch = "loongarch64"))] - new_uctx.set_ip(new_uctx.get_ip() + 4); + { + let new_ip = new_uctx.ip() + 4; + new_uctx.set_ip(new_ip); + } new_uctx.set_retval(0); let return_id: u64 = new_task.id().as_u64(); let new_task_ext = TaskExt::new( From d3d1ea6377ed4f90e28b0441d6dcad70fc7075b3 Mon Sep 17 00:00:00 2001 From: yyy Date: Tue, 8 Apr 2025 14:47:09 +0800 Subject: [PATCH 3/3] fix lseek for lseek_large --- api/src/imp/fs/io.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/imp/fs/io.rs b/api/src/imp/fs/io.rs index 68e18b171..05d59ea4a 100644 --- a/api/src/imp/fs/io.rs +++ b/api/src/imp/fs/io.rs @@ -34,8 +34,8 @@ pub fn sys_openat( Ok(api::sys_openat(dirfd, path.as_ptr(), flags, modes) as _) } -pub fn sys_lseek(fd: i32, offset: i32, whence: i32) -> LinuxResult { - Ok(api::sys_lseek(fd, offset.into(), whence) as _) +pub fn sys_lseek(fd: i32, offset: isize, whence: i32) -> LinuxResult { + Ok(api::sys_lseek(fd, offset as _, whence) as _) } pub fn sys_open(path: UserConstPtr, flags: i32, modes: mode_t) -> LinuxResult {