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