Add all program types to get_program_type_info in offline mode (#972)
* Encode all program info types Signed-off-by: Alan Jowett <alanjo@microsoft.com> * Expand hard coded program types and helper functions Signed-off-by: Alan Jowett <alanjo@microsoft.com> * Fix tail_call_map verification failure Signed-off-by: Alan Jowett <alanjo@microsoft.com> * Fix tail_call_map verification failure Signed-off-by: Alan Jowett <alanjo@microsoft.com>
This commit is contained in:
Родитель
05c92adeba
Коммит
17379737cf
|
@ -122,7 +122,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<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)</AdditionalIncludeDirectories>
|
||||
<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;$(SolutionDir)netebpfext;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -136,7 +136,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<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)</AdditionalIncludeDirectories>
|
||||
<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;$(SolutionDir)netebpfext;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
@ -162,6 +162,7 @@
|
|||
<ClInclude Include="tlv.h" />
|
||||
<ClInclude Include="device_helper.hpp" />
|
||||
<ClInclude Include="windows_platform_common.hpp" />
|
||||
<ClInclude Include="windows_program_type.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\tools\encode_program_info\encode_program_info.vcxproj">
|
||||
|
|
|
@ -48,5 +48,8 @@
|
|||
<ClInclude Include="device_helper.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="windows_program_type.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -12,7 +12,10 @@
|
|||
#include "ebpf_program_types.h"
|
||||
#include "ebpf_protocol.h"
|
||||
#include "ebpf_result.h"
|
||||
#include "ebpf_sample_ext_program_data.h"
|
||||
#include "ebpf_serialize.h"
|
||||
#include "ebpf_sockops_program_data.h"
|
||||
#include "ebpf_sock_addr_program_data.h"
|
||||
#include "ebpf_xdp_program_data.h"
|
||||
#include "platform.h"
|
||||
#include "platform.hpp"
|
||||
|
@ -42,6 +45,21 @@ static thread_local std::map<GUID, ebpf_helper::ebpf_memory_ptr, guid_compare> _
|
|||
|
||||
static thread_local ebpf_handle_t _program_under_verification = ebpf_handle_invalid;
|
||||
|
||||
struct encode_program_info_t
|
||||
{
|
||||
template <typename T> encode_program_info_t(const T& t) : size(sizeof(t)), data(t) {}
|
||||
const size_t size;
|
||||
const uint8_t* data;
|
||||
};
|
||||
|
||||
static std::map<GUID, encode_program_info_t, guid_compare> _encoded_program_info = {
|
||||
{EBPF_PROGRAM_TYPE_BIND, _ebpf_encoded_bind_program_info_data},
|
||||
{EBPF_PROGRAM_TYPE_SAMPLE, _ebpf_encoded_sample_ext_program_info_data},
|
||||
{EBPF_PROGRAM_TYPE_SOCK_OPS, _ebpf_encoded_sockops_program_info_data},
|
||||
{EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, _ebpf_encoded_sock_addr_program_info_data},
|
||||
{EBPF_PROGRAM_TYPE_XDP, _ebpf_encoded_xdp_program_info_data},
|
||||
};
|
||||
|
||||
void
|
||||
set_program_under_verification(ebpf_handle_t program)
|
||||
{
|
||||
|
@ -123,13 +141,10 @@ get_program_type_info(const ebpf_program_info_t** info)
|
|||
// TODO: remove this in the future.
|
||||
auto iter = _static_program_info_cache.find(*program_type);
|
||||
if (iter == _static_program_info_cache.end()) {
|
||||
if (memcmp(program_type, &EBPF_PROGRAM_TYPE_XDP, sizeof(*program_type)) == 0) {
|
||||
encoded_data = _ebpf_encoded_xdp_program_info_data;
|
||||
encoded_data_size = sizeof(_ebpf_encoded_xdp_program_info_data);
|
||||
} else if (memcmp(program_type, &EBPF_PROGRAM_TYPE_BIND, sizeof(*program_type)) == 0) {
|
||||
encoded_data = _ebpf_encoded_bind_program_info_data;
|
||||
encoded_data_size = sizeof(_ebpf_encoded_bind_program_info_data);
|
||||
}
|
||||
auto encoded_program_info = _encoded_program_info.find(*program_type);
|
||||
ebpf_assert(encoded_program_info != _encoded_program_info.end());
|
||||
encoded_data = encoded_program_info->second.data;
|
||||
encoded_data_size = encoded_program_info->second.size;
|
||||
ebpf_assert(encoded_data != nullptr);
|
||||
|
||||
result = ebpf_program_info_decode(&program_info, encoded_data, (unsigned long)encoded_data_size);
|
||||
|
|
|
@ -8,147 +8,13 @@
|
|||
#include "crab_verifier_wrapper.hpp"
|
||||
#include "ebpf_api.h"
|
||||
#include "ebpf_nethooks.h"
|
||||
#include "sample_ext_helpers.h"
|
||||
#include "helpers.hpp"
|
||||
#include "map_descriptors.hpp"
|
||||
#include "platform.hpp"
|
||||
#include "spec_type_descriptors.hpp"
|
||||
#include "windows_program_type.h"
|
||||
#include "windows_platform.hpp"
|
||||
|
||||
#define PTYPE(name, descr, native_type, prefixes) \
|
||||
{ \
|
||||
name, descr, native_type, prefixes \
|
||||
}
|
||||
|
||||
#define PTYPE_PRIVILEGED(name, descr, native_type, prefixes) \
|
||||
{ \
|
||||
name, descr, native_type, prefixes, true \
|
||||
}
|
||||
|
||||
// Allow for comma as a separator between multiple prefixes, to make
|
||||
// the preprocessor treat a prefix list as one macro argument.
|
||||
#define COMMA ,
|
||||
|
||||
//
|
||||
// XDP program type.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_xdp_context_descriptor = {
|
||||
sizeof(xdp_md_t),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data_end),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data_meta)};
|
||||
|
||||
const EbpfProgramType windows_xdp_program_type =
|
||||
PTYPE("xdp", &g_xdp_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_XDP, {"xdp"});
|
||||
|
||||
//
|
||||
// Bind program type.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_bind_context_descriptor = {
|
||||
sizeof(bind_md_t), EBPF_OFFSET_OF(bind_md_t, app_id_start), EBPF_OFFSET_OF(bind_md_t, app_id_end), -1};
|
||||
|
||||
const EbpfProgramType windows_bind_program_type =
|
||||
PTYPE("bind", &g_bind_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_BIND, {"bind"});
|
||||
|
||||
//
|
||||
// eBPF Sample extensions program type.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_sample_ext_context_descriptor = {
|
||||
sizeof(sample_program_context_t),
|
||||
EBPF_OFFSET_OF(sample_program_context_t, data_start),
|
||||
EBPF_OFFSET_OF(sample_program_context_t, data_end),
|
||||
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
||||
};
|
||||
|
||||
const EbpfProgramType windows_sample_ext_program_type =
|
||||
PTYPE("sample_ext", &g_sample_ext_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_SAMPLE, {"sample_ext"});
|
||||
|
||||
//
|
||||
// CGROUP_SOCK_ADDR.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_sock_addr_context_descriptor = {
|
||||
sizeof(bpf_sock_addr_t),
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
||||
};
|
||||
|
||||
const EbpfProgramType windows_sock_addr_program_type = {
|
||||
"sock_addr",
|
||||
&g_sock_addr_context_descriptor,
|
||||
(uint64_t)&EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR,
|
||||
{"cgroup/connect4", "cgroup/connect6", "cgroup/recv_accept4", "cgroup/recv_accept6"}};
|
||||
|
||||
//
|
||||
// SOCK_OPS.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_sock_ops_context_descriptor = {
|
||||
sizeof(bpf_sock_ops_t),
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
||||
};
|
||||
|
||||
const EbpfProgramType windows_sock_ops_program_type = {
|
||||
"sockops", &g_sock_ops_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_SOCK_OPS, {"sockops"}};
|
||||
|
||||
//
|
||||
// Global lists and vectors of program and attach types.
|
||||
//
|
||||
|
||||
const std::vector<EbpfProgramType> windows_program_types = {
|
||||
PTYPE("unspecified", {0}, 0, {}),
|
||||
windows_xdp_program_type,
|
||||
windows_bind_program_type,
|
||||
windows_sock_addr_program_type,
|
||||
windows_sock_ops_program_type,
|
||||
windows_sample_ext_program_type};
|
||||
|
||||
typedef struct _ebpf_section_definition
|
||||
{
|
||||
_Field_z_ const char* section_prefix;
|
||||
ebpf_program_type_t* prog_type;
|
||||
ebpf_attach_type_t* attach_type;
|
||||
} ebpf_section_definition_t;
|
||||
|
||||
const std::vector<ebpf_section_definition_t> windows_section_definitions = {
|
||||
// XDP.
|
||||
{"xdp", &EBPF_PROGRAM_TYPE_XDP, &EBPF_ATTACH_TYPE_XDP},
|
||||
// Bind.
|
||||
{"bind", &EBPF_PROGRAM_TYPE_BIND, &EBPF_ATTACH_TYPE_BIND},
|
||||
// socket connect v4.
|
||||
{"cgroup/connect4", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET4_CONNECT},
|
||||
// socket connect v6.
|
||||
{"cgroup/connect4", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET6_CONNECT},
|
||||
// socket recv/accept v4.
|
||||
{"cgroup/recv_accept4", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET4_RECV_ACCEPT},
|
||||
// socket recv/accept v6.
|
||||
{"cgroup/recv_accept6", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET6_RECV_ACCEPT},
|
||||
// sockops.
|
||||
{"sockops", &EBPF_PROGRAM_TYPE_SOCK_OPS, &EBPF_ATTACH_TYPE_CGROUP_SOCK_OPS},
|
||||
// Sample Extension.
|
||||
{"sample_ext", &EBPF_PROGRAM_TYPE_SAMPLE, &EBPF_ATTACH_TYPE_SAMPLE},
|
||||
};
|
||||
|
||||
struct ebpf_attach_type_compare
|
||||
{
|
||||
bool
|
||||
operator()(const ebpf_attach_type_t& lhs, const ebpf_attach_type_t& rhs) const
|
||||
{
|
||||
return (memcmp(&lhs, &rhs, sizeof(ebpf_attach_type_t)) < 0);
|
||||
}
|
||||
};
|
||||
|
||||
const std::map<ebpf_attach_type_t, const char*, ebpf_attach_type_compare> windows_section_names = {
|
||||
{EBPF_ATTACH_TYPE_XDP, "xdp"},
|
||||
{EBPF_ATTACH_TYPE_BIND, "bind"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET4_CONNECT, "cgroup/connect4"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET6_CONNECT, "cgroup/connect6"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET4_RECV_ACCEPT, "cgroup/recv_accept4"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET6_RECV_ACCEPT, "cgroup/recv_accept6"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_SOCK_OPS, "sockops"},
|
||||
{EBPF_ATTACH_TYPE_SAMPLE, "sample_ext"}};
|
||||
|
||||
const EbpfProgramType&
|
||||
get_program_type_windows(const GUID& program_type)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "crab_verifier_wrapper.hpp"
|
||||
#include "ebpf_program_types.h"
|
||||
#include "ebpf_nethooks.h"
|
||||
#include "net_ebpf_ext_program_info.h"
|
||||
#include "sample_ext_helpers.h"
|
||||
#include "sample_ext_program_info.h"
|
||||
|
||||
#define PTYPE(name, descr, native_type, prefixes) \
|
||||
{ \
|
||||
name, descr, native_type, prefixes \
|
||||
}
|
||||
|
||||
#define PTYPE_PRIVILEGED(name, descr, native_type, prefixes) \
|
||||
{ \
|
||||
name, descr, native_type, prefixes, true \
|
||||
}
|
||||
|
||||
// Allow for comma as a separator between multiple prefixes, to make
|
||||
// the preprocessor treat a prefix list as one macro argument.
|
||||
#define COMMA ,
|
||||
|
||||
//
|
||||
// XDP program type.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_xdp_context_descriptor = {
|
||||
sizeof(xdp_md_t),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data_end),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data_meta)};
|
||||
|
||||
const EbpfProgramType windows_xdp_program_type =
|
||||
PTYPE("xdp", &g_xdp_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_XDP, {"xdp"});
|
||||
|
||||
//
|
||||
// Bind program type.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_bind_context_descriptor = {
|
||||
sizeof(bind_md_t), EBPF_OFFSET_OF(bind_md_t, app_id_start), EBPF_OFFSET_OF(bind_md_t, app_id_end), -1};
|
||||
|
||||
const EbpfProgramType windows_bind_program_type =
|
||||
PTYPE("bind", &g_bind_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_BIND, {"bind"});
|
||||
|
||||
//
|
||||
// eBPF Sample extensions program type.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_sample_ext_context_descriptor = {
|
||||
sizeof(sample_program_context_t),
|
||||
EBPF_OFFSET_OF(sample_program_context_t, data_start),
|
||||
EBPF_OFFSET_OF(sample_program_context_t, data_end),
|
||||
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
||||
};
|
||||
|
||||
const EbpfProgramType windows_sample_ext_program_type =
|
||||
PTYPE("sample_ext", &g_sample_ext_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_SAMPLE, {"sample_ext"});
|
||||
|
||||
//
|
||||
// CGROUP_SOCK_ADDR.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_sock_addr_context_descriptor = {
|
||||
sizeof(bpf_sock_addr_t),
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
||||
};
|
||||
|
||||
const EbpfProgramType windows_sock_addr_program_type = {
|
||||
"sock_addr",
|
||||
&g_sock_addr_context_descriptor,
|
||||
(uint64_t)&EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR,
|
||||
{"cgroup/connect4", "cgroup/connect6", "cgroup/recv_accept4", "cgroup/recv_accept6"}};
|
||||
|
||||
//
|
||||
// SOCK_OPS.
|
||||
//
|
||||
const ebpf_context_descriptor_t g_sock_ops_context_descriptor = {
|
||||
sizeof(bpf_sock_ops_t),
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to data, or -1 if none.
|
||||
-1, // Offset into ctx struct for pointer to metadata, or -1 if none.
|
||||
};
|
||||
|
||||
const EbpfProgramType windows_sock_ops_program_type = {
|
||||
"sockops", &g_sock_ops_context_descriptor, (uint64_t)&EBPF_PROGRAM_TYPE_SOCK_OPS, {"sockops"}};
|
||||
|
||||
//
|
||||
// Global lists and vectors of program and attach types.
|
||||
//
|
||||
|
||||
const std::vector<EbpfProgramType> windows_program_types = {
|
||||
PTYPE("unspecified", {0}, 0, {}),
|
||||
windows_xdp_program_type,
|
||||
windows_bind_program_type,
|
||||
windows_sock_addr_program_type,
|
||||
windows_sock_ops_program_type,
|
||||
windows_sample_ext_program_type};
|
||||
|
||||
typedef struct _ebpf_section_definition
|
||||
{
|
||||
_Field_z_ const char* section_prefix;
|
||||
ebpf_program_type_t* prog_type;
|
||||
ebpf_attach_type_t* attach_type;
|
||||
} ebpf_section_definition_t;
|
||||
|
||||
const std::vector<ebpf_section_definition_t> windows_section_definitions = {
|
||||
// XDP.
|
||||
{"xdp", &EBPF_PROGRAM_TYPE_XDP, &EBPF_ATTACH_TYPE_XDP},
|
||||
// Bind.
|
||||
{"bind", &EBPF_PROGRAM_TYPE_BIND, &EBPF_ATTACH_TYPE_BIND},
|
||||
// socket connect v4.
|
||||
{"cgroup/connect4", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET4_CONNECT},
|
||||
// socket connect v6.
|
||||
{"cgroup/connect4", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET6_CONNECT},
|
||||
// socket recv/accept v4.
|
||||
{"cgroup/recv_accept4", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET4_RECV_ACCEPT},
|
||||
// socket recv/accept v6.
|
||||
{"cgroup/recv_accept6", &EBPF_PROGRAM_TYPE_CGROUP_SOCK_ADDR, &EBPF_ATTACH_TYPE_CGROUP_INET6_RECV_ACCEPT},
|
||||
// sockops.
|
||||
{"sockops", &EBPF_PROGRAM_TYPE_SOCK_OPS, &EBPF_ATTACH_TYPE_CGROUP_SOCK_OPS},
|
||||
// Sample Extension.
|
||||
{"sample_ext", &EBPF_PROGRAM_TYPE_SAMPLE, &EBPF_ATTACH_TYPE_SAMPLE},
|
||||
};
|
||||
|
||||
struct ebpf_attach_type_compare
|
||||
{
|
||||
bool
|
||||
operator()(const ebpf_attach_type_t& lhs, const ebpf_attach_type_t& rhs) const
|
||||
{
|
||||
return (memcmp(&lhs, &rhs, sizeof(ebpf_attach_type_t)) < 0);
|
||||
}
|
||||
};
|
||||
|
||||
const std::map<ebpf_attach_type_t, const char*, ebpf_attach_type_compare> windows_section_names = {
|
||||
{EBPF_ATTACH_TYPE_XDP, "xdp"},
|
||||
{EBPF_ATTACH_TYPE_BIND, "bind"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET4_CONNECT, "cgroup/connect4"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET6_CONNECT, "cgroup/connect6"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET4_RECV_ACCEPT, "cgroup/recv_accept4"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_INET6_RECV_ACCEPT, "cgroup/recv_accept6"},
|
||||
{EBPF_ATTACH_TYPE_CGROUP_SOCK_OPS, "sockops"},
|
||||
{EBPF_ATTACH_TYPE_SAMPLE, "sample_ext"}};
|
||||
|
||||
struct helper_function_info_t
|
||||
{
|
||||
template <typename T> helper_function_info_t(const T& t) : count(EBPF_COUNT_OF(t)), data(t) {}
|
||||
const size_t count;
|
||||
const ebpf_helper_function_prototype_t* data;
|
||||
};
|
||||
|
||||
const std::map<ebpf_program_type_t, helper_function_info_t, ebpf_attach_type_compare>
|
||||
program_type_specific_helper_functions = {
|
||||
{EBPF_PROGRAM_TYPE_XDP, _xdp_ebpf_extension_helper_function_prototype},
|
||||
{EBPF_PROGRAM_TYPE_SAMPLE, _sample_ebpf_extension_helper_function_prototype},
|
||||
};
|
|
@ -160,31 +160,7 @@
|
|||
<Message>Run bpf2c over ELF files</Message>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile Include="$(OutDir)bindmonitor_c.c" />
|
||||
<ClCompile Include="$(OutDir)bindmonitor_ringbuf_c.c" />
|
||||
<ClCompile Include="$(OutDir)bindmonitor_tailcall_c.c" />
|
||||
<ClCompile Include="$(OutDir)bpf_c.c" />
|
||||
<ClCompile Include="$(OutDir)bpf_call_c.c" />
|
||||
<ClCompile Include="$(OutDir)decap_permit_packet_c.c" />
|
||||
<ClCompile Include="$(OutDir)divide_by_zero_c.c" />
|
||||
<ClCompile Include="$(OutDir)droppacket_c.c" />
|
||||
<ClCompile Include="$(OutDir)encap_reflect_packet_c.c" />
|
||||
<ClCompile Include="$(OutDir)map_c.c" />
|
||||
<ClCompile Include="$(OutDir)map_in_map_c.c" />
|
||||
<ClCompile Include="$(OutDir)map_in_map_v2_c.c" />
|
||||
<ClCompile Include="$(OutDir)map_reuse_c.c" />
|
||||
<ClCompile Include="$(OutDir)map_reuse_2_c.c" />
|
||||
<ClCompile Include="$(OutDir)printk_c.c" />
|
||||
<ClCompile Include="$(OutDir)printk_legacy_c.c" />
|
||||
<ClCompile Include="$(OutDir)reflect_packet_c.c" />
|
||||
<ClCompile Include="$(OutDir)tail_call_c.c" />
|
||||
<ClCompile Include="$(OutDir)tail_call_bad_c.c" />
|
||||
<ClCompile Include="$(OutDir)tail_call_multiple_c.c" />
|
||||
<ClCompile Include="$(OutDir)test_utility_helpers_c.c" />
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(OutDir)bindmonitor_c.c" />
|
||||
<ClCompile Include="$(OutDir)bindmonitor_ringbuf_c.c" />
|
||||
<ClCompile Include="$(OutDir)bindmonitor_tailcall_c.c" />
|
||||
|
@ -228,7 +204,7 @@
|
|||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ItemDefinitionGroup>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
pushd $(OutDir)
|
||||
|
@ -237,6 +213,7 @@
|
|||
bpf2c --bpf bindmonitor_tailcall.o >bindmonitor_tailcall_c.c
|
||||
bpf2c --bpf bpf.o >bpf_c.c
|
||||
bpf2c --bpf bpf_call.o >bpf_call_c.c
|
||||
bpf2c --bpf cgroup_sock_addr.o >cgroup_sock_addr_c.c
|
||||
bpf2c --bpf decap_permit_packet.o >decap_permit_packet_c.c
|
||||
bpf2c --bpf divide_by_zero.o >divide_by_zero_c.c
|
||||
bpf2c --bpf droppacket.o >droppacket_c.c
|
||||
|
@ -249,45 +226,12 @@
|
|||
bpf2c --bpf printk.o >printk_c.c
|
||||
bpf2c --bpf printk_legacy.o >printk_legacy_c.c
|
||||
bpf2c --bpf reflect_packet.o >reflect_packet_c.c
|
||||
bpf2c --bpf sockops.o >sockops_c.c
|
||||
bpf2c --bpf tail_call.o >tail_call_c.c
|
||||
bpf2c --bpf tail_call_bad.o >tail_call_bad_c.c
|
||||
bpf2c --bpf tail_call_map.o >tail_call_map_c.c
|
||||
bpf2c --bpf tail_call_multiple.o >tail_call_multiple_c.c
|
||||
bpf2c --bpf test_utility_helpers.o >test_utility_helpers_c.c
|
||||
popd
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<DisableSpecificWarnings>4189;4245;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
pushd $(OutDir)
|
||||
bpf2c --bpf bindmonitor.o >bindmonitor_c.c
|
||||
bpf2c --bpf bindmonitor_ringbuf.o >bindmonitor_ringbuf_c.c
|
||||
bpf2c --bpf bindmonitor_tailcall.o >bindmonitor_tailcall_c.c
|
||||
bpf2c --bpf bpf.o >bpf_c.c
|
||||
bpf2c --bpf bpf_call.o >bpf_call_c.c
|
||||
bpf2c --no-verify --bpf cgroup_sock_addr.o >cgroup_sock_addr_c.c
|
||||
bpf2c --bpf decap_permit_packet.o >decap_permit_packet_c.c
|
||||
bpf2c --bpf divide_by_zero.o >divide_by_zero_c.c
|
||||
bpf2c --bpf droppacket.o >droppacket_c.c
|
||||
bpf2c --bpf encap_reflect_packet.o >encap_reflect_packet_c.c
|
||||
bpf2c --bpf map.o >map_c.c
|
||||
bpf2c --bpf map_in_map.o >map_in_map_c.c
|
||||
bpf2c --bpf map_in_map_v2.o >map_in_map_v2_c.c
|
||||
bpf2c --bpf map_reuse.o >map_reuse_c.c
|
||||
bpf2c --bpf map_reuse_2.o >map_reuse_2_c.c
|
||||
bpf2c --bpf printk.o >printk_c.c
|
||||
bpf2c --bpf printk_legacy.o >printk_legacy_c.c
|
||||
bpf2c --bpf reflect_packet.o >reflect_packet_c.c
|
||||
bpf2c --no-verify --bpf sockops.o >sockops_c.c
|
||||
bpf2c --bpf tail_call.o >tail_call_c.c
|
||||
bpf2c --bpf tail_call_bad.o >tail_call_bad_c.c
|
||||
bpf2c --no-verify --bpf tail_call_map.o >tail_call_map_c.c
|
||||
bpf2c --bpf tail_call_multiple.o >tail_call_multiple_c.c
|
||||
bpf2c --no-verify --bpf test_sample_ebpf.o >test_sample_ebpf_c.c
|
||||
bpf2c --bpf test_sample_ebpf.o >test_sample_ebpf_c.c
|
||||
bpf2c --bpf test_utility_helpers.o >test_utility_helpers_c.c
|
||||
popd
|
||||
</Command>
|
||||
|
|
|
@ -16,6 +16,7 @@ extern "C" metadata_table_t bindmonitor_ringbuf_metadata_table;
|
|||
extern "C" metadata_table_t bindmonitor_tailcall_metadata_table;
|
||||
extern "C" metadata_table_t bpf_metadata_table;
|
||||
extern "C" metadata_table_t bpf_call_metadata_table;
|
||||
extern "C" metadata_table_t cgroup_sock_addr_metadata_table;
|
||||
extern "C" metadata_table_t decap_permit_packet_metadata_table;
|
||||
extern "C" metadata_table_t divide_by_zero_metadata_table;
|
||||
extern "C" metadata_table_t droppacket_metadata_table;
|
||||
|
@ -28,17 +29,13 @@ extern "C" metadata_table_t map_reuse_2_metadata_table;
|
|||
extern "C" metadata_table_t printk_metadata_table;
|
||||
extern "C" metadata_table_t printk_legacy_metadata_table;
|
||||
extern "C" metadata_table_t reflect_packet_metadata_table;
|
||||
extern "C" metadata_table_t sockops_metadata_table;
|
||||
extern "C" metadata_table_t tail_call_metadata_table;
|
||||
extern "C" metadata_table_t tail_call_bad_metadata_table;
|
||||
extern "C" metadata_table_t tail_call_multiple_metadata_table;
|
||||
extern "C" metadata_table_t test_utility_helpers_metadata_table;
|
||||
|
||||
#if defined(_DEBUG)
|
||||
extern "C" metadata_table_t cgroup_sock_addr_metadata_table;
|
||||
extern "C" metadata_table_t sockops_metadata_table;
|
||||
extern "C" metadata_table_t test_sample_ebpf_metadata_table;
|
||||
extern "C" metadata_table_t tail_call_map_metadata_table;
|
||||
#endif
|
||||
extern "C" metadata_table_t tail_call_multiple_metadata_table;
|
||||
extern "C" metadata_table_t test_sample_ebpf_metadata_table;
|
||||
extern "C" metadata_table_t test_utility_helpers_metadata_table;
|
||||
|
||||
BOOL APIENTRY
|
||||
DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
|
@ -73,6 +70,7 @@ get_metadata_table(const char* name)
|
|||
FIND_METADATA_ENTRY(name, bindmonitor_tailcall);
|
||||
FIND_METADATA_ENTRY(name, bpf);
|
||||
FIND_METADATA_ENTRY(name, bpf_call);
|
||||
FIND_METADATA_ENTRY(name, cgroup_sock_addr);
|
||||
FIND_METADATA_ENTRY(name, decap_permit_packet);
|
||||
FIND_METADATA_ENTRY(name, divide_by_zero);
|
||||
FIND_METADATA_ENTRY(name, droppacket);
|
||||
|
@ -85,15 +83,12 @@ get_metadata_table(const char* name)
|
|||
FIND_METADATA_ENTRY(name, printk);
|
||||
FIND_METADATA_ENTRY(name, printk_legacy);
|
||||
FIND_METADATA_ENTRY(name, reflect_packet);
|
||||
FIND_METADATA_ENTRY(name, sockops);
|
||||
FIND_METADATA_ENTRY(name, tail_call);
|
||||
FIND_METADATA_ENTRY(name, tail_call_bad);
|
||||
FIND_METADATA_ENTRY(name, tail_call_multiple);
|
||||
FIND_METADATA_ENTRY(name, test_utility_helpers);
|
||||
#if defined(_DEBUG)
|
||||
FIND_METADATA_ENTRY(name, cgroup_sock_addr);
|
||||
FIND_METADATA_ENTRY(name, sockops);
|
||||
FIND_METADATA_ENTRY(name, tail_call_map);
|
||||
FIND_METADATA_ENTRY(name, tail_call_multiple);
|
||||
FIND_METADATA_ENTRY(name, test_sample_ebpf);
|
||||
#endif
|
||||
FIND_METADATA_ENTRY(name, test_utility_helpers);
|
||||
return nullptr;
|
||||
}
|
|
@ -49,13 +49,14 @@ get_metadata_table()
|
|||
#include "bpf2c.h"
|
||||
|
||||
static map_entry_t _maps[] = {
|
||||
{ NULL, { 7, 4, 4, 1, 0, 0, 0, 0, }, "outer_map" },
|
||||
{ NULL, { 7, 4, 4, 1, 1, 0, 0, 0, }, "outer_map" },
|
||||
{ NULL, { 3, 4, 4, 1, 0, 0, 0, 0, }, "inner_map" },
|
||||
};
|
||||
|
||||
static void _get_maps(_Outptr_result_buffer_maybenull_(*count) map_entry_t** maps, _Out_ size_t* count)
|
||||
{
|
||||
*maps = _maps;
|
||||
*count = 1;
|
||||
*count = 2;
|
||||
}
|
||||
|
||||
static helper_function_entry_t caller_helpers[] = {
|
||||
|
@ -71,80 +72,80 @@ static uint16_t caller_maps[] = {
|
|||
|
||||
static uint64_t caller(void* context)
|
||||
{
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
// Prologue
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
uint64_t stack[(UBPF_STACK_SIZE + 7) / 8];
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r0 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r1 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r2 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r3 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r4 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r5 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r6 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r10 = 0;
|
||||
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r1 = (uintptr_t)context;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack));
|
||||
|
||||
// EBPF_OP_MOV64_REG pc=0 dst=r6 src=r1 offset=0 imm=0
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r6 = r1;
|
||||
// EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=0
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r1 = IMMEDIATE(0);
|
||||
// EBPF_OP_STXW pc=2 dst=r10 src=r1 offset=-4 imm=0
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
*(uint32_t *)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1;
|
||||
// EBPF_OP_MOV64_REG pc=3 dst=r2 src=r10 offset=0 imm=0
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
r2 = r10;
|
||||
// EBPF_OP_ADD64_IMM pc=4 dst=r2 src=r0 offset=0 imm=-4
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
r2 += IMMEDIATE(-4);
|
||||
// EBPF_OP_LDDW pc=5 dst=r1 src=r0 offset=0 imm=0
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
r1 = POINTER(_maps[0].address);
|
||||
// EBPF_OP_CALL pc=7 dst=r0 src=r0 offset=0 imm=1
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
r0 = caller_helpers[0].address
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
(r1, r2, r3, r4, r5);
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
if ((caller_helpers[0].tail_call) && (r0 == 0)) return 0;
|
||||
// EBPF_OP_MOV64_REG pc=8 dst=r1 src=r6 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r1 = r6;
|
||||
// EBPF_OP_MOV64_REG pc=9 dst=r2 src=r0 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r2 = r0;
|
||||
// EBPF_OP_MOV64_IMM pc=10 dst=r3 src=r0 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r3 = IMMEDIATE(0);
|
||||
// EBPF_OP_CALL pc=11 dst=r0 src=r0 offset=0 imm=5
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r0 = caller_helpers[1].address
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
(r1, r2, r3, r4, r5);
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
if ((caller_helpers[1].tail_call) && (r0 == 0)) return 0;
|
||||
// EBPF_OP_MOV64_IMM pc=12 dst=r0 src=r0 offset=0 imm=6
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
r0 = IMMEDIATE(6);
|
||||
// EBPF_OP_EXIT pc=13 dst=r0 src=r0 offset=0 imm=0
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
return r0;
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
}
|
||||
#line __LINE__ __FILE__
|
||||
|
||||
|
@ -152,35 +153,35 @@ static GUID callee_program_type_guid = {0xf1832a85, 0x85d5, 0x45b0, {0x98, 0xa0,
|
|||
static GUID callee_attach_type_guid = {0x85e0d8ef, 0x579e, 0x4931, {0xb0, 0x72, 0x8e, 0xe2, 0x26, 0xbb, 0x2e, 0x9d}};
|
||||
static uint64_t callee(void* context)
|
||||
{
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
// Prologue
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
uint64_t stack[(UBPF_STACK_SIZE + 7) / 8];
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r0 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r1 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r2 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r3 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r6 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r10 = 0;
|
||||
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r1 = (uintptr_t)context;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack));
|
||||
|
||||
// EBPF_OP_MOV64_IMM pc=0 dst=r0 src=r0 offset=0 imm=42
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r0 = IMMEDIATE(42);
|
||||
// EBPF_OP_EXIT pc=1 dst=r0 src=r0 offset=0 imm=0
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
return r0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
}
|
||||
#line __LINE__ __FILE__
|
||||
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
#include "bpf2c.h"
|
||||
|
||||
static map_entry_t _maps[] = {
|
||||
{ NULL, { 7, 4, 4, 1, 0, 0, 0, 0, }, "outer_map" },
|
||||
{ NULL, { 7, 4, 4, 1, 1, 0, 0, 0, }, "outer_map" },
|
||||
{ NULL, { 3, 4, 4, 1, 0, 0, 0, 0, }, "inner_map" },
|
||||
};
|
||||
|
||||
static void _get_maps(_Outptr_result_buffer_maybenull_(*count) map_entry_t** maps, _Out_ size_t* count)
|
||||
{
|
||||
*maps = _maps;
|
||||
*count = 1;
|
||||
*count = 2;
|
||||
}
|
||||
|
||||
static helper_function_entry_t caller_helpers[] = {
|
||||
|
@ -29,80 +30,80 @@ static uint16_t caller_maps[] = {
|
|||
|
||||
static uint64_t caller(void* context)
|
||||
{
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
// Prologue
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
uint64_t stack[(UBPF_STACK_SIZE + 7) / 8];
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r0 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r1 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r2 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r3 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r4 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r5 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r6 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r10 = 0;
|
||||
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r1 = (uintptr_t)context;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack));
|
||||
|
||||
// EBPF_OP_MOV64_REG pc=0 dst=r6 src=r1 offset=0 imm=0
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r6 = r1;
|
||||
// EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=0
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r1 = IMMEDIATE(0);
|
||||
// EBPF_OP_STXW pc=2 dst=r10 src=r1 offset=-4 imm=0
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
*(uint32_t *)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1;
|
||||
// EBPF_OP_MOV64_REG pc=3 dst=r2 src=r10 offset=0 imm=0
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
r2 = r10;
|
||||
// EBPF_OP_ADD64_IMM pc=4 dst=r2 src=r0 offset=0 imm=-4
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
r2 += IMMEDIATE(-4);
|
||||
// EBPF_OP_LDDW pc=5 dst=r1 src=r0 offset=0 imm=0
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
r1 = POINTER(_maps[0].address);
|
||||
// EBPF_OP_CALL pc=7 dst=r0 src=r0 offset=0 imm=1
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
r0 = caller_helpers[0].address
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
(r1, r2, r3, r4, r5);
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
if ((caller_helpers[0].tail_call) && (r0 == 0)) return 0;
|
||||
// EBPF_OP_MOV64_REG pc=8 dst=r1 src=r6 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r1 = r6;
|
||||
// EBPF_OP_MOV64_REG pc=9 dst=r2 src=r0 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r2 = r0;
|
||||
// EBPF_OP_MOV64_IMM pc=10 dst=r3 src=r0 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r3 = IMMEDIATE(0);
|
||||
// EBPF_OP_CALL pc=11 dst=r0 src=r0 offset=0 imm=5
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r0 = caller_helpers[1].address
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
(r1, r2, r3, r4, r5);
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
if ((caller_helpers[1].tail_call) && (r0 == 0)) return 0;
|
||||
// EBPF_OP_MOV64_IMM pc=12 dst=r0 src=r0 offset=0 imm=6
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
r0 = IMMEDIATE(6);
|
||||
// EBPF_OP_EXIT pc=13 dst=r0 src=r0 offset=0 imm=0
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
return r0;
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
}
|
||||
#line __LINE__ __FILE__
|
||||
|
||||
|
@ -110,35 +111,35 @@ static GUID callee_program_type_guid = {0xf1832a85, 0x85d5, 0x45b0, {0x98, 0xa0,
|
|||
static GUID callee_attach_type_guid = {0x85e0d8ef, 0x579e, 0x4931, {0xb0, 0x72, 0x8e, 0xe2, 0x26, 0xbb, 0x2e, 0x9d}};
|
||||
static uint64_t callee(void* context)
|
||||
{
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
// Prologue
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
uint64_t stack[(UBPF_STACK_SIZE + 7) / 8];
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r0 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r1 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r2 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r3 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r6 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r10 = 0;
|
||||
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r1 = (uintptr_t)context;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack));
|
||||
|
||||
// EBPF_OP_MOV64_IMM pc=0 dst=r0 src=r0 offset=0 imm=42
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r0 = IMMEDIATE(42);
|
||||
// EBPF_OP_EXIT pc=1 dst=r0 src=r0 offset=0 imm=0
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
return r0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
}
|
||||
#line __LINE__ __FILE__
|
||||
|
||||
|
|
|
@ -174,13 +174,14 @@ division_by_zero(uint32_t address)
|
|||
#include "bpf2c.h"
|
||||
|
||||
static map_entry_t _maps[] = {
|
||||
{ NULL, { 7, 4, 4, 1, 0, 0, 0, 0, }, "outer_map" },
|
||||
{ NULL, { 7, 4, 4, 1, 1, 0, 0, 0, }, "outer_map" },
|
||||
{ NULL, { 3, 4, 4, 1, 0, 0, 0, 0, }, "inner_map" },
|
||||
};
|
||||
|
||||
static void _get_maps(_Outptr_result_buffer_maybenull_(*count) map_entry_t** maps, _Out_ size_t* count)
|
||||
{
|
||||
*maps = _maps;
|
||||
*count = 1;
|
||||
*count = 2;
|
||||
}
|
||||
|
||||
static helper_function_entry_t caller_helpers[] = {
|
||||
|
@ -196,80 +197,80 @@ static uint16_t caller_maps[] = {
|
|||
|
||||
static uint64_t caller(void* context)
|
||||
{
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
// Prologue
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
uint64_t stack[(UBPF_STACK_SIZE + 7) / 8];
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r0 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r1 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r2 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r3 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r4 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r5 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r6 = 0;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
register uint64_t r10 = 0;
|
||||
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r1 = (uintptr_t)context;
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack));
|
||||
|
||||
// EBPF_OP_MOV64_REG pc=0 dst=r6 src=r1 offset=0 imm=0
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r6 = r1;
|
||||
// EBPF_OP_MOV64_IMM pc=1 dst=r1 src=r0 offset=0 imm=0
|
||||
#line 20 "sample/tail_call_map.c"
|
||||
#line 29 "sample/tail_call_map.c"
|
||||
r1 = IMMEDIATE(0);
|
||||
// EBPF_OP_STXW pc=2 dst=r10 src=r1 offset=-4 imm=0
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
*(uint32_t *)(uintptr_t)(r10 + OFFSET(-4)) = (uint32_t)r1;
|
||||
// EBPF_OP_MOV64_REG pc=3 dst=r2 src=r10 offset=0 imm=0
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
r2 = r10;
|
||||
// EBPF_OP_ADD64_IMM pc=4 dst=r2 src=r0 offset=0 imm=-4
|
||||
#line 22 "sample/tail_call_map.c"
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
r2 += IMMEDIATE(-4);
|
||||
// EBPF_OP_LDDW pc=5 dst=r1 src=r0 offset=0 imm=0
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
r1 = POINTER(_maps[0].address);
|
||||
// EBPF_OP_CALL pc=7 dst=r0 src=r0 offset=0 imm=1
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
r0 = caller_helpers[0].address
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
(r1, r2, r3, r4, r5);
|
||||
#line 23 "sample/tail_call_map.c"
|
||||
#line 32 "sample/tail_call_map.c"
|
||||
if ((caller_helpers[0].tail_call) && (r0 == 0)) return 0;
|
||||
// EBPF_OP_MOV64_REG pc=8 dst=r1 src=r6 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r1 = r6;
|
||||
// EBPF_OP_MOV64_REG pc=9 dst=r2 src=r0 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r2 = r0;
|
||||
// EBPF_OP_MOV64_IMM pc=10 dst=r3 src=r0 offset=0 imm=0
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r3 = IMMEDIATE(0);
|
||||
// EBPF_OP_CALL pc=11 dst=r0 src=r0 offset=0 imm=5
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
r0 = caller_helpers[1].address
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
(r1, r2, r3, r4, r5);
|
||||
#line 25 "sample/tail_call_map.c"
|
||||
#line 34 "sample/tail_call_map.c"
|
||||
if ((caller_helpers[1].tail_call) && (r0 == 0)) return 0;
|
||||
// EBPF_OP_MOV64_IMM pc=12 dst=r0 src=r0 offset=0 imm=6
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
r0 = IMMEDIATE(6);
|
||||
// EBPF_OP_EXIT pc=13 dst=r0 src=r0 offset=0 imm=0
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
return r0;
|
||||
#line 28 "sample/tail_call_map.c"
|
||||
#line 37 "sample/tail_call_map.c"
|
||||
}
|
||||
#line __LINE__ __FILE__
|
||||
|
||||
|
@ -277,35 +278,35 @@ static GUID callee_program_type_guid = {0xf1832a85, 0x85d5, 0x45b0, {0x98, 0xa0,
|
|||
static GUID callee_attach_type_guid = {0x85e0d8ef, 0x579e, 0x4931, {0xb0, 0x72, 0x8e, 0xe2, 0x26, 0xbb, 0x2e, 0x9d}};
|
||||
static uint64_t callee(void* context)
|
||||
{
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
// Prologue
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
uint64_t stack[(UBPF_STACK_SIZE + 7) / 8];
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r0 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r1 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r2 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r3 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r6 = 0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
register uint64_t r10 = 0;
|
||||
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r1 = (uintptr_t)context;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack));
|
||||
|
||||
// EBPF_OP_MOV64_IMM pc=0 dst=r0 src=r0 offset=0 imm=42
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
r0 = IMMEDIATE(42);
|
||||
// EBPF_OP_EXIT pc=1 dst=r0 src=r0 offset=0 imm=0
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
return r0;
|
||||
#line 31 "sample/tail_call_map.c"
|
||||
#line 40 "sample/tail_call_map.c"
|
||||
}
|
||||
#line __LINE__ __FILE__
|
||||
|
||||
|
|
|
@ -924,8 +924,6 @@ _cgroup_load_test(
|
|||
|
||||
bpf_object__close(object);
|
||||
}
|
||||
// TODO: Re-enable this once https://github.com/microsoft/ebpf-for-windows/issues/971 is resolved.
|
||||
#if defined(_DEBUG)
|
||||
static void
|
||||
_cgroup_sock_addr_load_test(
|
||||
_In_z_ const char* file,
|
||||
|
@ -960,7 +958,6 @@ DECLARE_CGROUP_SOCK_ADDR_LOAD_TEST(
|
|||
SAMPLE_PATH "cgroup_sock_addr", "authorize_recv_accept4", EBPF_ATTACH_TYPE_CGROUP_INET4_RECV_ACCEPT);
|
||||
DECLARE_CGROUP_SOCK_ADDR_LOAD_TEST(
|
||||
SAMPLE_PATH "cgroup_sock_addr", "authorize_recv_accept6", EBPF_ATTACH_TYPE_CGROUP_INET6_RECV_ACCEPT);
|
||||
#endif
|
||||
|
||||
TEST_CASE("cgroup_sockops_load_test", "[cgroup_sockops]")
|
||||
{
|
||||
|
|
|
@ -15,7 +15,16 @@
|
|||
|
||||
SEC("maps")
|
||||
struct bpf_map outer_map = {
|
||||
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS, .key_size = sizeof(uint32_t), .value_size = sizeof(uint32_t), .max_entries = 1};
|
||||
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
|
||||
.key_size = sizeof(uint32_t),
|
||||
.value_size = sizeof(uint32_t),
|
||||
.max_entries = 1,
|
||||
// inner_map_idx refers to the map index in the same ELF object.
|
||||
.inner_map_idx = 1}; // (uint32_t)&inner_map
|
||||
|
||||
SEC("maps")
|
||||
struct bpf_map_def inner_map = {
|
||||
.type = BPF_MAP_TYPE_PROG_ARRAY, .key_size = sizeof(uint32_t), .value_size = sizeof(uint32_t), .max_entries = 1};
|
||||
|
||||
SEC("xdp_prog") int caller(struct xdp_md* ctx)
|
||||
{
|
||||
|
|
|
@ -141,6 +141,7 @@ main(int argc, char** argv)
|
|||
if (verify_programs &&
|
||||
ebpf_api_elf_verify_section_from_memory(
|
||||
data.c_str(), data.size(), section.c_str(), false, &report, &error_message, &stats) != 0) {
|
||||
report = ((report == nullptr) ? "" : report);
|
||||
throw std::runtime_error(
|
||||
std::string("Verification failed for ") + section + std::string(" with error ") +
|
||||
std::string(error_message) + std::string("\n Report:\n") + std::string(report));
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
#include <vector>
|
||||
|
||||
#include "ebpf_api.h"
|
||||
#include "ebpf_nethooks.h"
|
||||
#include "encode_program_info.h"
|
||||
#include "net_ebpf_ext_program_info.h"
|
||||
#include "windows_program_type.h"
|
||||
|
||||
static ebpf_result_t
|
||||
_emit_program_info_file(const char* file_name, const char* symbol_name, uint8_t* buffer, unsigned long buffer_size)
|
||||
|
@ -32,64 +31,39 @@ _emit_program_info_file(const char* file_name, const char* symbol_name, uint8_t*
|
|||
}
|
||||
|
||||
static ebpf_result_t
|
||||
_encode_bind()
|
||||
_encode_program_info(const EbpfProgramType& input_program_type)
|
||||
{
|
||||
ebpf_result_t return_value;
|
||||
std::string file_name = std::string("ebpf_") + input_program_type.name + std::string("_program_data.h");
|
||||
std::string type_name = std::string("_ebpf_encoded_") + input_program_type.name + std::string("_program_info_data");
|
||||
uint8_t* buffer = NULL;
|
||||
unsigned long buffer_size = 0;
|
||||
ebpf_context_descriptor_t bind_context_descriptor = {
|
||||
sizeof(bind_md_t), EBPF_OFFSET_OF(bind_md_t, app_id_start), EBPF_OFFSET_OF(bind_md_t, app_id_end), -1};
|
||||
ebpf_program_type_descriptor_t bind_program_type = {"bind", &bind_context_descriptor, EBPF_PROGRAM_TYPE_BIND};
|
||||
ebpf_program_info_t bind_program_info = {bind_program_type, 0, NULL};
|
||||
|
||||
bind_program_info.count_of_helpers = ebpf_core_helper_functions_count;
|
||||
bind_program_info.helper_prototype = ebpf_core_helper_function_prototype;
|
||||
return_value = ebpf_program_info_encode(&bind_program_info, &buffer, &buffer_size);
|
||||
if (return_value != EBPF_SUCCESS)
|
||||
goto Done;
|
||||
|
||||
return_value = _emit_program_info_file(
|
||||
"ebpf_bind_program_data.h", "_ebpf_encoded_bind_program_info_data", buffer, buffer_size);
|
||||
if (return_value != EBPF_SUCCESS)
|
||||
goto Done;
|
||||
|
||||
return_value = EBPF_SUCCESS;
|
||||
|
||||
Done:
|
||||
ebpf_free(buffer);
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static ebpf_result_t
|
||||
_encode_xdp()
|
||||
{
|
||||
ebpf_result_t return_value;
|
||||
uint8_t* buffer = NULL;
|
||||
unsigned long buffer_size = 0;
|
||||
ebpf_context_descriptor_t xdp_context_descriptor = {
|
||||
sizeof(xdp_md_t),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data_end),
|
||||
EBPF_OFFSET_OF(xdp_md_t, data_meta)};
|
||||
ebpf_program_type_descriptor_t xdp_program_type = {"xdp", &xdp_context_descriptor, EBPF_PROGRAM_TYPE_XDP};
|
||||
ebpf_program_info_t xdp_program_info = {xdp_program_type, 0, NULL};
|
||||
xdp_program_info.count_of_helpers =
|
||||
ebpf_core_helper_functions_count + EBPF_COUNT_OF(_xdp_ebpf_extension_helper_function_prototype);
|
||||
ebpf_context_descriptor_t context_descriptor = *input_program_type.context_descriptor;
|
||||
ebpf_program_type_descriptor_t program_type = {
|
||||
input_program_type.name.c_str(),
|
||||
&context_descriptor,
|
||||
*reinterpret_cast<GUID*>(input_program_type.platform_specific_data)};
|
||||
ebpf_program_info_t program_info = {program_type, 0, NULL};
|
||||
std::vector<ebpf_helper_function_prototype_t> _helper_function_prototypes;
|
||||
_helper_function_prototypes.assign(
|
||||
ebpf_core_helper_function_prototype, ebpf_core_helper_function_prototype + ebpf_core_helper_functions_count);
|
||||
_helper_function_prototypes.insert(
|
||||
_helper_function_prototypes.end(),
|
||||
_xdp_ebpf_extension_helper_function_prototype,
|
||||
_xdp_ebpf_extension_helper_function_prototype + EBPF_COUNT_OF(_xdp_ebpf_extension_helper_function_prototype));
|
||||
xdp_program_info.helper_prototype = _helper_function_prototypes.data();
|
||||
return_value = ebpf_program_info_encode(&xdp_program_info, &buffer, &buffer_size);
|
||||
|
||||
auto program_type_specific = program_type_specific_helper_functions.find(
|
||||
*reinterpret_cast<GUID*>(input_program_type.platform_specific_data));
|
||||
|
||||
if (program_type_specific != program_type_specific_helper_functions.end()) {
|
||||
for (size_t i = 0; i < program_type_specific->second.count; i++) {
|
||||
_helper_function_prototypes.push_back(program_type_specific->second.data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
program_info.count_of_helpers = static_cast<uint32_t>(_helper_function_prototypes.size());
|
||||
program_info.helper_prototype = _helper_function_prototypes.data();
|
||||
return_value = ebpf_program_info_encode(&program_info, &buffer, &buffer_size);
|
||||
if (return_value != EBPF_SUCCESS)
|
||||
goto Done;
|
||||
|
||||
return_value =
|
||||
_emit_program_info_file("ebpf_xdp_program_data.h", "_ebpf_encoded_xdp_program_info_data", buffer, buffer_size);
|
||||
return_value = _emit_program_info_file(file_name.c_str(), type_name.c_str(), buffer, buffer_size);
|
||||
if (return_value != EBPF_SUCCESS)
|
||||
goto Done;
|
||||
|
||||
|
@ -97,14 +71,17 @@ _encode_xdp()
|
|||
|
||||
Done:
|
||||
ebpf_free(buffer);
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
if (_encode_xdp() != EBPF_SUCCESS || _encode_bind() != EBPF_SUCCESS)
|
||||
return 1;
|
||||
for (const auto& program_type : windows_program_types) {
|
||||
if (program_type.platform_specific_data == 0) {
|
||||
continue;
|
||||
}
|
||||
_encode_program_info(program_type);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@
|
|||
<ClCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\api;$(SolutionDir)\netebpfext</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\api;$(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;$(SolutionDir)tests\sample\ext\drv;$(OutDir);$(SolutionDir)libs\thunk;$(SolutionDir)\netebpfext;$(SolutionDir)\libs\api_common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -139,7 +139,7 @@ $(OutputPath)encode_program_info.exe</Command>
|
|||
<ClCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\api;$(SolutionDir)\netebpfext</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\api;$(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;$(SolutionDir)tests\sample\ext\drv;$(OutDir);$(SolutionDir)libs\thunk;$(SolutionDir)\netebpfext;$(SolutionDir)\libs\api_common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -170,7 +170,17 @@ $(OutputPath)encode_program_info.exe</Command>
|
|||
<Project>{18127b0d-8381-4afe-9a3a-cf53241992d3}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\..\packages\boost.1.75.0.0\build\boost.targets" Condition="Exists('..\..\packages\boost.1.75.0.0\build\boost.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\packages\boost.1.75.0.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\boost.1.75.0.0\build\boost.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -23,4 +23,7 @@
|
|||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="boost" version="1.75.0.0" targetFramework="native" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче