@@ -85,16 +85,11 @@ impl UserspaceKernelBoundary for Boundary {
8585
8686 unsafe fn set_syscall_return_value (
8787 & self ,
88- accessible_memory_start : * const u8 ,
89- app_brk : * const u8 ,
88+ _accessible_memory_start : * const u8 ,
89+ _app_brk : * const u8 ,
9090 state : & mut Self :: StoredState ,
9191 return_value : SyscallReturn ,
9292 ) -> Result < ( ) , ( ) > {
93- let mut ret0 = 0 ;
94- let mut ret1 = 0 ;
95- let mut ret2 = 0 ;
96- let mut ret3 = 0 ;
97-
9893 // These operations are only safe so long as
9994 // - the pointers are properly aligned. This is guaranteed because the
10095 // pointers are all offset multiples of 4 bytes from the stack
@@ -117,59 +112,26 @@ impl UserspaceKernelBoundary for Boundary {
117112 & kernel:: utilities:: arch_helpers:: TRD104SyscallReturn :: from_syscall_return (
118113 return_value,
119114 ) ,
120- & mut ret0 ,
121- & mut ret1 ,
122- & mut ret2 ,
123- & mut ret3 ,
115+ & mut state . ebx ,
116+ & mut state . ecx ,
117+ & mut state . edx ,
118+ & mut state . edi ,
124119 ) ;
125120
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-
137121 Ok ( ( ) )
138122 }
139123
140124 unsafe fn set_process_function (
141125 & self ,
142- accessible_memory_start : * const u8 ,
143- app_brk : * const u8 ,
126+ _accessible_memory_start : * const u8 ,
127+ _app_brk : * const u8 ,
144128 state : & mut Self :: StoredState ,
145129 upcall : FunctionCall ,
146130 ) -> 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- }
131+ state. ebx = upcall. argument0 as u32 ;
132+ state. ecx = upcall. argument1 as u32 ;
133+ state. edx = upcall. argument2 as u32 ;
134+ state. edi = upcall. argument3 . as_usize ( ) as u32 ;
173135
174136 // The next time we switch to this process, we will directly jump to the upcall. When the
175137 // upcall issues `ret`, it will return to wherever the yield syscall was invoked.
@@ -180,8 +142,8 @@ impl UserspaceKernelBoundary for Boundary {
180142
181143 unsafe fn switch_to_process (
182144 & self ,
183- accessible_memory_start : * const u8 ,
184- app_brk : * const u8 ,
145+ _accessible_memory_start : * const u8 ,
146+ _app_brk : * const u8 ,
185147 state : & mut Self :: StoredState ,
186148 ) -> ( ContextSwitchReason , Option < * const u8 > ) {
187149 // Sanity check: don't try to run a faulted app
@@ -203,17 +165,10 @@ impl UserspaceKernelBoundary for Boundary {
203165 SYSCALL_VECTOR => {
204166 let num = state. eax as u8 ;
205167
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 ) ;
168+ let arg0 = state. ebx ;
169+ let arg1 = state. ecx ;
170+ let arg2 = state. edx ;
171+ let arg3 = state. edi ;
217172
218173 Syscall :: from_register_arguments (
219174 num,
0 commit comments