Each external interface method (SFC) that a custom firmware module provides may have its own input structure, and may also have its own output structure.
The low-level Utimaco libraries (host and HSM) do provide macros and methods that assist in the correct read and write of a byte buffer, but this assumes that the programmer understands what needs to be in the buffer, and what order those sub fields need to be in, and, importantly, how they should be entered into the byte stream (endianness, length-value protocol used, etc).
For the low-level call to the HSM from host-side code, Utimaco supplies library calls (ie, 'cxi.exec()' or 'cs_exec_command()') which send a previously serialized buffer, along with the routing information needed to target a specific module and sub-function code. Memory management is straightforward: The host application is responsible for both allocation and deallocation of space for the byte-buffer. The various exec methods simply copy from that space (or from a received socket receive buffer) into the PCIe driver's memory-mapped IO buffer.
On the HSM, the module's targeted sub-function will probably use the 'cmds_scanf' methodology (_install_\SDK\doc\mdl_CMDS.pdf) on receipt, to parse the input.
When the HSM sends an answer, HSM to host, the SFC implementation must allocate a buffer for the response within the _parent_ context, eg. by using the Utimaco CMDS-provided 'cmds_alloc_answ()'.
cmds_alloc_answ() is part of the CMDS public interface.
After the sub-function is finished with its processing, it copies its response into the provided buffer, and returns control to the context. The CMDS context is responsible for transmitting the bytes in the answer buffer. It will then free the memory allocated by the SFC's call to 'cmds_alloc_answ()'.
On receipt, the application may use the 'cs_scanp' methodology to parse the input. This helper routine is described in _install_ \SDK \doc \CryptoServer_CSXAPI.pdf).
Again, all of these input or output byte-buffers are manually serialized by the programmer.