From 4be43a7ea173de7e506493e0044e9c4ec37d8be7 Mon Sep 17 00:00:00 2001 From: Alan Jowett Date: Wed, 25 Aug 2021 09:01:16 -0600 Subject: [PATCH] Include required Clang version (#431) * Update Getting Started to recommend current release version of Clang/LLVM Clang-format behaves differently depending on the version of Clang installed. Update getting started guide to recommend Clang / LLVM 10.0.0. Update the development guide to indicate that Clang 10 or higher is required for consistent formatting. Reformat all code using Clang 10.0.0 Signed-off-by: Alan Jowett --- docs/DevelopmentGuide.md | 2 ++ docs/GettingStarted.md | 2 +- ebpfsvc/svcmain.cpp | 4 +-- include/ebpf_result.h | 2 +- libs/api/Verifier.cpp | 11 ++++---- libs/api/ebpf_api.cpp | 16 ++++++------ libs/api/windows_platform.cpp | 25 ++++++++++--------- libs/api_common/api_common.cpp | 5 ++-- libs/api_common/windows_platform_common.cpp | 18 +++++++------ libs/ebpfnetsh/programs.cpp | 11 ++++---- .../unit/execution_context_unit_test.cpp | 4 +-- libs/platform/unit/platform_unit_test.cpp | 23 ++++++++++------- libs/service/verifier_service.cpp | 4 +-- rpc_interface/rpc_interface.idl | 9 ++++--- scripts/format-code | 2 +- scripts/format-code.ps1 | 2 +- tests/sample/bindmonitor.c | 22 ++++++++-------- tests/sample/divide_by_zero.c | 11 ++++---- tests/sample/droppacket.c | 11 ++++---- tests/sample/droppacket_unsafe.c | 11 ++++---- tests/sample/ext/drv/sample_ext.c | 23 +++++++++-------- tests/sample/map_in_map.c | 13 +++++----- tests/sample/repro.c | 11 ++++---- tests/sample/tail_call_map.c | 11 ++++---- tests/sample/test_sample_ebpf.c | 11 ++++---- .../encode_program_info.cpp | 9 ++++--- 26 files changed, 151 insertions(+), 122 deletions(-) diff --git a/docs/DevelopmentGuide.md b/docs/DevelopmentGuide.md index d5b6856ba..3e4cc2c78 100644 --- a/docs/DevelopmentGuide.md +++ b/docs/DevelopmentGuide.md @@ -80,6 +80,8 @@ the default Visual Studio style. See [clang-format style options]( http://releases.llvm.org/3.6.0/tools/clang/docs/ClangFormatStyleOptions.html) for details. +If you see unexpected formatting changes in the code, verify that you are running version 10 or higher of the LLVM tool-chain. + ### License Header The following license header **must** be included at the top of every code file: diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index a120ec693..81f3a31a2 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -10,7 +10,7 @@ The following must be installed in order to build this project: which must be selected as an Individual component in the VS installer 3. [Visual Studio Build Tools 2019](https://aka.ms/vs/16/release/vs_buildtools.exe) 4. [WDK for Windows 10, version 2004](https://go.microsoft.com/fwlink/?linkid=2128854) -5. [Clang/LLVM for Windows 64-bit](https://github.com/llvm/llvm-project/releases/download/llvmorg-8.0.1/LLVM-8.0.1-win64.exe) +5. [Clang for Windows 64-bit version 10.0.0](https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe) or [The latest release of Clang for Windows 64-bit](https://github.com/llvm/llvm-project/releases/latest) 6. [nuget.exe](https://www.nuget.org/downloads) ## How to clone and build the project diff --git a/ebpfsvc/svcmain.cpp b/ebpfsvc/svcmain.cpp index 94701daf9..bddf14e5a 100644 --- a/ebpfsvc/svcmain.cpp +++ b/ebpfsvc/svcmain.cpp @@ -27,8 +27,8 @@ service_install(); int __cdecl wmain(ULONG argc, PWSTR* argv) { - SERVICE_TABLE_ENTRY dispatch_table[] = {{(PWSTR)SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)service_main}, - {nullptr, nullptr}}; + SERVICE_TABLE_ENTRY dispatch_table[] = { + {(PWSTR)SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)service_main}, {nullptr, nullptr}}; // If command-line parameter is "install", install the service. // Otherwise, the service is probably being started by the SCM. diff --git a/include/ebpf_result.h b/include/ebpf_result.h index c7743fcfe..9b1ecb3de 100644 --- a/include/ebpf_result.h +++ b/include/ebpf_result.h @@ -94,7 +94,7 @@ extern "C" // The requested key is already present. EBPF_KEY_ALREADY_EXISTS, - + /// Caller has reached tail call limit. EBPF_NO_MORE_TAIL_CALLS, } ebpf_result_t; diff --git a/libs/api/Verifier.cpp b/libs/api/Verifier.cpp index 0bd6bfe7a..3290a3902 100644 --- a/libs/api/Verifier.cpp +++ b/libs/api/Verifier.cpp @@ -348,11 +348,12 @@ ebpf_api_elf_enumerate_sections( } } - sequence.emplace_back(tlv_pack({tlv_pack(raw_program.section.c_str()), - tlv_pack(raw_program.info.type.name.c_str()), - tlv_pack(raw_program.info.map_descriptors.size()), - tlv_pack(convert_ebpf_program_to_bytes(raw_program.prog)), - tlv_pack(stats_sequence)})); + sequence.emplace_back(tlv_pack( + {tlv_pack(raw_program.section.c_str()), + tlv_pack(raw_program.info.type.name.c_str()), + tlv_pack(raw_program.info.map_descriptors.size()), + tlv_pack(convert_ebpf_program_to_bytes(raw_program.prog)), + tlv_pack(stats_sequence)})); } auto retval = tlv_pack(sequence); diff --git a/libs/api/ebpf_api.cpp b/libs/api/ebpf_api.cpp index acf849a0c..eb3a6dc60 100644 --- a/libs/api/ebpf_api.cpp +++ b/libs/api/ebpf_api.cpp @@ -1072,9 +1072,10 @@ ebpf_get_next_program(fd_t previous_fd, _Out_ fd_t* next_fd) *next_fd = ebpf_fd_invalid; ebpf_handle_t previous_handle = _get_handle_from_fd(local_fd); - ebpf_operation_get_next_program_request_t request{sizeof(request), - ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_PROGRAM, - reinterpret_cast(previous_handle)}; + ebpf_operation_get_next_program_request_t request{ + sizeof(request), + ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_PROGRAM, + reinterpret_cast(previous_handle)}; ebpf_operation_get_next_program_reply_t reply; @@ -1171,10 +1172,11 @@ ebpf_program_query_info( uint32_t ebpf_api_link_program(ebpf_handle_t program_handle, ebpf_attach_type_t attach_type, ebpf_handle_t* link_handle) { - ebpf_operation_link_program_request_t request = {EBPF_OFFSET_OF(ebpf_operation_link_program_request_t, data), - EBPF_OPERATION_LINK_PROGRAM, - reinterpret_cast(program_handle), - attach_type}; + ebpf_operation_link_program_request_t request = { + EBPF_OFFSET_OF(ebpf_operation_link_program_request_t, data), + EBPF_OPERATION_LINK_PROGRAM, + reinterpret_cast(program_handle), + attach_type}; ebpf_operation_link_program_reply_t reply; uint32_t retval = invoke_ioctl(request, reply); diff --git a/libs/api/windows_platform.cpp b/libs/api/windows_platform.cpp index 96c7e3dbc..18444a896 100644 --- a/libs/api/windows_platform.cpp +++ b/libs/api/windows_platform.cpp @@ -62,18 +62,19 @@ parse_maps_section_windows( std::vector((ebpf_map_definition_t*)data, (ebpf_map_definition_t*)(data + size)); for (int i = 0; i < mapdefs.size(); i++) { auto& s = mapdefs[i]; - map_descriptors.emplace_back(EbpfMapDescriptor{.original_fd = create_map_windows( - s.type, - s.key_size, - s.value_size, - s.max_entries, - s.inner_map_idx, - (i * sizeof(ebpf_map_definition_t)), - options), - .type = (uint32_t)s.type, - .key_size = s.key_size, - .value_size = s.value_size, - .inner_map_fd = s.inner_map_idx}); + map_descriptors.emplace_back(EbpfMapDescriptor{ + .original_fd = create_map_windows( + s.type, + s.key_size, + s.value_size, + s.max_entries, + s.inner_map_idx, + (i * sizeof(ebpf_map_definition_t)), + options), + .type = (uint32_t)s.type, + .key_size = s.key_size, + .value_size = s.value_size, + .inner_map_fd = s.inner_map_idx}); } for (size_t i = 0; i < mapdefs.size(); i++) { unsigned int inner = mapdefs[i].inner_map_idx; diff --git a/libs/api_common/api_common.cpp b/libs/api_common/api_common.cpp index 2ca22d9f6..abcb233cc 100644 --- a/libs/api_common/api_common.cpp +++ b/libs/api_common/api_common.cpp @@ -34,8 +34,9 @@ allocate_string(const std::string& string, uint32_t* length) noexcept std::vector convert_ebpf_program_to_bytes(const std::vector& instructions) { - return {reinterpret_cast(instructions.data()), - reinterpret_cast(instructions.data()) + instructions.size() * sizeof(ebpf_inst)}; + return { + reinterpret_cast(instructions.data()), + reinterpret_cast(instructions.data()) + instructions.size() * sizeof(ebpf_inst)}; } int diff --git a/libs/api_common/windows_platform_common.cpp b/libs/api_common/windows_platform_common.cpp index 57525bd0c..181d24985 100644 --- a/libs/api_common/windows_platform_common.cpp +++ b/libs/api_common/windows_platform_common.cpp @@ -29,10 +29,11 @@ // the preprocessor treat a prefix list as one macro argument. #define COMMA , -const ebpf_context_descriptor_t g_xdp_context_descriptor = {sizeof(xdp_md_t), - EBPF_OFFSET_OF(xdp_md_t, data), - EBPF_OFFSET_OF(xdp_md_t, data_end), - EBPF_OFFSET_OF(xdp_md_t, data_meta)}; +const ebpf_context_descriptor_t g_xdp_context_descriptor = { + sizeof(xdp_md_t), + EBPF_OFFSET_OF(xdp_md_t, data), + EBPF_OFFSET_OF(xdp_md_t, data_end), + EBPF_OFFSET_OF(xdp_md_t, data_meta)}; const EbpfProgramType windows_xdp_program_type = PTYPE("xdp", &g_xdp_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_XDP, {"xdp"}); @@ -53,10 +54,11 @@ const ebpf_context_descriptor_t g_sample_ext_context_descriptor = { const EbpfProgramType windows_sample_ext_program_type = PTYPE("sample_ext", &g_sample_ext_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_SAMPLE, {"sample_ext"}); -const std::vector windows_program_types = {PTYPE("unspecified", {0}, 0, {}), - windows_xdp_program_type, - windows_bind_program_type, - windows_sample_ext_program_type}; +const std::vector windows_program_types = { + PTYPE("unspecified", {0}, 0, {}), + windows_xdp_program_type, + windows_bind_program_type, + windows_sample_ext_program_type}; const std::map windows_program_type_to_attach_type = { {&EBPF_PROGRAM_TYPE_XDP, &EBPF_ATTACH_TYPE_XDP}, diff --git a/libs/ebpfnetsh/programs.cpp b/libs/ebpfnetsh/programs.cpp index 5e129599c..90a28c338 100644 --- a/libs/ebpfnetsh/programs.cpp +++ b/libs/ebpfnetsh/programs.cpp @@ -112,11 +112,12 @@ handle_ebpf_add_program( UNREFERENCED_PARAMETER(data); UNREFERENCED_PARAMETER(done); - TAG_TYPE tags[] = {{TOKEN_FILENAME, NS_REQ_PRESENT, FALSE}, - {TOKEN_SECTION, NS_REQ_PRESENT, FALSE}, - {TOKEN_TYPE, NS_REQ_ZERO, FALSE}, - {TOKEN_PINNED, NS_REQ_ZERO, FALSE}, - {TOKEN_EXECUTION, NS_REQ_ZERO, FALSE}}; + TAG_TYPE tags[] = { + {TOKEN_FILENAME, NS_REQ_PRESENT, FALSE}, + {TOKEN_SECTION, NS_REQ_PRESENT, FALSE}, + {TOKEN_TYPE, NS_REQ_ZERO, FALSE}, + {TOKEN_PINNED, NS_REQ_ZERO, FALSE}, + {TOKEN_EXECUTION, NS_REQ_ZERO, FALSE}}; ULONG tag_type[_countof(tags)] = {0}; ULONG status = diff --git a/libs/execution_context/unit/execution_context_unit_test.cpp b/libs/execution_context/unit/execution_context_unit_test.cpp index 5c593f3f4..07284a111 100644 --- a/libs/execution_context/unit/execution_context_unit_test.cpp +++ b/libs/execution_context/unit/execution_context_unit_test.cpp @@ -193,8 +193,8 @@ TEST_CASE("program", "[execution_context]") ebpf_result_t (*function_pointer1)() = provider_function1; uint32_t test_function_ids[] = {(EBPF_MAX_GENERAL_HELPER_FUNCTION + 1)}; const void* helper_functions[] = {(void*)function_pointer1}; - ebpf_helper_function_addresses_t helper_function_addresses = {EBPF_COUNT_OF(helper_functions), - (uint64_t*)helper_functions}; + ebpf_helper_function_addresses_t helper_function_addresses = { + EBPF_COUNT_OF(helper_functions), (uint64_t*)helper_functions}; REQUIRE(ebpf_allocate_trampoline_table(1, &table) == EBPF_SUCCESS); REQUIRE( diff --git a/libs/platform/unit/platform_unit_test.cpp b/libs/platform/unit/platform_unit_test.cpp index dd6485ae8..572c94e9e 100644 --- a/libs/platform/unit/platform_unit_test.cpp +++ b/libs/platform/unit/platform_unit_test.cpp @@ -74,10 +74,13 @@ TEST_CASE("hash_table_test", "[platform]") // Insert first REQUIRE( - ebpf_hash_table_update(table, key_1.data(), data_1.data(), nullptr, EBPF_HASH_TABLE_OPERATION_INSERT) == EBPF_SUCCESS); + ebpf_hash_table_update(table, key_1.data(), data_1.data(), nullptr, EBPF_HASH_TABLE_OPERATION_INSERT) == + EBPF_SUCCESS); // Insert second - REQUIRE(ebpf_hash_table_update(table, key_2.data(), data_2.data(), nullptr, EBPF_HASH_TABLE_OPERATION_ANY) == EBPF_SUCCESS); + REQUIRE( + ebpf_hash_table_update(table, key_2.data(), data_2.data(), nullptr, EBPF_HASH_TABLE_OPERATION_ANY) == + EBPF_SUCCESS); // Find the first REQUIRE(ebpf_hash_table_find(table, key_1.data(), &returned_value) == EBPF_SUCCESS); @@ -90,7 +93,8 @@ TEST_CASE("hash_table_test", "[platform]") // Replace memset(data_1.data(), '0x55', data_1.size()); REQUIRE( - ebpf_hash_table_update(table, key_1.data(), data_1.data(), nullptr, EBPF_HASH_TABLE_OPERATION_REPLACE) == EBPF_SUCCESS); + ebpf_hash_table_update(table, key_1.data(), data_1.data(), nullptr, EBPF_HASH_TABLE_OPERATION_REPLACE) == + EBPF_SUCCESS); // Find the first REQUIRE(ebpf_hash_table_find(table, key_1.data(), &returned_value) == EBPF_SUCCESS); @@ -346,8 +350,8 @@ TEST_CASE("trampoline_test", "[platform]") auto provider_function2 = []() { return EBPF_OBJECT_ALREADY_EXISTS; }; ebpf_result_t (*function_pointer2)() = provider_function2; const void* helper_functions2[] = {(void*)function_pointer2}; - ebpf_helper_function_addresses_t helper_function_addresses2 = {EBPF_COUNT_OF(helper_functions1), - (uint64_t*)helper_functions2}; + ebpf_helper_function_addresses_t helper_function_addresses2 = { + EBPF_COUNT_OF(helper_functions1), (uint64_t*)helper_functions2}; REQUIRE(ebpf_allocate_trampoline_table(1, &table) == EBPF_SUCCESS); REQUIRE( @@ -396,10 +400,11 @@ TEST_CASE("program_type_info", "[platform]") { _test_helper test_helper; - ebpf_context_descriptor_t context_descriptor{sizeof(xdp_md_t), - EBPF_OFFSET_OF(xdp_md_t, data), - EBPF_OFFSET_OF(xdp_md_t, data_end), - EBPF_OFFSET_OF(xdp_md_t, data_meta)}; + ebpf_context_descriptor_t context_descriptor{ + sizeof(xdp_md_t), + EBPF_OFFSET_OF(xdp_md_t, data), + EBPF_OFFSET_OF(xdp_md_t, data_end), + EBPF_OFFSET_OF(xdp_md_t, data_meta)}; ebpf_program_type_descriptor_t program_type{"xdp", &context_descriptor}; ebpf_program_info_t program_info{program_type, _countof(_helper_functions), _helper_functions}; ebpf_program_info_t* new_program_info = nullptr; diff --git a/libs/service/verifier_service.cpp b/libs/service/verifier_service.cpp index fe5e11591..75b4040ed 100644 --- a/libs/service/verifier_service.cpp +++ b/libs/service/verifier_service.cpp @@ -51,8 +51,8 @@ verify_byte_code( uint32_t* error_message_size) { const ebpf_platform_t* platform = &g_ebpf_platform_windows_service; - std::vector instructions{(ebpf_inst*)byte_code, - (ebpf_inst*)byte_code + byte_code_size / sizeof(ebpf_inst)}; + std::vector instructions{ + (ebpf_inst*)byte_code, (ebpf_inst*)byte_code + byte_code_size / sizeof(ebpf_inst)}; program_info info{platform}; std::string section; std::string file; diff --git a/rpc_interface/rpc_interface.idl b/rpc_interface/rpc_interface.idl index 33ded7c8d..cf0fdee18 100644 --- a/rpc_interface/rpc_interface.idl +++ b/rpc_interface/rpc_interface.idl @@ -70,8 +70,9 @@ import "wtypes.idl"; [ out, ref ] uint32_t * logs_size, [ out, size_is(, *logs_size), ref ] char** logs); - ebpf_result_t verify_program( - [ in, ref ] ebpf_program_verify_info * info, - [out] uint32_t * logs_size, - [ out, size_is(, *logs_size), ref ] char** logs); + ebpf_result_t verify_program([ in, ref ] ebpf_program_verify_info * info, [out] uint32_t * logs_size, [ + out, + size_is(, *logs_size), + ref + ] char** logs); } diff --git a/scripts/format-code b/scripts/format-code index ff25f3796..850e49713 100644 --- a/scripts/format-code +++ b/scripts/format-code @@ -174,7 +174,7 @@ check_clang-format() cf="clang-format" fi - local required_cfver='7.0.1' + local required_cfver='10.0.0' # shellcheck disable=SC2155 local cfver=$(${cf} --version | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+' | head -1) check_version "${required_cfver}" "${cfver}" diff --git a/scripts/format-code.ps1 b/scripts/format-code.ps1 index aa86a963b..3a066ab60 100644 --- a/scripts/format-code.ps1 +++ b/scripts/format-code.ps1 @@ -250,7 +250,7 @@ function check_clang-format() # Windows does not have a clang-format-7 executable - $required_cfver='7.0.0' + $required_cfver='10.0.01' try { $cfver=(( Invoke-Expression "clang-format --version" 2> $null ) -split " ")[2] diff --git a/tests/sample/bindmonitor.c b/tests/sample/bindmonitor.c index cfd9753a3..84d3b3046 100644 --- a/tests/sample/bindmonitor.c +++ b/tests/sample/bindmonitor.c @@ -16,17 +16,19 @@ typedef struct _process_entry } process_entry_t; #pragma clang section data = "maps" -ebpf_map_definition_t process_map = {.size = sizeof(ebpf_map_definition_t), - .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(uint64_t), - .value_size = sizeof(process_entry_t), - .max_entries = 1024}; +ebpf_map_definition_t process_map = { + .size = sizeof(ebpf_map_definition_t), + .type = BPF_MAP_TYPE_HASH, + .key_size = sizeof(uint64_t), + .value_size = sizeof(process_entry_t), + .max_entries = 1024}; -ebpf_map_definition_t limits_map = {.size = sizeof(ebpf_map_definition_t), - .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(uint32_t), - .value_size = sizeof(uint32_t), - .max_entries = 1}; +ebpf_map_definition_t limits_map = { + .size = sizeof(ebpf_map_definition_t), + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(uint32_t), + .value_size = sizeof(uint32_t), + .max_entries = 1}; inline process_entry_t* find_or_create_process_entry(bind_md_t* ctx) diff --git a/tests/sample/divide_by_zero.c b/tests/sample/divide_by_zero.c index 80cbf8621..ede2a68e5 100644 --- a/tests/sample/divide_by_zero.c +++ b/tests/sample/divide_by_zero.c @@ -10,11 +10,12 @@ #include "ebpf_helpers.h" #pragma clang section data = "maps" -ebpf_map_definition_t test_map = {.size = sizeof(ebpf_map_definition_t), - .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(uint32_t), - .value_size = sizeof(uint32_t), - .max_entries = 1}; +ebpf_map_definition_t test_map = { + .size = sizeof(ebpf_map_definition_t), + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(uint32_t), + .value_size = sizeof(uint32_t), + .max_entries = 1}; #pragma clang section text = "xdp" uint32_t diff --git a/tests/sample/droppacket.c b/tests/sample/droppacket.c index 45f17b3de..97911c306 100644 --- a/tests/sample/droppacket.c +++ b/tests/sample/droppacket.c @@ -10,11 +10,12 @@ #include "ebpf_helpers.h" #pragma clang section data = "maps" -ebpf_map_definition_t port_map = {.size = sizeof(ebpf_map_definition_t), - .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(uint32_t), - .value_size = sizeof(uint64_t), - .max_entries = 1}; +ebpf_map_definition_t port_map = { + .size = sizeof(ebpf_map_definition_t), + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(uint32_t), + .value_size = sizeof(uint64_t), + .max_entries = 1}; #pragma clang section text = "xdp" int diff --git a/tests/sample/droppacket_unsafe.c b/tests/sample/droppacket_unsafe.c index 462b6f7d6..648f5e3df 100644 --- a/tests/sample/droppacket_unsafe.c +++ b/tests/sample/droppacket_unsafe.c @@ -10,11 +10,12 @@ #include "ebpf_helpers.h" #pragma clang section data = "maps" -ebpf_map_definition_t port_map = {.size = sizeof(ebpf_map_definition_t), - .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(uint32_t), - .value_size = sizeof(uint64_t), - .max_entries = 1}; +ebpf_map_definition_t port_map = { + .size = sizeof(ebpf_map_definition_t), + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(uint32_t), + .value_size = sizeof(uint64_t), + .max_entries = 1}; #pragma clang section text = "xdp" int diff --git a/tests/sample/ext/drv/sample_ext.c b/tests/sample/ext/drv/sample_ext.c index f51ca3916..3e4a3084b 100644 --- a/tests/sample/ext/drv/sample_ext.c +++ b/tests/sample/ext/drv/sample_ext.c @@ -22,10 +22,11 @@ // f788ef4a-207d-4dc3-85cf-0f2ea107213c DEFINE_GUID(EBPF_PROGRAM_TYPE_SAMPLE, 0xf788ef4a, 0x207d, 0x4dc3, 0x85, 0xcf, 0x0f, 0x2e, 0xa1, 0x07, 0x21, 0x3c); -static ebpf_context_descriptor_t _sample_ebpf_context_descriptor = {sizeof(test_program_context_t), - EBPF_OFFSET_OF(test_program_context_t, data_start), - EBPF_OFFSET_OF(test_program_context_t, data_end), - -1}; +static ebpf_context_descriptor_t _sample_ebpf_context_descriptor = { + sizeof(test_program_context_t), + EBPF_OFFSET_OF(test_program_context_t, data_start), + EBPF_OFFSET_OF(test_program_context_t, data_end), + -1}; // Test Extension Helper function prototype descriptors. static ebpf_helper_function_prototype_t _sample_ebpf_extension_helper_function_prototype[] = { @@ -63,9 +64,10 @@ static int64_t _sample_ebpf_extension_replace( _In_ const void* buffer, uint32_t size, int64_t position, _In_ const void* replace, uint32_t arg_size); -static const void* _sample_ebpf_extension_helpers[] = {(void*)&_sample_ebpf_extension_helper_function1, - (void*)&_sample_ebpf_extension_find, - (void*)&_sample_ebpf_extension_replace}; +static const void* _sample_ebpf_extension_helpers[] = { + (void*)&_sample_ebpf_extension_helper_function1, + (void*)&_sample_ebpf_extension_find, + (void*)&_sample_ebpf_extension_replace}; static ebpf_helper_function_addresses_t _sample_ebpf_extension_helper_function_address_table = { EBPF_COUNT_OF(_sample_ebpf_extension_helpers), (uint64_t*)_sample_ebpf_extension_helpers}; @@ -201,9 +203,10 @@ _sample_ebpf_extension_hook_provider_detach_client(_In_ void* provider_binding_c // Test eBPF extension Hook NPI provider characteristics ebpf_attach_provider_data_t _sample_ebpf_extension_attach_provider_data; -ebpf_extension_data_t _sample_ebpf_extension_hook_provider_data = {EBPF_ATTACH_PROVIDER_DATA_VERSION, - sizeof(_sample_ebpf_extension_attach_provider_data), - &_sample_ebpf_extension_attach_provider_data}; +ebpf_extension_data_t _sample_ebpf_extension_hook_provider_data = { + EBPF_ATTACH_PROVIDER_DATA_VERSION, + sizeof(_sample_ebpf_extension_attach_provider_data), + &_sample_ebpf_extension_attach_provider_data}; const NPI_PROVIDER_CHARACTERISTICS _sample_ebpf_extension_hook_provider_characteristics = { 0, diff --git a/tests/sample/map_in_map.c b/tests/sample/map_in_map.c index 9b2d905ec..43b874338 100644 --- a/tests/sample/map_in_map.c +++ b/tests/sample/map_in_map.c @@ -7,12 +7,13 @@ typedef unsigned int uint32_t; typedef unsigned long uint64_t; SEC("maps") -struct bpf_map outer_map = {.type = BPF_MAP_TYPE_ARRAY_OF_MAPS, - .key_size = sizeof(uint32_t), - .value_size = sizeof(uint32_t), - .max_entries = 1, - // inner_map_idx refers to the map index in the same ELF object. - .inner_map_idx = 1}; // (uint32_t)&inner_map +struct bpf_map outer_map = { + .type = BPF_MAP_TYPE_ARRAY_OF_MAPS, + .key_size = sizeof(uint32_t), + .value_size = sizeof(uint32_t), + .max_entries = 1, + // inner_map_idx refers to the map index in the same ELF object. + .inner_map_idx = 1}; // (uint32_t)&inner_map SEC("maps") struct bpf_map inner_map = { diff --git a/tests/sample/repro.c b/tests/sample/repro.c index a4a1fd9e6..6fe3461c1 100644 --- a/tests/sample/repro.c +++ b/tests/sample/repro.c @@ -21,11 +21,12 @@ typedef unsigned char uint8_t; #include "ebpf_helpers.h" #pragma clang section data = "maps" -ebpf_map_definition_t test_map = {.size = sizeof(ebpf_map_definition_t), - .type = BPF_MAP_TYPE_HASH, - .key_size = sizeof(uint64_t), - .value_size = sizeof(uint64_t), - .max_entries = 1}; +ebpf_map_definition_t test_map = { + .size = sizeof(ebpf_map_definition_t), + .type = BPF_MAP_TYPE_HASH, + .key_size = sizeof(uint64_t), + .value_size = sizeof(uint64_t), + .max_entries = 1}; #pragma clang section text = "bind" int diff --git a/tests/sample/tail_call_map.c b/tests/sample/tail_call_map.c index dce9ab2c3..a4cecc435 100644 --- a/tests/sample/tail_call_map.c +++ b/tests/sample/tail_call_map.c @@ -7,11 +7,12 @@ #include "ebpf_helpers.h" #include "ebpf_nethooks.h" -__attribute__((section("maps"), used)) struct bpf_map outer_map = {.size = sizeof(struct bpf_map), - .type = BPF_MAP_TYPE_ARRAY_OF_MAPS, - .key_size = sizeof(uint32_t), - .value_size = sizeof(uint32_t), - .max_entries = 1}; +__attribute__((section("maps"), used)) struct bpf_map outer_map = { + .size = sizeof(struct bpf_map), + .type = BPF_MAP_TYPE_ARRAY_OF_MAPS, + .key_size = sizeof(uint32_t), + .value_size = sizeof(uint32_t), + .max_entries = 1}; __attribute__((section("xdp_prog"), used)) int caller(struct xdp_md* ctx) diff --git a/tests/sample/test_sample_ebpf.c b/tests/sample/test_sample_ebpf.c index d382ff15c..7eff2469a 100644 --- a/tests/sample/test_sample_ebpf.c +++ b/tests/sample/test_sample_ebpf.c @@ -10,11 +10,12 @@ #define VALUE_SIZE 32 #pragma clang section data = "maps" -ebpf_map_definition_t test_map = {.size = sizeof(ebpf_map_definition_t), - .type = BPF_MAP_TYPE_ARRAY, - .key_size = sizeof(uint32_t), - .value_size = VALUE_SIZE, - .max_entries = 2}; +ebpf_map_definition_t test_map = { + .size = sizeof(ebpf_map_definition_t), + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(uint32_t), + .value_size = VALUE_SIZE, + .max_entries = 2}; #pragma clang section text = "sample_ext" int diff --git a/tools/encode_program_info/encode_program_info.cpp b/tools/encode_program_info/encode_program_info.cpp index 68860e61d..1f98817f8 100644 --- a/tools/encode_program_info/encode_program_info.cpp +++ b/tools/encode_program_info/encode_program_info.cpp @@ -84,10 +84,11 @@ _encode_xdp() ebpf_result_t return_value; uint8_t* buffer = NULL; unsigned long buffer_size = 0; - ebpf_context_descriptor_t xdp_context_descriptor = {sizeof(xdp_md_t), - EBPF_OFFSET_OF(xdp_md_t, data), - EBPF_OFFSET_OF(xdp_md_t, data_end), - EBPF_OFFSET_OF(xdp_md_t, data_meta)}; + ebpf_context_descriptor_t xdp_context_descriptor = { + sizeof(xdp_md_t), + EBPF_OFFSET_OF(xdp_md_t, data), + EBPF_OFFSET_OF(xdp_md_t, data_end), + EBPF_OFFSET_OF(xdp_md_t, data_meta)}; ebpf_program_type_descriptor_t xdp_program_type = {"xdp", &xdp_context_descriptor, EBPF_PROGRAM_TYPE_XDP}; ebpf_program_info_t xdp_program_info = { xdp_program_type, EBPF_COUNT_OF(_ebpf_helper_function_prototype), _ebpf_helper_function_prototype};