Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert usersim to a DLL #2683

Merged
merged 9 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ SPDX-License-Identifier: MIT
<Component Id="EXPORT_PROGRAM_INFO.PDB" DiskId="1" Guid="{88356FE4-6247-4876-BA14-42EDA88CC5C7}">
<File Id="EXPORT_PROGRAM_INFO.PDB" Name="export_program_info.pdb" Source="$(var.export_program_info.TargetDir)export_program_info.pdb" />
</Component>
<!-- TODO(#2677): move usersim.dll down to the testing component. Until that issue is addressed,
export_program_info.exe requires it.
-->
<Component Id="USERSIM.DLL" DiskId="1" Guid="{739017F0-9E33-48FF-A33F-C1434AC757BE}">
<File Id="USERSIM.DLL" Name="usersim.dll" Source="$(var.SolutionDir)$(var.Platform)\$(var.Configuration)\usersim.dll" />
</Component>
<Component Id="USERSIM.PDB" DiskId="1" Guid="{BCE1BF99-6A3D-48A6-A382-4E87A2B20FB2}">
<File Id="USERSIM.PDB" Name="usersim.pdb" Source="$(var.SolutionDir)$(var.Platform)\$(var.Configuration)\usersim.pdb" />
</Component>
</ComponentGroup>

<!--Clear/Setup the eBPF store-->
Expand Down
3 changes: 3 additions & 0 deletions libs/execution_context/unit/execution_context_unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ TEST_CASE("program", "[execution_context]")
// Correct attach type, but wrong program type.
{
single_instance_hook_t hook(EBPF_PROGRAM_TYPE_BIND, EBPF_ATTACH_TYPE_XDP);
REQUIRE(hook.initialize() == EBPF_SUCCESS);
ebpf_link_t* local_link = nullptr;
REQUIRE(ebpf_link_create(EBPF_ATTACH_TYPE_XDP, nullptr, 0, &local_link) == EBPF_SUCCESS);
link.reset(local_link);
Expand All @@ -799,6 +800,7 @@ TEST_CASE("program", "[execution_context]")
// Wrong attach type, but correct program type.
{
single_instance_hook_t hook(EBPF_PROGRAM_TYPE_XDP, EBPF_ATTACH_TYPE_BIND);
REQUIRE(hook.initialize() == EBPF_SUCCESS);
ebpf_link_t* local_link = nullptr;
REQUIRE(ebpf_link_create(EBPF_ATTACH_TYPE_XDP, nullptr, 0, &local_link) == EBPF_SUCCESS);
link.reset(local_link);
Expand All @@ -808,6 +810,7 @@ TEST_CASE("program", "[execution_context]")
// Correct attach type and correct program type.
{
single_instance_hook_t hook(EBPF_PROGRAM_TYPE_XDP, EBPF_ATTACH_TYPE_XDP);
REQUIRE(hook.initialize() == EBPF_SUCCESS);
ebpf_link_t* local_link = nullptr;
REQUIRE(ebpf_link_create(EBPF_ATTACH_TYPE_XDP, nullptr, 0, &local_link) == EBPF_SUCCESS);
link.reset(local_link);
Expand Down
13 changes: 13 additions & 0 deletions libs/platform/ebpf_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,16 @@ ebpf_free_timer_work_item(_Frees_ptr_opt_ ebpf_timer_work_item_t* work_item)
KeFlushQueuedDpcs();
ebpf_free(work_item);
}

_Must_inspect_result_ ebpf_result_t
ebpf_platform_initiate()
{
ebpf_initialize_cpu_count();
return EBPF_SUCCESS;
}

void
ebpf_platform_terminate()
{
KeFlushQueuedDpcs();
}
13 changes: 0 additions & 13 deletions libs/platform/kernel/ebpf_platform_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ typedef struct _ebpf_ring_descriptor ebpf_ring_descriptor_t;
static KDEFERRED_ROUTINE _ebpf_deferred_routine;
static KDEFERRED_ROUTINE _ebpf_timer_routine;

_Must_inspect_result_ ebpf_result_t
ebpf_platform_initiate()
{
ebpf_initialize_cpu_count();
return EBPF_SUCCESS;
}

void
ebpf_platform_terminate()
{
KeFlushQueuedDpcs();
}

__drv_allocatesMem(Mem) _Must_inspect_result_
_Ret_writes_maybenull_(size) void* ebpf_allocate_cache_aligned_with_tag(size_t size, uint32_t tag)
{
Expand Down
5 changes: 0 additions & 5 deletions libs/platform/unit/platform_unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,6 @@ TEST_CASE("epoch_test_stale_items", "[platform]")
return;
}

KIRQL old_irql;
KeRaiseIrql(DISPATCH_LEVEL, &old_irql);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why did we remove this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's explained in the PR description.


size_t const test_iterations = 100;
for (size_t test_iteration = 0; test_iteration < test_iterations; test_iteration++) {

Expand Down Expand Up @@ -491,8 +488,6 @@ TEST_CASE("epoch_test_stale_items", "[platform]")
REQUIRE(ebpf_epoch_is_free_list_empty(0));
REQUIRE(ebpf_epoch_is_free_list_empty(1));
}

KeLowerIrql(old_irql);
}

static auto provider_function = []() { return EBPF_SUCCESS; };
Expand Down
23 changes: 0 additions & 23 deletions libs/platform/user/ebpf_platform_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,6 @@ bool _ebpf_platform_code_integrity_enabled = false;

extern "C" size_t ebpf_fuzzing_memory_limit = MAXSIZE_T;

static bool _usersim_platform_initiated = false;

_Must_inspect_result_ ebpf_result_t
ebpf_platform_initiate()
{
ebpf_initialize_cpu_count();
if (!NT_SUCCESS(usersim_platform_initiate())) {
return EBPF_NO_MEMORY;
}
_usersim_platform_initiated = true;
return EBPF_SUCCESS;
}

void
ebpf_platform_terminate()
{
if (_usersim_platform_initiated) {
KeFlushQueuedDpcs();
usersim_platform_terminate();
_usersim_platform_initiated = false;
}
}

_Must_inspect_result_ ebpf_result_t
ebpf_get_code_integrity_state(_Out_ ebpf_code_integrity_state_t* state)
{
Expand Down
6 changes: 5 additions & 1 deletion scripts/deploy-ebpf.ps1.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
$source_directory="."

# The following files should be installed on all platforms.
# TODO(#2677): export_program_info.exe temporarily requires usersim.dll,
# usersim.dll should get moved down to the test files list.
[System.Collections.ArrayList]$built_runtime_files=@(
"bpftool.exe",
"bpftool.pdb",
Expand All @@ -24,7 +26,9 @@ $source_directory="."
"NetEbpfExt.sys",
"NetEbpfExt.pdb",
"net-ebpf-ext.guid",
"ucrtbased.dll")
"ucrtbased.dll",
"usersim.dll",
"usersim.pdb")

[System.Collections.ArrayList]$built_runtime_jit_files=@(
"ebpfsvc.exe",
Expand Down
Loading