eBPF for Windows
ebpf_helpers.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation
2 // SPDX-License-Identifier: MIT
3 #pragma once
4 
5 #include <stdint.h>
6 
7 #include "ebpf_structs.h"
8 
9 #define MAX_TAIL_CALL_CNT 32
10 
11 // For eBPF programs, struct bpf_map means struct _ebpf_map_definition_in_file,
12 // since they use inner_map_idx and pass pointers to such structures to the various
13 // map APIs.
14 #define bpf_map _ebpf_map_definition_in_file
15 
16 #ifndef __doxygen
17 #define EBPF_HELPER(return_type, name, args) typedef return_type(*name##_t) args
18 #endif
19 
20 // This file contains APIs for global helpers that are
21 // exposed for use by all eBPF programs.
22 
30 EBPF_HELPER(void*, bpf_map_lookup_elem, (struct bpf_map * map, void* key));
31 #ifndef __doxygen
32 #define bpf_map_lookup_elem ((bpf_map_lookup_elem_t)1)
33 #endif
34 
46 EBPF_HELPER(int64_t, bpf_map_update_elem, (struct bpf_map * map, void* key, void* value, uint64_t flags));
47 #ifndef __doxygen
48 #define bpf_map_update_elem ((bpf_map_update_elem_t)2)
49 #endif
50 
59 EBPF_HELPER(int64_t, bpf_map_delete_elem, (struct bpf_map * map, void* key));
60 #ifndef __doxygen
61 #define bpf_map_delete_elem ((bpf_map_delete_elem_t)3)
62 #endif
63 
73 EBPF_HELPER(int64_t, bpf_tail_call, (void* ctx, struct bpf_map* prog_array_map, uint32_t index));
74 #ifndef __doxygen
75 #define bpf_tail_call ((bpf_tail_call_t)4)
76 #endif
77 
83 EBPF_HELPER(uint32_t, bpf_get_prandom_u32, ());
84 #ifndef __doxygen
85 #define bpf_get_prandom_u32 ((bpf_get_prandom_u32_t)5)
86 #endif
87 
93 EBPF_HELPER(uint64_t, bpf_ktime_get_boot_ns, ());
94 #ifndef __doxygen
95 #define bpf_ktime_get_boot_ns ((bpf_ktime_get_boot_ns_t)6)
96 #endif
97 
103 EBPF_HELPER(uint64_t, bpf_get_smp_processor_id, ());
104 #ifndef __doxygen
105 #define bpf_get_smp_processor_id ((bpf_get_smp_processor_id_t)7)
106 #endif
107 
108 #define SEC(name) __attribute__((section(name), used))
bpf_get_smp_processor_id
uint64_t bpf_get_smp_processor_id()
Return SMP id of the processor running the program.
bpf_tail_call
int64_t bpf_tail_call(void *ctx, struct _ebpf_map_definition_in_file *prog_array_map, uint32_t index)
Perform a tail call into another eBPF program.
bpf_map_delete_elem
int64_t bpf_map_delete_elem(struct _ebpf_map_definition_in_file *map, void *key)
Remove an entry from the map.
bpf_map_lookup_elem
void * bpf_map_lookup_elem(struct _ebpf_map_definition_in_file *map, void *key)
Get a pointer to an entry in the map.
bpf_map_update_elem
int64_t bpf_map_update_elem(struct _ebpf_map_definition_in_file *map, void *key, void *value, uint64_t flags)
Insert or update an entry in the map.
bpf_ktime_get_boot_ns
uint64_t bpf_ktime_get_boot_ns()
Return time elapsed since boot in nanoseconds.
ebpf_structs.h
bpf_map
#define bpf_map
Definition: ebpf_helpers.h:14
bpf_get_prandom_u32
uint32_t bpf_get_prandom_u32()
Get a pseudo-random number.