xref: /freebsd-src/tools/regression/tls/ttls3/tls-test.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1*2546665aSDoug Rabson /*-
2*2546665aSDoug Rabson  * Copyright (C) 2004 NVIDIA Corporation.
3*2546665aSDoug Rabson  * All rights reserved.
4*2546665aSDoug Rabson  *
5*2546665aSDoug Rabson  * Redistribution and use in source and binary forms, with or without
6*2546665aSDoug Rabson  * modification, are permitted provided that the following conditions
7*2546665aSDoug Rabson  * are met:
8*2546665aSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
9*2546665aSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
10*2546665aSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
11*2546665aSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
12*2546665aSDoug Rabson  *    documentation and/or other materials provided with the distribution.
13*2546665aSDoug Rabson  *
14*2546665aSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*2546665aSDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*2546665aSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*2546665aSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*2546665aSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*2546665aSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*2546665aSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*2546665aSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*2546665aSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*2546665aSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*2546665aSDoug Rabson  * SUCH DAMAGE.
25*2546665aSDoug Rabson  */
26*2546665aSDoug Rabson 
27*2546665aSDoug Rabson #include <stdio.h>
28*2546665aSDoug Rabson #include <dlfcn.h>
29*2546665aSDoug Rabson 
main(int argc,char ** argv)30*2546665aSDoug Rabson int main(int argc, char **argv)
31*2546665aSDoug Rabson {
32*2546665aSDoug Rabson     void *handle;
33*2546665aSDoug Rabson     void (*__gl_tls_test)(void);
34*2546665aSDoug Rabson     const char *error;
35*2546665aSDoug Rabson 
36*2546665aSDoug Rabson     handle = dlopen("libtls-test.so.1", RTLD_NOW);
37*2546665aSDoug Rabson     if (!handle) {
38*2546665aSDoug Rabson         error = dlerror();
39*2546665aSDoug Rabson         printf("dlopen failed (%s)!\n", error);
40*2546665aSDoug Rabson         exit(1);
41*2546665aSDoug Rabson     }
42*2546665aSDoug Rabson 
43*2546665aSDoug Rabson     dlerror();
44*2546665aSDoug Rabson     __gl_tls_test = dlsym(handle, "__gl_tls_test");
45*2546665aSDoug Rabson     error = dlerror();
46*2546665aSDoug Rabson 
47*2546665aSDoug Rabson     if (error) {
48*2546665aSDoug Rabson         dlclose(handle);
49*2546665aSDoug Rabson         printf("dlsym failed (%s)!\n", error);
50*2546665aSDoug Rabson         exit(1);
51*2546665aSDoug Rabson     }
52*2546665aSDoug Rabson 
53*2546665aSDoug Rabson     __gl_tls_test(); /* print TLS values */
54*2546665aSDoug Rabson     dlclose(handle);
55*2546665aSDoug Rabson 
56*2546665aSDoug Rabson     return 0;
57*2546665aSDoug Rabson }
58