Skip to content

Commit

Permalink
Separate out undocked components. (microsoft#3055)
Browse files Browse the repository at this point in the history
* remove not-needed includes

* fix

* fix

* update sample extension

* change include path

* export store APIs from ebpfapi.dll

* fix analyze build

* update dependencies

* add undocked projects

* undock sample_ext driver

* fix build

* more undocking

* fix build

* remove undocked projects from fuzzerdebug

* fix nuget

* remove usersim from export_program_info

* fix configuration manager

* fix tests

* skip building undocked samples for FuzzerDebug builds

* fix build

* try cicd changes

* fix cicd yml

* update export_program_info to not clean up all entries

* code cleanup

* delete global helpers from the store

* code cleanup

* export *delete* store APIs from ebpfapi

* code cleanup

* CR comments

* cr comments

* remove ansi APIs

* CR comments

* cr comments

* fix CI failure

* fix rebase build issues

* change default custom type to bind

* some more fixes

* fix tests

* fix tests

* update expected files

* fix bpf2c tests

* run export_program_info

* fix headers

* CR comments
  • Loading branch information
saxena-anurag authored Dec 7, 2023
1 parent 041d402 commit 3f5e0ba
Show file tree
Hide file tree
Showing 133 changed files with 20,410 additions and 19,592 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ jobs:
.\export_program_info.exe --clear
.\export_program_info.exe
- name: Configure eBPF store (undocked)
if: (steps.skip_check.outputs.should_skip != 'true') && (matrix.configurations != 'FuzzerDebug')
id: configure_ebpf_store_undocked
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
run: |
.\export_program_info_sample.exe --clear
.\export_program_info_sample.exe
- name: Run pre test command
if: steps.skip_check.outputs.should_skip != 'true' && (inputs.environment != 'ebpf_cicd_tests_ws2019' && inputs.environment != 'ebpf_cicd_tests_ws2022' && inputs.environment != 'ebpf_cicd_perf_ws2022')
id: run_pre_test_command
Expand Down
17 changes: 0 additions & 17 deletions docs/eBpfExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,23 +366,6 @@ When an eBPF extension is installed, it must update the eBPF store with the prog

To operate on the eBPF store, the extension must link the `\lib\ebpf_store_helper_km.lib` kernel-mode library and include the related `\include\ebpf_store_helper.h` header file, both distributed within the [eBPF for Windows NuGet package](https://www.nuget.org/packages/eBPF-for-Windows/). With these, the extension can use the following APIs to register program types, attach types and helper functions:

- `ebpf_store_update_helper_prototype`: updates the program type specific helper information in the eBPF store, given a pointer to the store key to be initialized and a pointer to the helper function prototype (i.e., `_ebpf_helper_function_prototype`):

```c
ebpf_result_t
ebpf_store_update_helper_prototype(
ebpf_store_key_t helper_info_key, _In_ const ebpf_helper_function_prototype_t* helper_info);
```c
```

- `ebpf_store_update_global_helper_information`: updates the global helper information in the eBPF store, given a pointer to an array of helper function prototypes:

```c
ebpf_result_t
ebpf_store_update_global_helper_information(
_In_reads_(helper_info_count) ebpf_helper_function_prototype_t* helper_info, uint32_t helper_info_count);
```

- `ebpf_store_update_section_information`: updates the section information in the eBPF store, given a pointer to an array of section information (i.e., `_ebpf_program_section_info`):

```c
Expand Down
350 changes: 206 additions & 144 deletions ebpf-for-windows.sln

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions ebpfapi/Source.def
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ EXPORTS
ebpf_program_attach
ebpf_program_attach_by_fd
ebpf_program_query_info
ebpf_store_delete_program_information
ebpf_store_delete_section_information
ebpf_store_update_program_information
ebpf_store_update_section_information
libbpf_attach_type_by_name
libbpf_bpf_attach_type_str
libbpf_bpf_link_type_str
Expand Down
2 changes: 0 additions & 2 deletions include/ebpf_extension_uuids.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "ebpf_windows.h"

#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
Expand Down
3 changes: 0 additions & 3 deletions include/ebpf_program_attach_type_guids.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

#include "ebpf_windows.h"

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
Expand Down
7 changes: 7 additions & 0 deletions include/ebpf_program_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
#include "ebpf_result.h"

#include <guiddef.h>
#if !defined(NO_CRT) && !defined(_NO_CRT_STDIO_INLINE)
#include <stdint.h>
#else
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned short wchar_t;
#endif

#define EBPF_MAX_PROGRAM_DESCRIPTOR_NAME_LENGTH 256
#define EBPF_MAX_HELPER_FUNCTION_NAME_LENGTH 256
Expand Down
35 changes: 21 additions & 14 deletions include/ebpf_store_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#pragma once

#include "ebpf_program_types.h"
#include "ebpf_shared_framework.h"
#include "ebpf_windows.h"
#ifdef USER_MODE
#include "ebpf_utilities.h"
#else
#include <ntifs.h>
#include <minwindef.h>
#include <wdm.h>
#endif

#define GUID_STRING_LENGTH 38 // not including the null terminator.
Expand All @@ -25,18 +24,6 @@ extern "C"
extern ebpf_store_key_t ebpf_store_root_key;
extern const wchar_t* ebpf_store_root_sub_key;

/**
* @brief Update the provider prototype information in the eBPF store.
*
* @param[in] helper_info_key Pointer to the store key to be initialized.
* @param[in] helper_info Pointer to the helper function prototype.
*
* @return Status of the operation.
*/
ebpf_result_t
ebpf_store_update_helper_prototype(
ebpf_store_key_t helper_info_key, _In_ const ebpf_helper_function_prototype_t* helper_info);

/**
* @brief Update global helper information in the eBPF store.
*
Expand Down Expand Up @@ -73,6 +60,26 @@ extern "C"
ebpf_store_update_program_information(
_In_reads_(program_info_count) const ebpf_program_info_t* program_info, uint32_t program_info_count);

/**
* @brief Delete program information from the eBPF store.
*
* @param[in] program_info Pointer to the program information.
*
* @returns Status of the operation.
*/
ebpf_result_t
ebpf_store_delete_program_information(_In_ const ebpf_program_info_t* program_info);

/**
* @brief Delete section information from the eBPF store.
*
* @param[in] section_info Pointer to the section information.
*
* @returns Status of the operation.
*/
ebpf_result_t
ebpf_store_delete_section_information(_In_ const ebpf_program_section_info_t* section_info);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion include/ebpf_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifdef _MSC_VER
#include <guiddef.h>
#else
#if !defined(NO_CRT)
#if !defined(NO_CRT) && !defined(_NO_CRT_STDIO_INLINE)
#include <stdint.h>
#else
typedef unsigned char uint8_t;
Expand Down
2 changes: 1 addition & 1 deletion installer/ebpf-for-windows.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ SPDX-License-Identifier: MIT
<RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
<ProjectReference Include="..\tests\sample\ext\drv\sample_ext.vcxproj">
<ProjectReference Include="..\undocked\tests\sample\ext\drv\sample_ext.vcxproj">
<Name>sample_ebpf_ext</Name>
<Project>{c8d46543-5ae5-4e66-b9ce-8b84588b1c9e}</Project>
<Private>True</Private>
Expand Down
3 changes: 0 additions & 3 deletions libs/api/api.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@
<ProjectReference Include="..\..\rpc_interface\rpc_interface.vcxproj">
<Project>{1423245d-0249-40fc-a077-ff7780acfe3f}</Project>
</ProjectReference>
<ProjectReference Include="..\..\tools\export_program_info\export_program_info.vcxproj">
<Project>{fa9bb88d-8259-40c1-9422-bdedf9e9ce68}</Project>
</ProjectReference>
<ProjectReference Include="..\elf_spec\elf_spec.vcxproj">
<Project>{c3d2cd73-bf4c-47df-8808-2a9996124d5b}</Project>
</ProjectReference>
Expand Down
55 changes: 55 additions & 0 deletions libs/api_common/store_helper_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "..\libs\store_helper\user\ebpf_registry_helper.h"
#include "ebpf_program_attach_type_guids.h"
#include "ebpf_serialize.h"
#include "ebpf_shared_framework.h"
#include "ebpf_store_helper.h"
#include "ebpf_utilities.h"
#include "store_helper_internal.h"
Expand Down Expand Up @@ -755,3 +756,57 @@ ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path)

return result;
}

