Skip to content

SPARC - passing argument from C++ to Rust issue #86163

Closed
@psumbera

Description

@psumbera

This was originally reported as Firefox issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1714064

But now it seems to be rather Rust issue.

Unfortunately I wasn't able to reproduce it outside of Firefox yet:

C++ code calls wr_dp_push_stacking_context() with parameter aParams.mFilterDatas.Length() which is zero (0):

https://searchfox.org/mozilla-central/rev/79d73b4aff88dd4a0f06dd3789e1148c49b0de60/gfx/webrender_bindings/WebRenderAPI.cpp#1028

But Rust code gets instead of 0 some nonsense number (e.g. 133081200598864):

https://searchfox.org/mozilla-central/rev/79d73b4aff88dd4a0f06dd3789e1148c49b0de60/gfx/webrender_bindings/src/bindings.rs#2455

I was able to limit the wr_dp_push_stacking_context() to just:

#[no_mangle]
pub extern "C" fn wr_dp_push_stacking_context(
    bounds: LayoutRect,
    filter_count: usize,
    glyph_raster_space: RasterSpace,
    params: &WrStackingContextParams,
)  {
    debug_assert!(unsafe { !is_in_render_thread() });
    println!("XXX start {}", filter_count);
}

And the problem is still there. But when I swap bounds: LayoutRect with filter_count: usize then filter_count is passed correctly!

LayoutRect is quite complicated (to me):
https://searchfox.org/mozilla-central/rev/79d73b4aff88dd4a0f06dd3789e1148c49b0de60/gfx/wr/webrender_api/src/units.rs#86
Important might be that it uses floating numbers!

Following is disassembled wr_dp_push_stacking_context function as defined above:

