Re: libbpf ringbuffer callback prototype

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 7, 2023 at 1:09 PM Martin Kelly
<martin.kelly@xxxxxxxxxxxxxxx> wrote:
>
> 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.

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.


>
> Thanks,
>
> Martin
>
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux