]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* Macros for using symbol sets for running lists of functions. |
dff8da6b | 2 | Copyright (C) 1994-2024 Free Software Foundation, Inc. |
5107cf1d | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
5107cf1d | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 9 | |
5107cf1d UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
18 | |
19 | #ifndef _SET_HOOKS_H | |
5107cf1d | 20 | #define _SET_HOOKS_H 1 |
28f540f4 RM |
21 | |
22 | #define __need_size_t | |
23 | #include <stddef.h> | |
24 | #include <sys/cdefs.h> | |
2827ab99 | 25 | #include <libc-symbols.h> |
28f540f4 | 26 | |
ae49f218 ST |
27 | #include "set-hooks-arch.h" |
28 | ||
a808d541 | 29 | #ifdef symbol_set_define |
28f540f4 RM |
30 | /* Define a hook variable called NAME. Functions put on this hook take |
31 | arguments described by PROTO. Use `text_set_element (NAME, FUNCTION)' | |
2827ab99 | 32 | from include/libc-symbols.h to add a function to the hook. */ |
28f540f4 | 33 | |
a808d541 | 34 | # define DEFINE_HOOK(NAME, PROTO) \ |
28f540f4 RM |
35 | typedef void __##NAME##_hook_function_t PROTO; \ |
36 | symbol_set_define (NAME) | |
37 | ||
a808d541 | 38 | # define DECLARE_HOOK(NAME, PROTO) \ |
28f540f4 RM |
39 | typedef void __##NAME##_hook_function_t PROTO;\ |
40 | symbol_set_declare (NAME) | |
41 | ||
42 | /* Run all the functions hooked on the set called NAME. | |
43 | Each function is called like this: `function ARGS'. */ | |
44 | ||
dd9423a6 UD |
45 | # define RUN_HOOK(NAME, ARGS) \ |
46 | do { \ | |
70d9946a | 47 | void *const *ptr; \ |
dd9423a6 UD |
48 | for (ptr = (void *const *) symbol_set_first_element (NAME); \ |
49 | ! symbol_set_end_p (NAME, ptr); ++ptr) \ | |
50 | (*(__##NAME##_hook_function_t *) *ptr) ARGS; \ | |
28f540f4 RM |
51 | } while (0) |
52 | ||
53 | /* Define a hook variable with NAME and PROTO, and a function called RUNNER | |
54 | which calls each function on the hook in turn, with ARGS. */ | |
55 | ||
a808d541 | 56 | # define DEFINE_HOOK_RUNNER(name, runner, proto, args) \ |
17427edd UD |
57 | DEFINE_HOOK (name, proto); \ |
58 | extern void runner proto; void runner proto { RUN_HOOK (name, args); } | |
28f540f4 | 59 | |
ae49f218 ST |
60 | # ifdef SET_RELHOOK |
61 | /* This is similar to RUN_RELHOOK, but the hooks were registered with | |
62 | * SET_RELHOOK so that a relative offset was computed by the linker | |
63 | * rather than an absolute address by the dynamic linker. */ | |
64 | # define RUN_RELHOOK(NAME, ARGS) \ | |
65 | do { \ | |
66 | void *const *ptr; \ | |
67 | for (ptr = (void *const *) symbol_set_first_element (NAME); \ | |
68 | ! symbol_set_end_p (NAME, ptr); ++ptr) { \ | |
69 | __##NAME##_hook_function_t *f = \ | |
70 | (void*) ((uintptr_t) ptr + (ptrdiff_t) *ptr); \ | |
71 | (*f) ARGS; \ | |
72 | } \ | |
73 | } while (0) | |
74 | # else | |
75 | # define SET_RELHOOK(NAME, HOOK) text_set_element (NAME, HOOK) | |
76 | # define RUN_RELHOOK(NAME, ARGS) RUN_HOOK(NAME, ARGS) | |
77 | # endif | |
78 | ||
a808d541 UD |
79 | #else |
80 | ||
81 | /* The system does not provide necessary support for this. */ | |
82 | # define DEFINE_HOOK(NAME, PROTO) | |
83 | ||
84 | # define DECLARE_HOOK(NAME, PROTO) | |
85 | ||
86 | # define RUN_HOOK(NAME, ARGS) | |
87 | ||
88 | # define DEFINE_HOOK_RUNNER(name, runner, proto, args) | |
89 | ||
ae49f218 ST |
90 | # define SET_RELHOOK(NAME, HOOK) |
91 | ||
92 | # define RUN_RELHOOK(NAME, ARGS) | |
93 | ||
a808d541 | 94 | #endif |
28f540f4 | 95 | |
5107cf1d | 96 | #endif /* set-hooks.h */ |