Use O_CLOEXEC in tzfile handling
[glibc.git] / nptl_db / td_ta_tsd_iter.c
blob9cfb1e8de00ea8126f62c04003c87c1f02c9a044
1 /* Iterate over a process's thread-specific data.
2 Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.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 <alloca.h>
24 td_err_e
25 td_ta_tsd_iter (const td_thragent_t *ta_arg, td_key_iter_f *callback,
26 void *cbdata_p)
28 td_thragent_t *const ta = (td_thragent_t *) ta_arg;
29 td_err_e err;
30 void *keys;
31 size_t keys_nb, keys_elemsize;
32 psaddr_t addr;
33 uint32_t idx;
35 LOG ("td_ta_tsd_iter");
37 /* Test whether the TA parameter is ok. */
38 if (! ta_ok (ta))
39 return TD_BADTA;
41 /* This makes sure we have the size information on hand. */
42 addr = 0;
43 err = _td_locate_field (ta,
44 ta->ta_var___pthread_keys, SYM_DESC___pthread_keys,
45 (psaddr_t) 0 + 1, &addr);
46 if (err != TD_OK)
47 return err;
49 /* Now copy in the entire array of key descriptors. */
50 keys_elemsize = (addr - (psaddr_t) 0) / 8;
51 keys_nb = keys_elemsize * DB_DESC_NELEM (ta->ta_var___pthread_keys);
52 keys = __alloca (keys_nb);
53 err = DB_GET_SYMBOL (addr, ta, __pthread_keys);
54 if (err != TD_OK)
55 return err;
56 if (ps_pdread (ta->ph, addr, keys, keys_nb) != PS_OK)
57 return TD_ERR;
59 /* Now get all descriptors, one after the other. */
60 for (idx = 0; idx < DB_DESC_NELEM (ta->ta_var___pthread_keys); ++idx)
62 psaddr_t seq, destr;
63 err = DB_GET_FIELD_LOCAL (seq, ta, keys, pthread_key_struct, seq, 0);
64 if (err != TD_OK)
65 return err;
66 if (((uintptr_t) seq) & 1)
68 err = DB_GET_FIELD_LOCAL (destr, ta, keys, pthread_key_struct,
69 destr, 0);
70 if (err != TD_OK)
71 return err;
72 /* Return with an error if the callback returns a nonzero value. */
73 if (callback ((thread_key_t) idx, destr, cbdata_p) != 0)
74 return TD_DBERR;
76 /* Advance to the next element in the copied array. */
77 keys += keys_elemsize;
80 return TD_OK;