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