4 #include "arch.h" // page_size
6 #include "sanitise.h" // get_address
8 #include "log.h" // For BUG
10 static void fabricate_onepage_struct(char *page
)
14 for (i
= 0; i
< page_size
; ) {
17 ptr
= (void*)&page
[i
];
20 i
+= sizeof(unsigned int);
23 *(unsigned int *)ptr
= rand32();
26 i
+= sizeof(unsigned long);
29 *(unsigned long *)ptr
= rand64();
38 i
+= sizeof(unsigned int);
41 *(unsigned int *)ptr
= rand() % page_size
;
47 void generate_random_page(char *page
)
53 /* return a page of complete trash */
55 for (i
= 0; i
< page_size
; )
56 page
[i
++] = (unsigned char)rand();
60 for (i
= 0; i
< (page_size
/ 2); ) {
62 page
[i
++] = (unsigned char)rand();
67 for (i
= 0; i
< (page_size
/ 4); ) {
71 page
[i
++] = (unsigned char)rand();
75 /* return a page that looks kinda like a struct */
76 case 3: fabricate_onepage_struct(page
);
79 /* return a page of unicode nonsense. */
80 case 4: gen_unicode_page(page
);
83 /* page of 0's and 1's. */
85 for (i
= 0; i
< page_size
; )
86 page
[i
++] = (unsigned char)rand_bool();
89 /* page full of format strings. */
91 for (i
= 0; i
< page_size
; ) {
93 switch (rand_bool()) {
94 case 0: page
[i
++] = 'd';
96 case 1: page
[i
++] = 's';
100 page_size
= getpagesize(); // Hack for clang 3.3 false positive.
101 page
[rand() % page_size
] = 0;
104 /* ascii representation of a random number */
106 switch (rand() % 3) {
108 switch (rand() % 3) {
109 case 0: p
= sprintf(page_rand
, "%lu", (unsigned long) rand64());
111 case 1: p
= sprintf(page_rand
, "%ld", (unsigned long) rand64());
113 case 2: p
= sprintf(page_rand
, "%lx", (unsigned long) rand64());
119 switch (rand() % 3) {
120 case 0: p
= sprintf(page_rand
, "%u", (unsigned int) rand64());
122 case 1: p
= sprintf(page_rand
, "%d", (int) rand64());
124 case 2: p
= sprintf(page_rand
, "%x", (int) rand64());
130 switch (rand() % 3) {
131 case 0: p
= sprintf(page_rand
, "%u", (unsigned char) rand64());
133 case 1: p
= sprintf(page_rand
, "%d", (char) rand64());
135 case 2: p
= sprintf(page_rand
, "%x", (char) rand64());