@@ -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,6 +201,22 @@ pub mod guard {
199
201
current ( ) . map ( |s| s as * mut libc:: c_void )
200
202
}
201
203
204
+ #[ cfg( target_os = "freebsd" ) ]
205
+ unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
206
+ let mut ret = None ;
207
+ let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
208
+ assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
209
+ if libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
210
+ let mut stackaddr = :: ptr:: null_mut ( ) ;
211
+ let mut stacksize = 0 ;
212
+ assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
213
+ & mut stacksize) , 0 ) ;
214
+ ret = Some ( stackaddr) ;
215
+ }
216
+ assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
217
+ ret
218
+ }
219
+
202
220
#[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
203
221
unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
204
222
let mut ret = None ;
@@ -248,7 +266,11 @@ pub mod guard {
248
266
panic ! ( "failed to allocate a guard page" ) ;
249
267
}
250
268
251
- let offset = if cfg ! ( target_os = "linux" ) { 2 } else { 1 } ;
269
+ let offset = if cfg ! ( any( target_os = "linux" , target_os = "freebsd" ) ) {
270
+ 2
271
+ } else {
272
+ 1
273
+ } ;
252
274
253
275
Some ( stackaddr as usize + offset * psize)
254
276
}
@@ -282,6 +304,27 @@ pub mod guard {
282
304
} )
283
305
}
284
306
307
+ #[ cfg( target_os = "freebsd" ) ]
308
+ pub unsafe fn current ( ) -> Option < usize > {
309
+ let mut ret = None ;
310
+ let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
311
+ assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
312
+ if libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
313
+ let mut guardsize = 0 ;
314
+ assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
315
+ if guardsize == 0 {
316
+ panic ! ( "there is no guard page" ) ;
317
+ }
318
+ let mut stackaddr = :: ptr:: null_mut ( ) ;
319
+ let mut size = 0 ;
320
+ assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
321
+ & mut size) , 0 ) ;
322
+ ret = Some ( stackaddr as usize - guardsize as usize ) ;
323
+ }
324
+ assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
325
+ ret
326
+ }
327
+
285
328
#[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
286
329
pub unsafe fn current ( ) -> Option < usize > {
287
330
let mut ret = None ;
0 commit comments