Skip to content

Commit

Permalink
PR Feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
shankarseal committed Mar 27, 2024
1 parent 6cd16fd commit 1418a44
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 18 deletions.
7 changes: 4 additions & 3 deletions docs/eBpfExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ This is a mandatory header that is common to all data structures needed by eBPF
#define EBPF_PROGRAM_TYPE_DESCRIPTOR_CURRENT_VERSION_SIZE \
(EBPF_OFFSET_OF(ebpf_program_type_descriptor_t, is_privileged) + sizeof(char))
```
> NOTE: Extension developers **must not** set the `size` field of these structures to `sizeof()` of the corresponding type.
> NOTE: Extension developers **must not** set the `size` field of these structures to `sizeof()` of the corresponding type. Instead,
> the `CURRENT_VERSION_SIZE` macros defined in `ebpf_windows.h` should be used.
#### `ebpf_program_data_t` Struct
The various fields of this structure should be set as follows:
Expand Down Expand Up @@ -401,11 +402,11 @@ To operate on the eBPF store, the user mode application needs to link with eBPFA
_In_reads_(section_info_count) const ebpf_program_section_info_t* section_info, uint32_t section_info_count);
```

- `ebpf_store_update_program_data`: updates program information in the eBPF store, given a pointer to an array of program information (i.e., `_ebpf_program_info`):
- `ebpf_store_update_program_information_array`: updates program information in the eBPF store, given a pointer to an array of program information (i.e., `_ebpf_program_info`):

```c
ebpf_result_t
ebpf_store_update_program_data(
ebpf_store_update_program_information_array(
_In_reads_(program_info_count) const ebpf_program_info_t* program_info, uint32_t program_info_count);
```

