Back to index

glibc  2.9
td_thr_get_info.c
Go to the documentation of this file.
00001 /* Get thread information.
00002    Copyright (C) 1999,2000,2001,2002,2003,2007 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stddef.h>
00022 #include <string.h>
00023 #include "thread_dbP.h"
00024 
00025 
00026 td_err_e
00027 td_thr_get_info (const td_thrhandle_t *th, td_thrinfo_t *infop)
00028 {
00029   td_err_e err;
00030   void *copy;
00031   psaddr_t tls, schedpolicy, schedprio, cancelhandling, tid, report_events;
00032 
00033   LOG ("td_thr_get_info");
00034 
00035   if (th->th_unique == 0)
00036     {
00037       /* Special case for the main thread before initialization.  */
00038       copy = NULL;
00039       tls = 0;
00040       cancelhandling = 0;
00041       schedprio = 0;
00042       tid = 0;
00043       err = DB_GET_VALUE (report_events, th->th_ta_p,
00044                        __nptl_initial_report_events, 0);
00045     }
00046   else
00047     {
00048       /* Copy the whole descriptor in once so we can access the several
00049         fields locally.  Excess copying in one go is much better than
00050         multiple ps_pdread calls.  */
00051       err = DB_GET_STRUCT (copy, th->th_ta_p, th->th_unique, pthread);
00052       if (err != TD_OK)
00053        return err;
00054 
00055       err = DB_GET_FIELD_ADDRESS (tls, th->th_ta_p, th->th_unique,
00056                               pthread, specific, 0);
00057       if (err != TD_OK)
00058        return err;
00059 
00060       err = DB_GET_FIELD_LOCAL (schedpolicy, th->th_ta_p, copy, pthread,
00061                             schedpolicy, 0);
00062       if (err != TD_OK)
00063        return err;
00064       err = DB_GET_FIELD_LOCAL (schedprio, th->th_ta_p, copy, pthread,
00065                             schedparam_sched_priority, 0);
00066       if (err != TD_OK)
00067        return err;
00068       err = DB_GET_FIELD_LOCAL (tid, th->th_ta_p, copy, pthread, tid, 0);
00069       if (err != TD_OK)
00070        return err;
00071       err = DB_GET_FIELD_LOCAL (cancelhandling, th->th_ta_p, copy, pthread,
00072                             cancelhandling, 0);
00073       if (err != TD_OK)
00074        return err;
00075       err = DB_GET_FIELD_LOCAL (report_events, th->th_ta_p, copy, pthread,
00076                             report_events, 0);
00077     }
00078   if (err != TD_OK)
00079     return err;
00080 
00081   /* Fill in information.  Clear first to provide reproducable
00082      results for the fields we do not fill in.  */
00083   memset (infop, '\0', sizeof (td_thrinfo_t));
00084 
00085   infop->ti_tid = (thread_t) th->th_unique;
00086   infop->ti_tls = (char *) tls;
00087   infop->ti_pri = ((uintptr_t) schedpolicy == SCHED_OTHER
00088                  ? 0 : (uintptr_t) schedprio);
00089   infop->ti_type = TD_THR_USER;
00090 
00091   if ((((int) (uintptr_t) cancelhandling) & EXITING_BITMASK) == 0)
00092     /* XXX For now there is no way to get more information.  */
00093     infop->ti_state = TD_THR_ACTIVE;
00094   else if ((((int) (uintptr_t) cancelhandling) & TERMINATED_BITMASK) == 0)
00095     infop->ti_state = TD_THR_ZOMBIE;
00096   else
00097     infop->ti_state = TD_THR_UNKNOWN;
00098 
00099   /* Initialization which are the same in both cases.  */
00100   infop->ti_ta_p = th->th_ta_p;
00101   infop->ti_lid = tid == 0 ? ps_getpid (th->th_ta_p->ph) : (uintptr_t) tid;
00102   infop->ti_traceme = report_events != 0;
00103 
00104   if (copy != NULL)
00105     err = DB_GET_FIELD_LOCAL (infop->ti_startfunc, th->th_ta_p, copy, pthread,
00106                            start_routine, 0);
00107   if (copy != NULL && err == TD_OK)
00108     {
00109       uint32_t idx;
00110       for (idx = 0; idx < TD_EVENTSIZE; ++idx)
00111        {
00112          psaddr_t word;
00113          err = DB_GET_FIELD_LOCAL (word, th->th_ta_p, copy, pthread,
00114                                 eventbuf_eventmask_event_bits, idx);
00115          if (err != TD_OK)
00116            break;
00117          infop->ti_events.event_bits[idx] = (uintptr_t) word;
00118        }
00119       if (err == TD_NOAPLIC)
00120        memset (&infop->ti_events.event_bits[idx], 0,
00121               (TD_EVENTSIZE - idx) * sizeof infop->ti_events.event_bits[0]);
00122     }
00123 
00124   return err;
00125 }