error-injection.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_NONE, /* Dummy value for undefined case */
  7. EI_ETYPE_NULL, /* Return NULL if failure */
  8. EI_ETYPE_ERRNO, /* Return -ERRNO if failure */
  9. EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */
  10. EI_ETYPE_TRUE, /* Return true if failure */
  11. };
  12. struct error_injection_entry {
  13. unsigned long addr;
  14. int etype;
  15. };
  16. struct pt_regs;
  17. #ifdef CONFIG_FUNCTION_ERROR_INJECTION
  18. /*
  19. * Whitelist generating macro. Specify functions which can be
  20. * error-injectable using this macro.
  21. */
  22. #define ALLOW_ERROR_INJECTION(fname, _etype) \
  23. static struct error_injection_entry __used \
  24. __section("_error_injection_whitelist") \
  25. _eil_addr_##fname = { \
  26. .addr = (unsigned long)fname, \
  27. .etype = EI_ETYPE_##_etype, \
  28. }
  29. void override_function_with_return(struct pt_regs *regs);
  30. #else
  31. #define ALLOW_ERROR_INJECTION(fname, _etype)
  32. static inline void override_function_with_return(struct pt_regs *regs) { }
  33. #endif
  34. #endif
  35. #endif /* _ASM_GENERIC_ERROR_INJECTION_H */