@@ -127,6 +127,21 @@ int execve(Thread *t, uint16_t id, const char *name, const char **argv, const ch
127
127
return status ;
128
128
}
129
129
130
+ /* execveHandle(): handles the response for execve()
131
+ * params: msg - response message structure
132
+ * returns: should not return on success
133
+ */
134
+
135
+ int execveHandle (void * msg ) {
136
+ ExecCommand * cmd = (ExecCommand * ) msg ;
137
+
138
+ Thread * t = getThread (cmd -> header .header .requester );
139
+ if (!t ) return - ESRCH ;
140
+
141
+ SyscallRequest * req = & t -> syscall ;
142
+ return execmve (t , cmd -> elf , NULL , NULL );;
143
+ }
144
+
130
145
/* execrdv(): replaces the current program, executes a program from the ramdisk
131
146
* this is only used before file system drivers are loaded
132
147
* params: t - parent thread structure
@@ -156,7 +171,10 @@ int execrdv(Thread *t, const char *name, const char **argv) {
156
171
return -1 ;
157
172
}
158
173
159
- return execmve (t , image , argv , NULL );
174
+ int status = execmve (t , image , argv , NULL );
175
+ free (image );
176
+ schedRelease ();
177
+ return status ;
160
178
}
161
179
162
180
/* execmve(): helper function that replaces the current running program from memory
@@ -172,15 +190,11 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) {
172
190
// this guarantees we can return on failure
173
191
void * newctx = calloc (1 , PLATFORM_CONTEXT_SIZE );
174
192
if (!newctx ) {
175
- free (image );
176
- schedRelease ();
177
193
return -1 ;
178
194
}
179
195
180
196
if (!platformCreateContext (newctx , PLATFORM_CONTEXT_USER , 0 , 0 )) {
181
197
free (newctx );
182
- free (image );
183
- schedRelease ();
184
198
return -1 ;
185
199
}
186
200
@@ -192,7 +206,6 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) {
192
206
// parse the binary
193
207
uint64_t highest ;
194
208
uint64_t entry = loadELF (image , & highest );
195
- free (image );
196
209
if (!entry || !highest ) {
197
210
t -> context = oldctx ;
198
211
free (newctx );
@@ -203,7 +216,6 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) {
203
216
if (platformSetContext (t , entry , highest , argv , envp )) {
204
217
t -> context = oldctx ;
205
218
free (newctx );
206
- schedRelease ();
207
219
return -1 ;
208
220
}
209
221
@@ -227,6 +239,5 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) {
227
239
228
240
t -> status = THREAD_QUEUED ;
229
241
schedAdjustTimeslice ();
230
- schedRelease ();
231
242
return 0 ; // return to syscall dispatcher; the thread will not see this return
232
243
}
0 commit comments