@@ -29,7 +29,7 @@ use crate::{mem, ptr};
2929// We can use true weak linkage on ELF targets.
3030#[ cfg( all( unix, not( target_vendor = "apple" ) ) ) ]
3131pub ( crate ) macro weak {
32- ( fn $name: ident( $( $t: ty) , * ) -> $ret: ty) => (
32+ ( fn $name: ident( $( $param : ident : $ t: ty) , * $ ( , ) ? ) -> $ret: ty; ) => (
3333 let ref $name: ExternWeak <unsafe extern "C" fn ( $( $t) , * ) -> $ret> = {
3434 unsafe extern "C" {
3535 #[ linkage = "extern_weak" ]
@@ -62,10 +62,16 @@ impl<F: Copy> ExternWeak<F> {
6262}
6363
6464pub ( crate ) macro dlsym {
65- ( fn $name: ident( $( $t: ty) , * ) -> $ret: ty) => (
66- dlsym ! ( fn $name( $( $t) , * ) -> $ret, stringify!( $name) ) ;
65+ ( fn $name: ident( $( $param: ident : $t: ty) , * $( , ) ?) -> $ret: ty; ) => (
66+ dlsym ! (
67+ #[ link_name = stringify!( $name) ]
68+ fn $name( $( $param : $t) , * ) -> $ret;
69+ ) ;
6770 ) ,
68- ( fn $name: ident( $( $t: ty) , * ) -> $ret: ty, $sym: expr) => (
71+ (
72+ #[ link_name = $sym: expr]
73+ fn $name: ident( $( $param: ident : $t: ty) , * $( , ) ?) -> $ret: ty ;
74+ ) => (
6975 static DLSYM : DlsymWeak < unsafe extern "C" fn ( $( $t) , * ) -> $ret> =
7076 DlsymWeak :: new ( concat ! ( $sym, '\0' ) ) ;
7177 let $name = & DLSYM ;
@@ -143,15 +149,15 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
143149
144150#[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
145151pub ( crate ) macro syscall {
146- ( fn $name: ident( $( $arg_name : ident: $t: ty) , * ) -> $ret: ty) => (
152+ ( fn $name: ident( $( $param : ident : $t: ty) , * $ ( , ) ? ) -> $ret: ty; ) => (
147153 // FIXME(#115199): Rust currently omits weak function definitions
148154 // and its metadata from LLVM IR.
149155 #[ no_sanitize( cfi) ]
150- unsafe fn $name( $( $arg_name : $t) , * ) -> $ret {
151- weak ! { fn $name( $( $t) , * ) -> $ret }
156+ unsafe fn $name( $( $param : $t) , * ) -> $ret {
157+ weak ! ( fn $name( $( $param : $ t) , * ) -> $ret; ) ;
152158
153159 if let Some ( fun) = $name. get ( ) {
154- fun ( $( $arg_name ) , * )
160+ fun ( $( $param ) , * )
155161 } else {
156162 super :: os:: set_errno ( libc:: ENOSYS ) ;
157163 -1
@@ -162,26 +168,28 @@ pub(crate) macro syscall {
162168
163169#[ cfg ( any ( target_os = "linux" , target_os = "android" ) ) ]
164170pub( crate ) macro syscall {
165- ( fn $name: ident( $( $arg_name: ident: $t: ty) , * ) -> $ret: ty) => (
166- unsafe fn $name( $( $arg_name: $t) , * ) -> $ret {
167- weak ! { fn $name( $( $t) , * ) -> $ret }
171+ (
172+ fn $name: ident( $( $param: ident : $t: ty) , * $( , ) ?) -> $ret: ty;
173+ ) => (
174+ unsafe fn $name( $( $param: $t) , * ) -> $ret {
175+ weak ! ( fn $name( $( $param: $t) , * ) -> $ret; ) ;
168176
169177 // Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
170178 // interposition, but if it's not found just use a raw syscall.
171179 if let Some ( fun) = $name. get ( ) {
172- fun ( $( $arg_name ) , * )
180+ fun ( $( $param ) , * )
173181 } else {
174- libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $arg_name ) , * ) as $ret
182+ libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param ) , * ) as $ret
175183 }
176184 }
177185 )
178186}
179187
180188#[ cfg ( any ( target_os = "linux" , target_os = "android" ) ) ]
181189pub( crate ) macro raw_syscall {
182- ( fn $name: ident( $( $arg_name : ident: $t: ty) , * ) -> $ret: ty) => (
183- unsafe fn $name( $( $arg_name : $t) , * ) -> $ret {
184- libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $arg_name ) , * ) as $ret
190+ ( fn $name: ident( $( $param : ident : $t: ty) , * $ ( , ) ? ) -> $ret: ty; ) => (
191+ unsafe fn $name( $( $param : $t) , * ) -> $ret {
192+ libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param ) , * ) as $ret
185193 }
186194 )
187195}
0 commit comments