Skip to content

Commit 865ac7e

Browse files
sys_sigprocmask: initial implementation
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 402b13c commit 865ac7e

File tree

6 files changed

+80
-28
lines changed

6 files changed

+80
-28
lines changed

patches/mlibc/mlibc.patch

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From c7e816f64f5dc357cfd6399413ac38098de6234a Mon Sep 17 00:00:00 2001
1+
From dc0eb6086c635232cf3fee338dbbaa8915938e4e Mon Sep 17 00:00:00 2001
22
From: Andy-Python-Programmer <[email protected]>
33
Date: Thu, 10 Feb 2022 19:12:25 +1100
44
Subject: [PATCH] yes
@@ -7,8 +7,9 @@ Signed-off-by: Andy-Python-Programmer <[email protected]>
77
---
88
.gitignore | 7 ++++++
99
sysdeps/aero/generic/filesystem.cpp | 34 +++++++++++++++++++++++------
10+
sysdeps/aero/generic/signals.cpp | 14 ++++++++++--
1011
sysdeps/aero/include/aero/syscall.h | 6 +++++
11-
3 files changed, 40 insertions(+), 7 deletions(-)
12+
4 files changed, 52 insertions(+), 9 deletions(-)
1213

1314
diff --git a/.gitignore b/.gitignore
1415
index dbb35e8b..384b3395 100644
@@ -89,6 +90,32 @@ index 6a13f19c..69833ae5 100644
8990
return 0;
9091
}
9192

93+
diff --git a/sysdeps/aero/generic/signals.cpp b/sysdeps/aero/generic/signals.cpp
94+
index 3527370c..67f23202 100644
95+
--- a/sysdeps/aero/generic/signals.cpp
96+
+++ b/sysdeps/aero/generic/signals.cpp
97+
@@ -42,8 +42,18 @@ int sys_sigaction(int how, const struct sigaction *__restrict action,
98+
99+
int sys_sigprocmask(int how, const sigset_t *__restrict set,
100+
sigset_t *__restrict retrieve) {
101+
- mlibc::infoLogger() << "sys_sigprocmask() is not implemented"
102+
- << frg::endlog;
103+
+ auto old_set = 0;
104+
+
105+
+ if (retrieve) {
106+
+ old_set = reinterpret_cast<sc_word_t>(retrieve);
107+
+ }
108+
+
109+
+ auto result = syscall(SYS_SIGPROCMASK, how, set, old_set);
110+
+
111+
+ if (result < 0) {
112+
+ return -result;
113+
+ }
114+
+
115+
return 0;
116+
}
117+
} // namespace mlibc
118+
\ No newline at end of file
92119
diff --git a/sysdeps/aero/include/aero/syscall.h b/sysdeps/aero/include/aero/syscall.h
93120
index 07b1b51b..f6d7836d 100644
94121
--- a/sysdeps/aero/include/aero/syscall.h

src/aero_kernel/src/arch/x86_64/signals.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ pub fn interrupt_check_signals(stack: &mut InterruptStack) {
9292
}
9393
}
9494

95-
/// Helper function to check for any pending signals from a sycall.
9695
pub fn syscall_check_signals(_syscall_result: isize, _stack: &mut InterruptStack) {
9796
if let Some((_signal, entry)) = userland::signals::check_for_signals() {
9897
if let aero_syscall::signal::SignalHandler::Handle(_) = entry.handler() {

src/aero_kernel/src/mem/paging/addr.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,40 @@ impl VirtAddr {
9494
self.as_ptr::<T>() as *mut T
9595
}
9696

97-
/// If the virtual address is a valid userland address, the [`Some`] varient is returned
98-
/// contaning the address, else the [`None`] variant is returned.
97+
/// Validate reads `sizeof(T)` bytes from the virtual address and returns a mutable
98+
/// reference to the value (`&mut T`).
9999
///
100100
/// ## Example
101101
/// ```no_run
102-
/// let address: VirtAddr = VirtAddr::new(stat)
103-
/// .validate_user()
104-
/// .ok_or(AeroSyscallError::EFAULT)?;
102+
/// let address: &mut SomeStruct = VirtAddr::new(0xcafebabe)
103+
/// .read_mut::<SomeStruct>();
104+
/// .ok_or(AeroSyscallError::EFAULT)?;
105105
/// ```
106-
pub fn validate_user(self) -> Option<Self> {
107-
if self <= crate::arch::task::userland_last_address() {
108-
Some(self)
106+
pub fn read_mut<'struc, T>(&self) -> Option<&'struc mut T> {
107+
if self.validate_read::<T>() {
108+
Some(unsafe { &mut *(self.as_mut_ptr() as *mut T) })
109109
} else {
110110
None
111111
}
112112
}
113113

114-
/// Reads `sizeof(T)` bytes from the virtual address and returns a mutable reference
115-
/// to the value (`&mut T`).
114+
/// Returns if the address is valid to read `sizeof(T)` bytes at the address.
115+
fn validate_read<T: Sized>(&self) -> bool {
116+
*self < crate::arch::task::userland_last_address()
117+
&& (*self + core::mem::size_of::<T>()) <= crate::arch::task::userland_last_address()
118+
}
119+
120+
/// Validate reads `sizeof(T)` bytes from the virtual address and returns a copy
121+
/// of the value (`T`).
116122
///
117123
/// ## Example
118124
/// ```no_run
119-
/// let address: SomeStruct = VirtAddr::new(0xcafebabe)
120-
/// .read_mut::<SomeStruct>();
125+
/// let value: u64 = VirtAddr::new(0xcafebabe)
126+
/// .copied_read::<u64>()
127+
/// .ok_or(AeroSyscallError::EFAULT)?;
121128
/// ```
122-
///
123-
/// ## Safety
124-
/// * The virtual address must be valid.
125-
/// * It must be safe to read `sizeof(T)` bytes from the virtual address.
126-
pub unsafe fn read_mut<'struc, T>(&self) -> &'struc mut T {
127-
&mut *(self.as_mut_ptr() as *mut T)
129+
pub fn copied_read<T: Copy + Sized>(&self) -> Option<T> {
130+
self.read_mut().map(|t| *t)
128131
}
129132

130133
/// Aligns the virtual address downwards to the given alignment.

src/aero_kernel/src/syscall/fs.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,9 @@ pub fn fcntl(fd: usize, command: usize, arg: usize) -> Result<usize, AeroSyscall
370370
fn validate_stat_struct<'struc>(
371371
stat_struct: usize,
372372
) -> Result<&'struc mut aero_syscall::Stat, AeroSyscallError> {
373-
let stat_struct = VirtAddr::new(stat_struct as _)
374-
.validate_user()
375-
.ok_or(AeroSyscallError::EFAULT)?;
376-
377-
// SAFETY: The user provided address is validated above.
378-
Ok(unsafe { stat_struct.read_mut::<aero_syscall::Stat>() })
373+
VirtAddr::new(stat_struct as _)
374+
.read_mut::<aero_syscall::Stat>()
375+
.ok_or(AeroSyscallError::EFAULT)
379376
}
380377

381378
pub fn fstat(fd: usize, stat_struct: usize) -> Result<usize, AeroSyscallError> {

src/aero_kernel/src/syscall/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub fn generic_do_syscall(
166166
SYS_SETHOSTNAME => process::sethostname(b, c),
167167
SYS_INFO => process::info(b),
168168
SYS_SIGACTION => process::sigaction(b, c, d, e),
169+
SYS_SIGPROCMASK => process::sigprocmask(b, c, d),
169170
SYS_CLONE => process::clone(b, c),
170171

171172
SYS_READ => fs::read(b, c, d),

src/aero_kernel/src/syscall/process.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
use aero_syscall::signal::SigAction;
20+
use aero_syscall::signal::{SigAction, SigProcMask};
2121
use aero_syscall::{AeroSyscallError, MMapFlags, MMapProt};
2222
use alloc::string::String;
2323
use spin::{Mutex, Once};
@@ -242,6 +242,31 @@ pub fn sethostname(ptr: usize, length: usize) -> Result<usize, AeroSyscallError>
242242
}
243243
}
244244

245+
pub fn sigprocmask(how: usize, set: usize, old_set: usize) -> Result<usize, AeroSyscallError> {
246+
let set = VirtAddr::new(set as _)
247+
.copied_read::<u64>()
248+
.ok_or(AeroSyscallError::EFAULT)?;
249+
250+
let old_set = if old_set > 0 {
251+
Some(
252+
VirtAddr::new(old_set as _)
253+
.read_mut::<u64>()
254+
.ok_or(AeroSyscallError::EFAULT)?,
255+
)
256+
} else {
257+
None
258+
};
259+
260+
let how = SigProcMask::from(how as u64);
261+
262+
scheduler::get_scheduler()
263+
.current_task()
264+
.signals()
265+
.set_mask(how, set, old_set);
266+
267+
Ok(0)
268+
}
269+
245270
pub fn sigaction(
246271
sig: usize,
247272
sigact: usize,

0 commit comments

Comments
 (0)