Skip to content

Commit cc8fa1b

Browse files
feat: basic support for x86_64
Co-authored-by: eternalcomet <mydragonos@outlook.com>
1 parent 066ebdb commit cc8fa1b

File tree

7 files changed

+24
-41
lines changed

7 files changed

+24
-41
lines changed

Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ optional = true
142142

143143
[patch.crates-io]
144144
axbacktrace = { git = "https://github.com/Starry-OS/axbacktrace.git", rev = "09c22b6" }
145-
axcpu = { git = "https://github.com/Starry-OS/axcpu.git", rev = "53455db" }
145+
axcpu = { git = "https://github.com/Starry-OS/axcpu.git", rev = "3349bfd" }
146146
axerrno = { git = "https://github.com/Starry-OS/axerrno.git", rev = "58be232" }
147147
axfs-ng-vfs = { git = "https://github.com/Starry-OS/axfs-ng-vfs.git", rev = "6cf8893" }
148148
axio = { git = "https://github.com/Starry-OS/axio.git", rev = "ebb0c6b" }
149149
axplat = { git = "https://github.com/Starry-OS/axplat_crates.git", rev = "243fdc9" }
150+
axplat-x86-pc = { git = "https://github.com/Starry-OS/axplat_crates.git", rev = "243fdc9" }
150151
axplat-aarch64-qemu-virt = { git = "https://github.com/Starry-OS/axplat_crates.git", rev = "243fdc9" }
151152
axplat-riscv64-qemu-virt = { git = "https://github.com/Starry-OS/axplat_crates.git", rev = "243fdc9" }
152153
axplat-loongarch64-qemu-virt = { git = "https://github.com/Starry-OS/axplat_crates.git", rev = "243fdc9" }

api/src/syscall/fs/ctl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ pub fn sys_readlinkat(
323323
}
324324

