kbd: use a better get_key method
[thunix.git] / fs / exec.c
blobff44977ca6ff99bd9afac82644f04202bcf73165
1 /*
2 * The thunix execve system call implementaion
3 */
4 #include <stdio.h>
5 #include <string.h>
6 #include <malloc.h>
7 #include <fs.h>
8 #include <err.h>
12 * Count how many arguments we hare
14 static inline int count(char **argv)
16 int i = 0;
17 if (argv) {
18 while (argv[i])
19 i++;
21 return i;
24 int sys_execve(const char *file, char **argv)
26 int fd = sys_open(file, 0);
29 * The current exec plan is: load the binary file to 16M,
30 * then jump to this address.
32 * I will try to make a good global thunix memory allocation
33 * map when I get time.
35 char * exec_buf = (char *)0x1600000;
36 char *p = exec_buf;
37 int bytes_read;
38 int argc;
39 int (*entry)(int, char **);
41 if (fd < 0)
42 return fd;
45 * Try to read 4K at a time
47 * Note: Since we don't support demand loading now, the current exec plan is
48 * to load the whole program into
49 * memory once.
51 while ((bytes_read = sys_read(fd, p, 4096)) > 0)
52 p += bytes_read;
53 sys_close(fd);
55 argc = count(argv);
57 entry = (int(*)(int, char **))(exec_buf);
58 return entry(argc, argv);