4 #include "log.h" // for BUG
8 static unsigned int plus_minus_two(unsigned int num
)
10 /* Now munge it for off-by-ones. */
25 unsigned int get_interesting_32bit_value(void)
29 switch (rand() % 10) {
30 case 0: num
= 0x00000000;
32 case 1: num
= rand() % 256; // 00-0xff
34 case 2: num
= 1 << (rand() % 32); // set a single bit.
36 case 3: num
= 0x8fffffff;
39 num
= num
<< (rand() % 31);
41 case 5: num
= 0xffff0000;
43 case 6: num
= 0xffffe000;
45 case 7: num
= 0xffffff00 | (rand() % 256);
47 case 8: num
= 0xffffffff - page_size
;
49 case 9: num
= 0xffffffff;
53 num
= plus_minus_two(num
);
58 static unsigned long per_arch_interesting_addr(unsigned long low
)
62 #if defined(__x86_64__)
66 case 0: return 0x00007fffffffffffUL
; // x86-64 canonical addr end.
67 case 1: return 0x0000800000000000UL
; // First x86-64 non-canonical addr
68 case 2: return 0xffff800000000000UL
| (low
<< 4); // x86-64 canonical addr range 2 begin
69 case 3: return VDSO_ADDR
| (low
& 0x0fffff);
73 // FIXME: Add more arch specific addresses here.
77 #endif /* __WORDSIZE */
79 unsigned long get_interesting_value(void)
82 return get_interesting_32bit_value();
84 unsigned long low
= 0;
87 low
= get_interesting_32bit_value();
89 switch (rand() % 13) {
92 case 2: return 0x0000000100000000UL
| low
;
93 case 3: return 0x7fffffff00000000UL
| low
;
94 case 4: return 0x8000000000000000UL
| low
;
95 case 5: return 0xffffffff00000000UL
| low
;
96 case 6: return 0xffffffffffffff00UL
| (rand() % 256);
97 case 7: return 0xffffffffffffffffUL
- page_size
;
98 case 8: return PAGE_OFFSET
| (low
<< 4);
99 case 9: return KERNEL_ADDR
| (low
& 0xffffff);
100 case 10: return MODULE_ADDR
| (low
& 0xffffff);
101 case 11: return per_arch_interesting_addr(low
);
102 case 12: return (low
<< 32);
105 return low
; // unreachable, but gcc is dumb.
106 #endif /* __WORDSIZE */