]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl_db/td_thr_validate.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / nptl_db / td_thr_validate.c
CommitLineData
76a50749 1/* Validate a thread handle.
581c785b 2 Copyright (C) 1999-2022 Free Software Foundation, Inc.
76a50749 3 This file is part of the GNU C Library.
76a50749
UD
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
76a50749
UD
18
19#include "thread_dbP.h"
090addb4 20#include <stdbool.h>
76a50749 21
1daccf40
FW
22td_err_e
23__td_ta_stack_user (td_thragent_t *ta, psaddr_t *plist)
24{
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);
28 else
29 {
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)
33 return TD_ERR;
34 *plist = ta->ta_addr__dl_stack_user;
35 return TD_OK;
36 }
37}
38
39td_err_e
40__td_ta_stack_used (td_thragent_t *ta, psaddr_t *plist)
41{
42
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);
46 else
47 {
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)
51 return TD_ERR;
52 *plist = ta->ta_addr__dl_stack_used;
53 return TD_OK;
54 }
55}
56
76a50749 57static td_err_e
090addb4 58check_thread_list (const td_thrhandle_t *th, psaddr_t head, bool *uninit)
76a50749 59{
7f08f55a
RM
60 td_err_e err;
61 psaddr_t next, ofs;
62
63 err = DB_GET_FIELD (next, th->th_ta_p, head, list_t, next, 0);
64 if (err == TD_OK)
65 {
66 if (next == 0)
090addb4
RM
67 {
68 *uninit = true;
69 return TD_NOTHR;
70 }
7f08f55a
RM
71 err = DB_GET_FIELD_ADDRESS (ofs, th->th_ta_p, 0, pthread, list, 0);
72 }
73
74 while (err == TD_OK)
75 {
76 if (next == head)
77 return TD_NOTHR;
78
79 if (next - (ofs - (psaddr_t) 0) == th->th_unique)
80 return TD_OK;
81
82 err = DB_GET_FIELD (next, th->th_ta_p, next, list_t, next, 0);
83 }
84
85 return err;
76a50749
UD
86}
87
88
89td_err_e
90td_thr_validate (const td_thrhandle_t *th)
91{
7f08f55a
RM
92 td_err_e err;
93 psaddr_t list;
94
76a50749
UD
95 LOG ("td_thr_validate");
96
97 /* First check the list with threads using user allocated stacks. */
090addb4 98 bool uninit = false;
1daccf40 99 err = __td_ta_stack_user (th->th_ta_p, &list);
7f08f55a 100 if (err == TD_OK)
090addb4 101 err = check_thread_list (th, list, &uninit);
76a50749
UD
102
103 /* If our thread is not on this list search the list with stack
104 using implementation allocated stacks. */
7f08f55a
RM
105 if (err == TD_NOTHR)
106 {
1daccf40 107 err = __td_ta_stack_used (th->th_ta_p, &list);
7f08f55a 108 if (err == TD_OK)
090addb4
RM
109 err = check_thread_list (th, list, &uninit);
110
7d9d8bd1
RM
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. */
114 err = TD_OK;
7f08f55a 115 }
76a50749 116
7f08f55a 117 return err;
76a50749 118}