1 /* Copyright (C) 2002-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
20 #include <shlib-compat.h>
23 ___pthread_getspecific (pthread_key_t key
)
25 struct pthread_key_data
*data
;
27 /* Special case access to the first 2nd-level block. This is the
29 if (__glibc_likely (key
< PTHREAD_KEY_2NDLEVEL_SIZE
))
30 data
= &THREAD_SELF
->specific_1stblock
[key
];
33 /* Verify the key is sane. */
34 if (key
>= PTHREAD_KEYS_MAX
)
38 unsigned int idx1st
= key
/ PTHREAD_KEY_2NDLEVEL_SIZE
;
39 unsigned int idx2nd
= key
% PTHREAD_KEY_2NDLEVEL_SIZE
;
41 /* If the sequence number doesn't match or the key cannot be defined
42 for this thread since the second level array is not allocated
44 struct pthread_key_data
*level2
= THREAD_GETMEM_NC (THREAD_SELF
,
47 /* Not allocated, therefore no data. */
51 data
= &level2
[idx2nd
];
54 void *result
= data
->data
;
57 uintptr_t seq
= data
->seq
;
59 if (__glibc_unlikely (seq
!= __pthread_keys
[key
].seq
))
60 result
= data
->data
= NULL
;
65 versioned_symbol (libc
, ___pthread_getspecific
, pthread_getspecific
,
67 libc_hidden_ver (___pthread_getspecific
, __pthread_getspecific
)
69 strong_alias (___pthread_getspecific
, __pthread_getspecific
)
72 #if OTHER_SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_34)
73 compat_symbol (libpthread
, ___pthread_getspecific
, __pthread_getspecific
,
75 compat_symbol (libpthread
, ___pthread_getspecific
, pthread_getspecific
,