diff --git a/external/ebpf-verifier b/external/ebpf-verifier index e4750ee30e..5195871ef0 160000 --- a/external/ebpf-verifier +++ b/external/ebpf-verifier @@ -1 +1 @@ -Subproject commit e4750ee30efe6b3634621735f63038d7d8d3ae05 +Subproject commit 5195871ef08e3d328bd1f948d864f09f0197414b diff --git a/libs/api/crab_verifier_wrapper.hpp b/libs/api/crab_verifier_wrapper.hpp deleted file mode 100644 index 9e8969327f..0000000000 --- a/libs/api/crab_verifier_wrapper.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) eBPF for Windows contributors -// SPDX-License-Identifier: MIT - -#pragma warning(push) -#pragma warning(disable : 4100) // 'identifier' : unreferenced formal parameter -#pragma warning(disable : 4244) // 'conversion' conversion from 'type1' to - // 'type2', possible loss of data -#pragma warning(disable : 4267) // conversion from 'size_t' to 'int', possible loss of data -#pragma warning(disable : 26451) // Arithmetic overflow -#pragma warning(disable : 26450) // Arithmetic overflow -#pragma warning(disable : 26450) // Arithmetic overflow -#pragma warning(disable : 26439) // This kind of function may not - // throw. Declare it 'noexcept' -#pragma warning(disable : 26495) // Always initialize a member variable -#undef FALSE -#undef TRUE -#undef min -#undef max -#include "crab_verifier.hpp" -#pragma warning(pop) diff --git a/libs/api/windows_platform.cpp b/libs/api/windows_platform.cpp index 0ab1a1a94e..22a8769797 100644 --- a/libs/api/windows_platform.cpp +++ b/libs/api/windows_platform.cpp @@ -3,8 +3,8 @@ #include "api_common.hpp" #include "api_internal.h" -#include "crab_verifier_wrapper.hpp" #include "ebpf_api.h" +#include "ebpf_verifier_wrapper.hpp" #include "helpers.hpp" #include "map_descriptors.hpp" #include "platform.hpp" diff --git a/libs/api_common/api_common.cpp b/libs/api_common/api_common.cpp index a622e1103b..a8ea22b1c5 100644 --- a/libs/api_common/api_common.cpp +++ b/libs/api_common/api_common.cpp @@ -175,13 +175,13 @@ ebpf_verify_program( const cfg_t cfg = prepare_cfg(prog, info, options.cfg_opts); auto invariants = analyze(cfg); if (options.verbosity_opts.print_invariants) { - invariants.print_invariants(os, cfg); + print_invariants(os, cfg, options.verbosity_opts.simplify, invariants); } bool pass; if (options.verbosity_opts.print_failures) { auto report = invariants.check_assertions(cfg); thread_local_options.verbosity_opts.print_line_info = true; - report.print_warnings(os); + print_warnings(os, report); pass = report.verified(); stats->total_warnings = (int)report.warning_set().size(); stats->total_unreachable = (int)report.reachability_set().size(); @@ -194,4 +194,4 @@ ebpf_verify_program( os << "error: " << e.what() << std::endl; return false; } -} \ No newline at end of file +} diff --git a/libs/api_common/ebpf_verifier_wrapper.hpp b/libs/api_common/ebpf_verifier_wrapper.hpp index 5eca8c54cd..0d98be1a59 100644 --- a/libs/api_common/ebpf_verifier_wrapper.hpp +++ b/libs/api_common/ebpf_verifier_wrapper.hpp @@ -6,10 +6,11 @@ #pragma warning(disable : 4244) // 'conversion' conversion from 'type1' to // 'type2', possible loss of data #pragma warning(disable : 4267) // conversion from 'size_t' to 'int', possible loss of data -#pragma warning(disable : 26451) // Arithmetic overflow -#pragma warning(disable : 26450) // Arithmetic overflow +#pragma warning(disable : 4458) // declaration of 'warnings' hides class member #pragma warning(disable : 26439) // This kind of function may not // throw. Declare it 'noexcept' +#pragma warning(disable : 26450) // Arithmetic overflow +#pragma warning(disable : 26451) // Arithmetic overflow #pragma warning(disable : 26495) // Always initialize a member variable #undef FALSE #undef TRUE diff --git a/libs/api_common/windows_platform_common.cpp b/libs/api_common/windows_platform_common.cpp index 0e2dee76f8..9fd46ae194 100644 --- a/libs/api_common/windows_platform_common.cpp +++ b/libs/api_common/windows_platform_common.cpp @@ -3,13 +3,13 @@ #include "api_common.hpp" #include "api_internal.h" -#include "crab_verifier_wrapper.hpp" #include "device_helper.hpp" #include "ebpf_api.h" #include "ebpf_nethooks.h" #include "ebpf_protocol.h" #include "ebpf_serialize.h" #include "ebpf_store_helper.h" +#include "ebpf_verifier_wrapper.hpp" #include "helpers.hpp" #include "map_descriptors.hpp" #include "platform.hpp" diff --git a/libs/api_common/windows_program_type.h b/libs/api_common/windows_program_type.h index 4c5e7f996a..06b3185420 100644 --- a/libs/api_common/windows_program_type.h +++ b/libs/api_common/windows_program_type.h @@ -3,9 +3,9 @@ #pragma once -#include "crab_verifier_wrapper.hpp" #include "ebpf_nethooks.h" #include "ebpf_program_types.h" +#include "ebpf_verifier_wrapper.hpp" #define PTYPE(name, descr, native_type, prefixes) \ { \ diff --git a/libs/service/windows_platform_service.cpp b/libs/service/windows_platform_service.cpp index 7861ec597f..2a523189db 100644 --- a/libs/service/windows_platform_service.cpp +++ b/libs/service/windows_platform_service.cpp @@ -3,8 +3,8 @@ #include "api_common.hpp" #include "api_internal.h" -#include "crab_verifier_wrapper.hpp" #include "ebpf_api.h" +#include "ebpf_verifier_wrapper.hpp" #include "helpers.hpp" #include "platform.hpp" #include "spec_type_descriptors.hpp" diff --git a/tests/bpf2c_tests/elf_bpf.cpp b/tests/bpf2c_tests/elf_bpf.cpp index 4953cc097b..bf0646814e 100644 --- a/tests/bpf2c_tests/elf_bpf.cpp +++ b/tests/bpf2c_tests/elf_bpf.cpp @@ -198,6 +198,7 @@ run_test_elf(const std::string& elf_file, _test_mode test_mode, const std::optio DECLARE_TEST("atomic_instruction_fetch_add", _test_mode::Verify) DECLARE_TEST("bad_map_name", _test_mode::Verify) DECLARE_TEST("bindmonitor", _test_mode::Verify) +DECLARE_TEST("bindmonitor_bpf2bpf", _test_mode::Verify) DECLARE_TEST("bindmonitor_ringbuf", _test_mode::Verify) DECLARE_TEST("bindmonitor_tailcall", _test_mode::Verify) DECLARE_TEST("bindmonitor_mt_tailcall", _test_mode::Verify) diff --git a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_dll.c b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_dll.c index db48098b0a..5ea0aae2d0 100644 --- a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_dll.c +++ b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_dll.c @@ -48,7 +48,19 @@ _get_maps(_Outptr_result_buffer_maybenull_(*count) map_entry_t** maps, _Out_ siz // Forward references for local functions. static uint64_t -BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +BindMonitor_Callee1(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee2(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee3(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee4(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee5(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee6(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee7(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); static GUID BindMonitor_Caller_program_type_guid = { 0x608c517c, 0x6c52, 0x4a26, {0xb6, 0x77, 0xbb, 0x1c, 0x34, 0x42, 0x5a, 0xdf}}; @@ -57,195 +69,363 @@ static GUID BindMonitor_Caller_attach_type_guid = { #pragma code_seg(push, "bind") static uint64_t BindMonitor_Caller(void* context) -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" { -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" // Prologue. -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" uint64_t stack[(UBPF_STACK_SIZE + 7) / 8]; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r0 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r1 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r2 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r3 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r4 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r5 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r10 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r1 = (uintptr_t)context; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack)); // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-16 imm=0 -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)) = (uint64_t)r1; // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=204 -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(204); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-18 imm=0 -#line 31 "sample/bindmonitor_bpf2bpf.c" +#line 49 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-18)) = (uint8_t)r1; // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-17 imm=0 -#line 32 "sample/bindmonitor_bpf2bpf.c" +#line 50 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-17)) = (uint8_t)r1; // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-16 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)); // EBPF_OP_LDXDW pc=5 dst=r1 src=r1 offset=16 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r1 + OFFSET(16)); // EBPF_OP_STXDW pc=6 dst=r10 src=r1 offset=-32 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-32)) = (uint64_t)r1; // EBPF_OP_LDXDW pc=7 dst=r1 src=r10 offset=-16 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)); // EBPF_OP_ADD64_IMM pc=8 dst=r1 src=r0 offset=0 imm=16 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 += IMMEDIATE(16); // EBPF_OP_CALL pc=9 dst=r0 src=r1 offset=0 imm=35 -#line 35 "sample/bindmonitor_bpf2bpf.c" - r0 = BindMonitor_Callee(r1, r2, r3, r4, r5, r10, context); +#line 53 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee1(r1, r2, r3, r4, r5, r10, context); // EBPF_OP_LSH64_IMM pc=10 dst=r0 src=r0 offset=0 imm=32 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r0 <<= (IMMEDIATE(32) & 63); // EBPF_OP_RSH64_IMM pc=11 dst=r0 src=r0 offset=0 imm=32 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r0 >>= (IMMEDIATE(32) & 63); // EBPF_OP_JNE_IMM pc=12 dst=r0 src=r0 offset=5 imm=1 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" if (r0 != IMMEDIATE(1)) { -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" goto label_2; -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=13 dst=r0 src=r0 offset=0 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" goto label_1; label_1: // EBPF_OP_MOV64_IMM pc=14 dst=r1 src=r0 offset=0 imm=1 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=15 dst=r10 src=r1 offset=-4 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_STXW pc=16 dst=r10 src=r1 offset=-36 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=17 dst=r0 src=r0 offset=25 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_2: // EBPF_OP_LDXB pc=18 dst=r1 src=r10 offset=-18 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint8_t*)(uintptr_t)(r10 + OFFSET(-18)); // EBPF_OP_JNE_IMM pc=19 dst=r1 src=r0 offset=4 imm=204 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_4; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=20 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_3; label_3: // EBPF_OP_LDXB pc=21 dst=r1 src=r10 offset=-17 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint8_t*)(uintptr_t)(r10 + OFFSET(-17)); // EBPF_OP_JEQ_IMM pc=22 dst=r1 src=r0 offset=7 imm=204 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_5; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=23 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_4; label_4: // EBPF_OP_LDDW pc=24 dst=r1 src=r0 offset=0 imm=-1 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = (uint64_t)4294967295; // EBPF_OP_STXW pc=26 dst=r10 src=r1 offset=-4 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=27 dst=r1 src=r0 offset=0 imm=1 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=28 dst=r10 src=r1 offset=-36 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=29 dst=r0 src=r0 offset=13 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_5: // EBPF_OP_LDXDW pc=30 dst=r1 src=r10 offset=-32 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-32)); // EBPF_OP_JNE_IMM pc=31 dst=r1 src=r0 offset=6 imm=1 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(1)) { -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" goto label_7; -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=32 dst=r0 src=r0 offset=0 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" goto label_6; label_6: // EBPF_OP_MOV64_IMM pc=33 dst=r1 src=r0 offset=0 imm=2 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(2); // EBPF_OP_STXW pc=34 dst=r10 src=r1 offset=-4 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=35 dst=r1 src=r0 offset=0 imm=1 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=36 dst=r10 src=r1 offset=-36 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=37 dst=r0 src=r0 offset=5 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_7: // EBPF_OP_MOV64_IMM pc=38 dst=r1 src=r0 offset=0 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(0); // EBPF_OP_STXW pc=39 dst=r10 src=r1 offset=-4 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=40 dst=r1 src=r0 offset=0 imm=1 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=41 dst=r10 src=r1 offset=-36 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=42 dst=r0 src=r0 offset=0 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_8: // EBPF_OP_LDXW pc=43 dst=r0 src=r10 offset=-4 imm=0 -#line 49 "sample/bindmonitor_bpf2bpf.c" +#line 67 "sample/bindmonitor_bpf2bpf.c" r0 = *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)); // EBPF_OP_EXIT pc=44 dst=r0 src=r0 offset=0 imm=0 -#line 49 "sample/bindmonitor_bpf2bpf.c" +#line 67 "sample/bindmonitor_bpf2bpf.c" return r0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" } #pragma code_seg(pop) #line __LINE__ __FILE__ static uint64_t -BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +BindMonitor_Callee1(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=17 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(17); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee2(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee2(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=34 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(34); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee3(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee3(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=51 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(51); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee4(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee4(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=68 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(68); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee5(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee5(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=85 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(85); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee6(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee6(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=102 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(102); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee7(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee7(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) { register uint64_t r0 = 0; (void)r2; @@ -255,39 +435,39 @@ BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t (void)context; // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 -#line 51 "sample/bindmonitor_bpf2bpf.c" +#line 70 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; - // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=187 -#line 51 "sample/bindmonitor_bpf2bpf.c" - r1 = IMMEDIATE(187); + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=119 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(119); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 -#line 55 "sample/bindmonitor_bpf2bpf.c" +#line 74 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 -#line 56 "sample/bindmonitor_bpf2bpf.c" +#line 75 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); // EBPF_OP_LDXDW pc=5 dst=r1 src=r1 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r1 + OFFSET(0)); // EBPF_OP_MOV64_IMM pc=6 dst=r0 src=r0 offset=0 imm=1 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r0 = IMMEDIATE(1); // EBPF_OP_JEQ_IMM pc=7 dst=r1 src=r0 offset=1 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(0)) { -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" goto label_1; -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_MOV64_IMM pc=8 dst=r0 src=r0 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" r0 = IMMEDIATE(0); label_1: // EBPF_OP_EXIT pc=9 dst=r0 src=r0 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 85 "sample/bindmonitor_bpf2bpf.c" return r0; } #pragma data_seg(push, "programs") diff --git a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_raw.c b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_raw.c index 0ae8379ade..1d80cb015f 100644 --- a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_raw.c +++ b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_raw.c @@ -22,7 +22,19 @@ _get_maps(_Outptr_result_buffer_maybenull_(*count) map_entry_t** maps, _Out_ siz // Forward references for local functions. static uint64_t -BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +BindMonitor_Callee1(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee2(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee3(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee4(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee5(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee6(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee7(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); static GUID BindMonitor_Caller_program_type_guid = { 0x608c517c, 0x6c52, 0x4a26, {0xb6, 0x77, 0xbb, 0x1c, 0x34, 0x42, 0x5a, 0xdf}}; @@ -31,195 +43,363 @@ static GUID BindMonitor_Caller_attach_type_guid = { #pragma code_seg(push, "bind") static uint64_t BindMonitor_Caller(void* context) -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" { -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" // Prologue. -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" uint64_t stack[(UBPF_STACK_SIZE + 7) / 8]; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r0 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r1 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r2 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r3 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r4 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r5 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r10 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r1 = (uintptr_t)context; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack)); // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-16 imm=0 -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)) = (uint64_t)r1; // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=204 -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(204); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-18 imm=0 -#line 31 "sample/bindmonitor_bpf2bpf.c" +#line 49 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-18)) = (uint8_t)r1; // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-17 imm=0 -#line 32 "sample/bindmonitor_bpf2bpf.c" +#line 50 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-17)) = (uint8_t)r1; // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-16 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)); // EBPF_OP_LDXDW pc=5 dst=r1 src=r1 offset=16 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r1 + OFFSET(16)); // EBPF_OP_STXDW pc=6 dst=r10 src=r1 offset=-32 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-32)) = (uint64_t)r1; // EBPF_OP_LDXDW pc=7 dst=r1 src=r10 offset=-16 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)); // EBPF_OP_ADD64_IMM pc=8 dst=r1 src=r0 offset=0 imm=16 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 += IMMEDIATE(16); // EBPF_OP_CALL pc=9 dst=r0 src=r1 offset=0 imm=35 -#line 35 "sample/bindmonitor_bpf2bpf.c" - r0 = BindMonitor_Callee(r1, r2, r3, r4, r5, r10, context); +#line 53 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee1(r1, r2, r3, r4, r5, r10, context); // EBPF_OP_LSH64_IMM pc=10 dst=r0 src=r0 offset=0 imm=32 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r0 <<= (IMMEDIATE(32) & 63); // EBPF_OP_RSH64_IMM pc=11 dst=r0 src=r0 offset=0 imm=32 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r0 >>= (IMMEDIATE(32) & 63); // EBPF_OP_JNE_IMM pc=12 dst=r0 src=r0 offset=5 imm=1 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" if (r0 != IMMEDIATE(1)) { -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" goto label_2; -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=13 dst=r0 src=r0 offset=0 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" goto label_1; label_1: // EBPF_OP_MOV64_IMM pc=14 dst=r1 src=r0 offset=0 imm=1 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=15 dst=r10 src=r1 offset=-4 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_STXW pc=16 dst=r10 src=r1 offset=-36 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=17 dst=r0 src=r0 offset=25 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_2: // EBPF_OP_LDXB pc=18 dst=r1 src=r10 offset=-18 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint8_t*)(uintptr_t)(r10 + OFFSET(-18)); // EBPF_OP_JNE_IMM pc=19 dst=r1 src=r0 offset=4 imm=204 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_4; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=20 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_3; label_3: // EBPF_OP_LDXB pc=21 dst=r1 src=r10 offset=-17 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint8_t*)(uintptr_t)(r10 + OFFSET(-17)); // EBPF_OP_JEQ_IMM pc=22 dst=r1 src=r0 offset=7 imm=204 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_5; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=23 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_4; label_4: // EBPF_OP_LDDW pc=24 dst=r1 src=r0 offset=0 imm=-1 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = (uint64_t)4294967295; // EBPF_OP_STXW pc=26 dst=r10 src=r1 offset=-4 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=27 dst=r1 src=r0 offset=0 imm=1 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=28 dst=r10 src=r1 offset=-36 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=29 dst=r0 src=r0 offset=13 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_5: // EBPF_OP_LDXDW pc=30 dst=r1 src=r10 offset=-32 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-32)); // EBPF_OP_JNE_IMM pc=31 dst=r1 src=r0 offset=6 imm=1 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(1)) { -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" goto label_7; -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=32 dst=r0 src=r0 offset=0 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" goto label_6; label_6: // EBPF_OP_MOV64_IMM pc=33 dst=r1 src=r0 offset=0 imm=2 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(2); // EBPF_OP_STXW pc=34 dst=r10 src=r1 offset=-4 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=35 dst=r1 src=r0 offset=0 imm=1 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=36 dst=r10 src=r1 offset=-36 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=37 dst=r0 src=r0 offset=5 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_7: // EBPF_OP_MOV64_IMM pc=38 dst=r1 src=r0 offset=0 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(0); // EBPF_OP_STXW pc=39 dst=r10 src=r1 offset=-4 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=40 dst=r1 src=r0 offset=0 imm=1 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=41 dst=r10 src=r1 offset=-36 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=42 dst=r0 src=r0 offset=0 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_8: // EBPF_OP_LDXW pc=43 dst=r0 src=r10 offset=-4 imm=0 -#line 49 "sample/bindmonitor_bpf2bpf.c" +#line 67 "sample/bindmonitor_bpf2bpf.c" r0 = *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)); // EBPF_OP_EXIT pc=44 dst=r0 src=r0 offset=0 imm=0 -#line 49 "sample/bindmonitor_bpf2bpf.c" +#line 67 "sample/bindmonitor_bpf2bpf.c" return r0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" } #pragma code_seg(pop) #line __LINE__ __FILE__ static uint64_t -BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +BindMonitor_Callee1(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=17 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(17); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee2(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee2(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=34 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(34); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee3(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee3(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=51 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(51); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee4(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee4(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=68 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(68); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee5(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee5(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=85 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(85); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee6(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee6(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=102 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(102); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee7(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee7(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) { register uint64_t r0 = 0; (void)r2; @@ -229,39 +409,39 @@ BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t (void)context; // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 -#line 51 "sample/bindmonitor_bpf2bpf.c" +#line 70 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; - // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=187 -#line 51 "sample/bindmonitor_bpf2bpf.c" - r1 = IMMEDIATE(187); + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=119 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(119); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 -#line 55 "sample/bindmonitor_bpf2bpf.c" +#line 74 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 -#line 56 "sample/bindmonitor_bpf2bpf.c" +#line 75 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); // EBPF_OP_LDXDW pc=5 dst=r1 src=r1 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r1 + OFFSET(0)); // EBPF_OP_MOV64_IMM pc=6 dst=r0 src=r0 offset=0 imm=1 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r0 = IMMEDIATE(1); // EBPF_OP_JEQ_IMM pc=7 dst=r1 src=r0 offset=1 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(0)) { -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" goto label_1; -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_MOV64_IMM pc=8 dst=r0 src=r0 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" r0 = IMMEDIATE(0); label_1: // EBPF_OP_EXIT pc=9 dst=r0 src=r0 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 85 "sample/bindmonitor_bpf2bpf.c" return r0; } #pragma data_seg(push, "programs") diff --git a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_sys.c b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_sys.c index e94f6e90c5..ed7f42f507 100644 --- a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_sys.c +++ b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_sys.c @@ -183,7 +183,19 @@ _get_maps(_Outptr_result_buffer_maybenull_(*count) map_entry_t** maps, _Out_ siz // Forward references for local functions. static uint64_t -BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +BindMonitor_Callee1(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee2(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee3(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee4(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee5(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee6(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); +static uint64_t +BindMonitor_Callee7(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context); static GUID BindMonitor_Caller_program_type_guid = { 0x608c517c, 0x6c52, 0x4a26, {0xb6, 0x77, 0xbb, 0x1c, 0x34, 0x42, 0x5a, 0xdf}}; @@ -192,195 +204,363 @@ static GUID BindMonitor_Caller_attach_type_guid = { #pragma code_seg(push, "bind") static uint64_t BindMonitor_Caller(void* context) -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" { -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" // Prologue. -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" uint64_t stack[(UBPF_STACK_SIZE + 7) / 8]; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r0 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r1 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r2 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r3 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r4 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r5 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" register uint64_t r10 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r1 = (uintptr_t)context; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack)); // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-16 imm=0 -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)) = (uint64_t)r1; // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=204 -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(204); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-18 imm=0 -#line 31 "sample/bindmonitor_bpf2bpf.c" +#line 49 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-18)) = (uint8_t)r1; // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-17 imm=0 -#line 32 "sample/bindmonitor_bpf2bpf.c" +#line 50 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-17)) = (uint8_t)r1; // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-16 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)); // EBPF_OP_LDXDW pc=5 dst=r1 src=r1 offset=16 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r1 + OFFSET(16)); // EBPF_OP_STXDW pc=6 dst=r10 src=r1 offset=-32 imm=0 -#line 34 "sample/bindmonitor_bpf2bpf.c" +#line 52 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-32)) = (uint64_t)r1; // EBPF_OP_LDXDW pc=7 dst=r1 src=r10 offset=-16 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-16)); // EBPF_OP_ADD64_IMM pc=8 dst=r1 src=r0 offset=0 imm=16 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 += IMMEDIATE(16); // EBPF_OP_CALL pc=9 dst=r0 src=r1 offset=0 imm=35 -#line 35 "sample/bindmonitor_bpf2bpf.c" - r0 = BindMonitor_Callee(r1, r2, r3, r4, r5, r10, context); +#line 53 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee1(r1, r2, r3, r4, r5, r10, context); // EBPF_OP_LSH64_IMM pc=10 dst=r0 src=r0 offset=0 imm=32 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r0 <<= (IMMEDIATE(32) & 63); // EBPF_OP_RSH64_IMM pc=11 dst=r0 src=r0 offset=0 imm=32 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r0 >>= (IMMEDIATE(32) & 63); // EBPF_OP_JNE_IMM pc=12 dst=r0 src=r0 offset=5 imm=1 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" if (r0 != IMMEDIATE(1)) { -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" goto label_2; -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=13 dst=r0 src=r0 offset=0 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" goto label_1; label_1: // EBPF_OP_MOV64_IMM pc=14 dst=r1 src=r0 offset=0 imm=1 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 53 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=15 dst=r10 src=r1 offset=-4 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_STXW pc=16 dst=r10 src=r1 offset=-36 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=17 dst=r0 src=r0 offset=25 imm=0 -#line 36 "sample/bindmonitor_bpf2bpf.c" +#line 54 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_2: // EBPF_OP_LDXB pc=18 dst=r1 src=r10 offset=-18 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint8_t*)(uintptr_t)(r10 + OFFSET(-18)); // EBPF_OP_JNE_IMM pc=19 dst=r1 src=r0 offset=4 imm=204 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_4; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=20 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_3; label_3: // EBPF_OP_LDXB pc=21 dst=r1 src=r10 offset=-17 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint8_t*)(uintptr_t)(r10 + OFFSET(-17)); // EBPF_OP_JEQ_IMM pc=22 dst=r1 src=r0 offset=7 imm=204 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_5; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=23 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" goto label_4; label_4: // EBPF_OP_LDDW pc=24 dst=r1 src=r0 offset=0 imm=-1 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 58 "sample/bindmonitor_bpf2bpf.c" r1 = (uint64_t)4294967295; // EBPF_OP_STXW pc=26 dst=r10 src=r1 offset=-4 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=27 dst=r1 src=r0 offset=0 imm=1 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=28 dst=r10 src=r1 offset=-36 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=29 dst=r0 src=r0 offset=13 imm=0 -#line 41 "sample/bindmonitor_bpf2bpf.c" +#line 59 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_5: // EBPF_OP_LDXDW pc=30 dst=r1 src=r10 offset=-32 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-32)); // EBPF_OP_JNE_IMM pc=31 dst=r1 src=r0 offset=6 imm=1 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(1)) { -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" goto label_7; -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=32 dst=r0 src=r0 offset=0 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" goto label_6; label_6: // EBPF_OP_MOV64_IMM pc=33 dst=r1 src=r0 offset=0 imm=2 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 62 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(2); // EBPF_OP_STXW pc=34 dst=r10 src=r1 offset=-4 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=35 dst=r1 src=r0 offset=0 imm=1 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=36 dst=r10 src=r1 offset=-36 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=37 dst=r0 src=r0 offset=5 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_7: // EBPF_OP_MOV64_IMM pc=38 dst=r1 src=r0 offset=0 imm=0 -#line 46 "sample/bindmonitor_bpf2bpf.c" +#line 64 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(0); // EBPF_OP_STXW pc=39 dst=r10 src=r1 offset=-4 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1; // EBPF_OP_MOV64_IMM pc=40 dst=r1 src=r0 offset=0 imm=1 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(1); // EBPF_OP_STXW pc=41 dst=r10 src=r1 offset=-36 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" *(uint32_t*)(uintptr_t)(r10 + OFFSET(-36)) = (uint32_t)r1; // EBPF_OP_JA pc=42 dst=r0 src=r0 offset=0 imm=0 -#line 48 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" goto label_8; label_8: // EBPF_OP_LDXW pc=43 dst=r0 src=r10 offset=-4 imm=0 -#line 49 "sample/bindmonitor_bpf2bpf.c" +#line 67 "sample/bindmonitor_bpf2bpf.c" r0 = *(uint32_t*)(uintptr_t)(r10 + OFFSET(-4)); // EBPF_OP_EXIT pc=44 dst=r0 src=r0 offset=0 imm=0 -#line 49 "sample/bindmonitor_bpf2bpf.c" +#line 67 "sample/bindmonitor_bpf2bpf.c" return r0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 45 "sample/bindmonitor_bpf2bpf.c" } #pragma code_seg(pop) #line __LINE__ __FILE__ static uint64_t -BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +BindMonitor_Callee1(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=17 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(17); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee2(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee2(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=34 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(34); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee3(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee3(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=51 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(51); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee4(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee4(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=68 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(68); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee5(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee5(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=85 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(85); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee6(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee6(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) +{ + register uint64_t r0 = 0; + (void)context; + + // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 +#line 70 "sample/bindmonitor_bpf2bpf.c" + *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=102 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(102); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 74 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; + // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 +#line 75 "sample/bindmonitor_bpf2bpf.c" + *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; + // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); + // EBPF_OP_CALL pc=5 dst=r0 src=r1 offset=0 imm=1 +#line 77 "sample/bindmonitor_bpf2bpf.c" + r0 = BindMonitor_Callee7(r1, r2, r3, r4, r5, r10, context); + // EBPF_OP_EXIT pc=6 dst=r0 src=r0 offset=0 imm=0 +#line 77 "sample/bindmonitor_bpf2bpf.c" + return r0; +} +static uint64_t +BindMonitor_Callee7(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5, uint64_t r10, void* context) { register uint64_t r0 = 0; (void)r2; @@ -390,39 +570,39 @@ BindMonitor_Callee(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t (void)context; // EBPF_OP_STXDW pc=0 dst=r10 src=r1 offset=-8 imm=0 -#line 51 "sample/bindmonitor_bpf2bpf.c" +#line 70 "sample/bindmonitor_bpf2bpf.c" *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)) = (uint64_t)r1; - // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=187 -#line 51 "sample/bindmonitor_bpf2bpf.c" - r1 = IMMEDIATE(187); + // EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=119 +#line 70 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(119); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 -#line 55 "sample/bindmonitor_bpf2bpf.c" +#line 74 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-10)) = (uint8_t)r1; // EBPF_OP_STXB pc=3 dst=r10 src=r1 offset=-9 imm=0 -#line 56 "sample/bindmonitor_bpf2bpf.c" +#line 75 "sample/bindmonitor_bpf2bpf.c" *(uint8_t*)(uintptr_t)(r10 + OFFSET(-9)) = (uint8_t)r1; // EBPF_OP_LDXDW pc=4 dst=r1 src=r10 offset=-8 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r10 + OFFSET(-8)); // EBPF_OP_LDXDW pc=5 dst=r1 src=r1 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r1 = *(uint64_t*)(uintptr_t)(r1 + OFFSET(0)); // EBPF_OP_MOV64_IMM pc=6 dst=r0 src=r0 offset=0 imm=1 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 77 "sample/bindmonitor_bpf2bpf.c" r0 = IMMEDIATE(1); // EBPF_OP_JEQ_IMM pc=7 dst=r1 src=r0 offset=1 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(0)) { -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" goto label_1; -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_MOV64_IMM pc=8 dst=r0 src=r0 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 81 "sample/bindmonitor_bpf2bpf.c" r0 = IMMEDIATE(0); label_1: // EBPF_OP_EXIT pc=9 dst=r0 src=r0 offset=0 imm=0 -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 85 "sample/bindmonitor_bpf2bpf.c" return r0; } #pragma data_seg(push, "programs") diff --git a/tests/sample/bindmonitor_bpf2bpf.c b/tests/sample/bindmonitor_bpf2bpf.c index 9de571cd78..da2072c163 100644 --- a/tests/sample/bindmonitor_bpf2bpf.c +++ b/tests/sample/bindmonitor_bpf2bpf.c @@ -20,7 +20,25 @@ #include "ebpf_nethooks.h" bind_action_t -BindMonitor_Callee(uint64_t* pid); +BindMonitor_Callee7(uint64_t* pid); + +bind_action_t +BindMonitor_Callee6(uint64_t* pid); + +bind_action_t +BindMonitor_Callee5(uint64_t* pid); + +bind_action_t +BindMonitor_Callee4(uint64_t* pid); + +bind_action_t +BindMonitor_Callee3(uint64_t* pid); + +bind_action_t +BindMonitor_Callee2(uint64_t* pid); + +bind_action_t +BindMonitor_Callee1(uint64_t* pid); SEC("bind") __attribute__((optnone)) bind_action_t @@ -32,7 +50,7 @@ BindMonitor_Caller(bind_md_t* ctx) outer_cookie[1] = 0xcc; uint64_t pid = ctx->process_id; - if (BindMonitor_Callee(&ctx->process_id) == BIND_DENY) { + if (BindMonitor_Callee1(&ctx->process_id) == BIND_DENY) { return BIND_DENY; } @@ -48,12 +66,79 @@ BindMonitor_Caller(bind_md_t* ctx) return BIND_PERMIT; } -__attribute__((noinline)) bind_action_t __attribute__((optnone)) BindMonitor_Callee(uint64_t* pid) +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee1(uint64_t* pid) +{ + // Use some stack space. + volatile uint8_t inner_cookie1[2]; + inner_cookie1[0] = 0x11; + inner_cookie1[1] = 0x11; + + return BindMonitor_Callee2(pid); +} + +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee2(uint64_t* pid) +{ + // Use some stack space. + volatile uint8_t inner_cookie2[2]; + inner_cookie2[0] = 0x22; + inner_cookie2[1] = 0x22; + + return BindMonitor_Callee3(pid); +} + +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee3(uint64_t* pid) +{ + // Use some stack space. + volatile uint8_t inner_cookie3[2]; + inner_cookie3[0] = 0x33; + inner_cookie3[1] = 0x33; + + return BindMonitor_Callee4(pid); +} + +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee4(uint64_t* pid) +{ + // Use some stack space. + volatile uint8_t inner_cookie4[2]; + inner_cookie4[0] = 0x44; + inner_cookie4[1] = 0x44; + + return BindMonitor_Callee5(pid); +} + +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee5(uint64_t* pid) +{ + // Use some stack space. + volatile uint8_t inner_cookie5[2]; + inner_cookie5[0] = 0x55; + inner_cookie5[1] = 0x55; + + return BindMonitor_Callee6(pid); +} + +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee6(uint64_t* pid) +{ + // Use some stack space. + volatile uint8_t inner_cookie6[2]; + inner_cookie6[0] = 0x66; + inner_cookie6[1] = 0x66; + + return BindMonitor_Callee7(pid); +} + +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee7(uint64_t* pid) { // Use some stack space. - volatile uint8_t inner_cookie[2]; - inner_cookie[0] = 0xbb; - inner_cookie[1] = 0xbb; + volatile uint8_t inner_cookie2[2]; + inner_cookie2[0] = 0x77; + inner_cookie2[1] = 0x77; return (*pid == 0) ? BIND_DENY : BIND_PERMIT; } diff --git a/tools/bpf2c/bpf_code_generator.cpp b/tools/bpf2c/bpf_code_generator.cpp index 00fb63386f..70acc222f6 100644 --- a/tools/bpf2c/bpf_code_generator.cpp +++ b/tools/bpf2c/bpf_code_generator.cpp @@ -111,16 +111,10 @@ static const std::string _predicate_format_string[] = { "{}{} <= {}{}", // JSLE }; -#define ADD_OPCODE(X) \ - { \ - static_cast(X), std::string(#X) \ - } +#define ADD_OPCODE(X) {static_cast(X), std::string(#X)} // remove EBPF_ATOMIC_ prefix -#define ADD_ATOMIC_OPCODE(X) \ - { \ - static_cast(X), std::string(#X).substr(12) \ - } +#define ADD_ATOMIC_OPCODE(X) {static_cast(X), std::string(#X).substr(12)} static std::map _atomic_opcode_name_strings = { ADD_ATOMIC_OPCODE(EBPF_ATOMIC_ADD), @@ -168,12 +162,12 @@ static std::map _opcode_name_strings = { ADD_OPCODE(EBPF_OP_ATOMIC64), ADD_OPCODE(EBPF_OP_ATOMIC)}; #define IS_ATOMIC_OPCODE(_opcode) \ - (((_opcode)&INST_CLS_MASK) == INST_CLS_STX && ((_opcode)&INST_MODE_MASK) == EBPF_MODE_ATOMIC) + (((_opcode) & INST_CLS_MASK) == INST_CLS_STX && ((_opcode) & INST_MODE_MASK) == EBPF_MODE_ATOMIC) #define IS_JMP_CLASS_OPCODE(_opcode) \ - (((_opcode)&INST_CLS_MASK) == INST_CLS_JMP || ((_opcode)&INST_CLS_MASK) == INST_CLS_JMP32) + (((_opcode) & INST_CLS_MASK) == INST_CLS_JMP || ((_opcode) & INST_CLS_MASK) == INST_CLS_JMP32) -#define IS_JMP32_CLASS_OPCODE(_opcode) (((_opcode)&INST_CLS_MASK) == INST_CLS_JMP32) +#define IS_JMP32_CLASS_OPCODE(_opcode) (((_opcode) & INST_CLS_MASK) == INST_CLS_JMP32) #define IS_SIGNED_CMP_OPCODE(_opcode) \ (((_opcode) >> 4) == (EBPF_MODE_JSGT >> 4) || ((_opcode) >> 4) == (EBPF_MODE_JSGE >> 4) || \ @@ -260,7 +254,7 @@ bpf_code_generator::bpf_code_generator( const bpf_code_generator::unsafe_string& c_name, const std::vector& instructions) : c_name(c_name) { - bpf_code_generator_program* current_program = add_program(c_name, c_name); + bpf_code_generator_program* current_program = add_program(c_name, c_name, 0); uint32_t offset = 0; for (const auto& instruction : instructions) { std::string unsafe_name = "local_subprogram" + std::to_string(offset); @@ -276,7 +270,7 @@ bpf_code_generator::bpf_code_generator( size_t subprogram_offset = ((size_t)offset) + instruction.imm; unsafe_name = "local_subprogram" + std::to_string(subprogram_offset); unsafe_string name(unsafe_name); - add_program(name, ".text"); + add_program(name, ".text", subprogram_offset); current_program->output_instructions.back().relocation = name; } } @@ -408,7 +402,7 @@ bpf_code_generator::extract_program( continue; } if (memcmp(program_info->raw_data + callee_offset, info->raw_data, info->raw_data_size) == 0) { - add_program(info->program_name, info->section_name); + add_program(info->program_name, info->section_name, info->offset_in_section); extract_program(info, infos); } } @@ -790,11 +784,13 @@ bpf_code_generator::parse_legacy_maps_section(const unsafe_string& name) } bpf_code_generator::bpf_code_generator_program* -bpf_code_generator::add_program(const unsafe_string& program_name, const unsafe_string& elf_section_name) +bpf_code_generator::add_program( + const unsafe_string& program_name, const unsafe_string& elf_section_name, size_t offset_in_section) { bpf_code_generator::bpf_code_generator_program* program = &programs[program_name]; program->program_name = program_name; program->elf_section_name = elf_section_name; + program->offset_in_section = offset_in_section; set_pe_section_name(*program, elf_section_name); return program; } @@ -1622,25 +1618,24 @@ bpf_code_generator::emit_c_code(std::ostream& output_stream) output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) << map_type + "," << "// Type of map." << std::endl; output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) - << std::to_string(entry.definition.key_size) + "," - << "// Size in bytes of a map key." << std::endl; + << std::to_string(entry.definition.key_size) + "," << "// Size in bytes of a map key." + << std::endl; output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) - << std::to_string(entry.definition.value_size) + "," - << "// Size in bytes of a map value." << std::endl; + << std::to_string(entry.definition.value_size) + "," << "// Size in bytes of a map value." + << std::endl; output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) << std::to_string(entry.definition.max_entries) + "," << "// Maximum number of entries allowed in the map." << std::endl; output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) - << std::to_string(entry.definition.inner_map_idx) + "," - << "// Inner map index." << std::endl; + << std::to_string(entry.definition.inner_map_idx) + "," << "// Inner map index." << std::endl; output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) << map_pinning + "," << "// Pinning type for the map." << std::endl; output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) - << std::to_string(entry.definition.id) + "," - << "// Identifier for a map template." << std::endl; + << std::to_string(entry.definition.id) + "," << "// Identifier for a map template." + << std::endl; output_stream << INDENT INDENT " " << std::left << std::setw(stream_width) - << std::to_string(entry.definition.inner_id) + "," - << "// The id of the inner map template." << std::endl; + << std::to_string(entry.definition.inner_id) + "," << "// The id of the inner map template." + << std::endl; output_stream << INDENT " }," << std::endl; output_stream << INDENT " " << name.quoted() << "}," << std::endl; } diff --git a/tools/bpf2c/bpf_code_generator.h b/tools/bpf2c/bpf_code_generator.h index 6701e87677..1ce5a46803 100644 --- a/tools/bpf2c/bpf_code_generator.h +++ b/tools/bpf2c/bpf_code_generator.h @@ -186,7 +186,8 @@ class bpf_code_generator */ bpf_code_generator_exception(const unsafe_string& what, size_t offset) : std::runtime_error(what.raw() + " at offset " + std::to_string(offset)) - {} + { + } }; /** @@ -398,10 +399,12 @@ class bpf_code_generator /** * @brief Add a program to the current section. * - * @param[in] name Program name. + * @param[in] program_name Program name. + * @param[in] elf_section_name ELF section name. + * @param[in] offset_in_section Offset in bytes into the ELF section where the program bytecode begins. */ bpf_code_generator_program* - add_program(const unsafe_string& program_name, const unsafe_string& elf_section_name); + add_program(const unsafe_string& program_name, const unsafe_string& elf_section_name, size_t offset_in_section); /** * @brief Generate C code from the parsed eBPF file.