Skip to content

Instantly share code, notes, and snippets.

@drakenclimber
Last active April 15, 2022 16:00
Show Gist options
  • Save drakenclimber/f7fa143f18ab394255e4c69514f3129a to your computer and use it in GitHub Desktop.
Save drakenclimber/f7fa143f18ab394255e4c69514f3129a to your computer and use it in GitHub Desktop.
print libseccomp bpf_blks
static void print_instr(struct bpf_instr *instr)
{
fprintf(stdout, "\t\t\t\top = 0x%x\n", instr->op);
fprintf(stdout, "\t\t\t\tjt type = %d hash = 0x%lx\n", instr->jt.type,
instr->jt.tgt.hash);
fprintf(stdout, "\t\t\t\tjf type = %d hash = 0x%lx\n", instr->jf.type,
instr->jf.tgt.hash);
fprintf(stdout, "\t\t\t\tk type = %d hash = 0x%lx\n", instr->k.type,
instr->k.tgt.hash);
}
static void print_blk(struct bpf_blk *b_cur)
{
int blk_cnt = 0;
fprintf(stdout, "\t\t--------bpf_blk %p--------\n", b_cur);
fprintf(stdout, "\t\t\tblk_cnt = %d blk_alloc = %d hash = 0x%lx\n",
b_cur->blk_cnt, b_cur->blk_alloc,
b_cur->hash);
for (blk_cnt = 0; blk_cnt < b_cur->blk_cnt; blk_cnt++) {
fprintf(stdout, "\t\t\t--------instr %d--------\n",
blk_cnt);
print_instr(&b_cur->blks[blk_cnt]);
}
fprintf(stdout, "\t\t\tlvl_prv = %p lvl_nxt = %p\n",
b_cur->lvl_prv, b_cur->lvl_nxt);
fprintf(stdout, "\t\t\tprev = %p next = %p\n",
b_cur->prev, b_cur->next);
}
static void print_blks(struct bpf_blk *b_head)
{
struct bpf_blk *b_cur = b_head;
fprintf(stdout, "--------b_head = %p--------\n", b_head);
fprintf(stdout, "\t--------next chain--------\n");
b_cur = b_head;
while (b_cur != NULL) {
print_blk(b_cur);
b_cur = b_cur->next;
}
fprintf(stdout, "\t--------prev chain--------\n");
b_cur = b_head;
while (b_cur != NULL) {
print_blk(b_cur);
b_cur = b_cur->prev;
}
fprintf(stdout, "\t--------lvl prv chain--------\n");
b_cur = b_head;
while (b_cur != NULL) {
print_blk(b_cur);
b_cur = b_cur->lvl_prv;
}
fprintf(stdout, "\t--------lvl nxt chain--------\n");
b_cur = b_head;
while (b_cur != NULL) {
print_blk(b_cur);
b_cur = b_cur->lvl_nxt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment