err.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef __TOOLS_LINUX_ERR_H
  2. #define __TOOLS_LINUX_ERR_H
  3. #include <linux/compiler.h>
  4. #include <linux/types.h>
  5. #include <asm/errno.h>
  6. /*
  7. * Original kernel header comment:
  8. *
  9. * Kernel pointers have redundant information, so we can use a
  10. * scheme where we can return either an error code or a normal
  11. * pointer with the same return value.
  12. *
  13. * This should be a per-architecture thing, to allow different
  14. * error and pointer decisions.
  15. *
  16. * Userspace note:
  17. * The same principle works for userspace, because 'error' pointers
  18. * fall down to the unused hole far from user space, as described
  19. * in Documentation/x86/x86_64/mm.txt for x86_64 arch:
  20. *
  21. * 0000000000000000 - 00007fffffffffff (=47 bits) user space, different per mm hole caused by [48:63] sign extension
  22. * ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole
  23. *
  24. * It should be the same case for other architectures, because
  25. * this code is used in generic kernel code.
  26. */
  27. #define MAX_ERRNO 4095
  28. #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
  29. static inline void * __must_check ERR_PTR(long error_)
  30. {
  31. return (void *) error_;
  32. }
  33. static inline long __must_check PTR_ERR(__force const void *ptr)
  34. {
  35. return (long) ptr;
  36. }
  37. static inline bool __must_check IS_ERR(__force const void *ptr)
  38. {
  39. return IS_ERR_VALUE((unsigned long)ptr);
  40. }
  41. #endif /* _LINUX_ERR_H */