-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.txt
233 lines (211 loc) · 7.47 KB
/
README.txt
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
By: Fatih Aktas
## How-to-use
1 - You 'make' to compile the c codes.
2 - Run mem_1.o, mem_2.o, mem_3.o
3 - Observe the differences caused in the memory because of
the selected action.
# Files:
- mem_1.c
- mem_2.c
- mem_3.c
- Makefile
- memlayout.c
- memlayout.h
- README.txt
Note the results below are ran using the CFLAG below to set the PAGE_SIZE.
CFLAG=-DUSER_PAGE_SIZE=16384
## File: mem_1.c
Action:
This code calls get_mem_layout before and after
allocating a massive array with malloc and initializing it.
Then, it prints out the location of the array and the location
of the last item in that array.
Results: >> ./mem_1.o
Memory Before(13 Regions):
0x00000000 - 0x08047fff NO
0x08048000 - 0x08049fff RO
0x0804a000 - 0x0804afff RW
0x0804b000 - 0x09dbffff NO
0x09dc0000 - 0x09de0fff RW
0x09de1000 - 0xf7d14fff NO
0xf7d15000 - 0xf7d15fff RW
0xf7d16000 - 0xf7ec5fff RO
0xf7ec6000 - 0xf7ec6fff NO
0xf7ec7000 - 0xf7ec8fff RO
0xf7ec9000 - 0xf7eccfff RW
0xf7ecd000 - 0xf7f22fff NO (0xf7ee2008 is here)
0xf7f23000 - 0xf7f23fff RW
0xf7f24000 - 0xf7f24fff RO
0xf7f25000 - 0xf7f26fff NO
0xf7f27000 - 0xf7f4cfff RO
0xf7f4d000 - 0xf7f4dfff RW
0xf7f4e000 - 0xff41dfff NO
0xff41e000 - 0xffc1dfff RW
0xffc1e000 - 0xffffffff NO
0x00000000 - 0x00000000 NO
0x00000000 - 0x00000000 NO
Memory After(15 Regions):
0x00000000 - 0x08047fff NO
0x08048000 - 0x08049fff RO
0x0804a000 - 0x0804afff RW
0x0804b000 - 0x09dbffff NO
0x09dc0000 - 0x09de0fff RW
0x09de1000 - 0xf7d14fff NO
0xf7d15000 - 0xf7d15fff RW
0xf7d16000 - 0xf7ec5fff RO
0xf7ec6000 - 0xf7ec6fff NO
0xf7ec7000 - 0xf7ec8fff RO
0xf7ec9000 - 0xf7eccfff RW
0xf7ecd000 - 0xf7ee1fff NO
0xf7ee2000 - 0xf7f23fff RW (0xf7ee2008 is here)
0xf7f24000 - 0xf7f24fff RO
0xf7f25000 - 0xf7f26fff NO
0xf7f27000 - 0xf7f4cfff RO
0xf7f4d000 - 0xf7f4dfff RW
0xf7f4e000 - 0xff41dfff NO
0xff41e000 - 0xffc1dfff RW
0xffc1e000 - 0xffffffff NO
0x00000000 - 0x00000000 NO
0x00000000 - 0x00000000 NO
Location of big array: 0xf7ee2008
Location of last element: 0xf7f22004
Differences Before-After:
The permissions of the address space regions
have changed. The location 0xf7ee2008 changed from NO to RW.
Reason behind the differences:
The program allocated a space that was enough for the big array to be stored
in a page starting at 0xf7ee2008. The allocated space needed Read-Write access, So
it made one.
## File: mem_2.c
Action:
This file creates a bigfile.txt file.
Then, it calls get_mem_layout before and after calling mmap() for bigfile.txt.
Results:
Memory Before:
0x00000000 - 0x08047fff NO
0x08048000 - 0x0804afff RO
0x0804b000 - 0x0804bfff RW
0x0804c000 - 0x081e7fff NO
0x081e8000 - 0x08208fff RW
0x08209000 - 0xf7ceffff NO
0xf7cf0000 - 0xf7cf0fff RW
0xf7cf1000 - 0xf7ea0fff RO
0xf7ea1000 - 0xf7ea1fff NO
0xf7ea2000 - 0xf7ea3fff RO
0xf7ea4000 - 0xf7ea7fff RW
0xf7ea8000 - 0xf7efdfff NO (0xf7eda000 was here)
0xf7efe000 - 0xf7efefff RW
0xf7eff000 - 0xf7efffff RO
0xf7f00000 - 0xf7f01fff NO
0xf7f02000 - 0xf7f27fff RO
0xf7f28000 - 0xf7f28fff RW
0xf7f29000 - 0xff541fff NO
0xff542000 - 0xffd41fff RW
0xffd42000 - 0xffffffff NO
0x00000000 - 0x00000000 NO
0x00000000 - 0x00000000 NO
Memory After:
0x00000000 - 0x08047fff NO
0x08048000 - 0x0804afff RO
0x0804b000 - 0x0804bfff RW
0x0804c000 - 0x081e7fff NO
0x081e8000 - 0x08208fff RW
0x08209000 - 0xf7ceffff NO
0xf7cf0000 - 0xf7cf0fff RW
0xf7cf1000 - 0xf7ea0fff RO
0xf7ea1000 - 0xf7ea1fff NO
0xf7ea2000 - 0xf7ea3fff RO
0xf7ea4000 - 0xf7ea7fff RW
0xf7ea8000 - 0xf7ed9fff NO
0xf7eda000 - 0xf7efefff RW (Location of big file mmap: 0xf7eda000)
0xf7eff000 - 0xf7efffff RO
0xf7f00000 - 0xf7f01fff NO
0xf7f02000 - 0xf7f27fff RO
0xf7f28000 - 0xf7f28fff RW
0xf7f29000 - 0xff541fff NO
0xff542000 - 0xffd41fff RW
0xffd42000 - 0xffffffff NO
0x00000000 - 0x00000000 NO
0x00000000 - 0x00000000 NO
Location of big file mmap:
0xf7eda000
Differences Before-After:
It can be seen that there was no access in 0xf714c000 before the allocation.
It was NO. After the allocation, 0xf7eda000 was a RW location used by the mmap operation in the
memory.
Reason behind the differences:
mmap() maps memory address space with a file in this code, which is bigfile.txt.
Since we mapped the file with both read and write access, mmap mapped the file
into address space as much as it needed for the file. So, it caused a change starting
at 0xf714c000 giving it a RW access.
## File: mem_3.c
Action:
This file runs a recursive function that adds integers up to integer i.
For each integer, it allocates an int in the memory space that is i-1.
Then, it adds those up in a recursive way.
It prints out the address and the value of the recursive i found in the function.
It then runs get_mem_layout before and after.
Results:
Memory Before:
0x00000000 - 0x08047fff NO
0x08048000 - 0x08049fff RO
0x0804a000 - 0x0804afff RW
0x0804b000 - 0x0852dfff NO
0x0852e000 - 0x0854efff RW
0x0854f000 - 0xf7d41fff NO
0xf7d42000 - 0xf7d42fff RW
0xf7d43000 - 0xf7ef2fff RO
0xf7ef3000 - 0xf7ef3fff NO
0xf7ef4000 - 0xf7ef5fff RO
0xf7ef6000 - 0xf7ef9fff RW
0xf7efa000 - 0xf7f4ffff NO
0xf7f50000 - 0xf7f50fff RW
0xf7f51000 - 0xf7f51fff RO
0xf7f52000 - 0xf7f53fff NO
0xf7f54000 - 0xf7f79fff RO
0xf7f7a000 - 0xf7f7afff RW
0xf7f7b000 - 0xff40dfff NO
0xff40e000 - 0xffc0dfff RW
0xffc0e000 - 0xffffffff NO
0x00000000 - 0x00000000 NO
0x00000000 - 0x00000000 NO
Memory After:
0x00000000 - 0x08047fff NO
0x08048000 - 0x08049fff RO
0x0804a000 - 0x0804afff RW
0x0804b000 - 0x0852dfff NO
0x0852e000 - 0x0854efff RW
0x0854f000 - 0xf7d41fff NO
0xf7d42000 - 0xf7d42fff RW
0xf7d43000 - 0xf7ef2fff RO
0xf7ef3000 - 0xf7ef3fff NO
0xf7ef4000 - 0xf7ef5fff RO
0xf7ef6000 - 0xf7ef9fff RW
0xf7efa000 - 0xf7f4ffff NO
0xf7f50000 - 0xf7f50fff RW
0xf7f51000 - 0xf7f51fff RO
0xf7f52000 - 0xf7f53fff NO
0xf7f54000 - 0xf7f79fff RO
0xf7f7a000 - 0xf7f7afff RW
0xf7f7b000 - 0xff40dfff NO
0xff40e000 - 0xffc0dfff RW
0xffc0e000 - 0xffffffff NO
0x00000000 - 0x00000000 NO
0x00000000 - 0x00000000 NO
Location of recursive parameters:
Number of recursions: 4097
First level of recursion is at i:0xffc0d340
Last level of recursion is at i:0xffbdd310
Result of recursive addition : 8394753
Differences Before-After:
Allocated memory space for i is in from 0xffc0d340 to 0xffbdd310 is in a RW access
in the memory space, which was NO permission before.
Reason behind the differences:
As the recursiveAddition() function recurses into deeper levels
to calculate, it pushes new rows into the stack. Every new allocated
memory space for i is in from 0xffc0d340 to 0xffbdd310 with a RW access
in the memory space, which was NO permission before.
In C, recursive functions push more elements to the stack as it goes into deeper
levels of recursion, causing the stack to grow in size. The allocated space
for j, which equals j=i-1 requires space in the memory. So, the result
ends up in the RW space starting at 0xffc0d340 to be used by recursiveAddition.