blob: 80ca61058dd20b9f1234bbec0c9c7431eabb1293 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_GENERIC_ERROR_INJECTION_H
3#define _ASM_GENERIC_ERROR_INJECTION_H
4
5#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
6enum {
7 EI_ETYPE_NONE, /* Dummy value for undefined case */
8 EI_ETYPE_NULL, /* Return NULL if failure */
9 EI_ETYPE_ERRNO, /* Return -ERRNO if failure */
10 EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */
David Brazdil0f672f62019-12-10 10:32:29 +000011 EI_ETYPE_TRUE, /* Return true if failure */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000012};
13
14struct error_injection_entry {
15 unsigned long addr;
16 int etype;
17};
18
David Brazdil0f672f62019-12-10 10:32:29 +000019struct pt_regs;
20
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000021#ifdef CONFIG_FUNCTION_ERROR_INJECTION
22/*
23 * Whitelist ganerating macro. Specify functions which can be
24 * error-injectable using this macro.
25 */
26#define ALLOW_ERROR_INJECTION(fname, _etype) \
27static struct error_injection_entry __used \
28 __attribute__((__section__("_error_injection_whitelist"))) \
29 _eil_addr_##fname = { \
30 .addr = (unsigned long)fname, \
31 .etype = EI_ETYPE_##_etype, \
32 };
David Brazdil0f672f62019-12-10 10:32:29 +000033
34void override_function_with_return(struct pt_regs *regs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000035#else
36#define ALLOW_ERROR_INJECTION(fname, _etype)
David Brazdil0f672f62019-12-10 10:32:29 +000037
38static inline void override_function_with_return(struct pt_regs *regs) { }
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039#endif
40#endif
41
42#endif /* _ASM_GENERIC_ERROR_INJECTION_H */