@@ -164,6 +164,7 @@ impl Drop for Thread {
164
164
}
165
165
166
166
#[ cfg( all( not( all( target_os = "linux" , not( target_env = "musl" ) ) ) ,
167
+ not( target_os = "freebsd" ) ,
167
168
not( target_os = "macos" ) ,
168
169
not( target_os = "bitrig" ) ,
169
170
not( all( target_os = "netbsd" , not( target_vendor = "rumprun" ) ) ) ,
@@ -177,6 +178,7 @@ pub mod guard {
177
178
178
179
179
180
#[ cfg( any( all( target_os = "linux" , not( target_env = "musl" ) ) ,
181
+ target_os = "freebsd" ,
180
182
target_os = "macos" ,
181
183
target_os = "bitrig" ,
182
184
all( target_os = "netbsd" , not( target_vendor = "rumprun" ) ) ,
@@ -199,12 +201,17 @@ pub mod guard {
199
201
current ( ) . map ( |s| s as * mut libc:: c_void )
200
202
}
201
203
202
- #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
204
+ #[ cfg( any( target_os = "android" , target_os = "freebsd" ,
205
+ target_os = "linux" , target_os = "netbsd" ) ) ]
203
206
unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
204
207
let mut ret = None ;
205
208
let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
206
209
assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
207
- if libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
210
+ #[ cfg( target_os = "freebsd" ) ]
211
+ let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) ;
212
+ #[ cfg( not( target_os = "freebsd" ) ) ]
213
+ let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) ;
214
+ if e == 0 {
208
215
let mut stackaddr = :: ptr:: null_mut ( ) ;
209
216
let mut stacksize = 0 ;
210
217
assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
@@ -248,7 +255,11 @@ pub mod guard {
248
255
panic ! ( "failed to allocate a guard page" ) ;
249
256
}
250
257
251
- let offset = if cfg ! ( target_os = "linux" ) { 2 } else { 1 } ;
258
+ let offset = if cfg ! ( any( target_os = "linux" , target_os = "freebsd" ) ) {
259
+ 2
260
+ } else {
261
+ 1
262
+ } ;
252
263
253
264
Some ( stackaddr as usize + offset * psize)
254
265
}
@@ -282,12 +293,17 @@ pub mod guard {
282
293
} )
283
294
}
284
295
285
- #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
296
+ #[ cfg( any( target_os = "android" , target_os = "freebsd" ,
297
+ target_os = "linux" , target_os = "netbsd" ) ) ]
286
298
pub unsafe fn current ( ) -> Option < usize > {
287
299
let mut ret = None ;
288
300
let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
289
301
assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
290
- if libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
302
+ #[ cfg( target_os = "freebsd" ) ]
303
+ let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) ;
304
+ #[ cfg( not( target_os = "freebsd" ) ) ]
305
+ let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) ;
306
+ if e == 0 {
291
307
let mut guardsize = 0 ;
292
308
assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
293
309
if guardsize == 0 {
@@ -298,7 +314,9 @@ pub mod guard {
298
314
assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
299
315
& mut size) , 0 ) ;
300
316
301
- ret = if cfg ! ( target_os = "netbsd" ) {
317
+ ret = if cfg ! ( target_os = "freebsd" ) {
318
+ Some ( stackaddr as usize - guardsize as usize )
319
+ } else if cfg ! ( target_os = "netbsd" ) {
302
320
Some ( stackaddr as usize )
303
321
} else {
304
322
Some ( stackaddr as usize + guardsize as usize )
0 commit comments