Make libio compile without _IO_MTSAFE_IO.
[glibc.git] / elf / tst-auditmod4b.c
blob80aaedcd3e2da4e43d8756a7122fb214764f926d
1 /* Verify that changing AVX registers in audit library won't affect
2 function parameter passing/return. */
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>
13 unsigned int
14 la_version (unsigned int v)
16 setlinebuf (stdout);
18 printf ("version: %u\n", v);
20 char buf[20];
21 sprintf (buf, "%u", v);
23 return v;
26 void
27 la_activity (uintptr_t *cookie, unsigned int flag)
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);
39 char *
40 la_objsearch (const char *name, uintptr_t *cookie, unsigned int flag)
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
58 sprintf (buf, "unknown flag %d", flag);
59 flagstr = buf;
61 printf ("objsearch: %s, %s\n", name, flagstr);
63 return (char *) name;
66 unsigned int
67 la_objopen (struct link_map *l, Lmid_t lmid, uintptr_t *cookie)
69 printf ("objopen: %ld, %s\n", lmid, l->l_name);
71 return 3;
74 void
75 la_preinit (uintptr_t *cookie)
77 printf ("preinit\n");
80 unsigned int
81 la_objclose (uintptr_t *cookie)
83 printf ("objclose\n");
84 return 0;
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)
91 printf ("symbind64: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
92 symname, (long int) sym->st_value, ndx, *flags);
94 return sym->st_value;
97 #include <tst-audit.h>
99 #ifdef __AVX__
100 #include <immintrin.h>
101 #include <cpuid.h>
103 static int avx = -1;
105 static inline int
106 __attribute ((always_inline))
107 check_avx (void)
109 if (avx == -1)
111 unsigned int eax, ebx, ecx, edx;
113 if (__get_cpuid (1, &eax, &ebx, &ecx, &edx)
114 && (ecx & bit_AVX))
115 avx = 1;
116 else
117 avx = 0;
119 return avx;
121 #else
122 #include <emmintrin.h>
123 #endif
125 ElfW(Addr)
126 pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
127 uintptr_t *defcook, La_regs *regs, unsigned int *flags,
128 const char *symname, long int *framesizep)
130 printf ("pltenter: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
131 symname, (long int) sym->st_value, ndx, *flags);
133 #ifdef __AVX__
134 if (check_avx () && strcmp (symname, "audit_test") == 0)
136 __m256i zero = _mm256_setzero_si256 ();
137 if (memcmp (&regs->lr_vector[0], &zero, sizeof (zero))
138 || memcmp (&regs->lr_vector[1], &zero, sizeof (zero))
139 || memcmp (&regs->lr_vector[2], &zero, sizeof (zero))
140 || memcmp (&regs->lr_vector[3], &zero, sizeof (zero))
141 || memcmp (&regs->lr_vector[4], &zero, sizeof (zero))
142 || memcmp (&regs->lr_vector[5], &zero, sizeof (zero))
143 || memcmp (&regs->lr_vector[6], &zero, sizeof (zero))
144 || memcmp (&regs->lr_vector[7], &zero, sizeof (zero)))
145 abort ();
147 for (int i = 0; i < 8; i++)
148 regs->lr_vector[i].ymm[0]
149 = (La_x86_64_ymm) _mm256_set1_epi32 (i + 1);
151 __m256i ymm = _mm256_set1_epi32 (-1);
152 asm volatile ("vmovdqa %0, %%ymm0" : : "x" (ymm) : "xmm0" );
153 asm volatile ("vmovdqa %0, %%ymm1" : : "x" (ymm) : "xmm1" );
154 asm volatile ("vmovdqa %0, %%ymm2" : : "x" (ymm) : "xmm2" );
155 asm volatile ("vmovdqa %0, %%ymm3" : : "x" (ymm) : "xmm3" );
156 asm volatile ("vmovdqa %0, %%ymm4" : : "x" (ymm) : "xmm4" );
157 asm volatile ("vmovdqa %0, %%ymm5" : : "x" (ymm) : "xmm5" );
158 asm volatile ("vmovdqa %0, %%ymm6" : : "x" (ymm) : "xmm6" );
159 asm volatile ("vmovdqa %0, %%ymm7" : : "x" (ymm) : "xmm7" );
161 *framesizep = 1024;
163 #endif
165 return sym->st_value;
168 unsigned int
169 pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
170 uintptr_t *defcook, const La_regs *inregs, La_retval *outregs,
171 const char *symname)
173 printf ("pltexit: symname=%s, st_value=%#lx, ndx=%u, retval=%tu\n",
174 symname, (long int) sym->st_value, ndx,
175 (ptrdiff_t) outregs->int_retval);
177 #ifdef __AVX__
178 if (check_avx () && strcmp (symname, "audit_test") == 0)
180 __m256i zero = _mm256_setzero_si256 ();
181 if (memcmp (&outregs->lrv_vector0, &zero, sizeof (zero)))
182 abort ();
184 for (int i = 0; i < 8; i++)
186 __m256i ymm = _mm256_set1_epi32 (i + 1);
187 if (memcmp (&inregs->lr_vector[i], &ymm, sizeof (ymm)) != 0)
188 abort ();
191 outregs->lrv_vector0.ymm[0]
192 = (La_x86_64_ymm) _mm256_set1_epi32 (0x12349876);
194 __m256i ymm = _mm256_set1_epi32 (-1);
195 asm volatile ("vmovdqa %0, %%ymm0" : : "x" (ymm) : "xmm0" );
196 asm volatile ("vmovdqa %0, %%ymm1" : : "x" (ymm) : "xmm1" );
198 #endif
200 return 0;