.. | .. |
---|
42 | 42 | /* |
---|
43 | 43 | * Helper macro to manipulate data structures |
---|
44 | 44 | */ |
---|
45 | | -#ifndef offsetof |
---|
46 | | -#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER) |
---|
47 | | -#endif |
---|
48 | | -#ifndef container_of |
---|
| 45 | + |
---|
| 46 | +/* offsetof() definition that uses __builtin_offset() might not preserve field |
---|
| 47 | + * offset CO-RE relocation properly, so force-redefine offsetof() using |
---|
| 48 | + * old-school approach which works with CO-RE correctly |
---|
| 49 | + */ |
---|
| 50 | +#undef offsetof |
---|
| 51 | +#define offsetof(type, member) ((unsigned long)&((type *)0)->member) |
---|
| 52 | + |
---|
| 53 | +/* redefined container_of() to ensure we use the above offsetof() macro */ |
---|
| 54 | +#undef container_of |
---|
49 | 55 | #define container_of(ptr, type, member) \ |
---|
50 | 56 | ({ \ |
---|
51 | 57 | void *__mptr = (void *)(ptr); \ |
---|
52 | 58 | ((type *)(__mptr - offsetof(type, member))); \ |
---|
53 | 59 | }) |
---|
54 | | -#endif |
---|
55 | 60 | |
---|
56 | 61 | /* |
---|
57 | 62 | * Helper macro to throw a compilation error if __bpf_unreachable() gets |
---|