| 1 | /* Copyright (C) 2002-2023 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | |
| 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. |
| 8 | |
| 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. |
| 13 | |
| 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/>. */ |
| 17 | |
| 18 | #include "pthreadP.h" |
| 19 | #include <string.h> |
| 20 | #include <pthread-offsets.h> |
| 21 | #include <shlib-compat.h> |
| 22 | |
| 23 | static const struct pthread_rwlockattr default_rwlockattr = |
| 24 | { |
| 25 | .lockkind = PTHREAD_RWLOCK_DEFAULT_NP, |
| 26 | .pshared = PTHREAD_PROCESS_PRIVATE |
| 27 | }; |
| 28 | |
| 29 | |
| 30 | /* See pthread_rwlock_common.c. */ |
| 31 | int |
| 32 | ___pthread_rwlock_init (pthread_rwlock_t *rwlock, |
| 33 | const pthread_rwlockattr_t *attr) |
| 34 | { |
| 35 | ASSERT_TYPE_SIZE (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T); |
| 36 | |
| 37 | /* The __flags is the only field where its offset should be checked to |
| 38 | avoid ABI breakage with static initializers. */ |
| 39 | ASSERT_PTHREAD_INTERNAL_OFFSET (pthread_rwlock_t, __data.__flags, |
| 40 | __PTHREAD_RWLOCK_FLAGS_OFFSET); |
| 41 | ASSERT_PTHREAD_INTERNAL_MEMBER_SIZE (pthread_rwlock_t, __data.__flags, |
| 42 | int); |
| 43 | |
| 44 | const struct pthread_rwlockattr *iattr; |
| 45 | |
| 46 | iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_rwlockattr; |
| 47 | |
| 48 | memset (rwlock, '\0', sizeof (*rwlock)); |
| 49 | |
| 50 | rwlock->__data.__flags = iattr->lockkind; |
| 51 | |
| 52 | /* The value of __SHARED in a private rwlock must be zero. */ |
| 53 | rwlock->__data.__shared = (iattr->pshared != PTHREAD_PROCESS_PRIVATE); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | versioned_symbol (libc, ___pthread_rwlock_init, pthread_rwlock_init, |
| 58 | GLIBC_2_34); |
| 59 | libc_hidden_ver (___pthread_rwlock_init, __pthread_rwlock_init) |
| 60 | #ifndef SHARED |
| 61 | strong_alias (___pthread_rwlock_init, __pthread_rwlock_init) |
| 62 | #endif |
| 63 | |
| 64 | #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_1, GLIBC_2_34) |
| 65 | compat_symbol (libpthread, ___pthread_rwlock_init, pthread_rwlock_init, |
| 66 | GLIBC_2_1); |
| 67 | #endif |
| 68 | #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_2, GLIBC_2_34) |
| 69 | compat_symbol (libpthread, ___pthread_rwlock_init, __pthread_rwlock_init, |
| 70 | GLIBC_2_2); |
| 71 | #endif |
| 72 | |