sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Align FfiCallbackTrampoline stub

Open liamappelbe opened this issue 2 years ago • 0 comments

We don't currently have the infrastructure to choose an alignment for a stub, but it would be useful in the case of FfiCallbackTrampoline.

We have to duplicate this stub using VirtualMemory operations, which are page aligned (actually FfiCallbackMetadata::kPageSize aligned). The stub is designed to fit in one page, so if it was page aligned we'd only need 1 page of memory for the duplicated stub. Since it's not aligned we need to grab 2 pages, because it will almost certainly straddle 2 pages, which wastes memory.

Additionally, StubCodeCompiler::GenerateLoadFfiCallbackMetadataRuntimeFunction could be simplified if the stub was aligned. We could remove the and instruction that aligns the PC, and end up with a single LoadFromOffset call.

liamappelbe avatar May 24 '23 02:05 liamappelbe