@@ -27,12 +27,11 @@ impl Default for Boundary {
2727impl Boundary {
2828 /// Minimum required size for initial process memory.
2929 ///
30- /// Need at least 9 dwords of initial stack space for CRT 0:
30+ /// Need at least 5 dwords of initial stack space for CRT 0:
3131 ///
32- /// - 4 dwords for initial upcall arguments
3332 /// - 1 dword for initial upcall return address (although this will be zero for init_fn)
3433 /// - 4 dwords of scratch space for invoking memop syscalls
35- const MIN_APP_BRK : u32 = 9 * core:: mem:: size_of :: < usize > ( ) as u32 ;
34+ const MIN_APP_BRK : u32 = 5 * core:: mem:: size_of :: < usize > ( ) as u32 ;
3635
3736 /// Constructs a new instance of `SysCall`.
3837 pub fn new ( ) -> Self {
@@ -85,91 +84,35 @@ impl UserspaceKernelBoundary for Boundary {
8584
8685 unsafe fn set_syscall_return_value (
8786 & self ,
88- accessible_memory_start : * const u8 ,
89- app_brk : * const u8 ,
87+ _accessible_memory_start : * const u8 ,
88+ _app_brk : * const u8 ,
9089 state : & mut Self :: StoredState ,
9190 return_value : SyscallReturn ,
9291 ) -> Result < ( ) , ( ) > {
93- let mut ret0 = 0 ;
94- let mut ret1 = 0 ;
95- let mut ret2 = 0 ;
96- let mut ret3 = 0 ;
97-
98- // These operations are only safe so long as
99- // - the pointers are properly aligned. This is guaranteed because the
100- // pointers are all offset multiples of 4 bytes from the stack
101- // pointer, which is guaranteed to be properly aligned after
102- // exception entry on x86. See
103- // https://github.com/tock/tock/pull/2478#issuecomment-796389747
104- // for more details.
105- // - the pointer is dereferencable, i.e. the memory range of
106- // the given size starting at the pointer must all be within
107- // the bounds of a single allocated object
108- // - the pointer must point to an initialized instance of its
109- // type
110- // - during the lifetime of the returned reference (of the
111- // cast, essentially an arbitrary 'a), the memory must not
112- // get accessed (read or written) through any other pointer.
113- //
114- // Refer to
115- // https://doc.rust-lang.org/std/primitive.pointer.html#safety-13
11692 kernel:: utilities:: arch_helpers:: encode_syscall_return_trd104 (
11793 & kernel:: utilities:: arch_helpers:: TRD104SyscallReturn :: from_syscall_return (
11894 return_value,
11995 ) ,
120- & mut ret0 ,
121- & mut ret1 ,
122- & mut ret2 ,
123- & mut ret3 ,
96+ & mut state . ebx ,
97+ & mut state . ecx ,
98+ & mut state . edx ,
99+ & mut state . edi ,
124100 ) ;
125101
126- // App allocates 16 bytes of stack space for passing syscall arguments. We re-use that stack
127- // space to pass return values.
128- //
129- // Safety: Caller of this function has guaranteed that the memory region is valid.
130- unsafe {
131- state. write_stack ( 0 , ret0, accessible_memory_start, app_brk) ?;
132- state. write_stack ( 1 , ret1, accessible_memory_start, app_brk) ?;
133- state. write_stack ( 2 , ret2, accessible_memory_start, app_brk) ?;
134- state. write_stack ( 3 , ret3, accessible_memory_start, app_brk) ?;
135- }
136-
137102 Ok ( ( ) )
138103 }
139104
140105 unsafe fn set_process_function (
141106 & self ,
142- accessible_memory_start : * const u8 ,
143- app_brk : * const u8 ,
107+ _accessible_memory_start : * const u8 ,
108+ _app_brk : * const u8 ,
144109 state : & mut Self :: StoredState ,
145110 upcall : FunctionCall ,
146111 ) -> Result < ( ) , ( ) > {
147- // Our x86 port expects upcalls to be standard cdecl routines. We push args and return
148- // address onto the stack accordingly.
149- //
150- // Upcall arguments are written directly into the existing stack space (rather than
151- // being pushed on top). This is safe to do because:
152- //
153- // * When the process first starts ESP is initialized to `app_brk - 16`, giving us exactly
154- // enough space for these arguments.
155- // * Otherwise, we assume the app is currently issuing a `yield` syscall. We re-use the
156- // stack space from that syscall. This is okay because `yield` doesn't return anything.
157- //
158- // Safety: Caller of this function has guaranteed that the memory region is valid.
159- // usize is u32 on x86
160- unsafe {
161- state. write_stack ( 0 , upcall. argument0 as u32 , accessible_memory_start, app_brk) ?;
162- state. write_stack ( 1 , upcall. argument1 as u32 , accessible_memory_start, app_brk) ?;
163- state. write_stack ( 2 , upcall. argument2 as u32 , accessible_memory_start, app_brk) ?;
164- state. write_stack (
165- 3 ,
166- upcall. argument3 . as_usize ( ) as u32 ,
167- accessible_memory_start,
168- app_brk,
169- ) ?;
170-
171- state. push_stack ( state. eip , accessible_memory_start, app_brk) ?;
172- }
112+ state. ebx = upcall. argument0 as u32 ;
113+ state. ecx = upcall. argument1 as u32 ;
114+ state. edx = upcall. argument2 as u32 ;
115+ state. edi = upcall. argument3 . as_usize ( ) as u32 ;
173116
174117 // The next time we switch to this process, we will directly jump to the upcall. When the
175118 // upcall issues `ret`, it will return to wherever the yield syscall was invoked.
@@ -180,8 +123,8 @@ impl UserspaceKernelBoundary for Boundary {
180123
181124 unsafe fn switch_to_process (
182125 & self ,
183- accessible_memory_start : * const u8 ,
184- app_brk : * const u8 ,
126+ _accessible_memory_start : * const u8 ,
127+ _app_brk : * const u8 ,
185128 state : & mut Self :: StoredState ,
186129 ) -> ( ContextSwitchReason , Option < * const u8 > ) {
187130 // Sanity check: don't try to run a faulted app
@@ -203,17 +146,10 @@ impl UserspaceKernelBoundary for Boundary {
203146 SYSCALL_VECTOR => {
204147 let num = state. eax as u8 ;
205148
206- // Syscall arguments are passed on the stack using cdecl convention.
207- //
208- // Safety: Caller of this function has guaranteed that the memory region is valid.
209- let arg0 =
210- unsafe { state. read_stack ( 0 , accessible_memory_start, app_brk) } . unwrap_or ( 0 ) ;
211- let arg1 =
212- unsafe { state. read_stack ( 1 , accessible_memory_start, app_brk) } . unwrap_or ( 0 ) ;
213- let arg2 =
214- unsafe { state. read_stack ( 2 , accessible_memory_start, app_brk) } . unwrap_or ( 0 ) ;
215- let arg3 =
216- unsafe { state. read_stack ( 3 , accessible_memory_start, app_brk) } . unwrap_or ( 0 ) ;
149+ let arg0 = state. ebx ;
150+ let arg1 = state. ecx ;
151+ let arg2 = state. edx ;
152+ let arg3 = state. edi ;
217153
218154 Syscall :: from_register_arguments (
219155 num,
0 commit comments