Skip to content

Commit

Permalink
Make runtime binaries not depend on usersim (#2783)
Browse files Browse the repository at this point in the history
* build ebpfcore under usersim

Signed-off-by: Dave Thaler <[email protected]>

* Work around analysis warnings

Signed-off-by: Dave Thaler <[email protected]>

* Fix installer project

Signed-off-by: Dave Thaler <[email protected]>

* Temporarily use ubpf branch with memory fix

Signed-off-by: Dave Thaler <[email protected]>

* WIP

Signed-off-by: Dave Thaler <[email protected]>

* WIP

Signed-off-by: Dave Thaler <[email protected]>

* Create project for files shared between ebpfapi and the ebpf runtime

Move existing files from libs/platform either to:
* libs/shared, if meant to be common between user-mode and ebpf runtime
* libs/runtime, if meant to be used by the ebpf runtime only (whether in
  user or kernel mode)

Signed-off-by: Dave Thaler <[email protected]>

* Move ebpf_tracelog.c to shared

Signed-off-by: Dave Thaler <[email protected]>

* Create shared_user and shared_kernel projects

Signed-off-by: Dave Thaler <[email protected]>

* WIP

Signed-off-by: Dave Thaler <[email protected]>

* WIP

Signed-off-by: Dave Thaler <[email protected]>

* Remove usersim from ebpfsvc

Signed-off-by: Dave Thaler <[email protected]>

* Update to cxplat branch of usersim

Signed-off-by: Dave Thaler <[email protected]>

* Use cxplat_utf8_string

Signed-off-by: Dave Thaler <[email protected]>

* Cleanup

Signed-off-by: Dave Thaler <[email protected]>

* Fix build errors

Signed-off-by: Dave Thaler <[email protected]>

* Fix ebpf_allocate_with_tag

Signed-off-by: Dave Thaler <[email protected]>

* Fixes

Signed-off-by: Dave Thaler <[email protected]>

* Bug fixes

Signed-off-by: Dave Thaler <[email protected]>

* Fix use of ebpf_reallocate to not pass a null pointer

Signed-off-by: Dave Thaler <[email protected]>

* Fix printf tests

Signed-off-by: Dave Thaler <[email protected]>

* Fix memory leaks

Signed-off-by: Dave Thaler <[email protected]>

* Temporary change to help debug double-free in test

Signed-off-by: Dave Thaler <[email protected]>

* Update to latest usersim

Signed-off-by: Dave Thaler <[email protected]>

* Fix analysis warnings

Signed-off-by: Dave Thaler <[email protected]>

* Update to latest usersim

Signed-off-by: Dave Thaler <[email protected]>

* Update usersim to latest

Signed-off-by: Dave Thaler <[email protected]>

* Change native module to use latest usersim

Signed-off-by: Dave Thaler <[email protected]>

* Update nuget package

Signed-off-by: Dave Thaler <[email protected]>

* Only call cxplat_cleanup if cxplat_initialize succeeds

Signed-off-by: Alan Jowett <[email protected]>

* Revert setup_build.vcxproj change

Signed-off-by: Dave Thaler <[email protected]>

* Update usersim to latest

Signed-off-by: Dave Thaler <[email protected]>

---------

Signed-off-by: Dave Thaler <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Co-authored-by: Alan Jowett <[email protected]>
  • Loading branch information
dthaler and Alan Jowett authored Sep 5, 2023
1 parent 5700eab commit c947ca6
Show file tree
Hide file tree
Showing 160 changed files with 1,586 additions and 1,127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
TEST_COMMAND: ${{inputs.test_command}}
PRE_COMMAND: ${{inputs.pre_test}}
POST_COMMAND: ${{inputs.post_test}}
USERSIM_MEMORY_LEAK_DETECTION: ${{inputs.leak_detection}}
CXPLAT_MEMORY_LEAK_DETECTION: ${{inputs.leak_detection}}
DUMP_PATH: c:/dumps/x64/${{matrix.configurations}}
TEST_TIMEOUT: 3600 # 1 hour timeout for tests.

Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
[submodule "external/usersim"]
path = external/usersim
url = https://github.com/microsoft/usersim.git
branch = doublefree
198 changes: 196 additions & 2 deletions ebpf-for-windows.sln

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ebpfapi/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @brief Defines the entry point for the DLL application.
*/
#include "api_internal.h"
#include "framework.h"

bool use_ebpf_store = true;

Expand Down
24 changes: 9 additions & 15 deletions ebpfapi/ebpfapi.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)external\usersim\inc;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -137,7 +137,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)external\usersim\inc;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -158,7 +158,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)external\usersim\inc;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -177,7 +177,7 @@
<PreprocessorDefinitions>NDEBUG;EBPFAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)external\usersim\inc;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -198,7 +198,7 @@
<PreprocessorDefinitions>NDEBUG;EBPFAPI_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)external\usersim\inc;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)include;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\user;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winuser;$(SolutionDir)libs\execution_context;$(SolutionDir)libs\api_common;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -216,15 +216,9 @@
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\libs\api\platform.h">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='NativeOnlyDebug|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='FuzzerDebug|x64'">true</DeploymentContent>
</ClInclude>
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\libs\platform\ebpf_tracelog.c" />
<ClCompile Include="..\libs\thunk\windows\platform.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="rpc_client.cpp">
Expand All @@ -242,8 +236,8 @@
<ProjectReference Include="..\external\ebpf-verifier\build\external\libbtf\libbtf\libbtf.vcxproj">
<Project>{bc45d39c-f956-3951-bd46-44eae20ec7c9}</Project>
</ProjectReference>
<ProjectReference Include="..\external\usersim\src\usersim.vcxproj">
<Project>{030a7ac6-14dc-45cf-af34-891057ab1402}</Project>
<ProjectReference Include="..\external\usersim\cxplat\src\cxplat_winuser\cxplat_winuser.vcxproj">
<Project>{f2ca70ab-af9a-47d1-9da9-94d5ab573ac2}</Project>
</ProjectReference>
<ProjectReference Include="..\libs\api\api.vcxproj">
<Project>{c8bf60c3-40a9-43ad-891a-8aa34f1c3a68}</Project>
Expand All @@ -257,8 +251,8 @@
<ProjectReference Include="..\libs\pe-parse\pe-parse.vcxproj">
<Project>{fe4fea79-bfbb-4822-abcb-0d3beea240a7}</Project>
</ProjectReference>
<ProjectReference Include="..\libs\platform\user\platform_user.vcxproj">
<Project>{c26cb6a9-158c-4a9e-a243-755ddd98e5fe}</Project>
<ProjectReference Include="..\libs\shared\user\shared_user.vcxproj">
<Project>{9388dd45-7941-45d7-b4ff-bc00f550af17}</Project>
</ProjectReference>
<ProjectReference Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='FuzzerDebug' Or '$(Configuration)'=='Release'" Include="..\libs\ubpf\user\ubpf_user.vcxproj">
<Project>{245f0ec7-1ebc-4d68-8b1f-f758ea9196ae}</Project>
Expand Down
6 changes: 0 additions & 6 deletions ebpfapi/ebpfapi.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\libs\api\platform.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -36,9 +33,6 @@
<ClCompile Include="..\libs\thunk\windows\platform.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\libs\platform\ebpf_tracelog.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Source.def">
Expand Down
2 changes: 1 addition & 1 deletion ebpfapi/rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT

