Skip to contentSkip to conversation

`zerocopy` support

PATCH Applied Miguel Ojeda 6 participants 30 messages Jun 8 – Jun 12

Subsystems (6)
DRM drivers Kbuild Rust DRM Rust +2 more subsystems
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

v2 cover `zerocopy` support

This patch series introduces support for zerocopy:

Fast, safe, compile error. Pick two.

Zerocopy makes zero-cost memory manipulation effortless. We write unsafe so you don't have to.

It essentially provides derivable traits (e.g. FromBytes) and macros (e.g. transmute!) for safely converting between byte sequences and other types. Having such support allows us to remove some unsafe code.

It is among the most downloaded Rust crates (top #50 recent, top #100 all-time downloads; according to crates.io), and it is also used by the Rust compiler itself.

The series starts with a few preparation commits, then the zerocopy and zerocopy-derive crates are added. Finally, an example patch using it is on top, removing one unsafe impl.

I had to adapt the crates slightly (just +2/-3 lines), but both patches could potentially be provided upstream eventually. Please see the commits for details.

In total, it is about ~39k lines added, ~32k without counting benches/ which are just for documentation purposes.

See the cover letter for syn for some more details about depending on third-party crates in commit 54e3eae85562 ("Merge patch series "syn support"").

The codegen of an isolated example function similar to the patch on top is essentially identical. It also turns out that (for that particular case) zerocopy's version, even under debug-assertions enabled, has no remaining panics, unlike a few in the current code (because the compiler can prove the remaining ub_checks statically).

So their "fast, safe" does indeed check out -- at least in that case.

P.S. This version of zerocopy has already the unstable Ptr{,Inner} types -- to play with them, please use:

make ... KRUSTFLAGS=--cfg=zerocopy_unstable_ptr

---
I will apply v2 for tomorrow's linux-next.

v2:
- Added zerocopy{,_derive}::FromBytes to prelude (new commit).
- Avoid qualified names in the nova-core example as discussed.
- Add rustc_target_envs to more commands for completeness.
- Simplify using dictionary unpacking.
- Added details and links about the upstream issues and PRs filed and the latest state on the discussion around our crate tweaks.
- Update Jack's email.

v1: https://lore.kernel.org/rust-for-linux/[email protected]/

Miguel Ojeda (19):
scripts: generate_rust_analyzer: support passing env vars
rust: kbuild: show the right quiet_cmd_rustc_procmacrolibrary
rust: kbuild: remove unused variable
rust: kbuild: define procmacro-name function
rust: kbuild: define procmacro-extension variable
rust: kbuild: support per-target environment variables
rust: kbuild: support skip_clippy for rustc_procmacro
rust: zerocopy: import crate
rust: zerocopy: add SPDX License Identifiers
rust: zerocopy: remove float Display support
rust: zerocopy: add README.md
rust: zerocopy: enable support in kbuild
rust: zerocopy-derive: import crate
rust: zerocopy-derive: add SPDX License Identifiers
rust: zerocopy-derive: avoid generating non-ASCII identifiers
rust: zerocopy-derive: add README.md
rust: zerocopy-derive: enable support in kbuild
rust: prelude: add zerocopy{,_derive}::FromBytes
gpu: nova-core: firmware: parse FalconUCodeDescV2 via zerocopy

 Makefile                                      |    2 +
 drivers/gpu/nova-core/firmware.rs             |    5 +-
 drivers/gpu/nova-core/vbios.rs                |    6 +-
 rust/Makefile                                 |   96 +-
 rust/kernel/prelude.rs                        |    6 +
 rust/zerocopy-derive/README.md                |   14 +
 rust/zerocopy-derive/derive/from_bytes.rs     |  192 +
 rust/zerocopy-derive/derive/into_bytes.rs     |  164 +
 rust/zerocopy-derive/derive/known_layout.rs   |  350 +
 rust/zerocopy-derive/derive/mod.rs            |  132 +
 rust/zerocopy-derive/derive/try_from_bytes.rs |  765 ++
 rust/zerocopy-derive/derive/unaligned.rs      |   80 +
 rust/zerocopy-derive/lib.rs                   |  146 +
 rust/zerocopy-derive/repr.rs                  |  851 ++
 rust/zerocopy-derive/util.rs                  |  845 ++
 rust/zerocopy/README.md                       |   14 +
 .../zerocopy/benches/as_bytes_dynamic_size.rs |    9 +
 .../benches/as_bytes_dynamic_size.x86-64      |    5 +
 .../benches/as_bytes_dynamic_size.x86-64.mca  |   47 +
 rust/zerocopy/benches/as_bytes_static_size.rs |    9 +
 .../benches/as_bytes_static_size.x86-64       |    4 +
 .../benches/as_bytes_static_size.x86-64.mca   |   45 +
 rust/zerocopy/benches/extend_vec_zeroed.rs    |    9 +
 .../zerocopy/benches/extend_vec_zeroed.x86-64 |   60 +
 .../benches/extend_vec_zeroed.x86-64.mca      |  147 +
 .../benches/formats/coco_dynamic_padding.rs   |   24 +
 .../benches/formats/coco_dynamic_size.rs      |   27 +
 .../benches/formats/coco_static_size.rs       |   27 +
 rust/zerocopy/benches/insert_vec_zeroed.rs    |   13 +
 .../zerocopy/benches/insert_vec_zeroed.x86-64 |   79 +
 .../benches/insert_vec_zeroed.x86-64.mca      |  183 +
 rust/zerocopy/benches/new_box_zeroed.rs       |    9 +
 rust/zerocopy/benches/new_box_zeroed.x86-64   |    7 +
 .../benches/new_box_zeroed.x86-64.mca         |   51 +
 ...w_box_zeroed_with_elems_dynamic_padding.rs |   11 +
 ...x_zeroed_with_elems_dynamic_padding.x86-64 |   24 +
 ...roed_with_elems_dynamic_padding.x86-64.mca |   81 +
 .../new_box_zeroed_with_elems_dynamic_size.rs |    9 +
 ..._box_zeroed_with_elems_dynamic_size.x86-64 |   22 +
 ..._zeroed_with_elems_dynamic_size.x86-64.mca |   77 +
 rust/zerocopy/benches/new_vec_zeroed.rs       |    9 +
 rust/zerocopy/benches/new_vec_zeroed.x86-64   |   40 +
 .../benches/new_vec_zeroed.x86-64.mca         |  113 +
 rust/zerocopy/benches/new_zeroed.rs           |    9 +
 rust/zerocopy/benches/new_zeroed.x86-64       |    3 +
 rust/zerocopy/benches/new_zeroed.x86-64.mca   |   43 +
 rust/zerocopy/benches/read_from_bytes.rs      |    7 +
 rust/zerocopy/benches/read_from_bytes.x86-64  |   15 +
 .../benches/read_from_bytes.x86-64.mca        |   65 +
 rust/zerocopy/benches/read_from_prefix.rs     |   10 +
 rust/zerocopy/benches/read_from_prefix.x86-64 |   14 +
 .../benches/read_from_prefix.x86-64.mca       |   63 +
 rust/zerocopy/benches/read_from_suffix.rs     |   10 +
 rust/zerocopy/benches/read_from_suffix.x86-64 |   15 +
 .../benches/read_from_suffix.x86-64.mca       |   65 +
 .../benches/ref_from_bytes_dynamic_padding.rs |    7 +
 .../ref_from_bytes_dynamic_padding.x86-64     |   22 +
 .../ref_from_bytes_dynamic_padding.x86-64.mca |   77 +
 .../benches/ref_from_bytes_dynamic_size.rs    |    7 +
 .../ref_from_bytes_dynamic_size.x86-64        |   20 +
 .../ref_from_bytes_dynamic_size.x86-64.mca    |   75 +
 .../benches/ref_from_bytes_static_size.rs     |    7 +
 .../benches/ref_from_bytes_static_size.x86-64 |    8 +
 .../ref_from_bytes_static_size.x86-64.mca     |   53 +
 ...f_from_bytes_with_elems_dynamic_padding.rs |   10 +
 ...om_bytes_with_elems_dynamic_padding.x86-64 |   19 +
 ...ytes_with_elems_dynamic_padding.x86-64.mca |   71 +
 .../ref_from_bytes_with_elems_dynamic_size.rs |   10 +
 ..._from_bytes_with_elems_dynamic_size.x86-64 |   16 +
 ...m_bytes_with_elems_dynamic_size.x86-64.mca |   65 +
 .../ref_from_prefix_dynamic_padding.rs        |   10 +
 .../ref_from_prefix_dynamic_padding.x86-64    |   22 +
 ...ref_from_prefix_dynamic_padding.x86-64.mca |   77 +
 .../benches/ref_from_prefix_dynamic_size.rs   |   10 +
 .../ref_from_prefix_dynamic_size.x86-64       |   17 +
 .../ref_from_prefix_dynamic_size.x86-64.mca   |   67 +
 .../benches/ref_from_prefix_static_size.rs    |   10 +
 .../ref_from_prefix_static_size.x86-64        |    8 +
 .../ref_from_prefix_static_size.x86-64.mca    |   53 +
 ..._from_prefix_with_elems_dynamic_padding.rs |   13 +
 ...m_prefix_with_elems_dynamic_padding.x86-64 |   26 +
 ...efix_with_elems_dynamic_padding.x86-64.mca |   85 +
 ...ref_from_prefix_with_elems_dynamic_size.rs |   13 +
 ...from_prefix_with_elems_dynamic_size.x86-64 |   22 +
 ..._prefix_with_elems_dynamic_size.x86-64.mca |   77 +
 .../ref_from_suffix_dynamic_padding.rs        |   10 +
 .../ref_from_suffix_dynamic_padding.x86-64    |   23 +
 ...ref_from_suffix_dynamic_padding.x86-64.mca |   79 +
 .../benches/ref_from_suffix_dynamic_size.rs   |   10 +
 .../ref_from_suffix_dynamic_size.x86-64       |   13 +
 .../ref_from_suffix_dynamic_size.x86-64.mca   |   63 +
 .../benches/ref_from_suffix_static_size.rs    |   10 +
 .../ref_from_suffix_static_size.x86-64        |   13 +
 .../ref_from_suffix_static_size.x86-64.mca    |   61 +
 ..._from_suffix_with_elems_dynamic_padding.rs |   13 +
 ...m_suffix_with_elems_dynamic_padding.x86-64 |   27 +
 ...ffix_with_elems_dynamic_padding.x86-64.mca |   85 +
 ...ref_from_suffix_with_elems_dynamic_size.rs |   13 +
 ...from_suffix_with_elems_dynamic_size.x86-64 |   23 +
 ..._suffix_with_elems_dynamic_size.x86-64.mca |   77 +
 .../benches/split_at_dynamic_padding.rs       |   12 +
 .../benches/split_at_dynamic_padding.x86-64   |   12 +
 .../split_at_dynamic_padding.x86-64.mca       |   59 +
 .../zerocopy/benches/split_at_dynamic_size.rs |   12 +
 .../benches/split_at_dynamic_size.x86-64      |   12 +
 .../benches/split_at_dynamic_size.x86-64.mca  |   59 +
 .../split_at_unchecked_dynamic_padding.rs     |   12 +
 .../split_at_unchecked_dynamic_padding.x86-64 |    6 +
 ...it_at_unchecked_dynamic_padding.x86-64.mca |   49 +
 .../split_at_unchecked_dynamic_size.rs        |   12 +
 .../split_at_unchecked_dynamic_size.x86-64    |    6 +
 ...split_at_unchecked_dynamic_size.x86-64.mca |   49 +
 .../split_via_immutable_dynamic_padding.rs    |   11 +
 ...split_via_immutable_dynamic_padding.x86-64 |   14 +
 ...t_via_immutable_dynamic_padding.x86-64.mca |   65 +
 .../split_via_immutable_dynamic_size.rs       |   11 +
 .../split_via_immutable_dynamic_size.x86-64   |   13 +
 ...plit_via_immutable_dynamic_size.x86-64.mca |   63 +
 ...split_via_runtime_check_dynamic_padding.rs |   11 +
 ...t_via_runtime_check_dynamic_padding.x86-64 |   22 +
 ...a_runtime_check_dynamic_padding.x86-64.mca |   79 +
 .../split_via_runtime_check_dynamic_size.rs   |   11 +
 ...plit_via_runtime_check_dynamic_size.x86-64 |   13 +
 ..._via_runtime_check_dynamic_size.x86-64.mca |   63 +
 .../split_via_unchecked_dynamic_padding.rs    |   11 +
 ...split_via_unchecked_dynamic_padding.x86-64 |   14 +
 ...t_via_unchecked_dynamic_padding.x86-64.mca |   65 +
 .../split_via_unchecked_dynamic_size.rs       |   11 +
 .../split_via_unchecked_dynamic_size.x86-64   |   13 +
 ...plit_via_unchecked_dynamic_size.x86-64.mca |   63 +
 rust/zerocopy/benches/transmute.rs            |   16 +
 rust/zerocopy/benches/transmute.x86-64        |    3 +
 rust/zerocopy/benches/transmute.x86-64.mca    |   43 +
 .../benches/transmute_ref_dynamic_size.rs     |   16 +
 .../benches/transmute_ref_dynamic_size.x86-64 |    4 +
 .../transmute_ref_dynamic_size.x86-64.mca     |   45 +
 .../benches/transmute_ref_static_size.rs      |   15 +
 .../benches/transmute_ref_static_size.x86-64  |    3 +
 .../transmute_ref_static_size.x86-64.mca      |   43 +
 rust/zerocopy/benches/try_read_from_bytes.rs  |    7 +
 .../benches/try_read_from_bytes.x86-64        |   23 +
 .../benches/try_read_from_bytes.x86-64.mca    |   79 +
 rust/zerocopy/benches/try_read_from_prefix.rs |   10 +
 .../benches/try_read_from_prefix.x86-64       |   16 +
 .../benches/try_read_from_prefix.x86-64.mca   |   67 +
 rust/zerocopy/benches/try_read_from_suffix.rs |   10 +
 .../benches/try_read_from_suffix.x86-64       |   18 +
 .../benches/try_read_from_suffix.x86-64.mca   |   71 +
 .../try_ref_from_bytes_dynamic_padding.rs     |    7 +
 .../try_ref_from_bytes_dynamic_padding.x86-64 |   24 +
 ..._ref_from_bytes_dynamic_padding.x86-64.mca |   81 +
 .../try_ref_from_bytes_dynamic_size.rs        |    7 +
 .../try_ref_from_bytes_dynamic_size.x86-64    |   22 +
 ...try_ref_from_bytes_dynamic_size.x86-64.mca |   79 +
 .../benches/try_ref_from_bytes_static_size.rs |    7 +
 .../try_ref_from_bytes_static_size.x86-64     |   13 +
 .../try_ref_from_bytes_static_size.x86-64.mca |   59 +
 ...f_from_bytes_with_elems_dynamic_padding.rs |   10 +
 ...om_bytes_with_elems_dynamic_padding.x86-64 |   21 +
 ...ytes_with_elems_dynamic_padding.x86-64.mca |   75 +
 ..._ref_from_bytes_with_elems_dynamic_size.rs |   10 +
 ..._from_bytes_with_elems_dynamic_size.x86-64 |   18 +
 ...m_bytes_with_elems_dynamic_size.x86-64.mca |   69 +
 .../try_ref_from_prefix_dynamic_padding.rs    |   10 +
 ...try_ref_from_prefix_dynamic_padding.x86-64 |   29 +
 ...ref_from_prefix_dynamic_padding.x86-64.mca |   91 +
 .../try_ref_from_prefix_dynamic_size.rs       |   10 +
 .../try_ref_from_prefix_dynamic_size.x86-64   |   22 +
 ...ry_ref_from_prefix_dynamic_size.x86-64.mca |   77 +
 .../try_ref_from_prefix_static_size.rs        |   10 +
 .../try_ref_from_prefix_static_size.x86-64    |   15 +
 ...try_ref_from_prefix_static_size.x86-64.mca |   63 +
 ..._from_prefix_with_elems_dynamic_padding.rs |   13 +
 ...m_prefix_with_elems_dynamic_padding.x86-64 |   30 +
 ...efix_with_elems_dynamic_padding.x86-64.mca |   91 +
 ...ref_from_prefix_with_elems_dynamic_size.rs |   13 +
 ...from_prefix_with_elems_dynamic_size.x86-64 |   26 +
 ..._prefix_with_elems_dynamic_size.x86-64.mca |   83 +
 .../try_ref_from_suffix_dynamic_padding.rs    |   10 +
 ...try_ref_from_suffix_dynamic_padding.x86-64 |   26 +
 ...ref_from_suffix_dynamic_padding.x86-64.mca |   85 +
 .../try_ref_from_suffix_dynamic_size.rs       |   10 +
 .../try_ref_from_suffix_dynamic_size.x86-64   |   18 +
 ...ry_ref_from_suffix_dynamic_size.x86-64.mca |   71 +
 .../try_ref_from_suffix_static_size.rs        |   10 +
 .../try_ref_from_suffix_static_size.x86-64    |   16 +
 ...try_ref_from_suffix_static_size.x86-64.mca |   67 +
 ..._from_suffix_with_elems_dynamic_padding.rs |   13 +
 ...m_suffix_with_elems_dynamic_padding.x86-64 |   32 +
 ...ffix_with_elems_dynamic_padding.x86-64.mca |   95 +
 ...ref_from_suffix_with_elems_dynamic_size.rs |   13 +
 ...from_suffix_with_elems_dynamic_size.x86-64 |   28 +
 ..._suffix_with_elems_dynamic_size.x86-64.mca |   87 +
 rust/zerocopy/benches/try_transmute.rs        |   16 +
 rust/zerocopy/benches/try_transmute.x86-64    |    9 +
 .../zerocopy/benches/try_transmute.x86-64.mca |   55 +
 .../benches/try_transmute_ref_dynamic_size.rs |   18 +
 .../try_transmute_ref_dynamic_size.x86-64     |    6 +
 .../try_transmute_ref_dynamic_size.x86-64.mca |   49 +
 .../benches/try_transmute_ref_static_size.rs  |   17 +
 .../try_transmute_ref_static_size.x86-64      |    5 +
 .../try_transmute_ref_static_size.x86-64.mca  |   47 +
 .../zerocopy/benches/write_to_dynamic_size.rs |    9 +
 .../benches/write_to_dynamic_size.x86-64      |   21 +
 .../benches/write_to_dynamic_size.x86-64.mca  |   77 +
 .../benches/write_to_prefix_dynamic_size.rs   |   12 +
 .../write_to_prefix_dynamic_size.x86-64       |   21 +
 .../write_to_prefix_dynamic_size.x86-64.mca   |   77 +
 .../benches/write_to_prefix_static_size.rs    |   12 +
 .../write_to_prefix_static_size.x86-64        |   11 +
 .../write_to_prefix_static_size.x86-64.mca    |   57 +
 rust/zerocopy/benches/write_to_static_size.rs |    9 +
 .../benches/write_to_static_size.x86-64       |   11 +
 .../benches/write_to_static_size.x86-64.mca   |   57 +
 .../benches/write_to_suffix_dynamic_size.rs   |   12 +
 .../write_to_suffix_dynamic_size.x86-64       |   22 +
 .../write_to_suffix_dynamic_size.x86-64.mca   |   79 +
 .../benches/write_to_suffix_static_size.rs    |   12 +
 .../write_to_suffix_static_size.x86-64        |   11 +
 .../write_to_suffix_static_size.x86-64.mca    |   57 +
 rust/zerocopy/benches/zero_dynamic_padding.rs |    9 +
 .../benches/zero_dynamic_padding.x86-64       |    7 +
 .../benches/zero_dynamic_padding.x86-64.mca   |   51 +
 rust/zerocopy/benches/zero_dynamic_size.rs    |    9 +
 .../zerocopy/benches/zero_dynamic_size.x86-64 |    5 +
 .../benches/zero_dynamic_size.x86-64.mca      |   47 +
 rust/zerocopy/benches/zero_static_size.rs     |    9 +
 rust/zerocopy/benches/zero_static_size.x86-64 |    4 +
 .../benches/zero_static_size.x86-64.mca       |   45 +
 rust/zerocopy/rustdoc/style.css               |   57 +
 rust/zerocopy/src/byte_slice.rs               |  434 +
 rust/zerocopy/src/byteorder.rs                | 1564 ++++
 rust/zerocopy/src/deprecated.rs               |  281 +
 rust/zerocopy/src/error.rs                    | 1350 +++
 rust/zerocopy/src/impls.rs                    | 2389 ++++++
 rust/zerocopy/src/layout.rs                   | 2225 +++++
 rust/zerocopy/src/lib.rs                      | 7612 +++++++++++++++++
 rust/zerocopy/src/macros.rs                   | 1825 ++++
 rust/zerocopy/src/pointer/inner.rs            |  754 ++
 rust/zerocopy/src/pointer/invariant.rs        |  298 +
 rust/zerocopy/src/pointer/mod.rs              |  410 +
 rust/zerocopy/src/pointer/ptr.rs              | 1586 ++++
 rust/zerocopy/src/pointer/transmute.rs        |  522 ++
 rust/zerocopy/src/ref.rs                      | 1358 +++
 rust/zerocopy/src/split_at.rs                 | 1090 +++
 rust/zerocopy/src/util/macro_util.rs          | 1310 +++
 rust/zerocopy/src/util/macros.rs              | 1067 +++
 rust/zerocopy/src/util/mod.rs                 |  938 ++
 rust/zerocopy/src/wrappers.rs                 | 1034 +++
 scripts/Makefile.build                        |    1 +
 scripts/generate_rust_analyzer.py             |   38 +-
 251 files changed, 38724 insertions(+), 27 deletions(-)
 create mode 100644 rust/zerocopy-derive/README.md
 create mode 100644 rust/zerocopy-derive/derive/from_bytes.rs
 create mode 100644 rust/zerocopy-derive/derive/into_bytes.rs
 create mode 100644 rust/zerocopy-derive/derive/known_layout.rs
 create mode 100644 rust/zerocopy-derive/derive/mod.rs
 create mode 100644 rust/zerocopy-derive/derive/try_from_bytes.rs
 create mode 100644 rust/zerocopy-derive/derive/unaligned.rs
 create mode 100644 rust/zerocopy-derive/lib.rs
 create mode 100644 rust/zerocopy-derive/repr.rs
 create mode 100644 rust/zerocopy-derive/util.rs
 create mode 100644 rust/zerocopy/README.md
 create mode 100644 rust/zerocopy/benches/as_bytes_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/as_bytes_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/as_bytes_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/as_bytes_static_size.rs
 create mode 100644 rust/zerocopy/benches/as_bytes_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/as_bytes_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/extend_vec_zeroed.rs
 create mode 100644 rust/zerocopy/benches/extend_vec_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/extend_vec_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/formats/coco_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/formats/coco_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/formats/coco_static_size.rs
 create mode 100644 rust/zerocopy/benches/insert_vec_zeroed.rs
 create mode 100644 rust/zerocopy/benches/insert_vec_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/insert_vec_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_box_zeroed.rs
 create mode 100644 rust/zerocopy/benches/new_box_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/new_box_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_vec_zeroed.rs
 create mode 100644 rust/zerocopy/benches/new_vec_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/new_vec_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_zeroed.rs
 create mode 100644 rust/zerocopy/benches/new_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/new_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/read_from_bytes.rs
 create mode 100644 rust/zerocopy/benches/read_from_bytes.x86-64
 create mode 100644 rust/zerocopy/benches/read_from_bytes.x86-64.mca
 create mode 100644 rust/zerocopy/benches/read_from_prefix.rs
 create mode 100644 rust/zerocopy/benches/read_from_prefix.x86-64
 create mode 100644 rust/zerocopy/benches/read_from_prefix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/read_from_suffix.rs
 create mode 100644 rust/zerocopy/benches/read_from_suffix.x86-64
 create mode 100644 rust/zerocopy/benches/read_from_suffix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_static_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_static_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_static_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/transmute.rs
 create mode 100644 rust/zerocopy/benches/transmute.x86-64
 create mode 100644 rust/zerocopy/benches/transmute.x86-64.mca
 create mode 100644 rust/zerocopy/benches/transmute_ref_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/transmute_ref_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/transmute_ref_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/transmute_ref_static_size.rs
 create mode 100644 rust/zerocopy/benches/transmute_ref_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/transmute_ref_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_read_from_bytes.rs
 create mode 100644 rust/zerocopy/benches/try_read_from_bytes.x86-64
 create mode 100644 rust/zerocopy/benches/try_read_from_bytes.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_read_from_prefix.rs
 create mode 100644 rust/zerocopy/benches/try_read_from_prefix.x86-64
 create mode 100644 rust/zerocopy/benches/try_read_from_prefix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_read_from_suffix.rs
 create mode 100644 rust/zerocopy/benches/try_read_from_suffix.x86-64
 create mode 100644 rust/zerocopy/benches/try_read_from_suffix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_transmute.rs
 create mode 100644 rust/zerocopy/benches/try_transmute.x86-64
 create mode 100644 rust/zerocopy/benches/try_transmute.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_prefix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_prefix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_prefix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_prefix_static_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_prefix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_prefix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_static_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_suffix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_suffix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_suffix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_suffix_static_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_suffix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_suffix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/zero_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/zero_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/zero_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/zero_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/zero_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/zero_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/zero_static_size.rs
 create mode 100644 rust/zerocopy/benches/zero_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/zero_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/rustdoc/style.css
 create mode 100644 rust/zerocopy/src/byte_slice.rs
 create mode 100644 rust/zerocopy/src/byteorder.rs
 create mode 100644 rust/zerocopy/src/deprecated.rs
 create mode 100644 rust/zerocopy/src/error.rs
 create mode 100644 rust/zerocopy/src/impls.rs
 create mode 100644 rust/zerocopy/src/layout.rs
 create mode 100644 rust/zerocopy/src/lib.rs
 create mode 100644 rust/zerocopy/src/macros.rs
 create mode 100644 rust/zerocopy/src/pointer/inner.rs
 create mode 100644 rust/zerocopy/src/pointer/invariant.rs
 create mode 100644 rust/zerocopy/src/pointer/mod.rs
 create mode 100644 rust/zerocopy/src/pointer/ptr.rs
 create mode 100644 rust/zerocopy/src/pointer/transmute.rs
 create mode 100644 rust/zerocopy/src/ref.rs
 create mode 100644 rust/zerocopy/src/split_at.rs
 create mode 100644 rust/zerocopy/src/util/macro_util.rs
 create mode 100644 rust/zerocopy/src/util/macros.rs
 create mode 100644 rust/zerocopy/src/util/mod.rs
 create mode 100644 rust/zerocopy/src/wrappers.rs

base-commit: 4fedd76393580ecc61603a986ff4322bf3858dd7 --
2.54.0

author maintainer
#1 lore raw

PATCH v2 1/19 scripts: generate_rust_analyzer: support passing env vars

A future commit adding zerocopy support will need to pass an environment variable during its build.

Thus add support for an --envs parameter, similar to --cfgs, that allows to pass a map of variables to set for a given crate.

This allows us to keep a single source of truth for those values.

No change intended in the generated rust-project.json.

---
 scripts/generate_rust_analyzer.py | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
scripts/generate_rust_analyzer.py +18 -4
index d5f9a0ca742c..2477209e1e94 100755
@@ -26,6 +26,14 @@ def args_crates_cfgs(cfgs: List[str]) -> Dict[str, List[str]]:
 
     return crates_cfgs
 
+def args_crates_envs(envs: List[str]) -> Dict[str, Dict[str, str]]:
+    crates_envs = {}
+    for env in envs:
+        crate, vals = env.split("=", 1)
+        crates_envs[crate] = dict(v.split("=", 1) for v in vals.split())
+
+    return crates_envs
+
 class Dependency(TypedDict):
     crate: int
     name: str
@@ -61,6 +69,7 @@ def generate_crates(
     sysroot_src: pathlib.Path,
     external_src: Optional[pathlib.Path],
     cfgs: List[str],
+    envs: List[str],
     core_edition: str,
 ) -> List[Crate]:
     # Generate the configuration list.
@@ -74,6 +83,7 @@ def generate_crates(
     # Now fill the crates list.
     crates: List[Crate] = []
     crates_cfgs = args_crates_cfgs(cfgs)
+    crates_envs = args_crates_envs(envs)
 
     def get_crate_name(path: pathlib.Path) -> str:
         return invoke_rustc(["--print", "crate-name", str(path)])
@@ -92,6 +102,10 @@ def generate_crates(
             is_workspace_member if is_workspace_member is not None else True
         )
         edition = edition if edition is not None else "2021"
+        crate_env = {
+            "RUST_MODFILE": "This is only for rust-analyzer",
+            **crates_envs.get(display_name, {}),
+        }
         return {
             "display_name": display_name,
             "root_module": str(root_module),
@@ -99,9 +113,7 @@ def generate_crates(
             "deps": deps,
             "cfg": cfg,
             "edition": edition,
-            "env": {
-                "RUST_MODFILE": "This is only for rust-analyzer"
-            }
+            "env": crate_env,
         }
 
     def append_proc_macro_crate(
@@ -347,6 +359,7 @@ def main() -> None:
     parser = argparse.ArgumentParser()
     parser.add_argument('--verbose', '-v', action='store_true')
     parser.add_argument('--cfgs', action='append', default=[])
+    parser.add_argument('--envs', action='append', default=[])
     parser.add_argument("core_edition")
     parser.add_argument("srctree", type=pathlib.Path)
     parser.add_argument("objtree", type=pathlib.Path)
@@ -357,6 +370,7 @@ def main() -> None:
     class Args(argparse.Namespace):
         verbose: bool
         cfgs: List[str]
+        envs: List[str]
         srctree: pathlib.Path
         objtree: pathlib.Path
         sysroot: pathlib.Path
@@ -372,7 +386,7 @@ def main() -> None:
     )
 
     rust_project = {
-        "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.core_edition),
+        "crates": generate_crates(args.srctree, args.objtree, args.sysroot_src, args.exttree, args.cfgs, args.envs, args.core_edition),
         "sysroot": str(args.sysroot),
     }
 
Signature · 1 line
2.54.0
author maintainer
#2 lore raw

PATCH v2 2/19 rust: kbuild: show the right `quiet_cmd_rustc_procmacrolibrary`

In reply to Miguel Ojeda

When Clippy is skipped, RUSTC should be shown in quiet instead of CLIPPY to be accurate and to avoid confusion.

Thus do so, matching what we do in quiet_cmd_rustc_library.

Fixes 7dbe46c0b11d ("rust: kbuild: add proc macro library support")
---
 rust/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/Makefile +1 -1
index b9e9f512cec3..bec9726f256c 100644
@@ -517,7 +517,7 @@ $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
 $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
 	$(call if_changed,exports)
 
-quiet_cmd_rustc_procmacrolibrary = $(RUSTC_OR_CLIPPY_QUIET) PL $@
+quiet_cmd_rustc_procmacrolibrary = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) PL $@
       cmd_rustc_procmacrolibrary = \
 	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
 		$(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH v2 3/19 rust: kbuild: remove unused variable

In reply to Miguel Ojeda

Since we are adding one more proc macro crate (zerocopy-derive), we are refactoring their handling.

libpin_init_internal_extension was added to mimic the setup for macros, but it is not used, since the extension is expected to be the same.

Thus remove it.

---
 rust/Makefile | 1 -
 1 file changed, 1 deletion(-)
rust/Makefile +0 -1
index bec9726f256c..2b4a3983bb1e 100644
@@ -51,7 +51,6 @@ libmacros_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name ma
 libmacros_extension := $(patsubst libmacros.%,%,$(libmacros_name))
 
 libpin_init_internal_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name pin_init_internal --crate-type proc-macro - </dev/null)
-libpin_init_internal_extension := $(patsubst libpin_init_internal.%,%,$(libpin_init_internal_name))
 
 always-$(CONFIG_RUST) += $(libmacros_name) $(libpin_init_internal_name)
 
Signature · 1 line
2.54.0
author maintainer
#4 lore raw

PATCH v2 4/19 rust: kbuild: define `procmacro-name` function

In reply to Miguel Ojeda

Since we are adding one more proc macro crate (zerocopy-derive), we are refactoring their handling.

Thus define a procmacro-name function and use it to fill the existing variables' values.

---
 rust/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
rust/Makefile +4 -2
index 2b4a3983bb1e..8dfccf7399d9 100644
@@ -47,10 +47,12 @@ endif
 # Avoids running `$(RUSTC)` when it may not be available.
 ifdef CONFIG_RUST
 
-libmacros_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name macros --crate-type proc-macro - </dev/null)
+procmacro-name = $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name $(1) --crate-type proc-macro - </dev/null)
+
+libmacros_name := $(call procmacro-name,macros)
 libmacros_extension := $(patsubst libmacros.%,%,$(libmacros_name))
 
