Skip to content

incorrect union passing on 32bit linux #14177

Closed
@metajack

Description

@metajack

Spidermonkey's jsval type is a union of size 64 bits. We represent this as struct JSVal { val: u64 } in Rust. This works great on 64bit platforms.

On 32bit platforms, the jsval values get mangled when passed to the C library functions. This seems to be an ABI issue. We've encountered this before with servo/servo#467 which was about 32bit ARM.

This gist contains sample programs and the generated IR for minimal test programs using rust-mozjs: https://gist.github.com/metajack/ddc94ef7e8e3ed838054

Note that you will need my 32bit branch of rust-mozjs: https://github.com/metajack/rust-mozjs/tree/build-32bit

You can put debugging printfs in jsapi.cpp in JS_SetReservedSlot to see the value on the C side.

The only notable thing I see in the IR is that the clang IR has byval when passing the jsval.

This seems like a Rust bug, but I'd also be interested if there is a workaround that will work on all platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions