-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.c
58 lines (51 loc) · 1.18 KB
/
dump.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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "syscall.h"
#define PGSIZE 4096
int main(int argc, char *argv[])
{
/* Fork a new process to play with */
/* We don't have a good way to list all pids in the system
so forking a new process works for testing */
int pid = fork();
if (pid == 0) {
/* child spins and yields */
while (1) {
sleep(5);
};
}
/* parent dumps memory of the child */
int size=(int)sbrk(0);
char *buffer=malloc(size);
char *addr=0;
int guardPage=dump(pid,addr,buffer,size);
int *ptr=(int*)buffer;
int i=0;
for(i=0;i<size;i+=16)
{
if(i==guardPage){
printf(1,"******************Guard page starts here************************");
printf(1,"\n");
}
if(i==guardPage+4096){
printf(1,"******************Stack starts here*****************************");
printf(1,"\n");
}
if(i==guardPage+8192){
printf(1,"******************Heap starts here******************************");
printf(1,"\n");
}
printf(1,"0x%x\t",i);
printf(1,"0x%x\t",*ptr);
ptr++;
printf(1,"0x%x\t",*ptr);
ptr++;
printf(1,"0x%x\t",*ptr);
ptr++;
printf(1,"0x%x\t",*ptr);
ptr++;
printf(1,"\n");
}
exit();
}