#include "ebpf_api.h"
#include "ebpf_platform.h"
#include "ebpf_shared_framework.h"
#include "ebpf_tracelog.h"

#include "rpc_interface_c.c"
Expand Down
16 changes: 11 additions & 5 deletions ebpfcore/EbpfCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
</ResourceCompile>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\kernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\runtime;$(SolutionDir)libs\runtime\kernel;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\kernel;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winkernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
<ExceptionHandling>
</ExceptionHandling>
Expand All @@ -139,7 +139,7 @@
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
</ResourceCompile>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\kernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\runtime;$(SolutionDir)libs\runtime\kernel;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\kernel;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winkernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
<ExceptionHandling>
</ExceptionHandling>
Expand All @@ -162,7 +162,7 @@
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
</ResourceCompile>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\kernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\runtime;$(SolutionDir)libs\runtime\kernel;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\kernel;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winkernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
<ExceptionHandling>
</ExceptionHandling>
Expand All @@ -185,7 +185,7 @@
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
</ResourceCompile>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\kernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SolutionDir)include;$(SolutionDir)libs\runtime;$(SolutionDir)libs\runtime\kernel;$(SolutionDir)libs\shared;$(SolutionDir)libs\shared\kernel;$(SolutionDir)external\usersim\cxplat\inc;$(SolutionDir)external\usersim\cxplat\inc\winkernel;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)include\kernel;$(SolutionDir)resource</AdditionalIncludeDirectories>
<PreprocessorDefinitions>%(PreprocessorDefinitions);BINARY_COMPATIBLE=0;NT;UNICODE;_UNICODE;NDIS60;POOL_NX_OPTIN_AUTO</PreprocessorDefinitions>
<ExceptionHandling>
</ExceptionHandling>
Expand All @@ -212,12 +212,18 @@
<FilesToPackage Include="$(TargetPath)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\external\usersim\cxplat\src\cxplat_winkernel\cxplat_winkernel.vcxproj">
<Project>{1ebe3966-7dc4-49b4-b840-3d33d63415ec}</Project>
</ProjectReference>
<ProjectReference Include="..\libs\execution_context\kernel\execution_context_kernel.vcxproj">
<Project>{26e7ed0b-c128-4d7c-a90e-c246def40ad3}</Project>
</ProjectReference>
<ProjectReference Include="..\libs\platform\kernel\platform_kernel.vcxproj">
<ProjectReference Include="..\libs\runtime\kernel\platform_kernel.vcxproj">
<Project>{fc3f9998-4085-4767-8386-5453f07c3aad}</Project>
</ProjectReference>
<ProjectReference Include="..\libs\shared\kernel\shared_kernel.vcxproj">
<Project>{d1b81388-23ca-4e4b-916f-8d37989ae836}</Project>
</ProjectReference>
<ProjectReference Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'" Include="..\libs\ubpf\kernel\ubpf_kernel.vcxproj">
<Project>{675b59f8-089e-40b5-8388-56254447cfa3}</Project>
</ProjectReference>
Expand Down
2 changes: 1 addition & 1 deletion ebpfcore/ebpf_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ DriverEntry(_In_ DRIVER_OBJECT* driver_object, _In_ UNICODE_STRING* registry_pat
return status;
}

DEVICE_OBJECT*
_Ret_notnull_ DEVICE_OBJECT*
ebpf_driver_get_device_object()
{
return _ebpf_driver_device_object;
Expand Down
Loading

0 comments on commit c947ca6

Please sign in to comment.