Skip to content

FFI broken with many parameters #62350

Closed
@aosmond

Description

@aosmond

We encountered this with WebRender, where we exposed a method in Rust to the Gecko, and the last parameters supplied appeared random on the Rust side. I made a reduced test case adapted from it that you can grab at:

https://github.com/aosmond/myrustffi

It is a very simple test case where the C++ program puts all the parameters on the stack, prints the expected values of some of them, and calls the Rust method. The Rust method prints the values it received. We have enough parameters to fill up the registers used in the calling convention, and once we get to pushing things on the stack, it goes wrong. You can see from the output that they mismatch.

./build-debug.sh && ./run-debug.sh

outputs

c++ expect width=7 height=8
c++ expect slice=9 10 11 12
c++ expect outset=13.000000 13.100000 13.200000 13.300000
c++ expect repeat h=0 v=0

got rust image 6 width 7 height 8
got rust slice SideOffsets { top: 9, right: 10, bottom: 11, left: 12 }
got rust outset LayoutGeometry { top: 0.0, left: 0.0, width: 0.0, height: 0.0 }
got rust repeat h=26 v=58

Note that the earlier parameters are correct, but the last 3 (outset, repeat h and repeat v) are all incorrect.

Metadata

Metadata

Assignees

Labels

A-FFIArea: Foreign function interface (FFI)A-codegenArea: Code generationC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions