8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- //! C definitions used by libnative that don't belong in liblibc
11
+ //! C definitions used by std::sys that don't belong in liblibc
12
+
13
+ // These are definitions sufficient for the users in this directory.
14
+ // This is not a general-purpose binding to this functionality, and in
15
+ // some cases (notably the definition of siginfo_t), we intentionally
16
+ // have incomplete bindings so that we don't need to fight with unions.
17
+ //
18
+ // Note that these types need to match the definitions from the platform
19
+ // libc (currently glibc on Linux), not the kernel definitions / the
20
+ // syscall interface. This has a few weirdnesses, like glibc's sigset_t
21
+ // being 1024 bits on all platforms. If you're adding a new GNU/Linux
22
+ // port, check glibc's sysdeps/unix/sysv/linux, not the kernel headers.
12
23
13
- #![ allow( dead_code) ]
14
24
#![ allow( non_camel_case_types) ]
15
25
16
- pub use self :: signal:: { sigaction, siginfo, sigset_t} ;
17
- pub use self :: signal:: { SA_ONSTACK , SA_RESTART , SA_RESETHAND , SA_NOCLDSTOP } ;
18
- pub use self :: signal:: { SA_NODEFER , SA_NOCLDWAIT , SA_SIGINFO , SIGCHLD } ;
26
+ pub use self :: signal_os:: { sigaction, siginfo, sigset_t, sigaltstack} ;
27
+ pub use self :: signal_os:: { SA_ONSTACK , SA_SIGINFO , SIGBUS , SIGSTKSZ } ;
19
28
20
29
use libc;
21
30
@@ -97,6 +106,12 @@ pub struct passwd {
97
106
pub pw_shell : * mut libc:: c_char ,
98
107
}
99
108
109
+ // This is really a function pointer (or a union of multiple function
110
+ // pointers), except for constants like SIG_DFL.
111
+ pub type sighandler_t = * mut libc:: c_void ;
112
+
113
+ pub const SIG_DFL : sighandler_t = 0 as sighandler_t ;
114
+
100
115
extern {
101
116
pub fn getsockopt ( sockfd : libc:: c_int ,
102
117
level : libc:: c_int ,
@@ -109,12 +124,16 @@ extern {
109
124
pub fn waitpid ( pid : libc:: pid_t , status : * mut libc:: c_int ,
110
125
options : libc:: c_int ) -> libc:: pid_t ;
111
126
127
+ pub fn signal ( signum : libc:: c_int , handler : sighandler_t ) -> sighandler_t ;
128
+ pub fn raise ( signum : libc:: c_int ) -> libc:: c_int ;
129
+
112
130
pub fn sigaction ( signum : libc:: c_int ,
113
131
act : * const sigaction ,
114
132
oldact : * mut sigaction ) -> libc:: c_int ;
115
133
116
- pub fn sigaddset ( set : * mut sigset_t , signum : libc:: c_int ) -> libc:: c_int ;
117
- pub fn sigdelset ( set : * mut sigset_t , signum : libc:: c_int ) -> libc:: c_int ;
134
+ pub fn sigaltstack ( ss : * const sigaltstack ,
135
+ oss : * mut sigaltstack ) -> libc:: c_int ;
136
+
118
137
pub fn sigemptyset ( set : * mut sigset_t ) -> libc:: c_int ;
119
138
120
139
#[ cfg( not( target_os = "ios" ) ) ]
@@ -133,123 +152,174 @@ extern {
133
152
-> * mut libc:: c_char ;
134
153
}
135
154
136
- #[ cfg( any( all( target_os = "linux" ,
137
- any( target_arch = "x86" ,
138
- target_arch = "x86_64" ,
139
- target_arch = "arm" ,
140
- target_arch = "aarch64" ) ) ,
155
+ #[ cfg( any( target_os = "linux" ,
141
156
target_os = "android" ) ) ]
142
- mod signal {
157
+ mod signal_os {
158
+ pub use self :: arch:: { SA_ONSTACK , SA_SIGINFO , SIGBUS ,
159
+ sigaction, sigaltstack} ;
143
160
use libc;
144
161
145
- pub const SA_NOCLDSTOP : libc:: c_ulong = 0x00000001 ;
146
- pub const SA_NOCLDWAIT : libc:: c_ulong = 0x00000002 ;
147
- pub const SA_NODEFER : libc:: c_ulong = 0x40000000 ;
148
- pub const SA_ONSTACK : libc:: c_ulong = 0x08000000 ;
149
- pub const SA_RESETHAND : libc:: c_ulong = 0x80000000 ;
150
- pub const SA_RESTART : libc:: c_ulong = 0x10000000 ;
151
- pub const SA_SIGINFO : libc:: c_ulong = 0x00000004 ;
152
- pub const SIGCHLD : libc:: c_int = 17 ;
153
-
154
- // This definition is not as accurate as it could be, {pid, uid, status} is
155
- // actually a giant union. Currently we're only interested in these fields,
156
- // however.
162
+ #[ cfg( any( target_arch = "x86" ,
163
+ target_arch = "x86_64" ,
164
+ target_arch = "arm" ,
165
+ target_arch = "mips" ,
166
+ target_arch = "mipsel" ) ) ]
167
+ pub const SIGSTKSZ : libc:: size_t = 8192 ;
168
+
169
+ // This is smaller on musl and Android, but no harm in being generous.
170
+ #[ cfg( any( target_arch = "aarch64" ,
171
+ target_arch = "powerpc" ) ) ]
172
+ pub const SIGSTKSZ : libc:: size_t = 16384 ;
173
+
174
+ // This definition is intentionally a subset of the C structure: the
175
+ // fields after si_code are actually a giant union. We're only
176
+ // interested in si_addr for this module, though.
157
177
#[ repr( C ) ]
158
178
pub struct siginfo {
159
- si_signo : libc:: c_int ,
160
- si_errno : libc:: c_int ,
161
- si_code : libc:: c_int ,
162
- pub pid : libc:: pid_t ,
163
- pub uid : libc:: uid_t ,
164
- pub status : libc:: c_int ,
179
+ _signo : libc:: c_int ,
180
+ _errno : libc:: c_int ,
181
+ _code : libc:: c_int ,
182
+ // This structure will need extra padding here for MIPS64.
183
+ pub si_addr : * mut libc:: c_void
165
184
}
166
185
186
+ #[ cfg( all( target_os = "linux" , target_pointer_width = "32" ) ) ]
167
187
#[ repr( C ) ]
168
- pub struct sigaction {
169
- pub sa_handler : extern fn ( libc:: c_int ) ,
170
- pub sa_mask : sigset_t ,
171
- pub sa_flags : libc:: c_ulong ,
172
- sa_restorer : * mut libc:: c_void ,
173
- }
174
-
175
- unsafe impl :: marker:: Send for sigaction { }
176
- unsafe impl :: marker:: Sync for sigaction { }
177
-
178
- #[ repr( C ) ]
179
- #[ cfg( target_pointer_width = "32" ) ]
180
188
pub struct sigset_t {
181
189
__val : [ libc:: c_ulong ; 32 ] ,
182
190
}
183
191
192
+ #[ cfg( all( target_os = "linux" , target_pointer_width = "64" ) ) ]
184
193
#[ repr( C ) ]
185
- #[ cfg( target_pointer_width = "64" ) ]
186
194
pub struct sigset_t {
187
195
__val : [ libc:: c_ulong ; 16 ] ,
188
196
}
189
- }
190
197
191
- #[ cfg( all( target_os = "linux" ,
192
- any( target_arch = "mips" ,
193
- target_arch = "mipsel" ,
194
- target_arch = "powerpc" ) ) ) ]
195
- mod signal {
196
- use libc;
197
-
198
- pub const SA_NOCLDSTOP : libc:: c_ulong = 0x00000001 ;
199
- pub const SA_NOCLDWAIT : libc:: c_ulong = 0x00010000 ;
200
- pub const SA_NODEFER : libc:: c_ulong = 0x40000000 ;
201
- pub const SA_ONSTACK : libc:: c_ulong = 0x08000000 ;
202
- pub const SA_RESETHAND : libc:: c_ulong = 0x80000000 ;
203
- pub const SA_RESTART : libc:: c_ulong = 0x10000000 ;
204
- pub const SA_SIGINFO : libc:: c_ulong = 0x00000008 ;
205
- pub const SIGCHLD : libc:: c_int = 18 ;
206
-
207
- // This definition is not as accurate as it could be, {pid, uid, status} is
208
- // actually a giant union. Currently we're only interested in these fields,
209
- // however.
210
- #[ repr( C ) ]
211
- pub struct siginfo {
212
- si_signo : libc:: c_int ,
213
- si_code : libc:: c_int ,
214
- si_errno : libc:: c_int ,
215
- pub pid : libc:: pid_t ,
216
- pub uid : libc:: uid_t ,
217
- pub status : libc:: c_int ,
198
+ // Android for MIPS has a 128-bit sigset_t, but we don't currently
199
+ // support it. Android for AArch64 technically has a structure of a
200
+ // single ulong.
201
+ #[ cfg( target_os = "android" ) ]
202
+ pub type sigset_t = libc:: ulong ;
203
+
204
+ #[ cfg( any( target_arch = "x86" ,
205
+ target_arch = "x86_64" ,
206
+ target_arch = "powerpc" ,
207
+ target_arch = "arm" ,
208
+ target_arch = "aarch64" ) ) ]
209
+ mod arch {
210
+ use libc;
211
+ use super :: super :: sighandler_t;
212
+ use super :: sigset_t;
213
+
214
+ pub const SA_ONSTACK : libc:: c_ulong = 0x08000000 ;
215
+ pub const SA_SIGINFO : libc:: c_ulong = 0x00000004 ;
216
+
217
+ pub const SIGBUS : libc:: c_int = 7 ;
218
+
219
+ #[ cfg( target_os = "linux" ) ]
220
+ #[ repr( C ) ]
221
+ pub struct sigaction {
222
+ pub sa_sigaction : sighandler_t ,
223
+ pub sa_mask : sigset_t ,
224
+ pub sa_flags : libc:: c_ulong ,
225
+ _restorer : * mut libc:: c_void ,
226
+ }
227
+
228
+ #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
229
+ #[ repr( C ) ]
230
+ pub struct sigaction {
231
+ pub sa_sigaction : sighandler_t ,
232
+ pub sa_flags : libc:: c_ulong ,
233
+ _restorer : * mut libc:: c_void ,
234
+ pub sa_mask : sigset_t ,
235
+ }
236
+
237
+ #[ cfg( all( target_os = "android" , target_pointer_width = "64" ) ) ]
238
+ #[ repr( C ) ]
239
+ pub struct sigaction {
240
+ pub sa_flags : libc:: c_uint ,
241
+ pub sa_sigaction : sighandler_t ,
242
+ pub sa_mask : sigset_t ,
243
+ _restorer : * mut libc:: c_void ,
244
+ }
245
+
246
+ #[ repr( C ) ]
247
+ pub struct sigaltstack {
248
+ pub ss_sp : * mut libc:: c_void ,
249
+ pub ss_flags : libc:: c_int ,
250
+ pub ss_size : libc:: size_t
251
+ }
218
252
}
219
253
220
- #[ repr( C ) ]
221
- pub struct sigaction {
222
- pub sa_flags : libc:: c_uint ,
223
- pub sa_handler : extern fn ( libc:: c_int ) ,
224
- pub sa_mask : sigset_t ,
225
- sa_restorer : * mut libc:: c_void ,
226
- sa_resv : [ libc:: c_int ; 1 ] ,
227
- }
228
-
229
- unsafe impl :: marker:: Send for sigaction { }
230
- unsafe impl :: marker:: Sync for sigaction { }
231
-
232
- #[ repr( C ) ]
233
- pub struct sigset_t {
234
- __val : [ libc:: c_ulong ; 32 ] ,
254
+ #[ cfg( any( target_arch = "mips" ,
255
+ target_arch = "mipsel" ) ) ]
256
+ mod arch {
257
+ use libc;
258
+ use super :: super :: sighandler_t;
259
+ use super :: sigset_t;
260
+
261
+ pub const SA_ONSTACK : libc:: c_ulong = 0x08000000 ;
262
+ pub const SA_SIGINFO : libc:: c_ulong = 0x00000008 ;
263
+
264
+ pub const SIGBUS : libc:: c_int = 10 ;
265
+
266
+ #[ cfg( all( target_os = "linux" , not( target_env = "musl" ) ) ) ]
267
+ #[ repr( C ) ]
268
+ pub struct sigaction {
269
+ pub sa_flags : libc:: c_uint ,
270
+ pub sa_sigaction : sighandler_t ,
271
+ pub sa_mask : sigset_t ,
272
+ _restorer : * mut libc:: c_void ,
273
+ _resv : [ libc:: c_int ; 1 ] ,
274
+ }
275
+
276
+ #[ cfg( target_env = "musl" ) ]
277
+ #[ repr( C ) ]
278
+ pub struct sigaction {
279
+ pub sa_sigaction : sighandler_t ,
280
+ pub sa_mask : sigset_t ,
281
+ pub sa_flags : libc:: c_ulong ,
282
+ _restorer : * mut libc:: c_void ,
283
+ }
284
+
285
+ #[ cfg( target_os = "android" ) ]
286
+ #[ repr( C ) ]
287
+ pub struct sigaction {
288
+ pub sa_flags : libc:: c_uint ,
289
+ pub sa_sigaction : sighandler_t ,
290
+ pub sa_mask : sigset_t ,
291
+ }
292
+
293
+ #[ repr( C ) ]
294
+ pub struct sigaltstack {
295
+ pub ss_sp : * mut libc:: c_void ,
296
+ pub ss_size : libc:: size_t ,
297
+ pub ss_flags : libc:: c_int ,
298
+ }
235
299
}
236
300
}
237
301
238
302
#[ cfg( any( target_os = "macos" ,
239
303
target_os = "ios" ,
240
304
target_os = "freebsd" ,
241
- target_os = "dragonfly" ) ) ]
242
- mod signal {
305
+ target_os = "dragonfly" ,
306
+ target_os = "bitrig" ,
307
+ target_os = "openbsd" ) ) ]
308
+ mod signal_os {
243
309
use libc;
310
+ use super :: sighandler_t;
244
311
245
312
pub const SA_ONSTACK : libc:: c_int = 0x0001 ;
246
- pub const SA_RESTART : libc:: c_int = 0x0002 ;
247
- pub const SA_RESETHAND : libc:: c_int = 0x0004 ;
248
- pub const SA_NOCLDSTOP : libc:: c_int = 0x0008 ;
249
- pub const SA_NODEFER : libc:: c_int = 0x0010 ;
250
- pub const SA_NOCLDWAIT : libc:: c_int = 0x0020 ;
251
313
pub const SA_SIGINFO : libc:: c_int = 0x0040 ;
252
- pub const SIGCHLD : libc:: c_int = 20 ;
314
+
315
+ pub const SIGBUS : libc:: c_int = 10 ;
316
+
317
+ #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
318
+ pub const SIGSTKSZ : libc:: size_t = 131072 ;
319
+ // FreeBSD's is actually arch-dependent, but never more than 40960.
320
+ // No harm in being generous.
321
+ #[ cfg( not( any( target_os = "macos" , target_os = "ios" ) ) ) ]
322
+ pub const SIGSTKSZ : libc:: size_t = 40960 ;
253
323
254
324
#[ cfg( any( target_os = "macos" ,
255
325
target_os = "ios" ) ) ]
@@ -259,61 +329,53 @@ mod signal {
259
329
pub struct sigset_t {
260
330
bits : [ u32 ; 4 ] ,
261
331
}
332
+ #[ cfg( any( target_os = "bitrig" , target_os = "openbsd" ) ) ]
333
+ pub type sigset_t = libc:: c_uint ;
262
334
263
335
// This structure has more fields, but we're not all that interested in
264
336
// them.
337
+ #[ cfg( any( target_os = "macos" , target_os = "ios" ,
338
+ target_os = "freebsd" , target_os = "dragonfly" ) ) ]
339
+ #[ repr( C ) ]
340
+ pub struct siginfo {
341
+ pub _signo : libc:: c_int ,
342
+ pub _errno : libc:: c_int ,
343
+ pub _code : libc:: c_int ,
344
+ pub _pid : libc:: pid_t ,
345
+ pub _uid : libc:: uid_t ,
346
+ pub _status : libc:: c_int ,
347
+ pub si_addr : * mut libc:: c_void
348
+ }
349
+ #[ cfg( any( target_os = "bitrig" , target_os = "openbsd" ) ) ]
265
350
#[ repr( C ) ]
266
351
pub struct siginfo {
267
352
pub si_signo : libc:: c_int ,
268
- pub si_errno : libc:: c_int ,
269
353
pub si_code : libc:: c_int ,
270
- pub pid : libc:: pid_t ,
271
- pub uid : libc:: uid_t ,
272
- pub status : libc:: c_int ,
354
+ pub si_errno : libc:: c_int ,
355
+ pub si_addr : * mut libc:: c_void
273
356
}
274
357
358
+ #[ cfg( any( target_os = "macos" , target_os = "ios" ,
359
+ target_os = "bitrig" , target_os = "openbsd" ) ) ]
275
360
#[ repr( C ) ]
276
361
pub struct sigaction {
277
- pub sa_handler : extern fn ( libc:: c_int ) ,
278
- pub sa_flags : libc:: c_int ,
362
+ pub sa_sigaction : sighandler_t ,
279
363
pub sa_mask : sigset_t ,
364
+ pub sa_flags : libc:: c_int ,
280
365
}
281
- }
282
-
283
- #[ cfg( any( target_os = "bitrig" , target_os = "openbsd" ) ) ]
284
- mod signal {
285
- use libc;
286
366
287
- pub const SA_ONSTACK : libc:: c_int = 0x0001 ;
288
- pub const SA_RESTART : libc:: c_int = 0x0002 ;
289
- pub const SA_RESETHAND : libc:: c_int = 0x0004 ;
290
- pub const SA_NOCLDSTOP : libc:: c_int = 0x0008 ;
291
- pub const SA_NODEFER : libc:: c_int = 0x0010 ;
292
- pub const SA_NOCLDWAIT : libc:: c_int = 0x0020 ;
293
- pub const SA_SIGINFO : libc:: c_int = 0x0040 ;
294
- pub const SIGCHLD : libc:: c_int = 20 ;
295
-
296
- pub type sigset_t = libc:: c_uint ;
297
-
298
- // This structure has more fields, but we're not all that interested in
299
- // them.
367
+ #[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" ) ) ]
300
368
#[ repr( C ) ]
301
- pub struct siginfo {
302
- pub si_signo : libc:: c_int ,
303
- pub si_code : libc:: c_int ,
304
- pub si_errno : libc:: c_int ,
305
- // FIXME: Bitrig has a crazy union here in the siginfo, I think this
306
- // layout will still work tho. The status might be off by the size of
307
- // a clock_t by my reading, but we can fix this later.
308
- pub pid : libc:: pid_t ,
309
- pub uid : libc:: uid_t ,
310
- pub status : libc:: c_int ,
369
+ pub struct sigaction {
370
+ pub sa_sigaction : sighandler_t ,
371
+ pub sa_flags : libc:: c_int ,
372
+ pub sa_mask : sigset_t ,
311
373
}
312
374
313
375
#[ repr( C ) ]
314
- pub struct sigaction {
315
- pub sa_handler : extern fn ( libc:: c_int ) ,
316
- pub sa_mask : sigset_t ,
317
- pub sa_flags : libc:: c_int ,
376
+ pub struct sigaltstack {
377
+ pub ss_sp : * mut libc:: c_void ,
378
+ pub ss_size : libc :: size_t ,
379
+ pub ss_flags : libc:: c_int ,
318
380
}
319
381
}
0 commit comments