sample_map_ret0.c 705 B

12345678910111213141516171819202122232425262728293031323334
  1. /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
  2. #include <linux/bpf.h>
  3. #include "bpf_helpers.h"
  4. struct bpf_map_def SEC("maps") htab = {
  5. .type = BPF_MAP_TYPE_HASH,
  6. .key_size = sizeof(__u32),
  7. .value_size = sizeof(long),
  8. .max_entries = 2,
  9. };
  10. struct bpf_map_def SEC("maps") array = {
  11. .type = BPF_MAP_TYPE_ARRAY,
  12. .key_size = sizeof(__u32),
  13. .value_size = sizeof(long),
  14. .max_entries = 2,
  15. };
  16. /* Sample program which should always load for testing control paths. */
  17. SEC(".text") int func()
  18. {
  19. __u64 key64 = 0;
  20. __u32 key = 0;
  21. long *value;
  22. value = bpf_map_lookup_elem(&htab, &key);
  23. if (!value)
  24. return 1;
  25. value = bpf_map_lookup_elem(&array, &key64);
  26. if (!value)
  27. return 1;
  28. return 0;
  29. }