@@ -29,7 +29,7 @@ use crate::{mem, ptr};
29
29
// We can use true weak linkage on ELF targets.
30
30
#[ cfg( all( unix, not( target_vendor = "apple" ) ) ) ]
31
31
pub ( crate ) macro weak {
32
- ( fn $name: ident( $( $t: ty) , * ) -> $ret: ty) => (
32
+ ( fn $name: ident( $( $param : ident : $ t: ty) , * $ ( , ) ? ) -> $ret: ty; ) => (
33
33
let ref $name: ExternWeak <unsafe extern "C" fn ( $( $t) , * ) -> $ret> = {
34
34
unsafe extern "C" {
35
35
#[ linkage = "extern_weak" ]
@@ -62,10 +62,16 @@ impl<F: Copy> ExternWeak<F> {
62
62
}
63
63
64
64
pub ( 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
+ ) ;
67
70
) ,
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
+ ) => (
69
75
static DLSYM : DlsymWeak < unsafe extern "C" fn ( $( $t) , * ) -> $ret> =
70
76
DlsymWeak :: new ( concat ! ( $sym, '\0' ) ) ;
71
77
let $name = & DLSYM ;
@@ -143,15 +149,15 @@ unsafe fn fetch(name: &str) -> *mut libc::c_void {
143
149
144
150
#[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
145
151
pub ( crate ) macro syscall {
146
- ( fn $name: ident( $( $arg_name : ident: $t: ty) , * ) -> $ret: ty) => (
152
+ ( fn $name: ident( $( $param : ident : $t: ty) , * $ ( , ) ? ) -> $ret: ty; ) => (
147
153
// FIXME(#115199): Rust currently omits weak function definitions
148
154
// and its metadata from LLVM IR.
149
155
#[ 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; ) ;
152
158
153
159
if let Some ( fun) = $name. get ( ) {
154
- fun ( $( $arg_name ) , * )
160
+ fun ( $( $param ) , * )
155
161
} else {
156
162
super :: os:: set_errno ( libc:: ENOSYS ) ;
157
163
-1
@@ -162,26 +168,28 @@ pub(crate) macro syscall {
162
168
163
169
#[ cfg ( any ( target_os = "linux" , target_os = "android" ) ) ]
164
170
pub( 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; ) ;
168
176
169
177
// Use a weak symbol from libc when possible, allowing `LD_PRELOAD`
170
178
// interposition, but if it's not found just use a raw syscall.
171
179
if let Some ( fun) = $name. get ( ) {
172
- fun ( $( $arg_name ) , * )
180
+ fun ( $( $param ) , * )
173
181
} else {
174
- libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $arg_name ) , * ) as $ret
182
+ libc:: syscall ( libc:: ${ concat ( SYS_ , $name) } , $( $param ) , * ) as $ret
175
183
}
176
184
}
177
185
)
178
186
}
179
187
180
188
#[ cfg ( any ( target_os = "linux" , target_os = "android" ) ) ]
181
189
pub( 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
185
193
}
186
194
)
187
195
}
0 commit comments