11 * Routine to perform various kinds of write operations to a mapping
14 void dirty_mapping(struct map
*map
)
18 unsigned int num_pages
= map
->size
/ page_size
;
20 /* Check mapping is writable, or we'll segv.
21 * TODO: Perhaps we should do that, and trap it, mark it writable,
22 * then reprotect after we dirtied it ? */
23 if (!(map
->prot
& PROT_WRITE
))
28 /* Just fault in one page. */
29 p
[rand() % map
->size
] = rand();
33 /* fault in the whole mapping. */
34 for (i
= 0; i
< map
->size
; i
+= page_size
)
39 /* every other page. */
40 for (i
= 0; i
< map
->size
; i
+= (page_size
* 2))
45 /* whole mapping in reverse */
46 for (i
= (map
->size
- page_size
); i
> 0; i
-= page_size
)
51 /* fault in a random set of map->size pages. (some may be faulted >once) */
52 for (i
= 0; i
< num_pages
; i
++)
53 p
[(rand() % (num_pages
+ 1)) * page_size
] = rand();
57 /* fault in the last page in a mapping
58 * Fill it with ascii, in the hope we do something like
59 * a strlen and go off the end. */
60 memset((void *) p
+ (map
->size
- page_size
), 'A', page_size
);