20
20
// each instance of `weak!` and `syscall!`. Rather than trying to unify all of
21
21
// that, we'll just allow that some unix targets don't use this module at all.
22
22
#![ allow( dead_code, unused_macros) ]
23
+ #![ forbid( unsafe_op_in_unsafe_fn) ]
23
24
24
25
use crate :: ffi:: CStr ;
25
26
use crate :: marker:: PhantomData ;
@@ -131,11 +132,15 @@ impl<F> DlsymWeak<F> {
131
132
unsafe fn initialize ( & self ) -> Option < F > {
132
133
assert_eq ! ( size_of:: <F >( ) , size_of:: <* mut libc:: c_void>( ) ) ;
133
134
134
- let val = fetch ( self . name ) ;
135
+ let val = unsafe { fetch ( self . name ) } ;
135
136
// This synchronizes with the acquire fence in `get`.
136
137
self . func . store ( val, Ordering :: Release ) ;
137
138
138
- if val. is_null ( ) { None } else { Some ( mem:: transmute_copy :: < * mut libc:: c_void , F > ( & val) ) }
139
+ if val. is_null ( ) {
140
+ None
141
+ } else {
142
+ Some ( unsafe { mem:: transmute_copy :: < * mut libc:: c_void , F > ( & val) } )
143
+ }
139
144
}
140
145
}
141
146
@@ -144,7 +149,7 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
144
149
Ok ( cstr) => cstr,
145
150
Err ( ..) => return ptr:: null_mut ( ) ,
146
151
} ;
147
- libc:: dlsym ( libc:: RTLD_DEFAULT , name. as_ptr ( ) )
152
+ unsafe { libc:: dlsym ( libc:: RTLD_DEFAULT , name. as_ptr ( ) ) }
148
153
}
149
154
150
155
#[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
@@ -157,7 +162,7 @@ pub(crate) macro syscall {
157
162
weak ! ( fn $name( $( $param: $t) , * ) -> $ret; ) ;
158
163
159
164
if let Some ( fun) = $name. get ( ) {
160
- fun ( $( $param) , * )
165
+ unsafe { fun ( $( $param) , * ) }
161
166
} else {
162
167
super :: os:: set_errno ( libc:: ENOSYS ) ;
163
168
-1
@@ -177,9 +182,9 @@ pub(crate) macro syscall {
177
182
// Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
178
183
// interposition, but if it's not found just use a raw syscall.
179
184
if let Some ( fun) = $name. get ( ) {
180
- fun ( $( $param) , * )
185
+ unsafe { fun ( $( $param) , * ) }
181
186
} else {
182
- libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param) , * ) as $ret
187
+ unsafe { libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param) , * ) as $ret }
183
188
}
184
189
}
185
190
)
@@ -189,7 +194,7 @@ pub(crate) macro syscall {
189
194
pub( crate ) macro raw_syscall {
190
195
( fn $name: ident( $( $param: ident : $t: ty) , * $( , ) ?) -> $ret: ty; ) => (
191
196
unsafe fn $name( $( $param: $t) , * ) -> $ret {
192
- libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param) , * ) as $ret
197
+ unsafe { libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param) , * ) as $ret }
193
198
}
194
199
)
195
200
}
0 commit comments