Skip to content

Commit dd10c95

Browse files
arch_prctl: move arch_prctl to arch/syscall.rs
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent db12578 commit dd10c95

File tree

3 files changed

+76
-53
lines changed

3 files changed

+76
-53
lines changed

src/aero_kernel/src/arch/x86_64/syscall.rs

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use aero_syscall::AeroSyscallError;
12
use raw_cpuid::CpuId;
23

34
use crate::arch::gdt::GdtEntryType;
5+
use crate::mem::paging::VirtAddr;
6+
use crate::userland::scheduler;
47
use crate::utils::io;
58

69
use super::interrupts::InterruptStack;
@@ -9,30 +12,78 @@ extern "C" {
912
fn x86_64_syscall_handler();
1013
}
1114

15+
const ARCH_SET_GS: usize = 0x1001;
16+
const ARCH_SET_FS: usize = 0x1002;
17+
const ARCH_GET_FS: usize = 0x1003;
18+
const ARCH_GET_GS: usize = 0x1004;
19+
20+
fn arch_prctl(command: usize, address: usize) -> Result<usize, AeroSyscallError> {
21+
match command {
22+
ARCH_SET_FS => unsafe {
23+
scheduler::get_scheduler()
24+
.current_task()
25+
.arch_task_mut()
26+
.set_fs_base(VirtAddr::new(address as u64));
27+
28+
Ok(0x00)
29+
},
30+
31+
ARCH_GET_FS => Ok(scheduler::get_scheduler()
32+
.current_task()
33+
.arch_task()
34+
.get_fs_base()
35+
.as_u64() as usize),
36+
37+
ARCH_SET_GS => unsafe {
38+
scheduler::get_scheduler()
39+
.current_task()
40+
.arch_task_mut()
41+
.set_gs_base(VirtAddr::new(address as u64));
42+
43+
Ok(0x00)
44+
},
45+
46+
ARCH_GET_GS => Ok(scheduler::get_scheduler()
47+
.current_task()
48+
.arch_task()
49+
.get_gs_base()
50+
.as_u64() as usize),
51+
52+
_ => Err(AeroSyscallError::EINVAL),
53+
}
54+
}
55+
1256
#[no_mangle]
1357
extern "C" fn x86_64_do_syscall(stack: &mut InterruptStack) {
14-
let syscall_number = stack.scratch.rax as usize;
58+
let syscall_number = stack.scratch.rax as usize; // syscall number
59+
let a = stack.scratch.rdi as usize; // argument 1
60+
let b = stack.scratch.rsi as usize; // argument 2
61+
let c = stack.scratch.rdx as usize; // argument 3
62+
let d = stack.scratch.r10 as usize; // argument 4
63+
let e = stack.scratch.r8 as usize; // argument 5
64+
let f = stack.scratch.r9 as usize; // argument 6
1565

1666
match syscall_number {
17-
aero_syscall::prelude::SYS_EXIT => {}
67+
// handle arch-specific syscalls (`sigreturn` and `arch_prctl`):
1868
aero_syscall::prelude::SYS_SIGRETURN => {
1969
let result = super::signals::sigreturn(stack);
2070
stack.scratch.rax = result as u64;
2171
return;
2272
}
2373

74+
aero_syscall::prelude::SYS_ARCH_PRCTL => {
75+
let result = self::arch_prctl(a, b);
76+
let result_usize = aero_syscall::syscall_result_as_usize(result);
77+
78+
stack.scratch.rax = result_usize as _;
79+
return;
80+
}
81+
82+
aero_syscall::prelude::SYS_EXIT => {}
2483
_ => unsafe { super::interrupts::enable_interrupts() },
2584
}
2685

27-
let result_usize = crate::syscall::generic_do_syscall(
28-
syscall_number,
29-
stack.scratch.rdi as usize, // argument 1
30-
stack.scratch.rsi as usize, // argument 2
31-
stack.scratch.rdx as usize, // argument 3
32-
stack.scratch.r10 as usize, // argument 4
33-
stack.scratch.r8 as usize, // argument 5
34-
stack.scratch.r9 as usize, // argument 6
35-
);
86+
let result_usize = crate::syscall::generic_do_syscall(syscall_number, a, b, c, d, e, f);
3687

3788
super::signals::syscall_check_signals(result_usize as isize, stack);
3889
stack.scratch.rax = result_usize as _;

src/aero_kernel/src/syscall/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@
5656
//! | 32 | access |
5757
//! | 33 | pipe |
5858
//! | 34 | unlink |
59+
//! | 35 | gethostname |
60+
//! | 36 | sethostname |
61+
//! | 37 | info |
62+
//! | 38 | clone |
63+
//! | 39 | sigreturn |
64+
//! | 40 | sigaction |
65+
//! | 41 | sigprocmask |
66+
//! | 42 | dup |
67+
//! | 43 | fcntl |
68+
//! | 44 | dup2 |
69+
//! | 45 | ipc_send |
70+
//! | 46 | ipc_recv |
71+
//! | 47 | ipc_discover_root |
72+
//! | 48 | ipc_become_root |
5973
6074
use core::mem::MaybeUninit;
6175

@@ -139,7 +153,6 @@ pub fn generic_do_syscall(
139153
SYS_SHUTDOWN => process::shutdown(),
140154
SYS_FORK => process::fork(),
141155
SYS_MMAP => process::mmap(b, c, d, e, f, g),
142-
SYS_ARCH_PRCTL => process::arch_prctl(b, c),
143156
SYS_MUNMAP => process::munmap(b, c),
144157
SYS_EXEC => process::exec(b, c, d, e, f, g),
145158
SYS_LOG => process::log(b, c),

src/aero_kernel/src/syscall/process.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,47 +52,6 @@ pub fn exit(status: usize) -> ! {
5252
}
5353
}
5454

55-
const ARCH_SET_GS: usize = 0x1001;
56-
const ARCH_SET_FS: usize = 0x1002;
57-
const ARCH_GET_FS: usize = 0x1003;
58-
const ARCH_GET_GS: usize = 0x1004;
59-
60-
pub fn arch_prctl(command: usize, address: usize) -> Result<usize, AeroSyscallError> {
61-
match command {
62-
ARCH_SET_FS => unsafe {
63-
scheduler::get_scheduler()
64-
.current_task()
65-
.arch_task_mut()
66-
.set_fs_base(VirtAddr::new(address as u64));
67-
68-
Ok(0x00)
69-
},
70-
71-
ARCH_GET_FS => Ok(scheduler::get_scheduler()
72-
.current_task()
73-
.arch_task()
74-
.get_fs_base()
75-
.as_u64() as usize),
76-
77-
ARCH_SET_GS => unsafe {
78-
scheduler::get_scheduler()
79-
.current_task()
80-
.arch_task_mut()
81-
.set_gs_base(VirtAddr::new(address as u64));
82-
83-
Ok(0x00)
84-
},
85-
86-
ARCH_GET_GS => Ok(scheduler::get_scheduler()
87-
.current_task()
88-
.arch_task()
89-
.get_gs_base()
90-
.as_u64() as usize),
91-
92-
_ => Err(AeroSyscallError::EINVAL),
93-
}
94-
}
95-
9655
pub fn uname(buffer: usize) -> Result<usize, AeroSyscallError> {
9756
fn init_array(fixed: &mut [u8; 65], init: &'static str) {
9857
let init_bytes = init.as_bytes();

0 commit comments

Comments
 (0)