-
Notifications
You must be signed in to change notification settings - Fork 13
/
env_test.c
70 lines (62 loc) · 1.28 KB
/
env_test.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <libstatic/libstatic.h>
int main(int ac, char **av, char **env);
/*
* This is the real entry point. It passes the initial stack into
* the C entry point.
*
* %rdi - holds value of argc
* %rsi - holds value of argv, a pointer
* %rdx - holds value of env, a pointer
*
* env = argv + 8*(argc+1)
*/
asm (
".text\n"
".global _start\n"
".type _start,@function\n"
"_start:\n\t"
"movq (%rsp),%rdi\n\t"
"movq %rsp,%rsi\n\t"
"addq $8,%rsi\n\t"
"movq %rdi, %rax\n\t"
"addq $1,%rax\n\t"
"movq $8,%rdx\n\n"
"mul %rdx\n\t"
"addq %rsi,%rax\n\t"
"movq %rax, %rdx\n\t"
"jmp c_main"
);
void
c_main(int ac, char **av, char **env)
{
int r = main(ac, av, env);
linux_exit(r);
}
int
main(int ac, char **av, char **env)
{
char buffer[32];
int i;
/*
if (env == NULL)
linux_exit(1);
*/
print_string(1, "argc holds ");
print_long(1, ac);
print_string(1, "\n");
print_string(1, "argv holds ");
to_hex((unsigned long)av, buffer);
print_string(1, buffer);
print_string(1, "\n");
print_string(1, "env holds ");
to_hex((unsigned long)env, buffer);
print_string(1, buffer);
print_string(1, "\n");
print_string(1, "\nEnvironment:\n\t");
for (i = 0; env[i]; ++i)
{
print_string(1, env[i]);
print_string(1, "\n\t");
}
return 0;
}