Skip to content

Commit

Permalink
PR feedback from Anurag
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Aug 17, 2023
1 parent c594542 commit b47cad1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
19 changes: 2 additions & 17 deletions ebpfsvc/rpc_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ ebpf_server_verify_and_load_program(
if (info->instruction_count == 0) {
return EBPF_INVALID_ARGUMENT;
}
*logs = nullptr;
*logs_size = 0;

// Set the handle of program being verified in thread-local storage.
set_program_under_verification(reinterpret_cast<ebpf_handle_t>(info->program_handle));

const char* ebpf_logs = nullptr;
uint32_t ebpf_logs_size = 0;
result = ebpf_verify_and_load_program(
&info->program_type,
reinterpret_cast<ebpf_handle_t>(info->program_handle),
Expand All @@ -40,19 +36,8 @@ ebpf_server_verify_and_load_program(
info->handle_map,
info->instruction_count,
reinterpret_cast<ebpf_inst*>(info->instructions),
&ebpf_logs,
&ebpf_logs_size);

if (ebpf_logs) {
// The ebpf_logs buffer was allocated by the ebpf allocator whereas we
// must return a string allocated by the MIDL allocator.
*logs = (char*)MIDL_user_allocate(ebpf_logs_size);
if (*logs) {
memcpy(*logs, ebpf_logs, ebpf_logs_size);
ebpf_free((void*)ebpf_logs);
*logs_size = ebpf_logs_size;
}
}
const_cast<const char**>(logs),
logs_size);

ebpf_clear_thread_local_storage();
return result;
Expand Down
5 changes: 3 additions & 2 deletions ebpfsvc/rpc_util.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT

#include "ebpf_platform.h"
#include "svc_common.h"

#include <winsock2.h>
Expand Down Expand Up @@ -117,11 +118,11 @@ shutdown_rpc_server()
_Must_inspect_result_ _Ret_maybenull_ _Post_writable_byte_size_(size) void* __RPC_USER
MIDL_user_allocate(_In_ size_t size)
{
return malloc(size);
return ebpf_allocate(size);
}

void __RPC_USER
MIDL_user_free(_Pre_maybenull_ _Post_invalid_ void* p)
{
free(p);
ebpf_free(p);
}

0 comments on commit b47cad1

Please sign in to comment.