1 // SPDX-License-Identifier: GPL-2.0
2
3 #include <linux/bpf.h>
4 #include <limits.h>
5 #include <bpf/bpf_helpers.h>
6 #include "bpf_misc.h"
7
8 #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
9 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \
10 defined(__TARGET_ARCH_arm) || defined(__TARGET_ARCH_s390) || \
11 defined(__TARGET_ARCH_loongarch)) && \
12 __clang_major__ >= 18
13
14 SEC("socket")
15 __description("SDIV32, non-zero imm divisor, check 1")
16 __success __success_unpriv __retval(-20)
sdiv32_non_zero_imm_1(void)17 __naked void sdiv32_non_zero_imm_1(void)
18 {
19 asm volatile (" \
20 w0 = -41; \
21 w0 s/= 2; \
22 exit; \
23 " ::: __clobber_all);
24 }
25
26 SEC("socket")
27 __description("SDIV32, non-zero imm divisor, check 2")
28 __success __success_unpriv __retval(-20)
sdiv32_non_zero_imm_2(void)29 __naked void sdiv32_non_zero_imm_2(void)
30 {
31 asm volatile (" \
32 w0 = 41; \
33 w0 s/= -2; \
34 exit; \
35 " ::: __clobber_all);
36 }
37
38 SEC("socket")
39 __description("SDIV32, non-zero imm divisor, check 3")
40 __success __success_unpriv __retval(20)
sdiv32_non_zero_imm_3(void)41 __naked void sdiv32_non_zero_imm_3(void)
42 {
43 asm volatile (" \
44 w0 = -41; \
45 w0 s/= -2; \
46 exit; \
47 " ::: __clobber_all);
48 }
49
50 SEC("socket")
51 __description("SDIV32, non-zero imm divisor, check 4")
52 __success __success_unpriv __retval(-21)
sdiv32_non_zero_imm_4(void)53 __naked void sdiv32_non_zero_imm_4(void)
54 {
55 asm volatile (" \
56 w0 = -42; \
57 w0 s/= 2; \
58 exit; \
59 " ::: __clobber_all);
60 }
61
62 SEC("socket")
63 __description("SDIV32, non-zero imm divisor, check 5")
64 __success __success_unpriv __retval(-21)
sdiv32_non_zero_imm_5(void)65 __naked void sdiv32_non_zero_imm_5(void)
66 {
67 asm volatile (" \
68 w0 = 42; \
69 w0 s/= -2; \
70 exit; \
71 " ::: __clobber_all);
72 }
73
74 SEC("socket")
75 __description("SDIV32, non-zero imm divisor, check 6")
76 __success __success_unpriv __retval(21)
sdiv32_non_zero_imm_6(void)77 __naked void sdiv32_non_zero_imm_6(void)
78 {
79 asm volatile (" \
80 w0 = -42; \
81 w0 s/= -2; \
82 exit; \
83 " ::: __clobber_all);
84 }
85
86 SEC("socket")
87 __description("SDIV32, non-zero imm divisor, check 7")
88 __success __success_unpriv __retval(21)
sdiv32_non_zero_imm_7(void)89 __naked void sdiv32_non_zero_imm_7(void)
90 {
91 asm volatile (" \
92 w0 = 42; \
93 w0 s/= 2; \
94 exit; \
95 " ::: __clobber_all);
96 }
97
98 SEC("socket")
99 __description("SDIV32, non-zero imm divisor, check 8")
100 __success __success_unpriv __retval(20)
sdiv32_non_zero_imm_8(void)101 __naked void sdiv32_non_zero_imm_8(void)
102 {
103 asm volatile (" \
104 w0 = 41; \
105 w0 s/= 2; \
106 exit; \
107 " ::: __clobber_all);
108 }
109
110 SEC("socket")
111 __description("SDIV32, non-zero reg divisor, check 1")
112 __success __success_unpriv __retval(-20)
sdiv32_non_zero_reg_1(void)113 __naked void sdiv32_non_zero_reg_1(void)
114 {
115 asm volatile (" \
116 w0 = -41; \
117 w1 = 2; \
118 w0 s/= w1; \
119 exit; \
120 " ::: __clobber_all);
121 }
122
123 SEC("socket")
124 __description("SDIV32, non-zero reg divisor, check 2")
125 __success __success_unpriv __retval(-20)
sdiv32_non_zero_reg_2(void)126 __naked void sdiv32_non_zero_reg_2(void)
127 {
128 asm volatile (" \
129 w0 = 41; \
130 w1 = -2; \
131 w0 s/= w1; \
132 exit; \
133 " ::: __clobber_all);
134 }
135
136 SEC("socket")
137 __description("SDIV32, non-zero reg divisor, check 3")
138 __success __success_unpriv __retval(20)
sdiv32_non_zero_reg_3(void)139 __naked void sdiv32_non_zero_reg_3(void)
140 {
141 asm volatile (" \
142 w0 = -41; \
143 w1 = -2; \
144 w0 s/= w1; \
145 exit; \
146 " ::: __clobber_all);
147 }
148
149 SEC("socket")
150 __description("SDIV32, non-zero reg divisor, check 4")
151 __success __success_unpriv __retval(-21)
sdiv32_non_zero_reg_4(void)152 __naked void sdiv32_non_zero_reg_4(void)
153 {
154 asm volatile (" \
155 w0 = -42; \
156 w1 = 2; \
157 w0 s/= w1; \
158 exit; \
159 " ::: __clobber_all);
160 }
161
162 SEC("socket")
163 __description("SDIV32, non-zero reg divisor, check 5")
164 __success __success_unpriv __retval(-21)
sdiv32_non_zero_reg_5(void)165 __naked void sdiv32_non_zero_reg_5(void)
166 {
167 asm volatile (" \
168 w0 = 42; \
169 w1 = -2; \
170 w0 s/= w1; \
171 exit; \
172 " ::: __clobber_all);
173 }
174
175 SEC("socket")
176 __description("SDIV32, non-zero reg divisor, check 6")
177 __success __success_unpriv __retval(21)
sdiv32_non_zero_reg_6(void)178 __naked void sdiv32_non_zero_reg_6(void)
179 {
180 asm volatile (" \
181 w0 = -42; \
182 w1 = -2; \
183 w0 s/= w1; \
184 exit; \
185 " ::: __clobber_all);
186 }
187
188 SEC("socket")
189 __description("SDIV32, non-zero reg divisor, check 7")
190 __success __success_unpriv __retval(21)
sdiv32_non_zero_reg_7(void)191 __naked void sdiv32_non_zero_reg_7(void)
192 {
193 asm volatile (" \
194 w0 = 42; \
195 w1 = 2; \
196 w0 s/= w1; \
197 exit; \
198 " ::: __clobber_all);
199 }
200
201 SEC("socket")
202 __description("SDIV32, non-zero reg divisor, check 8")
203 __success __success_unpriv __retval(20)
sdiv32_non_zero_reg_8(void)204 __naked void sdiv32_non_zero_reg_8(void)
205 {
206 asm volatile (" \
207 w0 = 41; \
208 w1 = 2; \
209 w0 s/= w1; \
210 exit; \
211 " ::: __clobber_all);
212 }
213
214 SEC("socket")
215 __description("SDIV64, non-zero imm divisor, check 1")
216 __success __success_unpriv __retval(-20)
sdiv64_non_zero_imm_1(void)217 __naked void sdiv64_non_zero_imm_1(void)
218 {
219 asm volatile (" \
220 r0 = -41; \
221 r0 s/= 2; \
222 exit; \
223 " ::: __clobber_all);
224 }
225
226 SEC("socket")
227 __description("SDIV64, non-zero imm divisor, check 2")
228 __success __success_unpriv __retval(-20)
sdiv64_non_zero_imm_2(void)229 __naked void sdiv64_non_zero_imm_2(void)
230 {
231 asm volatile (" \
232 r0 = 41; \
233 r0 s/= -2; \
234 exit; \
235 " ::: __clobber_all);
236 }
237
238 SEC("socket")
239 __description("SDIV64, non-zero imm divisor, check 3")
240 __success __success_unpriv __retval(20)
sdiv64_non_zero_imm_3(void)241 __naked void sdiv64_non_zero_imm_3(void)
242 {
243 asm volatile (" \
244 r0 = -41; \
245 r0 s/= -2; \
246 exit; \
247 " ::: __clobber_all);
248 }
249
250 SEC("socket")
251 __description("SDIV64, non-zero imm divisor, check 4")
252 __success __success_unpriv __retval(-21)
sdiv64_non_zero_imm_4(void)253 __naked void sdiv64_non_zero_imm_4(void)
254 {
255 asm volatile (" \
256 r0 = -42; \
257 r0 s/= 2; \
258 exit; \
259 " ::: __clobber_all);
260 }
261
262 SEC("socket")
263 __description("SDIV64, non-zero imm divisor, check 5")
264 __success __success_unpriv __retval(-21)
sdiv64_non_zero_imm_5(void)265 __naked void sdiv64_non_zero_imm_5(void)
266 {
267 asm volatile (" \
268 r0 = 42; \
269 r0 s/= -2; \
270 exit; \
271 " ::: __clobber_all);
272 }
273
274 SEC("socket")
275 __description("SDIV64, non-zero imm divisor, check 6")
276 __success __success_unpriv __retval(21)
sdiv64_non_zero_imm_6(void)277 __naked void sdiv64_non_zero_imm_6(void)
278 {
279 asm volatile (" \
280 r0 = -42; \
281 r0 s/= -2; \
282 exit; \
283 " ::: __clobber_all);
284 }
285
286 SEC("socket")
287 __description("SDIV64, non-zero reg divisor, check 1")
288 __success __success_unpriv __retval(-20)
sdiv64_non_zero_reg_1(void)289 __naked void sdiv64_non_zero_reg_1(void)
290 {
291 asm volatile (" \
292 r0 = -41; \
293 r1 = 2; \
294 r0 s/= r1; \
295 exit; \
296 " ::: __clobber_all);
297 }
298
299 SEC("socket")
300 __description("SDIV64, non-zero reg divisor, check 2")
301 __success __success_unpriv __retval(-20)
sdiv64_non_zero_reg_2(void)302 __naked void sdiv64_non_zero_reg_2(void)
303 {
304 asm volatile (" \
305 r0 = 41; \
306 r1 = -2; \
307 r0 s/= r1; \
308 exit; \
309 " ::: __clobber_all);
310 }
311
312 SEC("socket")
313 __description("SDIV64, non-zero reg divisor, check 3")
314 __success __success_unpriv __retval(20)
sdiv64_non_zero_reg_3(void)315 __naked void sdiv64_non_zero_reg_3(void)
316 {
317 asm volatile (" \
318 r0 = -41; \
319 r1 = -2; \
320 r0 s/= r1; \
321 exit; \
322 " ::: __clobber_all);
323 }
324
325 SEC("socket")
326 __description("SDIV64, non-zero reg divisor, check 4")
327 __success __success_unpriv __retval(-21)
sdiv64_non_zero_reg_4(void)328 __naked void sdiv64_non_zero_reg_4(void)
329 {
330 asm volatile (" \
331 r0 = -42; \
332 r1 = 2; \
333 r0 s/= r1; \
334 exit; \
335 " ::: __clobber_all);
336 }
337
338 SEC("socket")
339 __description("SDIV64, non-zero reg divisor, check 5")
340 __success __success_unpriv __retval(-21)
sdiv64_non_zero_reg_5(void)341 __naked void sdiv64_non_zero_reg_5(void)
342 {
343 asm volatile (" \
344 r0 = 42; \
345 r1 = -2; \
346 r0 s/= r1; \
347 exit; \
348 " ::: __clobber_all);
349 }
350
351 SEC("socket")
352 __description("SDIV64, non-zero reg divisor, check 6")
353 __success __success_unpriv __retval(21)
sdiv64_non_zero_reg_6(void)354 __naked void sdiv64_non_zero_reg_6(void)
355 {
356 asm volatile (" \
357 r0 = -42; \
358 r1 = -2; \
359 r0 s/= r1; \
360 exit; \
361 " ::: __clobber_all);
362 }
363
364 SEC("socket")
365 __description("SMOD32, non-zero imm divisor, check 1")
366 __success __success_unpriv __retval(-1)
smod32_non_zero_imm_1(void)367 __naked void smod32_non_zero_imm_1(void)
368 {
369 asm volatile (" \
370 w0 = -41; \
371 w0 s%%= 2; \
372 exit; \
373 " ::: __clobber_all);
374 }
375
376 SEC("socket")
377 __description("SMOD32, non-zero imm divisor, check 2")
378 __success __success_unpriv __retval(1)
smod32_non_zero_imm_2(void)379 __naked void smod32_non_zero_imm_2(void)
380 {
381 asm volatile (" \
382 w0 = 41; \
383 w0 s%%= -2; \
384 exit; \
385 " ::: __clobber_all);
386 }
387
388 SEC("socket")
389 __description("SMOD32, non-zero imm divisor, check 3")
390 __success __success_unpriv __retval(-1)
smod32_non_zero_imm_3(void)391 __naked void smod32_non_zero_imm_3(void)
392 {
393 asm volatile (" \
394 w0 = -41; \
395 w0 s%%= -2; \
396 exit; \
397 " ::: __clobber_all);
398 }
399
400 SEC("socket")
401 __description("SMOD32, non-zero imm divisor, check 4")
402 __success __success_unpriv __retval(0)
smod32_non_zero_imm_4(void)403 __naked void smod32_non_zero_imm_4(void)
404 {
405 asm volatile (" \
406 w0 = -42; \
407 w0 s%%= 2; \
408 exit; \
409 " ::: __clobber_all);
410 }
411
412 SEC("socket")
413 __description("SMOD32, non-zero imm divisor, check 5")
414 __success __success_unpriv __retval(0)
smod32_non_zero_imm_5(void)415 __naked void smod32_non_zero_imm_5(void)
416 {
417 asm volatile (" \
418 w0 = 42; \
419 w0 s%%= -2; \
420 exit; \
421 " ::: __clobber_all);
422 }
423
424 SEC("socket")
425 __description("SMOD32, non-zero imm divisor, check 6")
426 __success __success_unpriv __retval(0)
smod32_non_zero_imm_6(void)427 __naked void smod32_non_zero_imm_6(void)
428 {
429 asm volatile (" \
430 w0 = -42; \
431 w0 s%%= -2; \
432 exit; \
433 " ::: __clobber_all);
434 }
435
436 SEC("socket")
437 __description("SMOD32, non-zero reg divisor, check 1")
438 __success __success_unpriv __retval(-1)
smod32_non_zero_reg_1(void)439 __naked void smod32_non_zero_reg_1(void)
440 {
441 asm volatile (" \
442 w0 = -41; \
443 w1 = 2; \
444 w0 s%%= w1; \
445 exit; \
446 " ::: __clobber_all);
447 }
448
449 SEC("socket")
450 __description("SMOD32, non-zero reg divisor, check 2")
451 __success __success_unpriv __retval(1)
smod32_non_zero_reg_2(void)452 __naked void smod32_non_zero_reg_2(void)
453 {
454 asm volatile (" \
455 w0 = 41; \
456 w1 = -2; \
457 w0 s%%= w1; \
458 exit; \
459 " ::: __clobber_all);
460 }
461
462 SEC("socket")
463 __description("SMOD32, non-zero reg divisor, check 3")
464 __success __success_unpriv __retval(-1)
smod32_non_zero_reg_3(void)465 __naked void smod32_non_zero_reg_3(void)
466 {
467 asm volatile (" \
468 w0 = -41; \
469 w1 = -2; \
470 w0 s%%= w1; \
471 exit; \
472 " ::: __clobber_all);
473 }
474
475 SEC("socket")
476 __description("SMOD32, non-zero reg divisor, check 4")
477 __success __success_unpriv __retval(0)
smod32_non_zero_reg_4(void)478 __naked void smod32_non_zero_reg_4(void)
479 {
480 asm volatile (" \
481 w0 = -42; \
482 w1 = 2; \
483 w0 s%%= w1; \
484 exit; \
485 " ::: __clobber_all);
486 }
487
488 SEC("socket")
489 __description("SMOD32, non-zero reg divisor, check 5")
490 __success __success_unpriv __retval(0)
smod32_non_zero_reg_5(void)491 __naked void smod32_non_zero_reg_5(void)
492 {
493 asm volatile (" \
494 w0 = 42; \
495 w1 = -2; \
496 w0 s%%= w1; \
497 exit; \
498 " ::: __clobber_all);
499 }
500
501 SEC("socket")
502 __description("SMOD32, non-zero reg divisor, check 6")
503 __success __success_unpriv __retval(0)
smod32_non_zero_reg_6(void)504 __naked void smod32_non_zero_reg_6(void)
505 {
506 asm volatile (" \
507 w0 = -42; \
508 w1 = -2; \
509 w0 s%%= w1; \
510 exit; \
511 " ::: __clobber_all);
512 }
513
514 SEC("socket")
515 __description("SMOD64, non-zero imm divisor, check 1")
516 __success __success_unpriv __retval(-1)
smod64_non_zero_imm_1(void)517 __naked void smod64_non_zero_imm_1(void)
518 {
519 asm volatile (" \
520 r0 = -41; \
521 r0 s%%= 2; \
522 exit; \
523 " ::: __clobber_all);
524 }
525
526 SEC("socket")
527 __description("SMOD64, non-zero imm divisor, check 2")
528 __success __success_unpriv __retval(1)
smod64_non_zero_imm_2(void)529 __naked void smod64_non_zero_imm_2(void)
530 {
531 asm volatile (" \
532 r0 = 41; \
533 r0 s%%= -2; \
534 exit; \
535 " ::: __clobber_all);
536 }
537
538 SEC("socket")
539 __description("SMOD64, non-zero imm divisor, check 3")
540 __success __success_unpriv __retval(-1)
smod64_non_zero_imm_3(void)541 __naked void smod64_non_zero_imm_3(void)
542 {
543 asm volatile (" \
544 r0 = -41; \
545 r0 s%%= -2; \
546 exit; \
547 " ::: __clobber_all);
548 }
549
550 SEC("socket")
551 __description("SMOD64, non-zero imm divisor, check 4")
552 __success __success_unpriv __retval(0)
smod64_non_zero_imm_4(void)553 __naked void smod64_non_zero_imm_4(void)
554 {
555 asm volatile (" \
556 r0 = -42; \
557 r0 s%%= 2; \
558 exit; \
559 " ::: __clobber_all);
560 }
561
562 SEC("socket")
563 __description("SMOD64, non-zero imm divisor, check 5")
564 __success __success_unpriv __retval(-0)
smod64_non_zero_imm_5(void)565 __naked void smod64_non_zero_imm_5(void)
566 {
567 asm volatile (" \
568 r0 = 42; \
569 r0 s%%= -2; \
570 exit; \
571 " ::: __clobber_all);
572 }
573
574 SEC("socket")
575 __description("SMOD64, non-zero imm divisor, check 6")
576 __success __success_unpriv __retval(0)
smod64_non_zero_imm_6(void)577 __naked void smod64_non_zero_imm_6(void)
578 {
579 asm volatile (" \
580 r0 = -42; \
581 r0 s%%= -2; \
582 exit; \
583 " ::: __clobber_all);
584 }
585
586 SEC("socket")
587 __description("SMOD64, non-zero imm divisor, check 7")
588 __success __success_unpriv __retval(0)
smod64_non_zero_imm_7(void)589 __naked void smod64_non_zero_imm_7(void)
590 {
591 asm volatile (" \
592 r0 = 42; \
593 r0 s%%= 2; \
594 exit; \
595 " ::: __clobber_all);
596 }
597
598 SEC("socket")
599 __description("SMOD64, non-zero imm divisor, check 8")
600 __success __success_unpriv __retval(1)
smod64_non_zero_imm_8(void)601 __naked void smod64_non_zero_imm_8(void)
602 {
603 asm volatile (" \
604 r0 = 41; \
605 r0 s%%= 2; \
606 exit; \
607 " ::: __clobber_all);
608 }
609
610 SEC("socket")
611 __description("SMOD64, non-zero reg divisor, check 1")
612 __success __success_unpriv __retval(-1)
smod64_non_zero_reg_1(void)613 __naked void smod64_non_zero_reg_1(void)
614 {
615 asm volatile (" \
616 r0 = -41; \
617 r1 = 2; \
618 r0 s%%= r1; \
619 exit; \
620 " ::: __clobber_all);
621 }
622
623 SEC("socket")
624 __description("SMOD64, non-zero reg divisor, check 2")
625 __success __success_unpriv __retval(1)
smod64_non_zero_reg_2(void)626 __naked void smod64_non_zero_reg_2(void)
627 {
628 asm volatile (" \
629 r0 = 41; \
630 r1 = -2; \
631 r0 s%%= r1; \
632 exit; \
633 " ::: __clobber_all);
634 }
635
636 SEC("socket")
637 __description("SMOD64, non-zero reg divisor, check 3")
638 __success __success_unpriv __retval(-1)
smod64_non_zero_reg_3(void)639 __naked void smod64_non_zero_reg_3(void)
640 {
641 asm volatile (" \
642 r0 = -41; \
643 r1 = -2; \
644 r0 s%%= r1; \
645 exit; \
646 " ::: __clobber_all);
647 }
648
649 SEC("socket")
650 __description("SMOD64, non-zero reg divisor, check 4")
651 __success __success_unpriv __retval(0)
smod64_non_zero_reg_4(void)652 __naked void smod64_non_zero_reg_4(void)
653 {
654 asm volatile (" \
655 r0 = -42; \
656 r1 = 2; \
657 r0 s%%= r1; \
658 exit; \
659 " ::: __clobber_all);
660 }
661
662 SEC("socket")
663 __description("SMOD64, non-zero reg divisor, check 5")
664 __success __success_unpriv __retval(0)
smod64_non_zero_reg_5(void)665 __naked void smod64_non_zero_reg_5(void)
666 {
667 asm volatile (" \
668 r0 = 42; \
669 r1 = -2; \
670 r0 s%%= r1; \
671 exit; \
672 " ::: __clobber_all);
673 }
674
675 SEC("socket")
676 __description("SMOD64, non-zero reg divisor, check 6")
677 __success __success_unpriv __retval(0)
smod64_non_zero_reg_6(void)678 __naked void smod64_non_zero_reg_6(void)
679 {
680 asm volatile (" \
681 r0 = -42; \
682 r1 = -2; \
683 r0 s%%= r1; \
684 exit; \
685 " ::: __clobber_all);
686 }
687
688 SEC("socket")
689 __description("SMOD64, non-zero reg divisor, check 7")
690 __success __success_unpriv __retval(0)
smod64_non_zero_reg_7(void)691 __naked void smod64_non_zero_reg_7(void)
692 {
693 asm volatile (" \
694 r0 = 42; \
695 r1 = 2; \
696 r0 s%%= r1; \
697 exit; \
698 " ::: __clobber_all);
699 }
700
701 SEC("socket")
702 __description("SMOD64, non-zero reg divisor, check 8")
703 __success __success_unpriv __retval(1)
smod64_non_zero_reg_8(void)704 __naked void smod64_non_zero_reg_8(void)
705 {
706 asm volatile (" \
707 r0 = 41; \
708 r1 = 2; \
709 r0 s%%= r1; \
710 exit; \
711 " ::: __clobber_all);
712 }
713
714 SEC("socket")
715 __description("SDIV32, zero divisor")
716 __success __success_unpriv __retval(0)
sdiv32_zero_divisor(void)717 __naked void sdiv32_zero_divisor(void)
718 {
719 asm volatile (" \
720 w0 = 42; \
721 w1 = 0; \
722 w2 = -1; \
723 w2 s/= w1; \
724 w0 = w2; \
725 exit; \
726 " ::: __clobber_all);
727 }
728
729 SEC("socket")
730 __description("SDIV64, zero divisor")
731 __success __success_unpriv __retval(0)
sdiv64_zero_divisor(void)732 __naked void sdiv64_zero_divisor(void)
733 {
734 asm volatile (" \
735 r0 = 42; \
736 r1 = 0; \
737 r2 = -1; \
738 r2 s/= r1; \
739 r0 = r2; \
740 exit; \
741 " ::: __clobber_all);
742 }
743
744 SEC("socket")
745 __description("SMOD32, zero divisor")
746 __success __success_unpriv __retval(-1)
smod32_zero_divisor(void)747 __naked void smod32_zero_divisor(void)
748 {
749 asm volatile (" \
750 w0 = 42; \
751 w1 = 0; \
752 w2 = -1; \
753 w2 s%%= w1; \
754 w0 = w2; \
755 exit; \
756 " ::: __clobber_all);
757 }
758
759 SEC("socket")
760 __description("SMOD64, zero divisor")
761 __success __success_unpriv __retval(-1)
smod64_zero_divisor(void)762 __naked void smod64_zero_divisor(void)
763 {
764 asm volatile (" \
765 r0 = 42; \
766 r1 = 0; \
767 r2 = -1; \
768 r2 s%%= r1; \
769 r0 = r2; \
770 exit; \
771 " ::: __clobber_all);
772 }
773
774 SEC("socket")
775 __description("SDIV64, overflow r/r, LLONG_MIN/-1")
776 __success __retval(1)
777 __arch_x86_64
778 __xlated("0: r2 = 0x8000000000000000")
779 __xlated("2: r3 = -1")
780 __xlated("3: r4 = r2")
781 __xlated("4: r11 = r3")
782 __xlated("5: r11 += 1")
783 __xlated("6: if r11 > 0x1 goto pc+4")
784 __xlated("7: if r11 == 0x0 goto pc+1")
785 __xlated("8: r2 = 0")
786 __xlated("9: r2 = -r2")
787 __xlated("10: goto pc+1")
788 __xlated("11: r2 s/= r3")
789 __xlated("12: r0 = 0")
790 __xlated("13: if r2 != r4 goto pc+1")
791 __xlated("14: r0 = 1")
792 __xlated("15: exit")
sdiv64_overflow_rr(void)793 __naked void sdiv64_overflow_rr(void)
794 {
795 asm volatile (" \
796 r2 = %[llong_min] ll; \
797 r3 = -1; \
798 r4 = r2; \
799 r2 s/= r3; \
800 r0 = 0; \
801 if r2 != r4 goto +1; \
802 r0 = 1; \
803 exit; \
804 " :
805 : __imm_const(llong_min, LLONG_MIN)
806 : __clobber_all);
807 }
808
809 SEC("socket")
810 __description("SDIV64, r/r, small_val/-1")
811 __success __retval(-5)
812 __arch_x86_64
813 __xlated("0: r2 = 5")
814 __xlated("1: r3 = -1")
815 __xlated("2: r11 = r3")
816 __xlated("3: r11 += 1")
817 __xlated("4: if r11 > 0x1 goto pc+4")
818 __xlated("5: if r11 == 0x0 goto pc+1")
819 __xlated("6: r2 = 0")
820 __xlated("7: r2 = -r2")
821 __xlated("8: goto pc+1")
822 __xlated("9: r2 s/= r3")
823 __xlated("10: r0 = r2")
824 __xlated("11: exit")
sdiv64_rr_divisor_neg_1(void)825 __naked void sdiv64_rr_divisor_neg_1(void)
826 {
827 asm volatile (" \
828 r2 = 5; \
829 r3 = -1; \
830 r2 s/= r3; \
831 r0 = r2; \
832 exit; \
833 " :
834 :
835 : __clobber_all);
836 }
837
838 SEC("socket")
839 __description("SDIV64, overflow r/i, LLONG_MIN/-1")
840 __success __retval(1)
841 __arch_x86_64
842 __xlated("0: r2 = 0x8000000000000000")
843 __xlated("2: r4 = r2")
844 __xlated("3: r2 = -r2")
845 __xlated("4: r0 = 0")
846 __xlated("5: if r2 != r4 goto pc+1")
847 __xlated("6: r0 = 1")
848 __xlated("7: exit")
sdiv64_overflow_ri(void)849 __naked void sdiv64_overflow_ri(void)
850 {
851 asm volatile (" \
852 r2 = %[llong_min] ll; \
853 r4 = r2; \
854 r2 s/= -1; \
855 r0 = 0; \
856 if r2 != r4 goto +1; \
857 r0 = 1; \
858 exit; \
859 " :
860 : __imm_const(llong_min, LLONG_MIN)
861 : __clobber_all);
862 }
863
864 SEC("socket")
865 __description("SDIV64, r/i, small_val/-1")
866 __success __retval(-5)
867 __arch_x86_64
868 __xlated("0: r2 = 5")
869 __xlated("1: r4 = r2")
870 __xlated("2: r2 = -r2")
871 __xlated("3: r0 = r2")
872 __xlated("4: exit")
sdiv64_ri_divisor_neg_1(void)873 __naked void sdiv64_ri_divisor_neg_1(void)
874 {
875 asm volatile (" \
876 r2 = 5; \
877 r4 = r2; \
878 r2 s/= -1; \
879 r0 = r2; \
880 exit; \
881 " :
882 :
883 : __clobber_all);
884 }
885
886 SEC("socket")
887 __description("SDIV32, overflow r/r, INT_MIN/-1")
888 __success __retval(1)
889 __arch_x86_64
890 __xlated("0: w2 = -2147483648")
891 __xlated("1: w3 = -1")
892 __xlated("2: w4 = w2")
893 __xlated("3: r11 = r3")
894 __xlated("4: w11 += 1")
895 __xlated("5: if w11 > 0x1 goto pc+4")
896 __xlated("6: if w11 == 0x0 goto pc+1")
897 __xlated("7: w2 = 0")
898 __xlated("8: w2 = -w2")
899 __xlated("9: goto pc+1")
900 __xlated("10: w2 s/= w3")
901 __xlated("11: r0 = 0")
902 __xlated("12: if w2 != w4 goto pc+1")
903 __xlated("13: r0 = 1")
904 __xlated("14: exit")
sdiv32_overflow_rr(void)905 __naked void sdiv32_overflow_rr(void)
906 {
907 asm volatile (" \
908 w2 = %[int_min]; \
909 w3 = -1; \
910 w4 = w2; \
911 w2 s/= w3; \
912 r0 = 0; \
913 if w2 != w4 goto +1; \
914 r0 = 1; \
915 exit; \
916 " :
917 : __imm_const(int_min, INT_MIN)
918 : __clobber_all);
919 }
920
921 SEC("socket")
922 __description("SDIV32, r/r, small_val/-1")
923 __success __retval(5)
924 __arch_x86_64
925 __xlated("0: w2 = -5")
926 __xlated("1: w3 = -1")
927 __xlated("2: w4 = w2")
928 __xlated("3: r11 = r3")
929 __xlated("4: w11 += 1")
930 __xlated("5: if w11 > 0x1 goto pc+4")
931 __xlated("6: if w11 == 0x0 goto pc+1")
932 __xlated("7: w2 = 0")
933 __xlated("8: w2 = -w2")
934 __xlated("9: goto pc+1")
935 __xlated("10: w2 s/= w3")
936 __xlated("11: w0 = w2")
937 __xlated("12: exit")
sdiv32_rr_divisor_neg_1(void)938 __naked void sdiv32_rr_divisor_neg_1(void)
939 {
940 asm volatile (" \
941 w2 = -5; \
942 w3 = -1; \
943 w4 = w2; \
944 w2 s/= w3; \
945 w0 = w2; \
946 exit; \
947 " :
948 :
949 : __clobber_all);
950 }
951
952 SEC("socket")
953 __description("SDIV32, overflow r/i, INT_MIN/-1")
954 __success __retval(1)
955 __arch_x86_64
956 __xlated("0: w2 = -2147483648")
957 __xlated("1: w4 = w2")
958 __xlated("2: w2 = -w2")
959 __xlated("3: r0 = 0")
960 __xlated("4: if w2 != w4 goto pc+1")
961 __xlated("5: r0 = 1")
962 __xlated("6: exit")
sdiv32_overflow_ri(void)963 __naked void sdiv32_overflow_ri(void)
964 {
965 asm volatile (" \
966 w2 = %[int_min]; \
967 w4 = w2; \
968 w2 s/= -1; \
969 r0 = 0; \
970 if w2 != w4 goto +1; \
971 r0 = 1; \
972 exit; \
973 " :
974 : __imm_const(int_min, INT_MIN)
975 : __clobber_all);
976 }
977
978 SEC("socket")
979 __description("SDIV32, r/i, small_val/-1")
980 __success __retval(-5)
981 __arch_x86_64
982 __xlated("0: w2 = 5")
983 __xlated("1: w4 = w2")
984 __xlated("2: w2 = -w2")
985 __xlated("3: w0 = w2")
986 __xlated("4: exit")
sdiv32_ri_divisor_neg_1(void)987 __naked void sdiv32_ri_divisor_neg_1(void)
988 {
989 asm volatile (" \
990 w2 = 5; \
991 w4 = w2; \
992 w2 s/= -1; \
993 w0 = w2; \
994 exit; \
995 " :
996 :
997 : __clobber_all);
998 }
999
1000 SEC("socket")
1001 __description("SMOD64, overflow r/r, LLONG_MIN/-1")
1002 __success __retval(0)
1003 __arch_x86_64
1004 __xlated("0: r2 = 0x8000000000000000")
1005 __xlated("2: r3 = -1")
1006 __xlated("3: r4 = r2")
1007 __xlated("4: r11 = r3")
1008 __xlated("5: r11 += 1")
1009 __xlated("6: if r11 > 0x1 goto pc+3")
1010 __xlated("7: if r11 == 0x1 goto pc+3")
1011 __xlated("8: w2 = 0")
1012 __xlated("9: goto pc+1")
1013 __xlated("10: r2 s%= r3")
1014 __xlated("11: r0 = r2")
1015 __xlated("12: exit")
smod64_overflow_rr(void)1016 __naked void smod64_overflow_rr(void)
1017 {
1018 asm volatile (" \
1019 r2 = %[llong_min] ll; \
1020 r3 = -1; \
1021 r4 = r2; \
1022 r2 s%%= r3; \
1023 r0 = r2; \
1024 exit; \
1025 " :
1026 : __imm_const(llong_min, LLONG_MIN)
1027 : __clobber_all);
1028 }
1029
1030 SEC("socket")
1031 __description("SMOD64, r/r, small_val/-1")
1032 __success __retval(0)
1033 __arch_x86_64
1034 __xlated("0: r2 = 5")
1035 __xlated("1: r3 = -1")
1036 __xlated("2: r4 = r2")
1037 __xlated("3: r11 = r3")
1038 __xlated("4: r11 += 1")
1039 __xlated("5: if r11 > 0x1 goto pc+3")
1040 __xlated("6: if r11 == 0x1 goto pc+3")
1041 __xlated("7: w2 = 0")
1042 __xlated("8: goto pc+1")
1043 __xlated("9: r2 s%= r3")
1044 __xlated("10: r0 = r2")
1045 __xlated("11: exit")
smod64_rr_divisor_neg_1(void)1046 __naked void smod64_rr_divisor_neg_1(void)
1047 {
1048 asm volatile (" \
1049 r2 = 5; \
1050 r3 = -1; \
1051 r4 = r2; \
1052 r2 s%%= r3; \
1053 r0 = r2; \
1054 exit; \
1055 " :
1056 :
1057 : __clobber_all);
1058 }
1059
1060 SEC("socket")
1061 __description("SMOD64, overflow r/i, LLONG_MIN/-1")
1062 __success __retval(0)
1063 __arch_x86_64
1064 __xlated("0: r2 = 0x8000000000000000")
1065 __xlated("2: r4 = r2")
1066 __xlated("3: w2 = 0")
1067 __xlated("4: r0 = r2")
1068 __xlated("5: exit")
smod64_overflow_ri(void)1069 __naked void smod64_overflow_ri(void)
1070 {
1071 asm volatile (" \
1072 r2 = %[llong_min] ll; \
1073 r4 = r2; \
1074 r2 s%%= -1; \
1075 r0 = r2; \
1076 exit; \
1077 " :
1078 : __imm_const(llong_min, LLONG_MIN)
1079 : __clobber_all);
1080 }
1081
1082 SEC("socket")
1083 __description("SMOD64, r/i, small_val/-1")
1084 __success __retval(0)
1085 __arch_x86_64
1086 __xlated("0: r2 = 5")
1087 __xlated("1: r4 = r2")
1088 __xlated("2: w2 = 0")
1089 __xlated("3: r0 = r2")
1090 __xlated("4: exit")
smod64_ri_divisor_neg_1(void)1091 __naked void smod64_ri_divisor_neg_1(void)
1092 {
1093 asm volatile (" \
1094 r2 = 5; \
1095 r4 = r2; \
1096 r2 s%%= -1; \
1097 r0 = r2; \
1098 exit; \
1099 " :
1100 :
1101 : __clobber_all);
1102 }
1103
1104 SEC("socket")
1105 __description("SMOD32, overflow r/r, INT_MIN/-1")
1106 __success __retval(0)
1107 __arch_x86_64
1108 __xlated("0: w2 = -2147483648")
1109 __xlated("1: w3 = -1")
1110 __xlated("2: w4 = w2")
1111 __xlated("3: r11 = r3")
1112 __xlated("4: w11 += 1")
1113 __xlated("5: if w11 > 0x1 goto pc+3")
1114 __xlated("6: if w11 == 0x1 goto pc+4")
1115 __xlated("7: w2 = 0")
1116 __xlated("8: goto pc+1")
1117 __xlated("9: w2 s%= w3")
1118 __xlated("10: goto pc+1")
1119 __xlated("11: w2 = w2")
1120 __xlated("12: r0 = r2")
1121 __xlated("13: exit")
smod32_overflow_rr(void)1122 __naked void smod32_overflow_rr(void)
1123 {
1124 asm volatile (" \
1125 w2 = %[int_min]; \
1126 w3 = -1; \
1127 w4 = w2; \
1128 w2 s%%= w3; \
1129 r0 = r2; \
1130 exit; \
1131 " :
1132 : __imm_const(int_min, INT_MIN)
1133 : __clobber_all);
1134 }
1135
1136 SEC("socket")
1137 __description("SMOD32, r/r, small_val/-1")
1138 __success __retval(0)
1139 __arch_x86_64
1140 __xlated("0: w2 = -5")
1141 __xlated("1: w3 = -1")
1142 __xlated("2: w4 = w2")
1143 __xlated("3: r11 = r3")
1144 __xlated("4: w11 += 1")
1145 __xlated("5: if w11 > 0x1 goto pc+3")
1146 __xlated("6: if w11 == 0x1 goto pc+4")
1147 __xlated("7: w2 = 0")
1148 __xlated("8: goto pc+1")
1149 __xlated("9: w2 s%= w3")
1150 __xlated("10: goto pc+1")
1151 __xlated("11: w2 = w2")
1152 __xlated("12: r0 = r2")
1153 __xlated("13: exit")
smod32_rr_divisor_neg_1(void)1154 __naked void smod32_rr_divisor_neg_1(void)
1155 {
1156 asm volatile (" \
1157 w2 = -5; \
1158 w3 = -1; \
1159 w4 = w2; \
1160 w2 s%%= w3; \
1161 r0 = r2; \
1162 exit; \
1163 " :
1164 :
1165 : __clobber_all);
1166 }
1167
1168 SEC("socket")
1169 __description("SMOD32, overflow r/i, INT_MIN/-1")
1170 __success __retval(0)
1171 __arch_x86_64
1172 __xlated("0: w2 = -2147483648")
1173 __xlated("1: w4 = w2")
1174 __xlated("2: w2 = 0")
1175 __xlated("3: r0 = r2")
1176 __xlated("4: exit")
smod32_overflow_ri(void)1177 __naked void smod32_overflow_ri(void)
1178 {
1179 asm volatile (" \
1180 w2 = %[int_min]; \
1181 w4 = w2; \
1182 w2 s%%= -1; \
1183 r0 = r2; \
1184 exit; \
1185 " :
1186 : __imm_const(int_min, INT_MIN)
1187 : __clobber_all);
1188 }
1189
1190 SEC("socket")
1191 __description("SMOD32, r/i, small_val/-1")
1192 __success __retval(0)
1193 __arch_x86_64
1194 __xlated("0: w2 = 5")
1195 __xlated("1: w4 = w2")
1196 __xlated("2: w2 = 0")
1197 __xlated("3: w0 = w2")
1198 __xlated("4: exit")
smod32_ri_divisor_neg_1(void)1199 __naked void smod32_ri_divisor_neg_1(void)
1200 {
1201 asm volatile (" \
1202 w2 = 5; \
1203 w4 = w2; \
1204 w2 s%%= -1; \
1205 w0 = w2; \
1206 exit; \
1207 " :
1208 :
1209 : __clobber_all);
1210 }
1211
1212 #else
1213
1214 SEC("socket")
1215 __description("cpuv4 is not supported by compiler or jit, use a dummy test")
1216 __success
dummy_test(void)1217 int dummy_test(void)
1218 {
1219 return 0;
1220 }
1221
1222 #endif
1223
1224 char _license[] SEC("license") = "GPL";
1225