xref: /freebsd/contrib/netbsd-tests/lib/libc/tls/dso/h_tls_dlopen.c (revision d899be7d43d8df9cb485af5705e2724165a461c7)
157718be8SEnji Cooper /*	$NetBSD: h_tls_dlopen.c,v 1.5 2013/10/21 19:14:16 joerg Exp $	*/
257718be8SEnji Cooper /*-
357718be8SEnji Cooper  * Copyright (c) 2011 The NetBSD Foundation, Inc.
457718be8SEnji Cooper  * All rights reserved.
557718be8SEnji Cooper  *
657718be8SEnji Cooper  * This code is derived from software contributed to The NetBSD Foundation
757718be8SEnji Cooper  * by Joerg Sonnenberger.
857718be8SEnji Cooper  *
957718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
1057718be8SEnji Cooper  * modification, are permitted provided that the following conditions
1157718be8SEnji Cooper  * are met:
1257718be8SEnji Cooper  *
1357718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1457718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1557718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1657718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in
1757718be8SEnji Cooper  *    the documentation and/or other materials provided with the
1857718be8SEnji Cooper  *    distribution.
1957718be8SEnji Cooper  *
2057718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2157718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2257718be8SEnji Cooper  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2357718be8SEnji Cooper  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
2457718be8SEnji Cooper  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2557718be8SEnji Cooper  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
2657718be8SEnji Cooper  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2757718be8SEnji Cooper  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2857718be8SEnji Cooper  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2957718be8SEnji Cooper  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3057718be8SEnji Cooper  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3157718be8SEnji Cooper  * SUCH DAMAGE.
3257718be8SEnji Cooper  */
3357718be8SEnji Cooper 
3457718be8SEnji Cooper #include <sys/cdefs.h>
3557718be8SEnji Cooper __RCSID("$NetBSD: h_tls_dlopen.c,v 1.5 2013/10/21 19:14:16 joerg Exp $");
3657718be8SEnji Cooper 
3757718be8SEnji Cooper #include <atf-c.h>
3857718be8SEnji Cooper #include <unistd.h>
39*ff0ba872SEnji Cooper #ifdef __NetBSD__
4057718be8SEnji Cooper #include <sys/tls.h>
415bd73b51SEnji Cooper #endif
4257718be8SEnji Cooper 
4357718be8SEnji Cooper #ifdef __HAVE_NO___THREAD
4457718be8SEnji Cooper #define	__thread
4557718be8SEnji Cooper #endif
4657718be8SEnji Cooper 
4757718be8SEnji Cooper extern __thread int var1;
4857718be8SEnji Cooper extern __thread int var2;
4957718be8SEnji Cooper extern __thread int *var3;
5057718be8SEnji Cooper __thread int var5 = 1;
5157718be8SEnji Cooper static __thread pid_t (*local_var)(void) = getpid;
5257718be8SEnji Cooper 
5357718be8SEnji Cooper void testf_dso_helper(int x, int y);
5457718be8SEnji Cooper 
5557718be8SEnji Cooper void
testf_dso_helper(int x,int y)5657718be8SEnji Cooper testf_dso_helper(int x, int y)
5757718be8SEnji Cooper {
5857718be8SEnji Cooper 	var1 = x;
5957718be8SEnji Cooper 	var2 = y;
6057718be8SEnji Cooper 	var3 = &optind;
6157718be8SEnji Cooper 	ATF_CHECK_EQ(local_var, getpid);
6257718be8SEnji Cooper }
63