source: mainline/uspace/lib/dltest/dltest.c

Last change on this file was b192915a, checked in by Jiri Svoboda <jiri@…>, 13 months ago

Add test case for public variable initialized with a relocated value

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2024 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libdltest
30 * @{
31 */
32/** @file
33 */
34
35#include <fibril.h>
36#include "libdltest.h"
37
38/** Private initialized variable */
39static int private_var = dl_private_var_val;
40/** Private uninitialized variable */
41static int private_uvar;
42
43/** Public initialized variable */
44int dl_public_var = dl_public_var_val;
45/** Public variable initialized with the address of a symbol */
46int *dl_public_ptr_var = &dl_public_var;
47/** Public uninitialized variable */
48int dl_public_uvar;
49
50/** Private initialized fibril-local variable */
51static fibril_local int dl_private_fib_var = dl_private_fib_var_val;
52/** Private uninitialized fibril-local variable */
53static fibril_local int dl_private_fib_uvar;
54
55/** Public initialized fibril-local variable */
56fibril_local int dl_public_fib_var = dl_public_fib_var_val;
57/** Public uninitialized fibril-local variable */
58fibril_local int dl_public_fib_uvar;
59
60/** Return constant value. */
61int dl_get_constant(void)
62{
63 return dl_constant;
64}
65
66/** Return constant value by calling another function.
67 *
68 * This can be used to test dynamically linked call (via PLT) even in case
69 * binaries are statically linked.
70 */
71int dl_get_constant_via_call(void)
72{
73 return dl_get_constant();
74}
75
76/** Return value of private initialized variable */
77int dl_get_private_var(void)
78{
79 return private_var;
80}
81
82/** Return address of private initialized variable */
83int *dl_get_private_var_addr(void)
84{
85 return &private_var;
86}
87
88/** Return value of private uninitialized variable */
89int dl_get_private_uvar(void)
90{
91 return private_uvar;
92}
93
94/** Return vaddress of private uninitialized variable */
95int *dl_get_private_uvar_addr(void)
96{
97 return &private_uvar;
98}
99
100/** Return value of public initialized variable */
101int dl_get_public_var(void)
102{
103 return dl_public_var;
104}
105
106/** Return address of public initialized variable */
107int *dl_get_public_var_addr(void)
108{
109 return &dl_public_var;
110}
111
112/** Return value of public uninitialized variable */
113int dl_get_public_uvar(void)
114{
115 return dl_public_uvar;
116}
117
118/** Return address of public uninitialized variable */
119int *dl_get_public_uvar_addr(void)
120{
121 return &dl_public_uvar;
122}
123
124/** Return value of private initialized fibril-local variable */
125int dl_get_private_fib_var(void)
126{
127 return dl_private_fib_var;
128}
129
130/** Return address of private initialized fibril-local variable */
131int *dl_get_private_fib_var_addr(void)
132{
133 return &dl_private_fib_var;
134}
135
136/** Return value of private uninitialized fibril-local variable */
137int dl_get_private_fib_uvar(void)
138{
139 return dl_private_fib_uvar;
140}
141
142/** Return address of private uninitialized fibril-local variable */
143int *dl_get_private_fib_uvar_addr(void)
144{
145 return &dl_private_fib_uvar;
146}
147
148/** Return value of public initialized fibril-local variable */
149int dl_get_public_fib_var(void)
150{
151 return dl_public_fib_var;
152}
153
154/** Return value of public initialized fibril-local variable */
155int *dl_get_public_fib_var_addr(void)
156{
157 return &dl_public_fib_var;
158}
159
160/** Return value of public uninitialized fibril-local variable */
161int dl_get_public_fib_uvar(void)
162{
163 return dl_public_fib_uvar;
164}
165
166/** Return value of public uninitialized fibril-local variable */
167int *dl_get_public_fib_uvar_addr(void)
168{
169 return &dl_public_fib_uvar;
170}
171
172/**
173 * @}
174 */
Note: See TracBrowser for help on using the repository browser.