diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 388e34c6a..87e4d6f83 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -64,6 +64,12 @@ a kernel debugger (KD) attached and running, or test signing is enabled. (It is releases of eBPF for Windows will eventually be production signed at some point in the future after security hardening is completed.) +Ensure that the matching versions of the Microsoft C Runtime are installed on the machine. Versions of the Microsoft C Runtime are available on the developer machine, located in %ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\version, where version is updated with each patch of Visual Studio. + +With version 14.29.30133, the full path is: +1) Release - ```%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\vc_redist.x64.exe``` +2) Debug - ```%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\debug_nonredist\x64\Microsoft.VC142.DebugCRT``` + For basic testing, the simplest way to install eBPF for Windows is into a Windows VM with test signing enabled. Follow the [VM Installation Instructions](vm-setup.md) to do so. diff --git a/docs/SelfHostedRunnerSetup.md b/docs/SelfHostedRunnerSetup.md index 2c361aba8..bb5e91942 100644 --- a/docs/SelfHostedRunnerSetup.md +++ b/docs/SelfHostedRunnerSetup.md @@ -14,13 +14,14 @@ Self-hosted runners are necessary as GitHub-hosted runners don't have the requis 3) ```Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.281.1/actions-runner-win-x64-2.281.1.zip -OutFile actions-runner-win-x64-2.281.1.zip``` 4) ```if((Get-FileHash -Path actions-runner-win-x64-2.281.1.zip -Algorithm SHA256).Hash.ToUpper() -ne 'b8dccfef39c5d696443d98edd1ee57881075066bb62adef0a344fcb11bd19f1b'.ToUpper()){ throw 'Computed checksum did not match' }``` 5) ```Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/actions-runner-win-x64-2.281.1.zip", "$PWD")``` -5) Obtain an [authentication token](https://github.com/microsoft/ebpf-for-windows/settings/actions/runners/new). This requires administrator permissions in the project. -6) Configure action runner. +6) Obtain an [authentication token](https://github.com/microsoft/ebpf-for-windows/settings/actions/runners/new). This requires administrator permissions in the project. +7) Configure action runner. 1) ```./config.cmd --url https://github.com/microsoft/ebpf-for-windows --token ``` 8) Change action runner service to run as "LocalSystem". 1) Open services.msc. 2) Locate "GitHub Action Runner ...". 3) Right Click -> Properties -> Log On. 4) Change "Log on as:" to "Local System Account". -8) Install the [Visual C++ Runtime Files](https://docs.microsoft.com/en-us/visualstudio/releases/2019/redistribution#visual-c-runtime-files) -9) Reboot the runner. +9) Install the [Visual C++ Runtime Files](https://docs.microsoft.com/en-us/visualstudio/releases/2019/redistribution#visual-c-runtime-files) +10) Install the debug version of the Visual C++ Runtime files from ```"%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\debug_nonredist\x64\Microsoft.VC142.DebugCRT"``` on a machine with Visual Studio installed. +11) Reboot the runner. diff --git a/docs/vm-setup.md b/docs/vm-setup.md index b7502a17a..c1ad90b42 100644 --- a/docs/vm-setup.md +++ b/docs/vm-setup.md @@ -16,7 +16,7 @@ 4. When the Create Virtual Machine dialog appears, select "Windows 10 dev environment". 5. Click the "Create Virtual Machine" button. 6. Once that is complete click the "Edit Settings" button. - 7. Select security, clear the "Enable Scure Boot" checkbox, and click OK. (This is a prerequisite for + 7. Select security, clear the "Enable Secure Boot" checkbox, and click OK. (This is a prerequisite for enabling test signed binaries.) 8. Click "Connect" and start the VM. @@ -26,6 +26,13 @@ 2. Do `bcdedit.exe -set TESTSIGNING ON`. 3. Restart the VM so that the change will be applied. +4. Install the matching version of the Microsoft Visual C++ Runtime: +Versions of the Microsoft C Runtime are available on the developer machine, located in %ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\version, where version is updated with each patch of Visual Studio. + +With version 14.29.30133, the full path is: +1) Release - ```%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\vc_redist.x64.exe``` +2) Debug - ```%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Redist\MSVC\14.29.30133\debug_nonredist\x64\Microsoft.VC142.DebugCRT``` + ## Installing eBPF into a VM Once the one-time setup has been completed, the following steps will diff --git a/ebpfapi/Source.def b/ebpfapi/Source.def index 3d41750e6..96c0d770d 100644 --- a/ebpfapi/Source.def +++ b/ebpfapi/Source.def @@ -68,7 +68,6 @@ EXPORTS ebpf_api_close_handle ebpf_api_get_pinned_map_info ebpf_api_map_info_free - ebpf_close_fd ebpf_create_map ebpf_create_map_name ebpf_free_string diff --git a/ebpfapi/ebpfapi.vcxproj b/ebpfapi/ebpfapi.vcxproj index 74f7e3771..ae4bf50f7 100644 --- a/ebpfapi/ebpfapi.vcxproj +++ b/ebpfapi/ebpfapi.vcxproj @@ -134,8 +134,8 @@ + - diff --git a/ebpfapi/ebpfapi.vcxproj.filters b/ebpfapi/ebpfapi.vcxproj.filters index 08da6592e..516000fd5 100644 --- a/ebpfapi/ebpfapi.vcxproj.filters +++ b/ebpfapi/ebpfapi.vcxproj.filters @@ -33,10 +33,10 @@ Source Files - + Source Files - + Source Files diff --git a/ebpfapi/platform.cpp b/ebpfapi/platform.cpp deleted file mode 100644 index 4bc1efd88..000000000 --- a/ebpfapi/platform.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Corporation -// SPDX-License-Identifier: MIT - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include "pch.h" -#include -#include "ebpf_api.h" - -namespace Platform { -bool -DeviceIoControl( - _In_ ebpf_handle_t device_handle, - uint32_t io_control_code, - _In_reads_bytes_opt_(input_buffer_size) void* input_buffer, - uint32_t input_buffer_size, - _Out_writes_bytes_to_opt_(output_buffer_size, *count_of_bytes_returned) void* output_buffer, - uint32_t output_buffer_size, - _Out_opt_ uint32_t* count_of_bytes_returned, - _Inout_opt_ OVERLAPPED* overlapped) -{ - return ::DeviceIoControl( - device_handle, - io_control_code, - input_buffer, - input_buffer_size, - output_buffer, - output_buffer_size, - (DWORD*)count_of_bytes_returned, - overlapped); -} - -ebpf_handle_t -CreateFileW( - _In_z_ PCWSTR file_name, - uint32_t desired_access, - uint32_t share_mode, - _In_opt_ SECURITY_ATTRIBUTES* security_attributes, - uint32_t creation_disposition, - uint32_t flags_and_attributes, - _In_opt_ ebpf_handle_t template_file) -{ - return ::CreateFileW( - file_name, - desired_access, - share_mode, - security_attributes, - creation_disposition, - flags_and_attributes, - template_file); -} - -bool -CloseHandle(_In_ _Post_ptr_invalid_ ebpf_handle_t handle) -{ - return ::CloseHandle(handle); -} -} // namespace Platform \ No newline at end of file diff --git a/ebpfsvc/eBPFSvc.vcxproj b/ebpfsvc/eBPFSvc.vcxproj index 8f182b2ce..f9a853fc0 100644 --- a/ebpfsvc/eBPFSvc.vcxproj +++ b/ebpfsvc/eBPFSvc.vcxproj @@ -195,8 +195,8 @@ + - diff --git a/ebpfsvc/eBPFSvc.vcxproj.filters b/ebpfsvc/eBPFSvc.vcxproj.filters index ab2af8143..631b4a14b 100644 --- a/ebpfsvc/eBPFSvc.vcxproj.filters +++ b/ebpfsvc/eBPFSvc.vcxproj.filters @@ -39,7 +39,7 @@ Source Files - + Source Files diff --git a/ebpfsvc/platform.cpp b/ebpfsvc/platform.cpp deleted file mode 100644 index b5c8b7059..000000000 --- a/ebpfsvc/platform.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Corporation -// SPDX-License-Identifier: MIT - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include "ebpf_api.h" -#include "svc_common.h" - -namespace Platform { -bool -DeviceIoControl( - _In_ ebpf_handle_t device_handle, - uint32_t io_control_code, - _In_reads_bytes_opt_(input_buffer_size) void* input_buffer, - uint32_t input_buffer_size, - _Out_writes_bytes_to_opt_(output_buffer_size, *count_of_bytes_returned) void* output_buffer, - uint32_t output_buffer_size, - _Out_opt_ uint32_t* count_of_bytes_returned, - _Inout_opt_ OVERLAPPED* overlapped) -{ - return ::DeviceIoControl( - device_handle, - io_control_code, - input_buffer, - input_buffer_size, - output_buffer, - output_buffer_size, - (DWORD*)count_of_bytes_returned, - overlapped); -} - -ebpf_handle_t -CreateFileW( - _In_z_ PCWSTR file_name, - uint32_t desired_access, - uint32_t share_mode, - _In_opt_ SECURITY_ATTRIBUTES* security_attributes, - uint32_t creation_disposition, - uint32_t flags_and_attributes, - _In_opt_ ebpf_handle_t template_file) -{ - return ::CreateFileW( - file_name, - desired_access, - share_mode, - security_attributes, - creation_disposition, - flags_and_attributes, - template_file); -} - -bool -CloseHandle(_In_ _Post_ptr_invalid_ ebpf_handle_t handle) -{ - return ::CloseHandle(handle); -} -} // namespace Platform diff --git a/ebpfsvc/rpc_api.cpp b/ebpfsvc/rpc_api.cpp index 210f86924..b853567ab 100644 --- a/ebpfsvc/rpc_api.cpp +++ b/ebpfsvc/rpc_api.cpp @@ -22,11 +22,11 @@ ebpf_server_verify_and_load_program( } // Set the handle of program being verified in thread-local storage. - set_program_under_verification(info->program_handle); + set_program_under_verification(reinterpret_cast(info->program_handle)); result = ebpf_verify_and_load_program( &info->program_type, - info->program_handle, + reinterpret_cast(info->program_handle), info->execution_context, info->execution_type, info->map_count, diff --git a/include/ebpf_api.h b/include/ebpf_api.h index 5a7e20a51..26b1d88da 100644 --- a/include/ebpf_api.h +++ b/include/ebpf_api.h @@ -64,8 +64,7 @@ extern "C" typedef int32_t fd_t; const fd_t ebpf_fd_invalid = -1; - typedef void* ebpf_handle_t; - const ebpf_handle_t ebpf_handle_invalid = (ebpf_handle_t)-1; + typedef intptr_t ebpf_handle_t; typedef struct _tlv_type_length_value tlv_type_length_value_t; struct bpf_object; diff --git a/include/ebpf_core_structs.h b/include/ebpf_core_structs.h index 17ce1d80a..0595653ca 100644 --- a/include/ebpf_core_structs.h +++ b/include/ebpf_core_structs.h @@ -20,3 +20,6 @@ typedef struct _ebpf_map_info ebpf_map_definition_in_memory_t definition; _Field_z_ char* pin_path; } ebpf_map_info_t; + +typedef intptr_t ebpf_handle_t; +extern __declspec(selectany) const ebpf_handle_t ebpf_handle_invalid = (ebpf_handle_t)-1; diff --git a/libs/api/api.vcxproj b/libs/api/api.vcxproj index ea707a2d3..4dec8062c 100644 --- a/libs/api/api.vcxproj +++ b/libs/api/api.vcxproj @@ -134,7 +134,7 @@ true NotUsing pch.h - $(SolutionDir)external\libbpf\src;$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)libs\service;$(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)external\ebpf-verifier\external\elfio;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)external\libbpf\src;$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)libs\service;$(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)external\ebpf-verifier\external\elfio;$(OutDir);%(AdditionalIncludeDirectories);$(SolutionDir)libs\thunk stdcpplatest MultiThreadedDebugDll true @@ -156,7 +156,7 @@ true NotUsing pch.h - $(SolutionDir)external\libbpf\src;$(SolutionDir)rpc_interface;$(SolutionDir)libs\service;$(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)external\ebpf-verifier\external\elfio;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)external\libbpf\src;$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)rpc_interface;$(SolutionDir)libs\service;$(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)external\ebpf-verifier\external\elfio;$(OutDir);%(AdditionalIncludeDirectories);$(SolutionDir)libs\thunk stdcpplatest true @@ -181,9 +181,9 @@ + - diff --git a/libs/api/api.vcxproj.filters b/libs/api/api.vcxproj.filters index 5456076f4..95a10ba97 100644 --- a/libs/api/api.vcxproj.filters +++ b/libs/api/api.vcxproj.filters @@ -42,9 +42,6 @@ Header Files - - Header Files - Header Files @@ -60,5 +57,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/libs/api/ebpf_api.cpp b/libs/api/ebpf_api.cpp index 7e6715207..820ec09dc 100644 --- a/libs/api/ebpf_api.cpp +++ b/libs/api/ebpf_api.cpp @@ -19,14 +19,14 @@ extern "C" } #include "Verifier.h" +using namespace Platform; + #ifndef GUID_NULL const GUID GUID_NULL = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}}; #endif #define MAX_CODE_SIZE (32 * 1024) // 32 KB -static uint64_t _ebpf_file_descriptor_counter = 0; -static std::map _fd_to_handle_map; static std::map _ebpf_programs; static std::map _ebpf_maps; static std::vector _ebpf_objects; @@ -35,26 +35,15 @@ static void _clean_up_ebpf_objects(); static fd_t -_get_next_file_descriptor(ebpf_handle_t handle) noexcept +_create_file_descriptor_for_handle(ebpf_handle_t handle) noexcept { - try { - fd_t fd = static_cast(InterlockedIncrement(&_ebpf_file_descriptor_counter)); - _fd_to_handle_map.insert(std::pair(fd, handle)); - return fd; - } catch (...) { - return ebpf_fd_invalid; - } + return Platform::_open_osfhandle(handle, 0); } inline static ebpf_handle_t -_get_handle_from_fd(fd_t fd) +_get_handle_from_file_descriptor(fd_t fd) { - std::map::iterator it = _fd_to_handle_map.find(fd); - if (it != _fd_to_handle_map.end()) { - return it->second; - } - - return ebpf_handle_invalid; + return Platform::_get_osfhandle(fd); } inline static ebpf_map_t* @@ -120,7 +109,7 @@ ebpf_api_create_map( uint32_t value_size, uint32_t max_entries, uint32_t map_flags, - _Out_ handle_t* handle) + _Out_ ebpf_handle_t* handle) { UNREFERENCED_PARAMETER(map_flags); @@ -128,7 +117,7 @@ ebpf_api_create_map( EBPF_OFFSET_OF(ebpf_operation_create_map_request_t, data), ebpf_operation_id_t::EBPF_OPERATION_CREATE_MAP, {sizeof(ebpf_map_definition_in_memory_t), type, key_size, value_size, max_entries}, - (uint64_t)ebpf_handle_invalid}; + ebpf_handle_invalid}; _ebpf_operation_create_map_reply reply{}; @@ -138,7 +127,7 @@ ebpf_api_create_map( return_value = ERROR_INVALID_PARAMETER; goto Exit; } - *handle = INVALID_HANDLE_VALUE; + *handle = ebpf_handle_invalid; return_value = invoke_ioctl(request, reply); @@ -147,7 +136,7 @@ ebpf_api_create_map( ebpf_assert(reply.header.id == ebpf_operation_id_t::EBPF_OPERATION_CREATE_MAP); - *handle = reinterpret_cast(reply.handle); + *handle = reply.handle; Exit: return windows_error_to_ebpf_result(return_value); @@ -191,7 +180,7 @@ _create_map( goto Exit; } ebpf_assert(reply.header.id == ebpf_operation_id_t::EBPF_OPERATION_CREATE_MAP); - *map_handle = reinterpret_cast(reply.handle); + *map_handle = reply.handle; Exit: return result; @@ -228,7 +217,7 @@ ebpf_create_map_name( if (result != EBPF_SUCCESS) { goto Exit; } - *map_fd = _get_next_file_descriptor(map_handle); + *map_fd = _create_file_descriptor_for_handle(map_handle); if (*map_fd == ebpf_fd_invalid) { result = EBPF_NO_MEMORY; goto Exit; @@ -281,7 +270,7 @@ _map_lookup_element( request->header.length = static_cast(request_buffer.size()); request->header.id = ebpf_operation_id_t::EBPF_OPERATION_MAP_FIND_ELEMENT; - request->handle = reinterpret_cast(handle); + request->handle = handle; std::copy(key, key + key_size, request->key); result = windows_error_to_ebpf_result(invoke_ioctl(request_buffer, reply_buffer)); @@ -353,7 +342,7 @@ ebpf_map_lookup_element(fd_t map_fd, _In_ const void* key, _Out_ void* value) } *((uint8_t*)value) = 0; - map_handle = _get_handle_from_fd(map_fd); + map_handle = _get_handle_from_file_descriptor(map_fd); if (map_handle == ebpf_handle_invalid) { result = EBPF_INVALID_FD; goto Exit; @@ -454,7 +443,7 @@ ebpf_map_update_element(fd_t map_fd, _In_ const void* key, _In_ const void* valu return EBPF_INVALID_ARGUMENT; } - map_handle = _get_handle_from_fd(map_fd); + map_handle = _get_handle_from_file_descriptor(map_fd); if (map_handle == ebpf_handle_invalid) { return EBPF_INVALID_FD; } @@ -471,7 +460,7 @@ ebpf_map_update_element(fd_t map_fd, _In_ const void* key, _In_ const void* valu if ((type == BPF_MAP_TYPE_PROG_ARRAY) || (type == BPF_MAP_TYPE_HASH_OF_MAPS) || (type == BPF_MAP_TYPE_ARRAY_OF_MAPS)) { fd_t fd = *(fd_t*)value; - ebpf_handle_t handle = _get_handle_from_fd(fd); + ebpf_handle_t handle = _get_handle_from_file_descriptor(fd); if (handle == ebpf_handle_invalid) { return EBPF_INVALID_FD; } @@ -498,7 +487,7 @@ ebpf_map_delete_element(fd_t map_fd, _In_ const void* key) goto Exit; } - map_handle = _get_handle_from_fd(map_fd); + map_handle = _get_handle_from_file_descriptor(map_fd); if (map_handle == ebpf_handle_invalid) { result = EBPF_INVALID_FD; goto Exit; @@ -555,7 +544,7 @@ ebpf_map_get_next_key(fd_t map_fd, _In_opt_ const void* previous_key, _Out_ void goto Exit; } - map_handle = _get_handle_from_fd(map_fd); + map_handle = _get_handle_from_file_descriptor(map_fd); if (map_handle == ebpf_handle_invalid) { result = EBPF_INVALID_FD; goto Exit; @@ -577,7 +566,7 @@ ebpf_map_get_next_key(fd_t map_fd, _In_opt_ const void* previous_key, _Out_ void request->header.length = static_cast(request_buffer.size()); request->header.id = ebpf_operation_id_t::EBPF_OPERATION_MAP_GET_NEXT_KEY; - request->handle = reinterpret_cast(map_handle); + request->handle = map_handle; if (previous_key) { uint8_t* end = (uint8_t*)previous_key + key_size; std::copy((uint8_t*)previous_key, end, request->previous_key); @@ -643,7 +632,7 @@ _create_program( if (error != ERROR_SUCCESS) { goto Exit; } - *program_handle = reinterpret_cast(reply.program_handle); + *program_handle = reply.program_handle; Exit: return windows_error_to_ebpf_result(error); @@ -708,7 +697,7 @@ ebpf_api_load_program( ebpf_handle_t* map_handles, const char** error_message) { - ebpf_handle_t program_handle = INVALID_HANDLE_VALUE; + ebpf_handle_t program_handle = ebpf_handle_invalid; ebpf_protocol_buffer_t request_buffer; uint32_t error_message_size = 0; std::vector handles; @@ -744,7 +733,7 @@ ebpf_api_load_program( if (result != EBPF_SUCCESS) { goto Done; } - map->map_fd = _get_next_file_descriptor(map->map_handle); + map->map_fd = _create_file_descriptor_for_handle(map->map_handle); if (map->map_fd == ebpf_fd_invalid) { result = EBPF_FAILED; goto Done; @@ -768,7 +757,7 @@ ebpf_api_load_program( load_info.section_name = const_cast(section_name); load_info.program_name = nullptr; load_info.program_type = program->program_type; - load_info.program_handle = program_handle; + load_info.program_handle = reinterpret_cast(program_handle); load_info.execution_type = execution_type; load_info.byte_code = program->byte_code; load_info.byte_code_size = program->byte_code_size; @@ -793,12 +782,12 @@ ebpf_api_load_program( // Program is verified and loaded. *count_of_map_handles = 0; for (auto& map : maps) { - map_handles[*count_of_map_handles] = reinterpret_cast(map->map_handle); + map_handles[*count_of_map_handles] = map->map_handle; (*count_of_map_handles)++; } *handle = program_handle; - program_handle = INVALID_HANDLE_VALUE; + program_handle = ebpf_handle_invalid; } catch (const std::bad_alloc&) { result = EBPF_NO_MEMORY; goto Done; @@ -830,7 +819,7 @@ Done: clean_up_ebpf_map(map); } - if (program_handle != INVALID_HANDLE_VALUE) { + if (program_handle != ebpf_handle_invalid) { ebpf_api_close_handle(program_handle); } @@ -851,7 +840,7 @@ ebpf_api_pin_object(ebpf_handle_t handle, const uint8_t* name, uint32_t name_len request->header.id = EBPF_OPERATION_UPDATE_PINNING; request->header.length = static_cast(request_buffer.size()); - request->handle = reinterpret_cast(handle); + request->handle = handle; std::copy(name, name + name_length, request->name); return invoke_ioctl(request_buffer); } @@ -865,11 +854,7 @@ ebpf_object_pin(fd_t fd, _In_z_ const char* path) return EBPF_INVALID_ARGUMENT; } - // This is a workaround till we start using _open_osfhandle() to generate - // fds for the handles (issue tracked by TODO: Issue# 287). Once this is - // fixed, _get_osfhandle() can be directly used to fetch the corresponding - // handle. - handle = _get_handle_from_fd(fd); + handle = _get_handle_from_file_descriptor(fd); if (handle == ebpf_handle_invalid) { return EBPF_INVALID_FD; } @@ -880,7 +865,7 @@ ebpf_object_pin(fd_t fd, _In_z_ const char* path) request->header.id = EBPF_OPERATION_UPDATE_PINNING; request->header.length = static_cast(request_buffer.size()); - request->handle = reinterpret_cast(handle); + request->handle = handle; std::copy(path, path + path_length, request->name); result = windows_error_to_ebpf_result(invoke_ioctl(request_buffer)); @@ -1004,8 +989,8 @@ ebpf_object_get(_In_z_ const char* path) return ebpf_fd_invalid; } - ebpf_handle_t handle = reinterpret_cast(reply.handle); - fd_t fd = _get_next_file_descriptor(handle); + ebpf_handle_t handle = reply.handle; + fd_t fd = _create_file_descriptor_for_handle(handle); if (fd == ebpf_fd_invalid) { Platform::CloseHandle(handle); } @@ -1021,17 +1006,17 @@ ebpf_get_next_map(fd_t previous_fd, _Out_ fd_t* next_fd) fd_t local_fd = previous_fd; *next_fd = ebpf_fd_invalid; - ebpf_handle_t previous_handle = _get_handle_from_fd(local_fd); + ebpf_handle_t previous_handle = _get_handle_from_file_descriptor(local_fd); ebpf_operation_get_next_map_request_t request{ - sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_MAP, reinterpret_cast(previous_handle)}; + sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_MAP, previous_handle}; ebpf_operation_get_next_map_reply_t reply; uint32_t retval = invoke_ioctl(request, reply); if (retval == ERROR_SUCCESS) { - ebpf_handle_t next_handle = reinterpret_cast(reply.next_handle); + ebpf_handle_t next_handle = reply.next_handle; if (next_handle != ebpf_handle_invalid) { - fd_t fd = _get_next_file_descriptor(next_handle); + fd_t fd = _create_file_descriptor_for_handle(next_handle); if (fd == ebpf_fd_invalid) { // Some error getting fd for the handle. Platform::CloseHandle(next_handle); @@ -1055,19 +1040,17 @@ ebpf_get_next_program(fd_t previous_fd, _Out_ fd_t* next_fd) fd_t local_fd = previous_fd; *next_fd = ebpf_fd_invalid; - ebpf_handle_t previous_handle = _get_handle_from_fd(local_fd); + ebpf_handle_t previous_handle = _get_handle_from_file_descriptor(local_fd); ebpf_operation_get_next_program_request_t request{ - sizeof(request), - ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_PROGRAM, - reinterpret_cast(previous_handle)}; + sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_PROGRAM, previous_handle}; ebpf_operation_get_next_program_reply_t reply; uint32_t retval = invoke_ioctl(request, reply); if (retval == ERROR_SUCCESS) { - ebpf_handle_t next_handle = reinterpret_cast(reply.next_handle); + ebpf_handle_t next_handle = reply.next_handle; if (next_handle != ebpf_handle_invalid) { - fd_t fd = _get_next_file_descriptor(next_handle); + fd_t fd = _create_file_descriptor_for_handle(next_handle); if (fd == ebpf_fd_invalid) { // Some error getting fd for the handle. Platform::CloseHandle(next_handle); @@ -1092,7 +1075,7 @@ ebpf_map_query_definition( _Out_ uint32_t* max_entries, _Out_ ebpf_id_t* inner_map_id) { - ebpf_handle_t map_handle = _get_handle_from_fd(fd); + ebpf_handle_t map_handle = _get_handle_from_file_descriptor(fd); if (map_handle == ebpf_handle_invalid) { return EBPF_INVALID_FD; } @@ -1107,7 +1090,7 @@ ebpf_program_query_info( _Outptr_result_z_ const char** section_name) { ebpf_result_t result; - ebpf_handle_t handle = _get_handle_from_fd(fd); + ebpf_handle_t handle = _get_handle_from_file_descriptor(fd); if (handle == ebpf_handle_invalid) { return EBPF_INVALID_FD; } @@ -1118,7 +1101,7 @@ ebpf_program_query_info( ebpf_protocol_buffer_t reply_buffer(1024); ebpf_operation_query_program_info_request_t request{ - sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_QUERY_PROGRAM_INFO, reinterpret_cast(handle)}; + sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_QUERY_PROGRAM_INFO, handle}; auto reply = reinterpret_cast(reply_buffer.data()); @@ -1159,7 +1142,7 @@ ebpf_api_link_program(ebpf_handle_t program_handle, ebpf_attach_type_t attach_ty ebpf_operation_link_program_request_t request = { EBPF_OFFSET_OF(ebpf_operation_link_program_request_t, data), EBPF_OPERATION_LINK_PROGRAM, - reinterpret_cast(program_handle), + program_handle, attach_type}; ebpf_operation_link_program_reply_t reply; @@ -1172,7 +1155,7 @@ ebpf_api_link_program(ebpf_handle_t program_handle, ebpf_attach_type_t attach_ty return ERROR_INVALID_PARAMETER; } - *link_handle = reinterpret_cast(reply.link_handle); + *link_handle = reply.link_handle; return retval; } @@ -1196,7 +1179,7 @@ _link_ebpf_program( request = reinterpret_cast(request_buffer.data()); request->header.id = EBPF_OPERATION_LINK_PROGRAM; request->header.length = static_cast(request_buffer.size()); - request->program_handle = reinterpret_cast(program_handle); + request->program_handle = program_handle; request->attach_type = *attach_type; if (attach_parameter_size > 0) { @@ -1213,7 +1196,7 @@ _link_ebpf_program( goto Exit; } - *link_handle = reinterpret_cast(reply.link_handle); + *link_handle = reply.link_handle; } catch (const std::bad_alloc&) { result = EBPF_NO_MEMORY; goto Exit; @@ -1243,8 +1226,7 @@ _clean_up_ebpf_link(_In_opt_ _Post_invalid_ ebpf_link_t* link) static ebpf_result_t _detach_link_by_handle(ebpf_handle_t link_handle) { - ebpf_operation_unlink_program_request_t request = { - sizeof(request), EBPF_OPERATION_UNLINK_PROGRAM, reinterpret_cast(link_handle)}; + ebpf_operation_unlink_program_request_t request = {sizeof(request), EBPF_OPERATION_UNLINK_PROGRAM, link_handle}; return windows_error_to_ebpf_result(invoke_ioctl(request)); } @@ -1252,7 +1234,7 @@ _detach_link_by_handle(ebpf_handle_t link_handle) ebpf_result_t ebpf_detach_link_by_fd(fd_t fd) { - ebpf_handle_t link_handle = _get_handle_from_fd(fd); + ebpf_handle_t link_handle = _get_handle_from_file_descriptor(fd); if (link_handle == ebpf_handle_invalid) { return EBPF_INVALID_FD; } @@ -1301,7 +1283,7 @@ ebpf_program_attach( if (result != EBPF_SUCCESS) { goto Exit; } - new_link->fd = _get_next_file_descriptor(new_link->handle); + new_link->fd = _create_file_descriptor_for_handle(new_link->handle); if (new_link->fd == ebpf_fd_invalid) { result = EBPF_NO_MEMORY; goto Exit; @@ -1326,7 +1308,7 @@ ebpf_program_attach_by_fd( _In_ size_t attach_params_size, _Outptr_ struct bpf_link** link) { - ebpf_program_t* program = _get_ebpf_program_from_handle(_get_handle_from_fd(program_fd)); + ebpf_program_t* program = _get_ebpf_program_from_handle(_get_handle_from_file_descriptor(program_fd)); if (program == nullptr || link == nullptr) { return EBPF_INVALID_ARGUMENT; } @@ -1338,8 +1320,7 @@ ebpf_program_attach_by_fd( uint32_t ebpf_api_unlink_program(ebpf_handle_t link_handle) { - ebpf_operation_unlink_program_request_t request = { - sizeof(request), EBPF_OPERATION_UNLINK_PROGRAM, reinterpret_cast(link_handle)}; + ebpf_operation_unlink_program_request_t request = {sizeof(request), EBPF_OPERATION_UNLINK_PROGRAM, link_handle}; return invoke_ioctl(request); } @@ -1367,32 +1348,17 @@ ebpf_link_close(_In_ struct bpf_link* link) ebpf_result_t ebpf_api_close_handle(ebpf_handle_t handle) { - ebpf_operation_close_handle_request_t request = { - sizeof(request), EBPF_OPERATION_CLOSE_HANDLE, reinterpret_cast(handle)}; + ebpf_operation_close_handle_request_t request = {sizeof(request), EBPF_OPERATION_CLOSE_HANDLE, handle}; return windows_error_to_ebpf_result(invoke_ioctl(request)); } -ebpf_result_t -ebpf_close_fd(fd_t fd) -{ - ebpf_handle_t handle = _get_handle_from_fd(fd); - if (handle == ebpf_handle_invalid) { - return EBPF_INVALID_FD; - } - _fd_to_handle_map.erase(fd); - ebpf_api_close_handle(handle); - - return EBPF_SUCCESS; -} - ebpf_result_t ebpf_api_get_pinned_map_info( _Out_ uint16_t* map_count, _Outptr_result_buffer_maybenull_(*map_count) ebpf_map_info_t** map_info) { ebpf_result_t result = EBPF_SUCCESS; - ebpf_operation_get_map_info_request_t request = { - sizeof(request), EBPF_OPERATION_GET_MAP_INFO, reinterpret_cast(INVALID_HANDLE_VALUE)}; + ebpf_operation_get_map_info_request_t request = {sizeof(request), EBPF_OPERATION_GET_MAP_INFO, ebpf_handle_invalid}; ebpf_protocol_buffer_t reply_buffer; ebpf_operation_get_map_info_reply_t* reply = nullptr; size_t min_expected_buffer_length = 0; @@ -1495,12 +1461,11 @@ clean_up_ebpf_program(_In_ _Post_invalid_ ebpf_program_t* program) if (program == nullptr) { return; } - if (program->fd != 0) { - _fd_to_handle_map.erase(program->fd); + if (program->fd != ebpf_fd_invalid) { + Platform::_close(program->fd); } if (program->handle != ebpf_handle_invalid) { _ebpf_programs.erase(program->handle); - ebpf_api_close_handle(program->handle); } free(program->byte_code); free(program->program_name); @@ -1525,11 +1490,10 @@ clean_up_ebpf_map(_In_ _Post_invalid_ ebpf_map_t* map) return; } if (map->map_fd != 0) { - _fd_to_handle_map.erase(map->map_fd); + Platform::_close(map->map_fd); } if (map->map_handle != ebpf_handle_invalid) { _ebpf_maps.erase(map->map_handle); - ebpf_api_close_handle(map->map_handle); } free(map->name); @@ -1658,6 +1622,9 @@ _get_next_map_to_create(std::vector& maps) if (map->inner_map == nullptr) { // This map requires an inner map template, look up which one. for (auto& inner_map : maps) { + if (!inner_map) { + continue; + } if (inner_map->original_fd == map->inner_map_original_fd) { map->inner_map = inner_map; break; @@ -1745,7 +1712,7 @@ ebpf_program_load( if (result != EBPF_SUCCESS) { goto Done; } - map->map_fd = _get_next_file_descriptor(map->map_handle); + map->map_fd = _create_file_descriptor_for_handle(map->map_handle); } for (auto& program : new_object->programs) { @@ -1755,17 +1722,14 @@ ebpf_program_load( goto Done; } - // TODO: (Issue #287) _open_osfhandle() fails for the program handle. - // Workaround: for now increment a global counter and use that as - // file descriptor. - program->fd = _get_next_file_descriptor(program->handle); + program->fd = _create_file_descriptor_for_handle(program->handle); // populate load_info. load_info.file_name = const_cast(file_name); load_info.section_name = const_cast(program->section_name); load_info.program_name = const_cast(program->program_name); load_info.program_type = program->program_type; - load_info.program_handle = program->handle; + load_info.program_handle = reinterpret_cast(program->handle); load_info.execution_type = execution_type; load_info.byte_code = program->byte_code; load_info.byte_code_size = program->byte_code_size; @@ -1959,7 +1923,7 @@ _get_fd_by_id(ebpf_operation_id_t operation, ebpf_id_t id, _Out_ int* fd) noexce return result; } - *fd = _get_next_file_descriptor((ebpf_handle_t)reply.handle); + *fd = _create_file_descriptor_for_handle((ebpf_handle_t)reply.handle); return (*fd == ebpf_fd_invalid) ? EBPF_NO_MEMORY : EBPF_SUCCESS; } @@ -2023,7 +1987,7 @@ ebpf_object_get_info_by_fd( return EBPF_INVALID_ARGUMENT; } - ebpf_handle_t handle = _get_handle_from_fd(bpf_fd); + ebpf_handle_t handle = _get_handle_from_file_descriptor(bpf_fd); if (handle == ebpf_handle_invalid) { return EBPF_INVALID_FD; } @@ -2035,7 +1999,7 @@ ebpf_object_get_info_by_fd( request->header.length = static_cast(request_buffer.size()); request->header.id = ebpf_operation_id_t::EBPF_OPERATION_GET_OBJECT_INFO; - request->handle = reinterpret_cast(handle); + request->handle = handle; ebpf_result_t result = windows_error_to_ebpf_result(invoke_ioctl(request_buffer, reply_buffer)); if (result == EBPF_SUCCESS) { diff --git a/libs/api/windows_platform.cpp b/libs/api/windows_platform.cpp index 84b0b0a78..8cb00572b 100644 --- a/libs/api/windows_platform.cpp +++ b/libs/api/windows_platform.cpp @@ -44,7 +44,7 @@ parse_maps_section_windows( } cache_map_handle( - INVALID_HANDLE_VALUE, + ebpf_handle_invalid, original_fd, s.type, s.key_size, diff --git a/libs/api_common/api_common.cpp b/libs/api_common/api_common.cpp index 01e4cf5bf..09a4b3b10 100644 --- a/libs/api_common/api_common.cpp +++ b/libs/api_common/api_common.cpp @@ -67,7 +67,7 @@ query_map_definition( _Out_ ebpf_id_t* inner_map_id) noexcept { _ebpf_operation_query_map_definition_request request{ - sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_QUERY_MAP_DEFINITION, reinterpret_cast(handle)}; + sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_QUERY_MAP_DEFINITION, handle}; _ebpf_operation_query_map_definition_reply reply; diff --git a/libs/api_common/api_common.vcxproj b/libs/api_common/api_common.vcxproj index fda8f0e5a..4d9ec264f 100644 --- a/libs/api_common/api_common.vcxproj +++ b/libs/api_common/api_common.vcxproj @@ -133,7 +133,7 @@ true NotUsing pch.h - $(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)tests\sample\ext\inc;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)tests\sample\ext\inc;$(OutDir);$(SolutionDir)libs\thunk;%(AdditionalIncludeDirectories) stdcpplatest MultiThreadedDebugDll true @@ -155,7 +155,7 @@ true NotUsing pch.h - $(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)tests\sample\ext\inc;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(SolutionDir)tests\sample\ext\inc;$(OutDir);$(SolutionDir)libs\thunk;%(AdditionalIncludeDirectories) stdcpplatest true @@ -199,4 +199,4 @@ - + \ No newline at end of file diff --git a/libs/api_common/device_helper.cpp b/libs/api_common/device_helper.cpp index ee71c30cd..2e78d807d 100644 --- a/libs/api_common/device_helper.cpp +++ b/libs/api_common/device_helper.cpp @@ -17,7 +17,7 @@ #include "platform.h" #include "platform.hpp" -static ebpf_handle_t _device_handle = INVALID_HANDLE_VALUE; +static ebpf_handle_t _device_handle = ebpf_handle_invalid; static std::mutex _mutex; ebpf_result_t @@ -25,20 +25,14 @@ initialize_device_handle() { std::scoped_lock lock(_mutex); - if (_device_handle != INVALID_HANDLE_VALUE) { + if (_device_handle != ebpf_handle_invalid) { return EBPF_ALREADY_INITIALIZED; } _device_handle = Platform::CreateFile( - EBPF_DEVICE_WIN32_NAME, - GENERIC_READ | GENERIC_WRITE, - 0, - nullptr, - CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, - nullptr); + EBPF_DEVICE_WIN32_NAME, GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - if (_device_handle == INVALID_HANDLE_VALUE) { + if (_device_handle == ebpf_handle_invalid) { return windows_error_to_ebpf_result(GetLastError()); } @@ -50,16 +44,16 @@ clean_up_device_handle() { std::scoped_lock lock(_mutex); - if (_device_handle != INVALID_HANDLE_VALUE) { + if (_device_handle != ebpf_handle_invalid) { Platform::CloseHandle(_device_handle); - _device_handle = INVALID_HANDLE_VALUE; + _device_handle = ebpf_handle_invalid; } } ebpf_handle_t get_device_handle() { - if (_device_handle == INVALID_HANDLE_VALUE) { + if (_device_handle == ebpf_handle_invalid) { initialize_device_handle(); } diff --git a/libs/api_common/windows_helpers.cpp b/libs/api_common/windows_helpers.cpp index d75e147c6..c8addea6f 100644 --- a/libs/api_common/windows_helpers.cpp +++ b/libs/api_common/windows_helpers.cpp @@ -65,7 +65,7 @@ get_program_info_data(ebpf_program_type_t program_type, _Outptr_ ebpf_program_in sizeof(request), ebpf_operation_id_t::EBPF_OPERATION_GET_PROGRAM_INFO, program_type, - reinterpret_cast(_program_under_verification)}; + _program_under_verification}; *program_info = nullptr; diff --git a/libs/ebpfnetsh/ebpfnetsh.vcxproj b/libs/ebpfnetsh/ebpfnetsh.vcxproj index d5f22ca9e..b8fb6ffbe 100644 --- a/libs/ebpfnetsh/ebpfnetsh.vcxproj +++ b/libs/ebpfnetsh/ebpfnetsh.vcxproj @@ -132,7 +132,7 @@ true _DEBUG;_LIB;%(PreprocessorDefinitions) true - $(SolutionDir)include + $(SolutionDir)include;$(SolutionDir)libs\thunk stdcpplatest MultiThreadedDebugDll ProgramDatabase @@ -151,7 +151,7 @@ true NDEBUG;_LIB;%(PreprocessorDefinitions) true - $(SolutionDir)include + $(SolutionDir)include;$(SolutionDir)libs\thunk stdcpplatest diff --git a/libs/ebpfnetsh/maps.cpp b/libs/ebpfnetsh/maps.cpp index 2028fdb32..a769d721f 100644 --- a/libs/ebpfnetsh/maps.cpp +++ b/libs/ebpfnetsh/maps.cpp @@ -11,6 +11,7 @@ #include #include "ebpf_api.h" #include "ebpf_windows.h" +#include "platform.h" #include "maps.h" #include "tokens.h" @@ -49,7 +50,7 @@ handle_ebpf_show_maps( } if (map_fd != ebpf_fd_invalid) { - ebpf_close_fd(map_fd); + Platform::_close(map_fd); } map_fd = next_map_fd; @@ -76,7 +77,7 @@ handle_ebpf_show_maps( << map_definition.inner_map_idx << "\n"; } if (map_fd != ebpf_fd_invalid) { - ebpf_close_fd(map_fd); + Platform::_close(map_fd); } return result; } diff --git a/libs/ebpfnetsh/programs.cpp b/libs/ebpfnetsh/programs.cpp index 90a28c338..8652815fd 100644 --- a/libs/ebpfnetsh/programs.cpp +++ b/libs/ebpfnetsh/programs.cpp @@ -7,6 +7,7 @@ #include #include #include "ebpf_windows.h" +#include "platform.h" #include "programs.h" #include "tokens.h" @@ -24,11 +25,11 @@ class program_state_t final ebpf_handle_t map_handles[10]; program_state_t(std::string filename, std::string section) - : program_filename(filename), program_section(section), program_handle(INVALID_HANDLE_VALUE), - link_handle(INVALID_HANDLE_VALUE) + : program_filename(filename), program_section(section), program_handle(ebpf_handle_invalid), + link_handle(ebpf_handle_invalid) { for (int i = 0; i < _countof(map_handles); i++) { - map_handles[i] = INVALID_HANDLE_VALUE; + map_handles[i] = ebpf_handle_invalid; } } @@ -46,9 +47,9 @@ class program_state_t final void close_handle(ebpf_handle_t* handle) { - if (*handle != INVALID_HANDLE_VALUE) { + if (*handle != ebpf_handle_invalid) { ebpf_api_close_handle(*handle); - *handle = INVALID_HANDLE_VALUE; + *handle = ebpf_handle_invalid; } } }; @@ -232,7 +233,7 @@ _find_program_fd(const char* filename, const char* section) break; } if (program_fd != ebpf_fd_invalid) { - ebpf_close_fd(program_fd); + Platform::_close(program_fd); } program_fd = next_program_fd; @@ -260,7 +261,7 @@ _find_program_fd(const char* filename, const char* section) } if (program_fd != ebpf_fd_invalid) { - ebpf_close_fd(program_fd); + Platform::_close(program_fd); } return ebpf_fd_invalid; } @@ -405,7 +406,7 @@ handle_ebpf_set_program( return ERROR_SUPPRESS_OUTPUT; } - ebpf_close_fd(program_fd); + Platform::_close(program_fd); } return ERROR_CALL_NOT_IMPLEMENTED; @@ -510,7 +511,7 @@ handle_ebpf_show_programs( } if (program_fd != ebpf_fd_invalid) { - ebpf_close_fd(program_fd); + Platform::_close(program_fd); } program_fd = next_program_fd; @@ -538,7 +539,7 @@ handle_ebpf_show_programs( ebpf_free_string(program_section_name); } if (program_fd != ebpf_fd_invalid) { - ebpf_close_fd(program_fd); + Platform::_close(program_fd); } return status; } diff --git a/libs/execution_context/ebpf_core.c b/libs/execution_context/ebpf_core.c index 289e104d1..58c261651 100644 --- a/libs/execution_context/ebpf_core.c +++ b/libs/execution_context/ebpf_core.c @@ -11,8 +11,6 @@ #include "ebpf_serialize.h" #include "ebpf_state.h" -const ebpf_handle_t ebpf_handle_invalid = (ebpf_handle_t)-1; - GUID ebpf_general_helper_function_interface_id = {/* 8d2a1d3f-9ce6-473d-b48e-17aa5c5581fe */ 0x8d2a1d3f, 0x9ce6, diff --git a/libs/execution_context/ebpf_maps.c b/libs/execution_context/ebpf_maps.c index c11d868ba..a47930151 100644 --- a/libs/execution_context/ebpf_maps.c +++ b/libs/execution_context/ebpf_maps.c @@ -886,7 +886,7 @@ ebpf_map_create( goto Exit; } - if (inner_map_handle != (ebpf_handle_t)-1) { + if (inner_map_handle != ebpf_handle_invalid) { // Convert value handle to an object pointer. result = ebpf_reference_object_by_handle(inner_map_handle, EBPF_OBJECT_MAP, &inner_map_template_object); if (result != EBPF_SUCCESS) diff --git a/libs/execution_context/ebpf_maps.h b/libs/execution_context/ebpf_maps.h index 976b52794..2122aa9c6 100644 --- a/libs/execution_context/ebpf_maps.h +++ b/libs/execution_context/ebpf_maps.h @@ -3,6 +3,7 @@ #pragma once +#include "ebpf_core_structs.h" #include "bpf_helpers.h" #include "ebpf_platform.h" @@ -28,7 +29,7 @@ extern "C" ebpf_map_create( _In_ const ebpf_utf8_string_t* map_name, _In_ const ebpf_map_definition_in_memory_t* ebpf_map_definition, - uintptr_t inner_map_handle, + ebpf_handle_t inner_map_handle, _Outptr_ ebpf_map_t** map); /** diff --git a/libs/execution_context/ebpf_protocol.h b/libs/execution_context/ebpf_protocol.h index 7af4a3a94..56db256ef 100644 --- a/libs/execution_context/ebpf_protocol.h +++ b/libs/execution_context/ebpf_protocol.h @@ -62,27 +62,27 @@ typedef enum _ebpf_ec_function typedef struct _ebpf_operation_resolve_helper_request { struct _ebpf_operation_header header; - uint64_t program_handle; + ebpf_handle_t program_handle; uint32_t helper_id[1]; } ebpf_operation_resolve_helper_request_t; typedef struct _ebpf_operation_resolve_helper_reply { struct _ebpf_operation_header header; - uint64_t address[1]; + uintptr_t address[1]; } ebpf_operation_resolve_helper_reply_t; typedef struct _ebpf_operation_resolve_map_request { struct _ebpf_operation_header header; - uint64_t program_handle; - uint64_t map_handle[1]; + ebpf_handle_t program_handle; + ebpf_handle_t map_handle[1]; } ebpf_operation_resolve_map_request_t; typedef struct _ebpf_operation_resolve_map_reply { struct _ebpf_operation_header header; - uint64_t address[1]; + uintptr_t address[1]; } ebpf_operation_resolve_map_reply_t; typedef struct _ebpf_operation_create_program_request @@ -97,13 +97,13 @@ typedef struct _ebpf_operation_create_program_request typedef struct _ebpf_operation_create_program_reply { struct _ebpf_operation_header header; - uint64_t program_handle; + ebpf_handle_t program_handle; } ebpf_operation_create_program_reply_t; typedef struct _ebpf_operation_load_code_request { struct _ebpf_operation_header header; - uint64_t program_handle; + ebpf_handle_t program_handle; ebpf_code_type_t code_type; uint8_t code[1]; } ebpf_operation_load_code_request_t; @@ -112,20 +112,20 @@ typedef struct _ebpf_operation_create_map_request { struct _ebpf_operation_header header; ebpf_map_definition_in_memory_t ebpf_map_definition; - uint64_t inner_map_handle; + ebpf_handle_t inner_map_handle; uint8_t data[1]; } ebpf_operation_create_map_request_t; typedef struct _ebpf_operation_create_map_reply { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; } ebpf_operation_create_map_reply_t; typedef struct _ebpf_operation_map_find_element_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; uint8_t key[1]; } ebpf_operation_map_find_element_request_t; @@ -138,7 +138,7 @@ typedef struct _ebpf_operation_map_find_element_reply typedef struct _ebpf_operation_map_update_element_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; ebpf_map_option_t option; uint8_t data[1]; // data is key+value } epf_operation_map_update_element_request_t; @@ -155,38 +155,38 @@ typedef struct _ebpf_operation_map_update_element_with_handle_request typedef struct _ebpf_operation_map_delete_element_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; uint8_t key[1]; } ebpf_operation_map_delete_element_request_t; typedef struct _ebpf_operation_get_next_map_request { struct _ebpf_operation_header header; - uint64_t previous_handle; + ebpf_handle_t previous_handle; } ebpf_operation_get_next_map_request_t; typedef struct _ebpf_operation_get_next_map_reply { struct _ebpf_operation_header header; - uint64_t next_handle; + ebpf_handle_t next_handle; } ebpf_operation_get_next_map_reply_t; typedef struct _ebpf_operation_get_next_program_request { struct _ebpf_operation_header header; - uint64_t previous_handle; + ebpf_handle_t previous_handle; } ebpf_operation_get_next_program_request_t; typedef struct _ebpf_operation_get_next_program_reply { struct _ebpf_operation_header header; - uint64_t next_handle; + ebpf_handle_t next_handle; } ebpf_operation_get_next_program_reply_t; typedef struct _ebpf_operation_query_map_definition_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; } ebpf_operation_query_map_definition_request; typedef struct _ebpf_operation_query_map_definition_reply @@ -204,13 +204,13 @@ typedef struct _ebpf_operation_get_handle_by_id_request typedef struct _ebpf_operation_get_handle_by_id_reply { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; } ebpf_operation_get_handle_by_id_reply_t; typedef struct _ebpf_operation_query_program_info_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; } ebpf_operation_query_program_info_request_t; typedef struct _ebpf_operation_query_program_info_reply @@ -225,21 +225,21 @@ typedef struct _ebpf_operation_query_program_info_reply typedef struct _ebpf_operation_map_get_next_key_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; uint8_t previous_key[1]; } ebpf_operation_map_get_next_key_request_t; typedef struct _ebpf_operation_map_get_next_key_reply { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; uint8_t next_key[1]; } ebpf_operation_map_get_next_key_reply_t; typedef struct _ebpf_operation_update_map_pinning_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; uint8_t name[1]; } ebpf_operation_update_pinning_request_t; @@ -252,13 +252,13 @@ typedef struct _ebpf_operation_get_pinning_request typedef struct _ebpf_operation_get_pinning_reply { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; } ebpf_operation_get_map_pinning_reply_t; typedef struct _ebpf_operation_link_program_request { struct _ebpf_operation_header header; - uint64_t program_handle; + ebpf_handle_t program_handle; ebpf_attach_type_t attach_type; uint8_t data[1]; } ebpf_operation_link_program_request_t; @@ -266,19 +266,19 @@ typedef struct _ebpf_operation_link_program_request typedef struct _ebpf_operation_link_program_reply { struct _ebpf_operation_header header; - uint64_t link_handle; + ebpf_handle_t link_handle; } ebpf_operation_link_program_reply_t; typedef struct _ebpf_operation_unlink_program_request { struct _ebpf_operation_header header; - uint64_t link_handle; + ebpf_handle_t link_handle; } ebpf_operation_unlink_program_request_t; typedef struct _ebpf_operation_close_handle_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; } ebpf_operation_close_handle_request_t; typedef struct _ebpf_operation_get_ec_function_request @@ -290,14 +290,14 @@ typedef struct _ebpf_operation_get_ec_function_request typedef struct _ebpf_operation_get_ec_function_reply { struct _ebpf_operation_header header; - uint64_t address; + uintptr_t address; } ebpf_operation_get_ec_function_reply_t; typedef struct _ebpf_operation_get_program_info_request { struct _ebpf_operation_header header; ebpf_program_type_t program_type; - uint64_t program_handle; + ebpf_handle_t program_handle; } ebpf_operation_get_program_info_request_t; typedef struct _ebpf_operation_get_program_info_reply @@ -311,7 +311,7 @@ typedef struct _ebpf_operation_get_program_info_reply typedef struct _ebpf_operation_get_map_info_request { struct _ebpf_operation_header header; - uint64_t handle; + ebpf_handle_t handle; } ebpf_operation_get_map_info_request_t; typedef struct _ebpf_operation_get_map_info_reply diff --git a/libs/platform/ebpf_handle.h b/libs/platform/ebpf_handle.h index edc5b841c..7741d2b60 100644 --- a/libs/platform/ebpf_handle.h +++ b/libs/platform/ebpf_handle.h @@ -3,6 +3,7 @@ #pragma once +#include "ebpf_core_structs.h" #include "ebpf_object.h" #include "ebpf_platform.h" @@ -10,9 +11,6 @@ extern "C" { #endif - - typedef uint64_t ebpf_handle_t; - /** * @brief Initialize the global handle table. * diff --git a/libs/platform/kernel/ebpf_handle_kernel.c b/libs/platform/kernel/ebpf_handle_kernel.c index 1bbf1145b..b4bfb34ba 100644 --- a/libs/platform/kernel/ebpf_handle_kernel.c +++ b/libs/platform/kernel/ebpf_handle_kernel.c @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT #include "ebpf_handle.h" +#include "framework.h" extern DEVICE_OBJECT* ebpf_driver_get_device_object(); diff --git a/libs/platform/kernel/stdint.h b/libs/platform/kernel/stdint.h index 415e2a45c..2df19601d 100644 --- a/libs/platform/kernel/stdint.h +++ b/libs/platform/kernel/stdint.h @@ -13,3 +13,9 @@ typedef UINT8 uint8_t; typedef UINT16 uint16_t; typedef UINT32 uint32_t; typedef UINT64 uint64_t; + +#ifdef _WIN64 +typedef __int64 intptr_t; +#else +typedef _W64 int intptr_t; +#endif \ No newline at end of file diff --git a/libs/service/api_service.cpp b/libs/service/api_service.cpp index ea326e812..613faf6cc 100644 --- a/libs/service/api_service.cpp +++ b/libs/service/api_service.cpp @@ -60,7 +60,7 @@ _build_helper_id_to_address_map( auto reply = reinterpret_cast(reply_buffer.data()); request->header.id = ebpf_operation_id_t::EBPF_OPERATION_RESOLVE_HELPER; request->header.length = static_cast(request_buffer.size()); - request->program_handle = reinterpret_cast(program_handle); + request->program_handle = program_handle; // Build list of helper_ids to resolve and assign new helper id. // New helper ids are in the range [0,63] @@ -165,7 +165,7 @@ _resolve_maps_in_byte_code(ebpf_handle_t program_handle, ebpf_code_buffer_t& byt auto reply = reinterpret_cast(reply_buffer.data()); request->header.id = ebpf_operation_id_t::EBPF_OPERATION_RESOLVE_MAP; request->header.length = static_cast(request_buffer.size()); - request->program_handle = reinterpret_cast(program_handle); + request->program_handle = program_handle; for (size_t index = 0; index < map_handles.size(); index++) { if (map_handles[index] > get_map_descriptor_size()) { @@ -208,7 +208,7 @@ _query_and_cache_map_descriptors( descriptor = {0}; ebpf_id_t inner_map_id; result = query_map_definition( - handle_map[i].handle, + reinterpret_cast(handle_map[i].handle), &size, &descriptor.type, &descriptor.key_size, @@ -226,7 +226,7 @@ _query_and_cache_map_descriptors( descriptor.value_size, descriptor.max_entries, handle_map[i].inner_map_original_fd, - handle_map[i].handle, + reinterpret_cast(handle_map[i].handle), 0); } } @@ -398,7 +398,7 @@ ebpf_verify_and_load_program( request = reinterpret_cast(request_buffer.data()); request->header.id = ebpf_operation_id_t::EBPF_OPERATION_LOAD_CODE; request->header.length = static_cast(request_buffer.size()); - request->program_handle = reinterpret_cast(program_handle); + request->program_handle = program_handle; request->code_type = execution_type == EBPF_EXECUTION_JIT ? EBPF_CODE_NATIVE : EBPF_CODE_EBPF; std::copy( diff --git a/libs/service/service.vcxproj b/libs/service/service.vcxproj index 47ee9f920..23f6d1505 100644 --- a/libs/service/service.vcxproj +++ b/libs/service/service.vcxproj @@ -132,7 +132,7 @@ true NotUsing pch.h - $(SolutionDir)rpc_interface;$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)rpc_interface;$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(OutDir);$(SolutionDir)\libs\thunk;%(AdditionalIncludeDirectories) stdcpplatest MultiThreadedDebugDll true @@ -154,7 +154,7 @@ true NotUsing pch.h - $(SolutionDir)rpc_interface;$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)rpc_interface;$(SolutionDir)libs\api_common;$(SolutionDir)libs\api;$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)external\ebpf-verifier\external;$(OutDir);$(SolutionDir)\libs\thunk;%(AdditionalIncludeDirectories) stdcpplatest true @@ -198,4 +198,4 @@ - + \ No newline at end of file diff --git a/tests/end_to_end/mock.cpp b/libs/thunk/mock/mock.cpp similarity index 73% rename from tests/end_to_end/mock.cpp rename to libs/thunk/mock/mock.cpp index 8ab6c2920..ab328ffbc 100644 --- a/tests/end_to_end/mock.cpp +++ b/libs/thunk/mock/mock.cpp @@ -6,9 +6,12 @@ #include "mock.h" #include "rpc_interface_h.h" +std::function close_handler; +std::function close_handle_handler; std::function create_file_handler; std::function device_io_control_handler; -std::function close_handle_handler; +std::function get_osfhandle_handler; +std::function open_osfhandle_handler; namespace Platform { bool @@ -23,7 +26,7 @@ DeviceIoControl( _Inout_opt_ OVERLAPPED* overlapped) { return device_io_control_handler( - device_handle, + reinterpret_cast(device_handle), (DWORD)io_control_code, input_buffer, (DWORD)input_buffer_size, @@ -43,20 +46,38 @@ CreateFileW( uint32_t flags_and_attributes, _In_opt_ ebpf_handle_t template_file) { - return create_file_handler( + return reinterpret_cast(create_file_handler( file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, - template_file); + reinterpret_cast(template_file))); } bool CloseHandle(_In_ _Post_ptr_invalid_ ebpf_handle_t handle) { - return close_handle_handler(handle); + return close_handle_handler(reinterpret_cast(handle)); +} + +int +_open_osfhandle(intptr_t os_file_handle, int flags) +{ + return open_osfhandle_handler(os_file_handle, flags); +} + +intptr_t +_get_osfhandle(int file_descriptor) +{ + return get_osfhandle_handler(file_descriptor); +} + +int +_close(int file_handle) +{ + return close_handler(file_handle); } } // namespace Platform @@ -73,12 +94,12 @@ ebpf_result_t ebpf_rpc_load_program(ebpf_program_load_info* info, const char** logs, uint32_t* logs_size) { // Set the handle of program being verified in thread-local storage. - set_program_under_verification(info->program_handle); + set_program_under_verification(reinterpret_cast(info->program_handle)); // Short circuit rpc call to service lib. ebpf_result_t result = ebpf_verify_and_load_program( &info->program_type, - info->program_handle, + reinterpret_cast(info->program_handle), info->execution_context, info->execution_type, info->map_count, diff --git a/tests/end_to_end/mock.h b/libs/thunk/mock/mock.h similarity index 61% rename from tests/end_to_end/mock.h rename to libs/thunk/mock/mock.h index 30fd12a00..c2a8afbef 100644 --- a/tests/end_to_end/mock.h +++ b/libs/thunk/mock/mock.h @@ -4,7 +4,11 @@ #pragma once #include #include +#include +extern std::function close_handler; +extern std::function close_handle_handler; extern std::function create_file_handler; extern std::function device_io_control_handler; -extern std::function close_handle_handler; +extern std::function get_osfhandle_handler; +extern std::function open_osfhandle_handler; diff --git a/libs/api/platform.h b/libs/thunk/platform.h similarity index 83% rename from libs/api/platform.h rename to libs/thunk/platform.h index 3c0179714..780407898 100644 --- a/libs/api/platform.h +++ b/libs/thunk/platform.h @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation // SPDX-License-Identifier: MIT +#include "ebpf_core_structs.h" + #pragma once namespace Platform { bool @@ -26,4 +28,14 @@ CreateFileW( bool CloseHandle(_In_ _Post_ptr_invalid_ ebpf_handle_t handle); + +int +_open_osfhandle(intptr_t os_file_handle, int flags); + +intptr_t +_get_osfhandle(int file_descriptor); + +int +_close(int file_descriptor); + } // namespace Platform diff --git a/libs/thunk/windows/platform.cpp b/libs/thunk/windows/platform.cpp new file mode 100644 index 000000000..5c8f0cfbf --- /dev/null +++ b/libs/thunk/windows/platform.cpp @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation +// SPDX-License-Identifier: MIT + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include // For _CrtSetReportMode +#include "ebpf_api.h" + +class _invalid_parameter_suppression +{ + public: + _invalid_parameter_suppression() + { + _CrtSetReportMode(_CRT_ASSERT, 0); + previous_handler = _set_invalid_parameter_handler(_ignore_invalid_parameter); + } + ~_invalid_parameter_suppression() { _set_invalid_parameter_handler(previous_handler); } + + private: + static void + _ignore_invalid_parameter( + const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved) + { + UNREFERENCED_PARAMETER(expression); + UNREFERENCED_PARAMETER(function); + UNREFERENCED_PARAMETER(file); + UNREFERENCED_PARAMETER(line); + UNREFERENCED_PARAMETER(pReserved); + } + _invalid_parameter_handler previous_handler; +}; + +namespace Platform { +bool +DeviceIoControl( + _In_ ebpf_handle_t device_handle, + uint32_t io_control_code, + _In_reads_bytes_opt_(input_buffer_size) void* input_buffer, + uint32_t input_buffer_size, + _Out_writes_bytes_to_opt_(output_buffer_size, *count_of_bytes_returned) void* output_buffer, + uint32_t output_buffer_size, + _Out_opt_ uint32_t* count_of_bytes_returned, + _Inout_opt_ OVERLAPPED* overlapped) +{ + return ::DeviceIoControl( + reinterpret_cast(device_handle), + io_control_code, + input_buffer, + input_buffer_size, + output_buffer, + output_buffer_size, + (DWORD*)count_of_bytes_returned, + overlapped); +} + +ebpf_handle_t +CreateFileW( + _In_z_ PCWSTR file_name, + uint32_t desired_access, + uint32_t share_mode, + _In_opt_ SECURITY_ATTRIBUTES* security_attributes, + uint32_t creation_disposition, + uint32_t flags_and_attributes, + _In_opt_ ebpf_handle_t template_file) +{ + return reinterpret_cast(::CreateFileW( + file_name, + desired_access, + share_mode, + security_attributes, + creation_disposition, + flags_and_attributes, + reinterpret_cast(template_file))); +} + +bool +CloseHandle(_In_ _Post_ptr_invalid_ ebpf_handle_t handle) +{ + return ::CloseHandle(reinterpret_cast(handle)); +} + +int +_open_osfhandle(intptr_t os_file_handle, int flags) +{ + _invalid_parameter_suppression suppress; + return ::_open_osfhandle(os_file_handle, flags); +} + +intptr_t +_get_osfhandle(int file_descriptor) +{ + _invalid_parameter_suppression suppress; + return ::_get_osfhandle(file_descriptor); +} + +int +_close(int file_descriptor) +{ + _invalid_parameter_suppression suppress; + return ::_close(file_descriptor); +} +} // namespace Platform \ No newline at end of file diff --git a/tests/api_test/api_test.cpp b/tests/api_test/api_test.cpp index ac7ef141b..a5867eb31 100644 --- a/tests/api_test/api_test.cpp +++ b/tests/api_test/api_test.cpp @@ -9,6 +9,7 @@ #include "api_test.h" #include "catch_wrapper.hpp" #include "common_tests.h" +#include #include "service_helper.h" #include "libbpf.h" #define SAMPLE_PATH "" @@ -101,7 +102,7 @@ _test_program_load( REQUIRE(ebpf_get_next_program(previous_fd, &next_fd) == EBPF_SUCCESS); REQUIRE(next_fd == ebpf_fd_invalid); - ebpf_close_fd(previous_fd); + _close(previous_fd); previous_fd = ebpf_fd_invalid; bpf_object__close(object); diff --git a/tests/api_test/api_test.vcxproj b/tests/api_test/api_test.vcxproj index 839984283..6e8d4db04 100644 --- a/tests/api_test/api_test.vcxproj +++ b/tests/api_test/api_test.vcxproj @@ -125,7 +125,7 @@ true MultiThreadedDebugDll ProgramDatabase - $(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)libs\thunk;%(AdditionalIncludeDirectories) stdcpplatest true @@ -142,7 +142,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);%(AdditionalIncludeDirectories) + $(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)libs\thunk;%(AdditionalIncludeDirectories) stdcpplatest true MultiThreadedDLL @@ -161,9 +161,6 @@ {75fe223a-3e45-4b0e-a2e8-04285e52e440} - - {af85c549-57cc-40a5-bdfc-dcf1998de80f} - {1423245d-0249-40fc-a077-ff7780acfe3f} diff --git a/tests/client/ebpf_client.vcxproj b/tests/client/ebpf_client.vcxproj index 3710e8f83..e7e507dfd 100644 --- a/tests/client/ebpf_client.vcxproj +++ b/tests/client/ebpf_client.vcxproj @@ -160,8 +160,8 @@ + - diff --git a/tests/client/ebpf_client.vcxproj.filters b/tests/client/ebpf_client.vcxproj.filters index 29d020506..98341dcda 100644 --- a/tests/client/ebpf_client.vcxproj.filters +++ b/tests/client/ebpf_client.vcxproj.filters @@ -1,4 +1,8 @@  + @@ -15,15 +19,15 @@ - - Source Files - Source Files Source Files + + Source Files + diff --git a/tests/client/platform.cpp b/tests/client/platform.cpp deleted file mode 100644 index 4aadafe6c..000000000 --- a/tests/client/platform.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Corporation -// SPDX-License-Identifier: MIT - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include "ebpf_api.h" -#include "framework.h" - -namespace Platform { -bool -DeviceIoControl( - _In_ ebpf_handle_t device_handle, - uint32_t io_control_code, - _In_reads_bytes_opt_(input_buffer_size) void* input_buffer, - uint32_t input_buffer_size, - _Out_writes_bytes_to_opt_(output_buffer_size, *count_of_bytes_returned) void* output_buffer, - uint32_t output_buffer_size, - _Out_opt_ uint32_t* count_of_bytes_returned, - _Inout_opt_ OVERLAPPED* overlapped) -{ - return ::DeviceIoControl( - device_handle, - io_control_code, - input_buffer, - input_buffer_size, - output_buffer, - output_buffer_size, - (DWORD*)count_of_bytes_returned, - overlapped); -} - -ebpf_handle_t -CreateFileW( - _In_z_ PCWSTR file_name, - uint32_t desired_access, - uint32_t share_mode, - _In_opt_ SECURITY_ATTRIBUTES* security_attributes, - uint32_t creation_disposition, - uint32_t flags_and_attributes, - _In_opt_ ebpf_handle_t template_file) -{ - return ::CreateFileW( - file_name, - desired_access, - share_mode, - security_attributes, - creation_disposition, - flags_and_attributes, - template_file); -} - -bool -CloseHandle(_In_ _Post_ptr_invalid_ ebpf_handle_t handle) -{ - return ::CloseHandle(handle); -} -} // namespace Platform diff --git a/tests/end_to_end/end_to_end.cpp b/tests/end_to_end/end_to_end.cpp index 66ccf5762..80617cfa0 100644 --- a/tests/end_to_end/end_to_end.cpp +++ b/tests/end_to_end/end_to_end.cpp @@ -19,6 +19,7 @@ #include "helpers.h" #include "libbpf.h" #include "mock.h" +#include "platform.h" #include "program_helper.h" #include "sample_test_common.h" #include "test_helper.hpp" @@ -728,7 +729,7 @@ TEST_CASE("enumerate_and_query_programs", "[end_to_end]") REQUIRE(ebpf_get_next_program(program_fd, &next_program_fd) == EBPF_SUCCESS); REQUIRE(next_program_fd != ebpf_fd_invalid); - ebpf_close_fd(program_fd); + Platform::_close(program_fd); program_fd = next_program_fd; REQUIRE(ebpf_program_query_info(program_fd, &type, &file_name, §ion_name) == EBPF_SUCCESS); REQUIRE(type == EBPF_EXECUTION_INTERPRET); @@ -741,7 +742,7 @@ TEST_CASE("enumerate_and_query_programs", "[end_to_end]") REQUIRE(ebpf_get_next_program(program_fd, &next_program_fd) == EBPF_SUCCESS); REQUIRE(next_program_fd == ebpf_fd_invalid); - ebpf_close_fd(program_fd); + Platform::_close(program_fd); for (int i = 0; i < _countof(object); i++) { bpf_object__close(object[i]); diff --git a/tests/end_to_end/helpers.h b/tests/end_to_end/helpers.h index 22494f456..c3c45da64 100644 --- a/tests/end_to_end/helpers.h +++ b/tests/end_to_end/helpers.h @@ -73,7 +73,7 @@ typedef class _single_instance_hook : public _hook_helper public: _single_instance_hook(ebpf_program_type_t program_type, ebpf_attach_type_t attach_type) : _hook_helper{attach_type}, provider(nullptr), client_binding_context(nullptr), client_data(nullptr), - client_dispatch_table(nullptr), link_handle(nullptr) + client_dispatch_table(nullptr), link_handle(ebpf_handle_invalid) { ebpf_guid_create(&client_id); attach_provider_data.supported_program_type = program_type; diff --git a/tests/end_to_end/netsh_test.cpp b/tests/end_to_end/netsh_test.cpp index 11e673fa1..7379291ed 100644 --- a/tests/end_to_end/netsh_test.cpp +++ b/tests/end_to_end/netsh_test.cpp @@ -12,6 +12,7 @@ #include "libbpf.h" #pragma warning(pop) #include "maps.h" +#include "platform.h" #include "programs.h" #include "test_helper.hpp" @@ -279,6 +280,6 @@ TEST_CASE("show maps", "[netsh][maps]") " Hash of maps 4 4 2 0\n" " Array 4 4 1 0\n"); - ebpf_close_fd(inner_map_fd); // TODO(issue #287): change to _close(inner_map_fd); - ebpf_close_fd(outer_map_fd); // TODO(issue #287): change to _close(outer_map_fd); + Platform::_close(inner_map_fd); + Platform::_close(outer_map_fd); } \ No newline at end of file diff --git a/tests/end_to_end/test_helper.cpp b/tests/end_to_end/test_helper.cpp index d385acb3a..0b901228f 100644 --- a/tests/end_to_end/test_helper.cpp +++ b/tests/end_to_end/test_helper.cpp @@ -1,5 +1,7 @@ // Copyright (c) Microsoft Corporation // SPDX-License-Identifier: MIT +#include + #include "catch_wrapper.hpp" #include "ebpf_api.h" #include "ebpf_core.h" @@ -7,7 +9,10 @@ #include "mock.h" #include "test_helper.hpp" -ebpf_handle_t +static uint64_t _ebpf_file_descriptor_counter = 0; +static std::map _fd_to_handle_map; + +HANDLE GlueCreateFileW( PCWSTR lpFileName, DWORD dwDesiredAccess, @@ -15,7 +20,7 @@ GlueCreateFileW( PSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, - ebpf_handle_t hTemplateFile) + HANDLE hTemplateFile) { UNREFERENCED_PARAMETER(lpFileName); UNREFERENCED_PARAMETER(dwDesiredAccess); @@ -25,11 +30,11 @@ GlueCreateFileW( UNREFERENCED_PARAMETER(dwFlagsAndAttributes); UNREFERENCED_PARAMETER(hTemplateFile); - return (ebpf_handle_t)0x12345678; + return (HANDLE)0x12345678; } BOOL -GlueCloseHandle(ebpf_handle_t hObject) +GlueCloseHandle(HANDLE hObject) { UNREFERENCED_PARAMETER(hObject); return TRUE; @@ -37,7 +42,7 @@ GlueCloseHandle(ebpf_handle_t hObject) BOOL GlueDeviceIoControl( - ebpf_handle_t hDevice, + HANDLE hDevice, DWORD dwIoControlCode, PVOID lpInBuffer, DWORD nInBufferSize, @@ -121,11 +126,63 @@ Fail: return FALSE; } +int +Glue_open_osfhandle(intptr_t os_file_handle, int flags) +{ + UNREFERENCED_PARAMETER(flags); + try { + fd_t fd = static_cast(InterlockedIncrement(&_ebpf_file_descriptor_counter)); + _fd_to_handle_map.insert(std::pair(fd, os_file_handle)); + return fd; + } catch (...) { + return ebpf_fd_invalid; + } +} + +intptr_t +Glue_get_osfhandle(int file_descriptor) +{ + if (file_descriptor == ebpf_fd_invalid) { + errno = EINVAL; + return ebpf_handle_invalid; + } + + std::map::iterator it = _fd_to_handle_map.find(file_descriptor); + if (it != _fd_to_handle_map.end()) { + return it->second; + } + + errno = EINVAL; + return ebpf_handle_invalid; +} + +int +Glue_close(int file_descriptor) +{ + if (file_descriptor == ebpf_fd_invalid) { + errno = EINVAL; + return ebpf_handle_invalid; + } + + std::map::iterator it = _fd_to_handle_map.find(file_descriptor); + if (it == _fd_to_handle_map.end()) { + errno = EINVAL; + return -1; + } else { + ebpf_api_close_handle(it->second); + _fd_to_handle_map.erase(file_descriptor); + return 0; + } +} + _test_helper_end_to_end::_test_helper_end_to_end() { device_io_control_handler = GlueDeviceIoControl; create_file_handler = GlueCreateFileW; close_handle_handler = GlueCloseHandle; + open_osfhandle_handler = Glue_open_osfhandle; + get_osfhandle_handler = Glue_get_osfhandle; + close_handler = Glue_close; REQUIRE(ebpf_core_initiate() == EBPF_SUCCESS); ec_initialized = true; REQUIRE(ebpf_api_initiate() == EBPF_SUCCESS); diff --git a/tests/performance/performance.cpp b/tests/performance/performance.cpp index 0704b00ef..661e4cd61 100644 --- a/tests/performance/performance.cpp +++ b/tests/performance/performance.cpp @@ -275,9 +275,7 @@ typedef class _ebpf_map_test_state ebpf_map_definition_in_memory_t definition{ sizeof(ebpf_map_definition_in_memory_t), type, sizeof(uint32_t), sizeof(uint64_t), ebpf_get_cpu_count()}; - REQUIRE( - ebpf_map_create(&name, &definition, reinterpret_cast(ebpf_handle_invalid), &map) == - EBPF_SUCCESS); + REQUIRE(ebpf_map_create(&name, &definition, ebpf_handle_invalid, &map) == EBPF_SUCCESS); for (uint32_t i = 0; i < ebpf_get_cpu_count(); i++) { uint64_t value = 0; diff --git a/tests/performance/performance.vcxproj b/tests/performance/performance.vcxproj index 9ca5e98af..d1c6f01e3 100644 --- a/tests/performance/performance.vcxproj +++ b/tests/performance/performance.vcxproj @@ -125,7 +125,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample\ext\inc;$(SolutionDir)\netebpfext;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;%(AdditionalIncludeDirectories) + $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample\ext\inc;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)libs\thunk\mock;$(SolutionDir)\netebpfext;%(AdditionalIncludeDirectories) true stdcpp17 MultiThreadedDebugDll @@ -144,7 +144,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample\ext\inc;;$(SolutionDir)\netebpfext;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;%(AdditionalIncludeDirectories) + $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample\ext\inc;$(SolutionDir)external\ubpf\vm;$(SolutionDir)external\ubpf\vm\inc;$(SolutionDir)libs\thunk\mock;$(SolutionDir)\netebpfext;%(AdditionalIncludeDirectories) true stdcpp17 @@ -157,7 +157,7 @@ - + diff --git a/tests/performance/performance.vcxproj.filters b/tests/performance/performance.vcxproj.filters index ffcaf8fdb..03a125a1c 100644 --- a/tests/performance/performance.vcxproj.filters +++ b/tests/performance/performance.vcxproj.filters @@ -25,7 +25,7 @@ Source Files - + Source Files diff --git a/tests/unit/libbpf_test.cpp b/tests/unit/libbpf_test.cpp index da4be1b98..92e4b27ed 100644 --- a/tests/unit/libbpf_test.cpp +++ b/tests/unit/libbpf_test.cpp @@ -10,6 +10,7 @@ #pragma warning(disable : 4200) #include "libbpf.h" #pragma warning(pop) +#include "platform.h" #include "program_helper.h" #include "test_helper.hpp" @@ -370,7 +371,7 @@ _ebpf_test_tail_call(_In_z_ const char* filename, int expected_result) // a valid program ID. int callee_fd2 = bpf_prog_get_fd_by_id(callee_id); REQUIRE(callee_fd2 > 0); - ebpf_close_fd(callee_fd2); // TODO(issue #287): change to _close(callee_fd2); + Platform::_close(callee_fd2); bpf_link* link = bpf_program__attach_xdp(caller, 1); REQUIRE(link != nullptr); @@ -482,7 +483,7 @@ TEST_CASE("disallow prog_array mixed program type values", "[libbpf]") REQUIRE(error < 0); REQUIRE(errno == EINVAL); - ebpf_close_fd(map_fd); // TODO(issue #287): change to _close(map_fd); + Platform::_close(map_fd); bpf_object__close(bind_object); bpf_object__close(xdp_object); } @@ -508,13 +509,13 @@ TEST_CASE("enumerate program IDs", "[libbpf]") REQUIRE(bpf_prog_get_next_id(0, &id1) == 0); fd_t fd1 = bpf_prog_get_fd_by_id(id1); REQUIRE(fd1 >= 0); - ebpf_close_fd(fd1); // TODO(issue #287): change to _close(fd1); + Platform::_close(fd1); uint32_t id2; REQUIRE(bpf_prog_get_next_id(id1, &id2) == 0); fd_t fd2 = bpf_prog_get_fd_by_id(id2); REQUIRE(fd2 >= 0); - ebpf_close_fd(fd2); // TODO(issue #287): change to _close(fd2); + Platform::_close(fd2); uint32_t id3; REQUIRE(bpf_prog_get_next_id(id2, &id3) < 0); @@ -547,7 +548,7 @@ TEST_CASE("simple hash of maps", "[libbpf]") // a valid map ID. int inner_map_fd2 = bpf_map_get_fd_by_id(inner_map_id); REQUIRE(inner_map_fd2 > 0); - ebpf_close_fd(inner_map_fd2); // TODO(issue #287): change to _close(inner_map_fd2); + Platform::_close(inner_map_fd2); // Verify we can't insert an integer into the outer map. __u32 bad_value = 12345678; @@ -566,8 +567,8 @@ TEST_CASE("simple hash of maps", "[libbpf]") error = bpf_map_delete_elem(outer_map_fd, &outer_key); REQUIRE(error == 0); - ebpf_close_fd(inner_map_fd); // TODO(issue #287): change to _close(inner_map_fd); - ebpf_close_fd(outer_map_fd); // TODO(issue #287): change to _close(outer_map_fd); + Platform::_close(inner_map_fd); + Platform::_close(outer_map_fd); } // Verify an app can communicate with an eBPF program via an array of maps. @@ -619,7 +620,7 @@ TEST_CASE("array of maps", "[libbpf]") // Verify the return value is what we saved in the inner map. REQUIRE(result == inner_value); - ebpf_close_fd(inner_map_fd); // TODO(issue #287): change to _close(inner_map_fd); + Platform::_close(inner_map_fd); bpf_object__close(xdp_object); } @@ -650,7 +651,7 @@ TEST_CASE("disallow wrong inner map types", "[libbpf]") REQUIRE(error < 0); REQUIRE(errno == EINVAL); - ebpf_close_fd(inner_map_fd); // TODO(issue #287): change to _close(inner_map_fd); + Platform::_close(inner_map_fd); // Try an inner map with wrong key_size. inner_map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(__u64), sizeof(__u32), 1, 0); @@ -658,7 +659,7 @@ TEST_CASE("disallow wrong inner map types", "[libbpf]") error = bpf_map_update_elem(outer_map_fd, &outer_key, &inner_map_fd, 0); REQUIRE(error < 0); REQUIRE(errno == EINVAL); - ebpf_close_fd(inner_map_fd); // TODO(issue #287): change to _close(inner_map_fd); + Platform::_close(inner_map_fd); // Try an inner map of the wrong value size. inner_map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(__u32), sizeof(__u64), 1, 0); @@ -666,7 +667,7 @@ TEST_CASE("disallow wrong inner map types", "[libbpf]") error = bpf_map_update_elem(outer_map_fd, &outer_key, &inner_map_fd, 0); REQUIRE(error < 0); REQUIRE(errno == EINVAL); - ebpf_close_fd(inner_map_fd); // TODO(issue #287): change to _close(inner_map_fd); + Platform::_close(inner_map_fd); // Try an inner map with wrong max_entries. inner_map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(__u32), sizeof(__u32), 2, 0); @@ -674,7 +675,7 @@ TEST_CASE("disallow wrong inner map types", "[libbpf]") error = bpf_map_update_elem(outer_map_fd, &outer_key, &inner_map_fd, 0); REQUIRE(error < 0); REQUIRE(errno == EINVAL); - ebpf_close_fd(inner_map_fd); // TODO(issue #287): change to _close(inner_map_fd); + Platform::_close(inner_map_fd); bpf_object__close(xdp_object); } @@ -699,22 +700,22 @@ TEST_CASE("enumerate map IDs", "[libbpf]") REQUIRE(bpf_map_get_next_id(0, &id1) == 0); fd_t fd1 = bpf_map_get_fd_by_id(id1); REQUIRE(fd1 >= 0); - ebpf_close_fd(fd1); // TODO(issue #287): change to _close(fd1); + Platform::_close(fd1); uint32_t id2; REQUIRE(bpf_map_get_next_id(id1, &id2) == 0); fd_t fd2 = bpf_map_get_fd_by_id(id2); REQUIRE(fd2 >= 0); - ebpf_close_fd(fd2); // TODO(issue #287): change to _close(fd2); + Platform::_close(fd2); uint32_t id3; REQUIRE(bpf_map_get_next_id(id2, &id3) < 0); REQUIRE(errno == ENOENT); - ebpf_close_fd(map1_fd); // TODO(issue #287): change to _close(map1_fd); - ebpf_close_fd(map2_fd); // TODO(issue #287): change to _close(map2_fd); - ebpf_close_fd(fd1); // TODO(issue #287): change to _close(fd1); - ebpf_close_fd(fd2); // TODO(issue #287): change to _close(fd2); + Platform::_close(map1_fd); + Platform::_close(map2_fd); + Platform::_close(fd1); + Platform::_close(fd2); } TEST_CASE("enumerate link IDs", "[libbpf]") @@ -740,13 +741,13 @@ TEST_CASE("enumerate link IDs", "[libbpf]") REQUIRE(bpf_link_get_next_id(0, &id1) == 0); fd_t fd1 = bpf_link_get_fd_by_id(id1); REQUIRE(fd1 >= 0); - ebpf_close_fd(fd1); // TODO(issue #287): change to _close(fd1); + Platform::_close(fd1); uint32_t id2; REQUIRE(bpf_link_get_next_id(id1, &id2) == 0); fd_t fd2 = bpf_link_get_fd_by_id(id2); REQUIRE(fd2 >= 0); - ebpf_close_fd(fd2); // TODO(issue #287): change to _close(fd2); + Platform::_close(fd2); uint32_t id3; REQUIRE(bpf_link_get_next_id(id2, &id3) < 0); @@ -818,5 +819,5 @@ TEST_CASE("bpf_obj_get_info_by_fd", "[libbpf]") // This is the flow used by bpftool to detach a link. REQUIRE(bpf_link_detach(link_fd) == 0); - ebpf_close_fd(link_fd); // TODO(issue #287): change to _close(link_fd); + Platform::_close(link_fd); } diff --git a/tests/unit/test.vcxproj b/tests/unit/test.vcxproj index 090537e85..6bef6cc96 100644 --- a/tests/unit/test.vcxproj +++ b/tests/unit/test.vcxproj @@ -126,7 +126,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample;$(SolutionDir)tests\sample\ext\inc;$(SolutionDir)\netebpfext;$(SolutionDir)\tests\xdp;$(SolutionDir)tools\encode_program_info;%(AdditionalIncludeDirectories) + $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample;$(SolutionDir)tests\sample\ext\inc;$(SolutionDir)\tests\xdp;$(SolutionDir)tools\encode_program_info;$(SolutionDir)libs\thunk;$(SolutionDir)libs\thunk\mock;$(SolutionDir)\netebpfext;%(AdditionalIncludeDirectories) true stdcpp17 MultiThreadedDebugDll @@ -146,7 +146,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample;$(SolutionDir)tests\sample\ext\inc;$(SolutionDir)\netebpfext;$(SolutionDir)\tests\xdp;$(SolutionDir)tools\encode_program_info;%(AdditionalIncludeDirectories) + $(SolutionDir)libs\api_common;$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)tests\sample;$(SolutionDir)tests\sample\ext\inc;$(SolutionDir)\tests\xdp;$(SolutionDir)tools\encode_program_info;$(SolutionDir)libs\thunk;$(SolutionDir)libs\thunk\mock;$(SolutionDir)\netebpfext;%(AdditionalIncludeDirectories) true stdcpp17 @@ -202,16 +202,16 @@ + - + - diff --git a/tests/unit/test.vcxproj.filters b/tests/unit/test.vcxproj.filters index 3f23ad73b..63034aff1 100644 --- a/tests/unit/test.vcxproj.filters +++ b/tests/unit/test.vcxproj.filters @@ -28,9 +28,6 @@ Source Files - - Source Files - Source Files @@ -46,15 +43,18 @@ Source Files + + Source Files + Header Files - + Header Files - + Header Files diff --git a/tools/encode_program_info/encode_program_info.vcxproj b/tools/encode_program_info/encode_program_info.vcxproj index 186102302..36de56ef3 100644 --- a/tools/encode_program_info/encode_program_info.vcxproj +++ b/tools/encode_program_info/encode_program_info.vcxproj @@ -187,4 +187,4 @@ $(OutputPath)encode_program_info.exe - + \ No newline at end of file diff --git a/tools/netsh/ebpfnetsh.vcxproj b/tools/netsh/ebpfnetsh.vcxproj index 533d01779..40c5f6c70 100644 --- a/tools/netsh/ebpfnetsh.vcxproj +++ b/tools/netsh/ebpfnetsh.vcxproj @@ -112,6 +112,7 @@ + diff --git a/tools/netsh/ebpfnetsh.vcxproj.filters b/tools/netsh/ebpfnetsh.vcxproj.filters index 3da5d1165..c4534a122 100644 --- a/tools/netsh/ebpfnetsh.vcxproj.filters +++ b/tools/netsh/ebpfnetsh.vcxproj.filters @@ -36,6 +36,9 @@ Source Files + + Source Files +