forked from cahirwpz/mimiker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.c
More file actions
56 lines (49 loc) · 1.73 KB
/
exec.c
File metadata and controls
56 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <common.h>
#include <exec.h>
#include <thread.h>
#include <sched.h>
void program_thread(void *data) {
exec_args_t exec_args;
switch ((int)data) {
case 1:
exec_args.prog_name = "prog";
exec_args.argv = (char *[]){"argument1", "ARGUMENT2", "a-r-g-u-m-e-n-t-3"};
exec_args.argc = 3;
do_exec(&exec_args);
case 2:
exec_args.prog_name = "prog";
exec_args.argv = (char *[]){"String passed as argument."};
exec_args.argc = 1;
do_exec(&exec_args);
case 3:
exec_args.prog_name = "prog";
exec_args.argv = (char *[]){"abort_test"};
exec_args.argc = 1;
do_exec(&exec_args);
}
}
int main() {
/* This is a simple demonstration of the exec functionality. It
* requests to substitute current thread's image with program
* called "prog", which is implemented in ./user/prog.c, and after
* compilation embedded in the kernel image.
* As the loaded program has no means to communicate with the
* system, because system calls are not yet implemented, it runs
* quietly. To test its behavior with a debugger, after starting
* gdb issue the command:
* add-symbol-file user/prog.uelf 0x00400000
* which will load the symbols for the user program. You may then
* e.g. break at its main(), and see that argc and argv are set
* correctly. If you let it run further, you may `print textarea`
* to see that it accesses a string in .data and copies it to
* .bss.
*/
thread_t *td1 = thread_create("user_thread1", program_thread, (void *)1);
thread_t *td2 = thread_create("user_thread2", program_thread, (void *)2);
thread_t *td3 = thread_create("user_thread3", program_thread, (void *)3);
sched_add(td1);
sched_add(td2);
sched_add(td3);
sched_run();
return 0;
}