libbpf ringbuffer callback prototype
I noticed that the data pointer in the libbpf ringbuffer callback has type void *, without const:
typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size);
However, if you actually try to write to this data, you'll get a SIGSEGV.
It seems to me the prototype should ideally be const void * so the compiler can throw -Wdiscarded-qualifiers if someone tries to assign it to a non-const type. I'm not sure there's anything to be done about it, as changing it now would break the API. However, I wanted to mention it just in case anyone has thoughts about this.
Thanks,
Martin
Quoted 6 lines · Martin Kelly
I noticed that the data pointer in the libbpf ringbuffer callback has type void *, without const:
typedef int (*ring_buffer_sample_fn)(void *ctx, void *data,
size_tsize);
Quoted 7 lines
However, if you actually try to write to this data, you'll get a SIGSEGV.
It seems to me the prototype should ideally be const void * so the compiler can throw -Wdiscarded-qualifiers if someone tries to assign it to a non-const type. I'm not sure there's anything to be done about it, as changing it now would break the API. However, I wanted to mention it just in case anyone has thoughts about this.
Yeah, that's an unfortunate omission... Kernel never allowed to mmap data area as writable, so there is no way to ever write anything back through this pointer.
But as you said, adding that const in a callback type would cause compilation error for every single customer. So it seems just not worth it at this point.
Quoted 6 lines
Thanks,
Martin