-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alan Jowett <[email protected]>
- Loading branch information
Alan Jowett
committed
Nov 21, 2024
1 parent
b742962
commit e46f1b4
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) eBPF for Windows contributors | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Whenever this sample program changes, bpf2c_tests will fail unless the | ||
// expected files in tests\bpf2c_tests\expected are updated. The following | ||
// script can be used to regenerate the expected files: | ||
// generate_expected_bpf2c_output.ps1 | ||
// | ||
// Usage: | ||
// .\scripts\generate_expected_bpf2c_output.ps1 <build_output_path> | ||
// Example: | ||
// .\scripts\generate_expected_bpf2c_output.ps1 .\x64\Debug\ | ||
#include "bpf_helpers.h" | ||
#include "sample_ext_helpers.h" | ||
|
||
struct | ||
{ | ||
__uint(type, BPF_MAP_TYPE_RINGBUF); | ||
__uint(max_entries, 64 * 1024); | ||
} inner_map SEC(".maps"); | ||
|
||
struct | ||
{ | ||
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); | ||
__type(key, uint32_t); | ||
__type(value, uint32_t); | ||
__uint(max_entries, 1); | ||
__array(values, inner_map); | ||
} outer_map SEC(".maps"); | ||
|
||
SEC("sample_ext") int lookup(sample_program_context_t* ctx) | ||
{ | ||
uint8_t sample[] = "Hello, world!"; | ||
// Publish sample to per-cpu ringbuf | ||
uint32_t key = bpf_get_smp_processor_id(); | ||
struct bpf_map* map = bpf_map_lookup_elem(&outer_map, &key); | ||
if (map) { | ||
(void)bpf_ringbuf_output(map, sample, sizeof(sample), 0); | ||
} | ||
|
||
return 0; | ||
} |