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