kprobe /* Put 0 (the map key) on the stack */ BPF_ST_MEM(BPF_W, BPF_REG_10, -4, 0), /* Put frame pointer into R2 */ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), /* Decrement pointer by four */ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -4), /* Put map_fd into R1 */ BPF_LD_MAP_FD(BPF_REG_1, map_fd), /* Load current count from map into R0 */ BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem), /* If returned value NULL, skip two instructions and exit */ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2), /* Put 1 into R1 */ BPF_MOV64_IMM(BPF_REG_1, 1), /* Increment value by 1 */ BPF_RAW_INSN(BPF_STX | BPF_XADD | BPF_W, BPF_REG_0, BPF_REG_1, 0, 0), BPF_EXIT_INSN(), https://kinvolk.io/blog/2016/11/introducing-gobpf---using-ebpf-from-go/