diff --git a/SCR/SCR3.1/TP01/Exercise1/answer.txt b/SCR/SCR3.1/TP01/Exercise1/answer.txt new file mode 100644 index 0000000..16e993a --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise1/answer.txt @@ -0,0 +1,55 @@ +[baudrier@salle224-14 Exercise1]$ gcc virtual_adress.c +[baudrier@salle224-14 Exercise1]$ ./a.out +je suis le pid 157247 + +main = 0x56435b8ae179 +gettimeofday = 0x7fbdaf0c6870 +&argc = 0x7ffcf1b50e1c +&i = 0x7ffcf1b50e2c +&j = 0x56435b8b2000 +t = 0x56435b8b1060 +m = 0x56435ff42310 + +[baudrier@salle224-14 BUT2]$ cat /proc/157247/maps +56435b8ad000-56435b8ae000 r--p 00000000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out +56435b8ae000-56435b8af000 r-xp 00001000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out +56435b8af000-56435b8b0000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out +56435b8b0000-56435b8b1000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out +56435b8b1000-56435b8b3000 rw-p 00003000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out +56435ff42000-56435ff63000 rw-p 00000000 00:00 0 [heap] +7fbdaee00000-7fbdaee24000 r--p 00000000 103:05 6028 /usr/lib/libc.so.6 +7fbdaee24000-7fbdaef96000 r-xp 00024000 103:05 6028 /usr/lib/libc.so.6 +7fbdaef96000-7fbdaf005000 r--p 00196000 103:05 6028 /usr/lib/libc.so.6 +7fbdaf005000-7fbdaf009000 r--p 00204000 103:05 6028 /usr/lib/libc.so.6 +7fbdaf009000-7fbdaf00b000 rw-p 00208000 103:05 6028 /usr/lib/libc.so.6 +7fbdaf00b000-7fbdaf013000 rw-p 00000000 00:00 0 +7fbdaf08f000-7fbdaf094000 rw-p 00000000 00:00 0 +7fbdaf0c0000-7fbdaf0c4000 r--p 00000000 00:00 0 [vvar] +7fbdaf0c4000-7fbdaf0c6000 r--p 00000000 00:00 0 [vvar_vclock] +7fbdaf0c6000-7fbdaf0c8000 r-xp 00000000 00:00 0 [vdso] +7fbdaf0c8000-7fbdaf0c9000 r--p 00000000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2 +7fbdaf0c9000-7fbdaf0f3000 r-xp 00001000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2 +7fbdaf0f3000-7fbdaf101000 r--p 0002b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2 +7fbdaf101000-7fbdaf103000 r--p 00039000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2 +7fbdaf103000-7fbdaf104000 rw-p 0003b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2 +7fbdaf104000-7fbdaf105000 rw-p 00000000 00:00 0 +7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack] +ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] + +- main appartient au segment de pages : 56435b8ae000-56435b8af000 r-xp 00001000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out +-> C'est une fonction (donc du code) qui appartient au fichier a.out, et qui a besoin des droits d'exécutions (il a bien la permission 'x'). + +- gettimeofday : 7fbdaf0c6000-7fbdaf0c8000 r-xp 00000000 00:00 0 [vdso] +-> Code du noyau, exécuté par le noyau + +- &argc : 7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack] +-> Argument de la fonction main(), se trouve dans la pile (stack) + +- &i : 7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack] + +- &j : 56435b8b1000-56435b8b3000 rw-p 00003000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out + +- t : 56435b8b0000-56435b8b1000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out + +- m : 56435ff42000-56435ff63000 rw-p 00000000 00:00 0 [heap] +-> malloc() attribue de la mémoire dans le tas (heap) \ No newline at end of file diff --git a/SCR/SCR3.1/TP01/Exercise1/virtual_adress.c b/SCR/SCR3.1/TP01/Exercise1/virtual_adress.c new file mode 100644 index 0000000..7cfecd5 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise1/virtual_adress.c @@ -0,0 +1,27 @@ +/* adresses virtuelles d'un processus */ + +#include +#include +#include +#include +#include + +int t[1000] = {[0 ... 999] = 2}; + +int main(int argc, char * argv[]) +{ + int i=3; + static int j = 3; + char * m = (char*)malloc(1); + printf("je suis le pid %d\n\n",getpid()); + /* ------- Affichage des adresses --------*/ + printf("main\t\t=\t%p\n",main); + printf("gettimeofday\t=\t%p\n",gettimeofday); + printf("&argc\t\t=\t%p\n",&argc); + printf("&i\t\t=\t%p\n",&i); + printf("&j\t\t=\t%p\n",&j); + printf("t\t\t=\t%p\n",t); + printf("m\t\t=\t%p\n",m); + + getchar(); +} \ No newline at end of file diff --git a/SCR/SCR3.1/TP01/Exercise2/answer.txt b/SCR/SCR3.1/TP01/Exercise2/answer.txt new file mode 100644 index 0000000..ee7c4b4 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/answer.txt @@ -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 \ No newline at end of file diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/Makefile b/SCR/SCR3.1/TP01/Exercise2/subject/Makefile new file mode 100644 index 0000000..f6ddfde --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/Makefile @@ -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) diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/buf b/SCR/SCR3.1/TP01/Exercise2/subject/buf new file mode 100755 index 0000000..ff00b6a Binary files /dev/null and b/SCR/SCR3.1/TP01/Exercise2/subject/buf differ diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/buf.c b/SCR/SCR3.1/TP01/Exercise2/subject/buf.c new file mode 100644 index 0000000..4dbf387 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/buf.c @@ -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(); +} diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/data/256k b/SCR/SCR3.1/TP01/Exercise2/subject/data/256k new file mode 100644 index 0000000..f3e3746 Binary files /dev/null and b/SCR/SCR3.1/TP01/Exercise2/subject/data/256k differ diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/heap b/SCR/SCR3.1/TP01/Exercise2/subject/heap new file mode 100755 index 0000000..1a62a4c Binary files /dev/null and b/SCR/SCR3.1/TP01/Exercise2/subject/heap differ diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/heap.c b/SCR/SCR3.1/TP01/Exercise2/subject/heap.c new file mode 100644 index 0000000..196ecb9 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/heap.c @@ -0,0 +1,8 @@ +#include "helpers.h" + +int main(int argc, char **argv) +{ + dirty(16 MB); + clean(32 MB); + return interlude(); +} diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/helpers.c b/SCR/SCR3.1/TP01/Exercise2/subject/helpers.c new file mode 100644 index 0000000..1a2799f --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/helpers.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include "helpers.h" + +#include + +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 when you're done\n", pid); + fgetc(stdin); + return 0; +} diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/helpers.h b/SCR/SCR3.1/TP01/Exercise2/subject/helpers.h new file mode 100644 index 0000000..d8a774a --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/helpers.h @@ -0,0 +1,13 @@ +#ifndef _HELPERS_H +#define _HELPERS_H +#include + +#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 diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/huge b/SCR/SCR3.1/TP01/Exercise2/subject/huge new file mode 100755 index 0000000..8f4b1ec Binary files /dev/null and b/SCR/SCR3.1/TP01/Exercise2/subject/huge differ diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/huge.c b/SCR/SCR3.1/TP01/Exercise2/subject/huge.c new file mode 100644 index 0000000..046aea0 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/huge.c @@ -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(); +} diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/mmap b/SCR/SCR3.1/TP01/Exercise2/subject/mmap new file mode 100755 index 0000000..693e6c0 Binary files /dev/null and b/SCR/SCR3.1/TP01/Exercise2/subject/mmap differ diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/mmap.c b/SCR/SCR3.1/TP01/Exercise2/subject/mmap.c new file mode 100644 index 0000000..ac62144 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/mmap.c @@ -0,0 +1,38 @@ +#include "helpers.h" +#include +#include +#include + + +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(); +} diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/null b/SCR/SCR3.1/TP01/Exercise2/subject/null new file mode 100755 index 0000000..0bb4a72 Binary files /dev/null and b/SCR/SCR3.1/TP01/Exercise2/subject/null differ diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/null.c b/SCR/SCR3.1/TP01/Exercise2/subject/null.c new file mode 100644 index 0000000..fbd46f7 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/null.c @@ -0,0 +1,6 @@ +#include "helpers.h" + +int main(int argc, char **argv) +{ + return interlude(); +} diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/stack b/SCR/SCR3.1/TP01/Exercise2/subject/stack new file mode 100755 index 0000000..c20389c Binary files /dev/null and b/SCR/SCR3.1/TP01/Exercise2/subject/stack differ diff --git a/SCR/SCR3.1/TP01/Exercise2/subject/stack.c b/SCR/SCR3.1/TP01/Exercise2/subject/stack.c new file mode 100644 index 0000000..700eef1 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise2/subject/stack.c @@ -0,0 +1,8 @@ +#include "helpers.h" + +int main (int argc, char **argv) +{ + char buf[28 KB] = {0}; + randomize(buf, 28 KB); + return interlude(); +} diff --git a/SCR/SCR3.1/TP01/Exercise3/answer.txt b/SCR/SCR3.1/TP01/Exercise3/answer.txt new file mode 100644 index 0000000..0a65486 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise3/answer.txt @@ -0,0 +1,16 @@ +- Version 1 - +time = 0.149877 +[baudrier@salle224-14 Exercise3]$ size a.out + text data bss dec hex filename + 1136 512 40032 41680 a2d0 a.out + +- Version 2 - +time = 1.313450 +[baudrier@salle224-14 Exercise3]$ size a.out + text data bss dec hex filename + 1136 40528 8 41672 a2c8 a.out + +-> La version 2 est donc plus longue car dans la deuxième version on doit charger à chaque fois une nouvelle colonne du tableau à chaque itération. +-> Alors que dans la version 1, on parcours chaque colonne et chaque éléments de la colonne ensuite. +-> Donc dans cette première version le tableau t est dans le segment bss (car il n'est pas initialisé). +-> Et dans la deuxième version il est dans le segment data car il est initialisé. \ No newline at end of file diff --git a/SCR/SCR3.1/TP01/Exercise3/prog.c b/SCR/SCR3.1/TP01/Exercise3/prog.c new file mode 100644 index 0000000..b23d9c9 --- /dev/null +++ b/SCR/SCR3.1/TP01/Exercise3/prog.c @@ -0,0 +1,26 @@ +/* accès mémoire */ +#include +#include +#include +#define N 8192 + +int t[N][N]; + +static inline double tstamp(void) +{ + struct timespec tv; + clock_gettime(CLOCK_REALTIME, &tv); + return tv.tv_sec + tv.tv_nsec * 1.0e-9; +} + +int main() +{ + int i,j; + double t1,t2; + t1=tstamp(); + /* version 1 */ for(i=0;i +#include +#include +#include +#include + +void afficher(char* crible, int n) { + for(int i = 0; i < n; i++) { + if(crible[i]) printf("%d ", i); + } + + printf("\n"); +} + +void rayer_multiples(char* crible, int n, int k) { + for(int i = 0; i < n; i++) { + if(i % k == 0 && i != k) crible[i] = 0; + } +} + + +int main(int argc, char **argv) +{ + int n=1000; + if(argc>1){ + n = (int)strtol(argv[1],NULL,0); + assert( n > 0 ); + } + + char* crible = (char*)mmap(NULL, n * sizeof(int), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); + assert(crible != MAP_FAILED); + + for(int i=0; i +#include +#include +#include +#include + +static inline double tstamp(void) +{ + struct timespec tv; +// clock_gettime(CLOCK_REALTIME, &tv); + clock_gettime(CLOCK_MONOTONIC, &tv); + return tv.tv_sec + tv.tv_nsec * 1.0e-9; +} + +void shuffle(int *array, size_t n) +{ + if (n > 1) + { + size_t i; + for (i = 0; i < n - 1; i++) +// for (i = 0; i < n ; i++) + { + size_t j = i + rand() / (RAND_MAX / (n - i) + 1); +// size_t j = rand()%n; + int t = array[j]; + array[j] = array[i]; + array[i] = t; + } + } +} + +void init_access_c(int access[],size_t size) +{ + int i; + for(i=0;i +#include +#include +#include + +#define BLOCK_SIZE 1 + + +int main(int argc, char *argv[]) +{ + FILE* fin, + * fout; + char buf[BLOCK_SIZE]; + + assert( argc == 3 ); + + fin = fopen(argv[1], "r"); + assert( fin != NULL ); + + fout = fopen(argv[2],"w"); + assert( fout != NULL ); + + while(1){ + ssize_t nb_read; + nb_read = fread(buf,BLOCK_SIZE,1,fin); + if (nb_read <= 0) + break; + fwrite(buf,BLOCK_SIZE,nb_read,fout); + } + + fclose(fin); + fclose(fout); + + return 0; +} + diff --git a/SCR/SCR3.1/TP02/Exercise1/copy_sys.c b/SCR/SCR3.1/TP02/Exercise1/copy_sys.c new file mode 100644 index 0000000..9c52360 --- /dev/null +++ b/SCR/SCR3.1/TP02/Exercise1/copy_sys.c @@ -0,0 +1,37 @@ +//Correction + +#include +#include +#include + +#define BLOCK_SIZE 1 + + +int main(int argc, char *argv[]) +{ + int fin, + fout; + char buf[BLOCK_SIZE]; + + assert( argc == 3 ); + + fin = open(argv[1],O_RDONLY); + assert( fin >= 0 ); + + fout = open(argv[2],O_CREAT|O_WRONLY|O_TRUNC,0600); + assert( fout >= 0 ); + + while(1){ + ssize_t nb_read; + nb_read = read(fin,buf,BLOCK_SIZE); + if (nb_read <= 0) + break; + write(fout,buf,nb_read); + } + + close(fin); + close(fout); + + return 0; +} + diff --git a/SCR/SCR3.1/TP02/Exercise2/copy.c b/SCR/SCR3.1/TP02/Exercise2/copy.c new file mode 100644 index 0000000..c425b68 --- /dev/null +++ b/SCR/SCR3.1/TP02/Exercise2/copy.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include + + +#define BUFSIZE 1024 + + +static inline double tstamp(void) +{ + struct timespec tv; + clock_gettime(CLOCK_REALTIME, &tv); + return tv.tv_sec + tv.tv_nsec * 1.0e-9; +} + +int main(int argc, char *argv[]) +{ + //char buf[BUFSIZE]; + char * bufin = NULL, + * bufout = NULL; + + + int fin, + fout; + + double start, + end; + + size_t filesize = 0; + + assert(argc == 3); + + start = tstamp(); + + fin = open(argv[1],O_RDONLY); + assert(fin >=0); + + fout = open(argv[2],O_RDWR|O_CREAT|O_TRUNC,0600); + assert(fout >=0); + + filesize = lseek(fin,0,SEEK_END); + ftruncate (fout,filesize); + + bufin = mmap(NULL,filesize,PROT_READ,MAP_PRIVATE,fin,0); + assert(bufin != (void*)-1); + + bufout = mmap(NULL,filesize,PROT_WRITE,MAP_SHARED,fout,0); + + assert(bufout != (void*)-1); + + + memcpy(bufout,bufin,filesize); + + //munmap(bufin,filesize); + //munmap(bufout,filesize); + + //ssize_t nb_read = read(fin,buf,sizeof(buf)); + close(fin); + close(fout); + + end = tstamp(); + + printf("time = %.3lf\n",end - start); + return 0; +}