Back to index

glibc  2.9
td_thr_validate.c
Go to the documentation of this file.
00001 /* Validate a thread handle.
00002    Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.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 "thread_dbP.h"
00022 #include <linuxthreads/internals.h>
00023 
00024 
00025 td_err_e
00026 td_thr_validate (const td_thrhandle_t *th)
00027 {
00028   struct pthread_handle_struct *handles = th->th_ta_p->handles;
00029   int pthread_threads_max = th->th_ta_p->pthread_threads_max;
00030   int cnt;
00031   struct pthread_handle_struct phc;
00032 
00033   LOG ("td_thr_validate");
00034 
00035   /* A special case: if the program just starts up the handle is
00036      NULL.  */
00037   if (th->th_unique == NULL)
00038     {
00039       /* Read the first handle.  If the pointer to the thread
00040         descriptor is not NULL this is an error.  */
00041       if (ps_pdread (th->th_ta_p->ph, handles, &phc,
00042                    sizeof (struct pthread_handle_struct)) != PS_OK)
00043        return TD_ERR;       /* XXX Other error value?  */
00044 
00045       return phc.h_descr == NULL ? TD_OK : TD_NOTHR;
00046     }
00047 
00048   /* Now get all descriptors, one after the other.  */
00049   for (cnt = 0; cnt < pthread_threads_max; ++cnt, ++handles)
00050     {
00051       if (ps_pdread (th->th_ta_p->ph, handles, &phc,
00052                    sizeof (struct pthread_handle_struct)) != PS_OK)
00053        return TD_ERR;       /* XXX Other error value?  */
00054 
00055       if (phc.h_descr != NULL && phc.h_descr == th->th_unique)
00056        {
00057          struct _pthread_descr_struct pds;
00058 
00059          if (ps_pdread (th->th_ta_p->ph, phc.h_descr, &pds,
00060                       th->th_ta_p->sizeof_descr) != PS_OK)
00061            return TD_ERR;   /* XXX Other error value?  */
00062 
00063          /* XXX There should be another test using the TID but this is
00064             currently not available.  */
00065          return pds.p_terminated != 0 ? TD_NOTHR : TD_OK;
00066        }
00067     }
00068 
00069   return TD_ERR;
00070 }