add SCR Part
This commit is contained in:
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