4
4
unsigned long, fd, unsigned long, off)
8
#include "trinity.h" // page_size
9
10
#include "sanitise.h"
12
13
#include "compat.h"
15
#include "utils.h" //ARRAY_SIZE
14
21
#define NUM_FLAGS 12
16
24
// need this to actually get MAP_UNINITIALIZED defined
17
25
#define CONFIG_MMAP_ALLOW_UNINITIALIZED
27
static void do_anon(int childno)
29
/* no fd if anonymous mapping. */
30
shm->a5[childno] = -1;
19
34
void sanitise_mmap(int childno)
22
37
unsigned int flagvals[NUM_FLAGS] = { MAP_FIXED, MAP_ANONYMOUS,
23
MAP_GROWSDOWN, MAP_DENYWRITE, MAP_EXECUTABLE, MAP_LOCKED,
24
MAP_NORESERVE, MAP_POPULATE, MAP_NONBLOCK, MAP_STACK,
25
MAP_HUGETLB, MAP_UNINITIALIZED };
38
MAP_GROWSDOWN, MAP_DENYWRITE, MAP_EXECUTABLE, MAP_LOCKED,
39
MAP_NORESERVE, MAP_POPULATE, MAP_NONBLOCK, MAP_STACK,
40
MAP_HUGETLB, MAP_UNINITIALIZED,
26
45
unsigned int numflags = rand() % NUM_FLAGS;
28
/* Don't actually set a hint right now, in case we give out
29
something that we don't want changed. One day, we'll recycle
30
mappings from mmap results and the like here instead.
31
Right now, ARG_ADDRESS is a bad choice, as it causes page_rand()
32
to be remapped as unwritable/unreadable, and then we segfault */
46
unsigned long sizes[] = {
47
-1, /* over-written with page_size below */
48
1 * MB, 2 * MB, 4 * MB, 10 * MB,
54
/* Don't actually set a hint right now. */
33
55
shm->a1[childno] = 0;
35
shm->a2[childno] = page_size;
36
if (shm->a2[childno] == 0)
37
shm->a2[childno] = page_size;
57
shm->a2[childno] = sizes[rand() % ARRAY_SIZE(sizes)];
40
59
// set additional flags
41
60
for (i = 0; i < numflags; i++)
42
61
shm->a4[childno] |= flagvals[rand() % NUM_FLAGS];
44
/* no fd if anonymous mapping. */
45
if (shm->a4[childno] & MAP_ANONYMOUS)
46
shm->a5[childno] = -1;
48
/* page align non-anonymous mappings. */
49
if (shm->a4[childno] & MAP_ANONYMOUS)
63
if (shm->a4[childno] & MAP_ANONYMOUS) {
66
/* page align non-anonymous mappings. */
50
67
shm->a6[childno] &= PAGE_MASK;
71
static void post_mmap(int childno)
74
struct list_head *list;
77
p = (void *) shm->retval[childno];
81
new = zmalloc(sizeof(struct map));
82
new->name = strdup("misc");
83
new->size = shm->a2[childno];
84
new->prot = shm->a3[childno];
86
new->type = MAP_LOCAL;
88
// Add this to a list for use by subsequent syscalls.
89
list = &shm->mappings[childno]->list;
90
list_add_tail(&new->list, list);
91
shm->num_mappings[childno]++;
93
/* Sometimes dirty the mapping. */
56
98
struct syscall syscall_mmap = {