~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/global_data_init.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <test_progs.h>
  3 
  4 void test_global_data_init(void)
  5 {
  6         const char *file = "./test_global_data.bpf.o";
  7         int err = -ENOMEM, map_fd, zero = 0;
  8         __u8 *buff = NULL, *newval = NULL;
  9         struct bpf_object *obj;
 10         struct bpf_map *map;
 11         __u32 duration = 0;
 12         size_t sz;
 13 
 14         obj = bpf_object__open_file(file, NULL);
 15         err = libbpf_get_error(obj);
 16         if (CHECK_FAIL(err))
 17                 return;
 18 
 19         map = bpf_object__find_map_by_name(obj, ".rodata");
 20         if (CHECK_FAIL(!map || !bpf_map__is_internal(map)))
 21                 goto out;
 22 
 23         sz = bpf_map__value_size(map);
 24         newval = malloc(sz);
 25         if (CHECK_FAIL(!newval))
 26                 goto out;
 27 
 28         memset(newval, 0, sz);
 29         /* wrong size, should fail */
 30         err = bpf_map__set_initial_value(map, newval, sz - 1);
 31         if (CHECK(!err, "reject set initial value wrong size", "err %d\n", err))
 32                 goto out;
 33 
 34         err = bpf_map__set_initial_value(map, newval, sz);
 35         if (CHECK(err, "set initial value", "err %d\n", err))
 36                 goto out;
 37 
 38         err = bpf_object__load(obj);
 39         if (CHECK_FAIL(err))
 40                 goto out;
 41 
 42         map_fd = bpf_map__fd(map);
 43         if (CHECK_FAIL(map_fd < 0))
 44                 goto out;
 45 
 46         buff = malloc(sz);
 47         if (buff)
 48                 err = bpf_map_lookup_elem(map_fd, &zero, buff);
 49         if (CHECK(!buff || err || memcmp(buff, newval, sz),
 50                   "compare .rodata map data override",
 51                   "err %d errno %d\n", err, errno))
 52                 goto out;
 53 
 54         memset(newval, 1, sz);
 55         /* object loaded - should fail */
 56         err = bpf_map__set_initial_value(map, newval, sz);
 57         CHECK(!err, "reject set initial value after load", "err %d\n", err);
 58 out:
 59         free(buff);
 60         free(newval);
 61         bpf_object__close(obj);
 62 }
 63 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php