-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharg.c
65 lines (52 loc) · 1.34 KB
/
arg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "arg.h"
u8 fuzz_arg_u8(fuzz_arg_state_t *state, fuzz_arg_options_t options)
{
return fuzz_arg_u16(state, options) & 0xFF;
}
u16 fuzz_arg_u16(fuzz_arg_state_t *state, fuzz_arg_options_t options)
{
return fuzz_arg_u32(state, options) & 0xFFFF;
}
u32 fuzz_arg_u32(fuzz_arg_state_t *state, fuzz_arg_options_t options)
{
return fuzz_arg_u64(state, options) & 0xFFFFFFFF;
}
#ifndef fuzz_random_func
#include <immintrin.h>
#define fuzz_random_func _rdseed64_step
#else
extern
int fuzz_random_func(unsigned long long *);
#endif
u64 fuzz_arg_u64(fuzz_arg_state_t *state, fuzz_arg_options_t options)
{
u64 rand;
for(; fuzz_random_func(&rand) != 1;);
switch(options.type)
{
case 1: // min, max
{
u64 min, max;
min = options.min_max._64[0];
max = options.min_max._64[1];
return min + (rand % ((max + 1) - min));
}
case 2:
{
u64 ret = state->counter & 0xFFFFFFFFFFFFFFFF;
state->counter += options.step_size;
return ret;
}
case 3:
{
u64 ret = state->counter & 0xFFFFFFFFFFFFFFFF;
state->counter += options.step_size;
return ret % options.min_max._64[0];
}
default:
{
break;
}
}
return rand;
}