wr_dp_push_stacking_context:    save      %sp, -0x160, %sp
wr_dp_push_stacking_context+4:  call      +0x8          <wr_dp_push_stacking_context+0xc>
wr_dp_push_stacking_context+8:  sethi     %hi(0x3b05800), %i0
wr_dp_push_stacking_context+0xc:or        %i0, 0x3f8, %i0
wr_dp_push_stacking_context+0x10:       add       %i0, %o7, %i0
wr_dp_push_stacking_context+0x14:       stx       %i0, [%fp + 0x767]
wr_dp_push_stacking_context+0x18:       ldx       [%fp + 0x8af], %i0
wr_dp_push_stacking_context+0x1c:       st        %f1, [%fp + 0x787]
wr_dp_push_stacking_context+0x20:       st        %f3, [%fp + 0x78b]
wr_dp_push_stacking_context+0x24:       st        %f5, [%fp + 0x78f]
wr_dp_push_stacking_context+0x28:       st        %f7, [%fp + 0x793]
wr_dp_push_stacking_context+0x2c:       ld        [%fp + 0x787], %i0
wr_dp_push_stacking_context+0x30:       sllx      %i0, 0x20, %i0
wr_dp_push_stacking_context+0x34:       ld        [%fp + 0x78b], %i1
wr_dp_push_stacking_context+0x38:       or        %i0, %i1, %i0
wr_dp_push_stacking_context+0x3c:       stx       %i0, [%fp + 0x777]
wr_dp_push_stacking_context+0x40:       ld        [%fp + 0x78f], %i0
wr_dp_push_stacking_context+0x44:       sllx      %i0, 0x20, %i0
wr_dp_push_stacking_context+0x48:       ld        [%fp + 0x793], %i1
wr_dp_push_stacking_context+0x4c:       or        %i0, %i1, %i0
wr_dp_push_stacking_context+0x50:       stx       %i0, [%fp + 0x77f]
wr_dp_push_stacking_context+0x54:       stx       %i4, [%fp + 0x797]
wr_dp_push_stacking_context+0x58:       stx       %i5, [%fp + 0x7a7]
wr_dp_push_stacking_context+0x5c:       call      -0xae63cb0    <is_in_render_thread>
wr_dp_push_stacking_context+0x60:       stx       %i5, [%fp + 0x79f]
wr_dp_push_stacking_context+0x64:       ba        +0x8          <wr_dp_push_stacking_context+0x6c>
wr_dp_push_stacking_context+0x68:       st        %o0, [%fp + 0x773]
wr_dp_push_stacking_context+0x6c:       ld        [%fp + 0x773], %i0
wr_dp_push_stacking_context+0x70:       cmp       %i0, 0x0
wr_dp_push_stacking_context+0x74:       be        +0x38         <wr_dp_push_stacking_context+0xac>
wr_dp_push_stacking_context+0x78:       nop
wr_dp_push_stacking_context+0x7c:       ba        +0x8          <wr_dp_push_stacking_context+0x84>
wr_dp_push_stacking_context+0x80:       nop
wr_dp_push_stacking_context+0x84:       ldx       [%fp + 0x767], %i0
wr_dp_push_stacking_context+0x88:       sethi     %hi(0x35c00), %i1
wr_dp_push_stacking_context+0x8c:       add       %i1, 0x3b8, %i1
wr_dp_push_stacking_context+0x90:       ldx       [%i0 + %i1], %o0
wr_dp_push_stacking_context+0x94:       sethi     %hi(0x36000), %i1
wr_dp_push_stacking_context+0x98:       add       %i1, 0x50, %i1
wr_dp_push_stacking_context+0x9c:       ldx       [%i0 + %i1], %o2
wr_dp_push_stacking_context+0xa0:       call      +0x3c7726c    <PLT:_ZN4core9panicking5panic17he6543f3ddbf0355fE>
wr_dp_push_stacking_context+0xa4:       mov       0x33, %o1
wr_dp_push_stacking_context+0xa8:       ta        %icc, 0x5
wr_dp_push_stacking_context+0xac:       ldx       [%fp + 0x767], %i0
wr_dp_push_stacking_context+0xb0:       add       %fp, 0x797, %o0
wr_dp_push_stacking_context+0xb4:       stx       %o0, [%fp + 0x7ef]
wr_dp_push_stacking_context+0xb8:       stx       %o0, [%fp + 0x7f7]
wr_dp_push_stacking_context+0xbc:       sethi     %hi(0x1400), %i1
wr_dp_push_stacking_context+0xc0:       add       %i1, 0x190, %i1
wr_dp_push_stacking_context+0xc4:       call      +0x3c81028    <PLT:_ZN4core3fmt10ArgumentV13new17ha9bc9565de3aadf7E>
wr_dp_push_stacking_context+0xc8:       ldx       [%i0 + %i1], %o1
wr_dp_push_stacking_context+0xcc:       stx       %o0, [%fp + 0x757]
wr_dp_push_stacking_context+0xd0:       ba        +0x8          <wr_dp_push_stacking_context+0xd8>
wr_dp_push_stacking_context+0xd4:       stx       %o1, [%fp + 0x75f]
wr_dp_push_stacking_context+0xd8:       ldx       [%fp + 0x767], %i0
wr_dp_push_stacking_context+0xdc:       ldx       [%fp + 0x75f], %i1
wr_dp_push_stacking_context+0xe0:       ldx       [%fp + 0x757], %i2
wr_dp_push_stacking_context+0xe4:       stx       %i2, [%fp + 0x7df]
wr_dp_push_stacking_context+0xe8:       stx       %i1, [%fp + 0x7e7]
wr_dp_push_stacking_context+0xec:       sethi     %hi(0x36000), %i1
wr_dp_push_stacking_context+0xf0:       add       %i1, 0x58, %i1
wr_dp_push_stacking_context+0xf4:       ldx       [%i0 + %i1], %o1
wr_dp_push_stacking_context+0xf8:       add       %fp, 0x7af, %o0
wr_dp_push_stacking_context+0xfc:       mov       0x2, %o2
wr_dp_push_stacking_context+0x100:      add       %fp, 0x7df, %o3
wr_dp_push_stacking_context+0x104:      call      +0xe2a0c      <core::fmt::Arguments::new_v1::h337fca81b2e584b1>
wr_dp_push_stacking_context+0x108:      mov       0x1, %o4
wr_dp_push_stacking_context+0x10c:      ba        +0x8          <wr_dp_push_stacking_context+0x114>
wr_dp_push_stacking_context+0x110:      nop
wr_dp_push_stacking_context+0x114:      call      +0x3df5ab0    <PLT:_ZN3std2io5stdio6_print17h02792fbd1097b851E>
wr_dp_push_stacking_context+0x118:      add       %fp, 0x7af, %o0
wr_dp_push_stacking_context+0x11c:      ba        +0x8          <wr_dp_push_stacking_context+0x124>
wr_dp_push_stacking_context+0x120:      nop
wr_dp_push_stacking_context+0x124:      ret
wr_dp_push_stacking_context+0x128:      restore

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-SPARCTarget: SPARC processorsP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions