#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
int main(void);
struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(max_entries, 1);
__uint(key_size, sizeof(__u32));
__array(values, void (void));
} jmp_table SEC(".maps") = {
.values = {
[0] = (void *) &main,
},
};
__noinline __auxiliary
static __naked int sub(void)
{
asm volatile (
"r2 = %[jmp_table] ll;"
"r3 = 0;"
"call 12;"
"exit;"
:
: __imm_addr(jmp_table)
: __clobber_all);
}
__success
__arch_x86_64
__jited(" endbr64")
__jited(" nopl (%rax,%rax)")
__jited(" xorq %rax, %rax")
__jited(" pushq %rbp")
__jited(" movq %rsp, %rbp")
__jited(" endbr64")
__jited(" cmpq $0x21, %rax")
__jited(" ja L0")
__jited(" pushq %rax")
__jited(" movq %rsp, %rax")
__jited(" jmp L1")
__jited("L0: pushq %rax")
__jited("L1: pushq %rax")
__jited(" movq -0x10(%rbp), %rax")
__jited(" callq 0x{{.*}}")
__jited(" xorl %eax, %eax")
__jited(" leave")
__jited(" {{(retq|jmp 0x)}}")
__jited("...")
__jited(" endbr64")
__jited(" nopl (%rax,%rax)")
__jited(" nopl (%rax)")
__jited(" pushq %rbp")
__jited(" movq %rsp, %rbp")
__jited(" endbr64")
__jited(" pushq %rax")
__jited(" pushq %rax")
__jited(" movabsq ${{.*}}, %rsi")
__jited(" xorl %edx, %edx")
__jited(" movq -0x10(%rbp), %rax")
__jited(" cmpq $0x21, (%rax)")
__jited(" jae L0")
__jited(" nopl (%rax,%rax)")
__jited(" addq $0x1, (%rax)")
__jited(" popq %rax")
__jited(" popq %rax")
__jited(" jmp {{.*}}")
__jited("L0: leave")
__jited(" {{(retq|jmp 0x)}}")
SEC("tc")
__naked int main(void)
{
asm volatile (
"call %[sub];"
"r0 = 0;"
"exit;"
:
: __imm(sub)
: __clobber_all);
}
char __license[] SEC("license") = "GPL";