Comment by ziml77

Comment by ziml77 2 days ago

3 replies

Your code emits a compiler warning about casting an integer to a pointer. Changing the cast to void* emits a slightly different warning about the size of integer being cast to a pointer being smaller than the pointer type. Casting to a long and then a void* avoids both of these warnings.

fn-mote 18 hours ago

Sorry, all that stuff might be true but this whole process is nuts.

The code segment containing that code looks like a no-op.

The rest of the post seems sane and well informed, so my theory is that this is a C / packet filtering idiom I’m not aware of, working far from that field.

Otherwise I’m already freaked out by treating a 32 bit field as a pointer… even if you extend it to first.

  • foxmoss 17 hours ago

    > Otherwise I’m already freaked out by treating a 32 bit field as a pointer… even if you extend it to first.

    The cast from a 32 bit pointer to a 64 bit pointer is in fact an eBPF oddity. So what's happening here is that the virtual machine is just giving us a fake memory address just to use in the program and when the read actually needs to happen the kernel just rewrites the virtual addresses to the real ones. I'm assuming this is just a byproduct of the memory separation that eBPF does to prevent filters from accidentally reading kernel memory.

    Also yes the double cast is just to keep the compiler from throwing a warning.

  • mbac32768 18 hours ago

    Yeah it's freaky. It's C code but it targets the eBPF virtual machine.