MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / map_trampoline_alignment

Function map_trampoline_alignment

tests/all/component_model/func.rs:3527–3660  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3525///
3526#[test]
3527fn map_trampoline_alignment() -> Result<()> {
3528 // Test map<u8, u64> - key_size=1, value_align=8
3529 // With the alignment bug, value would be read/written at offset 1 instead of 8
3530 let component = format!(
3531 r#"
3532(component
3533 (import "host" (func $host (param "m" (map u8 u64)) (result (map u8 u64))))
3534
3535 ;; Component A: the "destination" that receives and echoes back
3536 (component $dst
3537 (import "echo" (func $echo (param "m" (map u8 u64)) (result (map u8 u64))))
3538 (core module $libc
3539 (memory (export "memory") 1)
3540 {REALLOC_AND_FREE}
3541 )
3542 (core module $echo_mod
3543 (import "" "echo" (func $echo (param i32 i32 i32)))
3544 (import "libc" "memory" (memory 0))
3545 (import "libc" "realloc" (func $realloc (param i32 i32 i32 i32) (result i32)))
3546
3547 (func (export "echo") (param i32 i32) (result i32)
3548 (local $retptr i32)
3549 (local.set $retptr
3550 (call $realloc (i32.const 0) (i32.const 0) (i32.const 4) (i32.const 8)))
3551 (call $echo (local.get 0) (local.get 1) (local.get $retptr))
3552 local.get $retptr
3553 )
3554 )
3555 (core instance $libc (instantiate $libc))
3556 (core func $echo_lower (canon lower (func $echo)
3557 (memory $libc "memory")
3558 (realloc (func $libc "realloc"))
3559 ))
3560 (core instance $echo_inst (instantiate $echo_mod
3561 (with "libc" (instance $libc))
3562 (with "" (instance (export "echo" (func $echo_lower))))
3563 ))
3564 (func (export "echo2") (param "m" (map u8 u64)) (result (map u8 u64))
3565 (canon lift
3566 (core func $echo_inst "echo")
3567 (memory $libc "memory")
3568 (realloc (func $libc "realloc"))
3569 )
3570 )
3571 )
3572
3573 ;; Component B: the "source" that calls dst
3574 (component $src
3575 (import "echo" (func $echo (param "m" (map u8 u64)) (result (map u8 u64))))
3576 (core module $libc
3577 (memory (export "memory") 1)
3578 {REALLOC_AND_FREE}
3579 )
3580 (core module $echo_mod
3581 (import "" "echo" (func $echo (param i32 i32 i32)))
3582 (import "libc" "memory" (memory 0))
3583 (import "libc" "realloc" (func $realloc (param i32 i32 i32 i32) (result i32)))
3584

Callers

nothing calls this directly

Calls 12

OkFunction · 0.85
newFunction · 0.50
MapClass · 0.50
wasm_component_modelMethod · 0.45
func_newMethod · 0.45
rootMethod · 0.45
cloneMethod · 0.45
instantiateMethod · 0.45
unwrapMethod · 0.45
get_funcMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected