@@ -22,6 +22,8 @@ use aero_syscall::{AeroSyscallError, MMapFlags, MMapProt};
22
22
use alloc:: string:: String ;
23
23
use spin:: { Mutex , Once } ;
24
24
25
+ use crate :: arch:: controlregs;
26
+
25
27
use crate :: fs;
26
28
use crate :: fs:: Path ;
27
29
@@ -104,10 +106,10 @@ pub fn exec(
104
106
envs : usize ,
105
107
envc : usize ,
106
108
) -> Result < usize , AeroSyscallError > {
107
- let path = validate_str ( path as * const u8 , path_size) . ok_or ( AeroSyscallError :: EINVAL ) ?;
109
+ let path = controlregs :: with_userspace_access ( || validate_str ( path as * const u8 , path_size) . ok_or ( AeroSyscallError :: EINVAL ) ) ?;
108
110
let path = Path :: new ( path) ;
109
111
110
- let executable = fs:: lookup_path ( path) ?;
112
+ let executable = controlregs :: with_userspace_access ( || fs:: lookup_path ( path) ) ?;
111
113
112
114
if executable. inode ( ) . metadata ( ) ?. is_directory ( ) {
113
115
return Err ( AeroSyscallError :: EISDIR ) ;
@@ -145,7 +147,7 @@ pub fn waitpid(pid: usize, status: usize, _flags: usize) -> Result<usize, AeroSy
145
147
let current_task = scheduler:: get_scheduler ( ) . current_task ( ) ;
146
148
let status = unsafe { & mut * ( status as * mut u32 ) } ;
147
149
148
- Ok ( current_task. waitpid ( pid, status) ?)
150
+ Ok ( controlregs :: with_userspace_access ( || current_task. waitpid ( pid, status) ) ?)
149
151
}
150
152
151
153
pub fn mmap (
@@ -215,7 +217,7 @@ pub fn gethostname(ptr: usize, length: usize) -> Result<usize, AeroSyscallError>
215
217
if bytes. len ( ) > slice. len ( ) {
216
218
Err ( AeroSyscallError :: ENAMETOOLONG )
217
219
} else {
218
- slice[ 0 ..bytes. len ( ) ] . copy_from_slice ( bytes) ;
220
+ controlregs :: with_userspace_access ( || slice[ 0 ..bytes. len ( ) ] . copy_from_slice ( bytes) ) ;
219
221
220
222
Ok ( bytes. len ( ) )
221
223
}
@@ -225,7 +227,7 @@ pub fn info(struc: usize) -> Result<usize, AeroSyscallError> {
225
227
let struc = unsafe { & mut * ( struc as * mut aero_syscall:: SysInfo ) } ;
226
228
227
229
// TODO: Fill in the rest of the struct.
228
- struc. uptime = crate :: time:: get_uptime_ticks ( ) as i64 ;
230
+ controlregs :: with_userspace_access ( || struc. uptime = crate :: time:: get_uptime_ticks ( ) as i64 ) ;
229
231
230
232
Ok ( 0x00 )
231
233
}
@@ -235,7 +237,7 @@ pub fn sethostname(ptr: usize, length: usize) -> Result<usize, AeroSyscallError>
235
237
236
238
match core:: str:: from_utf8 ( slice) {
237
239
Ok ( new_hostname) => {
238
- * hostname ( ) . lock ( ) = String :: from ( new_hostname) ;
240
+ controlregs :: with_userspace_access ( || * hostname ( ) . lock ( ) = String :: from ( new_hostname) ) ;
239
241
Ok ( 0 )
240
242
}
241
243
Err ( _) => Err ( AeroSyscallError :: EINVAL ) ,
@@ -259,7 +261,7 @@ pub fn sigaction(
259
261
} ;
260
262
261
263
let entry = if let Some ( new) = new {
262
- Some ( SignalEntry :: from_sigaction ( * new, sigreturn) ?)
264
+ Some ( controlregs :: with_userspace_access ( || SignalEntry :: from_sigaction ( * new, sigreturn) ) ?)
263
265
} else {
264
266
None
265
267
} ;
@@ -278,7 +280,7 @@ pub fn sigaction(
278
280
let task = scheduler. current_task ( ) ;
279
281
let signals = task. signals ( ) ;
280
282
281
- signals. set_signal ( sig, entry, old) ;
283
+ controlregs :: with_userspace_access ( || signals. set_signal ( sig, entry, old) ) ;
282
284
283
285
Ok ( 0 )
284
286
}
0 commit comments