ebpf_result_t
ebpf_store_delete_global_helper_information(_In_ ebpf_helper_function_prototype_t* helper_info)
{
ebpf_result_t result = EBPF_SUCCESS;
ebpf_store_key_t root_key = NULL;
ebpf_store_key_t provider_key = NULL;
ebpf_store_key_t helper_info_key = NULL;
wchar_t* helper_name = ebpf_get_wstring_from_string(helper_info->name);
if (helper_name == nullptr) {
result = EBPF_NO_MEMORY;
goto Exit;
}

// Open root registry key.
result = ebpf_open_registry_key(ebpf_store_root_key, EBPF_ROOT_RELATIVE_PATH, REG_CREATE_FLAGS, &root_key);
if (result != EBPF_SUCCESS) {
if (result == EBPF_FILE_NOT_FOUND) {
result = EBPF_SUCCESS;
}
goto Exit;
}

// Open "providers" registry key.
result = ebpf_open_registry_key(root_key, EBPF_PROVIDERS_REGISTRY_PATH, REG_CREATE_FLAGS, &provider_key);
if (result != EBPF_SUCCESS) {
if (result == EBPF_FILE_NOT_FOUND) {
result = EBPF_SUCCESS;
}
goto Exit;
}

// Open (or create) global helpers key.
result =
ebpf_open_registry_key(provider_key, EBPF_GLOBAL_HELPERS_REGISTRY_PATH, REG_DELETE_FLAGS, &helper_info_key);
if (result != EBPF_SUCCESS) {
if (result == EBPF_FILE_NOT_FOUND) {
result = EBPF_SUCCESS;
}
goto Exit;
}

result = ebpf_delete_registry_tree(helper_info_key, helper_name);
if (result != EBPF_SUCCESS) {
goto Exit;
}

Exit:
ebpf_free(helper_name);
ebpf_close_registry_key(helper_info_key);
ebpf_close_registry_key(provider_key);

return result;
}
12 changes: 11 additions & 1 deletion libs/api_common/store_helper_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ ebpf_store_load_global_helper_information(
_Out_ uint32_t* global_helper_info_count);

_Must_inspect_result_ ebpf_result_t
ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path);
ebpf_store_clear(_In_ const ebpf_store_key_t root_key_path);

/**
* @brief Delete global helper information from the eBPF store.
*
* @param[in] helper_info Pointer to the helper information.
*
* @returns Status of the operation.
*/
ebpf_result_t
ebpf_store_delete_global_helper_information(_In_ ebpf_helper_function_prototype_t* helper_info);
3 changes: 0 additions & 3 deletions libs/api_common/windows_program_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include "crab_verifier_wrapper.hpp"
#include "ebpf_nethooks.h"
#include "ebpf_program_types.h"
#include "net_ebpf_ext_program_info.h"
#include "sample_ext_helpers.h"
#include "sample_ext_program_info.h"

#define PTYPE(name, descr, native_type, prefixes) \
{ \
Expand Down
Loading

0 comments on commit 3f5e0ba

Please sign in to comment.