Closed jasondellaluce closed 1 year ago
cc @falcosecurity/core-maintainers, @falcosecurity/plugin-sdk-cpp-maintainers
What's everyone's feeling?
Big +1 for example if we want to follow through with approaches like https://github.com/falcosecurity/falco/pull/2655 and expose more sophisticated functionality over the plugins framework we urgently need this. Exposing syscalls hot path to plugins at least for me just marks the beginning.
+1 from me! Also, big thank you for doing this @jasondellaluce , our Plugins Master!
big +1 from me! :heart_eyes:
Motivation
The current SDK C++ is faulty and not usable for a variety of reasons, both in its current mantainance state and its design as a whole. As a primer, the SDK is not up to date with the latest plugin API version 3.0.0, thus producing plugins that are not loadable by the latest Falco. Second, the design relies on virtual inheritance interfaces, which bring the following concerns (just to name a few):
Proposal
I worked on re-implementing the SDK from scratch with a whole new design based on mixins, implicit interfaces based on type traits, RAII, and intensive function inlining. Although I hate to re-propose a design for the third time, I think these changes would be worth the effort. Plus, the current SDK is non usable, had no traction in the community, and is still a sandbox-level project in our organization, meaning that we consider it still in its early stages of development.
The progress of the big refactor can be checked on a branch of my fork: https://github.com/jasondellaluce/plugin-sdk-cpp/tree/refactor/performance-design-2 I invite anyone interested to take a look, as that will heavily help on understanding the technical approach.
Apprach
Goals
extern "C"
symbol manuallyGoal 1,2
Defining a plugin will look like:
As visible, no
virtual
function oroverride
marker is present. The SDK makes the heavy lift of figuring out if the type complies with the expected traits or not.Goal 3
Users should not deal with the complexity of the C API and the event definitions of falcosecurity/libs. For example, here's how an event can be produced for the event sourcing capability:
Goal 4
If a type trait is not respected, and a function is either missing or has the wrong signature, the compiler is capable of detecting it through the static assertions of the SDK and will provide errors such as:
Note how the SDK prompts an error and suggests the right/missing function signature :
error: static assertion failed: expected signature: std::string get_name()
Goal 5
The new design makes use of widespread inlining wherever possible, and some hacks involing templates and macros to avoid any performance penalty.
For example, we want the following two examples to produce almost the same assembly output, to prove that the SDK adds no extra overhead:
Without the SDK
With the SDK
Compilation output with the SDK (x86_64)
As visible, no virtual function call is involved and the function is as minimal as it gets, thus confirming that the compiler is capable of squashing most of the SDK abstractions. Of course, with more complex function symbols extra SDK work will be required, but this gives the idea.