-
Notifications
You must be signed in to change notification settings - Fork 0
/
useSystemCall.c
143 lines (118 loc) · 2.63 KB
/
useSystemCall.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define N 10000000
int a[1<<25];
int cnt = 0;
int rss , prev_rss , vss, prev_vss;
int *arg1;
char *arg2;
pid_t _pid;
void check_change() {
printf("vss = %d rss = %d\n",vss,rss);
if(abs(vss - prev_vss) > 0) {
printf("chnage in vss = %d\n", abs(vss - prev_vss));
}
if(abs(rss - prev_rss) > 0) {
printf("chnage in rss = %d\n", abs(rss - prev_rss));
}
prev_vss = vss; prev_rss = rss;
}
void recurse() {
if(cnt == 64) {
arg1[0] = (int)(_pid);
syscall(333,arg1,arg2);
vss = arg1[1];
rss = arg1[2];
check_change();
return;
}else {
cnt++;
int x[1<<12];
recurse();
}
}
int main() {
// setup...
arg1 = malloc(5*sizeof(int));
arg2 = malloc(sizeof(char)*1024);
_pid = getpid();
printf("pid of this process = %d\n",_pid);
//...
// first observatrion
arg1[0] = (int)(_pid);
long res = syscall(333,arg1,&arg2);
vss = prev_vss = arg1[1];
rss = prev_rss = arg1[2];
printf("without anything\n");
printf("vss = %d rss = %d\n",vss,rss);
printf("----------------------\n");
// -------------------------------------------------------------------------
// changes
unsigned int *ptr = malloc(1<<21); // 2 MB
printf("ptr = %p\n",ptr);
//
// second observatrion
printf("with malloc of 2 MB\n");
arg1[0] = (int)(_pid);
syscall(333,arg1,&arg2);
vss = arg1[1];
rss = arg1[2];
check_change();
printf("----------------------\n");
//.............................................................................
// changes
int i = 0;
printf("address of i = %p\n",&i);
while(i < ( 512 * (1<<8) ) ) {
ptr[i] = 1;
i++;
}
// third observatrion
printf("512 KB access of the above 2MB\n");
arg1[0] = (int)(_pid);
syscall(333,arg1,arg2);
vss = arg1[1];
rss = arg1[2];
check_change();
printf("----------------------\n");
// changes
free(ptr);
//
// fourth observatrion
printf("After free of the array\n");
arg1[0] = (int)(_pid);
syscall(333,arg1,&arg2);
vss = arg1[1];
rss = arg1[2];
check_change();
printf("----------------------\n");
// check for the global data a[]
i = 0;
while(i < ( 8 * (1<<20) ) ) {
a[i] = 1;
i++;
}
// fifth observatrion
printf("After access the global array\n");
arg1[0] = (int)(_pid);
syscall(333,arg1,&arg2);
vss = arg1[1];
rss = arg1[2];
check_change();
printf("----------------------\n");
printf("Recursion\n");
recurse(arg1,&arg2,_pid);
// generic test
for(i = 0; i<30 ;i++) {
calloc(1ULL<<i,1);
printf("after calloc = [ %lld B] \n",1ULL<<i);
arg1[0] = (int)(_pid);
syscall(333,arg1,&arg2);
vss = arg1[1];
rss = arg1[2];
check_change();
printf("------------------\n");
}
return 0;
}