kernel.h 752 B

1234567891011121314151617181920212223242526272829
  1. #ifndef PERF_LINUX_KERNEL_H_
  2. #define PERF_LINUX_KERNEL_H_
  3. #ifndef offsetof
  4. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  5. #endif
  6. #ifndef container_of
  7. /**
  8. * container_of - cast a member of a structure out to the containing structure
  9. * @ptr: the pointer to the member.
  10. * @type: the type of the container struct this is embedded in.
  11. * @member: the name of the member within the struct.
  12. *
  13. */
  14. #define container_of(ptr, type, member) ({ \
  15. const typeof(((type *)0)->member) * __mptr = (ptr); \
  16. (type *)((char *)__mptr - offsetof(type, member)); })
  17. #endif
  18. #ifndef max
  19. #define max(x, y) ({ \
  20. typeof(x) _max1 = (x); \
  21. typeof(y) _max2 = (y); \
  22. (void) (&_max1 == &_max2); \
  23. _max1 > _max2 ? _max1 : _max2; })
  24. #endif
  25. #endif