Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: Introduce atomic API helpers

In order to support LKMM atomics in Rust, add rust_helper_* for atomic
APIs. These helpers ensure the implementation of LKMM atomics in Rust is
the same as in C. This could save the maintenance burden of having two
similar atomic implementations in asm.

Originally-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/all/20250719030827.61357-2-boqun.feng@gmail.com/

authored by

Boqun Feng and committed by
Peter Zijlstra
fdd7c7e0 76eeb9b8

+1109
+1040
rust/helpers/atomic.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + // Generated by scripts/atomic/gen-rust-atomic-helpers.sh 4 + // DO NOT MODIFY THIS FILE DIRECTLY 5 + 6 + /* 7 + * This file provides helpers for the various atomic functions for Rust. 8 + */ 9 + #ifndef _RUST_ATOMIC_API_H 10 + #define _RUST_ATOMIC_API_H 11 + 12 + #include <linux/atomic.h> 13 + 14 + // TODO: Remove this after INLINE_HELPERS support is added. 15 + #ifndef __rust_helper 16 + #define __rust_helper 17 + #endif 18 + 19 + __rust_helper int 20 + rust_helper_atomic_read(const atomic_t *v) 21 + { 22 + return atomic_read(v); 23 + } 24 + 25 + __rust_helper int 26 + rust_helper_atomic_read_acquire(const atomic_t *v) 27 + { 28 + return atomic_read_acquire(v); 29 + } 30 + 31 + __rust_helper void 32 + rust_helper_atomic_set(atomic_t *v, int i) 33 + { 34 + atomic_set(v, i); 35 + } 36 + 37 + __rust_helper void 38 + rust_helper_atomic_set_release(atomic_t *v, int i) 39 + { 40 + atomic_set_release(v, i); 41 + } 42 + 43 + __rust_helper void 44 + rust_helper_atomic_add(int i, atomic_t *v) 45 + { 46 + atomic_add(i, v); 47 + } 48 + 49 + __rust_helper int 50 + rust_helper_atomic_add_return(int i, atomic_t *v) 51 + { 52 + return atomic_add_return(i, v); 53 + } 54 + 55 + __rust_helper int 56 + rust_helper_atomic_add_return_acquire(int i, atomic_t *v) 57 + { 58 + return atomic_add_return_acquire(i, v); 59 + } 60 + 61 + __rust_helper int 62 + rust_helper_atomic_add_return_release(int i, atomic_t *v) 63 + { 64 + return atomic_add_return_release(i, v); 65 + } 66 + 67 + __rust_helper int 68 + rust_helper_atomic_add_return_relaxed(int i, atomic_t *v) 69 + { 70 + return atomic_add_return_relaxed(i, v); 71 + } 72 + 73 + __rust_helper int 74 + rust_helper_atomic_fetch_add(int i, atomic_t *v) 75 + { 76 + return atomic_fetch_add(i, v); 77 + } 78 + 79 + __rust_helper int 80 + rust_helper_atomic_fetch_add_acquire(int i, atomic_t *v) 81 + { 82 + return atomic_fetch_add_acquire(i, v); 83 + } 84 + 85 + __rust_helper int 86 + rust_helper_atomic_fetch_add_release(int i, atomic_t *v) 87 + { 88 + return atomic_fetch_add_release(i, v); 89 + } 90 + 91 + __rust_helper int 92 + rust_helper_atomic_fetch_add_relaxed(int i, atomic_t *v) 93 + { 94 + return atomic_fetch_add_relaxed(i, v); 95 + } 96 + 97 + __rust_helper void 98 + rust_helper_atomic_sub(int i, atomic_t *v) 99 + { 100 + atomic_sub(i, v); 101 + } 102 + 103 + __rust_helper int 104 + rust_helper_atomic_sub_return(int i, atomic_t *v) 105 + { 106 + return atomic_sub_return(i, v); 107 + } 108 + 109 + __rust_helper int 110 + rust_helper_atomic_sub_return_acquire(int i, atomic_t *v) 111 + { 112 + return atomic_sub_return_acquire(i, v); 113 + } 114 + 115 + __rust_helper int 116 + rust_helper_atomic_sub_return_release(int i, atomic_t *v) 117 + { 118 + return atomic_sub_return_release(i, v); 119 + } 120 + 121 + __rust_helper int 122 + rust_helper_atomic_sub_return_relaxed(int i, atomic_t *v) 123 + { 124 + return atomic_sub_return_relaxed(i, v); 125 + } 126 + 127 + __rust_helper int 128 + rust_helper_atomic_fetch_sub(int i, atomic_t *v) 129 + { 130 + return atomic_fetch_sub(i, v); 131 + } 132 + 133 + __rust_helper int 134 + rust_helper_atomic_fetch_sub_acquire(int i, atomic_t *v) 135 + { 136 + return atomic_fetch_sub_acquire(i, v); 137 + } 138 + 139 + __rust_helper int 140 + rust_helper_atomic_fetch_sub_release(int i, atomic_t *v) 141 + { 142 + return atomic_fetch_sub_release(i, v); 143 + } 144 + 145 + __rust_helper int 146 + rust_helper_atomic_fetch_sub_relaxed(int i, atomic_t *v) 147 + { 148 + return atomic_fetch_sub_relaxed(i, v); 149 + } 150 + 151 + __rust_helper void 152 + rust_helper_atomic_inc(atomic_t *v) 153 + { 154 + atomic_inc(v); 155 + } 156 + 157 + __rust_helper int 158 + rust_helper_atomic_inc_return(atomic_t *v) 159 + { 160 + return atomic_inc_return(v); 161 + } 162 + 163 + __rust_helper int 164 + rust_helper_atomic_inc_return_acquire(atomic_t *v) 165 + { 166 + return atomic_inc_return_acquire(v); 167 + } 168 + 169 + __rust_helper int 170 + rust_helper_atomic_inc_return_release(atomic_t *v) 171 + { 172 + return atomic_inc_return_release(v); 173 + } 174 + 175 + __rust_helper int 176 + rust_helper_atomic_inc_return_relaxed(atomic_t *v) 177 + { 178 + return atomic_inc_return_relaxed(v); 179 + } 180 + 181 + __rust_helper int 182 + rust_helper_atomic_fetch_inc(atomic_t *v) 183 + { 184 + return atomic_fetch_inc(v); 185 + } 186 + 187 + __rust_helper int 188 + rust_helper_atomic_fetch_inc_acquire(atomic_t *v) 189 + { 190 + return atomic_fetch_inc_acquire(v); 191 + } 192 + 193 + __rust_helper int 194 + rust_helper_atomic_fetch_inc_release(atomic_t *v) 195 + { 196 + return atomic_fetch_inc_release(v); 197 + } 198 + 199 + __rust_helper int 200 + rust_helper_atomic_fetch_inc_relaxed(atomic_t *v) 201 + { 202 + return atomic_fetch_inc_relaxed(v); 203 + } 204 + 205 + __rust_helper void 206 + rust_helper_atomic_dec(atomic_t *v) 207 + { 208 + atomic_dec(v); 209 + } 210 + 211 + __rust_helper int 212 + rust_helper_atomic_dec_return(atomic_t *v) 213 + { 214 + return atomic_dec_return(v); 215 + } 216 + 217 + __rust_helper int 218 + rust_helper_atomic_dec_return_acquire(atomic_t *v) 219 + { 220 + return atomic_dec_return_acquire(v); 221 + } 222 + 223 + __rust_helper int 224 + rust_helper_atomic_dec_return_release(atomic_t *v) 225 + { 226 + return atomic_dec_return_release(v); 227 + } 228 + 229 + __rust_helper int 230 + rust_helper_atomic_dec_return_relaxed(atomic_t *v) 231 + { 232 + return atomic_dec_return_relaxed(v); 233 + } 234 + 235 + __rust_helper int 236 + rust_helper_atomic_fetch_dec(atomic_t *v) 237 + { 238 + return atomic_fetch_dec(v); 239 + } 240 + 241 + __rust_helper int 242 + rust_helper_atomic_fetch_dec_acquire(atomic_t *v) 243 + { 244 + return atomic_fetch_dec_acquire(v); 245 + } 246 + 247 + __rust_helper int 248 + rust_helper_atomic_fetch_dec_release(atomic_t *v) 249 + { 250 + return atomic_fetch_dec_release(v); 251 + } 252 + 253 + __rust_helper int 254 + rust_helper_atomic_fetch_dec_relaxed(atomic_t *v) 255 + { 256 + return atomic_fetch_dec_relaxed(v); 257 + } 258 + 259 + __rust_helper void 260 + rust_helper_atomic_and(int i, atomic_t *v) 261 + { 262 + atomic_and(i, v); 263 + } 264 + 265 + __rust_helper int 266 + rust_helper_atomic_fetch_and(int i, atomic_t *v) 267 + { 268 + return atomic_fetch_and(i, v); 269 + } 270 + 271 + __rust_helper int 272 + rust_helper_atomic_fetch_and_acquire(int i, atomic_t *v) 273 + { 274 + return atomic_fetch_and_acquire(i, v); 275 + } 276 + 277 + __rust_helper int 278 + rust_helper_atomic_fetch_and_release(int i, atomic_t *v) 279 + { 280 + return atomic_fetch_and_release(i, v); 281 + } 282 + 283 + __rust_helper int 284 + rust_helper_atomic_fetch_and_relaxed(int i, atomic_t *v) 285 + { 286 + return atomic_fetch_and_relaxed(i, v); 287 + } 288 + 289 + __rust_helper void 290 + rust_helper_atomic_andnot(int i, atomic_t *v) 291 + { 292 + atomic_andnot(i, v); 293 + } 294 + 295 + __rust_helper int 296 + rust_helper_atomic_fetch_andnot(int i, atomic_t *v) 297 + { 298 + return atomic_fetch_andnot(i, v); 299 + } 300 + 301 + __rust_helper int 302 + rust_helper_atomic_fetch_andnot_acquire(int i, atomic_t *v) 303 + { 304 + return atomic_fetch_andnot_acquire(i, v); 305 + } 306 + 307 + __rust_helper int 308 + rust_helper_atomic_fetch_andnot_release(int i, atomic_t *v) 309 + { 310 + return atomic_fetch_andnot_release(i, v); 311 + } 312 + 313 + __rust_helper int 314 + rust_helper_atomic_fetch_andnot_relaxed(int i, atomic_t *v) 315 + { 316 + return atomic_fetch_andnot_relaxed(i, v); 317 + } 318 + 319 + __rust_helper void 320 + rust_helper_atomic_or(int i, atomic_t *v) 321 + { 322 + atomic_or(i, v); 323 + } 324 + 325 + __rust_helper int 326 + rust_helper_atomic_fetch_or(int i, atomic_t *v) 327 + { 328 + return atomic_fetch_or(i, v); 329 + } 330 + 331 + __rust_helper int 332 + rust_helper_atomic_fetch_or_acquire(int i, atomic_t *v) 333 + { 334 + return atomic_fetch_or_acquire(i, v); 335 + } 336 + 337 + __rust_helper int 338 + rust_helper_atomic_fetch_or_release(int i, atomic_t *v) 339 + { 340 + return atomic_fetch_or_release(i, v); 341 + } 342 + 343 + __rust_helper int 344 + rust_helper_atomic_fetch_or_relaxed(int i, atomic_t *v) 345 + { 346 + return atomic_fetch_or_relaxed(i, v); 347 + } 348 + 349 + __rust_helper void 350 + rust_helper_atomic_xor(int i, atomic_t *v) 351 + { 352 + atomic_xor(i, v); 353 + } 354 + 355 + __rust_helper int 356 + rust_helper_atomic_fetch_xor(int i, atomic_t *v) 357 + { 358 + return atomic_fetch_xor(i, v); 359 + } 360 + 361 + __rust_helper int 362 + rust_helper_atomic_fetch_xor_acquire(int i, atomic_t *v) 363 + { 364 + return atomic_fetch_xor_acquire(i, v); 365 + } 366 + 367 + __rust_helper int 368 + rust_helper_atomic_fetch_xor_release(int i, atomic_t *v) 369 + { 370 + return atomic_fetch_xor_release(i, v); 371 + } 372 + 373 + __rust_helper int 374 + rust_helper_atomic_fetch_xor_relaxed(int i, atomic_t *v) 375 + { 376 + return atomic_fetch_xor_relaxed(i, v); 377 + } 378 + 379 + __rust_helper int 380 + rust_helper_atomic_xchg(atomic_t *v, int new) 381 + { 382 + return atomic_xchg(v, new); 383 + } 384 + 385 + __rust_helper int 386 + rust_helper_atomic_xchg_acquire(atomic_t *v, int new) 387 + { 388 + return atomic_xchg_acquire(v, new); 389 + } 390 + 391 + __rust_helper int 392 + rust_helper_atomic_xchg_release(atomic_t *v, int new) 393 + { 394 + return atomic_xchg_release(v, new); 395 + } 396 + 397 + __rust_helper int 398 + rust_helper_atomic_xchg_relaxed(atomic_t *v, int new) 399 + { 400 + return atomic_xchg_relaxed(v, new); 401 + } 402 + 403 + __rust_helper int 404 + rust_helper_atomic_cmpxchg(atomic_t *v, int old, int new) 405 + { 406 + return atomic_cmpxchg(v, old, new); 407 + } 408 + 409 + __rust_helper int 410 + rust_helper_atomic_cmpxchg_acquire(atomic_t *v, int old, int new) 411 + { 412 + return atomic_cmpxchg_acquire(v, old, new); 413 + } 414 + 415 + __rust_helper int 416 + rust_helper_atomic_cmpxchg_release(atomic_t *v, int old, int new) 417 + { 418 + return atomic_cmpxchg_release(v, old, new); 419 + } 420 + 421 + __rust_helper int 422 + rust_helper_atomic_cmpxchg_relaxed(atomic_t *v, int old, int new) 423 + { 424 + return atomic_cmpxchg_relaxed(v, old, new); 425 + } 426 + 427 + __rust_helper bool 428 + rust_helper_atomic_try_cmpxchg(atomic_t *v, int *old, int new) 429 + { 430 + return atomic_try_cmpxchg(v, old, new); 431 + } 432 + 433 + __rust_helper bool 434 + rust_helper_atomic_try_cmpxchg_acquire(atomic_t *v, int *old, int new) 435 + { 436 + return atomic_try_cmpxchg_acquire(v, old, new); 437 + } 438 + 439 + __rust_helper bool 440 + rust_helper_atomic_try_cmpxchg_release(atomic_t *v, int *old, int new) 441 + { 442 + return atomic_try_cmpxchg_release(v, old, new); 443 + } 444 + 445 + __rust_helper bool 446 + rust_helper_atomic_try_cmpxchg_relaxed(atomic_t *v, int *old, int new) 447 + { 448 + return atomic_try_cmpxchg_relaxed(v, old, new); 449 + } 450 + 451 + __rust_helper bool 452 + rust_helper_atomic_sub_and_test(int i, atomic_t *v) 453 + { 454 + return atomic_sub_and_test(i, v); 455 + } 456 + 457 + __rust_helper bool 458 + rust_helper_atomic_dec_and_test(atomic_t *v) 459 + { 460 + return atomic_dec_and_test(v); 461 + } 462 + 463 + __rust_helper bool 464 + rust_helper_atomic_inc_and_test(atomic_t *v) 465 + { 466 + return atomic_inc_and_test(v); 467 + } 468 + 469 + __rust_helper bool 470 + rust_helper_atomic_add_negative(int i, atomic_t *v) 471 + { 472 + return atomic_add_negative(i, v); 473 + } 474 + 475 + __rust_helper bool 476 + rust_helper_atomic_add_negative_acquire(int i, atomic_t *v) 477 + { 478 + return atomic_add_negative_acquire(i, v); 479 + } 480 + 481 + __rust_helper bool 482 + rust_helper_atomic_add_negative_release(int i, atomic_t *v) 483 + { 484 + return atomic_add_negative_release(i, v); 485 + } 486 + 487 + __rust_helper bool 488 + rust_helper_atomic_add_negative_relaxed(int i, atomic_t *v) 489 + { 490 + return atomic_add_negative_relaxed(i, v); 491 + } 492 + 493 + __rust_helper int 494 + rust_helper_atomic_fetch_add_unless(atomic_t *v, int a, int u) 495 + { 496 + return atomic_fetch_add_unless(v, a, u); 497 + } 498 + 499 + __rust_helper bool 500 + rust_helper_atomic_add_unless(atomic_t *v, int a, int u) 501 + { 502 + return atomic_add_unless(v, a, u); 503 + } 504 + 505 + __rust_helper bool 506 + rust_helper_atomic_inc_not_zero(atomic_t *v) 507 + { 508 + return atomic_inc_not_zero(v); 509 + } 510 + 511 + __rust_helper bool 512 + rust_helper_atomic_inc_unless_negative(atomic_t *v) 513 + { 514 + return atomic_inc_unless_negative(v); 515 + } 516 + 517 + __rust_helper bool 518 + rust_helper_atomic_dec_unless_positive(atomic_t *v) 519 + { 520 + return atomic_dec_unless_positive(v); 521 + } 522 + 523 + __rust_helper int 524 + rust_helper_atomic_dec_if_positive(atomic_t *v) 525 + { 526 + return atomic_dec_if_positive(v); 527 + } 528 + 529 + __rust_helper s64 530 + rust_helper_atomic64_read(const atomic64_t *v) 531 + { 532 + return atomic64_read(v); 533 + } 534 + 535 + __rust_helper s64 536 + rust_helper_atomic64_read_acquire(const atomic64_t *v) 537 + { 538 + return atomic64_read_acquire(v); 539 + } 540 + 541 + __rust_helper void 542 + rust_helper_atomic64_set(atomic64_t *v, s64 i) 543 + { 544 + atomic64_set(v, i); 545 + } 546 + 547 + __rust_helper void 548 + rust_helper_atomic64_set_release(atomic64_t *v, s64 i) 549 + { 550 + atomic64_set_release(v, i); 551 + } 552 + 553 + __rust_helper void 554 + rust_helper_atomic64_add(s64 i, atomic64_t *v) 555 + { 556 + atomic64_add(i, v); 557 + } 558 + 559 + __rust_helper s64 560 + rust_helper_atomic64_add_return(s64 i, atomic64_t *v) 561 + { 562 + return atomic64_add_return(i, v); 563 + } 564 + 565 + __rust_helper s64 566 + rust_helper_atomic64_add_return_acquire(s64 i, atomic64_t *v) 567 + { 568 + return atomic64_add_return_acquire(i, v); 569 + } 570 + 571 + __rust_helper s64 572 + rust_helper_atomic64_add_return_release(s64 i, atomic64_t *v) 573 + { 574 + return atomic64_add_return_release(i, v); 575 + } 576 + 577 + __rust_helper s64 578 + rust_helper_atomic64_add_return_relaxed(s64 i, atomic64_t *v) 579 + { 580 + return atomic64_add_return_relaxed(i, v); 581 + } 582 + 583 + __rust_helper s64 584 + rust_helper_atomic64_fetch_add(s64 i, atomic64_t *v) 585 + { 586 + return atomic64_fetch_add(i, v); 587 + } 588 + 589 + __rust_helper s64 590 + rust_helper_atomic64_fetch_add_acquire(s64 i, atomic64_t *v) 591 + { 592 + return atomic64_fetch_add_acquire(i, v); 593 + } 594 + 595 + __rust_helper s64 596 + rust_helper_atomic64_fetch_add_release(s64 i, atomic64_t *v) 597 + { 598 + return atomic64_fetch_add_release(i, v); 599 + } 600 + 601 + __rust_helper s64 602 + rust_helper_atomic64_fetch_add_relaxed(s64 i, atomic64_t *v) 603 + { 604 + return atomic64_fetch_add_relaxed(i, v); 605 + } 606 + 607 + __rust_helper void 608 + rust_helper_atomic64_sub(s64 i, atomic64_t *v) 609 + { 610 + atomic64_sub(i, v); 611 + } 612 + 613 + __rust_helper s64 614 + rust_helper_atomic64_sub_return(s64 i, atomic64_t *v) 615 + { 616 + return atomic64_sub_return(i, v); 617 + } 618 + 619 + __rust_helper s64 620 + rust_helper_atomic64_sub_return_acquire(s64 i, atomic64_t *v) 621 + { 622 + return atomic64_sub_return_acquire(i, v); 623 + } 624 + 625 + __rust_helper s64 626 + rust_helper_atomic64_sub_return_release(s64 i, atomic64_t *v) 627 + { 628 + return atomic64_sub_return_release(i, v); 629 + } 630 + 631 + __rust_helper s64 632 + rust_helper_atomic64_sub_return_relaxed(s64 i, atomic64_t *v) 633 + { 634 + return atomic64_sub_return_relaxed(i, v); 635 + } 636 + 637 + __rust_helper s64 638 + rust_helper_atomic64_fetch_sub(s64 i, atomic64_t *v) 639 + { 640 + return atomic64_fetch_sub(i, v); 641 + } 642 + 643 + __rust_helper s64 644 + rust_helper_atomic64_fetch_sub_acquire(s64 i, atomic64_t *v) 645 + { 646 + return atomic64_fetch_sub_acquire(i, v); 647 + } 648 + 649 + __rust_helper s64 650 + rust_helper_atomic64_fetch_sub_release(s64 i, atomic64_t *v) 651 + { 652 + return atomic64_fetch_sub_release(i, v); 653 + } 654 + 655 + __rust_helper s64 656 + rust_helper_atomic64_fetch_sub_relaxed(s64 i, atomic64_t *v) 657 + { 658 + return atomic64_fetch_sub_relaxed(i, v); 659 + } 660 + 661 + __rust_helper void 662 + rust_helper_atomic64_inc(atomic64_t *v) 663 + { 664 + atomic64_inc(v); 665 + } 666 + 667 + __rust_helper s64 668 + rust_helper_atomic64_inc_return(atomic64_t *v) 669 + { 670 + return atomic64_inc_return(v); 671 + } 672 + 673 + __rust_helper s64 674 + rust_helper_atomic64_inc_return_acquire(atomic64_t *v) 675 + { 676 + return atomic64_inc_return_acquire(v); 677 + } 678 + 679 + __rust_helper s64 680 + rust_helper_atomic64_inc_return_release(atomic64_t *v) 681 + { 682 + return atomic64_inc_return_release(v); 683 + } 684 + 685 + __rust_helper s64 686 + rust_helper_atomic64_inc_return_relaxed(atomic64_t *v) 687 + { 688 + return atomic64_inc_return_relaxed(v); 689 + } 690 + 691 + __rust_helper s64 692 + rust_helper_atomic64_fetch_inc(atomic64_t *v) 693 + { 694 + return atomic64_fetch_inc(v); 695 + } 696 + 697 + __rust_helper s64 698 + rust_helper_atomic64_fetch_inc_acquire(atomic64_t *v) 699 + { 700 + return atomic64_fetch_inc_acquire(v); 701 + } 702 + 703 + __rust_helper s64 704 + rust_helper_atomic64_fetch_inc_release(atomic64_t *v) 705 + { 706 + return atomic64_fetch_inc_release(v); 707 + } 708 + 709 + __rust_helper s64 710 + rust_helper_atomic64_fetch_inc_relaxed(atomic64_t *v) 711 + { 712 + return atomic64_fetch_inc_relaxed(v); 713 + } 714 + 715 + __rust_helper void 716 + rust_helper_atomic64_dec(atomic64_t *v) 717 + { 718 + atomic64_dec(v); 719 + } 720 + 721 + __rust_helper s64 722 + rust_helper_atomic64_dec_return(atomic64_t *v) 723 + { 724 + return atomic64_dec_return(v); 725 + } 726 + 727 + __rust_helper s64 728 + rust_helper_atomic64_dec_return_acquire(atomic64_t *v) 729 + { 730 + return atomic64_dec_return_acquire(v); 731 + } 732 + 733 + __rust_helper s64 734 + rust_helper_atomic64_dec_return_release(atomic64_t *v) 735 + { 736 + return atomic64_dec_return_release(v); 737 + } 738 + 739 + __rust_helper s64 740 + rust_helper_atomic64_dec_return_relaxed(atomic64_t *v) 741 + { 742 + return atomic64_dec_return_relaxed(v); 743 + } 744 + 745 + __rust_helper s64 746 + rust_helper_atomic64_fetch_dec(atomic64_t *v) 747 + { 748 + return atomic64_fetch_dec(v); 749 + } 750 + 751 + __rust_helper s64 752 + rust_helper_atomic64_fetch_dec_acquire(atomic64_t *v) 753 + { 754 + return atomic64_fetch_dec_acquire(v); 755 + } 756 + 757 + __rust_helper s64 758 + rust_helper_atomic64_fetch_dec_release(atomic64_t *v) 759 + { 760 + return atomic64_fetch_dec_release(v); 761 + } 762 + 763 + __rust_helper s64 764 + rust_helper_atomic64_fetch_dec_relaxed(atomic64_t *v) 765 + { 766 + return atomic64_fetch_dec_relaxed(v); 767 + } 768 + 769 + __rust_helper void 770 + rust_helper_atomic64_and(s64 i, atomic64_t *v) 771 + { 772 + atomic64_and(i, v); 773 + } 774 + 775 + __rust_helper s64 776 + rust_helper_atomic64_fetch_and(s64 i, atomic64_t *v) 777 + { 778 + return atomic64_fetch_and(i, v); 779 + } 780 + 781 + __rust_helper s64 782 + rust_helper_atomic64_fetch_and_acquire(s64 i, atomic64_t *v) 783 + { 784 + return atomic64_fetch_and_acquire(i, v); 785 + } 786 + 787 + __rust_helper s64 788 + rust_helper_atomic64_fetch_and_release(s64 i, atomic64_t *v) 789 + { 790 + return atomic64_fetch_and_release(i, v); 791 + } 792 + 793 + __rust_helper s64 794 + rust_helper_atomic64_fetch_and_relaxed(s64 i, atomic64_t *v) 795 + { 796 + return atomic64_fetch_and_relaxed(i, v); 797 + } 798 + 799 + __rust_helper void 800 + rust_helper_atomic64_andnot(s64 i, atomic64_t *v) 801 + { 802 + atomic64_andnot(i, v); 803 + } 804 + 805 + __rust_helper s64 806 + rust_helper_atomic64_fetch_andnot(s64 i, atomic64_t *v) 807 + { 808 + return atomic64_fetch_andnot(i, v); 809 + } 810 + 811 + __rust_helper s64 812 + rust_helper_atomic64_fetch_andnot_acquire(s64 i, atomic64_t *v) 813 + { 814 + return atomic64_fetch_andnot_acquire(i, v); 815 + } 816 + 817 + __rust_helper s64 818 + rust_helper_atomic64_fetch_andnot_release(s64 i, atomic64_t *v) 819 + { 820 + return atomic64_fetch_andnot_release(i, v); 821 + } 822 + 823 + __rust_helper s64 824 + rust_helper_atomic64_fetch_andnot_relaxed(s64 i, atomic64_t *v) 825 + { 826 + return atomic64_fetch_andnot_relaxed(i, v); 827 + } 828 + 829 + __rust_helper void 830 + rust_helper_atomic64_or(s64 i, atomic64_t *v) 831 + { 832 + atomic64_or(i, v); 833 + } 834 + 835 + __rust_helper s64 836 + rust_helper_atomic64_fetch_or(s64 i, atomic64_t *v) 837 + { 838 + return atomic64_fetch_or(i, v); 839 + } 840 + 841 + __rust_helper s64 842 + rust_helper_atomic64_fetch_or_acquire(s64 i, atomic64_t *v) 843 + { 844 + return atomic64_fetch_or_acquire(i, v); 845 + } 846 + 847 + __rust_helper s64 848 + rust_helper_atomic64_fetch_or_release(s64 i, atomic64_t *v) 849 + { 850 + return atomic64_fetch_or_release(i, v); 851 + } 852 + 853 + __rust_helper s64 854 + rust_helper_atomic64_fetch_or_relaxed(s64 i, atomic64_t *v) 855 + { 856 + return atomic64_fetch_or_relaxed(i, v); 857 + } 858 + 859 + __rust_helper void 860 + rust_helper_atomic64_xor(s64 i, atomic64_t *v) 861 + { 862 + atomic64_xor(i, v); 863 + } 864 + 865 + __rust_helper s64 866 + rust_helper_atomic64_fetch_xor(s64 i, atomic64_t *v) 867 + { 868 + return atomic64_fetch_xor(i, v); 869 + } 870 + 871 + __rust_helper s64 872 + rust_helper_atomic64_fetch_xor_acquire(s64 i, atomic64_t *v) 873 + { 874 + return atomic64_fetch_xor_acquire(i, v); 875 + } 876 + 877 + __rust_helper s64 878 + rust_helper_atomic64_fetch_xor_release(s64 i, atomic64_t *v) 879 + { 880 + return atomic64_fetch_xor_release(i, v); 881 + } 882 + 883 + __rust_helper s64 884 + rust_helper_atomic64_fetch_xor_relaxed(s64 i, atomic64_t *v) 885 + { 886 + return atomic64_fetch_xor_relaxed(i, v); 887 + } 888 + 889 + __rust_helper s64 890 + rust_helper_atomic64_xchg(atomic64_t *v, s64 new) 891 + { 892 + return atomic64_xchg(v, new); 893 + } 894 + 895 + __rust_helper s64 896 + rust_helper_atomic64_xchg_acquire(atomic64_t *v, s64 new) 897 + { 898 + return atomic64_xchg_acquire(v, new); 899 + } 900 + 901 + __rust_helper s64 902 + rust_helper_atomic64_xchg_release(atomic64_t *v, s64 new) 903 + { 904 + return atomic64_xchg_release(v, new); 905 + } 906 + 907 + __rust_helper s64 908 + rust_helper_atomic64_xchg_relaxed(atomic64_t *v, s64 new) 909 + { 910 + return atomic64_xchg_relaxed(v, new); 911 + } 912 + 913 + __rust_helper s64 914 + rust_helper_atomic64_cmpxchg(atomic64_t *v, s64 old, s64 new) 915 + { 916 + return atomic64_cmpxchg(v, old, new); 917 + } 918 + 919 + __rust_helper s64 920 + rust_helper_atomic64_cmpxchg_acquire(atomic64_t *v, s64 old, s64 new) 921 + { 922 + return atomic64_cmpxchg_acquire(v, old, new); 923 + } 924 + 925 + __rust_helper s64 926 + rust_helper_atomic64_cmpxchg_release(atomic64_t *v, s64 old, s64 new) 927 + { 928 + return atomic64_cmpxchg_release(v, old, new); 929 + } 930 + 931 + __rust_helper s64 932 + rust_helper_atomic64_cmpxchg_relaxed(atomic64_t *v, s64 old, s64 new) 933 + { 934 + return atomic64_cmpxchg_relaxed(v, old, new); 935 + } 936 + 937 + __rust_helper bool 938 + rust_helper_atomic64_try_cmpxchg(atomic64_t *v, s64 *old, s64 new) 939 + { 940 + return atomic64_try_cmpxchg(v, old, new); 941 + } 942 + 943 + __rust_helper bool 944 + rust_helper_atomic64_try_cmpxchg_acquire(atomic64_t *v, s64 *old, s64 new) 945 + { 946 + return atomic64_try_cmpxchg_acquire(v, old, new); 947 + } 948 + 949 + __rust_helper bool 950 + rust_helper_atomic64_try_cmpxchg_release(atomic64_t *v, s64 *old, s64 new) 951 + { 952 + return atomic64_try_cmpxchg_release(v, old, new); 953 + } 954 + 955 + __rust_helper bool 956 + rust_helper_atomic64_try_cmpxchg_relaxed(atomic64_t *v, s64 *old, s64 new) 957 + { 958 + return atomic64_try_cmpxchg_relaxed(v, old, new); 959 + } 960 + 961 + __rust_helper bool 962 + rust_helper_atomic64_sub_and_test(s64 i, atomic64_t *v) 963 + { 964 + return atomic64_sub_and_test(i, v); 965 + } 966 + 967 + __rust_helper bool 968 + rust_helper_atomic64_dec_and_test(atomic64_t *v) 969 + { 970 + return atomic64_dec_and_test(v); 971 + } 972 + 973 + __rust_helper bool 974 + rust_helper_atomic64_inc_and_test(atomic64_t *v) 975 + { 976 + return atomic64_inc_and_test(v); 977 + } 978 + 979 + __rust_helper bool 980 + rust_helper_atomic64_add_negative(s64 i, atomic64_t *v) 981 + { 982 + return atomic64_add_negative(i, v); 983 + } 984 + 985 + __rust_helper bool 986 + rust_helper_atomic64_add_negative_acquire(s64 i, atomic64_t *v) 987 + { 988 + return atomic64_add_negative_acquire(i, v); 989 + } 990 + 991 + __rust_helper bool 992 + rust_helper_atomic64_add_negative_release(s64 i, atomic64_t *v) 993 + { 994 + return atomic64_add_negative_release(i, v); 995 + } 996 + 997 + __rust_helper bool 998 + rust_helper_atomic64_add_negative_relaxed(s64 i, atomic64_t *v) 999 + { 1000 + return atomic64_add_negative_relaxed(i, v); 1001 + } 1002 + 1003 + __rust_helper s64 1004 + rust_helper_atomic64_fetch_add_unless(atomic64_t *v, s64 a, s64 u) 1005 + { 1006 + return atomic64_fetch_add_unless(v, a, u); 1007 + } 1008 + 1009 + __rust_helper bool 1010 + rust_helper_atomic64_add_unless(atomic64_t *v, s64 a, s64 u) 1011 + { 1012 + return atomic64_add_unless(v, a, u); 1013 + } 1014 + 1015 + __rust_helper bool 1016 + rust_helper_atomic64_inc_not_zero(atomic64_t *v) 1017 + { 1018 + return atomic64_inc_not_zero(v); 1019 + } 1020 + 1021 + __rust_helper bool 1022 + rust_helper_atomic64_inc_unless_negative(atomic64_t *v) 1023 + { 1024 + return atomic64_inc_unless_negative(v); 1025 + } 1026 + 1027 + __rust_helper bool 1028 + rust_helper_atomic64_dec_unless_positive(atomic64_t *v) 1029 + { 1030 + return atomic64_dec_unless_positive(v); 1031 + } 1032 + 1033 + __rust_helper s64 1034 + rust_helper_atomic64_dec_if_positive(atomic64_t *v) 1035 + { 1036 + return atomic64_dec_if_positive(v); 1037 + } 1038 + 1039 + #endif /* _RUST_ATOMIC_API_H */ 1040 + // 615a0e0c98b5973a47fe4fa65e92935051ca00ed
+1
rust/helpers/helpers.c
··· 7 7 * Sorted alphabetically. 8 8 */ 9 9 10 + #include "atomic.c" 10 11 #include "auxiliary.c" 11 12 #include "blk.c" 12 13 #include "bug.c"
+1
scripts/atomic/gen-atomics.sh
··· 11 11 gen-atomic-instrumented.sh linux/atomic/atomic-instrumented.h 12 12 gen-atomic-long.sh linux/atomic/atomic-long.h 13 13 gen-atomic-fallback.sh linux/atomic/atomic-arch-fallback.h 14 + gen-rust-atomic-helpers.sh ../rust/helpers/atomic.c 14 15 EOF 15 16 while read script header args; do 16 17 /bin/sh ${ATOMICDIR}/${script} ${ATOMICTBL} ${args} > ${LINUXDIR}/include/${header}
+67
scripts/atomic/gen-rust-atomic-helpers.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + ATOMICDIR=$(dirname $0) 5 + 6 + . ${ATOMICDIR}/atomic-tbl.sh 7 + 8 + #gen_proto_order_variant(meta, pfx, name, sfx, order, atomic, int, arg...) 9 + gen_proto_order_variant() 10 + { 11 + local meta="$1"; shift 12 + local pfx="$1"; shift 13 + local name="$1"; shift 14 + local sfx="$1"; shift 15 + local order="$1"; shift 16 + local atomic="$1"; shift 17 + local int="$1"; shift 18 + 19 + local atomicname="${atomic}_${pfx}${name}${sfx}${order}" 20 + 21 + local ret="$(gen_ret_type "${meta}" "${int}")" 22 + local params="$(gen_params "${int}" "${atomic}" "$@")" 23 + local args="$(gen_args "$@")" 24 + local retstmt="$(gen_ret_stmt "${meta}")" 25 + 26 + cat <<EOF 27 + __rust_helper ${ret} 28 + rust_helper_${atomicname}(${params}) 29 + { 30 + ${retstmt}${atomicname}(${args}); 31 + } 32 + 33 + EOF 34 + } 35 + 36 + cat << EOF 37 + // SPDX-License-Identifier: GPL-2.0 38 + 39 + // Generated by $0 40 + // DO NOT MODIFY THIS FILE DIRECTLY 41 + 42 + /* 43 + * This file provides helpers for the various atomic functions for Rust. 44 + */ 45 + #ifndef _RUST_ATOMIC_API_H 46 + #define _RUST_ATOMIC_API_H 47 + 48 + #include <linux/atomic.h> 49 + 50 + // TODO: Remove this after INLINE_HELPERS support is added. 51 + #ifndef __rust_helper 52 + #define __rust_helper 53 + #endif 54 + 55 + EOF 56 + 57 + grep '^[a-z]' "$1" | while read name meta args; do 58 + gen_proto "${meta}" "${name}" "atomic" "int" ${args} 59 + done 60 + 61 + grep '^[a-z]' "$1" | while read name meta args; do 62 + gen_proto "${meta}" "${name}" "atomic64" "s64" ${args} 63 + done 64 + 65 + cat <<EOF 66 + #endif /* _RUST_ATOMIC_API_H */ 67 + EOF