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/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..1b5674357d 100644 --- a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_dll.c +++ b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_dll.c @@ -48,7 +48,9 @@ _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 GUID BindMonitor_Caller_program_type_guid = { 0x608c517c, 0x6c52, 0x4a26, {0xb6, 0x77, 0xbb, 0x1c, 0x34, 0x42, 0x5a, 0xdf}}; @@ -57,195 +59,223 @@ 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 30 "sample/bindmonitor_bpf2bpf.c" { -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" // Prologue. -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" uint64_t stack[(UBPF_STACK_SIZE + 7) / 8]; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r0 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r1 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r2 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r3 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r4 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r5 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r10 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" r1 = (uintptr_t)context; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "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 30 "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 30 "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 34 "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 35 "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 37 "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 37 "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 37 "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 38 "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 38 "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 38 "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 38 "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 38 "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 38 "sample/bindmonitor_bpf2bpf.c" if (r0 != IMMEDIATE(1)) { -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "sample/bindmonitor_bpf2bpf.c" goto label_2; -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=13 dst=r0 src=r0 offset=0 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "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 38 "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 39 "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 39 "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 39 "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 43 "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 43 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" goto label_4; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=20 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "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 43 "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 43 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" goto label_5; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=23 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "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 43 "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 44 "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 44 "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 44 "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 44 "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 47 "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 47 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(1)) { -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "sample/bindmonitor_bpf2bpf.c" goto label_7; -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=32 dst=r0 src=r0 offset=0 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "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 47 "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 49 "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 49 "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 49 "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 49 "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 49 "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 51 "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 51 "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 51 "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 51 "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 52 "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 52 "sample/bindmonitor_bpf2bpf.c" return r0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "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 55 "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 55 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(187); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 59 "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 60 "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 62 "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 62 "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 62 "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)r2; @@ -255,39 +285,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 55 "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" +#line 55 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(187); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 -#line 55 "sample/bindmonitor_bpf2bpf.c" +#line 59 "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 60 "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 62 "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 62 "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 62 "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 66 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(0)) { -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" goto label_1; -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 66 "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 66 "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 70 "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..301fefadb3 100644 --- a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_raw.c +++ b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_raw.c @@ -22,7 +22,9 @@ _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 GUID BindMonitor_Caller_program_type_guid = { 0x608c517c, 0x6c52, 0x4a26, {0xb6, 0x77, 0xbb, 0x1c, 0x34, 0x42, 0x5a, 0xdf}}; @@ -31,195 +33,223 @@ 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 30 "sample/bindmonitor_bpf2bpf.c" { -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" // Prologue. -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" uint64_t stack[(UBPF_STACK_SIZE + 7) / 8]; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r0 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r1 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r2 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r3 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r4 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r5 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r10 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" r1 = (uintptr_t)context; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "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 30 "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 30 "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 34 "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 35 "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 37 "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 37 "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 37 "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 38 "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 38 "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 38 "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 38 "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 38 "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 38 "sample/bindmonitor_bpf2bpf.c" if (r0 != IMMEDIATE(1)) { -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "sample/bindmonitor_bpf2bpf.c" goto label_2; -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=13 dst=r0 src=r0 offset=0 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "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 38 "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 39 "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 39 "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 39 "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 43 "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 43 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" goto label_4; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=20 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "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 43 "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 43 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" goto label_5; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=23 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "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 43 "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 44 "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 44 "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 44 "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 44 "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 47 "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 47 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(1)) { -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "sample/bindmonitor_bpf2bpf.c" goto label_7; -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=32 dst=r0 src=r0 offset=0 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "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 47 "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 49 "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 49 "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 49 "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 49 "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 49 "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 51 "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 51 "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 51 "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 51 "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 52 "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 52 "sample/bindmonitor_bpf2bpf.c" return r0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "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 55 "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 55 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(187); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 59 "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 60 "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 62 "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 62 "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 62 "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)r2; @@ -229,39 +259,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 55 "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" +#line 55 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(187); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 -#line 55 "sample/bindmonitor_bpf2bpf.c" +#line 59 "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 60 "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 62 "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 62 "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 62 "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 66 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(0)) { -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" goto label_1; -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 66 "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 66 "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 70 "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..247e54bfc7 100644 --- a/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_sys.c +++ b/tests/bpf2c_tests/expected/bindmonitor_bpf2bpf_sys.c @@ -183,7 +183,9 @@ _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 GUID BindMonitor_Caller_program_type_guid = { 0x608c517c, 0x6c52, 0x4a26, {0xb6, 0x77, 0xbb, 0x1c, 0x34, 0x42, 0x5a, 0xdf}}; @@ -192,195 +194,223 @@ 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 30 "sample/bindmonitor_bpf2bpf.c" { -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" // Prologue. -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" uint64_t stack[(UBPF_STACK_SIZE + 7) / 8]; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r0 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r1 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r2 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r3 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r4 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r5 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" register uint64_t r10 = 0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "sample/bindmonitor_bpf2bpf.c" r1 = (uintptr_t)context; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "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 30 "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 30 "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 34 "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 35 "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 37 "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 37 "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 37 "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 38 "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 38 "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 38 "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 38 "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 38 "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 38 "sample/bindmonitor_bpf2bpf.c" if (r0 != IMMEDIATE(1)) { -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "sample/bindmonitor_bpf2bpf.c" goto label_2; -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=13 dst=r0 src=r0 offset=0 imm=0 -#line 35 "sample/bindmonitor_bpf2bpf.c" +#line 38 "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 38 "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 39 "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 39 "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 39 "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 43 "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 43 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" goto label_4; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=20 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "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 43 "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 43 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(204)) { -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" goto label_5; -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=23 dst=r0 src=r0 offset=0 imm=0 -#line 40 "sample/bindmonitor_bpf2bpf.c" +#line 43 "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 43 "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 44 "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 44 "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 44 "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 44 "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 47 "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 47 "sample/bindmonitor_bpf2bpf.c" if (r1 != IMMEDIATE(1)) { -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "sample/bindmonitor_bpf2bpf.c" goto label_7; -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "sample/bindmonitor_bpf2bpf.c" } // EBPF_OP_JA pc=32 dst=r0 src=r0 offset=0 imm=0 -#line 44 "sample/bindmonitor_bpf2bpf.c" +#line 47 "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 47 "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 49 "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 49 "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 49 "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 49 "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 49 "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 51 "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 51 "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 51 "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 51 "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 52 "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 52 "sample/bindmonitor_bpf2bpf.c" return r0; -#line 27 "sample/bindmonitor_bpf2bpf.c" +#line 30 "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 55 "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 55 "sample/bindmonitor_bpf2bpf.c" + r1 = IMMEDIATE(187); + // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 +#line 59 "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 60 "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 62 "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 62 "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 62 "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)r2; @@ -390,39 +420,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 55 "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" +#line 55 "sample/bindmonitor_bpf2bpf.c" r1 = IMMEDIATE(187); // EBPF_OP_STXB pc=2 dst=r10 src=r1 offset=-10 imm=0 -#line 55 "sample/bindmonitor_bpf2bpf.c" +#line 59 "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 60 "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 62 "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 62 "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 62 "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 66 "sample/bindmonitor_bpf2bpf.c" if (r1 == IMMEDIATE(0)) { -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 66 "sample/bindmonitor_bpf2bpf.c" goto label_1; -#line 58 "sample/bindmonitor_bpf2bpf.c" +#line 66 "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 66 "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 70 "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..6ad1875717 100644 --- a/tests/sample/bindmonitor_bpf2bpf.c +++ b/tests/sample/bindmonitor_bpf2bpf.c @@ -20,7 +20,10 @@ #include "ebpf_nethooks.h" bind_action_t -BindMonitor_Callee(uint64_t* pid); +BindMonitor_Callee2(uint64_t* pid); + +bind_action_t +BindMonitor_Callee1(uint64_t* pid); SEC("bind") __attribute__((optnone)) bind_action_t @@ -32,7 +35,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 +51,24 @@ 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] = 0xbb; + inner_cookie1[1] = 0xbb; + + return BindMonitor_Callee2(pid); +} + +__attribute__((noinline)) bind_action_t __attribute__((optnone)) +BindMonitor_Callee2(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] = 0xbb; + inner_cookie2[1] = 0xbb; return (*pid == 0) ? BIND_DENY : BIND_PERMIT; }