(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads_db / td_thr_tsd.c
blob978dc5e5249bf5409556f493becffce1ec4aa4da
1 /* Get a thread-specific data pointer for a thread.
2 Copyright (C) 1999, 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include "thread_dbP.h"
22 #include <linuxthreads/internals.h>
25 td_err_e
26 td_thr_tsd (const td_thrhandle_t *th, const thread_key_t tk, void **data)
28 struct _pthread_descr_struct pds;
29 struct pthread_key_struct *keys = th->th_ta_p->keys;
30 struct pthread_key_struct key;
31 int pthread_keys_max = th->th_ta_p->pthread_keys_max;
32 int pthread_key_2ndlevel_size = th->th_ta_p->pthread_key_2ndlevel_size;
33 unsigned int idx1st;
34 unsigned int idx2nd;
35 void *p;
37 LOG ("td_thr_tsd");
39 /* If there is no thread descriptor there cannot be any thread
40 specific data. */
41 if (th->th_unique == NULL)
42 return TD_BADKEY;
44 /* Get the thread descriptor. */
45 if (ps_pdread (th->th_ta_p->ph, th->th_unique, &pds,
46 sizeof (struct _pthread_descr_struct)) != PS_OK)
47 return TD_ERR; /* XXX Other error value? */
49 /* Check correct value of key. */
50 if (tk >= pthread_keys_max)
51 return TD_BADKEY;
53 /* Get the key entry. */
54 if (ps_pdread (th->th_ta_p->ph, &keys[tk], &key,
55 sizeof (struct pthread_key_struct)) != PS_OK)
56 return TD_ERR; /* XXX Other error value? */
58 /* Fail if this key is not at all used. */
59 if (! key.in_use)
60 return TD_BADKEY;
62 /* Compute the indeces. */
63 idx1st = tk / pthread_key_2ndlevel_size;
64 idx2nd = tk % pthread_key_2ndlevel_size;
66 /* Check the pointer to the second level array. */
67 if (pds.p_specific[idx1st] == NULL)
68 return TD_NOTSD;
70 /* Now get the real key.
71 XXX I don't know whether it's correct but there is currently no
72 easy way to determine whether a key was never set or the value
73 is NULL. We return an error whenever the value is NULL. */
74 if (ps_pdread (th->th_ta_p->ph, &pds.p_specific[idx1st][idx2nd], &p,
75 sizeof (void *)) != PS_OK)
76 return TD_ERR;
78 if (p != NULL)
79 *data = p;
81 return p != NULL ? TD_OK : TD_NOTSD;