1 | /* Audit modules for tst-audit24b. |
2 | Copyright (C) 2022 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 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <link.h> |
20 | #include <inttypes.h> |
21 | #include <stdlib.h> |
22 | #include <string.h> |
23 | #include <tst-auditmod24.h> |
24 | |
25 | #define TEST_NAME "tst-audit24b" |
26 | #define TEST_FUNC "tst_audit24b" |
27 | |
28 | #define AUDIT24_COOKIE 0x1 |
29 | #define AUDIT24MOD1_COOKIE 0x2 |
30 | #define AUDIT24MOD2_COOKIE 0x3 |
31 | |
32 | unsigned int |
33 | la_version (unsigned int version) |
34 | { |
35 | return LAV_CURRENT; |
36 | } |
37 | |
38 | unsigned int |
39 | la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie) |
40 | { |
41 | const char *p = strrchr (s: map->l_name, c: '/'); |
42 | const char *l_name = p == NULL ? TEST_NAME : p + 1; |
43 | |
44 | uintptr_t ck = -1; |
45 | if (strcmp (s1: l_name, TEST_NAME "mod1.so" ) == 0) |
46 | ck = AUDIT24MOD1_COOKIE; |
47 | else if (strcmp (s1: l_name, TEST_NAME "mod2.so" ) == 0) |
48 | ck = AUDIT24MOD2_COOKIE; |
49 | else if (strcmp (s1: l_name, TEST_NAME) == 0) |
50 | ck = AUDIT24_COOKIE; |
51 | |
52 | *cookie = ck; |
53 | return ck == -1 ? 0 : LA_FLG_BINDFROM | LA_FLG_BINDTO; |
54 | } |
55 | |
56 | static int |
57 | tst_func1 (void) |
58 | { |
59 | return 1; |
60 | } |
61 | |
62 | static int |
63 | tst_func2 (void) |
64 | { |
65 | return 2; |
66 | } |
67 | |
68 | #if __ELF_NATIVE_CLASS == 64 |
69 | uintptr_t |
70 | la_symbind64 (Elf64_Sym *sym, unsigned int ndx, |
71 | uintptr_t *refcook, uintptr_t *defcook, |
72 | unsigned int *flags, const char *symname) |
73 | #else |
74 | uintptr_t |
75 | la_symbind32 (Elf32_Sym *sym, unsigned int ndx, |
76 | uintptr_t *refcook, uintptr_t *defcook, |
77 | unsigned int *flags, const char *symname) |
78 | #endif |
79 | { |
80 | if (*refcook == AUDIT24_COOKIE) |
81 | { |
82 | if (*defcook == AUDIT24MOD1_COOKIE) |
83 | { |
84 | if (strcmp (s1: symname, TEST_FUNC "mod1_func1" ) == 0) |
85 | return (uintptr_t) tst_func1; |
86 | else if (strcmp (s1: symname, TEST_FUNC "mod1_func2" ) == 0) |
87 | return sym->st_value; |
88 | abort (); |
89 | } |
90 | /* malloc functions. */ |
91 | return sym->st_value; |
92 | } |
93 | else if (*refcook == AUDIT24MOD1_COOKIE) |
94 | { |
95 | if (*defcook == AUDIT24MOD2_COOKIE |
96 | && (strcmp (s1: symname, TEST_FUNC "mod2_func1" ) == 0)) |
97 | { |
98 | test_symbind_flags (flags: *flags); |
99 | return (uintptr_t) tst_func2; |
100 | } |
101 | } |
102 | |
103 | abort (); |
104 | } |
105 | |