1 #include <dlfcn.h>
2 #include <link.h>
3 #include <stddef.h>
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <bits/wordsize.h>
10 #include <gnu/lib-names.h>
11 
12 
13 unsigned int
la_version(unsigned int v)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
la_activity(uintptr_t * cookie,unsigned int flag)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 *
la_objsearch(const char * name,uintptr_t * cookie,unsigned int flag)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
la_objopen(struct link_map * l,Lmid_t lmid,uintptr_t * cookie)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
la_preinit(uintptr_t * cookie)75 la_preinit (uintptr_t *cookie)
76 {
77   printf ("preinit\n");
78 }
79 
80 unsigned int
la_objclose(uintptr_t * cookie)81 la_objclose  (uintptr_t *cookie)
82 {
83   printf ("objclose\n");
84   return 0;
85 }
86 
87 uintptr_t
la_symbind32(Elf32_Sym * sym,unsigned int ndx,uintptr_t * refcook,uintptr_t * defcook,unsigned int * flags,const char * symname)88 la_symbind32 (Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook,
89 	      uintptr_t *defcook, unsigned int *flags, const char *symname)
90 {
91   printf ("symbind32: 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 uintptr_t
la_symbind64(Elf64_Sym * sym,unsigned int ndx,uintptr_t * refcook,uintptr_t * defcook,unsigned int * flags,const char * symname)98 la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
99 	      uintptr_t *defcook, unsigned int *flags, const char *symname)
100 {
101   printf ("symbind64: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
102 	  symname, (long int) sym->st_value, ndx, *flags);
103 
104   return sym->st_value;
105 }
106 
107 #include <tst-audit.h>
108 #if (!defined (pltenter) || !defined (pltexit) || !defined (La_regs) \
109      || !defined (La_retval) || !defined (int_retval))
110 # error "architecture specific code needed in sysdeps/CPU/tst-audit.h"
111 #endif
112 
113 
114 ElfW(Addr)
pltenter(ElfW (Sym)* sym,unsigned int ndx,uintptr_t * refcook,uintptr_t * defcook,La_regs * regs,unsigned int * flags,const char * symname,long int * framesizep)115 pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
116 	  uintptr_t *defcook, La_regs *regs, unsigned int *flags,
117 	  const char *symname, long int *framesizep)
118 {
119   printf ("pltenter: symname=%s, st_value=%#lx, ndx=%u, flags=%u\n",
120 	  symname, (long int) sym->st_value, ndx, *flags);
121 
122   return sym->st_value;
123 }
124 
125 unsigned int
pltexit(ElfW (Sym)* sym,unsigned int ndx,uintptr_t * refcook,uintptr_t * defcook,const La_regs * inregs,La_retval * outregs,const char * symname)126 pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
127 	 uintptr_t *defcook, const La_regs *inregs, La_retval *outregs,
128 	 const char *symname)
129 {
130   printf ("pltexit: symname=%s, st_value=%#lx, ndx=%u, retval=%tu\n",
131 	  symname, (long int) sym->st_value, ndx,
132 	  (ptrdiff_t) outregs->int_retval);
133 
134   return 0;
135 }
136