NPTL/arc: notify kernel of the TP value
[uClibc.git] / libpthread / linuxthreads_db / td_thr_get_info.c
blobc73f330201eb7edb42e1e421bd8c29737b6e5293
1 /* Get thread information.
2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <stddef.h>
21 #include <string.h>
23 #include "thread_dbP.h"
26 td_err_e
27 td_thr_get_info (const td_thrhandle_t *th, td_thrinfo_t *infop)
29 struct _pthread_descr_struct pds;
31 LOG ("td_thr_get_info");
33 /* Handle the case when the thread library is not yet initialized. */
34 if (th->th_unique == NULL)
36 memset (&pds, '\0', sizeof (pds));
37 pds.p_tid = PTHREAD_THREADS_MAX;
39 else
40 /* Get the thread descriptor. */
41 if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
42 th->th_ta_p->sizeof_descr) != PS_OK)
43 return TD_ERR; /* XXX Other error value? */
45 /* Fill in information. Clear first to provide reproducable
46 results for the fields we do not fill in. */
47 memset (infop, '\0', sizeof (td_thrinfo_t));
49 /* We have to handle the manager thread special since the thread
50 descriptor in older versions is not fully initialized. */
51 if (pds.p_nr == 1)
53 infop->ti_tid = th->th_ta_p->pthread_threads_max * 2 + 1;
54 infop->ti_type = TD_THR_SYSTEM;
55 infop->ti_state = TD_THR_ACTIVE;
57 else
59 infop->ti_tid = pds.p_tid;
60 infop->ti_tls = (char *) pds.p_specific;
61 infop->ti_pri = pds.p_priority;
62 infop->ti_type = TD_THR_USER;
64 if (! pds.p_terminated)
65 /* XXX For now there is no way to get more information. */
66 infop->ti_state = TD_THR_ACTIVE;
67 else if (! pds.p_detached)
68 infop->ti_state = TD_THR_ZOMBIE;
69 else
70 infop->ti_state = TD_THR_UNKNOWN;
73 /* Initialization which are the same in both cases. */
74 infop->ti_lid = pds.p_pid ?: ps_getpid (th->th_ta_p->ph);
75 infop->ti_ta_p = th->th_ta_p;
76 infop->ti_startfunc = pds.p_start_args.start_routine;
77 memcpy (&infop->ti_events, &pds.p_eventbuf.eventmask,
78 sizeof (td_thr_events_t));
79 infop->ti_traceme = pds.p_report_events != 0;
81 return TD_OK;