Re: [PATCH RFC bpf-next 03/10] bpf: Add proto of bpf_core_apply_relo()

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

 



On Thu, Sep 23, 2021 at 4:22 AM Lorenz Bauer <lmb@xxxxxxxxxxxxxx> wrote:
>
> On Fri, 17 Sept 2021 at 22:57, Alexei Starovoitov
> <alexei.starovoitov@xxxxxxxxx> wrote:
> >
> > From: Alexei Starovoitov <ast@xxxxxxxxxx>
> >
> > Prototype of bpf_core_apply_relo() helper.
> >
> > Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
>
> ...
>
> > @@ -6313,4 +6321,10 @@ enum bpf_core_relo_kind {
> >         BPF_CORE_ENUMVAL_VALUE = 11,         /* enum value integer value */
> >  };
> >
> > +struct bpf_core_relo_desc {
> > +       __u32 type_id;
> > +       __u32 access_str_off;
> > +       enum bpf_core_relo_kind kind;
>
> Not a C expert, I thought enums don't have a fixed size?

They are backed by int (4 bytes) in C, unless values don't fit into
int, then it's long long (or unsigned variants of int or long long).
The only exception is when it's used in a packed struct, then field
will get allocated only as little space as necessary to keep all
values (so could be byte or two bytes). You can also have a
bitfield-backed enum field in a struct, but enum itself is still going
to be of whole and power-of-two of number of bytes.

So long story short, here it's 4 bytes and will stay 4 bytes.

C++ gives more flexibility and you can actually specify backing
integer type. Not the case for C, though.

>
> --
> Lorenz Bauer  |  Systems Engineer
> 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK
>
> www.cloudflare.com



[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