1 /* Validate a thread handle.
2 Copyright (C) 1999-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include "thread_dbP.h"
23 __td_ta_stack_user (td_thragent_t
*ta
, psaddr_t
*plist
)
25 if (__td_ta_rtld_global (ta
))
26 return DB_GET_FIELD_ADDRESS (*plist
, ta
, ta
->ta_addr__rtld_global
,
27 rtld_global
, _dl_stack_user
, 0);
30 if (ta
->ta_addr__dl_stack_user
== 0
31 && td_mod_lookup (ta
->ph
, NULL
, SYM__dl_stack_user
,
32 &ta
->ta_addr__dl_stack_user
) != PS_OK
)
34 *plist
= ta
->ta_addr__dl_stack_user
;
40 __td_ta_stack_used (td_thragent_t
*ta
, psaddr_t
*plist
)
43 if (__td_ta_rtld_global (ta
))
44 return DB_GET_FIELD_ADDRESS (*plist
, ta
, ta
->ta_addr__rtld_global
,
45 rtld_global
, _dl_stack_used
, 0);
48 if (ta
->ta_addr__dl_stack_used
== 0
49 && td_mod_lookup (ta
->ph
, NULL
, SYM__dl_stack_used
,
50 &ta
->ta_addr__dl_stack_used
) != PS_OK
)
52 *plist
= ta
->ta_addr__dl_stack_used
;
58 check_thread_list (const td_thrhandle_t
*th
, psaddr_t head
, bool *uninit
)
63 err
= DB_GET_FIELD (next
, th
->th_ta_p
, head
, list_t
, next
, 0);
71 err
= DB_GET_FIELD_ADDRESS (ofs
, th
->th_ta_p
, 0, pthread
, list
, 0);
79 if (next
- (ofs
- (psaddr_t
) 0) == th
->th_unique
)
82 err
= DB_GET_FIELD (next
, th
->th_ta_p
, next
, list_t
, next
, 0);
90 td_thr_validate (const td_thrhandle_t
*th
)
95 LOG ("td_thr_validate");
97 /* First check the list with threads using user allocated stacks. */
99 err
= __td_ta_stack_user (th
->th_ta_p
, &list
);
101 err
= check_thread_list (th
, list
, &uninit
);
103 /* If our thread is not on this list search the list with stack
104 using implementation allocated stacks. */
107 err
= __td_ta_stack_used (th
->th_ta_p
, &list
);
109 err
= check_thread_list (th
, list
, &uninit
);
111 if (err
== TD_NOTHR
&& uninit
&& th
->th_unique
== 0)
112 /* __pthread_initialize_minimal has not run yet.
113 There is only the special case thread handle. */