rbpf icon indicating copy to clipboard operation
rbpf copied to clipboard

Instruction stack data structure

Open alex-dukhno opened this issue 8 years ago • 1 comments

Working on #6, looking at #10, #9 and #8. I see that we have a lack of high-level stack of bpf instructions. Personally, I see it as the following:

struct InsnStack {
   head: RefToInsn // points on the first instruction that will be executed
   tail: RefToInsn // points on `exit` instuction, unless it is an invalid bpf program
}

impl InsnStack {
   pub fn create() -> Self {
       //...
   }

   pub fn disassemble() -> String {
       //...
   }

   //may be a bunch of functions from #6 ... I am ok if we remove `insn_builder` module

   pub fn patch(patch: MbuffStructure) {
       //...
   }

   pub fn validate() -> Result<ValidInsnStack, ValidationError> { // <- the same as InsnStack but `tail` always points to `exit` Insn :smile:
       //...
   }
}

pub fn parse_assemble(raw_bpf_asm: String) -> InsnStack {
   //...
}

RefToInsn can be any type of reference, however, we could not use Box here. Having that structure we can provide API to easily manipulate its content.

@qmonnet, thoughts?

PS1: again as in #12 we need to do some prototype here. PS2: I also don't like that we have the bunch of different structures that in some or other way represent bpf instruction, but I don't see the solution to this problem right now.

alex-dukhno avatar Mar 05 '17 15:03 alex-dukhno

Hi, having this kind of structure to unify program handling seems a good thing. Thanks for proposing!

Apart from the .patch() use case—for which we might have to change the number of instructions if we ever get something good enough in the future—what would we earn with a stack over some vector / array of instructions as we had this far?

qmonnet avatar Mar 05 '17 17:03 qmonnet