2 * SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
3 unsigned long, prot, unsigned long, flags,
4 unsigned long, fd, unsigned long, off)
15 #include "utils.h" //ARRAY_SIZE
24 // need this to actually get MAP_UNINITIALIZED defined
25 #define CONFIG_MMAP_ALLOW_UNINITIALIZED
27 static void do_anon(int childno
)
29 /* no fd if anonymous mapping. */
30 shm
->a5
[childno
] = -1;
34 void sanitise_mmap(int childno
)
37 unsigned int flagvals
[NUM_FLAGS
] = { MAP_FIXED
, MAP_ANONYMOUS
,
38 MAP_GROWSDOWN
, MAP_DENYWRITE
, MAP_EXECUTABLE
, MAP_LOCKED
,
39 MAP_NORESERVE
, MAP_POPULATE
, MAP_NONBLOCK
, MAP_STACK
,
40 MAP_HUGETLB
, MAP_UNINITIALIZED
,
45 unsigned int numflags
= rand() % NUM_FLAGS
;
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. */
57 shm
->a2
[childno
] = sizes
[rand() % ARRAY_SIZE(sizes
)];
59 // set additional flags
60 for (i
= 0; i
< numflags
; i
++)
61 shm
->a4
[childno
] |= flagvals
[rand() % NUM_FLAGS
];
63 if (shm
->a4
[childno
] & MAP_ANONYMOUS
) {
66 /* page align non-anonymous mappings. */
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
];
87 // Add this to a list for use by subsequent syscalls.
88 list
= &shm
->mappings
[childno
]->list
;
89 list_add_tail(&new->list
, list
);
90 shm
->num_mappings
[childno
]++;
92 /* Sometimes dirty the mapping. */
93 if (!(new->prot
& PROT_WRITE
))
97 p
[rand() % page_size
] = 1;
100 struct syscall syscall_mmap
= {
103 .sanitise
= sanitise_mmap
,
105 .arg1type
= ARG_MMAP
,
109 .arg3type
= ARG_LIST
,
112 .values
= { PROT_READ
, PROT_WRITE
, PROT_EXEC
, PROT_SEM
},
118 .values
= { MAP_SHARED
, MAP_PRIVATE
},