Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
saxena-anurag committed Feb 29, 2024
1 parent ff2a400 commit 2de7a78
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
68 changes: 46 additions & 22 deletions libs/execution_context/ebpf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ ebpf_core_terminate()
ebpf_platform_terminate();
}

#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
_Must_inspect_result_ ebpf_result_t
ebpf_core_load_code(
ebpf_handle_t program_handle,
Expand All @@ -317,12 +318,17 @@ ebpf_core_load_code(
EBPF_OBJECT_RELEASE_REFERENCE((ebpf_core_object_t*)program);
EBPF_RETURN_RESULT(retval);
}
#endif

#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
static ebpf_result_t
_ebpf_core_protocol_load_code(_In_ const ebpf_operation_load_code_request_t* request)
{
EBPF_LOG_ENTRY();

#if defined(CONFIG_BPF_JIT_DISABLED) && defined(CONFIG_BPF_INTERPRETER_DISABLED)
UNREFERENCED_PARAMETER(request);
EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED);
#else
ebpf_result_t retval;
uint8_t* code = NULL;
size_t code_length = 0;
Expand Down Expand Up @@ -359,8 +365,8 @@ _ebpf_core_protocol_load_code(_In_ const ebpf_operation_load_code_request_t* req

Done:
EBPF_RETURN_RESULT(retval);
#endif // CONFIG_BPF_JIT_DISABLED && CONFIG_BPF_INTERPRETER_DISABLED
}
#endif

_Must_inspect_result_ ebpf_result_t
ebpf_core_resolve_helper(
Expand Down Expand Up @@ -400,14 +406,19 @@ ebpf_core_resolve_helper(
EBPF_RETURN_RESULT(return_value);
}

#if !defined(CONFIG_BPF_JIT_DISABLED)
static ebpf_result_t
_ebpf_core_protocol_resolve_helper(
_In_ const ebpf_operation_resolve_helper_request_t* request,
_Inout_ ebpf_operation_resolve_helper_reply_t* reply,
uint16_t reply_length)
{
EBPF_LOG_ENTRY();

#if defined(CONFIG_BPF_JIT_DISABLED)
UNREFERENCED_PARAMETER(request);
UNREFERENCED_PARAMETER(reply);
EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED);
#else
uint32_t* request_helper_ids = NULL;
size_t required_reply_length = 0;
size_t helper_id_length;
Expand Down Expand Up @@ -447,8 +458,8 @@ _ebpf_core_protocol_resolve_helper(

ebpf_free(request_helper_ids);
EBPF_RETURN_RESULT(return_value);
#endif // CONFIG_BPF_JIT_DISABLED
}
#endif

_Must_inspect_result_ ebpf_result_t
ebpf_core_resolve_maps(
Expand Down Expand Up @@ -491,14 +502,20 @@ ebpf_core_resolve_maps(
EBPF_RETURN_RESULT(return_value);
}

#if !defined(CONFIG_BPF_JIT_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED)
static ebpf_result_t
_ebpf_core_protocol_resolve_map(
_In_ const struct _ebpf_operation_resolve_map_request* request,
_Inout_ struct _ebpf_operation_resolve_map_reply* reply,
uint16_t reply_length)
{
EBPF_LOG_ENTRY();

#if defined(CONFIG_BPF_JIT_DISABLED)
UNREFERENCED_PARAMETER(request);
UNREFERENCED_PARAMETER(reply);
EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED);
#else
size_t map_handle_length;
ebpf_result_t return_value = ebpf_safe_size_t_subtract(
request->header.length, EBPF_OFFSET_OF(ebpf_operation_resolve_map_request_t, map_handle), &map_handle_length);
Expand Down Expand Up @@ -526,8 +543,9 @@ _ebpf_core_protocol_resolve_map(

Done:
EBPF_RETURN_RESULT(return_value);
#endif // CONFIG_BPF_JIT_DISABLED
}
#endif
// #endif

_Must_inspect_result_ ebpf_result_t
ebpf_core_create_map(
Expand Down Expand Up @@ -578,12 +596,18 @@ _ebpf_core_protocol_create_map(
EBPF_RETURN_RESULT(retval);
}

#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
static ebpf_result_t
_ebpf_core_protocol_create_program(
_In_ const ebpf_operation_create_program_request_t* request, _Inout_ ebpf_operation_create_program_reply_t* reply)
{
EBPF_LOG_ENTRY();

#if defined(CONFIG_BPF_JIT_DISABLED) && defined(CONFIG_BPF_INTERPRETER_DISABLED)
UNREFERENCED_PARAMETER(request);
UNREFERENCED_PARAMETER(reply);
EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED);
#else
ebpf_result_t retval;
ebpf_program_parameters_t parameters = {0};
uint8_t* file_name = NULL;
Expand Down Expand Up @@ -620,8 +644,9 @@ _ebpf_core_protocol_create_program(

Done:
EBPF_RETURN_RESULT(retval);
#endif // CONFIG_BPF_JIT_DISABLED && CONFIG_BPF_INTERPRETER_DISABLED
}
#endif
// #endif

static ebpf_result_t
_ebpf_core_protocol_load_native_module(
Expand Down Expand Up @@ -1597,20 +1622,27 @@ _ebpf_core_protocol_close_handle(_In_ const ebpf_operation_close_handle_request_
EBPF_RETURN_RESULT(ebpf_handle_close(request->handle));
}

#if !defined(CONFIG_BPF_JIT_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED)
static uint64_t
_ebpf_core_protocol_get_ec_function(
_In_ const ebpf_operation_get_ec_function_request_t* request, _Inout_ ebpf_operation_get_ec_function_reply_t* reply)
{
EBPF_LOG_ENTRY();

#if defined(CONFIG_BPF_JIT_DISABLED)
UNREFERENCED_PARAMETER(request);
UNREFERENCED_PARAMETER(reply);
EBPF_RETURN_RESULT(EBPF_OPERATION_NOT_SUPPORTED);
#else
if (request->function != EBPF_EC_FUNCTION_LOG) {
return EBPF_INVALID_ARGUMENT;
}

reply->address = (uint64_t)ebpf_log_function;
EBPF_RETURN_RESULT(EBPF_SUCCESS);
#endif // CONFIG_BPF_JIT_DISABLED
}
#endif
// #endif

// Get helper info for a program or program type. This is used by the jitter/verifier,
// not by libbpf which instead uses ebpf_program_get_info
Expand Down Expand Up @@ -2392,12 +2424,12 @@ typedef struct _ebpf_protocol_handler
} const ebpf_protocol_handler_t;

#define PROTOCOL_NATIVE_MODE 1
#if !defined(CONFIG_BPF_JIT_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED)
#define PROTOCOL_JIT_MODE 2
#endif
#if !defined(CONFIG_BPF_INTERPRETER_DISABLED)
// #endif
// #if !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#define PROTOCOL_INTERPRET_MODE 4
#endif
// #endif
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#define PROTOCOL_JIT_OR_INTERPRET_MODE (PROTOCOL_JIT_MODE | PROTOCOL_INTERPRET_MODE)
#define PROTOCOL_ALL_MODES (PROTOCOL_NATIVE_MODE | PROTOCOL_JIT_MODE | PROTOCOL_INTERPRET_MODE)
Expand Down Expand Up @@ -2475,17 +2507,11 @@ ALIAS_TYPES(get_handle_by_id, get_map_handle_by_id)
ALIAS_TYPES(get_handle_by_id, get_program_handle_by_id)

static ebpf_protocol_handler_t _ebpf_protocol_handlers[] = {
#if !defined(CONFIG_BPF_JIT_DISABLED)
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_VARIABLE_REPLY(resolve_helper, helper_id, address, PROTOCOL_JIT_MODE),
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_VARIABLE_REPLY(resolve_map, map_handle, address, PROTOCOL_JIT_MODE),
#endif
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_FIXED_REPLY(create_program, data, PROTOCOL_JIT_OR_INTERPRET_MODE),
#endif
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_FIXED_REPLY(create_map, data, PROTOCOL_ALL_MODES),
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(load_code, code, PROTOCOL_JIT_OR_INTERPRET_MODE),
#endif
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_VARIABLE_REPLY(map_find_element, key, value, PROTOCOL_ALL_MODES),
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(map_update_element, data, PROTOCOL_ALL_MODES),
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(map_update_element_with_handle, key, PROTOCOL_ALL_MODES),
Expand All @@ -2498,9 +2524,7 @@ static ebpf_protocol_handler_t _ebpf_protocol_handlers[] = {
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_FIXED_REPLY(link_program, data, PROTOCOL_ALL_MODES),
DECLARE_PROTOCOL_HANDLER_VARIABLE_REQUEST_NO_REPLY(unlink_program, data, PROTOCOL_ALL_MODES),
DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_NO_REPLY(close_handle, PROTOCOL_ALL_MODES),
#if !defined(CONFIG_BPF_JIT_DISABLED)
DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_FIXED_REPLY(get_ec_function, PROTOCOL_JIT_MODE),
#endif
DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_VARIABLE_REPLY(get_program_info, data, PROTOCOL_ALL_MODES),
DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_VARIABLE_REPLY(get_pinned_map_info, data, PROTOCOL_ALL_MODES),
DECLARE_PROTOCOL_HANDLER_FIXED_REQUEST_FIXED_REPLY(get_link_handle_by_id, PROTOCOL_ALL_MODES),
Expand Down
24 changes: 8 additions & 16 deletions libs/execution_context/ebpf_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@

typedef enum _ebpf_operation_id
{
#if !defined(CONFIG_BPF_JIT_DISABLED)
EBPF_OPERATION_RESOLVE_HELPER,
EBPF_OPERATION_RESOLVE_MAP,
#endif
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
EBPF_OPERATION_CREATE_PROGRAM,
#endif
EBPF_OPERATION_CREATE_MAP,
#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
EBPF_OPERATION_LOAD_CODE,
#endif
EBPF_OPERATION_MAP_FIND_ELEMENT,
EBPF_OPERATION_MAP_UPDATE_ELEMENT,
EBPF_OPERATION_MAP_UPDATE_ELEMENT_WITH_HANDLE,
Expand All @@ -31,9 +25,7 @@ typedef enum _ebpf_operation_id
EBPF_OPERATION_LINK_PROGRAM,
EBPF_OPERATION_UNLINK_PROGRAM,
EBPF_OPERATION_CLOSE_HANDLE,
#if !defined(CONFIG_BPF_JIT_DISABLED)
EBPF_OPERATION_GET_EC_FUNCTION,
#endif
EBPF_OPERATION_GET_PROGRAM_INFO,
EBPF_OPERATION_GET_PINNED_MAP_INFO,
EBPF_OPERATION_GET_LINK_HANDLE_BY_ID,
Expand Down Expand Up @@ -74,7 +66,7 @@ typedef enum _ebpf_ec_function
EBPF_EC_FUNCTION_LOG
} ebpf_ec_function_t;

#if !defined(CONFIG_BPF_JIT_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED)
typedef struct _ebpf_operation_resolve_helper_request
{
struct _ebpf_operation_header header;
Expand All @@ -100,9 +92,9 @@ typedef struct _ebpf_operation_resolve_map_reply
struct _ebpf_operation_header header;
uintptr_t address[1];
} ebpf_operation_resolve_map_reply_t;
#endif
// #endif

#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
typedef struct _ebpf_operation_create_program_request
{
struct _ebpf_operation_header header;
Expand All @@ -117,17 +109,17 @@ typedef struct _ebpf_operation_create_program_reply
struct _ebpf_operation_header header;
ebpf_handle_t program_handle;
} ebpf_operation_create_program_reply_t;
#endif
// #endif

#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)
typedef struct _ebpf_operation_load_code_request
{
struct _ebpf_operation_header header;
ebpf_handle_t program_handle;
ebpf_code_type_t code_type;
uint8_t code[1];
} ebpf_operation_load_code_request_t;
#endif
// #endif

typedef struct _ebpf_operation_create_map_request
{
Expand Down Expand Up @@ -283,7 +275,7 @@ typedef struct _ebpf_operation_close_handle_request
ebpf_handle_t handle;
} ebpf_operation_close_handle_request_t;

#if !defined(CONFIG_BPF_JIT_DISABLED)
// #if !defined(CONFIG_BPF_JIT_DISABLED)
typedef struct _ebpf_operation_get_ec_function_request
{
struct _ebpf_operation_header header;
Expand All @@ -295,7 +287,7 @@ typedef struct _ebpf_operation_get_ec_function_reply
struct _ebpf_operation_header header;
uintptr_t address;
} ebpf_operation_get_ec_function_reply_t;
#endif
// #endif

typedef struct _ebpf_operation_get_program_info_request
{
Expand Down

0 comments on commit 2de7a78

Please sign in to comment.