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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/iters_num.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
  3 
  4 #include <limits.h>
  5 #include <linux/errno.h>
  6 #include "vmlinux.h"
  7 #include <bpf/bpf_helpers.h>
  8 #include "bpf_misc.h"
  9 
 10 const volatile __s64 exp_empty_zero = 0 + 1;
 11 __s64 res_empty_zero;
 12 
 13 SEC("raw_tp/sys_enter")
 14 int num_empty_zero(const void *ctx)
 15 {
 16         __s64 sum = 0, i;
 17 
 18         bpf_for(i, 0, 0) sum += i;
 19         res_empty_zero = 1 + sum;
 20 
 21         return 0;
 22 }
 23 
 24 const volatile __s64 exp_empty_int_min = 0 + 2;
 25 __s64 res_empty_int_min;
 26 
 27 SEC("raw_tp/sys_enter")
 28 int num_empty_int_min(const void *ctx)
 29 {
 30         __s64 sum = 0, i;
 31 
 32         bpf_for(i, INT_MIN, INT_MIN) sum += i;
 33         res_empty_int_min = 2 + sum;
 34 
 35         return 0;
 36 }
 37 
 38 const volatile __s64 exp_empty_int_max = 0 + 3;
 39 __s64 res_empty_int_max;
 40 
 41 SEC("raw_tp/sys_enter")
 42 int num_empty_int_max(const void *ctx)
 43 {
 44         __s64 sum = 0, i;
 45 
 46         bpf_for(i, INT_MAX, INT_MAX) sum += i;
 47         res_empty_int_max = 3 + sum;
 48 
 49         return 0;
 50 }
 51 
 52 const volatile __s64 exp_empty_minus_one = 0 + 4;
 53 __s64 res_empty_minus_one;
 54 
 55 SEC("raw_tp/sys_enter")
 56 int num_empty_minus_one(const void *ctx)
 57 {
 58         __s64 sum = 0, i;
 59 
 60         bpf_for(i, -1, -1) sum += i;
 61         res_empty_minus_one = 4 + sum;
 62 
 63         return 0;
 64 }
 65 
 66 const volatile __s64 exp_simple_sum = 9 * 10 / 2;
 67 __s64 res_simple_sum;
 68 
 69 SEC("raw_tp/sys_enter")
 70 int num_simple_sum(const void *ctx)
 71 {
 72         __s64 sum = 0, i;
 73 
 74         bpf_for(i, 0, 10) sum += i;
 75         res_simple_sum = sum;
 76 
 77         return 0;
 78 }
 79 
 80 const volatile __s64 exp_neg_sum = -11 * 10 / 2;
 81 __s64 res_neg_sum;
 82 
 83 SEC("raw_tp/sys_enter")
 84 int num_neg_sum(const void *ctx)
 85 {
 86         __s64 sum = 0, i;
 87 
 88         bpf_for(i, -10, 0) sum += i;
 89         res_neg_sum = sum;
 90 
 91         return 0;
 92 }
 93 
 94 const volatile __s64 exp_very_neg_sum = INT_MIN + (__s64)(INT_MIN + 1);
 95 __s64 res_very_neg_sum;
 96 
 97 SEC("raw_tp/sys_enter")
 98 int num_very_neg_sum(const void *ctx)
 99 {
100         __s64 sum = 0, i;
101 
102         bpf_for(i, INT_MIN, INT_MIN + 2) sum += i;
103         res_very_neg_sum = sum;
104 
105         return 0;
106 }
107 
108 const volatile __s64 exp_very_big_sum = (__s64)(INT_MAX - 1) + (__s64)(INT_MAX - 2);
109 __s64 res_very_big_sum;
110 
111 SEC("raw_tp/sys_enter")
112 int num_very_big_sum(const void *ctx)
113 {
114         __s64 sum = 0, i;
115 
116         bpf_for(i, INT_MAX - 2, INT_MAX) sum += i;
117         res_very_big_sum = sum;
118 
119         return 0;
120 }
121 
122 const volatile __s64 exp_neg_pos_sum = -3;
123 __s64 res_neg_pos_sum;
124 
125 SEC("raw_tp/sys_enter")
126 int num_neg_pos_sum(const void *ctx)
127 {
128         __s64 sum = 0, i;
129 
130         bpf_for(i, -3, 3) sum += i;
131         res_neg_pos_sum = sum;
132 
133         return 0;
134 }
135 
136 const volatile __s64 exp_invalid_range = -EINVAL;
137 __s64 res_invalid_range;
138 
139 SEC("raw_tp/sys_enter")
140 int num_invalid_range(const void *ctx)
141 {
142         struct bpf_iter_num it;
143 
144         res_invalid_range = bpf_iter_num_new(&it, 1, 0);
145         bpf_iter_num_destroy(&it);
146 
147         return 0;
148 }
149 
150 const volatile __s64 exp_max_range = 0 + 10;
151 __s64 res_max_range;
152 
153 SEC("raw_tp/sys_enter")
154 int num_max_range(const void *ctx)
155 {
156         struct bpf_iter_num it;
157 
158         res_max_range = 10 + bpf_iter_num_new(&it, 0, BPF_MAX_LOOPS);
159         bpf_iter_num_destroy(&it);
160 
161         return 0;
162 }
163 
164 const volatile __s64 exp_e2big_range = -E2BIG;
165 __s64 res_e2big_range;
166 
167 SEC("raw_tp/sys_enter")
168 int num_e2big_range(const void *ctx)
169 {
170         struct bpf_iter_num it;
171 
172         res_e2big_range = bpf_iter_num_new(&it, -1, BPF_MAX_LOOPS);
173         bpf_iter_num_destroy(&it);
174 
175         return 0;
176 }
177 
178 const volatile __s64 exp_succ_elem_cnt = 10;
179 __s64 res_succ_elem_cnt;
180 
181 SEC("raw_tp/sys_enter")
182 int num_succ_elem_cnt(const void *ctx)
183 {
184         struct bpf_iter_num it;
185         int cnt = 0, *v;
186 
187         bpf_iter_num_new(&it, 0, 10);
188         while ((v = bpf_iter_num_next(&it))) {
189                 cnt++;
190         }
191         bpf_iter_num_destroy(&it);
192 
193         res_succ_elem_cnt = cnt;
194 
195         return 0;
196 }
197 
198 const volatile __s64 exp_overfetched_elem_cnt = 5;
199 __s64 res_overfetched_elem_cnt;
200 
201 SEC("raw_tp/sys_enter")
202 int num_overfetched_elem_cnt(const void *ctx)
203 {
204         struct bpf_iter_num it;
205         int cnt = 0, *v, i;
206 
207         bpf_iter_num_new(&it, 0, 5);
208         for (i = 0; i < 10; i++) {
209                 v = bpf_iter_num_next(&it);
210                 if (v)
211                         cnt++;
212         }
213         bpf_iter_num_destroy(&it);
214 
215         res_overfetched_elem_cnt = cnt;
216 
217         return 0;
218 }
219 
220 const volatile __s64 exp_fail_elem_cnt = 20 + 0;
221 __s64 res_fail_elem_cnt;
222 
223 SEC("raw_tp/sys_enter")
224 int num_fail_elem_cnt(const void *ctx)
225 {
226         struct bpf_iter_num it;
227         int cnt = 0, *v, i;
228 
229         bpf_iter_num_new(&it, 100, 10);
230         for (i = 0; i < 10; i++) {
231                 v = bpf_iter_num_next(&it);
232                 if (v)
233                         cnt++;
234         }
235         bpf_iter_num_destroy(&it);
236 
237         res_fail_elem_cnt = 20 + cnt;
238 
239         return 0;
240 }
241 
242 char _license[] SEC("license") = "GPL";
243 

~ [ 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