|
Packit |
6c4009 |
/* Validate a thread handle.
|
|
Packit |
6c4009 |
Copyright (C) 1999-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "thread_dbP.h"
|
|
Packit |
6c4009 |
#include <stdbool.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static td_err_e
|
|
Packit |
6c4009 |
check_thread_list (const td_thrhandle_t *th, psaddr_t head, bool *uninit)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
td_err_e err;
|
|
Packit |
6c4009 |
psaddr_t next, ofs;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
err = DB_GET_FIELD (next, th->th_ta_p, head, list_t, next, 0);
|
|
Packit |
6c4009 |
if (err == TD_OK)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (next == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
*uninit = true;
|
|
Packit |
6c4009 |
return TD_NOTHR;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
err = DB_GET_FIELD_ADDRESS (ofs, th->th_ta_p, 0, pthread, list, 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
while (err == TD_OK)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (next == head)
|
|
Packit |
6c4009 |
return TD_NOTHR;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (next - (ofs - (psaddr_t) 0) == th->th_unique)
|
|
Packit |
6c4009 |
return TD_OK;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
err = DB_GET_FIELD (next, th->th_ta_p, next, list_t, next, 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return err;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
td_err_e
|
|
Packit |
6c4009 |
td_thr_validate (const td_thrhandle_t *th)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
td_err_e err;
|
|
Packit |
6c4009 |
psaddr_t list;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
LOG ("td_thr_validate");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* First check the list with threads using user allocated stacks. */
|
|
Packit |
6c4009 |
bool uninit = false;
|
|
Packit |
6c4009 |
err = DB_GET_SYMBOL (list, th->th_ta_p, __stack_user);
|
|
Packit |
6c4009 |
if (err == TD_OK)
|
|
Packit |
6c4009 |
err = check_thread_list (th, list, &uninit);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* If our thread is not on this list search the list with stack
|
|
Packit |
6c4009 |
using implementation allocated stacks. */
|
|
Packit |
6c4009 |
if (err == TD_NOTHR)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
err = DB_GET_SYMBOL (list, th->th_ta_p, stack_used);
|
|
Packit |
6c4009 |
if (err == TD_OK)
|
|
Packit |
6c4009 |
err = check_thread_list (th, list, &uninit);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (err == TD_NOTHR && uninit && th->th_unique == 0)
|
|
Packit |
6c4009 |
/* __pthread_initialize_minimal has not run yet.
|
|
Packit |
6c4009 |
There is only the special case thread handle. */
|
|
Packit |
6c4009 |
err = TD_OK;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return err;
|
|
Packit |
6c4009 |
}
|