-libpin_init_internal_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name pin_init_internal --crate-type proc-macro - </dev/null)
+libpin_init_internal_name := $(call procmacro-name,pin_init_internal)
 
 always-$(CONFIG_RUST) += $(libmacros_name) $(libpin_init_internal_name)
 
Signature · 1 line
2.54.0
author maintainer
#5 lore raw

PATCH v2 5/19 rust: kbuild: define `procmacro-extension` variable

In reply to Miguel Ojeda

Since we are adding one more proc macro crate (zerocopy-derive), we are refactoring their handling.

Thus, instead of using libmacros_extension as the common variable to hold the extension for all of them, use a dedicated variable with a more generic name (including for its implementation).

---
 rust/Makefile | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
rust/Makefile +2 -3
index 8dfccf7399d9..df90fabefb70 100644
@@ -48,10 +48,9 @@ endif
 ifdef CONFIG_RUST
 
 procmacro-name = $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name $(1) --crate-type proc-macro - </dev/null)
+procmacro-extension := $(patsubst libname.%,%,$(call procmacro-name,name))
 
 libmacros_name := $(call procmacro-name,macros)
-libmacros_extension := $(patsubst libmacros.%,%,$(libmacros_name))
-
 libpin_init_internal_name := $(call procmacro-name,pin_init_internal)
 
 always-$(CONFIG_RUST) += $(libmacros_name) $(libpin_init_internal_name)
@@ -549,7 +548,7 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
 		-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
 		--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
 		--crate-type proc-macro -L$(objtree)/$(obj) \
-		--crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) \
+		--crate-name $(patsubst lib%.$(procmacro-extension),%,$(notdir $@)) \
 		@$(objtree)/include/generated/rustc_cfg $<
 
 # Procedural macros can only be used with the `rustc` that compiled it.
Signature · 1 line
2.54.0
author maintainer
#6 lore raw

PATCH v2 6/19 rust: kbuild: support per-target environment variables

In reply to Miguel Ojeda

Certain vendored crates, like the upcoming zerocopy, use extra environment variables (e.g. via env!).

Thus add support to easily specify those.

---
 rust/Makefile | 8 ++++++++
 1 file changed, 8 insertions(+)
