Skip to content

Allow host to pass reference types (&[u8] and &str) to guest funcs #1987

Open

Description

@ludfjig

Sandbox::call only accepts owned string and byte arguments: String, Vec<u8> and Vec<Bytes>. Guest call_host has the same limit. Hyperlight never needs ownership, because arguments are only borrowed and copied once into the virtqueue. A user holding a &[u8] or &str must clone it first, for example sandbox.call("f", bytes.to_vec()), which costs an extra allocation and copy.

For bytes, users must also pick the type that matches the guest function's parameter:

  • Vec<u8> (VecBytes): the guest copies the bytes into a Vec<u8>.
  • Vec<Bytes> (ByteChunks): the guest keeps Bytes handles to the transport buffers without copying.

Fix:

  • Accept &str and &[u8] arguments, and keep accepting owned ones.
  • Send all byte arguments in one format, and let the guest function's parameter type decide how to read them. A Vec<Bytes> parameter keeps the transport buffers without copying, and a Vec<u8> parameter copies once.

Copies per byte argument:

User holds Guest parameter Today After fix
Vec<u8> Vec<u8> 2 2
&[u8] Vec<u8> 3 2
Bytes Vec<Bytes> 1 1
&[u8] Vec<Bytes> 2 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions