]>
Commit | Line | Data |
---|---|---|
4e1e2f42 L |
1 | /* Verify that changing AVX registers in audit library won't affect |
2 | function parameter passing/return. */ | |
3 | ||
4 | #include <dlfcn.h> | |
5 | #include <stdint.h> | |
6 | #include <stdio.h> | |
7 | #include <stdlib.h> | |
8 | #include <string.h> | |
9 | #include <unistd.h> | |
10 | #include <bits/wordsize.h> | |
11 | #include <gnu/lib-names.h> | |
12 | ||
13 | unsigned int | |
14 | la_version (unsigned int v) | |
15 | { | |
16 | setlinebuf (stdout); | |
17 | ||
18 | printf ("version: %u\n", v); | |
19 | ||
20 | char buf[20]; | |
21 | sprintf (buf, "%u", v); | |
22 | ||
23 | return v; | |
24 | } | |
25 | ||
26 | void | |
27 | la_activity (uintptr_t *cookie, unsigned int flag) | |
28 | { | |
29 | if (flag == LA_ACT_CONSISTENT) | |
30 | printf ("activity: consistent\n"); | |
31 | else if (flag == LA_ACT_ADD) | |
32 | printf ("activity: add\n"); | |
33 | else if (flag == LA_ACT_DELETE) | |
34 | printf ("activity: delete\n"); | |
35 | else | |
36 | printf ("activity: unknown activity %u\n", flag); | |
37 | } | |
38 | ||
39 | char * | |
40 | la_objsearch (const char *name, uintptr_t *cookie, unsigned int flag) | |
41 | { | |
42 | char buf[100]; | |
43 | const char *flagstr; | |
44 | if (flag == LA_SER_ORIG) | |
45 | flagstr = "LA_SET_ORIG"; | |
46 | else if (flag == LA_SER_LIBPATH) | |
47 | flagstr = "LA_SER_LIBPATH"; | |
48 | else if (flag == LA_SER_RUNPATH) | |
49 | flagstr = "LA_SER_RUNPATH"; | |
50 | else if (flag == LA_SER_CONFIG) | |
51 | flagstr = "LA_SER_CONFIG"; | |
52 | else if (flag == LA_SER_DEFAULT) | |
53 | flagstr = "LA_SER_DEFAULT"; | |
54 | else if (flag == LA_SER_SECURE) | |
55 | flagstr = "LA_SER_SECURE"; | |
56 | else | |
57 | { | |
58 | sprintf (buf, "unknown flag %d", flag); | |
59 | flagstr = buf; | |
60 | } | |
61 | printf ("objsearch: %s, %s\n", name, flagstr); | |
62 | ||
63 | return (char *) name; | |
64 | } | |
65 | ||
66 | unsigned int | |
67 | la_objopen (struct link_map *l, Lmid_t lmid, uintptr_t *cookie) | |
68 | { | |
69 | printf ("objopen: %ld, %s\n", lmid, l->l_name); | |
70 | ||
71 | return 3; | |
72 | } | |
73 | ||
74 | void | |
75 | la_preinit (uintptr_t *cookie) | |
76 | { | |
77 | printf ("preinit\n"); | |
78 | } | |
79 | ||
80 | unsigned int | |
81 | la_objclose (uintptr_t *cookie) | |
82 | { | |
83 | printf ("objclose\n"); | |
84 | return 0; | |
85 | } | |
86 | ||
87 | uintptr_t | |
88 | la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook, | |
89 | uintptr_t *defcook, unsigned int *flags, const char *symname) | |
90 | { | |
91 | printf ("symbind64: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n", | |
92 | symname, (long int) sym->st_value, ndx, *flags); | |
93 | ||
94 | return sym->st_value; | |
95 | } | |
96 | ||
97 | #define pltenter la_x86_64_gnu_pltenter | |
98 | #define pltexit la_x86_64_gnu_pltexit | |
99 | #define La_regs La_x86_64_regs | |
100 | #define La_retval La_x86_64_retval | |
101 | #define int_retval lrv_rax | |
102 | ||
103 | #include <tst-audit.h> | |
104 | ||
105 | #ifdef __AVX__ | |
106 | #include <immintrin.h> | |
107 | #include <cpuid.h> | |
108 | ||
109 | static int avx = -1; | |
110 | ||
2b2596b1 | 111 | static inline int |
4e1e2f42 L |
112 | __attribute ((always_inline)) |
113 | check_avx (void) | |
114 | { | |
115 | if (avx == -1) | |
116 | { | |
117 | unsigned int eax, ebx, ecx, edx; | |
118 | ||
119 | if (__get_cpuid (1, &eax, &ebx, &ecx, &edx) | |
120 | && (ecx & bit_AVX)) | |
121 | avx = 1; | |
122 | else | |
123 | avx = 0; | |
124 | } | |
125 | return avx; | |
126 | } | |
127 | #else | |
128 | #include <emmintrin.h> | |
129 | #endif | |
130 | ||
131 | ElfW(Addr) | |
132 | pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook, | |
133 | uintptr_t *defcook, La_regs *regs, unsigned int *flags, | |
134 | const char *symname, long int *framesizep) | |
135 | { | |
136 | printf ("pltenter: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n", | |
137 | symname, (long int) sym->st_value, ndx, *flags); | |
138 | ||
139 | #ifdef __AVX__ | |
140 | if (check_avx () && strcmp (symname, "audit_test") == 0) | |
141 | { | |
142 | int i; | |
143 | ||
144 | __m128i xmm = _mm_setzero_si128 (); | |
145 | for (i = 0; i < 8; i++) | |
146 | if (memcmp (®s->lr_xmm[i], &xmm, sizeof (xmm)) | |
147 | || memcmp (®s->lr_vector[i], &xmm, sizeof (xmm))) | |
148 | abort (); | |
149 | ||
150 | for (i = 0; i < 8; i += 2) | |
151 | { | |
152 | regs->lr_xmm[i] = (La_x86_64_xmm) _mm_set1_epi32 (i + 0x100); | |
153 | regs->lr_vector[i + 1].ymm[0] | |
154 | = (La_x86_64_ymm) _mm256_set1_epi32 (i + 0x101); | |
155 | } | |
156 | ||
157 | __m256i ymm = _mm256_set1_epi32 (-1); | |
158 | asm volatile ("vmovdqa %0, %%ymm0" : : "x" (ymm) : "xmm0" ); | |
159 | asm volatile ("vmovdqa %0, %%ymm1" : : "x" (ymm) : "xmm1" ); | |
160 | asm volatile ("vmovdqa %0, %%ymm2" : : "x" (ymm) : "xmm2" ); | |
161 | asm volatile ("vmovdqa %0, %%ymm3" : : "x" (ymm) : "xmm3" ); | |
162 | asm volatile ("vmovdqa %0, %%ymm4" : : "x" (ymm) : "xmm4" ); | |
163 | asm volatile ("vmovdqa %0, %%ymm5" : : "x" (ymm) : "xmm5" ); | |
164 | asm volatile ("vmovdqa %0, %%ymm6" : : "x" (ymm) : "xmm6" ); | |
165 | asm volatile ("vmovdqa %0, %%ymm7" : : "x" (ymm) : "xmm7" ); | |
166 | ||
167 | *framesizep = 1024; | |
168 | } | |
169 | #endif | |
170 | ||
171 | return sym->st_value; | |
172 | } | |
173 | ||
174 | unsigned int | |
175 | pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook, | |
176 | uintptr_t *defcook, const La_regs *inregs, La_retval *outregs, | |
177 | const char *symname) | |
178 | { | |
179 | printf ("pltexit: symname=%s, st_value=%#lx, ndx=%u, retval=%tu\n", | |
180 | symname, (long int) sym->st_value, ndx, outregs->int_retval); | |
181 | ||
182 | #ifdef __AVX__ | |
183 | if (check_avx () && strcmp (symname, "audit_test") == 0) | |
184 | { | |
185 | int i; | |
186 | ||
187 | __m128i xmm = _mm_setzero_si128 (); | |
188 | if (memcmp (&outregs->lrv_xmm0, &xmm, sizeof (xmm)) | |
189 | || memcmp (&outregs->lrv_vector0, &xmm, sizeof (xmm))) | |
190 | abort (); | |
191 | ||
192 | __m256i ymm; | |
193 | ||
194 | for (i = 0; i < 8; i += 2) | |
195 | { | |
196 | xmm = _mm_set1_epi32 (i + 0x100); | |
197 | if (memcmp (&inregs->lr_xmm[i], &xmm, sizeof (xmm)) | |
198 | || memcmp (&inregs->lr_vector[i], &xmm, sizeof (xmm))) | |
199 | abort (); | |
200 | ||
201 | ymm = _mm256_set1_epi32 (i + 0x101); | |
202 | if (memcmp (&inregs->lr_xmm[i + 1], | |
203 | &inregs->lr_vector[i + 1].xmm[0], sizeof (xmm)) | |
204 | || memcmp (&inregs->lr_vector[i + 1], &ymm, sizeof (ymm))) | |
205 | abort (); | |
206 | } | |
207 | ||
208 | outregs->lrv_vector0.ymm[0] | |
209 | = (La_x86_64_ymm) _mm256_set1_epi32 (0x98abcdef); | |
210 | ||
211 | ymm = _mm256_set1_epi32 (-1); | |
212 | asm volatile ("vmovdqa %0, %%ymm0" : : "x" (ymm) : "xmm0" ); | |
213 | asm volatile ("vmovdqa %0, %%ymm1" : : "x" (ymm) : "xmm1" ); | |
214 | } | |
215 | #endif | |
216 | ||
217 | return 0; | |
218 | } |