rust/Makefile +8 -0
index df90fabefb70..9b5a3f9dd934 100644
@@ -144,6 +144,7 @@ doctests_modifiers_workaround := $(rustdoc_modifiers_workaround)$(if $(call rust
 
 quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
       cmd_rustdoc = \
+	$(rustc_target_envs) \
 	OBJTREE=$(abspath $(objtree)) \
 	$(RUSTDOC) $(filter-out $(skip_flags) --remap-path-scope=%,$(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
 		$(rustc_target_flags) -L$(objtree)/$(obj) \
@@ -250,6 +251,7 @@ rustdoc-clean: FORCE
 
 quiet_cmd_rustc_test_library = $(RUSTC_OR_CLIPPY_QUIET) TL $<
       cmd_rustc_test_library = \
+	$(rustc_target_envs) \
 	OBJTREE=$(abspath $(objtree)) \
 	$(RUSTC_OR_CLIPPY) $(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
 		@$(objtree)/include/generated/rustc_cfg \
@@ -314,6 +316,7 @@ rusttestlib-uapi: $(src)/uapi/lib.rs rusttestlib-ffi rusttestlib-pin_init FORCE
 
 quiet_cmd_rustdoc_test = RUSTDOC T $<
       cmd_rustdoc_test = \
+	$(rustc_target_envs) \
 	RUST_MODFILE=test.rs \
 	OBJTREE=$(abspath $(objtree)) \
 	$(RUSTDOC) --test $(rust_common_flags) \
@@ -328,6 +331,7 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
       cmd_rustdoc_test_kernel = \
 	rm -rf $(objtree)/$(obj)/test/doctests/kernel; \
 	mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \
+	$(rustc_target_envs) \
 	OBJTREE=$(abspath $(objtree)) \
 	$(RUSTDOC) --test $(filter-out --remap-path-scope=%,$(rust_flags)) \
 		-L$(objtree)/$(obj) --extern ffi --extern pin_init \
@@ -350,6 +354,7 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
 # so for the moment we skip `-Cpanic=abort`.
 quiet_cmd_rustc_test = $(RUSTC_OR_CLIPPY_QUIET) T  $<
       cmd_rustc_test = \
+	$(rustc_target_envs) \
 	OBJTREE=$(abspath $(objtree)) \
 	$(RUSTC_OR_CLIPPY) --test $(rust_common_flags) \
 		@$(objtree)/include/generated/rustc_cfg \
@@ -519,6 +524,7 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
 
 quiet_cmd_rustc_procmacrolibrary = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) PL $@
       cmd_rustc_procmacrolibrary = \
+	$(rustc_target_envs) \
 	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
 		$(filter-out $(skip_flags),$(rust_common_flags) $(rustc_target_flags)) \
 		--emit=dep-info=$(depfile) --emit=link=$@ --crate-type rlib -O \
@@ -543,6 +549,7 @@ $(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
 
 quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
       cmd_rustc_procmacro = \
+	$(rustc_target_envs) \
 	$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
 		-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
 		-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
@@ -567,6 +574,7 @@ $(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs \
 # since Rust 1.95.0 (https://github.com/rust-lang/rust/pull/151534).
 quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
       cmd_rustc_library = \
+	$(rustc_target_envs) \
 	OBJTREE=$(abspath $(objtree)) \
 	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
 		$(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \
Signature · 1 line
2.54.0
author maintainer
#7 lore raw

PATCH v2 7/19 rust: kbuild: support `skip_clippy` for `rustc_procmacro`

In reply to Miguel Ojeda

Certain vendored crates, like the upcoming zerocopy-derive, do not need to be built with Clippy since we --cap-lints=allow them anyway.

Thus add support to skip Clippy for proc macro crates.

---
 rust/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
rust/Makefile +2 -2
index 9b5a3f9dd934..7b1db0d5d423 100644
@@ -547,10 +547,10 @@ $(obj)/libsyn.rlib: private rustc_target_flags = $(syn-flags)
 $(obj)/libsyn.rlib: $(src)/syn/lib.rs $(obj)/libquote.rlib FORCE
 	+$(call if_changed_dep,rustc_procmacrolibrary)
 
-quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
+quiet_cmd_rustc_procmacro = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) P $@
       cmd_rustc_procmacro = \
 	$(rustc_target_envs) \
-	$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
+	$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) $(rust_common_flags) $(rustc_target_flags) \
 		-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
 		-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
 		--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
Signature · 1 line
2.54.0
author maintainer
#8 lore raw

PATCH v2 8/19 rust: zerocopy: import crate

In reply to Miguel Ojeda

This is a subset of the Rust zerocopy crate, version v0.8.50 (released 2026-05-31), licensed under "BSD-2-Clause OR Apache-2.0 OR MIT", from:

    https://github.com/google/zerocopy/tree/v0.8.50

The files are copied as-is, with no modifications whatsoever (not even adding the SPDX identifiers).

The benches folder is added (i.e. not just src like in other cases) since the files there are included in the rendered documentation, as well as the rustdoc CSS style file that is needed to make those visually more understandable.

For copyright details, please see:

    https://github.com/google/zerocopy/blob/v0.8.50/README.md?plain=1
    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-BSD
    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-APACHE
    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-MIT

The next two patches modify these files as needed for use within the kernel. This patch split allows reviewers to double-check the import and to clearly see the differences introduced.

The following script may be used to verify the contents:

    for path in $(cd rust/zerocopy/ && find . -type f); do
        curl --silent --show-error --location \
            https://github.com/google/zerocopy/raw/v0.8.50/$path \
            | diff --unified rust/zerocopy/$path - && echo $path: OK
    done
Cc Joshua Liebow-Feeser <[email protected]>
Cc Jack Wrenn <[email protected]>
---
 .../zerocopy/benches/as_bytes_dynamic_size.rs |    9 +
 .../benches/as_bytes_dynamic_size.x86-64      |    5 +
 .../benches/as_bytes_dynamic_size.x86-64.mca  |   47 +
 rust/zerocopy/benches/as_bytes_static_size.rs |    9 +
 .../benches/as_bytes_static_size.x86-64       |    4 +
 .../benches/as_bytes_static_size.x86-64.mca   |   45 +
 rust/zerocopy/benches/extend_vec_zeroed.rs    |    9 +
 .../zerocopy/benches/extend_vec_zeroed.x86-64 |   60 +
 .../benches/extend_vec_zeroed.x86-64.mca      |  147 +
 .../benches/formats/coco_dynamic_padding.rs   |   24 +
 .../benches/formats/coco_dynamic_size.rs      |   27 +
 .../benches/formats/coco_static_size.rs       |   27 +
 rust/zerocopy/benches/insert_vec_zeroed.rs    |   13 +
 .../zerocopy/benches/insert_vec_zeroed.x86-64 |   79 +
 .../benches/insert_vec_zeroed.x86-64.mca      |  183 +
 rust/zerocopy/benches/new_box_zeroed.rs       |    9 +
 rust/zerocopy/benches/new_box_zeroed.x86-64   |    7 +
 .../benches/new_box_zeroed.x86-64.mca         |   51 +
 ...w_box_zeroed_with_elems_dynamic_padding.rs |   11 +
 ...x_zeroed_with_elems_dynamic_padding.x86-64 |   24 +
 ...roed_with_elems_dynamic_padding.x86-64.mca |   81 +
 .../new_box_zeroed_with_elems_dynamic_size.rs |    9 +
 ..._box_zeroed_with_elems_dynamic_size.x86-64 |   22 +
 ..._zeroed_with_elems_dynamic_size.x86-64.mca |   77 +
 rust/zerocopy/benches/new_vec_zeroed.rs       |    9 +
 rust/zerocopy/benches/new_vec_zeroed.x86-64   |   40 +
 .../benches/new_vec_zeroed.x86-64.mca         |  113 +
 rust/zerocopy/benches/new_zeroed.rs           |    9 +
 rust/zerocopy/benches/new_zeroed.x86-64       |    3 +
 rust/zerocopy/benches/new_zeroed.x86-64.mca   |   43 +
 rust/zerocopy/benches/read_from_bytes.rs      |    7 +
 rust/zerocopy/benches/read_from_bytes.x86-64  |   15 +
 .../benches/read_from_bytes.x86-64.mca        |   65 +
 rust/zerocopy/benches/read_from_prefix.rs     |   10 +
 rust/zerocopy/benches/read_from_prefix.x86-64 |   14 +
 .../benches/read_from_prefix.x86-64.mca       |   63 +
 rust/zerocopy/benches/read_from_suffix.rs     |   10 +
 rust/zerocopy/benches/read_from_suffix.x86-64 |   15 +
 .../benches/read_from_suffix.x86-64.mca       |   65 +
 .../benches/ref_from_bytes_dynamic_padding.rs |    7 +
 .../ref_from_bytes_dynamic_padding.x86-64     |   22 +
 .../ref_from_bytes_dynamic_padding.x86-64.mca |   77 +
 .../benches/ref_from_bytes_dynamic_size.rs    |    7 +
 .../ref_from_bytes_dynamic_size.x86-64        |   20 +
 .../ref_from_bytes_dynamic_size.x86-64.mca    |   75 +
 .../benches/ref_from_bytes_static_size.rs     |    7 +
 .../benches/ref_from_bytes_static_size.x86-64 |    8 +
 .../ref_from_bytes_static_size.x86-64.mca     |   53 +
 ...f_from_bytes_with_elems_dynamic_padding.rs |   10 +
 ...om_bytes_with_elems_dynamic_padding.x86-64 |   19 +
 ...ytes_with_elems_dynamic_padding.x86-64.mca |   71 +
 .../ref_from_bytes_with_elems_dynamic_size.rs |   10 +
 ..._from_bytes_with_elems_dynamic_size.x86-64 |   16 +
 ...m_bytes_with_elems_dynamic_size.x86-64.mca |   65 +
 .../ref_from_prefix_dynamic_padding.rs        |   10 +
 .../ref_from_prefix_dynamic_padding.x86-64    |   22 +
 ...ref_from_prefix_dynamic_padding.x86-64.mca |   77 +
 .../benches/ref_from_prefix_dynamic_size.rs   |   10 +
 .../ref_from_prefix_dynamic_size.x86-64       |   17 +
 .../ref_from_prefix_dynamic_size.x86-64.mca   |   67 +
 .../benches/ref_from_prefix_static_size.rs    |   10 +
 .../ref_from_prefix_static_size.x86-64        |    8 +
 .../ref_from_prefix_static_size.x86-64.mca    |   53 +
 ..._from_prefix_with_elems_dynamic_padding.rs |   13 +
 ...m_prefix_with_elems_dynamic_padding.x86-64 |   26 +
 ...efix_with_elems_dynamic_padding.x86-64.mca |   85 +
 ...ref_from_prefix_with_elems_dynamic_size.rs |   13 +
 ...from_prefix_with_elems_dynamic_size.x86-64 |   22 +
 ..._prefix_with_elems_dynamic_size.x86-64.mca |   77 +
 .../ref_from_suffix_dynamic_padding.rs        |   10 +
 .../ref_from_suffix_dynamic_padding.x86-64    |   23 +
 ...ref_from_suffix_dynamic_padding.x86-64.mca |   79 +
 .../benches/ref_from_suffix_dynamic_size.rs   |   10 +
 .../ref_from_suffix_dynamic_size.x86-64       |   13 +
 .../ref_from_suffix_dynamic_size.x86-64.mca   |   63 +
 .../benches/ref_from_suffix_static_size.rs    |   10 +
 .../ref_from_suffix_static_size.x86-64        |   13 +
 .../ref_from_suffix_static_size.x86-64.mca    |   61 +
 ..._from_suffix_with_elems_dynamic_padding.rs |   13 +
 ...m_suffix_with_elems_dynamic_padding.x86-64 |   27 +
 ...ffix_with_elems_dynamic_padding.x86-64.mca |   85 +
 ...ref_from_suffix_with_elems_dynamic_size.rs |   13 +
 ...from_suffix_with_elems_dynamic_size.x86-64 |   23 +
 ..._suffix_with_elems_dynamic_size.x86-64.mca |   77 +
 .../benches/split_at_dynamic_padding.rs       |   12 +
 .../benches/split_at_dynamic_padding.x86-64   |   12 +
 .../split_at_dynamic_padding.x86-64.mca       |   59 +
 .../zerocopy/benches/split_at_dynamic_size.rs |   12 +
 .../benches/split_at_dynamic_size.x86-64      |   12 +
 .../benches/split_at_dynamic_size.x86-64.mca  |   59 +
 .../split_at_unchecked_dynamic_padding.rs     |   12 +
 .../split_at_unchecked_dynamic_padding.x86-64 |    6 +
 ...it_at_unchecked_dynamic_padding.x86-64.mca |   49 +
 .../split_at_unchecked_dynamic_size.rs        |   12 +
 .../split_at_unchecked_dynamic_size.x86-64    |    6 +
 ...split_at_unchecked_dynamic_size.x86-64.mca |   49 +
 .../split_via_immutable_dynamic_padding.rs    |   11 +
 ...split_via_immutable_dynamic_padding.x86-64 |   14 +
 ...t_via_immutable_dynamic_padding.x86-64.mca |   65 +
 .../split_via_immutable_dynamic_size.rs       |   11 +
 .../split_via_immutable_dynamic_size.x86-64   |   13 +
 ...plit_via_immutable_dynamic_size.x86-64.mca |   63 +
 ...split_via_runtime_check_dynamic_padding.rs |   11 +
 ...t_via_runtime_check_dynamic_padding.x86-64 |   22 +
 ...a_runtime_check_dynamic_padding.x86-64.mca |   79 +
 .../split_via_runtime_check_dynamic_size.rs   |   11 +
 ...plit_via_runtime_check_dynamic_size.x86-64 |   13 +
 ..._via_runtime_check_dynamic_size.x86-64.mca |   63 +
 .../split_via_unchecked_dynamic_padding.rs    |   11 +
 ...split_via_unchecked_dynamic_padding.x86-64 |   14 +
 ...t_via_unchecked_dynamic_padding.x86-64.mca |   65 +
 .../split_via_unchecked_dynamic_size.rs       |   11 +
 .../split_via_unchecked_dynamic_size.x86-64   |   13 +
 ...plit_via_unchecked_dynamic_size.x86-64.mca |   63 +
 rust/zerocopy/benches/transmute.rs            |   16 +
 rust/zerocopy/benches/transmute.x86-64        |    3 +
 rust/zerocopy/benches/transmute.x86-64.mca    |   43 +
 .../benches/transmute_ref_dynamic_size.rs     |   16 +
 .../benches/transmute_ref_dynamic_size.x86-64 |    4 +
 .../transmute_ref_dynamic_size.x86-64.mca     |   45 +
 .../benches/transmute_ref_static_size.rs      |   15 +
 .../benches/transmute_ref_static_size.x86-64  |    3 +
 .../transmute_ref_static_size.x86-64.mca      |   43 +
 rust/zerocopy/benches/try_read_from_bytes.rs  |    7 +
 .../benches/try_read_from_bytes.x86-64        |   23 +
 .../benches/try_read_from_bytes.x86-64.mca    |   79 +
 rust/zerocopy/benches/try_read_from_prefix.rs |   10 +
 .../benches/try_read_from_prefix.x86-64       |   16 +
 .../benches/try_read_from_prefix.x86-64.mca   |   67 +
 rust/zerocopy/benches/try_read_from_suffix.rs |   10 +
 .../benches/try_read_from_suffix.x86-64       |   18 +
 .../benches/try_read_from_suffix.x86-64.mca   |   71 +
 .../try_ref_from_bytes_dynamic_padding.rs     |    7 +
 .../try_ref_from_bytes_dynamic_padding.x86-64 |   24 +
 ..._ref_from_bytes_dynamic_padding.x86-64.mca |   81 +
 .../try_ref_from_bytes_dynamic_size.rs        |    7 +
 .../try_ref_from_bytes_dynamic_size.x86-64    |   22 +
 ...try_ref_from_bytes_dynamic_size.x86-64.mca |   79 +
 .../benches/try_ref_from_bytes_static_size.rs |    7 +
 .../try_ref_from_bytes_static_size.x86-64     |   13 +
 .../try_ref_from_bytes_static_size.x86-64.mca |   59 +
 ...f_from_bytes_with_elems_dynamic_padding.rs |   10 +
 ...om_bytes_with_elems_dynamic_padding.x86-64 |   21 +
 ...ytes_with_elems_dynamic_padding.x86-64.mca |   75 +
 ..._ref_from_bytes_with_elems_dynamic_size.rs |   10 +
 ..._from_bytes_with_elems_dynamic_size.x86-64 |   18 +
 ...m_bytes_with_elems_dynamic_size.x86-64.mca |   69 +
 .../try_ref_from_prefix_dynamic_padding.rs    |   10 +
 ...try_ref_from_prefix_dynamic_padding.x86-64 |   29 +
 ...ref_from_prefix_dynamic_padding.x86-64.mca |   91 +
 .../try_ref_from_prefix_dynamic_size.rs       |   10 +
 .../try_ref_from_prefix_dynamic_size.x86-64   |   22 +
 ...ry_ref_from_prefix_dynamic_size.x86-64.mca |   77 +
 .../try_ref_from_prefix_static_size.rs        |   10 +
 .../try_ref_from_prefix_static_size.x86-64    |   15 +
 ...try_ref_from_prefix_static_size.x86-64.mca |   63 +
 ..._from_prefix_with_elems_dynamic_padding.rs |   13 +
 ...m_prefix_with_elems_dynamic_padding.x86-64 |   30 +
 ...efix_with_elems_dynamic_padding.x86-64.mca |   91 +
 ...ref_from_prefix_with_elems_dynamic_size.rs |   13 +
 ...from_prefix_with_elems_dynamic_size.x86-64 |   26 +
 ..._prefix_with_elems_dynamic_size.x86-64.mca |   83 +
 .../try_ref_from_suffix_dynamic_padding.rs    |   10 +
 ...try_ref_from_suffix_dynamic_padding.x86-64 |   26 +
 ...ref_from_suffix_dynamic_padding.x86-64.mca |   85 +
 .../try_ref_from_suffix_dynamic_size.rs       |   10 +
 .../try_ref_from_suffix_dynamic_size.x86-64   |   18 +
 ...ry_ref_from_suffix_dynamic_size.x86-64.mca |   71 +
 .../try_ref_from_suffix_static_size.rs        |   10 +
 .../try_ref_from_suffix_static_size.x86-64    |   16 +
 ...try_ref_from_suffix_static_size.x86-64.mca |   67 +
 ..._from_suffix_with_elems_dynamic_padding.rs |   13 +
 ...m_suffix_with_elems_dynamic_padding.x86-64 |   32 +
 ...ffix_with_elems_dynamic_padding.x86-64.mca |   95 +
 ...ref_from_suffix_with_elems_dynamic_size.rs |   13 +
 ...from_suffix_with_elems_dynamic_size.x86-64 |   28 +
 ..._suffix_with_elems_dynamic_size.x86-64.mca |   87 +
 rust/zerocopy/benches/try_transmute.rs        |   16 +
 rust/zerocopy/benches/try_transmute.x86-64    |    9 +
 .../zerocopy/benches/try_transmute.x86-64.mca |   55 +
 .../benches/try_transmute_ref_dynamic_size.rs |   18 +
 .../try_transmute_ref_dynamic_size.x86-64     |    6 +
 .../try_transmute_ref_dynamic_size.x86-64.mca |   49 +
 .../benches/try_transmute_ref_static_size.rs  |   17 +
 .../try_transmute_ref_static_size.x86-64      |    5 +
 .../try_transmute_ref_static_size.x86-64.mca  |   47 +
 .../zerocopy/benches/write_to_dynamic_size.rs |    9 +
 .../benches/write_to_dynamic_size.x86-64      |   21 +
 .../benches/write_to_dynamic_size.x86-64.mca  |   77 +
 .../benches/write_to_prefix_dynamic_size.rs   |   12 +
 .../write_to_prefix_dynamic_size.x86-64       |   21 +
 .../write_to_prefix_dynamic_size.x86-64.mca   |   77 +
 .../benches/write_to_prefix_static_size.rs    |   12 +
 .../write_to_prefix_static_size.x86-64        |   11 +
 .../write_to_prefix_static_size.x86-64.mca    |   57 +
 rust/zerocopy/benches/write_to_static_size.rs |    9 +
 .../benches/write_to_static_size.x86-64       |   11 +
 .../benches/write_to_static_size.x86-64.mca   |   57 +
 .../benches/write_to_suffix_dynamic_size.rs   |   12 +
 .../write_to_suffix_dynamic_size.x86-64       |   22 +
 .../write_to_suffix_dynamic_size.x86-64.mca   |   79 +
 .../benches/write_to_suffix_static_size.rs    |   12 +
 .../write_to_suffix_static_size.x86-64        |   11 +
 .../write_to_suffix_static_size.x86-64.mca    |   57 +
 rust/zerocopy/benches/zero_dynamic_padding.rs |    9 +
 .../benches/zero_dynamic_padding.x86-64       |    7 +
 .../benches/zero_dynamic_padding.x86-64.mca   |   51 +
 rust/zerocopy/benches/zero_dynamic_size.rs    |    9 +
 .../zerocopy/benches/zero_dynamic_size.x86-64 |    5 +
 .../benches/zero_dynamic_size.x86-64.mca      |   47 +
 rust/zerocopy/benches/zero_static_size.rs     |    9 +
 rust/zerocopy/benches/zero_static_size.x86-64 |    4 +
 .../benches/zero_static_size.x86-64.mca       |   45 +
 rust/zerocopy/rustdoc/style.css               |   55 +
 rust/zerocopy/src/byte_slice.rs               |  432 +
 rust/zerocopy/src/byteorder.rs                | 1563 ++++
 rust/zerocopy/src/deprecated.rs               |  279 +
 rust/zerocopy/src/error.rs                    | 1348 +++
 rust/zerocopy/src/impls.rs                    | 2387 ++++++
 rust/zerocopy/src/layout.rs                   | 2223 +++++
 rust/zerocopy/src/lib.rs                      | 7610 +++++++++++++++++
 rust/zerocopy/src/macros.rs                   | 1823 ++++
 rust/zerocopy/src/pointer/inner.rs            |  752 ++
 rust/zerocopy/src/pointer/invariant.rs        |  296 +
 rust/zerocopy/src/pointer/mod.rs              |  408 +
 rust/zerocopy/src/pointer/ptr.rs              | 1584 ++++
 rust/zerocopy/src/pointer/transmute.rs        |  520 ++
 rust/zerocopy/src/ref.rs                      | 1356 +++
 rust/zerocopy/src/split_at.rs                 | 1088 +++
 rust/zerocopy/src/util/macro_util.rs          | 1308 +++
 rust/zerocopy/src/util/macros.rs              | 1065 +++
 rust/zerocopy/src/util/mod.rs                 |  936 ++
 rust/zerocopy/src/wrappers.rs                 | 1032 +++
 233 files changed, 35005 insertions(+)
 create mode 100644 rust/zerocopy/benches/as_bytes_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/as_bytes_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/as_bytes_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/as_bytes_static_size.rs
 create mode 100644 rust/zerocopy/benches/as_bytes_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/as_bytes_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/extend_vec_zeroed.rs
 create mode 100644 rust/zerocopy/benches/extend_vec_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/extend_vec_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/formats/coco_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/formats/coco_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/formats/coco_static_size.rs
 create mode 100644 rust/zerocopy/benches/insert_vec_zeroed.rs
 create mode 100644 rust/zerocopy/benches/insert_vec_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/insert_vec_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_box_zeroed.rs
 create mode 100644 rust/zerocopy/benches/new_box_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/new_box_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_vec_zeroed.rs
 create mode 100644 rust/zerocopy/benches/new_vec_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/new_vec_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/new_zeroed.rs
 create mode 100644 rust/zerocopy/benches/new_zeroed.x86-64
 create mode 100644 rust/zerocopy/benches/new_zeroed.x86-64.mca
 create mode 100644 rust/zerocopy/benches/read_from_bytes.rs
 create mode 100644 rust/zerocopy/benches/read_from_bytes.x86-64
 create mode 100644 rust/zerocopy/benches/read_from_bytes.x86-64.mca
 create mode 100644 rust/zerocopy/benches/read_from_prefix.rs
 create mode 100644 rust/zerocopy/benches/read_from_prefix.x86-64
 create mode 100644 rust/zerocopy/benches/read_from_prefix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/read_from_suffix.rs
 create mode 100644 rust/zerocopy/benches/read_from_suffix.x86-64
 create mode 100644 rust/zerocopy/benches/read_from_suffix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_static_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_static_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_static_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_at_unchecked_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_immutable_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_runtime_check_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/split_via_unchecked_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/transmute.rs
 create mode 100644 rust/zerocopy/benches/transmute.x86-64
 create mode 100644 rust/zerocopy/benches/transmute.x86-64.mca
 create mode 100644 rust/zerocopy/benches/transmute_ref_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/transmute_ref_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/transmute_ref_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/transmute_ref_static_size.rs
 create mode 100644 rust/zerocopy/benches/transmute_ref_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/transmute_ref_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_read_from_bytes.rs
 create mode 100644 rust/zerocopy/benches/try_read_from_bytes.x86-64
 create mode 100644 rust/zerocopy/benches/try_read_from_bytes.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_read_from_prefix.rs
 create mode 100644 rust/zerocopy/benches/try_read_from_prefix.x86-64
 create mode 100644 rust/zerocopy/benches/try_read_from_prefix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_read_from_suffix.rs
 create mode 100644 rust/zerocopy/benches/try_read_from_suffix.x86-64
 create mode 100644 rust/zerocopy/benches/try_read_from_suffix.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_transmute.rs
 create mode 100644 rust/zerocopy/benches/try_transmute.x86-64
 create mode 100644 rust/zerocopy/benches/try_transmute.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_static_size.rs
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/try_transmute_ref_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_prefix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_prefix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_prefix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_prefix_static_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_prefix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_prefix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_static_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_suffix_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_suffix_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_suffix_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/write_to_suffix_static_size.rs
 create mode 100644 rust/zerocopy/benches/write_to_suffix_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/write_to_suffix_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/zero_dynamic_padding.rs
 create mode 100644 rust/zerocopy/benches/zero_dynamic_padding.x86-64
 create mode 100644 rust/zerocopy/benches/zero_dynamic_padding.x86-64.mca
 create mode 100644 rust/zerocopy/benches/zero_dynamic_size.rs
 create mode 100644 rust/zerocopy/benches/zero_dynamic_size.x86-64
 create mode 100644 rust/zerocopy/benches/zero_dynamic_size.x86-64.mca
 create mode 100644 rust/zerocopy/benches/zero_static_size.rs
 create mode 100644 rust/zerocopy/benches/zero_static_size.x86-64
 create mode 100644 rust/zerocopy/benches/zero_static_size.x86-64.mca
 create mode 100644 rust/zerocopy/rustdoc/style.css
 create mode 100644 rust/zerocopy/src/byte_slice.rs
 create mode 100644 rust/zerocopy/src/byteorder.rs
 create mode 100644 rust/zerocopy/src/deprecated.rs
 create mode 100644 rust/zerocopy/src/error.rs
 create mode 100644 rust/zerocopy/src/impls.rs
 create mode 100644 rust/zerocopy/src/layout.rs
 create mode 100644 rust/zerocopy/src/lib.rs
 create mode 100644 rust/zerocopy/src/macros.rs
 create mode 100644 rust/zerocopy/src/pointer/inner.rs
 create mode 100644 rust/zerocopy/src/pointer/invariant.rs
 create mode 100644 rust/zerocopy/src/pointer/mod.rs
 create mode 100644 rust/zerocopy/src/pointer/ptr.rs
 create mode 100644 rust/zerocopy/src/pointer/transmute.rs
 create mode 100644 rust/zerocopy/src/ref.rs
 create mode 100644 rust/zerocopy/src/split_at.rs
 create mode 100644 rust/zerocopy/src/util/macro_util.rs
 create mode 100644 rust/zerocopy/src/util/macros.rs
 create mode 100644 rust/zerocopy/src/util/mod.rs
 create mode 100644 rust/zerocopy/src/wrappers.rs
rust/zerocopy/benches/as_bytes_dynamic_size.rs new file +9 -0
new file mode 100644
index 000000000000..68cd1d6f4111
@@ -0,0 +1,9 @@
+use zerocopy::*;
+
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_as_bytes_dynamic_size(source: &format::CocoPacket) -> &[u8] {
+    source.as_bytes()
+}
rust/zerocopy/benches/as_bytes_dynamic_size.x86-64 new file +5 -0
new file mode 100644
index 000000000000..f68bad612695
@@ -0,0 +1,5 @@
+bench_as_bytes_dynamic_size:
+	mov rax, rdi
+	lea rdx, [2*rsi + 5]
+	and rdx, -2
+	ret
rust/zerocopy/benches/as_bytes_dynamic_size.x86-64.mca new file +47 -0

47 lines not on this page · raw message

rust/zerocopy/benches/as_bytes_static_size.rs new file +9 -0
new file mode 100644
index 000000000000..2ad738e95480
@@ -0,0 +1,9 @@
+use zerocopy::*;
+
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_as_bytes_static_size(source: &format::CocoPacket) -> &[u8] {
+    source.as_bytes()
+}
rust/zerocopy/benches/as_bytes_static_size.x86-64 new file +4 -0
new file mode 100644
index 000000000000..213e74ab54ff
@@ -0,0 +1,4 @@
+bench_as_bytes_static_size:
+	mov rax, rdi
+	mov edx, 6
+	ret
rust/zerocopy/benches/as_bytes_static_size.x86-64.mca new file +45 -0

45 lines not on this page · raw message

rust/zerocopy/benches/extend_vec_zeroed.rs new file +9 -0
new file mode 100644
index 000000000000..1fbf772d1ea7
@@ -0,0 +1,9 @@
+use zerocopy::*;
+
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_extend_vec_zeroed(v: &mut Vec<format::LocoPacket>, additional: usize) -> Option<()> {
+    FromZeros::extend_vec_zeroed(v, additional).ok()
+}
rust/zerocopy/benches/extend_vec_zeroed.x86-64 new file +60 -0

60 lines not on this page · raw message

rust/zerocopy/benches/extend_vec_zeroed.x86-64.mca new file +147 -0

147 lines not on this page · raw message

rust/zerocopy/benches/formats/coco_dynamic_padding.rs new file +24 -0
new file mode 100644
index 000000000000..e494bce67312
@@ -0,0 +1,24 @@
+use zerocopy_derive::*;
+
+// The only valid value of this type are the bytes `0xC0C0`.
+#[derive(TryFromBytes, KnownLayout, Immutable)]
+#[repr(u16)]
+pub enum C0C0 {
+    _XC0C0 = 0xC0C0,
+}
+
+#[derive(FromBytes, KnownLayout, Immutable, SplitAt)]
+#[repr(C, align(4))]
+pub struct Packet<Magic> {
+    magic_number: Magic,
+    milk: u8,
+    mug_size: u8,
+    temperature: [u8; 5],
+    marshmallows: [[u8; 3]],
+}
+
+/// A packet begining with the magic number `0xC0C0`.
+pub type CocoPacket = Packet<C0C0>;
+
+/// A packet beginning with any two initialized bytes.
+pub type LocoPacket = Packet<[u8; 2]>;
rust/zerocopy/benches/formats/coco_dynamic_size.rs new file +27 -0
new file mode 100644
index 000000000000..59364638e66c
@@ -0,0 +1,27 @@
+use zerocopy_derive::*;
+
+// The only valid value of this type are the bytes `0xC0C0`.
+#[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)]
+#[repr(u16)]
+pub enum C0C0 {
+    _XC0C0 = 0xC0C0,
+}
+
+macro_rules! define_packet {
+    ($name: ident, $trait: ident, $leading_field: ty) => {
+        #[derive($trait, KnownLayout, Immutable, IntoBytes, SplitAt)]
+        #[repr(C, align(2))]
+        pub struct $name {
+            magic_number: $leading_field,
+            mug_size: u8,
+            temperature: u8,
+            marshmallows: [[u8; 2]],
+        }
+    };
+}
+
+/// Packet begins with bytes 0xC0C0.
+define_packet!(CocoPacket, TryFromBytes, C0C0);
+
+/// Packet begins with any two bytes.
+define_packet!(LocoPacket, FromBytes, [u8; 2]);
rust/zerocopy/benches/formats/coco_static_size.rs new file +27 -0
new file mode 100644
index 000000000000..0839497e1748
@@ -0,0 +1,27 @@
+use zerocopy_derive::*;
+
+// The only valid value of this type are the bytes `0xC0C0`.
+#[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)]
+#[repr(u16)]
+pub enum C0C0 {
+    _XC0C0 = 0xC0C0,
+}
+
+macro_rules! define_packet {
+    ($name: ident, $trait: ident, $leading_field: ty) => {
+        #[derive($trait, KnownLayout, Immutable, IntoBytes)]
+        #[repr(C, align(2))]
+        pub struct $name {
+            magic_number: $leading_field,
+            mug_size: u8,
+            temperature: u8,
+            marshmallows: [u8; 2],
+        }
+    };
+}
+
+/// Packet begins with bytes 0xC0C0.
+define_packet!(CocoPacket, TryFromBytes, C0C0);
+
+/// Packet begins with any two bytes.
+define_packet!(LocoPacket, FromBytes, [u8; 2]);
rust/zerocopy/benches/insert_vec_zeroed.rs new file +13 -0
new file mode 100644
index 000000000000..a5d685c2b027
@@ -0,0 +1,13 @@
+use zerocopy::*;
+
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_insert_vec_zeroed(
+    v: &mut Vec<format::LocoPacket>,
+    position: usize,
+    additional: usize,
+) -> Option<()> {
+    FromZeros::insert_vec_zeroed(v, position, additional).ok()
+}
rust/zerocopy/benches/insert_vec_zeroed.x86-64 new file +79 -0

79 lines not on this page · raw message

rust/zerocopy/benches/insert_vec_zeroed.x86-64.mca new file +183 -0

183 lines not on this page · raw message

rust/zerocopy/benches/new_box_zeroed.rs new file +9 -0
new file mode 100644
index 000000000000..aa9a66cce353
@@ -0,0 +1,9 @@
+use zerocopy::*;
+
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_new_box_zeroed() -> Option<Box<format::LocoPacket>> {
+    FromZeros::new_box_zeroed().ok()
+}
rust/zerocopy/benches/new_box_zeroed.x86-64 new file +7 -0
new file mode 100644
index 000000000000..ef74ea5388ac
@@ -0,0 +1,7 @@
+bench_new_box_zeroed:
+	push rax
+	call qword ptr [rip + __rustc::__rust_no_alloc_shim_is_unstable_v2@GOTPCREL]
+	mov edi, 6
+	mov esi, 2
+	pop rax
+	jmp qword ptr [rip + __rustc::__rust_alloc_zeroed@GOTPCREL]
rust/zerocopy/benches/new_box_zeroed.x86-64.mca new file +51 -0

51 lines not on this page · raw message

rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.rs new file +11 -0
new file mode 100644
index 000000000000..0afde999bff8
@@ -0,0 +1,11 @@
+use zerocopy::*;
+
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_new_box_zeroed_with_elems_dynamic_padding(
+    count: usize,
+) -> Option<Box<format::LocoPacket>> {
+    FromZeros::new_box_zeroed_with_elems(count).ok()
+}
rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.x86-64 new file +24 -0
new file mode 100644
index 000000000000..22a8d048ce0f
@@ -0,0 +1,24 @@
+bench_new_box_zeroed_with_elems_dynamic_padding:
+	push r14
+	push rbx
+	push rax
+	mov rbx, rdi
+	movabs rax, 3074457345618258598
+	cmp rdi, rax
+	ja .LBB5_1
+	lea r14, [rbx + 2*rbx]
+	or r14, 3
+	add r14, 9
+	call qword ptr [rip + __rustc::__rust_no_alloc_shim_is_unstable_v2@GOTPCREL]
+	mov esi, 4
+	mov rdi, r14
+	call qword ptr [rip + __rustc::__rust_alloc_zeroed@GOTPCREL]
+	jmp .LBB5_3
+.LBB5_1:
+	xor eax, eax
+.LBB5_3:
+	mov rdx, rbx
+	add rsp, 8
+	pop rbx
+	pop r14
+	ret
rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_padding.x86-64.mca new file +81 -0

81 lines not on this page · raw message

rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.rs new file +9 -0
new file mode 100644
index 000000000000..1b12ca220692
@@ -0,0 +1,9 @@
+use zerocopy::*;
+
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_new_box_zeroed_with_elems_dynamic_size(count: usize) -> Option<Box<format::LocoPacket>> {
+    FromZeros::new_box_zeroed_with_elems(count).ok()
+}
rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.x86-64 new file +22 -0
new file mode 100644
index 000000000000..bff15e55ad9f
@@ -0,0 +1,22 @@
+bench_new_box_zeroed_with_elems_dynamic_size:
+	push r14
+	push rbx
+	push rax
+	mov rbx, rdi
+	movabs rax, 4611686018427387901
+	cmp rdi, rax
+	ja .LBB5_1
+	lea r14, [2*rbx + 4]
+	call qword ptr [rip + __rustc::__rust_no_alloc_shim_is_unstable_v2@GOTPCREL]
+	mov esi, 2
+	mov rdi, r14
+	call qword ptr [rip + __rustc::__rust_alloc_zeroed@GOTPCREL]
+	jmp .LBB5_3
+.LBB5_1:
+	xor eax, eax
+.LBB5_3:
+	mov rdx, rbx
+	add rsp, 8
+	pop rbx
+	pop r14
+	ret
rust/zerocopy/benches/new_box_zeroed_with_elems_dynamic_size.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/new_vec_zeroed.rs new file +9 -0
new file mode 100644
index 000000000000..3d95b2b24d8d
@@ -0,0 +1,9 @@
+use zerocopy::*;
+
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_new_vec_zeroed(len: usize) -> Option<Vec<format::LocoPacket>> {
+    FromZeros::new_vec_zeroed(len).ok()
+}
rust/zerocopy/benches/new_vec_zeroed.x86-64 new file +40 -0
new file mode 100644
index 000000000000..b5c083aa0d36
@@ -0,0 +1,40 @@
+bench_new_vec_zeroed:
+	mov rax, rdi
+	movabs rcx, 1537228672809129301
+	cmp rsi, rcx
+	ja .LBB5_5
+	test rsi, rsi
+	je .LBB5_2
+	push r15
+	push r14
+	push rbx
+	lea rcx, [rsi + rsi]
+	lea rbx, [rcx + 2*rcx]
+	mov r14, rax
+	mov r15, rsi
+	call qword ptr [rip + __rustc::__rust_no_alloc_shim_is_unstable_v2@GOTPCREL]
+	mov esi, 2
+	mov rdi, rbx
+	call qword ptr [rip + __rustc::__rust_alloc_zeroed@GOTPCREL]
+	mov rsi, r15
+	mov rcx, rax
+	mov rax, r14
+	test rcx, rcx
+	pop rbx
+	pop r14
+	pop r15
+	je .LBB5_5
+	mov qword ptr [rax], rsi
+	mov qword ptr [rax + 8], rcx
+	mov qword ptr [rax + 16], rsi
+	ret
+.LBB5_5:
+	movabs rcx, -9223372036854775808
+	mov qword ptr [rax], rcx
+	ret
+.LBB5_2:
+	mov ecx, 2
+	mov qword ptr [rax], rsi
+	mov qword ptr [rax + 8], rcx
+	mov qword ptr [rax + 16], rsi
+	ret
rust/zerocopy/benches/new_vec_zeroed.x86-64.mca new file +113 -0

113 lines not on this page · raw message

rust/zerocopy/benches/new_zeroed.rs new file +9 -0
new file mode 100644
index 000000000000..b49f62edb146
@@ -0,0 +1,9 @@
+use zerocopy::*;
+
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_new_zeroed() -> format::LocoPacket {
+    FromZeros::new_zeroed()
+}
rust/zerocopy/benches/new_zeroed.x86-64 new file +3 -0
new file mode 100644
index 000000000000..b4d305e41fff
@@ -0,0 +1,3 @@
+bench_new_zeroed:
+	xor eax, eax
+	ret
rust/zerocopy/benches/new_zeroed.x86-64.mca new file +43 -0

43 lines not on this page · raw message

rust/zerocopy/benches/read_from_bytes.rs new file +7 -0
new file mode 100644
index 000000000000..8a3baddad9cb
@@ -0,0 +1,7 @@
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_read_from_bytes_static_size(source: &[u8]) -> Option<format::LocoPacket> {
+    zerocopy::FromBytes::read_from_bytes(source).ok()
+}
rust/zerocopy/benches/read_from_bytes.x86-64 new file +15 -0
new file mode 100644
index 000000000000..9082d79f1fd5
@@ -0,0 +1,15 @@
+bench_read_from_bytes_static_size:
+	mov rcx, rsi
+	cmp rsi, 6
+	jne .LBB5_2
+	mov eax, dword ptr [rdi]
+	movzx ecx, word ptr [rdi + 4]
+	shl rcx, 32
+	or rcx, rax
+.LBB5_2:
+	shl rcx, 16
+	inc rcx
+	xor eax, eax
+	cmp rsi, 6
+	cmove rax, rcx
+	ret
rust/zerocopy/benches/read_from_bytes.x86-64.mca new file +65 -0

65 lines not on this page · raw message

rust/zerocopy/benches/read_from_prefix.rs new file +10 -0
new file mode 100644
index 000000000000..d49bf80ab785
@@ -0,0 +1,10 @@
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_read_from_prefix_static_size(source: &[u8]) -> Option<format::LocoPacket> {
+    match zerocopy::FromBytes::read_from_prefix(source) {
+        Ok((packet, _rest)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/read_from_prefix.x86-64 new file +14 -0
new file mode 100644
index 000000000000..c75b06c0c22a
@@ -0,0 +1,14 @@
+bench_read_from_prefix_static_size:
+	cmp rsi, 5
+	jbe .LBB5_2
+	mov eax, dword ptr [rdi]
+	movzx edi, word ptr [rdi + 4]
+	shl rdi, 32
+	or rdi, rax
+.LBB5_2:
+	shl rdi, 16
+	inc rdi
+	xor eax, eax
+	cmp rsi, 6
+	cmovae rax, rdi
+	ret
rust/zerocopy/benches/read_from_prefix.x86-64.mca new file +63 -0

63 lines not on this page · raw message

rust/zerocopy/benches/read_from_suffix.rs new file +10 -0
new file mode 100644
index 000000000000..4eaadb0d4dff
@@ -0,0 +1,10 @@
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_read_from_suffix_static_size(source: &[u8]) -> Option<format::LocoPacket> {
+    match zerocopy::FromBytes::read_from_suffix(source) {
+        Ok((_rest, packet)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/read_from_suffix.x86-64 new file +15 -0
new file mode 100644
index 000000000000..5cff2a0e2f36
@@ -0,0 +1,15 @@
+bench_read_from_suffix_static_size:
+	mov rcx, rsi
+	cmp rsi, 6
+	jb .LBB5_2
+	mov eax, dword ptr [rdi + rsi - 6]
+	movzx ecx, word ptr [rdi + rsi - 2]
+	shl rcx, 32
+	or rcx, rax
+.LBB5_2:
+	shl rcx, 16
+	inc rcx
+	xor eax, eax
+	cmp rsi, 6
+	cmovae rax, rcx
+	ret
rust/zerocopy/benches/read_from_suffix.x86-64.mca new file +65 -0

65 lines not on this page · raw message

rust/zerocopy/benches/ref_from_bytes_dynamic_padding.rs new file +7 -0
new file mode 100644
index 000000000000..29708df55b45
@@ -0,0 +1,7 @@
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_bytes_dynamic_padding(source: &[u8]) -> Option<&format::LocoPacket> {
+    zerocopy::FromBytes::ref_from_bytes(source).ok()
+}
rust/zerocopy/benches/ref_from_bytes_dynamic_padding.x86-64 new file +22 -0
new file mode 100644
index 000000000000..e844a4608fac
@@ -0,0 +1,22 @@
+bench_ref_from_bytes_dynamic_padding:
+	test dil, 3
+	jne .LBB5_3
+	movabs rax, 9223372036854775804
+	and rax, rsi
+	cmp rax, 9
+	jb .LBB5_3
+	add rax, -9
+	movabs rcx, -6148914691236517205
+	mul rcx
+	shr rdx
+	lea rax, [rdx + 2*rdx]
+	or rax, 3
+	add rax, 9
+	cmp rsi, rax
+	je .LBB5_4
+.LBB5_3:
+	xor edi, edi
+	mov rdx, rsi
+.LBB5_4:
+	mov rax, rdi
+	ret
rust/zerocopy/benches/ref_from_bytes_dynamic_padding.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/ref_from_bytes_dynamic_size.rs new file +7 -0
new file mode 100644
index 000000000000..4eb4f970e365
@@ -0,0 +1,7 @@
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_bytes_dynamic_size(source: &[u8]) -> Option<&format::LocoPacket> {
+    zerocopy::FromBytes::ref_from_bytes(source).ok()
+}
rust/zerocopy/benches/ref_from_bytes_dynamic_size.x86-64 new file +20 -0
new file mode 100644
index 000000000000..cc905b76c06f
@@ -0,0 +1,20 @@
+bench_ref_from_bytes_dynamic_size:
+	mov rdx, rsi
+	cmp rsi, 4
+	setb al
+	or al, dil
+	test al, 1
+	je .LBB5_2
+	xor eax, eax
+	ret
+.LBB5_2:
+	lea rcx, [rdx - 4]
+	mov rsi, rcx
+	and rsi, -2
+	add rsi, 4
+	shr rcx
+	xor eax, eax
+	cmp rdx, rsi
+	cmove rdx, rcx
+	cmove rax, rdi
+	ret
rust/zerocopy/benches/ref_from_bytes_dynamic_size.x86-64.mca new file +75 -0

75 lines not on this page · raw message

rust/zerocopy/benches/ref_from_bytes_static_size.rs new file +7 -0
new file mode 100644
index 000000000000..3742bba0780f
@@ -0,0 +1,7 @@
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_bytes_static_size(source: &[u8]) -> Option<&format::LocoPacket> {
+    zerocopy::FromBytes::ref_from_bytes(source).ok()
+}
rust/zerocopy/benches/ref_from_bytes_static_size.x86-64 new file +8 -0
new file mode 100644
index 000000000000..2c8da68c8b5b
@@ -0,0 +1,8 @@
+bench_ref_from_bytes_static_size:
+	mov ecx, edi
+	and ecx, 1
+	xor rsi, 6
+	xor eax, eax
+	or rsi, rcx
+	cmove rax, rdi
+	ret
rust/zerocopy/benches/ref_from_bytes_static_size.x86-64.mca new file +53 -0

53 lines not on this page · raw message

rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.rs new file +10 -0
new file mode 100644
index 000000000000..b4fea4aee51d
@@ -0,0 +1,10 @@
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_bytes_with_elems_dynamic_padding(
+    source: &[u8],
+    count: usize,
+) -> Option<&format::LocoPacket> {
+    zerocopy::FromBytes::ref_from_bytes_with_elems(source, count).ok()
+}
rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.x86-64 new file +19 -0
new file mode 100644
index 000000000000..d579b3faefe7
@@ -0,0 +1,19 @@
+bench_ref_from_bytes_with_elems_dynamic_padding:
+	movabs rax, 3074457345618258598
+	cmp rdx, rax
+	seta cl
+	mov rax, rdi
+	test al, 3
+	setne dil
+	or dil, cl
+	jne .LBB5_2
+	lea rcx, [rdx + 2*rdx]
+	or rcx, 3
+	add rcx, 9
+	cmp rsi, rcx
+	je .LBB5_3
+.LBB5_2:
+	xor eax, eax
+	mov rdx, rsi
+.LBB5_3:
+	ret
rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_padding.x86-64.mca new file +71 -0

71 lines not on this page · raw message

rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.rs new file +10 -0
new file mode 100644
index 000000000000..9d33a7c31bc3
@@ -0,0 +1,10 @@
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_bytes_with_elems_dynamic_size(
+    source: &[u8],
+    count: usize,
+) -> Option<&format::LocoPacket> {
+    zerocopy::FromBytes::ref_from_bytes_with_elems(source, count).ok()
+}
rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.x86-64 new file +16 -0
new file mode 100644
index 000000000000..3d8d15b7f6c1
@@ -0,0 +1,16 @@
+bench_ref_from_bytes_with_elems_dynamic_size:
+	movabs rax, 4611686018427387901
+	cmp rdx, rax
+	seta cl
+	mov rax, rdi
+	or dil, cl
+	test dil, 1
+	jne .LBB5_2
+	lea rcx, [2*rdx + 4]
+	cmp rsi, rcx
+	je .LBB5_3
+.LBB5_2:
+	xor eax, eax
+	mov rdx, rsi
+.LBB5_3:
+	ret
rust/zerocopy/benches/ref_from_bytes_with_elems_dynamic_size.x86-64.mca new file +65 -0

65 lines not on this page · raw message

rust/zerocopy/benches/ref_from_prefix_dynamic_padding.rs new file +10 -0
new file mode 100644
index 000000000000..53c707b88256
@@ -0,0 +1,10 @@
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_prefix_dynamic_padding(source: &[u8]) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_prefix(source) {
+        Ok((packet, _rest)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_prefix_dynamic_padding.x86-64 new file +22 -0
new file mode 100644
index 000000000000..a58592a24503
@@ -0,0 +1,22 @@
+bench_ref_from_prefix_dynamic_padding:
+	xor edx, edx
+	mov eax, 0
+	test dil, 3
+	je .LBB5_1
+	ret
+.LBB5_1:
+	movabs rax, 9223372036854775804
+	and rsi, rax
+	cmp rsi, 9
+	jae .LBB5_3
+	mov edx, 1
+	xor eax, eax
+	ret
+.LBB5_3:
+	add rsi, -9
+	movabs rcx, -6148914691236517205
+	mov rax, rsi
+	mul rcx
+	shr rdx
+	mov rax, rdi
+	ret
rust/zerocopy/benches/ref_from_prefix_dynamic_padding.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/ref_from_prefix_dynamic_size.rs new file +10 -0
new file mode 100644
index 000000000000..a3f26f6b4e6c
@@ -0,0 +1,10 @@
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_prefix_dynamic_size(source: &[u8]) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_prefix(source) {
+        Ok((packet, _rest)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_prefix_dynamic_size.x86-64 new file +17 -0
new file mode 100644
index 000000000000..fe6332c9100c
@@ -0,0 +1,17 @@
+bench_ref_from_prefix_dynamic_size:
+	xor edx, edx
+	mov eax, 0
+	test dil, 1
+	jne .LBB5_4
+	cmp rsi, 4
+	jae .LBB5_3
+	mov edx, 1
+	xor eax, eax
+	ret
+.LBB5_3:
+	add rsi, -4
+	shr rsi
+	mov rdx, rsi
+	mov rax, rdi
+.LBB5_4:
+	ret
rust/zerocopy/benches/ref_from_prefix_dynamic_size.x86-64.mca new file +67 -0

67 lines not on this page · raw message

rust/zerocopy/benches/ref_from_prefix_static_size.rs new file +10 -0
new file mode 100644
index 000000000000..834fa3928611
@@ -0,0 +1,10 @@
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_prefix_static_size(source: &[u8]) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_prefix(source) {
+        Ok((packet, _rest)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_prefix_static_size.x86-64 new file +8 -0
new file mode 100644
index 000000000000..7c1bf45bb6c2
@@ -0,0 +1,8 @@
+bench_ref_from_prefix_static_size:
+	xor eax, eax
+	cmp rsi, 6
+	mov rcx, rdi
+	cmovb rcx, rax
+	test dil, 1
+	cmove rax, rcx
+	ret
rust/zerocopy/benches/ref_from_prefix_static_size.x86-64.mca new file +53 -0

53 lines not on this page · raw message

rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.rs new file +13 -0
new file mode 100644
index 000000000000..55d495e00c59
@@ -0,0 +1,13 @@
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_prefix_with_elems_dynamic_padding(
+    source: &[u8],
+    count: usize,
+) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_prefix_with_elems(source, count) {
+        Ok((packet, _rest)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.x86-64 new file +26 -0
new file mode 100644
index 000000000000..5b31277bdebe
@@ -0,0 +1,26 @@
+bench_ref_from_prefix_with_elems_dynamic_padding:
+	movabs rax, 3074457345618258598
+	cmp rdx, rax
+	ja .LBB5_1
+	xor ecx, ecx
+	mov eax, 0
+	test dil, 3
+	je .LBB5_3
+	mov rdx, rcx
+	ret
+.LBB5_1:
+	mov edx, 1
+	xor eax, eax
+	ret
+.LBB5_3:
+	lea rax, [rdx + 2*rdx]
+	or rax, 3
+	add rax, 9
+	xor r8d, r8d
+	cmp rax, rsi
+	mov ecx, 1
+	cmovbe rcx, rdx
+	cmova rdi, r8
+	mov rax, rdi
+	mov rdx, rcx
+	ret
rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_padding.x86-64.mca new file +85 -0

85 lines not on this page · raw message

rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.rs new file +13 -0
new file mode 100644
index 000000000000..e9663c721ece
@@ -0,0 +1,13 @@
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_prefix_with_elems_dynamic_size(
+    source: &[u8],
+    count: usize,
+) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_prefix_with_elems(source, count) {
+        Ok((packet, _rest)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.x86-64 new file +22 -0
new file mode 100644
index 000000000000..069fd4859c74
@@ -0,0 +1,22 @@
+bench_ref_from_prefix_with_elems_dynamic_size:
+	movabs rax, 4611686018427387901
+	cmp rdx, rax
+	ja .LBB5_1
+	mov rcx, rdx
+	xor edx, edx
+	mov eax, 0
+	test dil, 1
+	jne .LBB5_4
+	lea rax, [2*rcx + 4]
+	xor r8d, r8d
+	cmp rax, rsi
+	mov edx, 1
+	cmovbe rdx, rcx
+	cmova rdi, r8
+	mov rax, rdi
+.LBB5_4:
+	ret
+.LBB5_1:
+	mov edx, 1
+	xor eax, eax
+	ret
rust/zerocopy/benches/ref_from_prefix_with_elems_dynamic_size.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/ref_from_suffix_dynamic_padding.rs new file +10 -0
new file mode 100644
index 000000000000..5a6ea3a33dde
@@ -0,0 +1,10 @@
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_suffix_dynamic_padding(source: &[u8]) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_suffix(source) {
+        Ok((_rest, packet)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_suffix_dynamic_padding.x86-64 new file +23 -0
new file mode 100644
index 000000000000..3e05f6023f38
@@ -0,0 +1,23 @@
+bench_ref_from_suffix_dynamic_padding:
+	lea eax, [rsi + rdi]
+	test al, 3
+	jne .LBB5_1
+	movabs rax, 9223372036854775804
+	and rax, rsi
+	cmp rax, 9
+	jae .LBB5_3
+.LBB5_1:
+	xor eax, eax
+	ret
+.LBB5_3:
+	add rax, -9
+	movabs rcx, -6148914691236517205
+	mul rcx
+	shr rdx
+	lea rax, [rdx + 2*rdx]
+	sub rsi, rax
+	or rax, -4
+	add rsi, rdi
+	add rax, rsi
+	add rax, -8
+	ret
rust/zerocopy/benches/ref_from_suffix_dynamic_padding.x86-64.mca new file +79 -0

79 lines not on this page · raw message

rust/zerocopy/benches/ref_from_suffix_dynamic_size.rs new file +10 -0
new file mode 100644
index 000000000000..3437b14f404a
@@ -0,0 +1,10 @@
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_suffix_dynamic_size(source: &[u8]) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_suffix(source) {
+        Ok((_rest, packet)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_suffix_dynamic_size.x86-64 new file +13 -0
new file mode 100644
index 000000000000..bd4ace89836a
@@ -0,0 +1,13 @@
+bench_ref_from_suffix_dynamic_size:
+	mov rdx, rsi
+	lea ecx, [rsi + rdi]
+	mov eax, edx
+	and eax, 1
+	add rax, rdi
+	xor esi, esi
+	sub rdx, 4
+	cmovb rax, rsi
+	shr rdx
+	test cl, 1
+	cmovne rax, rsi
+	ret
rust/zerocopy/benches/ref_from_suffix_dynamic_size.x86-64.mca new file +63 -0

63 lines not on this page · raw message

rust/zerocopy/benches/ref_from_suffix_static_size.rs new file +10 -0
new file mode 100644
index 000000000000..c8435d10d38c
@@ -0,0 +1,10 @@
+#[path = "formats/coco_static_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_suffix_static_size(source: &[u8]) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_suffix(source) {
+        Ok((_rest, packet)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_suffix_static_size.x86-64 new file +13 -0
new file mode 100644
index 000000000000..9e90b9e2543f
@@ -0,0 +1,13 @@
+bench_ref_from_suffix_static_size:
+	lea eax, [rsi + rdi]
+	cmp rsi, 6
+	setb cl
+	or cl, al
+	test cl, 1
+	je .LBB5_2
+	xor eax, eax
+	ret
+.LBB5_2:
+	lea rax, [rdi + rsi]
+	add rax, -6
+	ret
rust/zerocopy/benches/ref_from_suffix_static_size.x86-64.mca new file +61 -0

61 lines not on this page · raw message

rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.rs new file +13 -0
new file mode 100644
index 000000000000..73d91cee5992
@@ -0,0 +1,13 @@
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_suffix_with_elems_dynamic_padding(
+    source: &[u8],
+    count: usize,
+) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_suffix_with_elems(source, count) {
+        Ok((_rest, packet)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.x86-64 new file +27 -0
new file mode 100644
index 000000000000..c3d10b5fc685
@@ -0,0 +1,27 @@
+bench_ref_from_suffix_with_elems_dynamic_padding:
+	movabs rax, 3074457345618258598
+	cmp rdx, rax
+	ja .LBB5_1
+	lea r8d, [rsi + rdi]
+	xor ecx, ecx
+	mov eax, 0
+	test r8b, 3
+	je .LBB5_3
+	mov rdx, rcx
+	ret
+.LBB5_3:
+	lea rax, [rdx + 2*rdx]
+	or rax, 3
+	add rax, 9
+	sub rsi, rax
+	jae .LBB5_4
+.LBB5_1:
+	xor eax, eax
+	mov edx, 1
+	ret
+.LBB5_4:
+	add rdi, rsi
+	mov rcx, rdx
+	mov rax, rdi
+	mov rdx, rcx
+	ret
rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_padding.x86-64.mca new file +85 -0

85 lines not on this page · raw message

rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.rs new file +13 -0
new file mode 100644
index 000000000000..68a28baf55e6
@@ -0,0 +1,13 @@
+#[path = "formats/coco_dynamic_size.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_ref_from_suffix_with_elems_dynamic_size(
+    source: &[u8],
+    count: usize,
+) -> Option<&format::LocoPacket> {
+    match zerocopy::FromBytes::ref_from_suffix_with_elems(source, count) {
+        Ok((_rest, packet)) => Some(packet),
+        _ => None,
+    }
+}
rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.x86-64 new file +23 -0
new file mode 100644
index 000000000000..bdca57192455
@@ -0,0 +1,23 @@
+bench_ref_from_suffix_with_elems_dynamic_size:
+	movabs rax, 4611686018427387901
+	cmp rdx, rax
+	ja .LBB5_1
+	lea r8d, [rsi + rdi]
+	xor ecx, ecx
+	mov eax, 0
+	test r8b, 1
+	jne .LBB5_5
+	lea rax, [2*rdx + 4]
+	sub rsi, rax
+	jae .LBB5_4
+.LBB5_1:
+	xor eax, eax
+	mov edx, 1
+	ret
+.LBB5_4:
+	add rdi, rsi
+	mov rcx, rdx
+	mov rax, rdi
+.LBB5_5:
+	mov rdx, rcx
+	ret
rust/zerocopy/benches/ref_from_suffix_with_elems_dynamic_size.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/split_at_dynamic_padding.rs new file +12 -0
new file mode 100644
index 000000000000..bed90f60165e
@@ -0,0 +1,12 @@
+use zerocopy::*;
+
+#[path = "formats/coco_dynamic_padding.rs"]
+mod format;
+
+#[unsafe(no_mangle)]
+fn bench_split_at_dynamic_padding(
+    source: &format::CocoPacket,
+    len: usize,
+) -> Option<Split<&format::CocoPacket>> {
+    source.split_at(len)
+}
rust/zerocopy/benches/split_at_dynamic_padding.x86-64 new file +12 -0
new file mode 100644
index 000000000000..6eaf5a004612
@@ -0,0 +1,12 @@
+bench_split_at_dynamic_padding:
+	mov rax, rdi
+	cmp rcx, rdx
+	jbe .LBB5_2
+	xor esi, esi
+	mov qword ptr [rax], rsi
+	ret
+.LBB5_2:
+	mov qword ptr [rax + 8], rdx
+	mov qword ptr [rax + 16], rcx
+	mov qword ptr [rax], rsi
+	ret
rust/zerocopy/benches/split_at_dynamic_padding.x86-64.mca new file +59 -0

19 lines not on this page · raw message

rust/zerocopy/benches/split_at_dynamic_size.rs new file +12 -0
new file mode 100644
index 000000000000..07a22ba2e5b5

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_at_dynamic_size.x86-64 new file +12 -0
new file mode 100644
index 000000000000..8d81b98bdab1

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_at_dynamic_size.x86-64.mca new file +59 -0

59 lines not on this page · raw message

rust/zerocopy/benches/split_at_unchecked_dynamic_padding.rs new file +12 -0
new file mode 100644
index 000000000000..3c147d3bdd39

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_at_unchecked_dynamic_padding.x86-64 new file +6 -0
new file mode 100644
index 000000000000..74c3b52f63fa

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_at_unchecked_dynamic_padding.x86-64.mca new file +49 -0

49 lines not on this page · raw message

rust/zerocopy/benches/split_at_unchecked_dynamic_size.rs new file +12 -0
new file mode 100644
index 000000000000..b1aa1dfb35be

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_at_unchecked_dynamic_size.x86-64 new file +6 -0
new file mode 100644
index 000000000000..56671d1ee8dc

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_at_unchecked_dynamic_size.x86-64.mca new file +49 -0

49 lines not on this page · raw message

rust/zerocopy/benches/split_via_immutable_dynamic_padding.rs new file +11 -0
new file mode 100644
index 000000000000..b86ad3614bf7

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_immutable_dynamic_padding.x86-64 new file +14 -0
new file mode 100644
index 000000000000..dac183428b31

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_immutable_dynamic_padding.x86-64.mca new file +65 -0

65 lines not on this page · raw message

rust/zerocopy/benches/split_via_immutable_dynamic_size.rs new file +11 -0
new file mode 100644
index 000000000000..7d115caa3c00

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_immutable_dynamic_size.x86-64 new file +13 -0
new file mode 100644
index 000000000000..58f6b09fc9d2

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_immutable_dynamic_size.x86-64.mca new file +63 -0

63 lines not on this page · raw message

rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.rs new file +11 -0
new file mode 100644
index 000000000000..edba7bf34ba8

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.x86-64 new file +22 -0
new file mode 100644
index 000000000000..03684cb09f8f

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_runtime_check_dynamic_padding.x86-64.mca new file +79 -0

79 lines not on this page · raw message

rust/zerocopy/benches/split_via_runtime_check_dynamic_size.rs new file +11 -0
new file mode 100644
index 000000000000..ce22de909aca

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_runtime_check_dynamic_size.x86-64 new file +13 -0
new file mode 100644
index 000000000000..e54276bd85e8

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_runtime_check_dynamic_size.x86-64.mca new file +63 -0

63 lines not on this page · raw message

rust/zerocopy/benches/split_via_unchecked_dynamic_padding.rs new file +11 -0
new file mode 100644
index 000000000000..21d74dba176f

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_unchecked_dynamic_padding.x86-64 new file +14 -0
new file mode 100644
index 000000000000..3c2c4ec9f6ed

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_unchecked_dynamic_padding.x86-64.mca new file +65 -0

65 lines not on this page · raw message

rust/zerocopy/benches/split_via_unchecked_dynamic_size.rs new file +11 -0
new file mode 100644
index 000000000000..824e22d67a7b

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_unchecked_dynamic_size.x86-64 new file +13 -0
new file mode 100644
index 000000000000..1e31268edc7f

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/split_via_unchecked_dynamic_size.x86-64.mca new file +63 -0

63 lines not on this page · raw message

rust/zerocopy/benches/transmute.rs new file +16 -0
new file mode 100644
index 000000000000..e60bfb252f5c

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/transmute.x86-64 new file +3 -0
new file mode 100644
index 000000000000..a4c6299d1112

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/transmute.x86-64.mca new file +43 -0

43 lines not on this page · raw message

rust/zerocopy/benches/transmute_ref_dynamic_size.rs new file +16 -0
new file mode 100644
index 000000000000..825f0f2bed24

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/transmute_ref_dynamic_size.x86-64 new file +4 -0
new file mode 100644
index 000000000000..80a0f5906610

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/transmute_ref_dynamic_size.x86-64.mca new file +45 -0

45 lines not on this page · raw message

rust/zerocopy/benches/transmute_ref_static_size.rs new file +15 -0
new file mode 100644
index 000000000000..a6db611fde0d

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/transmute_ref_static_size.x86-64 new file +3 -0
new file mode 100644
index 000000000000..7a9229c129b0

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/transmute_ref_static_size.x86-64.mca new file +43 -0

43 lines not on this page · raw message

rust/zerocopy/benches/try_read_from_bytes.rs new file +7 -0
new file mode 100644
index 000000000000..f8384b32f518

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_read_from_bytes.x86-64 new file +23 -0
new file mode 100644
index 000000000000..08088a08fd85

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_read_from_bytes.x86-64.mca new file +79 -0

79 lines not on this page · raw message

rust/zerocopy/benches/try_read_from_prefix.rs new file +10 -0
new file mode 100644
index 000000000000..fabbac3bd7d9

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_read_from_prefix.x86-64 new file +16 -0
new file mode 100644
index 000000000000..d3e1edc3ea73

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_read_from_prefix.x86-64.mca new file +67 -0

67 lines not on this page · raw message

rust/zerocopy/benches/try_read_from_suffix.rs new file +10 -0
new file mode 100644
index 000000000000..1e961647b3f3

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_read_from_suffix.x86-64 new file +18 -0
new file mode 100644
index 000000000000..095e326f0467

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_read_from_suffix.x86-64.mca new file +71 -0

71 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.rs new file +7 -0
new file mode 100644
index 000000000000..126009cd71d5

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.x86-64 new file +24 -0
new file mode 100644
index 000000000000..217c5fc61796

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_dynamic_padding.x86-64.mca new file +81 -0

81 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.rs new file +7 -0
new file mode 100644
index 000000000000..fc3cfbae27a2

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.x86-64 new file +22 -0
new file mode 100644
index 000000000000..cf67afd31ce0

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_dynamic_size.x86-64.mca new file +79 -0

79 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_bytes_static_size.rs new file +7 -0
new file mode 100644
index 000000000000..521557146324

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_static_size.x86-64 new file +13 -0
new file mode 100644
index 000000000000..a11f27189e90

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_static_size.x86-64.mca new file +59 -0

59 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.rs new file +10 -0
new file mode 100644
index 000000000000..8b9e7355e367

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.x86-64 new file +21 -0
new file mode 100644
index 000000000000..3ef8d1448a50

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_padding.x86-64.mca new file +75 -0

75 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.rs new file +10 -0
new file mode 100644
index 000000000000..9ccd6fef558a

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.x86-64 new file +18 -0
new file mode 100644
index 000000000000..ba34b1855bf1

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_bytes_with_elems_dynamic_size.x86-64.mca new file +69 -0

69 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.rs new file +10 -0
new file mode 100644
index 000000000000..23b346f9c98d

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.x86-64 new file +29 -0
new file mode 100644
index 000000000000..d832cb7ecf7f

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_dynamic_padding.x86-64.mca new file +91 -0

91 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.rs new file +10 -0
new file mode 100644
index 000000000000..41a466ec8e6a

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.x86-64 new file +22 -0
new file mode 100644
index 000000000000..be7f34b9f8f5

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_dynamic_size.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_prefix_static_size.rs new file +10 -0
new file mode 100644
index 000000000000..5f13d482b505

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_static_size.x86-64 new file +15 -0
new file mode 100644
index 000000000000..83212f776ea6

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_static_size.x86-64.mca new file +63 -0

63 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.rs new file +13 -0
new file mode 100644
index 000000000000..1744a40759b1

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.x86-64 new file +30 -0
new file mode 100644
index 000000000000..80e66ba1601c

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_padding.x86-64.mca new file +91 -0

91 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.rs new file +13 -0
new file mode 100644
index 000000000000..ed0f50941194

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.x86-64 new file +26 -0
new file mode 100644
index 000000000000..c12e87c137c5

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_prefix_with_elems_dynamic_size.x86-64.mca new file +83 -0

83 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.rs new file +10 -0
new file mode 100644
index 000000000000..981feca3ca24

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.x86-64 new file +26 -0
new file mode 100644
index 000000000000..b3e924442865

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_dynamic_padding.x86-64.mca new file +85 -0

85 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.rs new file +10 -0
new file mode 100644
index 000000000000..c3d75ac9b3e1

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.x86-64 new file +18 -0
new file mode 100644
index 000000000000..d51f7817e599

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_dynamic_size.x86-64.mca new file +71 -0

71 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_suffix_static_size.rs new file +10 -0
new file mode 100644
index 000000000000..d4b92f639a32

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_static_size.x86-64 new file +16 -0
new file mode 100644
index 000000000000..cd39f70931bc

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_static_size.x86-64.mca new file +67 -0

67 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.rs new file +13 -0
new file mode 100644
index 000000000000..1da455c9a238

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.x86-64 new file +32 -0
new file mode 100644
index 000000000000..c7530d8b6815

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_padding.x86-64.mca new file +95 -0

95 lines not on this page · raw message

rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.rs new file +13 -0
new file mode 100644
index 000000000000..8c2b80f8762f

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.x86-64 new file +28 -0
new file mode 100644
index 000000000000..952eb12de8d6

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_ref_from_suffix_with_elems_dynamic_size.x86-64.mca new file +87 -0

87 lines not on this page · raw message

rust/zerocopy/benches/try_transmute.rs new file +16 -0
new file mode 100644
index 000000000000..c0de07a8d094

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_transmute.x86-64 new file +9 -0
new file mode 100644
index 000000000000..9e16a663257c

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_transmute.x86-64.mca new file +55 -0

55 lines not on this page · raw message

rust/zerocopy/benches/try_transmute_ref_dynamic_size.rs new file +18 -0
new file mode 100644
index 000000000000..c9236e13d23c

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_transmute_ref_dynamic_size.x86-64 new file +6 -0
new file mode 100644
index 000000000000..d34d2b3eb3df

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_transmute_ref_dynamic_size.x86-64.mca new file +49 -0

49 lines not on this page · raw message

rust/zerocopy/benches/try_transmute_ref_static_size.rs new file +17 -0
new file mode 100644
index 000000000000..631cce2b0bb9

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_transmute_ref_static_size.x86-64 new file +5 -0
new file mode 100644
index 000000000000..8c16face9875

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/try_transmute_ref_static_size.x86-64.mca new file +47 -0

47 lines not on this page · raw message

rust/zerocopy/benches/write_to_dynamic_size.rs new file +9 -0
new file mode 100644
index 000000000000..c126a1468c9b

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_dynamic_size.x86-64 new file +21 -0
new file mode 100644
index 000000000000..c5abb17f7eba

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_dynamic_size.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/write_to_prefix_dynamic_size.rs new file +12 -0
new file mode 100644
index 000000000000..a54d32773113

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_prefix_dynamic_size.x86-64 new file +21 -0
new file mode 100644
index 000000000000..d7779c6c9178

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_prefix_dynamic_size.x86-64.mca new file +77 -0

77 lines not on this page · raw message

rust/zerocopy/benches/write_to_prefix_static_size.rs new file +12 -0
new file mode 100644
index 000000000000..826222c129fe

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_prefix_static_size.x86-64 new file +11 -0
new file mode 100644
index 000000000000..9cf066295304

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_prefix_static_size.x86-64.mca new file +57 -0

57 lines not on this page · raw message

rust/zerocopy/benches/write_to_static_size.rs new file +9 -0
new file mode 100644
index 000000000000..3bb9435c5ade

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_static_size.x86-64 new file +11 -0
new file mode 100644
index 000000000000..d6413e0fd614

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_static_size.x86-64.mca new file +57 -0

57 lines not on this page · raw message

rust/zerocopy/benches/write_to_suffix_dynamic_size.rs new file +12 -0
new file mode 100644
index 000000000000..9fa6b91cda41

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_suffix_dynamic_size.x86-64 new file +22 -0
new file mode 100644
index 000000000000..75f349562db6

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_suffix_dynamic_size.x86-64.mca new file +79 -0

79 lines not on this page · raw message

rust/zerocopy/benches/write_to_suffix_static_size.rs new file +12 -0
new file mode 100644
index 000000000000..1c95aba4b16c

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_suffix_static_size.x86-64 new file +11 -0
new file mode 100644
index 000000000000..934aa370d4d6

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/write_to_suffix_static_size.x86-64.mca new file +57 -0

57 lines not on this page · raw message

rust/zerocopy/benches/zero_dynamic_padding.rs new file +9 -0
new file mode 100644
index 000000000000..8eda0953d1e6

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/zero_dynamic_padding.x86-64 new file +7 -0
new file mode 100644
index 000000000000..7dccf1745f81

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/zero_dynamic_padding.x86-64.mca new file +51 -0

51 lines not on this page · raw message

rust/zerocopy/benches/zero_dynamic_size.rs new file +9 -0
new file mode 100644
index 000000000000..536d800ebc76

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/zero_dynamic_size.x86-64 new file +5 -0
new file mode 100644
index 000000000000..2b31ed644eaf

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/zero_dynamic_size.x86-64.mca new file +47 -0

47 lines not on this page · raw message

rust/zerocopy/benches/zero_static_size.rs new file +9 -0
new file mode 100644
index 000000000000..fa7fa0839c15

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/zero_static_size.x86-64 new file +4 -0
new file mode 100644
index 000000000000..ced8e18949b2

Lines of this file are not shown. View the raw message.

rust/zerocopy/benches/zero_static_size.x86-64.mca new file +45 -0

45 lines not on this page · raw message

rust/zerocopy/rustdoc/style.css new file +55 -0

55 lines not on this page · raw message

rust/zerocopy/src/byte_slice.rs new file +432 -0

432 lines not on this page · raw message

rust/zerocopy/src/byteorder.rs new file +1563 -0

1,563 lines not on this page · raw message

rust/zerocopy/src/deprecated.rs new file +279 -0

279 lines not on this page · raw message

rust/zerocopy/src/error.rs new file +1348 -0

1,348 lines not on this page · raw message

rust/zerocopy/src/impls.rs new file +2387 -0

2,387 lines not on this page · raw message

rust/zerocopy/src/layout.rs new file +2223 -0

2,223 lines not on this page · raw message

rust/zerocopy/src/lib.rs new file +7610 -0

7,610 lines not on this page · raw message

rust/zerocopy/src/macros.rs new file +1823 -0

1,823 lines not on this page · raw message

rust/zerocopy/src/pointer/inner.rs new file +752 -0

752 lines not on this page · raw message

rust/zerocopy/src/pointer/invariant.rs new file +296 -0

296 lines not on this page · raw message

rust/zerocopy/src/pointer/mod.rs new file +408 -0

408 lines not on this page · raw message

rust/zerocopy/src/pointer/ptr.rs new file +1584 -0

1,584 lines not on this page · raw message

rust/zerocopy/src/pointer/transmute.rs new file +520 -0

520 lines not on this page · raw message

rust/zerocopy/src/ref.rs new file +1356 -0

1,356 lines not on this page · raw message

rust/zerocopy/src/split_at.rs new file +1088 -0

1,088 lines not on this page · raw message

rust/zerocopy/src/util/macro_util.rs new file +1308 -0

1,308 lines not on this page · raw message

rust/zerocopy/src/util/macros.rs new file +1065 -0

1,065 lines not on this page · raw message

rust/zerocopy/src/util/mod.rs new file +936 -0

936 lines not on this page · raw message

rust/zerocopy/src/wrappers.rs new file +1032 -0

1,032 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.54.0

Part of the diff is not shown here. View the raw message.

author maintainer
#9 lore raw

PATCH v2 9/19 rust: zerocopy: add SPDX License Identifiers

In reply to Miguel Ojeda

Originally, when the Rust upstream alloc standard library crate was vendored, the SPDX License Identifiers were added to every file so that the license on those was clear. The same happened with the vendoring of proc_macro2, quote and syn. Please see:

commit 057b8d257107 ("rust: adapt alloc crate to the kernel") commit 69942c0a8965 ("rust: syn: add SPDX License Identifiers") commit ddfa1b279d08 ("rust: quote: add SPDX License Identifiers") commit a9acfceb9614 ("rust: proc-macro2: add SPDX License Identifiers")

Thus do the same for the zerocopy crate.

This makes scripts/spdxcheck.py pass: use parentheses like commit 06e9bfc1e57d ("ionic: make spdxcheck.py happy") did since we have two OR operators in the expression (three licenses).

SPDX identifiers are not added to the benches files because they are included in rendered documentation. Nevertheless, the README.md to be added by a later commit mentions the license.

Finally, as requested, I filed an issue [1] with upstream about it.

---
 rust/zerocopy/rustdoc/style.css        | 2 ++
 rust/zerocopy/src/byte_slice.rs        | 2 ++
 rust/zerocopy/src/byteorder.rs         | 2 ++
 rust/zerocopy/src/deprecated.rs        | 2 ++
 rust/zerocopy/src/error.rs             | 2 ++
 rust/zerocopy/src/impls.rs             | 2 ++
 rust/zerocopy/src/layout.rs            | 2 ++
 rust/zerocopy/src/lib.rs               | 2 ++
 rust/zerocopy/src/macros.rs            | 2 ++
 rust/zerocopy/src/pointer/inner.rs     | 2 ++
 rust/zerocopy/src/pointer/invariant.rs | 2 ++
 rust/zerocopy/src/pointer/mod.rs       | 2 ++
 rust/zerocopy/src/pointer/ptr.rs       | 2 ++
 rust/zerocopy/src/pointer/transmute.rs | 2 ++
 rust/zerocopy/src/ref.rs               | 2 ++
 rust/zerocopy/src/split_at.rs          | 2 ++
 rust/zerocopy/src/util/macro_util.rs   | 2 ++
 rust/zerocopy/src/util/macros.rs       | 2 ++
 rust/zerocopy/src/util/mod.rs          | 2 ++
 rust/zerocopy/src/wrappers.rs          | 2 ++
 20 files changed, 40 insertions(+)
rust/zerocopy/rustdoc/style.css +2 -0
index c5c8aeb743a1..414348964af2 100644
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT */
+
 /*
 Copyright 2026 The Fuchsia Authors
 
rust/zerocopy/src/byte_slice.rs +2 -0
index 6f9ee9ac3336..a5ded4a18b39 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/byteorder.rs +2 -0
index 257505203415..36ca4c0c88b0 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2019 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/deprecated.rs +2 -0
index 61b29aa5f485..24bafbf9adeb 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/error.rs +2 -0
index 05fdfe3b91f8..7cb08c31d452 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/impls.rs +2 -0
index 80538bfc8a26..22fd6c3d5d94 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/layout.rs +2 -0
index 19ad5ca85f74..6015d0f2de52 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/lib.rs +2 -0
index 89a696f732b8..3302d67602ab 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2018 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/macros.rs +2 -0
index 948f8f912bb7..b801d86a8fa6 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/pointer/inner.rs +2 -0
index c8dd9f01f456..5db08080141f 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/pointer/invariant.rs +2 -0
index 2af211dd9fdd..1802d23563db 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/pointer/mod.rs +2 -0
index 4c3658679d46..3461f7f5ca80 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2023 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/pointer/ptr.rs +2 -0
index 307b2aee63ca..b7c4ea56d2b2 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2023 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/pointer/transmute.rs +2 -0
index 45b4f727fd0d..a534984b70d3 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2025 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/ref.rs +2 -0
index 496afc435c61..860066d75196 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2024 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/split_at.rs +2 -0
index 1d7b2c7d6032..9a67d5acbb0d 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2025 The Fuchsia Authors
 //
 // Licensed under the 2-Clause BSD License <LICENSE-BSD or
rust/zerocopy/src/util/macro_util.rs +2 -0
index 2235d0b8b49a..1abb0fbeb46e 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2022 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/util/macros.rs +2 -0
index 7dca5410c84f..43e4fd64ee15 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2023 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/util/mod.rs +2 -0
index 1a6c0b22a47b..d6d4c6c2fcd9 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2023 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy/src/wrappers.rs +2 -0
index f3930eb7ebc0..266aec25fa58 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2023 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
Signature · 1 line
2.54.0
author maintainer
#10 lore raw

PATCH v2 10/19 rust: zerocopy: remove float `Display` support

In reply to Miguel Ojeda

The kernel builds core with the no_fp_fmt_parse --cfg, which means we do not have support for formatting floating point primitives. However, zerocopy expects those implementations to exist:

    error[E0277]: `f32` doesn't implement `core::fmt::Display`
       --> rust/zerocopy/src/byteorder.rs:172:29
        |
    172 |                   $trait::fmt(&self.get(), f)
        |                   ----------- ^^^^^^^^^^^ the trait `core::fmt::Display` is not implemented for `f32`
        |                   |
        |                   required by a bound introduced by this call
    ...
    907 | / define_type!(
    908 | |     An,
    909 | |     "A 32-bit floating point number",
    910 | |     F32,
    ...   |
    922 | |     []
    923 | | );
        | |_- in this macro invocation
        |
        = help: the following other types implement trait `core::fmt::Display`:
                  i128
                  i16
                  i32
                  i64
                  i8
                  isize
                  u128
                  u16
                and 4 others
        = note: this error originates in the macro `impl_fmt_trait` which comes from the expansion of the macro `define_type` (in Nightly builds, run with -Z macro-backtrace for more info)

Thus work around it by skipping those implementations in zerocopy.

Ideally, zerocopy would have the equivalent of no_fp_fmt_parse; and, indeed, upstream just added it [1] after I filed an issue [2] about it as requested. We can try it in a future update of our vendored copy.

---
 rust/zerocopy/src/byteorder.rs | 1 -
 1 file changed, 1 deletion(-)
rust/zerocopy/src/byteorder.rs +0 -1
index 36ca4c0c88b0..8f70048f1eb0 100644
@@ -177,7 +177,6 @@ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
 
 macro_rules! impl_fmt_traits {
     ($name:ident, $native:ident, "floating point number") => {
-        impl_fmt_trait!($name, $native, Display);
     };
     ($name:ident, $native:ident, "unsigned integer") => {
         impl_fmt_traits!($name, $native, @all_types);
Signature · 1 line
2.54.0
author maintainer
#11 lore raw

PATCH v2 11/19 rust: zerocopy: add `README.md`

In reply to Miguel Ojeda

Originally, when the Rust upstream alloc standard library crate was vendored in commit 057b8d257107 ("rust: adapt alloc crate to the kernel"), a README.md file was added to explain the provenance and licensing of the source files.

Thus do the same for the zerocopy crate.

Cc Joshua Liebow-Feeser <[email protected]>
Cc Jack Wrenn <[email protected]>
---
 rust/zerocopy/README.md | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 rust/zerocopy/README.md
rust/zerocopy/README.md new file +14 -0
new file mode 100644
index 000000000000..99e6cad0e26c
@@ -0,0 +1,14 @@
+# `zerocopy`
+
+These source files come from the Rust `zerocopy` crate, version v0.8.50
+(released 2026-05-31), hosted in the <https://github.com/google/zerocopy>
+repository, licensed under "BSD-2-Clause OR Apache-2.0 OR MIT" and only
+modified to add the SPDX license identifiers and to remove `Display`
+for `f32` and `f64`.
+
+For copyright details, please see:
+
+    https://github.com/google/zerocopy/blob/v0.8.50/README.md?plain=1
+    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-BSD
+    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-APACHE
+    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-MIT
Signature · 1 line
2.54.0
author maintainer
#12 lore raw

PATCH v2 12/19 rust: zerocopy: enable support in kbuild

In reply to Miguel Ojeda

With all the new files in place and ready from the new crate, enable the support for it in the build system.

In addition, skip formatting for this vendored crate.

Finally, there are no generated symbols expected from zerocopy, thus skip adding the exports generation.

---
 Makefile                          |  1 +
 rust/Makefile                     | 45 ++++++++++++++++++++++++++-----
 scripts/Makefile.build            |  1 +
 scripts/generate_rust_analyzer.py | 10 +++++--
 4 files changed, 49 insertions(+), 8 deletions(-)
Makefile +1 -0
index 3a265e7e3347..33135f39bbee 100644
@@ -1956,6 +1956,7 @@ rustfmt:
 			-path $(srctree)/rust/proc-macro2 \
 			-o -path $(srctree)/rust/quote \
 			-o -path $(srctree)/rust/syn \
+			-o -path $(srctree)/rust/zerocopy \
 		\) -prune -o \
 		-type f -a -name '*.rs' -a ! -name '*generated*' -print \
 		| xargs $(RUSTFMT) $(rustfmt_flags)
rust/Makefile +39 -6

114 lines not on this page · raw message

scripts/Makefile.build +1 -0
index 3498d25b15e8..ddf0461dda6a 100644
@@ -329,6 +329,7 @@ rust_common_cmd = \
 	-Zcrate-attr=no_std \
 	-Zcrate-attr='feature($(rust_allowed_features))' \
 	-Zunstable-options --extern pin_init --extern kernel \
+	--extern zerocopy \
 	--crate-type rlib -L $(objtree)/rust/ \
 	--sysroot=/dev/null \
 	--out-dir $(dir $@) --emit=dep-info=$(depfile)
scripts/generate_rust_analyzer.py +8 -2
index 2477209e1e94..80f7647f633a 100755
@@ -276,6 +276,12 @@ def generate_crates(
         [core, compiler_builtins],
     )
 
+    zerocopy = append_crate(
+        "zerocopy",
+        srctree / "rust" / "zerocopy" / "src" / "lib.rs",
+        [core, compiler_builtins],
+    )
+
     def append_crate_with_generated(
         display_name: str,
         deps: List[Dependency],
@@ -304,7 +310,7 @@ def generate_crates(
     bindings = append_crate_with_generated("bindings", [core, ffi, pin_init])
     uapi = append_crate_with_generated("uapi", [core, ffi, pin_init])
     kernel = append_crate_with_generated(
-        "kernel", [core, macros, build_error, pin_init, ffi, bindings, uapi]
+        "kernel", [core, macros, build_error, pin_init, ffi, bindings, uapi, zerocopy]
     )
 
     scripts = srctree / "scripts"
@@ -349,7 +355,7 @@ def generate_crates(
             append_crate(
                 crate_name,
                 path,
-                [core, kernel, pin_init],
+                [core, kernel, pin_init, zerocopy],
                 cfg=generated_cfg,
             )
 
Signature · 1 line
2.54.0
author maintainer
#13 lore raw

PATCH v2 13/19 rust: zerocopy-derive: import crate

In reply to Miguel Ojeda

This is a subset of the Rust zerocopy-derive crate, version v0.8.50 (released 2026-05-31), licensed under "BSD-2-Clause OR Apache-2.0 OR MIT", from:

    https://github.com/google/zerocopy/tree/v0.8.50/zerocopy-derive/src

The files are copied as-is, with no modifications whatsoever (not even adding the SPDX identifiers).

For copyright details, please see:

    https://github.com/google/zerocopy/blob/v0.8.50/README.md?plain=1
    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-BSD
    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-APACHE
    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-MIT

The next two patches modify these files as needed for use within the kernel. This patch split allows reviewers to double-check the import and to clearly see the differences introduced.

The following script may be used to verify the contents:

    for path in $(cd rust/zerocopy-derive/ && find . -type f); do
        curl --silent --show-error --location \
            https://github.com/google/zerocopy/raw/v0.8.50/zerocopy-derive/src/$path \
            | diff --unified rust/zerocopy-derive/$path - && echo $path: OK
    done
Cc Joshua Liebow-Feeser <[email protected]>
Cc Jack Wrenn <[email protected]>
---
 rust/zerocopy-derive/derive/from_bytes.rs     | 190 ++++
 rust/zerocopy-derive/derive/into_bytes.rs     | 162 ++++
 rust/zerocopy-derive/derive/known_layout.rs   | 348 +++++++
 rust/zerocopy-derive/derive/mod.rs            | 130 +++
 rust/zerocopy-derive/derive/try_from_bytes.rs | 763 ++++++++++++++++
 rust/zerocopy-derive/derive/unaligned.rs      |  78 ++
 rust/zerocopy-derive/lib.rs                   | 144 +++
 rust/zerocopy-derive/repr.rs                  | 849 ++++++++++++++++++
 rust/zerocopy-derive/util.rs                  | 843 +++++++++++++++++
 9 files changed, 3507 insertions(+)
 create mode 100644 rust/zerocopy-derive/derive/from_bytes.rs
 create mode 100644 rust/zerocopy-derive/derive/into_bytes.rs
 create mode 100644 rust/zerocopy-derive/derive/known_layout.rs
 create mode 100644 rust/zerocopy-derive/derive/mod.rs
 create mode 100644 rust/zerocopy-derive/derive/try_from_bytes.rs
 create mode 100644 rust/zerocopy-derive/derive/unaligned.rs
 create mode 100644 rust/zerocopy-derive/lib.rs
 create mode 100644 rust/zerocopy-derive/repr.rs
 create mode 100644 rust/zerocopy-derive/util.rs
rust/zerocopy-derive/derive/from_bytes.rs new file +190 -0
new file mode 100644
index 000000000000..ad8b6233fe54
@@ -0,0 +1,190 @@
+use proc_macro2::{Span, TokenStream};
+use syn::{
+    parse_quote, Data, DataEnum, DataStruct, DataUnion, Error, Expr, ExprLit, ExprUnary, Lit, UnOp,
+    WherePredicate,
+};
+
+use crate::{
+    derive::try_from_bytes::derive_try_from_bytes,
+    repr::{CompoundRepr, EnumRepr, Repr, Spanned},
+    util::{enum_size_from_repr, Ctx, FieldBounds, ImplBlockBuilder, Trait, TraitBound},
+};
+/// Returns `Ok(index)` if variant `index` of the enum has a discriminant of
+/// zero. If `Err(bool)` is returned, the boolean is true if the enum has
+/// unknown discriminants (e.g. discriminants set to const expressions which we
+/// can't evaluate in a proc macro). If the enum has unknown discriminants, then
+/// it might have a zero variant that we just can't detect.
+pub(crate) fn find_zero_variant(enm: &DataEnum) -> Result<usize, bool> {
+    // Discriminants can be anywhere in the range [i128::MIN, u128::MAX] because
+    // the discriminant type may be signed or unsigned. Since we only care about
+    // tracking the discriminant when it's less than or equal to zero, we can
+    // avoid u128 -> i128 conversions and bounds checking by making the "next
+    // discriminant" value implicitly negative.
+    // Technically 64 bits is enough, but 128 is better for future compatibility
+    // with https://github.com/rust-lang/rust/issues/56071
+    let mut next_negative_discriminant = Some(0);
+
+    // Sometimes we encounter explicit discriminants that we can't know the
+    // value of (e.g. a constant expression that requires evaluation). These
+    // could evaluate to zero or a negative number, but we can't assume that
+    // they do (no false positives allowed!). So we treat them like strictly-
+    // positive values that can't result in any zero variants, and track whether
+    // we've encountered any unknown discriminants.
+    let mut has_unknown_discriminants = false;
+
+    for (i, v) in enm.variants.iter().enumerate() {
+        match v.discriminant.as_ref() {
+            // Implicit discriminant
+            None => {
+                match next_negative_discriminant.as_mut() {
+                    Some(0) => return Ok(i),
+                    // n is nonzero so subtraction is always safe
+                    Some(n) => *n -= 1,
+                    None => (),
+                }
+            }
+            // Explicit positive discriminant
+            Some((_, Expr::Lit(ExprLit { lit: Lit::Int(int), .. }))) => {
+                match int.base10_parse::<u128>().ok() {
+                    Some(0) => return Ok(i),
+                    Some(_) => next_negative_discriminant = None,
+                    None => {
+                        // Numbers should never fail to parse, but just in case:
+                        has_unknown_discriminants = true;
+                        next_negative_discriminant = None;
+                    }
+                }
+            }
+            // Explicit negative discriminant
+            Some((_, Expr::Unary(ExprUnary { op: UnOp::Neg(_), expr, .. }))) => match &**expr {
+                Expr::Lit(ExprLit { lit: Lit::Int(int), .. }) => {
+                    match int.base10_parse::<u128>().ok() {
+                        Some(0) => return Ok(i),
+                        // x is nonzero so subtraction is always safe
+                        Some(x) => next_negative_discriminant = Some(x - 1),
+                        None => {
+                            // Numbers should never fail to parse, but just in
+                            // case:
+                            has_unknown_discriminants = true;
+                            next_negative_discriminant = None;
+                        }
+                    }
+                }
+                // Unknown negative discriminant (e.g. const repr)
+                _ => {
+                    has_unknown_discriminants = true;
+                    next_negative_discriminant = None;
+                }
+            },
+            // Unknown discriminant (e.g. const expr)
+            _ => {
+                has_unknown_discriminants = true;
+                next_negative_discriminant = None;
+            }
+        }
+    }
+
+    Err(has_unknown_discriminants)
+}
+pub(crate) fn derive_from_zeros(ctx: &Ctx, top_level: Trait) -> Result<TokenStream, Error> {
+    let try_from_bytes = derive_try_from_bytes(ctx, top_level)?;
+    let from_zeros = match &ctx.ast.data {
+        Data::Struct(strct) => derive_from_zeros_struct(ctx, strct),
+        Data::Enum(enm) => derive_from_zeros_enum(ctx, enm)?,
+        Data::Union(unn) => derive_from_zeros_union(ctx, unn),
+    };
+    Ok(IntoIterator::into_iter([try_from_bytes, from_zeros]).collect())
+}
+pub(crate) fn derive_from_bytes(ctx: &Ctx, top_level: Trait) -> Result<TokenStream, Error> {
+    let from_zeros = derive_from_zeros(ctx, top_level)?;
+    let from_bytes = match &ctx.ast.data {
+        Data::Struct(strct) => derive_from_bytes_struct(ctx, strct),
+        Data::Enum(enm) => derive_from_bytes_enum(ctx, enm)?,
+        Data::Union(unn) => derive_from_bytes_union(ctx, unn),
+    };
+
+    Ok(IntoIterator::into_iter([from_zeros, from_bytes]).collect())
+}
+fn derive_from_zeros_struct(ctx: &Ctx, strct: &DataStruct) -> TokenStream {
+    ImplBlockBuilder::new(ctx, strct, Trait::FromZeros, FieldBounds::ALL_SELF).build()
+}
+fn derive_from_zeros_enum(ctx: &Ctx, enm: &DataEnum) -> Result<TokenStream, Error> {
+    let repr = EnumRepr::from_attrs(&ctx.ast.attrs)?;
+
+    // We don't actually care what the repr is; we just care that it's one of
+    // the allowed ones.
+    match repr {
+        Repr::Compound(Spanned { t: CompoundRepr::C | CompoundRepr::Primitive(_), span: _ }, _) => {
+        }
+        Repr::Transparent(_) | Repr::Compound(Spanned { t: CompoundRepr::Rust, span: _ }, _) => {
+            return ctx.error_or_skip(
+                Error::new(
+                    Span::call_site(),
+                    "must have #[repr(C)] or #[repr(Int)] attribute in order to guarantee this type's memory layout",
+                ),
+            );
+        }
+    }
+
+    let zero_variant = match find_zero_variant(enm) {
+        Ok(index) => enm.variants.iter().nth(index).unwrap(),
+        // Has unknown variants
+        Err(true) => {
+            return ctx.error_or_skip(Error::new_spanned(
+                &ctx.ast,
+                "FromZeros only supported on enums with a variant that has a discriminant of `0`\n\
+                help: This enum has discriminants which are not literal integers. One of those may \
+                define or imply which variant has a discriminant of zero. Use a literal integer to \
+                define or imply the variant with a discriminant of zero.",
+            ));
+        }
+        // Does not have unknown variants
+        Err(false) => {
+            return ctx.error_or_skip(Error::new_spanned(
+                &ctx.ast,
+                "FromZeros only supported on enums with a variant that has a discriminant of `0`",
+            ));
+        }
+    };
+
+    let zerocopy_crate = &ctx.zerocopy_crate;
+    let explicit_bounds = zero_variant
+        .fields
+        .iter()
+        .map(|field| {
+            let ty = &field.ty;
+            parse_quote! { #ty: #zerocopy_crate::FromZeros }
+        })
+        .collect::<Vec<WherePredicate>>();
+
+    Ok(ImplBlockBuilder::new(ctx, enm, Trait::FromZeros, FieldBounds::Explicit(explicit_bounds))
+        .build())
+}
+fn derive_from_zeros_union(ctx: &Ctx, unn: &DataUnion) -> TokenStream {
+    let field_type_trait_bounds = FieldBounds::All(&[TraitBound::Slf]);
+    ImplBlockBuilder::new(ctx, unn, Trait::FromZeros, field_type_trait_bounds).build()
+}
+fn derive_from_bytes_struct(ctx: &Ctx, strct: &DataStruct) -> TokenStream {
+    ImplBlockBuilder::new(ctx, strct, Trait::FromBytes, FieldBounds::ALL_SELF).build()
+}
+fn derive_from_bytes_enum(ctx: &Ctx, enm: &DataEnum) -> Result<TokenStream, Error> {
+    let repr = EnumRepr::from_attrs(&ctx.ast.attrs)?;
+
+    let variants_required = 1usize << enum_size_from_repr(&repr)?;
+    if enm.variants.len() != variants_required {
+        return ctx.error_or_skip(Error::new_spanned(
+            &ctx.ast,
+            format!(
+                "FromBytes only supported on {} enum with {} variants",
+                repr.repr_type_name(),
+                variants_required
+            ),
+        ));
+    }
+
+    Ok(ImplBlockBuilder::new(ctx, enm, Trait::FromBytes, FieldBounds::ALL_SELF).build())
+}
+fn derive_from_bytes_union(ctx: &Ctx, unn: &DataUnion) -> TokenStream {
+    let field_type_trait_bounds = FieldBounds::All(&[TraitBound::Slf]);
+    ImplBlockBuilder::new(ctx, unn, Trait::FromBytes, field_type_trait_bounds).build()
+}
rust/zerocopy-derive/derive/into_bytes.rs new file +162 -0

162 lines not on this page · raw message

rust/zerocopy-derive/derive/known_layout.rs new file +348 -0

348 lines not on this page · raw message

rust/zerocopy-derive/derive/mod.rs new file +130 -0

130 lines not on this page · raw message

rust/zerocopy-derive/derive/try_from_bytes.rs new file +763 -0

763 lines not on this page · raw message

rust/zerocopy-derive/derive/unaligned.rs new file +78 -0

78 lines not on this page · raw message

rust/zerocopy-derive/lib.rs new file +144 -0

144 lines not on this page · raw message

rust/zerocopy-derive/repr.rs new file +849 -0

849 lines not on this page · raw message

rust/zerocopy-derive/util.rs new file +843 -0

336 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.54.0

Part of the diff is not shown here. View the raw message.

author maintainer
#14 lore raw

PATCH v2 14/19 rust: zerocopy-derive: add SPDX License Identifiers

In reply to Miguel Ojeda

Originally, when the Rust upstream alloc standard library crate was vendored, the SPDX License Identifiers were added to every file so that the license on those was clear. The same happened with the vendoring of proc_macro2, quote and syn. Please see:

commit 057b8d257107 ("rust: adapt alloc crate to the kernel") commit 69942c0a8965 ("rust: syn: add SPDX License Identifiers") commit ddfa1b279d08 ("rust: quote: add SPDX License Identifiers") commit a9acfceb9614 ("rust: proc-macro2: add SPDX License Identifiers")

Thus do the same for the zerocopy-derive crate.

This makes scripts/spdxcheck.py pass: use parentheses like commit 06e9bfc1e57d ("ionic: make spdxcheck.py happy") did since we have two OR operators in the expression (three licenses).

Finally, as requested, I filed an issue [1] with upstream about it.

---
 rust/zerocopy-derive/derive/from_bytes.rs     | 2 ++
 rust/zerocopy-derive/derive/into_bytes.rs     | 2 ++
 rust/zerocopy-derive/derive/known_layout.rs   | 2 ++
 rust/zerocopy-derive/derive/mod.rs            | 2 ++
 rust/zerocopy-derive/derive/try_from_bytes.rs | 2 ++
 rust/zerocopy-derive/derive/unaligned.rs      | 2 ++
 rust/zerocopy-derive/lib.rs                   | 2 ++
 rust/zerocopy-derive/repr.rs                  | 2 ++
 rust/zerocopy-derive/util.rs                  | 2 ++
 9 files changed, 18 insertions(+)
rust/zerocopy-derive/derive/from_bytes.rs +2 -0
index ad8b6233fe54..d693a63b7645 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 use proc_macro2::{Span, TokenStream};
 use syn::{
     parse_quote, Data, DataEnum, DataStruct, DataUnion, Error, Expr, ExprLit, ExprUnary, Lit, UnOp,
rust/zerocopy-derive/derive/into_bytes.rs +2 -0
index 8c1e1009dd91..ad52a6b45d28 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 use proc_macro2::{Span, TokenStream};
 use quote::quote;
 use syn::{Data, DataEnum, DataStruct, DataUnion, Error, Type};
rust/zerocopy-derive/derive/known_layout.rs +2 -0
index b91b4de0098c..fddffd167c82 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 use proc_macro2::TokenStream;
 use quote::quote;
 use syn::{parse_quote, Data, Error, Type};
rust/zerocopy-derive/derive/mod.rs +2 -0
index a3d066ed2b4d..665ba7da55a8 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 pub mod from_bytes;
 pub mod into_bytes;
 pub mod known_layout;
rust/zerocopy-derive/derive/try_from_bytes.rs +2 -0
index 4e36ab40bcf8..ce9c926d5b8e 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 use proc_macro2::TokenStream;
 use quote::quote;
 use syn::{
rust/zerocopy-derive/derive/unaligned.rs +2 -0
index 819d84984a03..d6dea0a11f1e 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 use proc_macro2::{Span, TokenStream};
 use syn::{Data, DataEnum, DataStruct, DataUnion, Error};
 
rust/zerocopy-derive/lib.rs +2 -0
index a1d10a2ada27..c517ea7db1eb 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2019 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy-derive/repr.rs +2 -0
index 57014b38b2da..74fd376d9fda 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2019 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
rust/zerocopy-derive/util.rs +2 -0
index 4ec28bf95758..5ba5228e2a44 100644
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: (BSD-2-Clause OR Apache-2.0) OR MIT
+
 // Copyright 2019 The Fuchsia Authors
 //
 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
Signature · 1 line
2.54.0
author maintainer
#15 lore raw

PATCH v2 15/19 rust: zerocopy-derive: avoid generating non-ASCII identifiers

In reply to Miguel Ojeda

Linux is built with -Dnon_ascii_idents. However, zerocopy-derive uses a non-ASCII character (ẕ) internally, which in turn triggers the lint when attempting to use derives like FromBytes:

    error: identifier contains non-ASCII characters
       --> rust/kernel/lib.rs:153:9
        |
    153 |         a: u32,
        |         ^
        |
        = note: requested on the command line with `-D non-ascii-idents`

This was already noticed by another project using #![deny(non_ascii_idents)] [1]. zerocopy added an #[allow(non_ascii_idents)] [2], but it does not work since, at the moment, the non_ascii_idents lint is a crate_level_only one, and thus allows only work at the crate root level.

Due to this, an issue about relaxing this restriction was created in upstream Rust [3] some months ago.

Thus work around it here by using another prefix. The likelihood of a collision is very small for us, since we control the callers, and this will hopefully be fixed soon at either the zerocopy or the Rust level.

I filed an issue [4] about it with upstream zerocopy as requested and we discussed this with upstream Rust and zerocopy: the Rust issue got nominated and a PR [5] to relax the restriction was submitted by Joshua. Upstream zerocopy prefers that approach, so if Rust merges it, then it means we will be able to remove the workaround when we bump the MSRV, thus likely late 2027, since we follow Debian Stable.

---
 rust/zerocopy-derive/derive/try_from_bytes.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
rust/zerocopy-derive/derive/try_from_bytes.rs +2 -2
index ce9c926d5b8e..a3e4a75631a5 100644
@@ -457,7 +457,7 @@ fn derive_has_field_struct_union(ctx: &Ctx, data: &dyn DataExt) -> TokenStream {
     }
 
     let field_tokens = fields.iter().map(|(vis, ident, _)| {
-        let ident = ident!(("ẕ{}", ident), ident.span());
+        let ident = ident!(("__z{}", ident), ident.span());
         quote!(
             #vis enum #ident {}
         )
@@ -487,7 +487,7 @@ fn derive_has_field_struct_union(ctx: &Ctx, data: &dyn DataExt) -> TokenStream {
         })
         .build();
     let has_fields = fields.iter().map(move |(_, ident, ty)| {
-        let field_token = ident!(("ẕ{}", ident), ident.span());
+        let field_token = ident!(("__z{}", ident), ident.span());
         let field: Box<Type> = parse_quote!(#field_token);
         let field_id: Box<Expr> = parse_quote!({ #zerocopy_crate::ident_id!(#ident) });
         let has_field_trait = Trait::HasField {
Signature · 1 line
2.54.0
author maintainer
#16 lore raw

PATCH v2 16/19 rust: zerocopy-derive: add `README.md`

In reply to Miguel Ojeda

Originally, when the Rust upstream alloc standard library crate was vendored in commit 057b8d257107 ("rust: adapt alloc crate to the kernel"), a README.md file was added to explain the provenance and licensing of the source files.

Thus do the same for the zerocopy-derive crate.

Cc Joshua Liebow-Feeser <[email protected]>
Cc Jack Wrenn <[email protected]>
---
 rust/zerocopy-derive/README.md | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 rust/zerocopy-derive/README.md
rust/zerocopy-derive/README.md new file +14 -0
new file mode 100644
index 000000000000..110f4a401778
@@ -0,0 +1,14 @@
+# `zerocopy-derive`
+
+These source files come from the Rust `zerocopy-derive` crate, version v0.8.50
+(released 2026-05-31), hosted in the <https://github.com/google/zerocopy>
+repository, licensed under "BSD-2-Clause OR Apache-2.0 OR MIT" and only
+modified to add the SPDX license identifiers and to remove the generation of
+non-ASCII identifiers.
+
+For copyright details, please see:
+
+    https://github.com/google/zerocopy/blob/v0.8.50/README.md?plain=1
+    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-BSD
+    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-APACHE
+    https://github.com/google/zerocopy/blob/v0.8.50/LICENSE-MIT
Signature · 1 line
2.54.0
author maintainer
#17 lore raw

PATCH v2 17/19 rust: zerocopy-derive: enable support in kbuild

In reply to Miguel Ojeda

With all the new files in place and ready from the new crate, enable the support for it in the build system.

In addition, skip formatting for this vendored crate.

---
 Makefile                          |  1 +
 rust/Makefile                     | 41 +++++++++++++++++++++++++------
 scripts/Makefile.build            |  2 +-
 scripts/generate_rust_analyzer.py | 10 ++++++--
 4 files changed, 43 insertions(+), 11 deletions(-)
Makefile +1 -0
index 33135f39bbee..c71c43bc3658 100644
@@ -1957,6 +1957,7 @@ rustfmt:
 			-o -path $(srctree)/rust/quote \
 			-o -path $(srctree)/rust/syn \
 			-o -path $(srctree)/rust/zerocopy \
+			-o -path $(srctree)/rust/zerocopy-derive \
 		\) -prune -o \
 		-type f -a -name '*.rs' -a ! -name '*generated*' -print \
 		| xargs $(RUSTFMT) $(rustfmt_flags)
rust/Makefile +33 -8

108 lines not on this page · raw message

scripts/Makefile.build +1 -1
index ddf0461dda6a..911745743246 100644
@@ -329,7 +329,7 @@ rust_common_cmd = \
 	-Zcrate-attr=no_std \
 	-Zcrate-attr='feature($(rust_allowed_features))' \
 	-Zunstable-options --extern pin_init --extern kernel \
-	--extern zerocopy \
+	--extern zerocopy --extern zerocopy_derive \
 	--crate-type rlib -L $(objtree)/rust/ \
 	--sysroot=/dev/null \
 	--out-dir $(dir $@) --emit=dep-info=$(depfile)
scripts/generate_rust_analyzer.py +8 -2
index 80f7647f633a..dc1219736f77 100755
@@ -252,6 +252,12 @@ def generate_crates(
         [std, proc_macro, proc_macro2, quote, syn],
     )
 
+    zerocopy_derive = append_proc_macro_crate(
+        "zerocopy_derive",
+        srctree / "rust" / "zerocopy-derive" / "lib.rs",
+        [std, proc_macro, proc_macro2, quote, syn],
+    )
+
     build_error = append_crate(
         "build_error",
         srctree / "rust" / "build_error.rs",
@@ -310,7 +316,7 @@ def generate_crates(
     bindings = append_crate_with_generated("bindings", [core, ffi, pin_init])
     uapi = append_crate_with_generated("uapi", [core, ffi, pin_init])
     kernel = append_crate_with_generated(
-        "kernel", [core, macros, build_error, pin_init, ffi, bindings, uapi, zerocopy]
+        "kernel", [core, macros, build_error, pin_init, ffi, bindings, uapi, zerocopy, zerocopy_derive]
     )
 
     scripts = srctree / "scripts"
@@ -355,7 +361,7 @@ def generate_crates(
             append_crate(
                 crate_name,
                 path,
-                [core, kernel, pin_init, zerocopy],
+                [core, kernel, pin_init, zerocopy, zerocopy_derive],
                 cfg=generated_cfg,
             )
 
Signature · 1 line
2.54.0
author maintainer
#18 lore raw

PATCH v2 18/19 rust: prelude: add `zerocopy{,_derive}::FromBytes`

In reply to Miguel Ojeda

In order to easily use FromBytes, add it to the prelude.

This adds both the trait (zerocopy::FromBytes) as well as the derive macro (zerocopy_derive::FromBytes).

We will be adding more as we need them.

---
 rust/kernel/prelude.rs | 6 ++++++
 1 file changed, 6 insertions(+)
rust/kernel/prelude.rs +6 -0
index bcd4e7f90bc7..ca260cc3937a 100644
@@ -60,6 +60,12 @@
     Zeroable, //
 };
 
+#[doc(no_inline)]
+pub use zerocopy::FromBytes;
+
+#[doc(no_inline)]
+pub use zerocopy_derive::FromBytes;
+
 #[doc(no_inline)]
 pub use super::{
     alloc::{
Signature · 1 line
2.54.0
author maintainer
#19 lore raw

PATCH v2 19/19 gpu: nova-core: firmware: parse `FalconUCodeDescV2` via `zerocopy`

In reply to Miguel Ojeda

Now that we have zerocopy support, we can avoid some unsafe code.

For instance, for FalconUCodeDescV2, we can replace the unsafe impl FromBytes by safely deriving zerocopy's FromBytes and then calling read_from_prefix.

---
 drivers/gpu/nova-core/firmware.rs | 5 +----
 drivers/gpu/nova-core/vbios.rs    | 6 ++++--
 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/nova-core/firmware.rs +1 -4
index 6c2ab69cb605..ad37994ac15a 100644
@@ -48,7 +48,7 @@ fn request_firmware(
 
 /// Structure used to describe some firmwares, notably FWSEC-FRTS.
 #[repr(C)]
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, FromBytes)]
 pub(crate) struct FalconUCodeDescV2 {
     /// Header defined by 'NV_BIT_FALCON_UCODE_DESC_HEADER_VDESC*' in OpenRM.
     hdr: u32,
@@ -84,9 +84,6 @@ pub(crate) struct FalconUCodeDescV2 {
     pub(crate) alt_dmem_load_size: u32,
 }
 
-// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
-unsafe impl FromBytes for FalconUCodeDescV2 {}
-
 /// Structure used to describe some firmwares, notably FWSEC-FRTS.
 #[repr(C)]
 #[derive(Debug, Clone)]
drivers/gpu/nova-core/vbios.rs +4 -2
index ebda28e596c5..8b7d17a24660 100644
@@ -16,6 +16,8 @@
     transmute::FromBytes,
 };
 
+use zerocopy::FromBytes as _;
+
 use crate::{
     driver::Bar0,
     firmware::{
@@ -1011,8 +1013,8 @@ pub(crate) fn header(&self) -> Result<FalconUCodeDesc> {
         let data = self.base.data.get(falcon_ucode_offset..).ok_or(EINVAL)?;
         match ver {
             2 => {
-                let v2 = FalconUCodeDescV2::from_bytes_copy_prefix(data)
-                    .ok_or(EINVAL)?
+                let v2 = FalconUCodeDescV2::read_from_prefix(data)
+                    .map_err(|_| EINVAL)?
                     .0;
                 Ok(FalconUCodeDesc::V2(v2))
             }
Signature · 1 line
2.54.0
reviewer
#20 lore raw

Re: [PATCH v2 19/19] gpu: nova-core: firmware: parse `FalconUCodeDescV2` via `zerocopy`

Quoted 42 lines · Miguel Ojeda

Now that we have zerocopy support, we can avoid some unsafe code.

For instance, for FalconUCodeDescV2, we can replace the unsafe impl FromBytes by safely deriving zerocopy's FromBytes and then calling read_from_prefix.

---
 drivers/gpu/nova-core/firmware.rs | 5 +----
 drivers/gpu/nova-core/vbios.rs    | 6 ++++--
 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/nova-core/firmware.rs +1 -4
index 6c2ab69cb605..ad37994ac15a 100644
@@ -48,7 +48,7 @@ fn request_firmware(
 
 /// Structure used to describe some firmwares, notably FWSEC-FRTS.
 #[repr(C)]
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, FromBytes)]
 pub(crate) struct FalconUCodeDescV2 {
     /// Header defined by 'NV_BIT_FALCON_UCODE_DESC_HEADER_VDESC*' in OpenRM.
     hdr: u32,
@@ -84,9 +84,6 @@ pub(crate) struct FalconUCodeDescV2 {
     pub(crate) alt_dmem_load_size: u32,
 }
 
-// SAFETY: all bit patterns are valid for this type, and it doesn't use interior mutability.
-unsafe impl FromBytes for FalconUCodeDescV2 {}
-
 /// Structure used to describe some firmwares, notably FWSEC-FRTS.
 #[repr(C)]
 #[derive(Debug, Clone)]
drivers/gpu/nova-core/vbios.rs +0 -0
index ebda28e596c5..8b7d17a24660 100644

drivers/gpu/nova-core/vbios.rs line 19

Quoted 4 lines
drivers/gpu/nova-core/vbios.rs +1 -0
@@ -16,6 +16,8 @@
     transmute::FromBytes,
 };
 
+use zerocopy::FromBytes as _;

Is this still needed given the prelude additional?

Best,
Gary

Quoted 15 lines
drivers/gpu/nova-core/vbios.rs +3 -2
+
 use crate::{
     driver::Bar0,
     firmware::{
@@ -1011,8 +1013,8 @@ pub(crate) fn header(&self) -> Result<FalconUCodeDesc> {
         let data = self.base.data.get(falcon_ucode_offset..).ok_or(EINVAL)?;
         match ver {
             2 => {
-                let v2 = FalconUCodeDescV2::from_bytes_copy_prefix(data)
-                    .ok_or(EINVAL)?
+                let v2 = FalconUCodeDescV2::read_from_prefix(data)
+                    .map_err(|_| EINVAL)?
                     .0;
                 Ok(FalconUCodeDesc::V2(v2))
             }
maintainer
#21 lore raw

Re: [PATCH v2 19/19] gpu: nova-core: firmware: parse `FalconUCodeDescV2` via `zerocopy`

Quoted 4 lines · Gary Guo
Quoted 1 line · Miguel Ojeda

+use zerocopy::FromBytes as _;

Is this still needed given the prelude additional?

There are still lots of other places in this file where FromBytes from the transmute module is used, thus the file still has an explicit transmute::FromBytes import.

#22 lore raw

Re: [PATCH v2 19/19] gpu: nova-core: firmware: parse `FalconUCodeDescV2` via `zerocopy`

Quoted 4 lines · Danilo Krummrich

There are still lots of other places in this file where FromBytes from the transmute module is used, thus the file still has an explicit transmute::FromBytes import.

Exactly, it gets shadowed and thus the methods (well, associated functions) are not available in that case.

For files that do not have this, then we don't need it, indeed.

That why I mentioned in the Zulip discussion that this "incentivizes" developers to remove their old transmute::s so that they can remove the ugly line ;)

Cheers,
Miguel

Applied
#23 lore raw
In reply to Miguel Ojeda
Quoted 39 lines · Miguel Ojeda

This patch series introduces support for zerocopy:

Fast, safe, compile error. Pick two.

Zerocopy makes zero-cost memory manipulation effortless. We write unsafe so you don't have to.

It essentially provides derivable traits (e.g. FromBytes) and macros (e.g. transmute!) for safely converting between byte sequences and other types. Having such support allows us to remove some unsafe code.

It is among the most downloaded Rust crates (top #50 recent, top #100 all-time downloads; according to crates.io), and it is also used by the Rust compiler itself.

The series starts with a few preparation commits, then the zerocopy and zerocopy-derive crates are added. Finally, an example patch using it is on top, removing one unsafe impl.

I had to adapt the crates slightly (just +2/-3 lines), but both patches could potentially be provided upstream eventually. Please see the commits for details.

In total, it is about ~39k lines added, ~32k without counting benches/ which are just for documentation purposes.

See the cover letter for syn for some more details about depending on third-party crates in commit 54e3eae85562 ("Merge patch series "syn support"").

The codegen of an isolated example function similar to the patch on top is essentially identical. It also turns out that (for that particular case) zerocopy's version, even under debug-assertions enabled, has no remaining panics, unlike a few in the current code (because the compiler can prove the remaining ub_checks statically).

So their "fast, safe" does indeed check out -- at least in that case.

Quoted 7 lines

P.S. This version of zerocopy has already the unstable Ptr{,Inner} types -- to play with them, please use:

make ... KRUSTFLAGS=--cfg=zerocopy_unstable_ptr

---
I will apply v2 for tomorrow's linux-next.

Applied to rust-next (yesterday) -- thanks everyone!

Cheers,
Miguel

maintainer
#24 lore raw
In reply to Miguel Ojeda
Quoted 6 lines · Miguel Ojeda

This patch series introduces support for zerocopy:

Fast, safe, compile error. Pick two.

Zerocopy makes zero-cost memory manipulation effortless. We write unsafe so you don't have to.

I tried applying this and using it with Binder. I ran into one challenge, which is this uapi struct:

struct binder_transaction_data {
	/* The first two are only used for bcTRANSACTION and brTRANSACTION,
	 * identifying the target and contents of the transaction.
	 */
	union {
		/* target descriptor of command transaction */
		__u32	handle;
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;
	binder_uintptr_t	cookie;	/* target object cookie */
	...
}

The problem is that when the union contains a handle, there are 4 bytes of padding in the union. Currently Rust Binder handles this by wrapping the uapi struct in MaybeUninit and using MaybeUninit::zeroed() to construct it, ensuring that even if padding is present, it is zeroed.

However, this trick relies on unsafely implementing AsBytes for BinderTransactionData with the safety comment being that the MaybeUninit actually always contains initialized data.

To translate this to zerocopy, I'd have to do this:

unsafe impl zerocopy::IntoBytes for $newname {
    fn only_derive_is_allowed_to_implement_this_trait() {}
}

One fix could be to update the uapi header by explicitly adding the padding, but that's kind of awkward for a union like this, since I'd have to do it like this with an extra struct:

	union {
		/* target descriptor of command transaction */
		struct {
			__u32	handle;
			__u32	_pad;
		};
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;

It's not clear to me if changing the uapi headers like this is even allowed to begin with. It's a somewhat non-trivial change.

Any better ideas?

Alice

reviewer
#25 lore raw
Quoted 54 lines · Alice Ryhl
Quoted 6 lines · Miguel Ojeda

This patch series introduces support for zerocopy:

Fast, safe, compile error. Pick two.

Zerocopy makes zero-cost memory manipulation effortless. We write unsafe so you don't have to.

I tried applying this and using it with Binder. I ran into one challenge, which is this uapi struct:

struct binder_transaction_data {
	/* The first two are only used for bcTRANSACTION and brTRANSACTION,
	 * identifying the target and contents of the transaction.
	 */
	union {
		/* target descriptor of command transaction */
		__u32	handle;
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;
	binder_uintptr_t	cookie;	/* target object cookie */
	...
}

The problem is that when the union contains a handle, there are 4 bytes of padding in the union. Currently Rust Binder handles this by wrapping the uapi struct in MaybeUninit and using MaybeUninit::zeroed() to construct it, ensuring that even if padding is present, it is zeroed.

However, this trick relies on unsafely implementing AsBytes for BinderTransactionData with the safety comment being that the MaybeUninit actually always contains initialized data.

To translate this to zerocopy, I'd have to do this:

unsafe impl zerocopy::IntoBytes for $newname {
    fn only_derive_is_allowed_to_implement_this_trait() {}
}

One fix could be to update the uapi header by explicitly adding the padding, but that's kind of awkward for a union like this, since I'd have to do it like this with an extra struct:

	union {
		/* target descriptor of command transaction */
		struct {
			__u32	handle;
			__u32	_pad;
		};
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;
Quoted 6 lines

It's not clear to me if changing the uapi headers like this is even allowed to begin with. It's a somewhat non-trivial change.

Any better ideas?

Alice

We can patch out only_derive_is_allowed_to_implement_this_trait? I don't like this "extra safeguarding" in the first place. I think the "unsafe" there is sufficient.

Best,
Gary

maintainer
#26 lore raw
In reply to Alice Ryhl
Quoted 54 lines · Alice Ryhl
Quoted 6 lines · Miguel Ojeda

This patch series introduces support for zerocopy:

Fast, safe, compile error. Pick two.

Zerocopy makes zero-cost memory manipulation effortless. We write unsafe so you don't have to.

I tried applying this and using it with Binder. I ran into one challenge, which is this uapi struct:

struct binder_transaction_data {
	/* The first two are only used for bcTRANSACTION and brTRANSACTION,
	 * identifying the target and contents of the transaction.
	 */
	union {
		/* target descriptor of command transaction */
		__u32	handle;
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;
	binder_uintptr_t	cookie;	/* target object cookie */
	...
}

The problem is that when the union contains a handle, there are 4 bytes of padding in the union. Currently Rust Binder handles this by wrapping the uapi struct in MaybeUninit and using MaybeUninit::zeroed() to construct it, ensuring that even if padding is present, it is zeroed.

However, this trick relies on unsafely implementing AsBytes for BinderTransactionData with the safety comment being that the MaybeUninit actually always contains initialized data.

To translate this to zerocopy, I'd have to do this:

unsafe impl zerocopy::IntoBytes for $newname {
    fn only_derive_is_allowed_to_implement_this_trait() {}
}

One fix could be to update the uapi header by explicitly adding the padding, but that's kind of awkward for a union like this, since I'd have to do it like this with an extra struct:

	union {
		/* target descriptor of command transaction */
		struct {
			__u32	handle;
			__u32	_pad;
		};
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;
Quoted 2 lines

It's not clear to me if changing the uapi headers like this is even allowed to begin with. It's a somewhat non-trivial change.

Hey Greg,
Do you have any input on this from the C side?

For context, zerocopy is a tool that helps convert raw bytes into structs and vice-versa. When I tried using zerocopy with Rust Binder to see if it helps there, I found that zerocopy is flagging that Rust Binder copied a uapi struct containing padding into userspace, which is of course dangerous since padding on the kernel stack may contain data we don't want to leak to userspace.

Now, there's not actually a problem today because I'm using another strategy to ensure that the padding is zeroed when copying the output of the ioctl to userspace, but ideally I'd like to switch over to using zerocopy.

How is this kind of thing usually handled on the C side? As far as I can tell, C Binder handles it by just being extra careful like this:

	fp->binder = 0;
	fp->handle = rdata.desc;

where fp->binder and fp->handle are fields of the same union, with fp->binder being 8 bytes and fp->handle being 4 bytes. The first assignment ensures that the extra 4 bytes in the union are zeroed.

Alice

#27 lore raw
Quoted 3 lines · Alice Ryhl
Quoted 3 lines

It's not clear to me if changing the uapi headers like this is even allowed to begin with. It's a somewhat non-trivial change.

After our call I recalled the tool I was thinking about:

scripts/check-uapi.sh
Documentation/dev-tools/checkuapi.rst

It turns out it uses abidiff (abigail).

From a quick look, it seems to complain if I add explicit padding where implicit padding was there before, i.e. as a "data member insertion", even if the types etc. are the same.

However, for this change, i.e. when inside the union, it doesn't seem to complain.

Cheers,
Miguel

#28 lore raw
Quoted 10 lines · Miguel Ojeda
Quoted 3 lines · Alice Ryhl
Quoted 3 lines

It's not clear to me if changing the uapi headers like this is even allowed to begin with. It's a somewhat non-trivial change.

After our call I recalled the tool I was thinking about:

scripts/check-uapi.sh
Documentation/dev-tools/checkuapi.rst

Quoted 8 lines

It turns out it uses abidiff (abigail).

Quoted 1 line

From a quick look, it seems to complain if I add explicit padding

where implicit padding was there before, i.e. as a "data member insertion", even if the types etc. are the same.

However, for this change, i.e. when inside the union, it doesn't seem to complain.

check-uapi is there just to determine if we actually change the user/kernel api, by adding explicit padding you didn't change the size or location of anything, so all is good.

Ideally yes, we should have explicit padding everywhere, so we know to catch this, but for older structures sometimes we didn't :(

thanks,

greg k-h

#29 lore raw
In reply to Alice Ryhl
Quoted 61 lines · Alice Ryhl
Quoted 54 lines · Alice Ryhl
Quoted 6 lines · Miguel Ojeda

This patch series introduces support for zerocopy:

Fast, safe, compile error. Pick two.

Zerocopy makes zero-cost memory manipulation effortless. We write unsafe so you don't have to.

I tried applying this and using it with Binder. I ran into one challenge, which is this uapi struct:

struct binder_transaction_data {
	/* The first two are only used for bcTRANSACTION and brTRANSACTION,
	 * identifying the target and contents of the transaction.
	 */
	union {
		/* target descriptor of command transaction */
		__u32	handle;
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;
	binder_uintptr_t	cookie;	/* target object cookie */
	...
}

The problem is that when the union contains a handle, there are 4 bytes of padding in the union. Currently Rust Binder handles this by wrapping the uapi struct in MaybeUninit and using MaybeUninit::zeroed() to construct it, ensuring that even if padding is present, it is zeroed.

However, this trick relies on unsafely implementing AsBytes for BinderTransactionData with the safety comment being that the MaybeUninit actually always contains initialized data.

To translate this to zerocopy, I'd have to do this:

unsafe impl zerocopy::IntoBytes for $newname {
    fn only_derive_is_allowed_to_implement_this_trait() {}
}

One fix could be to update the uapi header by explicitly adding the padding, but that's kind of awkward for a union like this, since I'd have to do it like this with an extra struct:

	union {
		/* target descriptor of command transaction */
		struct {
			__u32	handle;
			__u32	_pad;
		};
		/* target descriptor of return transaction */
		binder_uintptr_t ptr;
	} target;
Quoted 2 lines

It's not clear to me if changing the uapi headers like this is even allowed to begin with. It's a somewhat non-trivial change.

Hey Greg,
Do you have any input on this from the C side?

Quoted 6 lines

For context, zerocopy is a tool that helps convert raw bytes into structs and vice-versa. When I tried using zerocopy with Rust Binder to see if it helps there, I found that zerocopy is flagging that Rust Binder copied a uapi struct containing padding into userspace, which is of course dangerous since padding on the kernel stack may contain data we don't want to leak to userspace.

A UAPI structure should not have padding, and if it does, it must be zeroed out, as you say. So in C we normally manually fix this up.

Quoted 10 lines

Now, there's not actually a problem today because I'm using another strategy to ensure that the padding is zeroed when copying the output of the ioctl to userspace, but ideally I'd like to switch over to using zerocopy.

How is this kind of thing usually handled on the C side? As far as I can tell, C Binder handles it by just being extra careful like this:

	fp->binder = 0;
	fp->handle = rdata.desc;

Yes, we have to almost always manually do this. Sometimes we use memset on the structure first before copying, or rely on a foo = {}; to do it for us (but I never remember if the compiler will zero out the holes...)

Quoted 3 lines

where fp->binder and fp->handle are fields of the same union, with fp->binder being 8 bytes and fp->handle being 4 bytes. The first assignment ensures that the extra 4 bytes in the union are zeroed.

Yes, that's why we manually do this :(

thanks,

greg k-h