ebpf-for-windows/include/bpf2c.h

107 строки
2.4 KiB
C
Исходник Обычный вид История

// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT
#pragma once
#if defined(NO_CRT)
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#define bool _Bool
#define false 0
#define true 1
#define UINT32_MAX ((uint32_t)0xFFFFFFFF)
#else
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#endif
#include "ebpf_structs.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define UBPF_STACK_SIZE 512
#define IMMEDIATE(X) (int32_t) X
#define OFFSET(X) (int16_t) X
#define POINTER(X) (uint64_t)(X)
#if !defined(htobe16)
#define htobe16(X) swap16(X)
#define htobe32(X) swap32(X)
#define htobe64(X) swap64(X)
#define htole16(X) (X)
#define htole32(X) (X)
#define htole64(X) (X)
#endif
typedef struct _helper_function_entry
{
uint64_t (*address)(uint64_t r1, uint64_t r2, uint64_t r3, uint64_t r4, uint64_t r5);
uint32_t helper_id;
const char* name;
bool tail_call;
} helper_function_entry_t;
typedef struct _map_entry
{
void* address;
ebpf_map_definition_in_file_t definition;
const char* name;
} map_entry_t;
typedef struct _program_entry
{
uint64_t (*function)(void*);
const char* section_name;
EC and API changes to load generated BPF driver (#811) * initial_commit * fix build * fix build * fix build break due to merge * debug build * api changes, other changes * bpf2c change to enmit program type, other fixes * hydrate UM ebpf_object, other fixes * remove logic to disable programs * fixes * fix sal * build break * build break * fix sal errors * fixes * fix bpf2c_tests failure * unload driver when program ref count becomes 0, other minor fixes * fixes * tail_call fixes, add test cases, other fixes * build break * build break * code cleanup * fix bad merge * code cleanup * code cleanup * cleanup * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * address cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * add tracing in ebpfcore, other fixes * tracing * add section for each map in sample * do not delete the native service * fix bad merge * remove code to delete service, other fixes * cr comments * bpf2c should read and populate all the maps in ELF file * add test case for creating map-in-map from native driver * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * add tracing for api code changes * rename epbf_native_t to ebpf_native_module_t * fix bad merge Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-04-01 22:52:04 +03:00
const char* program_name;
uint16_t* referenced_map_indices;
uint16_t referenced_map_count;
helper_function_entry_t* helpers;
uint16_t helper_count;
size_t bpf_instruction_count;
EC and API changes to load generated BPF driver (#811) * initial_commit * fix build * fix build * fix build break due to merge * debug build * api changes, other changes * bpf2c change to enmit program type, other fixes * hydrate UM ebpf_object, other fixes * remove logic to disable programs * fixes * fix sal * build break * build break * fix sal errors * fixes * fix bpf2c_tests failure * unload driver when program ref count becomes 0, other minor fixes * fixes * tail_call fixes, add test cases, other fixes * build break * build break * code cleanup * fix bad merge * code cleanup * code cleanup * cleanup * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * address cr comments * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * add tracing in ebpfcore, other fixes * tracing * add section for each map in sample * do not delete the native service * fix bad merge * remove code to delete service, other fixes * cr comments * bpf2c should read and populate all the maps in ELF file * add test case for creating map-in-map from native driver * Apply suggestions from code review Co-authored-by: Dave Thaler <dthaler@microsoft.com> * cr comments * add tracing for api code changes * rename epbf_native_t to ebpf_native_module_t * fix bad merge Co-authored-by: Dave Thaler <dthaler@microsoft.com>
2022-04-01 22:52:04 +03:00
ebpf_program_type_t* program_type;
ebpf_attach_type_t* expected_attach_type;
} program_entry_t;
typedef struct _metadata_table
{
void (*programs)(program_entry_t** programs, size_t* count);
void (*maps)(map_entry_t** maps, size_t* count);
} metadata_table_t;
inline uint16_t
swap16(uint16_t value)
{
return value << 8 | value >> 8;
}
inline uint32_t
swap32(uint32_t value)
{
return swap16(value >> 16) | ((uint32_t)swap16(value & ((1 << 16) - 1))) << 16;
}
inline uint64_t
swap64(uint64_t value)
{
return swap32(value >> 32) | ((uint64_t)swap32(value & ((1ull << 32ull) - 1))) << 32;
}
void
division_by_zero(uint32_t address);
#ifdef __cplusplus
}
#endif