Expand Down
2 changes: 1 addition & 1 deletion ebpfapi/Source.def
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ EXPORTS
ebpf_program_query_info
ebpf_store_delete_program_information
ebpf_store_delete_section_information
ebpf_store_update_program_data
ebpf_store_update_program_information_array
ebpf_store_update_section_information
libbpf_attach_type_by_name
libbpf_bpf_attach_type_str
Expand Down
2 changes: 1 addition & 1 deletion include/ebpf_store_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C"
* @returns Status of the operation.
*/
ebpf_result_t
ebpf_store_update_program_data(
ebpf_store_update_program_information_array(
_In_reads_(program_info_count) const ebpf_program_info_t* program_info, uint32_t program_info_count);

/**
Expand Down
10 changes: 5 additions & 5 deletions include/ebpf_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ typedef enum _ebpf_helper_function

#define EBPF_PROGRAM_TYPE_DESCRIPTOR_CURRENT_VERSION 1
#define EBPF_PROGRAM_TYPE_DESCRIPTOR_CURRENT_VERSION_SIZE \
(EBPF_OFFSET_OF(ebpf_program_type_descriptor_t, is_privileged) + sizeof(char))
EBPF_SIZE_INCLUDING_FIELD(ebpf_program_type_descriptor_t, is_privileged)

#define EBPF_HELPER_FUNCTION_PROTOTYPE_CURRENT_VERSION 1
#define EBPF_HELPER_FUNCTION_PROTOTYPE_CURRENT_VERSION_SIZE \
(EBPF_OFFSET_OF(ebpf_helper_function_prototype_t, arguments) + 5 * sizeof(ebpf_argument_type_t))
EBPF_SIZE_INCLUDING_FIELD(ebpf_helper_function_prototype_t, arguments)

#define EBPF_PROGRAM_INFORMATION_CURRENT_VERSION 1
#define EBPF_PROGRAM_INFORMATION_CURRENT_VERSION_SIZE \
(EBPF_OFFSET_OF(ebpf_program_info_t, global_helper_prototype) + sizeof(ebpf_helper_function_prototype_t*))
EBPF_SIZE_INCLUDING_FIELD(ebpf_program_info_t, global_helper_prototype)

#define EBPF_HELPER_FUNCTION_ADDRESSES_CURRENT_VERSION 1

#define EBPF_PROGRAM_DATA_CURRENT_VERSION 1
#define EBPF_PROGRAM_DATA_CURRENT_VERSION_SIZE (EBPF_OFFSET_OF(ebpf_program_data_t, required_irql) + sizeof(uint8_t))
#define EBPF_PROGRAM_DATA_CURRENT_VERSION_SIZE EBPF_SIZE_INCLUDING_FIELD(ebpf_program_data_t, required_irql)

#define EBPF_PROGRAM_SECTION_INFORMATION_CURRENT_VERSION 1
#define EBPF_PROGRAM_SECTION_INFORMATION_CURRENT_VERSION_SIZE \
(EBPF_OFFSET_OF(ebpf_program_section_info_t, bpf_attach_type) + sizeof(uint32_t))
EBPF_SIZE_INCLUDING_FIELD(ebpf_program_section_info_t, bpf_attach_type)

/**
* @brief Header of an eBPF extension data structure.
Expand Down
6 changes: 1 addition & 5 deletions libs/execution_context/ebpf_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ typedef enum _ebpf_link_state
EBPF_LINK_STATE_DETACHED, ///< Program is detached from a provider.
} ebpf_link_state_t;

// Latest version of the eBPF extension attach/hook data structures.
#define EBPF_ATTACH_CLIENT_DATA_VERSION EBPF_ATTACH_CLIENT_DATA_CURRENT_VERSION
#define EBPF_ATTACH_PROVIDER_DATA_VERSION EBPF_ATTACH_PROVIDER_DATA_CURRENT_VERSION

typedef struct _ebpf_link
{
ebpf_core_object_t object;
Expand Down Expand Up @@ -63,7 +59,7 @@ static const NPI_CLIENT_CHARACTERISTICS _ebpf_link_client_characteristics = {
_ebpf_link_client_detach_provider,
NULL,
{
EBPF_ATTACH_CLIENT_DATA_VERSION,
EBPF_ATTACH_CLIENT_DATA_CURRENT_VERSION,
sizeof(NPI_REGISTRATION_INSTANCE),
&EBPF_HOOK_EXTENSION_IID,
NULL,
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/ebpf_shared_framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ CXPLAT_EXTERN_C_BEGIN

#define EBPF_COUNT_OF(arr) (sizeof(arr) / sizeof(arr[0]))
#define EBPF_OFFSET_OF(s, m) (((size_t) & ((s*)0)->m))
#define EBPF_FIELD_SIZE(s, m) (sizeof(((s*)0)->m))
#define EBPF_SIZE_INCLUDING_FIELD(s, m) (EBPF_OFFSET_OF(s, m) + EBPF_FIELD_SIZE(s, m))
#define EBPF_FROM_FIELD(s, m, o) (s*)((uint8_t*)o - EBPF_OFFSET_OF(s, m))

#define EBPF_CACHE_LINE_SIZE 64
Expand Down
2 changes: 1 addition & 1 deletion libs/store_helper/ebpf_store_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ _ebpf_store_update_program_info(ebpf_store_key_t program_key, _In_ const ebpf_pr
}

ebpf_result_t
ebpf_store_update_program_data(
ebpf_store_update_program_information_array(
_In_reads_(program_info_count) const ebpf_program_info_t* program_info, uint32_t program_info_count)
{
ebpf_result_t result = EBPF_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion tools/export_program_info/export_program_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export_all_program_information()
uint32_t status = ERROR_SUCCESS;
size_t array_size = _countof(_program_information_array);
for (uint32_t i = 0; i < array_size; i++) {
status = ebpf_store_update_program_data(_program_information_array[i], 1);
status = ebpf_store_update_program_information_array(_program_information_array[i], 1);
if (status != ERROR_SUCCESS) {
break;
}
Expand Down
2 changes: 2 additions & 0 deletions undocked/tests/sample/ext/inc/sample_ext_program_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#define EBPF_COUNT_OF(arr) (sizeof(arr) / sizeof(arr[0]))
#define EBPF_OFFSET_OF(s, m) (((size_t) & ((s*)0)->m))
#define EBPF_FIELD_SIZE(s, m) (sizeof(((s*)0)->m))
#define EBPF_SIZE_INCLUDING_FIELD(s, m) (EBPF_OFFSET_OF(s, m) + EBPF_FIELD_SIZE(s, m))

static const ebpf_context_descriptor_t _sample_ebpf_context_descriptor = {
sizeof(sample_program_context_t),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export_program_information()
uint32_t status = ERROR_SUCCESS;
size_t array_size = _countof(_program_information_array);
for (uint32_t i = 0; i < array_size; i++) {
status = ebpf_store_update_program_data(_program_information_array[i], 1);
status = ebpf_store_update_program_information_array(_program_information_array[i], 1);
if (status != ERROR_SUCCESS) {
break;
}
Expand Down

0 comments on commit 1418a44

Please sign in to comment.