2020// each instance of `weak!` and `syscall!`. Rather than trying to unify all of
2121// that, we'll just allow that some unix targets don't use this module at all.
2222#![ allow( dead_code, unused_macros) ]
23+ #![ forbid( unsafe_op_in_unsafe_fn) ]
2324
2425use crate :: ffi:: CStr ;
2526use crate :: marker:: PhantomData ;
@@ -131,11 +132,15 @@ impl<F> DlsymWeak<F> {
131132 unsafe fn initialize ( & self ) -> Option < F > {
132133 assert_eq ! ( size_of:: <F >( ) , size_of:: <* mut libc:: c_void>( ) ) ;
133134
134- let val = fetch ( self . name ) ;
135+ let val = unsafe { fetch ( self . name ) } ;
135136 // This synchronizes with the acquire fence in `get`.
136137 self . func . store ( val, Ordering :: Release ) ;
137138
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+ }
139144 }
140145}
141146
@@ -144,7 +149,7 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
144149 Ok ( cstr) => cstr,
145150 Err ( ..) => return ptr:: null_mut ( ) ,
146151 } ;
147- libc:: dlsym ( libc:: RTLD_DEFAULT , name. as_ptr ( ) )
152+ unsafe { libc:: dlsym ( libc:: RTLD_DEFAULT , name. as_ptr ( ) ) }
148153}
149154
150155#[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
@@ -157,7 +162,7 @@ pub(crate) macro syscall {
157162 weak ! ( fn $name( $( $param: $t) , * ) -> $ret; ) ;
158163
159164 if let Some ( fun) = $name. get ( ) {
160- fun ( $( $param) , * )
165+ unsafe { fun ( $( $param) , * ) }
161166 } else {
162167 super :: os:: set_errno ( libc:: ENOSYS ) ;
163168 -1
@@ -177,9 +182,9 @@ pub(crate) macro syscall {
177182 // Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
178183 // interposition, but if it's not found just use a raw syscall.
179184 if let Some ( fun) = $name. get ( ) {
180- fun ( $( $param) , * )
185+ unsafe { fun ( $( $param) , * ) }
181186 } else {
182- libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param) , * ) as $ret
187+ unsafe { libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param) , * ) as $ret }
183188 }
184189 }
185190 )
@@ -189,7 +194,7 @@ pub(crate) macro syscall {
189194pub( crate ) macro raw_syscall {
190195 ( fn $name: ident( $( $param: ident : $t: ty) , * $( , ) ?) -> $ret: ty; ) => (
191196 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 }
193198 }
194199 )
195200}
0 commit comments