Skip to content

Commit 9ec78ad

Browse files
Andreagit97FedeDP
authored andcommitted
new(libsinsp,libscap): add a new generable event API
Signed-off-by: Andrea Terzolo <[email protected]>
1 parent 18e4fd8 commit 9ec78ad

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

userspace/libscap/scap.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,23 @@ int scap_get_events_from_ppm_sc(IN uint32_t ppm_sc_array[PPM_SC_MAX], OUT uint32
12461246
return SCAP_SUCCESS;
12471247
}
12481248

1249+
bool scap_is_generable_event(uint16_t event_type)
1250+
{
1251+
ASSERT(event_type < PPM_EVENT_MAX);
1252+
1253+
#ifdef __linux__
1254+
for(int syscall_nr = 0; syscall_nr < SYSCALL_TABLE_SIZE; syscall_nr++)
1255+
{
1256+
struct syscall_evt_pair pair = g_syscall_table[syscall_nr];
1257+
if(pair.enter_event_type == event_type || pair.exit_event_type == event_type)
1258+
{
1259+
return true;
1260+
}
1261+
}
1262+
#endif
1263+
return false;
1264+
}
1265+
12491266
int scap_get_modifies_state_tracepoints(OUT uint32_t tp_array[TP_VAL_MAX])
12501267
{
12511268
if(tp_array == NULL)

userspace/libscap/scap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,11 @@ int scap_get_modifies_state_ppm_sc(OUT uint32_t ppm_sc_array[PPM_SC_MAX]);
848848
*/
849849
int scap_get_events_from_ppm_sc(IN uint32_t ppm_sc_array[PPM_SC_MAX], OUT uint32_t events_array[PPM_EVENT_MAX]);
850850

851+
/*!
852+
\brief Return true if the event is generable by the live system instrumentation.
853+
*/
854+
bool scap_is_generable_event(uint16_t event_type);
855+
851856
/*!
852857
\brief Returns the set of minimum tracepoints required by `libsinsp` state.
853858
*/

userspace/libsinsp/sinsp.h

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -963,71 +963,77 @@ class SINSP_PUBLIC sinsp : public capture_stats_source, public wmi_handle_source
963963
* - `EF_SKIPPARSERESET`
964964
* - `EF_UNUSED`
965965
*
966-
* @param event_type type of event we want to check
966+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
967967
* @return true if the event type has at least one of these flags.
968968
*/
969969
static inline bool is_unused_event(uint16_t event_type)
970970
{
971+
ASSERT(event_type < PPM_EVENT_MAX);
971972
enum ppm_event_flags flags = g_infotables.m_event_info[event_type].flags;
972973
return (flags & (EF_SKIPPARSERESET | EF_UNUSED));
973974
}
974975

975976
/**
976977
* @brief Return true if the event has the `EF_OLD_VERSION` flag
977978
*
978-
* @param event_type type of event we want to check
979+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
979980
* @return true if the event type has the `EF_OLD_VERSION` flag.
980981
*/
981982
static inline bool is_old_version_event(uint16_t event_type)
982983
{
984+
ASSERT(event_type < PPM_EVENT_MAX);
983985
enum ppm_event_flags flags = g_infotables.m_event_info[event_type].flags;
984986
return (flags & EF_OLD_VERSION);
985987
}
986988

987989
/**
988990
* @brief Return true if the event belongs to the `EC_SYSCALL` category
989991
*
990-
* @param event_type type of event we want to check
992+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
991993
* @return true if the event type has the `EC_SYSCALL` category.
992994
*/
993995
static inline bool is_syscall_event(uint16_t event_type)
994996
{
997+
ASSERT(event_type < PPM_EVENT_MAX);
995998
enum ppm_event_category category = g_infotables.m_event_info[event_type].category;
996999
return (category & EC_SYSCALL);
9971000
}
9981001

9991002
/**
10001003
* @brief Return true if the event belongs to the `EC_TRACEPOINT` category
10011004
*
1002-
* @param event_type type of event we want to check
1005+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
10031006
* @return true if the event type has the `EC_TRACEPOINT` category.
10041007
*/
10051008
static inline bool is_tracepoint_event(uint16_t event_type)
10061009
{
1010+
ASSERT(event_type < PPM_EVENT_MAX);
10071011
enum ppm_event_category category = g_infotables.m_event_info[event_type].category;
10081012
return (category & EC_TRACEPOINT);
10091013
}
10101014

10111015
/**
10121016
* @brief Return true if the event belongs to the `EC_METAEVENT` category
10131017
*
1014-
* @param event_type type of event we want to check
1018+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
10151019
* @return true if the event type has the `EC_METAEVENT` category.
10161020
*/
10171021
static inline bool is_metaevent(uint16_t event_type)
10181022
{
1023+
ASSERT(event_type < PPM_EVENT_MAX);
10191024
enum ppm_event_category category = g_infotables.m_event_info[event_type].category;
10201025
return (category & EC_METAEVENT);
10211026
}
10221027

10231028
/**
10241029
* @brief Return true if the event belongs to the `EC_UNKNOWN` category
10251030
*
1026-
* @param event_type type of event we want to check
1031+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
10271032
* @return true if the event type has the `EC_UNKNOWN` category.
10281033
*/
10291034
static inline bool is_unknown_event(uint16_t event_type)
10301035
{
1036+
ASSERT(event_type < PPM_EVENT_MAX);
10311037
enum ppm_event_category category = g_infotables.m_event_info[event_type].category;
10321038
/* Please note this is not an `&` but an `==` if one event has
10331039
* the `EC_UNKNOWN` category, it must have only this category!
@@ -1038,15 +1044,28 @@ class SINSP_PUBLIC sinsp : public capture_stats_source, public wmi_handle_source
10381044
/**
10391045
* @brief Return true if the event belongs to the `EC_PLUGIN` category
10401046
*
1041-
* @param event_type type of event we want to check
1047+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
10421048
* @return true if the event type has the `EC_PLUGIN` category.
10431049
*/
10441050
static inline bool is_plugin_event(uint16_t event_type)
10451051
{
1052+
ASSERT(event_type < PPM_EVENT_MAX);
10461053
enum ppm_event_category category = g_infotables.m_event_info[event_type].category;
10471054
return (category & EC_PLUGIN);
10481055
}
10491056

1057+
/**
1058+
* @brief Return true if the event is generable by the live system instrumentation.
1059+
*
1060+
* @param event_type type of event we want to check (must be less than `PPM_EVENT_MAX`)
1061+
* @return true if the event is generable by the live system.
1062+
*/
1063+
static inline bool is_generable_event(uint16_t event_type)
1064+
{
1065+
ASSERT(event_type < PPM_EVENT_MAX);
1066+
return scap_is_generable_event(event_type);
1067+
}
1068+
10501069
/*=============================== Events related ===============================*/
10511070

10521071
bool setup_cycle_writer(std::string base_file_name, int rollover_mb, int duration_seconds, int file_limit, unsigned long event_limit, bool compress);

0 commit comments

Comments
 (0)