keos/syscall/mod.rs
1//! System call infrastructure.
2use crate::thread::with_current;
3pub use abyss::interrupt::Registers;
4use abyss::x86_64::PrivilegeLevel;
5
6pub mod uaccess;
7
8#[doc(hidden)]
9#[unsafe(no_mangle)]
10pub extern "C" fn do_handle_syscall(frame: &mut Registers) {
11 with_current(|th| match th.task.as_mut() {
12 Some(task) => {
13 task.syscall(frame);
14 }
15 _ => {
16 panic!("Unexpected `syscall` instruction.")
17 }
18 });
19
20 if frame.interrupt_stack_frame.cs.dpl() == PrivilegeLevel::Ring3 {
21 crate::thread::__check_for_signal();
22 }
23}
24
25/// Flags for system calls.
26pub mod flags {
27 /// The [`FileMode`] enum represents the access modes available when opening
28 /// a file.
29 ///
30 /// This enum is used by user program to specify how a file is opened,
31 /// determining which operations can be performed on the file. It
32 /// defines three basic modes:
33 /// - [`FileMode::Read`]: The file is opened for reading only.
34 /// - [`FileMode::Write`]: The file is opened for writing only.
35 /// - [`FileMode::ReadWrite`]: The file is opened for both reading and
36 /// writing.
37 ///
38 /// These modes are used to control how the file descriptor behaves when
39 /// interacting with the file (e.g., reading, writing, or both).
40 #[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Clone, Copy)]
41 pub enum FileMode {
42 /// Read-only access to the file.
43 ///
44 /// In this mode, the file can only be read from, and no changes can be
45 /// made to the file's contents.
46 Read = 0,
47
48 /// Write-only access to the file.
49 ///
50 /// In this mode, the file can only be written to, and any existing
51 /// content in the file is overwritten with new data.
52 Write = 1,
53
54 /// Both Read and Write access to the file.
55 ///
56 /// In this mode, the file can both be read and written, and does NOT
57 /// removes existing content, but can be overwritten with new
58 /// data.
59 ReadWrite = 2,
60 }
61}