/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003 Networks Associates Technology, Inc.4* All rights reserved.5*6* This software was developed for the FreeBSD Project by7* Jacques A. Vidrine, Safeport Network Services, and Network8* Associates Laboratories, the Security Research Division of Network9* Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-803510* ("CBOSS"), as part of the DARPA CHATS research program.11*12* Redistribution and use in source and binary forms, with or without13* modification, are permitted provided that the following conditions14* are met:15* 1. Redistributions of source code must retain the above copyright16* notice, this list of conditions and the following disclaimer.17* 2. Redistributions in binary form must reproduce the above copyright18* notice, this list of conditions and the following disclaimer in the19* documentation and/or other materials provided with the distribution.20*21* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*33* Macros which generate thread local storage handling code in NSS modules.34*/35#ifndef _NSS_TLS_H_36#define _NSS_TLS_H_3738#define NSS_TLS_HANDLING(name) \39static pthread_key_t name##_state_key; \40static void name##_keyinit(void); \41static int name##_getstate(struct name##_state **); \42\43static void \44name##_keyinit(void) \45{ \46(void)_pthread_key_create(&name##_state_key, name##_endstate); \47} \48\49static int \50name##_getstate(struct name##_state **p) \51{ \52static struct name##_state st; \53static pthread_once_t keyinit = PTHREAD_ONCE_INIT; \54int rv; \55\56if (!__isthreaded || _pthread_main_np() != 0) { \57*p = &st; \58return (0); \59} \60rv = _pthread_once(&keyinit, name##_keyinit); \61if (rv != 0) \62return (rv); \63*p = _pthread_getspecific(name##_state_key); \64if (*p != NULL) \65return (0); \66*p = calloc(1, sizeof(**p)); \67if (*p == NULL) \68return (ENOMEM); \69rv = _pthread_setspecific(name##_state_key, *p); \70if (rv != 0) { \71free(*p); \72*p = NULL; \73} \74return (rv); \75} \76/* allow the macro invocation to end with a semicolon */ \77struct _clashproof_bmVjdGFy7879#endif /* _NSS_TLS_H_ */808182