|
1 | 1 | # eBPF Ring Buffer Map |
2 | 2 |
|
| 3 | +NOTE: With [#4640](https://github.com/microsoft/ebpf-for-windows/pull/4640) The default behavior has been changed to be linux-compatible. |
| 4 | +- Code expecting asynchonous callbacks should switch to `ebpf_ring_buffer__new` with `EBPF_RINGBUF_FLAG_AUTO_CALLBACK` set in the opts flags. |
| 5 | +- The synchronous API has not been implemented yet, so `ring_buffer__new` will return a not implemented error. |
| 6 | + |
3 | 7 | ebpf-for-windows exposes the [libbpf.h](/include/bpf/libbpf.h) interface for user-mode code. |
4 | 8 |
|
5 | 9 | *More documentation on user-mode API to be added later.* |
@@ -114,22 +118,13 @@ typedef int (*ring_buffer_sample_fn)(_Inout_ void *ctx, _In_reads_bytes_(size) v |
114 | 118 |
|
115 | 119 | struct ring_buffer_opts { |
116 | 120 | size_t sz; /* size of this struct, for forward/backward compatiblity */ |
117 | | - uint64_t flags; /* ring buffer option flags */ |
118 | | -}; |
119 | | -
|
120 | | -// Ring buffer manager options. |
121 | | -// - The default behaviour is currently automatic callbacks, but may change in the future per #4142. |
122 | | -// - Only specify one of AUTO_CALLBACKS or NO_AUTO_CALLBACKS - specifying both is not allowed. |
123 | | -enum ring_buffer_flags { |
124 | | - RINGBUF_FLAG_AUTO_CALLBACK = (uint64_t)1 << 0 /* Automatically invoke callback for each record */ |
125 | | - RINGBUF_FLAG_NO_AUTO_CALLBACK = (uint64_t)2 << 0 /* Don't automatically invoke callback for each record */ |
126 | 121 | }; |
127 | 122 |
|
128 | | -#define ring_buffer_opts__last_field sz |
129 | | -
|
130 | 123 | /** |
131 | 124 | * @brief Creates a new ring buffer manager. |
132 | 125 | * |
| 126 | + * @note This currently returns NULL because the synchronous API is not implemented yet. |
| 127 | + * |
133 | 128 | * Only one consumer can be attached at a time, so it should not be called multiple times on an fd. |
134 | 129 | * |
135 | 130 | * If the return value is NULL the error will be returned in errno. |
@@ -167,6 +162,46 @@ int ring_buffer__poll(_In_ struct ring_buffer *rb, int timeout_ms); |
167 | 162 | * @param[in] rb Pointer to ring buffer manager to be freed. |
168 | 163 | */ |
169 | 164 | void ring_buffer__free(_Frees_ptr_opt_ struct ring_buffer *rb); |
| 165 | +
|
| 166 | +
|
| 167 | +// |
| 168 | +// Windows-specific Ring Buffer APIs |
| 169 | +// |
| 170 | +
|
| 171 | +/** |
| 172 | + * @brief Windows-specific ring buffer options structure. |
| 173 | + * |
| 174 | + * This structure extends ring_buffer_opts with Windows-specific fields. |
| 175 | + * The first field(s) must match ring_buffer_opts exactly for compatibility. |
| 176 | + */ |
| 177 | +struct ebpf_ring_buffer_opts |
| 178 | +{ |
| 179 | + size_t sz; /* Size of this struct, for forward/backward compatibility (must match ring_buffer_opts). */ |
| 180 | + uint64_t flags; /* Windows-specific ring buffer option flags. */ |
| 181 | +}; |
| 182 | +
|
| 183 | +/* Ring buffer option flags. */ |
| 184 | +enum ebpf_ring_buffer_flags |
| 185 | +{ |
| 186 | + EBPF_RINGBUF_FLAG_AUTO_CALLBACK = (uint64_t)1 << 0, /* Automatically invoke callback for each record. */ |
| 187 | +}; |
| 188 | +
|
| 189 | +/** |
| 190 | + * @brief Creates a new ring buffer manager (Windows-specific with flags support). |
| 191 | + * |
| 192 | + * @param[in] map_fd File descriptor to ring buffer map. |
| 193 | + * @param[in] sample_cb Pointer to ring buffer notification callback function. |
| 194 | + * @param[in] ctx Pointer to sample_cb callback function context. |
| 195 | + * @param[in] opts Ring buffer options with flags support. |
| 196 | + * |
| 197 | + * @returns Pointer to ring buffer manager, or NULL on error. |
| 198 | + */ |
| 199 | +_Ret_maybenull_ struct ring_buffer* |
| 200 | +ebpf_ring_buffer__new( |
| 201 | + int map_fd, |
| 202 | + ring_buffer_sample_fn sample_cb, |
| 203 | + _In_opt_ void* ctx, |
| 204 | + _In_opt_ const struct ebpf_ring_buffer_opts* opts) EBPF_NO_EXCEPT; |
170 | 205 | ``` |
171 | 206 |
|
172 | 207 | ### New ebpf APIs for mapped memory consumer |
|
0 commit comments