1 // SPDX-License-Identifier: GPL-2.0 2 3 #include <linux/bpf.h> 4 #include <bpf/bpf_helpers.h> 5 #include "bpf_misc.h" 6 7 #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \ 8 (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) || \ 9 defined(__TARGET_ARCH_arm) || defined(__TARGET_ARCH_s390)) && \ 10 __clang_major__ >= 18 11 12 SEC("socket") 13 __description("SDIV32, non-zero imm divisor, check 1") 14 __success __success_unpriv __retval(-20) 15 __naked void sdiv32_non_zero_imm_1(void) 16 { 17 asm volatile (" \ 18 w0 = -41; \ 19 w0 s/= 2; \ 20 exit; \ 21 " ::: __clobber_all); 22 } 23 24 SEC("socket") 25 __description("SDIV32, non-zero imm divisor, check 2") 26 __success __success_unpriv __retval(-20) 27 __naked void sdiv32_non_zero_imm_2(void) 28 { 29 asm volatile (" \ 30 w0 = 41; \ 31 w0 s/= -2; \ 32 exit; \ 33 " ::: __clobber_all); 34 } 35 36 SEC("socket") 37 __description("SDIV32, non-zero imm divisor, check 3") 38 __success __success_unpriv __retval(20) 39 __naked void sdiv32_non_zero_imm_3(void) 40 { 41 asm volatile (" \ 42 w0 = -41; \ 43 w0 s/= -2; \ 44 exit; \ 45 " ::: __clobber_all); 46 } 47 48 SEC("socket") 49 __description("SDIV32, non-zero imm divisor, check 4") 50 __success __success_unpriv __retval(-21) 51 __naked void sdiv32_non_zero_imm_4(void) 52 { 53 asm volatile (" \ 54 w0 = -42; \ 55 w0 s/= 2; \ 56 exit; \ 57 " ::: __clobber_all); 58 } 59 60 SEC("socket") 61 __description("SDIV32, non-zero imm divisor, check 5") 62 __success __success_unpriv __retval(-21) 63 __naked void sdiv32_non_zero_imm_5(void) 64 { 65 asm volatile (" \ 66 w0 = 42; \ 67 w0 s/= -2; \ 68 exit; \ 69 " ::: __clobber_all); 70 } 71 72 SEC("socket") 73 __description("SDIV32, non-zero imm divisor, check 6") 74 __success __success_unpriv __retval(21) 75 __naked void sdiv32_non_zero_imm_6(void) 76 { 77 asm volatile (" \ 78 w0 = -42; \ 79 w0 s/= -2; \ 80 exit; \ 81 " ::: __clobber_all); 82 } 83 84 SEC("socket") 85 __description("SDIV32, non-zero imm divisor, check 7") 86 __success __success_unpriv __retval(21) 87 __naked void sdiv32_non_zero_imm_7(void) 88 { 89 asm volatile (" \ 90 w0 = 42; \ 91 w0 s/= 2; \ 92 exit; \ 93 " ::: __clobber_all); 94 } 95 96 SEC("socket") 97 __description("SDIV32, non-zero imm divisor, check 8") 98 __success __success_unpriv __retval(20) 99 __naked void sdiv32_non_zero_imm_8(void) 100 { 101 asm volatile (" \ 102 w0 = 41; \ 103 w0 s/= 2; \ 104 exit; \ 105 " ::: __clobber_all); 106 } 107 108 SEC("socket") 109 __description("SDIV32, non-zero reg divisor, check 1") 110 __success __success_unpriv __retval(-20) 111 __naked void sdiv32_non_zero_reg_1(void) 112 { 113 asm volatile (" \ 114 w0 = -41; \ 115 w1 = 2; \ 116 w0 s/= w1; \ 117 exit; \ 118 " ::: __clobber_all); 119 } 120 121 SEC("socket") 122 __description("SDIV32, non-zero reg divisor, check 2") 123 __success __success_unpriv __retval(-20) 124 __naked void sdiv32_non_zero_reg_2(void) 125 { 126 asm volatile (" \ 127 w0 = 41; \ 128 w1 = -2; \ 129 w0 s/= w1; \ 130 exit; \ 131 " ::: __clobber_all); 132 } 133 134 SEC("socket") 135 __description("SDIV32, non-zero reg divisor, check 3") 136 __success __success_unpriv __retval(20) 137 __naked void sdiv32_non_zero_reg_3(void) 138 { 139 asm volatile (" \ 140 w0 = -41; \ 141 w1 = -2; \ 142 w0 s/= w1; \ 143 exit; \ 144 " ::: __clobber_all); 145 } 146 147 SEC("socket") 148 __description("SDIV32, non-zero reg divisor, check 4") 149 __success __success_unpriv __retval(-21) 150 __naked void sdiv32_non_zero_reg_4(void) 151 { 152 asm volatile (" \ 153 w0 = -42; \ 154 w1 = 2; \ 155 w0 s/= w1; \ 156 exit; \ 157 " ::: __clobber_all); 158 } 159 160 SEC("socket") 161 __description("SDIV32, non-zero reg divisor, check 5") 162 __success __success_unpriv __retval(-21) 163 __naked void sdiv32_non_zero_reg_5(void) 164 { 165 asm volatile (" \ 166 w0 = 42; \ 167 w1 = -2; \ 168 w0 s/= w1; \ 169 exit; \ 170 " ::: __clobber_all); 171 } 172 173 SEC("socket") 174 __description("SDIV32, non-zero reg divisor, check 6") 175 __success __success_unpriv __retval(21) 176 __naked void sdiv32_non_zero_reg_6(void) 177 { 178 asm volatile (" \ 179 w0 = -42; \ 180 w1 = -2; \ 181 w0 s/= w1; \ 182 exit; \ 183 " ::: __clobber_all); 184 } 185 186 SEC("socket") 187 __description("SDIV32, non-zero reg divisor, check 7") 188 __success __success_unpriv __retval(21) 189 __naked void sdiv32_non_zero_reg_7(void) 190 { 191 asm volatile (" \ 192 w0 = 42; \ 193 w1 = 2; \ 194 w0 s/= w1; \ 195 exit; \ 196 " ::: __clobber_all); 197 } 198 199 SEC("socket") 200 __description("SDIV32, non-zero reg divisor, check 8") 201 __success __success_unpriv __retval(20) 202 __naked void sdiv32_non_zero_reg_8(void) 203 { 204 asm volatile (" \ 205 w0 = 41; \ 206 w1 = 2; \ 207 w0 s/= w1; \ 208 exit; \ 209 " ::: __clobber_all); 210 } 211 212 SEC("socket") 213 __description("SDIV64, non-zero imm divisor, check 1") 214 __success __success_unpriv __retval(-20) 215 __naked void sdiv64_non_zero_imm_1(void) 216 { 217 asm volatile (" \ 218 r0 = -41; \ 219 r0 s/= 2; \ 220 exit; \ 221 " ::: __clobber_all); 222 } 223 224 SEC("socket") 225 __description("SDIV64, non-zero imm divisor, check 2") 226 __success __success_unpriv __retval(-20) 227 __naked void sdiv64_non_zero_imm_2(void) 228 { 229 asm volatile (" \ 230 r0 = 41; \ 231 r0 s/= -2; \ 232 exit; \ 233 " ::: __clobber_all); 234 } 235 236 SEC("socket") 237 __description("SDIV64, non-zero imm divisor, check 3") 238 __success __success_unpriv __retval(20) 239 __naked void sdiv64_non_zero_imm_3(void) 240 { 241 asm volatile (" \ 242 r0 = -41; \ 243 r0 s/= -2; \ 244 exit; \ 245 " ::: __clobber_all); 246 } 247 248 SEC("socket") 249 __description("SDIV64, non-zero imm divisor, check 4") 250 __success __success_unpriv __retval(-21) 251 __naked void sdiv64_non_zero_imm_4(void) 252 { 253 asm volatile (" \ 254 r0 = -42; \ 255 r0 s/= 2; \ 256 exit; \ 257 " ::: __clobber_all); 258 } 259 260 SEC("socket") 261 __description("SDIV64, non-zero imm divisor, check 5") 262 __success __success_unpriv __retval(-21) 263 __naked void sdiv64_non_zero_imm_5(void) 264 { 265 asm volatile (" \ 266 r0 = 42; \ 267 r0 s/= -2; \ 268 exit; \ 269 " ::: __clobber_all); 270 } 271 272 SEC("socket") 273 __description("SDIV64, non-zero imm divisor, check 6") 274 __success __success_unpriv __retval(21) 275 __naked void sdiv64_non_zero_imm_6(void) 276 { 277 asm volatile (" \ 278 r0 = -42; \ 279 r0 s/= -2; \ 280 exit; \ 281 " ::: __clobber_all); 282 } 283 284 SEC("socket") 285 __description("SDIV64, non-zero reg divisor, check 1") 286 __success __success_unpriv __retval(-20) 287 __naked void sdiv64_non_zero_reg_1(void) 288 { 289 asm volatile (" \ 290 r0 = -41; \ 291 r1 = 2; \ 292 r0 s/= r1; \ 293 exit; \ 294 " ::: __clobber_all); 295 } 296 297 SEC("socket") 298 __description("SDIV64, non-zero reg divisor, check 2") 299 __success __success_unpriv __retval(-20) 300 __naked void sdiv64_non_zero_reg_2(void) 301 { 302 asm volatile (" \ 303 r0 = 41; \ 304 r1 = -2; \ 305 r0 s/= r1; \ 306 exit; \ 307 " ::: __clobber_all); 308 } 309 310 SEC("socket") 311 __description("SDIV64, non-zero reg divisor, check 3") 312 __success __success_unpriv __retval(20) 313 __naked void sdiv64_non_zero_reg_3(void) 314 { 315 asm volatile (" \ 316 r0 = -41; \ 317 r1 = -2; \ 318 r0 s/= r1; \ 319 exit; \ 320 " ::: __clobber_all); 321 } 322 323 SEC("socket") 324 __description("SDIV64, non-zero reg divisor, check 4") 325 __success __success_unpriv __retval(-21) 326 __naked void sdiv64_non_zero_reg_4(void) 327 { 328 asm volatile (" \ 329 r0 = -42; \ 330 r1 = 2; \ 331 r0 s/= r1; \ 332 exit; \ 333 " ::: __clobber_all); 334 } 335 336 SEC("socket") 337 __description("SDIV64, non-zero reg divisor, check 5") 338 __success __success_unpriv __retval(-21) 339 __naked void sdiv64_non_zero_reg_5(void) 340 { 341 asm volatile (" \ 342 r0 = 42; \ 343 r1 = -2; \ 344 r0 s/= r1; \ 345 exit; \ 346 " ::: __clobber_all); 347 } 348 349 SEC("socket") 350 __description("SDIV64, non-zero reg divisor, check 6") 351 __success __success_unpriv __retval(21) 352 __naked void sdiv64_non_zero_reg_6(void) 353 { 354 asm volatile (" \ 355 r0 = -42; \ 356 r1 = -2; \ 357 r0 s/= r1; \ 358 exit; \ 359 " ::: __clobber_all); 360 } 361 362 SEC("socket") 363 __description("SMOD32, non-zero imm divisor, check 1") 364 __success __success_unpriv __retval(-1) 365 __naked void smod32_non_zero_imm_1(void) 366 { 367 asm volatile (" \ 368 w0 = -41; \ 369 w0 s%%= 2; \ 370 exit; \ 371 " ::: __clobber_all); 372 } 373 374 SEC("socket") 375 __description("SMOD32, non-zero imm divisor, check 2") 376 __success __success_unpriv __retval(1) 377 __naked void smod32_non_zero_imm_2(void) 378 { 379 asm volatile (" \ 380 w0 = 41; \ 381 w0 s%%= -2; \ 382 exit; \ 383 " ::: __clobber_all); 384 } 385 386 SEC("socket") 387 __description("SMOD32, non-zero imm divisor, check 3") 388 __success __success_unpriv __retval(-1) 389 __naked void smod32_non_zero_imm_3(void) 390 { 391 asm volatile (" \ 392 w0 = -41; \ 393 w0 s%%= -2; \ 394 exit; \ 395 " ::: __clobber_all); 396 } 397 398 SEC("socket") 399 __description("SMOD32, non-zero imm divisor, check 4") 400 __success __success_unpriv __retval(0) 401 __naked void smod32_non_zero_imm_4(void) 402 { 403 asm volatile (" \ 404 w0 = -42; \ 405 w0 s%%= 2; \ 406 exit; \ 407 " ::: __clobber_all); 408 } 409 410 SEC("socket") 411 __description("SMOD32, non-zero imm divisor, check 5") 412 __success __success_unpriv __retval(0) 413 __naked void smod32_non_zero_imm_5(void) 414 { 415 asm volatile (" \ 416 w0 = 42; \ 417 w0 s%%= -2; \ 418 exit; \ 419 " ::: __clobber_all); 420 } 421 422 SEC("socket") 423 __description("SMOD32, non-zero imm divisor, check 6") 424 __success __success_unpriv __retval(0) 425 __naked void smod32_non_zero_imm_6(void) 426 { 427 asm volatile (" \ 428 w0 = -42; \ 429 w0 s%%= -2; \ 430 exit; \ 431 " ::: __clobber_all); 432 } 433 434 SEC("socket") 435 __description("SMOD32, non-zero reg divisor, check 1") 436 __success __success_unpriv __retval(-1) 437 __naked void smod32_non_zero_reg_1(void) 438 { 439 asm volatile (" \ 440 w0 = -41; \ 441 w1 = 2; \ 442 w0 s%%= w1; \ 443 exit; \ 444 " ::: __clobber_all); 445 } 446 447 SEC("socket") 448 __description("SMOD32, non-zero reg divisor, check 2") 449 __success __success_unpriv __retval(1) 450 __naked void smod32_non_zero_reg_2(void) 451 { 452 asm volatile (" \ 453 w0 = 41; \ 454 w1 = -2; \ 455 w0 s%%= w1; \ 456 exit; \ 457 " ::: __clobber_all); 458 } 459 460 SEC("socket") 461 __description("SMOD32, non-zero reg divisor, check 3") 462 __success __success_unpriv __retval(-1) 463 __naked void smod32_non_zero_reg_3(void) 464 { 465 asm volatile (" \ 466 w0 = -41; \ 467 w1 = -2; \ 468 w0 s%%= w1; \ 469 exit; \ 470 " ::: __clobber_all); 471 } 472 473 SEC("socket") 474 __description("SMOD32, non-zero reg divisor, check 4") 475 __success __success_unpriv __retval(0) 476 __naked void smod32_non_zero_reg_4(void) 477 { 478 asm volatile (" \ 479 w0 = -42; \ 480 w1 = 2; \ 481 w0 s%%= w1; \ 482 exit; \ 483 " ::: __clobber_all); 484 } 485 486 SEC("socket") 487 __description("SMOD32, non-zero reg divisor, check 5") 488 __success __success_unpriv __retval(0) 489 __naked void smod32_non_zero_reg_5(void) 490 { 491 asm volatile (" \ 492 w0 = 42; \ 493 w1 = -2; \ 494 w0 s%%= w1; \ 495 exit; \ 496 " ::: __clobber_all); 497 } 498 499 SEC("socket") 500 __description("SMOD32, non-zero reg divisor, check 6") 501 __success __success_unpriv __retval(0) 502 __naked void smod32_non_zero_reg_6(void) 503 { 504 asm volatile (" \ 505 w0 = -42; \ 506 w1 = -2; \ 507 w0 s%%= w1; \ 508 exit; \ 509 " ::: __clobber_all); 510 } 511 512 SEC("socket") 513 __description("SMOD64, non-zero imm divisor, check 1") 514 __success __success_unpriv __retval(-1) 515 __naked void smod64_non_zero_imm_1(void) 516 { 517 asm volatile (" \ 518 r0 = -41; \ 519 r0 s%%= 2; \ 520 exit; \ 521 " ::: __clobber_all); 522 } 523 524 SEC("socket") 525 __description("SMOD64, non-zero imm divisor, check 2") 526 __success __success_unpriv __retval(1) 527 __naked void smod64_non_zero_imm_2(void) 528 { 529 asm volatile (" \ 530 r0 = 41; \ 531 r0 s%%= -2; \ 532 exit; \ 533 " ::: __clobber_all); 534 } 535 536 SEC("socket") 537 __description("SMOD64, non-zero imm divisor, check 3") 538 __success __success_unpriv __retval(-1) 539 __naked void smod64_non_zero_imm_3(void) 540 { 541 asm volatile (" \ 542 r0 = -41; \ 543 r0 s%%= -2; \ 544 exit; \ 545 " ::: __clobber_all); 546 } 547 548 SEC("socket") 549 __description("SMOD64, non-zero imm divisor, check 4") 550 __success __success_unpriv __retval(0) 551 __naked void smod64_non_zero_imm_4(void) 552 { 553 asm volatile (" \ 554 r0 = -42; \ 555 r0 s%%= 2; \ 556 exit; \ 557 " ::: __clobber_all); 558 } 559 560 SEC("socket") 561 __description("SMOD64, non-zero imm divisor, check 5") 562 __success __success_unpriv __retval(-0) 563 __naked void smod64_non_zero_imm_5(void) 564 { 565 asm volatile (" \ 566 r0 = 42; \ 567 r0 s%%= -2; \ 568 exit; \ 569 " ::: __clobber_all); 570 } 571 572 SEC("socket") 573 __description("SMOD64, non-zero imm divisor, check 6") 574 __success __success_unpriv __retval(0) 575 __naked void smod64_non_zero_imm_6(void) 576 { 577 asm volatile (" \ 578 r0 = -42; \ 579 r0 s%%= -2; \ 580 exit; \ 581 " ::: __clobber_all); 582 } 583 584 SEC("socket") 585 __description("SMOD64, non-zero imm divisor, check 7") 586 __success __success_unpriv __retval(0) 587 __naked void smod64_non_zero_imm_7(void) 588 { 589 asm volatile (" \ 590 r0 = 42; \ 591 r0 s%%= 2; \ 592 exit; \ 593 " ::: __clobber_all); 594 } 595 596 SEC("socket") 597 __description("SMOD64, non-zero imm divisor, check 8") 598 __success __success_unpriv __retval(1) 599 __naked void smod64_non_zero_imm_8(void) 600 { 601 asm volatile (" \ 602 r0 = 41; \ 603 r0 s%%= 2; \ 604 exit; \ 605 " ::: __clobber_all); 606 } 607 608 SEC("socket") 609 __description("SMOD64, non-zero reg divisor, check 1") 610 __success __success_unpriv __retval(-1) 611 __naked void smod64_non_zero_reg_1(void) 612 { 613 asm volatile (" \ 614 r0 = -41; \ 615 r1 = 2; \ 616 r0 s%%= r1; \ 617 exit; \ 618 " ::: __clobber_all); 619 } 620 621 SEC("socket") 622 __description("SMOD64, non-zero reg divisor, check 2") 623 __success __success_unpriv __retval(1) 624 __naked void smod64_non_zero_reg_2(void) 625 { 626 asm volatile (" \ 627 r0 = 41; \ 628 r1 = -2; \ 629 r0 s%%= r1; \ 630 exit; \ 631 " ::: __clobber_all); 632 } 633 634 SEC("socket") 635 __description("SMOD64, non-zero reg divisor, check 3") 636 __success __success_unpriv __retval(-1) 637 __naked void smod64_non_zero_reg_3(void) 638 { 639 asm volatile (" \ 640 r0 = -41; \ 641 r1 = -2; \ 642 r0 s%%= r1; \ 643 exit; \ 644 " ::: __clobber_all); 645 } 646 647 SEC("socket") 648 __description("SMOD64, non-zero reg divisor, check 4") 649 __success __success_unpriv __retval(0) 650 __naked void smod64_non_zero_reg_4(void) 651 { 652 asm volatile (" \ 653 r0 = -42; \ 654 r1 = 2; \ 655 r0 s%%= r1; \ 656 exit; \ 657 " ::: __clobber_all); 658 } 659 660 SEC("socket") 661 __description("SMOD64, non-zero reg divisor, check 5") 662 __success __success_unpriv __retval(0) 663 __naked void smod64_non_zero_reg_5(void) 664 { 665 asm volatile (" \ 666 r0 = 42; \ 667 r1 = -2; \ 668 r0 s%%= r1; \ 669 exit; \ 670 " ::: __clobber_all); 671 } 672 673 SEC("socket") 674 __description("SMOD64, non-zero reg divisor, check 6") 675 __success __success_unpriv __retval(0) 676 __naked void smod64_non_zero_reg_6(void) 677 { 678 asm volatile (" \ 679 r0 = -42; \ 680 r1 = -2; \ 681 r0 s%%= r1; \ 682 exit; \ 683 " ::: __clobber_all); 684 } 685 686 SEC("socket") 687 __description("SMOD64, non-zero reg divisor, check 7") 688 __success __success_unpriv __retval(0) 689 __naked void smod64_non_zero_reg_7(void) 690 { 691 asm volatile (" \ 692 r0 = 42; \ 693 r1 = 2; \ 694 r0 s%%= r1; \ 695 exit; \ 696 " ::: __clobber_all); 697 } 698 699 SEC("socket") 700 __description("SMOD64, non-zero reg divisor, check 8") 701 __success __success_unpriv __retval(1) 702 __naked void smod64_non_zero_reg_8(void) 703 { 704 asm volatile (" \ 705 r0 = 41; \ 706 r1 = 2; \ 707 r0 s%%= r1; \ 708 exit; \ 709 " ::: __clobber_all); 710 } 711 712 SEC("socket") 713 __description("SDIV32, zero divisor") 714 __success __success_unpriv __retval(0) 715 __naked void sdiv32_zero_divisor(void) 716 { 717 asm volatile (" \ 718 w0 = 42; \ 719 w1 = 0; \ 720 w2 = -1; \ 721 w2 s/= w1; \ 722 w0 = w2; \ 723 exit; \ 724 " ::: __clobber_all); 725 } 726 727 SEC("socket") 728 __description("SDIV64, zero divisor") 729 __success __success_unpriv __retval(0) 730 __naked void sdiv64_zero_divisor(void) 731 { 732 asm volatile (" \ 733 r0 = 42; \ 734 r1 = 0; \ 735 r2 = -1; \ 736 r2 s/= r1; \ 737 r0 = r2; \ 738 exit; \ 739 " ::: __clobber_all); 740 } 741 742 SEC("socket") 743 __description("SMOD32, zero divisor") 744 __success __success_unpriv __retval(-1) 745 __naked void smod32_zero_divisor(void) 746 { 747 asm volatile (" \ 748 w0 = 42; \ 749 w1 = 0; \ 750 w2 = -1; \ 751 w2 s%%= w1; \ 752 w0 = w2; \ 753 exit; \ 754 " ::: __clobber_all); 755 } 756 757 SEC("socket") 758 __description("SMOD64, zero divisor") 759 __success __success_unpriv __retval(-1) 760 __naked void smod64_zero_divisor(void) 761 { 762 asm volatile (" \ 763 r0 = 42; \ 764 r1 = 0; \ 765 r2 = -1; \ 766 r2 s%%= r1; \ 767 r0 = r2; \ 768 exit; \ 769 " ::: __clobber_all); 770 } 771 772 #else 773 774 SEC("socket") 775 __description("cpuv4 is not supported by compiler or jit, use a dummy test") 776 __success 777 int dummy_test(void) 778 { 779 return 0; 780 } 781 782 #endif 783 784 char _license[] SEC("license") = "GPL"; 785