325325
#[cfg(target_arch = "x86_64")]
326-
pub fn sys_chown(path: *const c_char, uid: u32, gid: u32) -> AxResult<isize> {
326+
pub fn sys_chown(path: *const c_char, uid: i32, gid: i32) -> AxResult<isize> {
327327
sys_fchownat(AT_FDCWD, path, uid, gid, 0)
328328
}
329329

330330
#[cfg(target_arch = "x86_64")]
331-
pub fn sys_lchown(path: *const c_char, uid: u32, gid: u32) -> AxResult<isize> {
331+
pub fn sys_lchown(path: *const c_char, uid: i32, gid: i32) -> AxResult<isize> {
332332
use linux_raw_sys::general::AT_SYMLINK_NOFOLLOW;
333333
sys_fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW)
334334
}

api/src/syscall/fs/stat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ pub fn sys_fstat(fd: i32, statbuf: *mut stat) -> AxResult<isize> {
3434
///
3535
/// Return 0 if success.
3636
#[cfg(target_arch = "x86_64")]
37-
pub fn sys_lstat(path: *const c_char, statbuf: UserPtr<stat>) -> AxResult<isize> {
38-
use linux_raw_sys::general::{AT_FDCWD, AT_SYMLINK_FOLLOW};
37+
pub fn sys_lstat(path: *const c_char, statbuf: *mut stat) -> AxResult<isize> {
38+
use linux_raw_sys::general::{AT_FDCWD, AT_SYMLINK_NOFOLLOW};
3939

40-
sys_fstatat(AT_FDCWD, path, statbuf, AT_SYMLINK_FOLLOW)
40+
sys_fstatat(AT_FDCWD, path, statbuf, AT_SYMLINK_NOFOLLOW)
4141
}
4242

4343
pub fn sys_fstatat(

api/src/syscall/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub fn handle_syscall(uctx: &mut UserContext) {
7575
Sysno::syncfs => sys_syncfs(uctx.arg0() as _),
7676

7777
// file ops
78+
#[cfg(target_arch = "x86_64")]
79+
Sysno::chown => sys_chown(uctx.arg0() as _, uctx.arg1() as _, uctx.arg2() as _),
80+
#[cfg(target_arch = "x86_64")]
81+
Sysno::lchown => sys_lchown(uctx.arg0() as _, uctx.arg1() as _, uctx.arg2() as _),
7882
Sysno::fchown => sys_fchown(uctx.arg0() as _, uctx.arg1() as _, uctx.arg2() as _),
7983
Sysno::fchownat => sys_fchownat(
8084
uctx.arg0() as _,
@@ -427,7 +431,7 @@ pub fn handle_syscall(uctx: &mut UserContext) {
427431
Sysno::fork => sys_fork(uctx),
428432
Sysno::exit => sys_exit(uctx.arg0() as _),
429433
Sysno::exit_group => sys_exit_group(uctx.arg0() as _),
430-
Sysno::wait4 => sys_waitpid(uctx, uctx.arg0() as _, uctx.arg1() as _, uctx.arg2() as _),
434+
Sysno::wait4 => sys_waitpid(uctx.arg0() as _, uctx.arg1() as _, uctx.arg2() as _),
431435
Sysno::getsid => sys_getsid(uctx.arg0() as _),
432436
Sysno::setsid => sys_setsid(),
433437
Sysno::getpgid => sys_getpgid(uctx.arg0() as _),

api/src/syscall/task/thread.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,35 @@ pub fn sys_set_tid_address(clear_child_tid: usize) -> AxResult<isize> {
5454

5555
#[cfg(target_arch = "x86_64")]
5656
pub fn sys_arch_prctl(
57-
tf: &mut axhal::context::TrapFrame,
57+
uctx: &mut axhal::uspace::UserContext,
5858
code: i32,
5959
addr: usize,
6060
) -> AxResult<isize> {
6161
use starry_vm::VmMutPtr;
6262

63-
let code = ArchPrctlCode::try_from(code).map_err(|_| axerrno::AxError::EINVAL)?;
63+
let code = ArchPrctlCode::try_from(code).map_err(|_| AxError::InvalidInput)?;
6464
debug!("sys_arch_prctl: code = {:?}, addr = {:#x}", code, addr);
6565

6666
match code {
6767
// According to Linux implementation, SetFs & SetGs does not return
6868
// error at all
6969
ArchPrctlCode::GetFs => {
70-
(addr as *mut usize).vm_write(tf.tls())?;
70+
(addr as *mut usize).vm_write(uctx.tls())?;
7171
Ok(0)
7272
}
7373
ArchPrctlCode::SetFs => {
74-
tf.set_tls(addr);
74+
uctx.set_tls(addr);
7575
Ok(0)
7676
}
7777
ArchPrctlCode::GetGs => {
78-
(addr as *mut usize)
79-
.vm_write(unsafe { x86::msr::rdmsr(x86::msr::IA32_KERNEL_GSBASE) })?;
78+
(addr as *mut usize).vm_write(uctx.gs_base as _)?;
8079
Ok(0)
8180
}
8281
ArchPrctlCode::SetGs => {
83-
unsafe {
84-
x86::msr::wrmsr(x86::msr::IA32_KERNEL_GSBASE, addr as _);
85-
}
82+
uctx.gs_base = addr as _;
8683
Ok(0)
8784
}
8885
ArchPrctlCode::GetCpuid => Ok(0),
89-
ArchPrctlCode::SetCpuid => Err(axerrno::AxError::ENODEV),
86+
ArchPrctlCode::SetCpuid => Err(axerrno::AxError::NoSuchDevice),
9087
}
9188
}

api/src/syscall/task/wait.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use alloc::vec::Vec;
22
use core::{future::poll_fn, task::Poll};
33

44
use axerrno::{AxError, AxResult, LinuxError};
5-
use axhal::uspace::UserContext;
65
use axtask::{
76
current,
87
future::{block_on, interruptible},
@@ -15,8 +14,6 @@ use starry_core::task::AsThread;
1514
use starry_process::{Pid, Process};
1615
use starry_vm::{VmMutPtr, VmPtr};
1716

18-
use crate::signal::check_signals;
19-
2017
bitflags! {
2118
#[derive(Debug)]
2219
struct WaitOptions: u32 {
@@ -62,12 +59,7 @@ impl WaitPid {
6259
}
6360
}
6461

65-
pub fn sys_waitpid(
66-
uctx: &mut UserContext,
67-
pid: i32,
68-
exit_code: *mut i32,
69-
options: u32,
70-
) -> AxResult<isize> {
62+
pub fn sys_waitpid(pid: i32, exit_code: *mut i32, options: u32) -> AxResult<isize> {
7163
let options = WaitOptions::from_bits_truncate(options);
7264
info!("sys_waitpid <= pid: {:?}, options: {:?}", pid, options);
7365

@@ -112,23 +104,13 @@ pub fn sys_waitpid(
112104
}
113105
};
114106

115-
let result = block_on(interruptible(poll_fn(|cx| {
107+
block_on(interruptible(poll_fn(|cx| {
116108
match check_children().transpose() {
117109
Some(res) => Poll::Ready(res),
118110
None => {
119111
proc_data.child_exit_event.register(cx.waker());
120112
Poll::Pending
121113
}
122114
}
123-
})));
124-
match result {
125-
Ok(r) => r,
126-
Err(_) => {
127-
// FIXME: more general syscall RESTART
128-
let ip = uctx.ip() - 4;
129-
uctx.set_ip(ip);
130-
while check_signals(curr.as_thread(), uctx, None) {}
131-
Ok(0)
132-
}
133-
}
115+
})))?
134116
}

0 commit comments

Comments
 (0)