Skip to content

Commit 043e647

Browse files
committed
sched: partial implementation of execve()
1 parent f6b5a57 commit 043e647

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/sched/exec.c

+19-8
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ int execve(Thread *t, uint16_t id, const char *name, const char **argv, const ch
127127
return status;
128128
}
129129

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+
130145
/* execrdv(): replaces the current program, executes a program from the ramdisk
131146
* this is only used before file system drivers are loaded
132147
* params: t - parent thread structure
@@ -156,7 +171,10 @@ int execrdv(Thread *t, const char *name, const char **argv) {
156171
return -1;
157172
}
158173

159-
return execmve(t, image, argv, NULL);
174+
int status = execmve(t, image, argv, NULL);
175+
free(image);
176+
schedRelease();
177+
return status;
160178
}
161179

162180
/* 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) {
172190
// this guarantees we can return on failure
173191
void *newctx = calloc(1, PLATFORM_CONTEXT_SIZE);
174192
if(!newctx) {
175-
free(image);
176-
schedRelease();
177193
return -1;
178194
}
179195

180196
if(!platformCreateContext(newctx, PLATFORM_CONTEXT_USER, 0, 0)) {
181197
free(newctx);
182-
free(image);
183-
schedRelease();
184198
return -1;
185199
}
186200

@@ -192,7 +206,6 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) {
192206
// parse the binary
193207
uint64_t highest;
194208
uint64_t entry = loadELF(image, &highest);
195-
free(image);
196209
if(!entry || !highest) {
197210
t->context = oldctx;
198211
free(newctx);
@@ -203,7 +216,6 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) {
203216
if(platformSetContext(t, entry, highest, argv, envp)) {
204217
t->context = oldctx;
205218
free(newctx);
206-
schedRelease();
207219
return -1;
208220
}
209221

@@ -227,6 +239,5 @@ int execmve(Thread *t, void *image, const char **argv, const char **envp) {
227239

228240
t->status = THREAD_QUEUED;
229241
schedAdjustTimeslice();
230-
schedRelease();
231242
return 0; // return to syscall dispatcher; the thread will not see this return
232243
}

0 commit comments

Comments
 (0)