add SCR Part
This commit is contained in:
189
SCR/SCR3.1/TP01/Exercise2/answer.txt
Normal file
189
SCR/SCR3.1/TP01/Exercise2/answer.txt
Normal file
@@ -0,0 +1,189 @@
|
||||
- Stack -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 16088
|
||||
16088: ./stack
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000055fc39741000 4 4 0 r---- stack
|
||||
000055fc39742000 4 4 0 r-x-- stack
|
||||
000055fc39743000 4 4 0 r---- stack
|
||||
000055fc39744000 4 4 4 r---- stack
|
||||
000055fc39745000 4 4 4 rw--- stack
|
||||
000055fc55245000 132 4 4 rw--- [ anon ]
|
||||
00007fb88b000000 144 144 0 r---- libc.so.6
|
||||
00007fb88b024000 1480 1060 0 r-x-- libc.so.6
|
||||
00007fb88b196000 444 128 0 r---- libc.so.6
|
||||
00007fb88b205000 16 16 16 r---- libc.so.6
|
||||
00007fb88b209000 8 8 8 rw--- libc.so.6
|
||||
00007fb88b20b000 32 20 20 rw--- [ anon ]
|
||||
00007fb88b353000 20 12 12 rw--- [ anon ]
|
||||
00007fb88b384000 16 0 0 r---- [ anon ]
|
||||
00007fb88b388000 8 0 0 r---- [ anon ]
|
||||
00007fb88b38a000 8 8 0 r-x-- [ anon ]
|
||||
00007fb88b38c000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b38d000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007fb88b3b7000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b3c5000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b3c7000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007fb88b3c8000 4 4 4 rw--- [ anon ]
|
||||
00007ffcc07fd000 132 36 36 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 2708 1700 120
|
||||
|
||||
- MMAP -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 17734
|
||||
17734: ./mmap
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000055e00c982000 4 4 0 r---- mmap
|
||||
000055e00c983000 4 4 0 r-x-- mmap
|
||||
000055e00c984000 4 4 0 r---- mmap
|
||||
000055e00c985000 4 4 4 r---- mmap
|
||||
000055e00c986000 4 4 4 rw--- mmap
|
||||
000055e020dd6000 132 4 4 rw--- [ anon ]
|
||||
00007f2007800000 144 144 0 r---- libc.so.6
|
||||
00007f2007824000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f2007996000 444 128 0 r---- libc.so.6
|
||||
00007f2007a05000 16 16 16 r---- libc.so.6
|
||||
00007f2007a09000 8 8 8 rw--- libc.so.6
|
||||
00007f2007a0b000 32 20 20 rw--- [ anon ]
|
||||
00007f2007b2b000 256 128 128 rw--- 256k
|
||||
00007f2007b6b000 20 12 12 rw--- [ anon ]
|
||||
00007f2007b80000 64 64 64 rw-s- zero (deleted)
|
||||
00007f2007b90000 48 32 32 rw--- [ anon ]
|
||||
00007f2007b9c000 16 0 0 r---- [ anon ]
|
||||
00007f2007ba0000 8 0 0 r---- [ anon ]
|
||||
00007f2007ba2000 8 8 0 r-x-- [ anon ]
|
||||
00007f2007ba4000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2007ba5000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f2007bcf000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2007bdd000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f2007bdf000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f2007be0000 4 4 4 rw--- [ anon ]
|
||||
00007ffcfccb6000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 3076 1904 324
|
||||
|
||||
- Huge -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18284
|
||||
18284: ./huge
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
0000555e2f729000 4 4 0 r---- huge
|
||||
0000555e2f72a000 4 4 0 r-x-- huge
|
||||
0000555e2f72b000 4 4 0 r---- huge
|
||||
0000555e2f72c000 4 4 4 r---- huge
|
||||
0000555e2f72d000 4 4 4 rw--- huge
|
||||
0000555e40ba4000 228 100 100 rw--- [ anon ]
|
||||
00007f2f5d400000 144 144 0 r---- libc.so.6
|
||||
00007f2f5d424000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f2f5d596000 444 128 0 r---- libc.so.6
|
||||
00007f2f5d605000 16 16 16 r---- libc.so.6
|
||||
00007f2f5d609000 8 8 8 rw--- libc.so.6
|
||||
00007f2f5d60b000 32 20 20 rw--- [ anon ]
|
||||
00007f2f5d757000 280 272 272 rw--- [ anon ]
|
||||
00007f2f5d7c9000 16 0 0 r---- [ anon ]
|
||||
00007f2f5d7cd000 8 0 0 r---- [ anon ]
|
||||
00007f2f5d7cf000 8 8 0 r-x-- [ anon ]
|
||||
00007f2f5d7d1000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d7d2000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f2f5d7fc000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d80a000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d80c000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f2f5d80d000 4 4 4 rw--- [ anon ]
|
||||
00007ffdcfdcf000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 3064 2036 456
|
||||
|
||||
- Null -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18519
|
||||
18519: ./null
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
0000561bf65bf000 4 4 0 r---- null
|
||||
0000561bf65c0000 4 4 0 r-x-- null
|
||||
0000561bf65c1000 4 4 0 r---- null
|
||||
0000561bf65c2000 4 4 4 r---- null
|
||||
0000561bf65c3000 4 4 4 rw--- null
|
||||
0000561c26834000 132 4 4 rw--- [ anon ]
|
||||
00007f293fa00000 144 144 0 r---- libc.so.6
|
||||
00007f293fa24000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f293fb96000 444 128 0 r---- libc.so.6
|
||||
00007f293fc05000 16 16 16 r---- libc.so.6
|
||||
00007f293fc09000 8 8 8 rw--- libc.so.6
|
||||
00007f293fc0b000 32 20 20 rw--- [ anon ]
|
||||
00007f293fca6000 20 12 12 rw--- [ anon ]
|
||||
00007f293fcd7000 16 0 0 r---- [ anon ]
|
||||
00007f293fcdb000 8 0 0 r---- [ anon ]
|
||||
00007f293fcdd000 8 8 0 r-x-- [ anon ]
|
||||
00007f293fcdf000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f293fce0000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f293fd0a000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f293fd18000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f293fd1a000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f293fd1b000 4 4 4 rw--- [ anon ]
|
||||
00007ffe4e9df000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 2708 1680 100
|
||||
|
||||
- Heap -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18846
|
||||
18846: ./heap
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
00005571639f9000 4 4 0 r---- heap
|
||||
00005571639fa000 4 4 0 r-x-- heap
|
||||
00005571639fb000 4 4 0 r---- heap
|
||||
00005571639fc000 4 4 4 r---- heap
|
||||
00005571639fd000 4 4 4 rw--- heap
|
||||
000055717e499000 50028 49924 49924 rw--- [ anon ]
|
||||
00007f485aa00000 144 144 0 r---- libc.so.6
|
||||
00007f485aa24000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f485ab96000 444 128 0 r---- libc.so.6
|
||||
00007f485ac05000 16 16 16 r---- libc.so.6
|
||||
00007f485ac09000 8 8 8 rw--- libc.so.6
|
||||
00007f485ac0b000 32 20 20 rw--- [ anon ]
|
||||
00007f485ad82000 20 12 12 rw--- [ anon ]
|
||||
00007f485adb3000 16 0 0 r---- [ anon ]
|
||||
00007f485adb7000 8 0 0 r---- [ anon ]
|
||||
00007f485adb9000 8 8 0 r-x-- [ anon ]
|
||||
00007f485adbb000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f485adbc000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f485ade6000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f485adf4000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f485adf6000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f485adf7000 4 4 4 rw--- [ anon ]
|
||||
00007fffd8762000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 52604 51600 50020
|
||||
|
||||
- Buf -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 19569
|
||||
19569: ./buf
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000056423e617000 4 4 0 r---- buf
|
||||
000056423e618000 4 4 0 r-x-- buf
|
||||
000056423e619000 4 4 0 r---- buf
|
||||
000056423e61a000 4 4 4 r---- buf
|
||||
000056423e61b000 4 4 4 rw--- buf
|
||||
000056423e61c000 16384 16384 16384 rw--- [ anon ]
|
||||
0000564255eda000 132 4 4 rw--- [ anon ]
|
||||
00007f576c600000 144 144 0 r---- libc.so.6
|
||||
00007f576c624000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f576c796000 444 128 0 r---- libc.so.6
|
||||
00007f576c805000 16 16 16 r---- libc.so.6
|
||||
00007f576c809000 8 8 8 rw--- libc.so.6
|
||||
00007f576c80b000 32 20 20 rw--- [ anon ]
|
||||
00007f576c8c9000 20 12 12 rw--- [ anon ]
|
||||
00007f576c8fa000 16 0 0 r---- [ anon ]
|
||||
00007f576c8fe000 8 0 0 r---- [ anon ]
|
||||
00007f576c900000 8 8 0 r-x-- [ anon ]
|
||||
00007f576c902000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f576c903000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f576c92d000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f576c93b000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f576c93d000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f576c93e000 4 4 4 rw--- [ anon ]
|
||||
00007ffd7eb9e000 132 12 12 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 19092 18060 16480
|
17
SCR/SCR3.1/TP01/Exercise2/subject/Makefile
Normal file
17
SCR/SCR3.1/TP01/Exercise2/subject/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
CFLAGS := -Wall -g -O0
|
||||
SRC=buf.c heap.c huge.c mmap.c null.c stack.c
|
||||
|
||||
DEPENDHELPERS=helpers.o
|
||||
|
||||
BINARIES=$(SRC:%.c=%)
|
||||
|
||||
%.o : %c
|
||||
gcc -c $+
|
||||
|
||||
$(BINARIES): % : %.o $(DEPENDHELPERS)
|
||||
gcc -o $@ $+
|
||||
|
||||
all : $(BINARIES)
|
||||
|
||||
clean:
|
||||
rm -f *.o $(BINARIES)
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/buf
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/buf
Executable file
Binary file not shown.
9
SCR/SCR3.1/TP01/Exercise2/subject/buf.c
Normal file
9
SCR/SCR3.1/TP01/Exercise2/subject/buf.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "helpers.h"
|
||||
|
||||
static char buffer[16 MB] = {0};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
randomize(buffer, 16 MB);
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/data/256k
Normal file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/data/256k
Normal file
Binary file not shown.
BIN
SCR/SCR3.1/TP01/Exercise2/subject/heap
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/heap
Executable file
Binary file not shown.
8
SCR/SCR3.1/TP01/Exercise2/subject/heap.c
Normal file
8
SCR/SCR3.1/TP01/Exercise2/subject/heap.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
dirty(16 MB);
|
||||
clean(32 MB);
|
||||
return interlude();
|
||||
}
|
36
SCR/SCR3.1/TP01/Exercise2/subject/helpers.c
Normal file
36
SCR/SCR3.1/TP01/Exercise2/subject/helpers.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "helpers.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void randomize(char *buf, size_t n)
|
||||
{
|
||||
assert(buf);
|
||||
memset(buf, rand() & 0xff, n);
|
||||
}
|
||||
|
||||
void clean(size_t b)
|
||||
{
|
||||
for (; b > 0; b -= 1 KB)
|
||||
calloc(1 KB, sizeof(char));
|
||||
}
|
||||
|
||||
void dirty(size_t b)
|
||||
{
|
||||
for (; b > 0; b -= 1 KB)
|
||||
randomize(calloc(1 KB, sizeof(char)), 1 KB);
|
||||
}
|
||||
|
||||
int interlude(void)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
printf("pid %i\n", (int)pid);
|
||||
printf("------------------------------------------\n"
|
||||
"go check /proc/%i/smaps; I'll wait...\n"
|
||||
"press <Enter> when you're done\n", pid);
|
||||
fgetc(stdin);
|
||||
return 0;
|
||||
}
|
13
SCR/SCR3.1/TP01/Exercise2/subject/helpers.h
Normal file
13
SCR/SCR3.1/TP01/Exercise2/subject/helpers.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _HELPERS_H
|
||||
#define _HELPERS_H
|
||||
#include <stdlib.h>
|
||||
|
||||
#define KB * 1024
|
||||
#define MB * 1024 * 1024
|
||||
|
||||
void randomize(char *buf, size_t n);
|
||||
void clean(size_t n);
|
||||
void dirty(size_t n);
|
||||
int interlude(void);
|
||||
|
||||
#endif
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/huge
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/huge
Executable file
Binary file not shown.
12
SCR/SCR3.1/TP01/Exercise2/subject/huge.c
Normal file
12
SCR/SCR3.1/TP01/Exercise2/subject/huge.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *under = malloc(96 KB);
|
||||
randomize(under, 96 KB);
|
||||
|
||||
char *over = malloc(256 KB);
|
||||
randomize(over, 256 KB);
|
||||
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/mmap
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/mmap
Executable file
Binary file not shown.
38
SCR/SCR3.1/TP01/Exercise2/subject/mmap.c
Normal file
38
SCR/SCR3.1/TP01/Exercise2/subject/mmap.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "helpers.h"
|
||||
#include <sys/mman.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* inert map (never modified) */
|
||||
char *inert = mmap(NULL, 16 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_PRIVATE,
|
||||
-1, 0);
|
||||
/* anonymous, private mmap */
|
||||
char *anon_priv = mmap(NULL, 32 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_PRIVATE,
|
||||
-1, 0);
|
||||
randomize(anon_priv, 32 KB);
|
||||
|
||||
/* anonymous, shared map */
|
||||
char *anon_shared = mmap(NULL, 64 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_SHARED,
|
||||
-1, 0);
|
||||
randomize(anon_shared, 64 KB);
|
||||
|
||||
/* private, file-backed map */
|
||||
int fd = open("data/256k", O_RDWR);
|
||||
assert(fd >= 0);
|
||||
char *file = mmap(NULL, 256 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE,
|
||||
fd, 0);
|
||||
randomize(file, 128 KB);
|
||||
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/null
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/null
Executable file
Binary file not shown.
6
SCR/SCR3.1/TP01/Exercise2/subject/null.c
Normal file
6
SCR/SCR3.1/TP01/Exercise2/subject/null.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/stack
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/stack
Executable file
Binary file not shown.
8
SCR/SCR3.1/TP01/Exercise2/subject/stack.c
Normal file
8
SCR/SCR3.1/TP01/Exercise2/subject/stack.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
char buf[28 KB] = {0};
|
||||
randomize(buf, 28 KB);
|
||||
return interlude();
|
||||
}
|
Reference in New Issue
Block a user