Changement de disposition
This commit is contained in:
17
TP1/Exo1/ex1bis/Makefile
Normal file
17
TP1/Exo1/ex1bis/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)
|
10
TP1/Exo1/ex1bis/buf.c
Normal file
10
TP1/Exo1/ex1bis/buf.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "helpers.h"
|
||||
|
||||
static char buf1[8 MB] = {0};
|
||||
static char buf2[16 MB] = {0};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
randomize(buf2, 16 MB);
|
||||
return interlude();
|
||||
}
|
BIN
TP1/Exo1/ex1bis/data/256k
Normal file
BIN
TP1/Exo1/ex1bis/data/256k
Normal file
Binary file not shown.
8
TP1/Exo1/ex1bis/heap.c
Normal file
8
TP1/Exo1/ex1bis/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
TP1/Exo1/ex1bis/helpers.c
Normal file
36
TP1/Exo1/ex1bis/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
TP1/Exo1/ex1bis/helpers.h
Normal file
13
TP1/Exo1/ex1bis/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
|
12
TP1/Exo1/ex1bis/huge.c
Normal file
12
TP1/Exo1/ex1bis/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();
|
||||
}
|
38
TP1/Exo1/ex1bis/mmap.c
Normal file
38
TP1/Exo1/ex1bis/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();
|
||||
}
|
6
TP1/Exo1/ex1bis/null.c
Normal file
6
TP1/Exo1/ex1bis/null.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return interlude();
|
||||
}
|
8
TP1/Exo1/ex1bis/stack.c
Normal file
8
TP1/Exo1/ex1bis/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