]> git.ipfire.org Git - thirdparty/glibc.git/blame - include/set-hooks.h
Correct range checking in mallopt/mxfast/tcache [BZ #25194]
[thirdparty/glibc.git] / include / set-hooks.h
CommitLineData
28f540f4 1/* Macros for using symbol sets for running lists of functions.
04277e02 2 Copyright (C) 1994-2019 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
a808d541 27#ifdef symbol_set_define
28f540f4
RM
28/* Define a hook variable called NAME. Functions put on this hook take
29 arguments described by PROTO. Use `text_set_element (NAME, FUNCTION)'
2827ab99 30 from include/libc-symbols.h to add a function to the hook. */
28f540f4 31
a808d541 32# define DEFINE_HOOK(NAME, PROTO) \
28f540f4
RM
33 typedef void __##NAME##_hook_function_t PROTO; \
34 symbol_set_define (NAME)
35
a808d541 36# define DECLARE_HOOK(NAME, PROTO) \
28f540f4
RM
37 typedef void __##NAME##_hook_function_t PROTO;\
38 symbol_set_declare (NAME)
39
40/* Run all the functions hooked on the set called NAME.
41 Each function is called like this: `function ARGS'. */
42
dd9423a6
UD
43# define RUN_HOOK(NAME, ARGS) \
44do { \
70d9946a 45 void *const *ptr; \
dd9423a6
UD
46 for (ptr = (void *const *) symbol_set_first_element (NAME); \
47 ! symbol_set_end_p (NAME, ptr); ++ptr) \
48 (*(__##NAME##_hook_function_t *) *ptr) ARGS; \
28f540f4
RM
49} while (0)
50
51/* Define a hook variable with NAME and PROTO, and a function called RUNNER
52 which calls each function on the hook in turn, with ARGS. */
53
a808d541 54# define DEFINE_HOOK_RUNNER(name, runner, proto, args) \
17427edd
UD
55DEFINE_HOOK (name, proto); \
56extern void runner proto; void runner proto { RUN_HOOK (name, args); }
28f540f4 57
a808d541
UD
58#else
59
60/* The system does not provide necessary support for this. */
61# define DEFINE_HOOK(NAME, PROTO)
62
63# define DECLARE_HOOK(NAME, PROTO)
64
65# define RUN_HOOK(NAME, ARGS)
66
67# define DEFINE_HOOK_RUNNER(name, runner, proto, args)
68
69#endif
28f540f4 70
5107cf1d 71#endif /* set-hooks.h */