@@ -22,6 +22,8 @@ use aero_syscall::{AeroSyscallError, MMapFlags, MMapProt};
2222use alloc:: string:: String ;
2323use spin:: { Mutex , Once } ;
2424
25+ use crate :: arch:: controlregs;
26+
2527use crate :: fs;
2628use crate :: fs:: Path ;
2729
@@ -104,10 +106,10 @@ pub fn exec(
104106 envs : usize ,
105107 envc : usize ,
106108) -> 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 ) ) ?;
108110 let path = Path :: new ( path) ;
109111
110- let executable = fs:: lookup_path ( path) ?;
112+ let executable = controlregs :: with_userspace_access ( || fs:: lookup_path ( path) ) ?;
111113
112114 if executable. inode ( ) . metadata ( ) ?. is_directory ( ) {
113115 return Err ( AeroSyscallError :: EISDIR ) ;
@@ -145,7 +147,7 @@ pub fn waitpid(pid: usize, status: usize, _flags: usize) -> Result<usize, AeroSy
145147 let current_task = scheduler:: get_scheduler ( ) . current_task ( ) ;
146148 let status = unsafe { & mut * ( status as * mut u32 ) } ;
147149
148- Ok ( current_task. waitpid ( pid, status) ?)
150+ Ok ( controlregs :: with_userspace_access ( || current_task. waitpid ( pid, status) ) ?)
149151}
150152
151153pub fn mmap (
@@ -215,7 +217,7 @@ pub fn gethostname(ptr: usize, length: usize) -> Result<usize, AeroSyscallError>
215217 if bytes. len ( ) > slice. len ( ) {
216218 Err ( AeroSyscallError :: ENAMETOOLONG )
217219 } else {
218- slice[ 0 ..bytes. len ( ) ] . copy_from_slice ( bytes) ;
220+ controlregs :: with_userspace_access ( || slice[ 0 ..bytes. len ( ) ] . copy_from_slice ( bytes) ) ;
219221
220222 Ok ( bytes. len ( ) )
221223 }
@@ -225,7 +227,7 @@ pub fn info(struc: usize) -> Result<usize, AeroSyscallError> {
225227 let struc = unsafe { & mut * ( struc as * mut aero_syscall:: SysInfo ) } ;
226228
227229 // 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 ) ;
229231
230232 Ok ( 0x00 )
231233}
@@ -235,7 +237,7 @@ pub fn sethostname(ptr: usize, length: usize) -> Result<usize, AeroSyscallError>
235237
236238 match core:: str:: from_utf8 ( slice) {
237239 Ok ( new_hostname) => {
238- * hostname ( ) . lock ( ) = String :: from ( new_hostname) ;
240+ controlregs :: with_userspace_access ( || * hostname ( ) . lock ( ) = String :: from ( new_hostname) ) ;
239241 Ok ( 0 )
240242 }
241243 Err ( _) => Err ( AeroSyscallError :: EINVAL ) ,
@@ -259,7 +261,7 @@ pub fn sigaction(
259261 } ;
260262
261263 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) ) ?)
263265 } else {
264266 None
265267 } ;
@@ -278,7 +280,7 @@ pub fn sigaction(
278280 let task = scheduler. current_task ( ) ;
279281 let signals = task. signals ( ) ;
280282
281- signals. set_signal ( sig, entry, old) ;
283+ controlregs :: with_userspace_access ( || signals. set_signal ( sig, entry, old) ) ;
282284
283285 Ok ( 0 )
284286}
0 commit comments