Skip to content

Commit 53156c9

Browse files
committed
feat: add lseek and ioctl syscall
1 parent cfc5f30 commit 53156c9

File tree

9 files changed

+407
-16
lines changed

9 files changed

+407
-16
lines changed

api/src/imp/fs/ctl.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::ffi::{c_char, c_void};
22

33
use alloc::string::ToString;
4-
use arceos_posix_api::AT_FDCWD;
4+
use arceos_posix_api::{AT_FDCWD, FD_TABLE};
55
use axerrno::{AxError, LinuxError, LinuxResult};
66
use macro_rules_attribute::apply;
77

@@ -10,6 +10,18 @@ use crate::{
1010
syscall_instrument,
1111
};
1212

13+
#[allow(missing_docs)]
14+
pub const TIOCGWINSZ: usize = 0x5413;
15+
16+
#[repr(C)]
17+
#[derive(Clone, Copy, Default)]
18+
pub struct ConsoleWinSize {
19+
ws_row: u16,
20+
ws_col: u16,
21+
ws_xpixel: u16,
22+
ws_ypixel: u16,
23+
}
24+
1325
/// The ioctl() system call manipulates the underlying device parameters
1426
/// of special files.
1527
///
@@ -19,9 +31,26 @@ use crate::{
1931
/// and of type int in musl and other UNIX systems.
2032
/// * `argp` - The argument to the request. It is a pointer to a memory location
2133
#[apply(syscall_instrument)]
22-
pub fn sys_ioctl(_fd: i32, _op: usize, _argp: UserPtr<c_void>) -> LinuxResult<isize> {
23-
warn!("Unimplemented syscall: SYS_IOCTL");
24-
Ok(0)
34+
pub fn sys_ioctl(fd: i32, op: usize, argp: UserPtr<c_void>) -> LinuxResult<isize> {
35+
if fd >= FD_TABLE.read().count() as i32 {
36+
debug!("fd {} is out of range", fd);
37+
return Err(LinuxError::EBADF);
38+
}
39+
if FD_TABLE.read().get(fd as usize).is_none() {
40+
debug!("fd {} is none", fd);
41+
return Err(LinuxError::EBADF);
42+
}
43+
let argp = argp.get_as_bytes(size_of::<ConsoleWinSize>())?;
44+
match op {
45+
TIOCGWINSZ => {
46+
let winsize = argp as *mut ConsoleWinSize;
47+
unsafe {
48+
*winsize = ConsoleWinSize::default();
49+
}
50+
Ok(0)
51+
}
52+
_ => Err(LinuxError::EOPNOTSUPP),
53+
}
2554
}
2655

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

288+
pub fn sys_unlink(_path: UserConstPtr<c_char>) -> LinuxResult<isize> {
289+
warn!("sys_unlink: not implemented");
290+
Ok(0)
291+
}
292+
259293
/// remove link of specific file (can be used to delete file)
260294
/// dir_fd: the directory of link to be removed
261295
/// path: the name of link to be removed

api/src/imp/fs/io.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use axerrno::LinuxResult;
55

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

8+
pub fn sys_lseek(fd: i32, offset: isize, whence: i32) -> LinuxResult<isize> {
9+
Ok(api::sys_lseek(fd, offset as _, whence) as _)
10+
}
11+
812
pub fn sys_read(fd: i32, buf: UserPtr<c_void>, count: usize) -> LinuxResult<isize> {
913
let buf = buf.get_as_bytes(count)?;
1014
Ok(api::sys_read(fd, buf, count))
@@ -38,3 +42,22 @@ pub fn sys_open(path: UserConstPtr<c_char>, flags: i32, modes: mode_t) -> LinuxR
3842
use arceos_posix_api::AT_FDCWD;
3943
sys_openat(AT_FDCWD as _, path, flags, modes)
4044
}
45+
46+
pub fn sys_readlink(
47+
_pathname: UserConstPtr<c_char>,
48+
_buf: UserPtr<c_char>,
49+
_bufsiz: usize,
50+
) -> LinuxResult<isize> {
51+
warn!("sys_readlink: not implemented");
52+
Ok(0)
53+
}
54+
55+
pub fn sys_readlinkat(
56+
_dirfd: i32,
57+
_pathname: UserConstPtr<c_char>,
58+
_buf: UserPtr<c_char>,
59+
_bufsiz: usize,
60+
) -> LinuxResult<isize> {
61+
warn!("sys_readlinkat: not implemented");
62+
Ok(0)
63+
}

api/src/imp/signal.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ pub fn sys_rt_sigaction(
2323
warn!("sys_rt_sigaction: not implemented");
2424
Ok(0)
2525
}
26+
27+
pub fn sys_rt_sigtimedwait(
28+
_set: UserConstPtr<c_void>,
29+
_info: UserPtr<c_void>,
30+
_timeout: UserConstPtr<c_void>,
31+
) -> LinuxResult<isize> {
32+
warn!("sys_rt_sigtimedwait: not implemented");
33+
Ok(0)
34+
}

api/src/imp/sys.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use core::ffi::c_void;
2+
13
use axerrno::LinuxResult;
24

3-
use crate::ptr::{PtrWrapper, UserPtr};
5+
use crate::ptr::{PtrWrapper, UserConstPtr, UserPtr};
46

57
pub fn sys_getuid() -> LinuxResult<isize> {
68
Ok(0)
@@ -47,3 +49,28 @@ pub fn sys_uname(name: UserPtr<UtsName>) -> LinuxResult<isize> {
4749
unsafe { *name.get()? = UtsName::default() };
4850
Ok(0)
4951
}
52+
53+
pub fn sys_prlimit64(
54+
_pid: i32,
55+
_resource: i32,
56+
_new_limit: UserConstPtr<c_void>,
57+
_old_limit: UserPtr<c_void>,
58+
) -> LinuxResult<isize> {
59+
warn!("sys_prlimit64: not implemented");
60+
Ok(0)
61+
}
62+
63+
pub fn sys_rseq(
64+
_rseq: UserPtr<c_void>,
65+
_rseq_len: u32,
66+
_flags: u32,
67+
_sig: UserPtr<c_void>,
68+
) -> LinuxResult<isize> {
69+
warn!("sys_rseq: not implemented");
70+
Ok(0)
71+
}
72+
73+
pub fn sys_getrandom(_buf: UserPtr<c_void>, _buflen: usize, _flags: u32) -> LinuxResult<isize> {
74+
warn!("sys_getrandom: not implemented");
75+
Ok(0)
76+
}

api/src/imp/task/thread.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use core::{ffi::c_char, ptr};
1+
use core::{
2+
ffi::{c_char, c_void},
3+
ptr,
4+
};
25

36
use alloc::vec::Vec;
47
use axerrno::{LinuxError, LinuxResult};
@@ -210,3 +213,15 @@ pub fn sys_execve(
210213

211214
unreachable!("execve should never return");
212215
}
216+
217+
#[apply(syscall_instrument)]
218+
pub fn sys_gettid() -> LinuxResult<isize> {
219+
warn!("sys_gettid: not implemented");
220+
Ok(axtask::current().task_ext().proc_id as _)
221+
}
222+
223+
#[apply(syscall_instrument)]
224+
pub fn sys_set_robust_list(_head: UserPtr<c_void>, _len: usize) -> LinuxResult<isize> {
225+
warn!("sys_set_robust_list: not implemented");
226+
Ok(0)
227+
}

apps/oscomp/judge_libctest.py

Lines changed: 184 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,195 @@
22
import sys
33

44
# TODO: Add more commands to test here
5-
libctest_baseline = """"""
5+
libctest_baseline = """
6+
========== START entry-static.exe argv ==========
7+
Pass!
8+
========== END entry-static.exe argv ==========
9+
========== START entry-static.exe basename ==========
10+
Pass!
11+
========== END entry-static.exe basename ==========
12+
========== START entry-static.exe dirname ==========
13+
Pass!
14+
========== END entry-static.exe dirname ==========
15+
========== START entry-static.exe env ==========
16+
Pass!
17+
========== END entry-static.exe env ==========
18+
========== START entry-static.exe fdopen ==========
19+
Pass!
20+
========== END entry-static.exe fdopen ==========
21+
========== START entry-static.exe inet_pton ==========
22+
Pass!
23+
========== END entry-static.exe inet_pton ==========
24+
========== START entry-static.exe memstream ==========
25+
Pass!
26+
========== END entry-static.exe memstream ==========
27+
========== START entry-static.exe random ==========
28+
Pass!
29+
========== END entry-static.exe random ==========
30+
========== START entry-static.exe search_hsearch ==========
31+
Pass!
32+
========== END entry-static.exe search_hsearch ==========
33+
========== START entry-static.exe search_insque ==========
34+
Pass!
35+
========== END entry-static.exe search_insque ==========
36+
========== START entry-static.exe search_lsearch ==========
37+
Pass!
38+
========== END entry-static.exe search_lsearch ==========
39+
========== START entry-static.exe search_tsearch ==========
40+
Pass!
41+
========== END entry-static.exe search_tsearch ==========
42+
========== START entry-static.exe snprintf ==========
43+
Pass!
44+
========== END entry-static.exe snprintf ==========
45+
========== START entry-static.exe string ==========
46+
Pass!
47+
========== END entry-static.exe string ==========
48+
========== START entry-static.exe string_memcpy ==========
49+
Pass!
50+
========== END entry-static.exe string_memcpy ==========
51+
========== START entry-static.exe string_memmem ==========
52+
Pass!
53+
========== END entry-static.exe string_memmem ==========
54+
========== START entry-static.exe string_memset ==========
55+
Pass!
56+
========== END entry-static.exe string_memset ==========
57+
========== START entry-static.exe string_strchr ==========
58+
Pass!
59+
========== END entry-static.exe string_strchr ==========
60+
========== START entry-static.exe string_strcspn ==========
61+
Pass!
62+
========== END entry-static.exe string_strcspn ==========
63+
========== START entry-static.exe string_strstr ==========
64+
Pass!
65+
========== END entry-static.exe string_strstr ==========
66+
========== START entry-static.exe strptime ==========
67+
Pass!
68+
========== END entry-static.exe strptime ==========
69+
========== START entry-static.exe strtod ==========
70+
Pass!
71+
========== END entry-static.exe strtod ==========
72+
========== START entry-static.exe strtod_simple ==========
73+
Pass!
74+
========== END entry-static.exe strtod_simple ==========
75+
========== START entry-static.exe strtof ==========
76+
Pass!
77+
========== END entry-static.exe strtof ==========
78+
========== START entry-static.exe strtold ==========
79+
Pass!
80+
========== END entry-static.exe strtold ==========
81+
========== START entry-static.exe tgmath ==========
82+
Pass!
83+
========== END entry-static.exe tgmath ==========
84+
========== START entry-static.exe time ==========
85+
Pass!
86+
========== END entry-static.exe time ==========
87+
========== START entry-static.exe tls_align ==========
88+
Pass!
89+
========== END entry-static.exe tls_align ==========
90+
Pass!
91+
========== START entry-static.exe udiv ==========
92+
Pass!
93+
========== END entry-static.exe udiv ==========
94+
========== START entry-static.exe wcsstr ==========
95+
Pass!
96+
========== END entry-static.exe wcsstr ==========
97+
========== START entry-static.exe fgets_eof ==========
98+
Pass!
99+
========== END entry-static.exe fgets_eof ==========
100+
========== START entry-static.exe inet_ntop_v4mapped ==========
101+
Pass!
102+
========== END entry-static.exe inet_ntop_v4mapped ==========
103+
========== START entry-static.exe inet_pton_empty_last_field ==========
104+
Pass!
105+
========== END entry-static.exe inet_pton_empty_last_field ==========
106+
========== START entry-static.exe iswspace_null ==========
107+
Pass!
108+
========== END entry-static.exe iswspace_null ==========
109+
========== START entry-static.exe lrand48_signextend ==========
110+
Pass!
111+
========== END entry-static.exe lrand48_signextend ==========
112+
========== START entry-static.exe malloc_0 ==========
113+
Pass!
114+
========== END entry-static.exe malloc_0 ==========
115+
========== START entry-static.exe mbsrtowcs_overflow ==========
116+
Pass!
117+
========== END entry-static.exe mbsrtowcs_overflow ==========
118+
========== START entry-static.exe memmem_oob_read ==========
119+
Pass!
120+
========== END entry-static.exe memmem_oob_read ==========
121+
========== START entry-static.exe memmem_oob ==========
122+
Pass!
123+
========== END entry-static.exe memmem_oob ==========
124+
========== START entry-static.exe mkdtemp_failure ==========
125+
Pass!
126+
========== END entry-static.exe mkdtemp_failure ==========
127+
========== START entry-static.exe mkstemp_failure ==========
128+
Pass!
129+
========== END entry-static.exe mkstemp_failure ==========
130+
========== START entry-static.exe printf_1e9_oob ==========
131+
Pass!
132+
========== END entry-static.exe printf_1e9_oob ==========
133+
========== START entry-static.exe printf_fmt_g_round ==========
134+
Pass!
135+
========== END entry-static.exe printf_fmt_g_round ==========
136+
========== START entry-static.exe printf_fmt_g_zeros ==========
137+
Pass!
138+
========== END entry-static.exe printf_fmt_g_zeros ==========
139+
========== START entry-static.exe printf_fmt_n ==========
140+
Pass!
141+
========== END entry-static.exe printf_fmt_n ==========
142+
========== START entry-static.exe putenv_doublefree ==========
143+
Pass!
144+
========== END entry-static.exe putenv_doublefree ==========
145+
========== START entry-static.exe regex_backref_0 ==========
146+
Pass!
147+
========== END entry-static.exe regex_backref_0 ==========
148+
========== START entry-static.exe regex_bracket_icase ==========
149+
Pass!
150+
========== END entry-static.exe regex_bracket_icase ==========
151+
========== START entry-static.exe regex_negated_range ==========
152+
Pass!
153+
========== END entry-static.exe regex_negated_range ==========
154+
========== START entry-static.exe regexec_nosub ==========
155+
Pass!
156+
========== END entry-static.exe regexec_nosub ==========
157+
========== START entry-static.exe scanf_bytes_consumed ==========
158+
Pass!
159+
========== END entry-static.exe scanf_bytes_consumed ==========
160+
========== START entry-static.exe scanf_match_literal_eof ==========
161+
Pass!
162+
========== END entry-static.exe scanf_match_literal_eof ==========
163+
========== START entry-static.exe scanf_nullbyte_char ==========
164+
Pass!
165+
========== END entry-static.exe scanf_nullbyte_char ==========
166+
========== START entry-static.exe sigprocmask_internal ==========
167+
Pass!
168+
========== END entry-static.exe sigprocmask_internal ==========
169+
========== START entry-static.exe sscanf_eof ==========
170+
Pass!
171+
========== END entry-static.exe sscanf_eof ==========
172+
========== START entry-static.exe strverscmp ==========
173+
Pass!
174+
========== END entry-static.exe strverscmp ==========
175+
========== START entry-static.exe syscall_sign_extend ==========
176+
Pass!
177+
========== END entry-static.exe syscall_sign_extend ==========
178+
========== START entry-static.exe uselocale_0 ==========
179+
Pass!
180+
========== END entry-static.exe uselocale_0 ==========
181+
========== START entry-static.exe wcsncpy_read_overflow ==========
182+
Pass!
183+
========== END entry-static.exe wcsncpy_read_overflow ==========
184+
========== START entry-static.exe wcsstr_false_negative ==========
185+
Pass!
186+
========== END entry-static.exe wcsstr_false_negative ==========
187+
"""
6188

7189
def parse_libctest(output):
8190
ans = {}
9191
key = ""
10192
for line in output.split("\n"):
193+
line = line.replace('\n', '').replace('\r', '')
11194
if "START entry-static.exe" in line:
12195
key = "libctest static " + line.split(" ")[3]
13196
elif "START entry-dynamic.exe" in line:

0 commit comments

Comments
 (0)