7
7
8
8
use std:: env;
9
9
use std:: io:: { self , Read } ;
10
+ use std:: os:: raw:: c_char;
10
11
use std:: panic;
11
12
12
13
// those functions are provided by the afl-compiler-rt static library
@@ -28,7 +29,7 @@ unsafe extern "C" {
28
29
pub fn ijon_reset_state ( ) ;
29
30
pub fn ijon_simple_hash ( x : u64 ) -> u64 ;
30
31
pub fn ijon_hashint ( old : u32 , val : u32 ) -> u32 ;
31
- pub fn ijon_hashstr ( old : u32 , val : * const u8 ) -> u32 ;
32
+ pub fn ijon_hashstr ( old : u32 , val : * const c_char ) -> u32 ;
32
33
pub fn ijon_hashmen ( old : u32 , val : * const u8 , len : usize ) -> u32 ;
33
34
pub fn ijon_hashstack_backtrace ( ) -> u32 ;
34
35
pub fn ijon_hashstack ( ) -> u32 ;
@@ -45,11 +46,12 @@ macro_rules! ijon_inc {
45
46
static LOC_CACHE : AtomicU32 = AtomicU32 :: new( 0 ) ;
46
47
let mut loc = LOC_CACHE . load( Ordering :: Relaxed ) ;
47
48
if loc == 0 {
48
- let new_val = ijon_hashstr( line!( ) , file!( ) ) ;
49
+ let cfile = CString :: new( file!( ) ) . unwrap( ) ;
50
+ let new_val = unsafe { ijon_hashstr( line!( ) , cfile. as_ptr( ) ) } ;
49
51
LOC_CACHE . store( new_val, Ordering :: Relaxed ) ;
50
52
loc = new_val;
51
53
}
52
- ijon_inc( loc, $x) ;
54
+ unsafe { ijon_inc( loc, $x) } ;
53
55
} } ;
54
56
}
55
57
@@ -60,11 +62,12 @@ macro_rules! ijon_max {
60
62
static LOC_CACHE : AtomicU32 = AtomicU32 :: new( 0 ) ;
61
63
let mut loc = LOC_CACHE . load( Ordering :: Relaxed ) ;
62
64
if loc == 0 {
63
- let new_val = ijon_hashstr( line!( ) , file!( ) ) ;
65
+ let cfile = CString :: new( file!( ) ) . unwrap( ) ;
66
+ let new_val = unsafe { ijon_hashstr( line!( ) , cfile. as_ptr( ) ) } ;
64
67
LOC_CACHE . store( new_val, Ordering :: Relaxed ) ;
65
68
loc = new_val;
66
69
}
67
- ijon_max_variadic( loc, $( $x) ,+, 0u64 ) ;
70
+ unsafe { ijon_max_variadic( loc, $( $x) ,+, 0u64 ) } ;
68
71
} } ;
69
72
}
70
73
@@ -75,11 +78,12 @@ macro_rules! ijon_min {
75
78
static LOC_CACHE : AtomicU32 = AtomicU32 :: new( 0 ) ;
76
79
let mut loc = LOC_CACHE . load( Ordering :: Relaxed ) ;
77
80
if loc == 0 {
78
- let new_val = ijon_hashstr( line!( ) , file!( ) ) ;
81
+ let cfile = CString :: new( file!( ) ) . unwrap( ) ;
82
+ let new_val = unsafe { ijon_hashstr( line!( ) , cfile. as_ptr( ) ) } ;
79
83
LOC_CACHE . store( new_val, Ordering :: Relaxed ) ;
80
84
loc = new_val;
81
85
}
82
- ijon_min_variadic( loc, $( $x) ,+, 0u64 ) ;
86
+ unsafe { ijon_min_variadic( loc, $( $x) ,+, 0u64 ) } ;
83
87
} } ;
84
88
}
85
89
@@ -90,43 +94,45 @@ macro_rules! ijon_set {
90
94
static LOC_CACHE : AtomicU32 = AtomicU32 :: new( 0 ) ;
91
95
let mut loc = LOC_CACHE . load( Ordering :: Relaxed ) ;
92
96
if loc == 0 {
93
- let new_val = ijon_hashstr( line!( ) , file!( ) ) ;
97
+ let cfile = CString :: new( file!( ) ) . unwrap( ) ;
98
+ let new_val = unsafe { ijon_hashstr( line!( ) , cfile. as_ptr( ) ) } ;
94
99
LOC_CACHE . store( new_val, Ordering :: Relaxed ) ;
95
100
loc = new_val;
96
101
}
97
- ijon_set( loc, $x) ;
102
+ unsafe { ijon_set( loc, $x) } ;
98
103
} } ;
99
104
}
100
105
101
106
#[ macro_export]
102
107
macro_rules! ijon_state {
103
108
( $n: expr) => {
104
- ijon_xor_state( $n)
109
+ unsafe { ijon_xor_state( $n) }
105
110
} ;
106
111
}
107
112
108
113
#[ macro_export]
109
114
macro_rules! ijon_ctx {
110
115
( $x: expr) => { {
111
- let hash = ijon_hashstr( line!( ) , file!( ) ) ;
112
- ijon_xor_state( hash) ;
116
+ let cfile = CString :: new( file!( ) ) . unwrap( ) ;
117
+ let hash = unsafe { ijon_hashstr( line!( ) , cfile. as_ptr( ) ) } ;
118
+ unsafe { ijon_xor_state( hash) } ;
113
119
let temp = $x;
114
- ijon_xor_state( hash) ;
120
+ unsafe { ijon_xor_state( hash) } ;
115
121
temp
116
122
} } ;
117
123
}
118
124
119
125
#[ macro_export]
120
126
macro_rules! ijon_max_at {
121
127
( $addr: expr, $x: expr) => {
122
- ijon_max( $addr, $x)
128
+ unsafe { ijon_max( $addr, $x) }
123
129
} ;
124
130
}
125
131
126
132
#[ macro_export]
127
133
macro_rules! ijon_min_at {
128
134
( $addr: expr, $x: expr) => {
129
- ijon_min( $addr, $x)
135
+ unsafe { ijon_min( $addr, $x) }
130
136
} ;
131
137
}
132
138
@@ -140,38 +146,42 @@ macro_rules! _ijon_abs_dist {
140
146
#[ macro_export]
141
147
macro_rules! ijon_bits {
142
148
( $x: expr) => {
143
- ijon_set( ijon_hashint(
144
- ijon_hashstack( ) ,
145
- if $x == 0 {
146
- 0
147
- } else {
148
- $x. leading_zeros( ) as u32
149
- } ,
150
- ) )
149
+ unsafe {
150
+ ijon_set( ijon_hashint(
151
+ ijon_hashstack( ) ,
152
+ if $x == 0 {
153
+ 0
154
+ } else {
155
+ $x. leading_zeros( ) as u32
156
+ } ,
157
+ ) )
158
+ }
151
159
} ;
152
160
}
153
161
154
162
#[ macro_export]
155
163
macro_rules! ijon_strdist {
156
164
( $x: expr, $y: expr) => {
157
- ijon_set( ijon_hashint( ijon_hashstack( ) , ijon_strdist( $x, $y) ) )
165
+ unsafe { ijon_set( ijon_hashint( ijon_hashstack( ) , ijon_strdist( $x, $y) ) ) }
158
166
} ;
159
167
}
160
168
161
169
#[ macro_export]
162
170
macro_rules! ijon_dist {
163
171
( $x: expr, $y: expr) => {
164
- ijon_set( ijon_hashint(
165
- ijon_hashstack( ) ,
166
- $crate:: _ijon_abs_dist!( $x, $y) ,
167
- ) )
172
+ unsafe {
173
+ ijon_set( ijon_hashint(
174
+ ijon_hashstack( ) ,
175
+ $crate:: _ijon_abs_dist!( $x, $y) ,
176
+ ) )
177
+ }
168
178
} ;
169
179
}
170
180
171
181
#[ macro_export]
172
182
macro_rules! ijon_cmp {
173
183
( $x: expr, $y: expr) => {
174
- ijon_inc( ijon_hashint( ijon_hashstack( ) , ( $x ^ $y) . count_ones( ) ) )
184
+ unsafe { ijon_inc( ijon_hashint( ijon_hashstack( ) , ( $x ^ $y) . count_ones( ) ) ) }
175
185
} ;
176
186
}
177
187
@@ -182,11 +192,12 @@ macro_rules! ijon_stack_max {
182
192
static LOC : AtomicU32 = AtomicU32 :: new( 0 ) ;
183
193
let mut loc = LOC . load( Ordering :: Relaxed ) ;
184
194
if loc == 0 {
185
- let new_val = ijon_hashstr( line!( ) , file!( ) ) ;
195
+ let cfile = CString :: new( file!( ) ) . unwrap( ) ;
196
+ let new_val = unsafe { ijon_hashstr( line!( ) , cfile. as_ptr( ) ) } ;
186
197
LOC . store( new_val, Ordering :: Relaxed ) ;
187
198
loc = new_val;
188
199
}
189
- ijon_max( ijon_hashint( loc, ijon_hashstack( ) ) , $x) ;
200
+ unsafe { ijon_max( ijon_hashint( loc, ijon_hashstack( ) ) , $x) } ;
190
201
} } ;
191
202
}
192
203
@@ -197,11 +208,12 @@ macro_rules! ijon_stack_min {
197
208
static LOC : AtomicU32 = AtomicU32 :: new( 0 ) ;
198
209
let mut loc = LOC . load( Ordering :: Relaxed ) ;
199
210
if loc == 0 {
200
- let new_val = ijon_hashstr( line!( ) , file!( ) ) ;
211
+ let cfile = CString :: new( file!( ) ) . unwrap( ) ;
212
+ let new_val = unsafe { ijon_hashstr( line!( ) , cfile. as_ptr( ) ) } ;
201
213
LOC . store( new_val, Ordering :: Relaxed ) ;
202
214
loc = new_val;
203
215
}
204
- ijon_min( ijon_hashint( loc, ijon_hashstack( ) ) , $x) ;
216
+ unsafe { ijon_min( ijon_hashint( loc, ijon_hashstack( ) ) , $x) } ;
205
217
} } ;
206
218
}
207
219
0 commit comments