@@ -227,19 +227,16 @@ pub unsafe fn create(stack: usize, p: Thunk) -> io::Result<rust_thread> {
227
227
228
228
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
229
229
pub unsafe fn set_name ( name : & str ) {
230
- // pthread_setname_np() since glibc 2.12
231
- // availability autodetected via weak linkage
232
- type F = unsafe extern fn ( libc:: pthread_t , * const libc:: c_char )
233
- -> libc:: c_int ;
230
+ // pthread wrapper only appeared in glibc 2.12, so we use syscall directly.
234
231
extern {
235
- #[ linkage = "extern_weak" ]
236
- static pthread_setname_np: * const ( ) ;
237
- }
238
- if !pthread_setname_np. is_null ( ) {
239
- let cname = CString :: new ( name) . unwrap ( ) ;
240
- mem:: transmute :: < * const ( ) , F > ( pthread_setname_np) ( pthread_self ( ) ,
241
- cname. as_ptr ( ) ) ;
232
+ fn prctl ( option : libc:: c_int , arg2 : libc:: c_ulong , arg3 : libc:: c_ulong ,
233
+ arg4 : libc:: c_ulong , arg5 : libc:: c_ulong ) -> libc:: c_int ;
242
234
}
235
+ const PR_SET_NAME : libc:: c_int = 15 ;
236
+ let cname = CString :: new ( name) . unwrap_or_else ( |_| {
237
+ panic ! ( "thread name may not contain interior null bytes" )
238
+ } ) ;
239
+ prctl ( PR_SET_NAME , cname. as_ptr ( ) as libc:: c_ulong , 0 , 0 , 0 ) ;
243
240
}
244
241
245
242
#[ cfg( any( target_os = "freebsd" ,
0 commit comments