Skip to content

Commit d9955f7

Browse files
authored
Remove deprecated internal API ebpf_allocate() (#4681)
* Remove deprecated ebpf_allocate() API Replace all calls to deprecated ebpf_allocate() with ebpf_allocate_with_tag() using EBPF_POOL_TAG_DEFAULT. This cleanup removes the deprecated internal API as requested in issue #4674. Changes: - Replaced ebpf_allocate(size) calls with ebpf_allocate_with_tag(size, EBPF_POOL_TAG_DEFAULT) - Removed deprecated ebpf_allocate() function definition from ebpf_shared_framework.h - Updated all callers across the codebase to use the non-deprecated API Fixes #4674 * Fix syntax errors in ebpf_allocate_with_tag calls - Fix parentheses placement in macro definitions for malloc/calloc - Fix parameter separation in function calls - Ensure all calls use proper syntax: ebpf_allocate_with_tag(size, tag) Fixes compilation errors in CI builds. * Fix comprehensive syntax errors in ebpf_allocate_with_tag calls Correct parentheses placement across 24 files where sizeof() parameters were incorrectly grouped with EBPF_POOL_TAG_DEFAULT. Changes: - Fixed ~60 function calls with wrong syntax: sizeof(type, tag) -> sizeof(type), tag - Corrected macro definitions for malloc/calloc in ubpf files - Fixed multiplication order in array allocations - Resolved all CI compilation errors from original API migration All ebpf_allocate_with_tag calls now use proper two-parameter syntax.
1 parent 28d9238 commit d9955f7

29 files changed

+87
-99
lines changed

ebpfapi/rpc_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ clean_up_rpc_binding()
193193
_Must_inspect_result_ _Ret_maybenull_
194194
_Post_writable_byte_size_(size) void* __RPC_USER MIDL_user_allocate(_In_ size_t size)
195195
{
196-
return ebpf_allocate(size);
196+
return ebpf_allocate_with_tag(size, EBPF_POOL_TAG_DEFAULT);
197197
}
198198

199199
void __RPC_USER

ebpfsvc/rpc_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ shutdown_rpc_server()
117117
_Must_inspect_result_ _Ret_maybenull_
118118
_Post_writable_byte_size_(size) void* __RPC_USER MIDL_user_allocate(_In_ size_t size)
119119
{
120-
return ebpf_allocate(size);
120+
return ebpf_allocate_with_tag(size, EBPF_POOL_TAG_DEFAULT);
121121
}
122122

123123
void __RPC_USER

libs/api/Verifier.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ load_byte_code(
326326
}
327327

328328
for (auto& raw_program : raw_programs) {
329-
program = (ebpf_program_t*)ebpf_allocate(sizeof(ebpf_program_t));
329+
program = (ebpf_program_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_t), EBPF_POOL_TAG_DEFAULT);
330330
if (program == nullptr) {
331331
result = EBPF_NO_MEMORY;
332332
goto Exit;
@@ -348,7 +348,7 @@ load_byte_code(
348348
goto Exit;
349349
}
350350
size_t ebpf_bytes = instruction_count * sizeof(ebpf_inst);
351-
program->instructions = (ebpf_inst*)ebpf_allocate(ebpf_bytes);
351+
program->instructions = (ebpf_inst*)ebpf_allocate_with_tag(ebpf_bytes, EBPF_POOL_TAG_DEFAULT);
352352
if (program->instructions == nullptr) {
353353
result = EBPF_NO_MEMORY;
354354
goto Exit;
@@ -405,7 +405,7 @@ load_byte_code(
405405
goto Exit;
406406
}
407407

408-
map = (ebpf_map_t*)ebpf_allocate(sizeof(ebpf_map_t));
408+
map = (ebpf_map_t*)ebpf_allocate_with_tag(sizeof(ebpf_map_t), EBPF_POOL_TAG_DEFAULT);
409409
if (map == nullptr) {
410410
result = EBPF_NO_MEMORY;
411411
goto Exit;
@@ -435,7 +435,7 @@ load_byte_code(
435435
} catch (std::runtime_error& err) {
436436
auto message = err.what();
437437
auto message_length = strlen(message) + 1;
438-
char* error = reinterpret_cast<char*>(ebpf_allocate(message_length + 1));
438+
char* error = reinterpret_cast<char*>(ebpf_allocate_with_tag(message_length + 1, EBPF_POOL_TAG_DEFAULT));
439439
if (error) {
440440
strcpy_s(error, message_length, message);
441441
}
@@ -468,7 +468,7 @@ load_byte_code(
468468
static void
469469
_ebpf_add_stat(_Inout_ ebpf_api_program_info_t* info, std::string key, int value) noexcept(false)
470470
{
471-
ebpf_stat_t* stat = (ebpf_stat_t*)ebpf_allocate(sizeof(*stat));
471+
ebpf_stat_t* stat = (ebpf_stat_t*)ebpf_allocate_with_tag(sizeof(*stat), EBPF_POOL_TAG_DEFAULT);
472472
if (stat == nullptr) {
473473
throw std::runtime_error("Out of memory");
474474
}
@@ -503,7 +503,7 @@ ebpf_api_elf_enumerate_programs(
503503
try {
504504
auto raw_programs = read_elf(file, section ? std::string(section) : std::string(), verifier_options, platform);
505505
for (const auto& raw_program : raw_programs) {
506-
info = (ebpf_api_program_info_t*)ebpf_allocate(sizeof(*info));
506+
info = (ebpf_api_program_info_t*)ebpf_allocate_with_tag(sizeof(*info), EBPF_POOL_TAG_DEFAULT);
507507
if (info == nullptr) {
508508
throw std::runtime_error("Out of memory");
509509
}
@@ -548,7 +548,7 @@ ebpf_api_elf_enumerate_programs(
548548
info->offset_in_section = raw_program.insn_off;
549549
std::vector<uint8_t> raw_data = convert_ebpf_program_to_bytes(raw_program.prog);
550550
info->raw_data_size = raw_data.size();
551-
info->raw_data = (char*)ebpf_allocate(info->raw_data_size);
551+
info->raw_data = (char*)ebpf_allocate_with_tag(info->raw_data_size, EBPF_POOL_TAG_DEFAULT);
552552
if (info->raw_data == nullptr) {
553553
throw std::runtime_error("Out of memory");
554554
}

libs/api/ebpf_api.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,8 @@ ebpf_program_query_info(
14831483

14841484
size_t file_name_length = reply->section_name_offset - reply->file_name_offset;
14851485
size_t section_name_length = reply->header.length - reply->section_name_offset;
1486-
char* local_file_name = reinterpret_cast<char*>(ebpf_allocate(file_name_length + 1));
1487-
char* local_section_name = reinterpret_cast<char*>(ebpf_allocate(section_name_length + 1));
1486+
char* local_file_name = reinterpret_cast<char*>(ebpf_allocate_with_tag(file_name_length + 1, EBPF_POOL_TAG_DEFAULT));
1487+
char* local_section_name = reinterpret_cast<char*>(ebpf_allocate_with_tag(section_name_length + 1, EBPF_POOL_TAG_DEFAULT));
14881488

14891489
if (!local_file_name || !local_section_name) {
14901490
ebpf_free(local_file_name);
@@ -1656,7 +1656,7 @@ ebpf_program_attach(
16561656

16571657
ebpf_assert(program);
16581658

1659-
ebpf_link_t* new_link = (ebpf_link_t*)ebpf_allocate(sizeof(ebpf_link_t));
1659+
ebpf_link_t* new_link = (ebpf_link_t*)ebpf_allocate_with_tag(sizeof(ebpf_link_t), EBPF_POOL_TAG_DEFAULT);
16601660
if (new_link == nullptr) {
16611661
EBPF_RETURN_RESULT(EBPF_NO_MEMORY);
16621662
}
@@ -1712,7 +1712,7 @@ ebpf_program_attach_by_fd(
17121712
EBPF_LOG_ENTRY();
17131713
ebpf_assert(link);
17141714

1715-
ebpf_link_t* new_link = (ebpf_link_t*)ebpf_allocate(sizeof(ebpf_link_t));
1715+
ebpf_link_t* new_link = (ebpf_link_t*)ebpf_allocate_with_tag(sizeof(ebpf_link_t), EBPF_POOL_TAG_DEFAULT);
17161716
if (new_link == nullptr) {
17171717
EBPF_RETURN_RESULT(EBPF_NO_MEMORY);
17181718
}
@@ -2286,7 +2286,7 @@ _initialize_ebpf_object_from_native_file(
22862286
object.execution_type = EBPF_EXECUTION_NATIVE;
22872287

22882288
for (ebpf_api_program_info_t* info = infos; info; info = info->next) {
2289-
program = (ebpf_program_t*)ebpf_allocate(sizeof(ebpf_program_t));
2289+
program = (ebpf_program_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_t), EBPF_POOL_TAG_DEFAULT);
22902290
if (program == nullptr) {
22912291
result = EBPF_NO_MEMORY;
22922292
goto Exit;
@@ -2580,7 +2580,7 @@ _ebpf_pe_get_map_definitions(
25802580
break;
25812581
}
25822582

2583-
map = (ebpf_map_t*)ebpf_allocate(sizeof(ebpf_map_t));
2583+
map = (ebpf_map_t*)ebpf_allocate_with_tag(sizeof(ebpf_map_t), EBPF_POOL_TAG_DEFAULT);
25842584
if (map == nullptr) {
25852585
goto Error;
25862586
}
@@ -2759,7 +2759,7 @@ _ebpf_pe_add_section(
27592759
std::string elf_section_name = pe_context->section_names[pe_section_name];
27602760
std::string program_name = pe_context->program_names[pe_section_name];
27612761

2762-
ebpf_api_program_info_t* info = (ebpf_api_program_info_t*)ebpf_allocate(sizeof(*info));
2762+
ebpf_api_program_info_t* info = (ebpf_api_program_info_t*)ebpf_allocate_with_tag(sizeof(*info), EBPF_POOL_TAG_DEFAULT);
27632763
if (info == nullptr) {
27642764
pe_context->result = EBPF_NO_MEMORY;
27652765
return_value = 1;
@@ -2785,7 +2785,7 @@ _ebpf_pe_add_section(
27852785
info->expected_attach_type = pe_context->section_attach_types[pe_section_name];
27862786

27872787
info->raw_data_size = section_header.Misc.VirtualSize;
2788-
info->raw_data = (char*)ebpf_allocate(section_header.Misc.VirtualSize);
2788+
info->raw_data = (char*)ebpf_allocate_with_tag(section_header.Misc.VirtualSize, EBPF_POOL_TAG_DEFAULT);
27892789
if (info->raw_data == nullptr || info->section_name == nullptr) {
27902790
pe_context->result = EBPF_NO_MEMORY;
27912791
return_value = 1;
@@ -3633,7 +3633,7 @@ _load_native_programs(
36333633
size_t buffer_size = offsetof(ebpf_operation_load_native_programs_reply_t, data) + handles_size;
36343634

36353635
if (count_of_maps > 0) {
3636-
*map_handles = (ebpf_handle_t*)ebpf_allocate(map_handles_size);
3636+
*map_handles = (ebpf_handle_t*)ebpf_allocate_with_tag(map_handles_size, EBPF_POOL_TAG_DEFAULT);
36373637
if (*map_handles == nullptr) {
36383638
EBPF_LOG_MESSAGE(
36393639
EBPF_TRACELOG_LEVEL_ERROR,
@@ -3645,7 +3645,7 @@ _load_native_programs(
36453645
}
36463646

36473647
if (count_of_programs > 0) {
3648-
*program_handles = (ebpf_handle_t*)ebpf_allocate(program_handles_size);
3648+
*program_handles = (ebpf_handle_t*)ebpf_allocate_with_tag(program_handles_size, EBPF_POOL_TAG_DEFAULT);
36493649
if (*program_handles == nullptr) {
36503650
EBPF_LOG_MESSAGE(
36513651
EBPF_TRACELOG_LEVEL_ERROR,

libs/api/libbpf_link.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bpf_link__open(const char* path)
2020
return nullptr;
2121
}
2222

23-
link = (struct bpf_link*)ebpf_allocate(sizeof(struct bpf_link));
23+
link = (struct bpf_link*)ebpf_allocate_with_tag(sizeof(struct bpf_link), EBPF_POOL_TAG_DEFAULT);
2424
if (!link) {
2525
(void)ebpf_close_fd(link_fd);
2626
libbpf_err(-ENOMEM);

libs/api_common/api_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ allocate_string(const std::string& string, uint32_t* length) noexcept
2121
{
2222
char* new_string;
2323
size_t string_length = string.size() + 1;
24-
new_string = (char*)ebpf_allocate(string_length);
24+
new_string = (char*)ebpf_allocate_with_tag(string_length, EBPF_POOL_TAG_DEFAULT);
2525
if (new_string != nullptr) {
2626
strcpy_s(new_string, string_length, string.c_str());
2727
if (length != nullptr) {

libs/api_common/device_helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ initialize_async_ioctl_operation(
210210
*async_ioctl_completion = nullptr;
211211

212212
async_ioctl_completion_context_t* local_async_ioctl_completion =
213-
(async_ioctl_completion_context_t*)ebpf_allocate(sizeof(async_ioctl_completion_context_t));
213+
(async_ioctl_completion_context_t*)ebpf_allocate_with_tag(sizeof(async_ioctl_completion_context_t), EBPF_POOL_TAG_DEFAULT);
214214
if (local_async_ioctl_completion == nullptr) {
215215
result = EBPF_NO_MEMORY;
216216
goto Exit;

libs/api_common/store_helper_internal.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ _ebpf_store_load_program_type_descriptor(
164164

165165
// Allocate the program type descriptor.
166166
local_program_type_descriptor =
167-
(ebpf_program_type_descriptor_t*)ebpf_allocate(sizeof(ebpf_program_type_descriptor_t));
167+
(ebpf_program_type_descriptor_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_type_descriptor_t), EBPF_POOL_TAG_DEFAULT);
168168
if (local_program_type_descriptor == nullptr) {
169169
result = EBPF_NO_MEMORY;
170170
goto Exit;
@@ -197,7 +197,7 @@ _ebpf_store_load_program_type_descriptor(
197197
}
198198

199199
// Allocate and read context descriptor.
200-
context_descriptor = (ebpf_context_descriptor_t*)ebpf_allocate(sizeof(ebpf_context_descriptor_t));
200+
context_descriptor = (ebpf_context_descriptor_t*)ebpf_allocate_with_tag(sizeof(ebpf_context_descriptor_t), EBPF_POOL_TAG_DEFAULT);
201201
if (context_descriptor == nullptr) {
202202
result = EBPF_NO_MEMORY;
203203
goto Exit;
@@ -276,7 +276,7 @@ _ebpf_store_load_program_information(
276276
}
277277

278278
// Allocate the program information struct.
279-
program_information = (ebpf_program_info_t*)ebpf_allocate(sizeof(ebpf_program_info_t));
279+
program_information = (ebpf_program_info_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_info_t), EBPF_POOL_TAG_DEFAULT);
280280
if (program_information == nullptr) {
281281
result = EBPF_NO_MEMORY;
282282
goto Exit;
@@ -289,7 +289,7 @@ _ebpf_store_load_program_information(
289289
}
290290

291291
// Allocate and read the program type GUID.
292-
program_type = (ebpf_program_type_t*)ebpf_allocate(sizeof(ebpf_program_type_t));
292+
program_type = (ebpf_program_type_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_type_t), EBPF_POOL_TAG_DEFAULT);
293293
if (program_type == nullptr) {
294294
result = EBPF_NO_MEMORY;
295295
goto Exit;
@@ -353,7 +353,7 @@ _ebpf_store_load_program_information(
353353
}
354354

355355
ebpf_helper_function_prototype_t* helper_prototype =
356-
(ebpf_helper_function_prototype_t*)ebpf_allocate(helper_count * sizeof(ebpf_helper_function_prototype_t));
356+
(ebpf_helper_function_prototype_t*)ebpf_allocate_with_tag(helper_count * sizeof(ebpf_helper_function_prototype_t), EBPF_POOL_TAG_DEFAULT);
357357
if (helper_prototype == nullptr) {
358358
result = EBPF_NO_MEMORY;
359359
goto Exit;
@@ -363,7 +363,7 @@ _ebpf_store_load_program_information(
363363
// Add space for null terminator.
364364
max_helper_name_size += 1;
365365

366-
helper_name = (wchar_t*)ebpf_allocate(max_helper_name_size * sizeof(wchar_t));
366+
helper_name = (wchar_t*)ebpf_allocate_with_tag(max_helper_name_size * sizeof(wchar_t), EBPF_POOL_TAG_DEFAULT);
367367
if (helper_name == nullptr) {
368368
result = EBPF_NO_MEMORY;
369369
goto Exit;
@@ -486,7 +486,7 @@ ebpf_store_load_program_data(
486486
if (program_info_array.size() > 0) {
487487
// Copy the vector data to a new array.
488488
auto size = program_info_array.size() * sizeof(ebpf_program_info_t*);
489-
*program_info = (ebpf_program_info_t**)ebpf_allocate(size);
489+
*program_info = (ebpf_program_info_t**)ebpf_allocate_with_tag(size, EBPF_POOL_TAG_DEFAULT);
490490
if (*program_info == nullptr) {
491491
result = EBPF_NO_MEMORY;
492492
goto Exit;
@@ -544,13 +544,13 @@ _load_section_data_information(
544544
goto Exit;
545545
}
546546

547-
program_type = (ebpf_program_type_t*)ebpf_allocate(sizeof(ebpf_program_type_t));
547+
program_type = (ebpf_program_type_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_type_t), EBPF_POOL_TAG_DEFAULT);
548548
if (program_type == nullptr) {
549549
result = EBPF_NO_MEMORY;
550550
goto Exit;
551551
}
552552

553-
attach_type = (ebpf_attach_type_t*)ebpf_allocate(sizeof(ebpf_attach_type_t));
553+
attach_type = (ebpf_attach_type_t*)ebpf_allocate_with_tag(sizeof(ebpf_attach_type_t), EBPF_POOL_TAG_DEFAULT);
554554
if (attach_type == nullptr) {
555555
result = EBPF_NO_MEMORY;
556556
goto Exit;
@@ -594,7 +594,7 @@ _load_section_data_information(
594594
goto Exit;
595595
}
596596

597-
section_information = (ebpf_section_definition_t*)ebpf_allocate(sizeof(ebpf_section_definition_t));
597+
section_information = (ebpf_section_definition_t*)ebpf_allocate_with_tag(sizeof(ebpf_section_definition_t), EBPF_POOL_TAG_DEFAULT);
598598
if (section_information == nullptr) {
599599
result = EBPF_NO_MEMORY;
600600
goto Exit;
@@ -691,7 +691,7 @@ ebpf_store_load_section_information(
691691
if (section_info_array.size() > 0) {
692692
// Copy the vector data to a new array.
693693
auto size = section_info_array.size() * sizeof(ebpf_section_definition_t*);
694-
*section_info = (ebpf_section_definition_t**)ebpf_allocate(size);
694+
*section_info = (ebpf_section_definition_t**)ebpf_allocate_with_tag(size, EBPF_POOL_TAG_DEFAULT);
695695
if (*section_info == nullptr) {
696696
result = EBPF_NO_MEMORY;
697697
goto Exit;
@@ -794,14 +794,14 @@ ebpf_store_load_global_helper_information(
794794
// Add space for null terminator.
795795
max_helper_name_size += 1;
796796

797-
helper_name = (wchar_t*)ebpf_allocate(max_helper_name_size * sizeof(wchar_t));
797+
helper_name = (wchar_t*)ebpf_allocate_with_tag(max_helper_name_size * sizeof(wchar_t), EBPF_POOL_TAG_DEFAULT);
798798
if (helper_name == nullptr) {
799799
result = EBPF_NO_MEMORY;
800800
goto Exit;
801801
}
802802

803803
helper_prototype =
804-
(ebpf_helper_function_prototype_t*)ebpf_allocate(max_helpers_count * sizeof(ebpf_helper_function_prototype_t));
804+
(ebpf_helper_function_prototype_t*)ebpf_allocate_with_tag(max_helpers_count * sizeof(ebpf_helper_function_prototype_t), EBPF_POOL_TAG_DEFAULT);
805805
if (helper_prototype == nullptr) {
806806
result = EBPF_NO_MEMORY;
807807
goto Exit;

libs/api_common/windows_platform_common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ _get_program_descriptor_from_info(
158158
goto Exit;
159159
}
160160
type->name = std::string(name);
161-
type->context_descriptor = (ebpf_context_descriptor_t*)ebpf_allocate(sizeof(ebpf_context_descriptor_t));
161+
type->context_descriptor = (ebpf_context_descriptor_t*)ebpf_allocate_with_tag(sizeof(ebpf_context_descriptor_t), EBPF_POOL_TAG_DEFAULT);
162162
if (type->context_descriptor == nullptr) {
163163
result = EBPF_NO_MEMORY;
164164
goto Exit;
@@ -167,7 +167,7 @@ _get_program_descriptor_from_info(
167167
(void*)type->context_descriptor,
168168
info->program_type_descriptor->context_descriptor,
169169
sizeof(ebpf_context_descriptor_t));
170-
ebpf_program_type_t* program_type = (ebpf_program_type_t*)ebpf_allocate(sizeof(ebpf_program_type_t));
170+
ebpf_program_type_t* program_type = (ebpf_program_type_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_type_t), EBPF_POOL_TAG_DEFAULT);
171171
if (program_type == nullptr) {
172172
result = EBPF_NO_MEMORY;
173173
goto Exit;
@@ -535,7 +535,7 @@ _update_global_helpers_for_program_information(
535535
goto Exit;
536536
}
537537
total_helper_size = total_helper_count * sizeof(ebpf_helper_function_prototype_t);
538-
new_helpers = (ebpf_helper_function_prototype_t*)ebpf_allocate(total_helper_size);
538+
new_helpers = (ebpf_helper_function_prototype_t*)ebpf_allocate_with_tag(total_helper_size, EBPF_POOL_TAG_DEFAULT);
539539
if (new_helpers == nullptr) {
540540
result = EBPF_NO_MEMORY;
541541
break;

libs/execution_context/ebpf_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ _ebpf_core_protocol_program_test_run(
11611161
goto Done;
11621162
}
11631163

1164-
options = (ebpf_program_test_run_options_t*)ebpf_allocate(sizeof(ebpf_program_test_run_options_t));
1164+
options = (ebpf_program_test_run_options_t*)ebpf_allocate_with_tag(sizeof(ebpf_program_test_run_options_t), EBPF_POOL_TAG_DEFAULT);
11651165
if (!options) {
11661166
retval = EBPF_NO_MEMORY;
11671167
goto Done;

0 commit comments

Comments
 (0)