2021-06-10 22:02:00 +03:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
// SPDX-License-Identifier: MIT
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ebpf_platform.h"
|
2021-04-26 22:16:20 +03:00
|
|
|
#include "framework.h"
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum _ebpf_object_type
|
|
|
|
{
|
2021-04-30 21:49:23 +03:00
|
|
|
EBPF_OBJECT_UNKNOWN,
|
2021-04-23 19:21:12 +03:00
|
|
|
EBPF_OBJECT_MAP,
|
2021-04-27 02:17:44 +03:00
|
|
|
EBPF_OBJECT_LINK,
|
2021-04-23 19:21:12 +03:00
|
|
|
EBPF_OBJECT_PROGRAM,
|
|
|
|
} ebpf_object_type_t;
|
|
|
|
|
|
|
|
typedef struct _ebpf_object ebpf_object_t;
|
2021-04-30 22:55:21 +03:00
|
|
|
typedef void (*ebpf_free_object_t)(ebpf_object_t* object);
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
typedef struct _ebpf_object
|
|
|
|
{
|
|
|
|
uint32_t marker;
|
|
|
|
volatile int32_t reference_count;
|
|
|
|
ebpf_object_type_t type;
|
2021-04-30 22:55:21 +03:00
|
|
|
ebpf_free_object_t free_function;
|
|
|
|
ebpf_list_entry_t entry;
|
2021-04-23 19:21:12 +03:00
|
|
|
} ebpf_object_t;
|
|
|
|
|
2021-04-30 22:55:21 +03:00
|
|
|
/**
|
|
|
|
* @brief Initiate object tracking.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_tracking_initiate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Terminate object tracking.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_tracking_terminate();
|
|
|
|
|
2021-04-23 19:21:12 +03:00
|
|
|
/**
|
|
|
|
* @brief Initialize an ebpf_object_t structure.
|
|
|
|
*
|
|
|
|
* @param[in,out] object ebpf_object_t structure to initialize.
|
|
|
|
* @param[in] object_type The type of the object.
|
|
|
|
* @param[in] free_function The function used to free the object.
|
|
|
|
*/
|
|
|
|
void
|
2021-04-30 22:55:21 +03:00
|
|
|
ebpf_object_initialize(ebpf_object_t* object, ebpf_object_type_t object_type, ebpf_free_object_t free_function);
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Acquire a reference to this object.
|
|
|
|
*
|
|
|
|
* @param[in] object Object on which to acquire a reference.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_acquire_reference(ebpf_object_t* object);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Release a reference on this object. If the reference count reaches
|
|
|
|
* zero, the free_function is invoked on the object.
|
|
|
|
*
|
|
|
|
* @param[in] object Object on which to release a reference.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_release_reference(ebpf_object_t* object);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query the stored type of the object.
|
|
|
|
*
|
|
|
|
* @param[in] object Object to be queried.
|
|
|
|
* @return Type of the object.
|
|
|
|
*/
|
|
|
|
ebpf_object_type_t
|
|
|
|
ebpf_object_get_type(ebpf_object_t* object);
|
|
|
|
|
2021-04-30 22:55:21 +03:00
|
|
|
/**
|
|
|
|
* @brief Find the next object that is of this type and acquire reference
|
|
|
|
* on it.
|
|
|
|
*
|
|
|
|
* @param[in] previous_object Previous object that was found. Can be NULL
|
|
|
|
* to find first object.
|
|
|
|
* @param[in] type Type of object to find.
|
|
|
|
* @param[out] next_object Pointer to memory containing the next object or
|
|
|
|
* NULL if there are no more objects of that type.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_reference_next_object(
|
|
|
|
ebpf_object_t* previous_object, ebpf_object_type_t type, ebpf_object_t** next_object);
|
|
|
|
|
2021-04-23 19:21:12 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|