Skip to content

Unsound transmute in lib #26

@MolotovCherry

Description

@MolotovCherry

Just a small note, but the repr(Rust) memory layout does not guarantee that two similarly defined structs are laid out the exact same way in memory. Thus, transmutes between repr(Rust) types are UB.

For reference, please see this nomicon article here:
https://doc.rust-lang.org/nomicon/repr-rust.html

Rust does guarantee that two instances of A have their data laid out in exactly the same way. However Rust does not currently guarantee that an instance of A has the same field ordering or padding as an instance of B.

The struct in question requires a repr(transparent) or repr(C) to be safe. However, ThreadId does not have any of these on it, so putting it only on one will do little good.

std::mem::transmute::<std::thread::ThreadId, FakeThreadId>(thread::current().id()).0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions