error-injection.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_GENERIC_ERROR_INJECTION_H
  3. #define _ASM_GENERIC_ERROR_INJECTION_H
  4. #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
  5. enum {
  6. EI_ETYPE_NULL, /* Return NULL if failure */
  7. EI_ETYPE_ERRNO, /* Return -ERRNO if failure */
  8. EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */
  9. EI_ETYPE_TRUE, /* Return true if failure */
  10. };
  11. struct error_injection_entry {
  12. unsigned long addr;
  13. int etype;
  14. };
  15. struct pt_regs;
  16. #ifdef CONFIG_FUNCTION_ERROR_INJECTION
  17. /*
  18. * Whitelist generating macro. Specify functions which can be error-injectable
  19. * using this macro. If you unsure what is required for the error-injectable
  20. * functions, please read Documentation/fault-injection/fault-injection.rst
  21. * 'Error Injectable Functions' section.
  22. */
  23. #define ALLOW_ERROR_INJECTION(fname, _etype) \
  24. static struct error_injection_entry __used \
  25. __section("_error_injection_whitelist") \
  26. _eil_addr_##fname = { \
  27. .addr = (unsigned long)fname, \
  28. .etype = EI_ETYPE_##_etype, \
  29. }
  30. void override_function_with_return(struct pt_regs *regs);
  31. #else
  32. #define ALLOW_ERROR_INJECTION(fname, _etype)
  33. static inline void override_function_with_return(struct pt_regs *regs) { }
  34. #endif
  35. #endif
  36. #endif /* _ASM_GENERIC_ERROR_INJECTION_H */