Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions api/src/imp/fs/ctl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ffi::{c_char, c_void};

use alloc::string::ToString;
use arceos_posix_api::AT_FDCWD;
use arceos_posix_api::{AT_FDCWD, FD_TABLE};
use axerrno::{AxError, LinuxError, LinuxResult};
use macro_rules_attribute::apply;

Expand All @@ -10,6 +10,18 @@ use crate::{
syscall_instrument,
};

#[allow(missing_docs)]
pub const TIOCGWINSZ: usize = 0x5413;

#[repr(C)]
#[derive(Clone, Copy, Default)]
pub struct ConsoleWinSize {
ws_row: u16,
ws_col: u16,
ws_xpixel: u16,
ws_ypixel: u16,
}

/// The ioctl() system call manipulates the underlying device parameters
/// of special files.
///
Expand All @@ -19,9 +31,26 @@ use crate::{
/// and of type int in musl and other UNIX systems.
/// * `argp` - The argument to the request. It is a pointer to a memory location
#[apply(syscall_instrument)]
pub fn sys_ioctl(_fd: i32, _op: usize, _argp: UserPtr<c_void>) -> LinuxResult<isize> {
warn!("Unimplemented syscall: SYS_IOCTL");
Ok(0)
pub fn sys_ioctl(fd: i32, op: usize, argp: UserPtr<c_void>) -> LinuxResult<isize> {
if fd >= FD_TABLE.read().count() as i32 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. Please refer to oscomp/arceos#6.

debug!("fd {} is out of range", fd);
return Err(LinuxError::EBADF);
}
if FD_TABLE.read().get(fd as usize).is_none() {
debug!("fd {} is none", fd);
return Err(LinuxError::EBADF);
}
let argp = argp.get_as_bytes(size_of::<ConsoleWinSize>())?;
match op {
TIOCGWINSZ => {
let winsize = argp as *mut ConsoleWinSize;
unsafe {
*winsize = ConsoleWinSize::default();
}
Ok(0)
}
_ => Err(LinuxError::EOPNOTSUPP),
}
}

pub fn sys_chdir(path: UserConstPtr<c_char>) -> LinuxResult<isize> {
Expand Down Expand Up @@ -256,6 +285,11 @@ pub fn sys_linkat(
.map_err(|err| err.into())
}

pub fn sys_unlink(_path: UserConstPtr<c_char>) -> LinuxResult<isize> {
warn!("sys_unlink: not implemented");
Ok(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
Expand Down
23 changes: 23 additions & 0 deletions api/src/imp/fs/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use axerrno::LinuxResult;

use crate::ptr::{PtrWrapper, UserConstPtr, UserPtr};

pub fn sys_lseek(fd: i32, offset: isize, whence: i32) -> LinuxResult<isize> {
Ok(api::sys_lseek(fd, offset as _, whence) as _)
}

pub fn sys_read(fd: i32, buf: UserPtr<c_void>, count: usize) -> LinuxResult<isize> {
let buf = buf.get_as_bytes(count)?;
Ok(api::sys_read(fd, buf, count))
Expand Down Expand Up @@ -38,3 +42,22 @@ pub fn sys_open(path: UserConstPtr<c_char>, flags: i32, modes: mode_t) -> LinuxR
use arceos_posix_api::AT_FDCWD;
sys_openat(AT_FDCWD as _, path, flags, modes)
}

pub fn sys_readlink(
_pathname: UserConstPtr<c_char>,
_buf: UserPtr<c_char>,
_bufsiz: usize,
) -> LinuxResult<isize> {
warn!("sys_readlink: not implemented");
Ok(0)
}

pub fn sys_readlinkat(
_dirfd: i32,
_pathname: UserConstPtr<c_char>,
_buf: UserPtr<c_char>,
_bufsiz: usize,
) -> LinuxResult<isize> {
warn!("sys_readlinkat: not implemented");
Ok(0)
}
9 changes: 9 additions & 0 deletions api/src/imp/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ pub fn sys_rt_sigaction(
warn!("sys_rt_sigaction: not implemented");
Ok(0)
}

pub fn sys_rt_sigtimedwait(
_set: UserConstPtr<c_void>,
_info: UserPtr<c_void>,
_timeout: UserConstPtr<c_void>,
) -> LinuxResult<isize> {
warn!("sys_rt_sigtimedwait: not implemented");
Ok(0)
}
29 changes: 28 additions & 1 deletion api/src/imp/sys.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::ffi::c_void;

use axerrno::LinuxResult;

use crate::ptr::{PtrWrapper, UserPtr};
use crate::ptr::{PtrWrapper, UserConstPtr, UserPtr};

pub fn sys_getuid() -> LinuxResult<isize> {
Ok(0)
Expand Down Expand Up @@ -47,3 +49,28 @@ pub fn sys_uname(name: UserPtr<UtsName>) -> LinuxResult<isize> {
unsafe { *name.get()? = UtsName::default() };
Ok(0)
}

pub fn sys_prlimit64(
_pid: i32,
_resource: i32,
_new_limit: UserConstPtr<c_void>,
_old_limit: UserPtr<c_void>,
) -> LinuxResult<isize> {
warn!("sys_prlimit64: not implemented");
Ok(0)
}

pub fn sys_rseq(
_rseq: UserPtr<c_void>,
_rseq_len: u32,
_flags: u32,
_sig: UserPtr<c_void>,
) -> LinuxResult<isize> {
warn!("sys_rseq: not implemented");
Ok(0)
}

pub fn sys_getrandom(_buf: UserPtr<c_void>, _buflen: usize, _flags: u32) -> LinuxResult<isize> {
warn!("sys_getrandom: not implemented");
Ok(0)
}
17 changes: 16 additions & 1 deletion api/src/imp/task/thread.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use core::{ffi::c_char, ptr};
use core::{
ffi::{c_char, c_void},
ptr,
};

use alloc::vec::Vec;
use axerrno::{LinuxError, LinuxResult};
Expand Down Expand Up @@ -210,3 +213,15 @@ pub fn sys_execve(

unreachable!("execve should never return");
}

#[apply(syscall_instrument)]
pub fn sys_gettid() -> LinuxResult<isize> {
warn!("sys_gettid: not implemented");
Ok(axtask::current().task_ext().proc_id as _)
}

#[apply(syscall_instrument)]
pub fn sys_set_robust_list(_head: UserPtr<c_void>, _len: usize) -> LinuxResult<isize> {
warn!("sys_set_robust_list: not implemented");
Ok(0)
}
185 changes: 184 additions & 1 deletion apps/oscomp/judge_libctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,195 @@
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 basename ==========
Pass!
========== END entry-static.exe basename ==========
========== START entry-static.exe dirname ==========
Pass!
========== END entry-static.exe dirname ==========
========== START entry-static.exe env ==========
Pass!
========== END entry-static.exe env ==========
========== START entry-static.exe fdopen ==========
Pass!
========== END entry-static.exe fdopen ==========
========== START entry-static.exe inet_pton ==========
Pass!
========== END entry-static.exe inet_pton ==========
========== START entry-static.exe memstream ==========
Pass!
========== END entry-static.exe memstream ==========
========== START entry-static.exe random ==========
Pass!
========== END entry-static.exe random ==========
========== START entry-static.exe search_hsearch ==========
Pass!
========== END entry-static.exe search_hsearch ==========
========== START entry-static.exe search_insque ==========
Pass!
========== END entry-static.exe search_insque ==========
========== START entry-static.exe search_lsearch ==========
Pass!
========== END entry-static.exe search_lsearch ==========
========== START entry-static.exe search_tsearch ==========
Pass!
========== END entry-static.exe search_tsearch ==========
========== START entry-static.exe snprintf ==========
Pass!
========== END entry-static.exe snprintf ==========
========== START entry-static.exe string ==========
Pass!
========== END entry-static.exe string ==========
========== START entry-static.exe string_memcpy ==========
Pass!
========== END entry-static.exe string_memcpy ==========
========== START entry-static.exe string_memmem ==========
Pass!
========== END entry-static.exe string_memmem ==========
========== START entry-static.exe string_memset ==========
Pass!
========== END entry-static.exe string_memset ==========
========== START entry-static.exe string_strchr ==========
Pass!
========== END entry-static.exe string_strchr ==========
========== START entry-static.exe string_strcspn ==========
Pass!
========== END entry-static.exe string_strcspn ==========
========== START entry-static.exe string_strstr ==========
Pass!
========== END entry-static.exe string_strstr ==========
========== START entry-static.exe strptime ==========
Pass!
========== END entry-static.exe strptime ==========
========== START entry-static.exe strtod ==========
Pass!
========== END entry-static.exe strtod ==========
========== START entry-static.exe strtod_simple ==========
Pass!
========== END entry-static.exe strtod_simple ==========
========== START entry-static.exe strtof ==========
Pass!
========== END entry-static.exe strtof ==========
========== START entry-static.exe strtold ==========
Pass!
========== END entry-static.exe strtold ==========
========== START entry-static.exe tgmath ==========
Pass!
========== END entry-static.exe tgmath ==========
========== START entry-static.exe time ==========
Pass!
========== END entry-static.exe time ==========
========== START entry-static.exe tls_align ==========
Pass!
========== END entry-static.exe tls_align ==========
Pass!
========== START entry-static.exe udiv ==========
Pass!
========== END entry-static.exe udiv ==========
========== START entry-static.exe wcsstr ==========
Pass!
========== END entry-static.exe wcsstr ==========
========== START entry-static.exe fgets_eof ==========
Pass!
========== END entry-static.exe fgets_eof ==========
========== START entry-static.exe inet_ntop_v4mapped ==========
Pass!
========== END entry-static.exe inet_ntop_v4mapped ==========
========== START entry-static.exe inet_pton_empty_last_field ==========
Pass!
========== END entry-static.exe inet_pton_empty_last_field ==========
========== START entry-static.exe iswspace_null ==========
Pass!
========== END entry-static.exe iswspace_null ==========
========== START entry-static.exe lrand48_signextend ==========
Pass!
========== END entry-static.exe lrand48_signextend ==========
========== START entry-static.exe malloc_0 ==========
Pass!
========== END entry-static.exe malloc_0 ==========
========== START entry-static.exe mbsrtowcs_overflow ==========
Pass!
========== END entry-static.exe mbsrtowcs_overflow ==========
========== START entry-static.exe memmem_oob_read ==========
Pass!
========== END entry-static.exe memmem_oob_read ==========
========== START entry-static.exe memmem_oob ==========
Pass!
========== END entry-static.exe memmem_oob ==========
========== START entry-static.exe mkdtemp_failure ==========
Pass!
========== END entry-static.exe mkdtemp_failure ==========
========== START entry-static.exe mkstemp_failure ==========
Pass!
========== END entry-static.exe mkstemp_failure ==========
========== START entry-static.exe printf_1e9_oob ==========
Pass!
========== END entry-static.exe printf_1e9_oob ==========
========== START entry-static.exe printf_fmt_g_round ==========
Pass!
========== END entry-static.exe printf_fmt_g_round ==========
========== START entry-static.exe printf_fmt_g_zeros ==========
Pass!
========== END entry-static.exe printf_fmt_g_zeros ==========
========== START entry-static.exe printf_fmt_n ==========
Pass!
========== END entry-static.exe printf_fmt_n ==========
========== START entry-static.exe putenv_doublefree ==========
Pass!
========== END entry-static.exe putenv_doublefree ==========
========== START entry-static.exe regex_backref_0 ==========
Pass!
========== END entry-static.exe regex_backref_0 ==========
========== START entry-static.exe regex_bracket_icase ==========
Pass!
========== END entry-static.exe regex_bracket_icase ==========
========== START entry-static.exe regex_negated_range ==========
Pass!
========== END entry-static.exe regex_negated_range ==========
========== START entry-static.exe regexec_nosub ==========
Pass!
========== END entry-static.exe regexec_nosub ==========
========== START entry-static.exe scanf_bytes_consumed ==========
Pass!
========== END entry-static.exe scanf_bytes_consumed ==========
========== START entry-static.exe scanf_match_literal_eof ==========
Pass!
========== END entry-static.exe scanf_match_literal_eof ==========
========== START entry-static.exe scanf_nullbyte_char ==========
Pass!
========== END entry-static.exe scanf_nullbyte_char ==========
========== START entry-static.exe sigprocmask_internal ==========
Pass!
========== END entry-static.exe sigprocmask_internal ==========
========== START entry-static.exe sscanf_eof ==========
Pass!
========== END entry-static.exe sscanf_eof ==========
========== START entry-static.exe strverscmp ==========
Pass!
========== END entry-static.exe strverscmp ==========
========== START entry-static.exe syscall_sign_extend ==========
Pass!
========== END entry-static.exe syscall_sign_extend ==========
========== START entry-static.exe uselocale_0 ==========
Pass!
========== END entry-static.exe uselocale_0 ==========
========== START entry-static.exe wcsncpy_read_overflow ==========
Pass!
========== END entry-static.exe wcsncpy_read_overflow ==========
========== START entry-static.exe wcsstr_false_negative ==========
Pass!
========== END entry-static.exe wcsstr_false_negative ==========
"""

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:
Expand Down
Loading