blob: 5b26a132fab6e8a78b3adb350d1a6ccf5dd818fb [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* Test case for i386 preserved registers in dynamic linker.
2 Copyright (C) 2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#include <dlfcn.h>
20#include <stdint.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <stddef.h>
24#include <string.h>
25#include <unistd.h>
26#include <link.h>
27#include <bits/wordsize.h>
28#include <gnu/lib-names.h>
29
30unsigned int
31la_version (unsigned int v)
32{
33 setlinebuf (stdout);
34
35 printf ("version: %u\n", v);
36
37 char buf[20];
38 sprintf (buf, "%u", v);
39
40 return v;
41}
42
43void
44la_activity (uintptr_t *cookie, unsigned int flag)
45{
46 const char *flagstr;
47 switch (flag)
48 {
49 case LA_ACT_CONSISTENT:
50 flagstr = "consistent";
51 break;
52 case LA_ACT_ADD:
53 flagstr = "add";
54 break;
55 case LA_ACT_DELETE:
56 flagstr = "delete";
57 break;
58 default:
59 printf ("activity: unknown activity %u\n", flag);
60 return;
61 }
62 printf ("activity: %s\n", flagstr);
63}
64
65char *
66la_objsearch (const char *name, uintptr_t *cookie, unsigned int flag)
67{
68 const char *flagstr;
69 switch (flag)
70 {
71 case LA_SER_ORIG:
72 flagstr = "LA_SET_ORIG";
73 break;
74 case LA_SER_LIBPATH:
75 flagstr = "LA_SER_LIBPATH";
76 break;
77 case LA_SER_RUNPATH:
78 flagstr = "LA_SER_RUNPATH";
79 break;
80 case LA_SER_CONFIG:
81 flagstr = "LA_SER_CONFIG";
82 break;
83 case LA_SER_DEFAULT:
84 flagstr = "LA_SER_DEFAULT";
85 case LA_SER_SECURE:
86 flagstr = "LA_SER_SECURE";
87 break;
88 default:
89 printf ("objsearch: %s, unknown flag %d\n", name, flag);
90 return (char *) name;
91 }
92
93 printf ("objsearch: %s, %s\n", name, flagstr);
94 return (char *) name;
95}
96
97unsigned int
98la_objopen (struct link_map *l, Lmid_t lmid, uintptr_t *cookie)
99{
100 printf ("objopen: %ld, %s\n", lmid, l->l_name);
101
102 return 3;
103}
104
105void
106la_preinit (uintptr_t *cookie)
107{
108 printf ("preinit\n");
109}
110
111unsigned int
112la_objclose (uintptr_t *cookie)
113{
114 printf ("objclose\n");
115 return 0;
116}
117
118uintptr_t
119la_symbind32 (Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
120 uintptr_t *defcook, unsigned int *flags, const char *symname)
121{
122 printf ("symbind32: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
123 symname, (long int) sym->st_value, ndx, *flags);
124
125 return sym->st_value;
126}
127
128#include "tst-audit.h"
129
130ElfW(Addr)
131pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
132 uintptr_t *defcook, La_regs *regs, unsigned int *flags,
133 const char *symname, long int *framesizep)
134{
135 printf ("pltenter: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
136 symname, (long int) sym->st_value, ndx, *flags);
137
138 if (strcmp (symname, "audit1_test") == 0
139 || strcmp (symname, "audit2_test") == 0)
140 {
141 if (regs->lr_eax != 1
142 || regs->lr_edx != 2
143 || regs->lr_ecx != 3)
144 abort ();
145
146 *framesizep = 200;
147 }
148
149 return sym->st_value;
150}
151
152unsigned int
153pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
154 uintptr_t *defcook, const La_regs *inregs, La_retval *outregs,
155 const char *symname)
156{
157 printf ("pltexit: symname=%s, st_value=%#lx, ndx=%u, retval=%tu\n",
158 symname, (long int) sym->st_value, ndx,
159 (ptrdiff_t) outregs->int_retval);
160
161 if (strcmp (symname, "audit1_test") == 0
162 || strcmp (symname, "audit2_test") == 0)
163 {
164 if (inregs->lr_eax != 1
165 || inregs->lr_edx != 2
166 || inregs->lr_ecx != 3)
167 abort ();
168
169 if (strcmp (symname, "audit1_test") == 0)
170 {
171 long long x = ((unsigned long long) outregs->lrv_eax
172 | (unsigned long long) outregs->lrv_edx << 32);
173
174 if (x != 30)
175 abort ();
176 }
177 else if (strcmp (symname, "audit2_test") == 0)
178 {
179 if (outregs->lrv_st0 != 30)
180 abort ();
181 }
182 }
183
184 return 0;
185}