Save an unconditional clone of guest parameters for registered guest functions#1241
Save an unconditional clone of guest parameters for registered guest functions#1241ludfjig wants to merge 2 commits intohyperlight-dev:mainfrom
Conversation
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
dblnz
left a comment
There was a problem hiding this comment.
This is fine from my point of view. I've got burnt by this slight difference between the guest_dispatch_function definition and the other function definitions.
|
The perf improvement looks great, and I don't think that the amount of breaking that you mention there is necessarily a barrier. If we wanted to be very proper I suppose we would introduce a new Two slight comments:
|
I know @jsturtevant has strong opinions on the permissibility of breaking changes that can cause silent failure in downstreams, so paging him on this as well. |
|
Maybe we can rename Regarding the owned |
|
This LGTM. |
Or we can make the type private, and make people use the |
This seems like a pretty small and reasonable thing to do to avoid any downstream users having any issues with this. I believe building a habit of recognizing and coming up with patterns to avoid unexpected downstream issues is a good thing. |
1c1e23f to
bef122c
Compare
|
Updated @syntactically @jprendes @dblnz @jsturtevant |
f808d25 to
4dec0e4
Compare
|
|
||
| #[unsafe(no_mangle)] | ||
| pub fn guest_dispatch_function(function_call: FunctionCall) -> Result<Vec<u8>> { | ||
| pub fn guest_dispatch_function_v2(function_call: FunctionCall) -> Result<Vec<u8>> { |
There was a problem hiding this comment.
does this still need to be public? could we just use the marco going forward?
There was a problem hiding this comment.
oh yeah let's switch to the macro here too! Fixed
| let guest_func = | ||
| unsafe { mem::transmute::<usize, CGuestFunc>(registered_func.function_pointer) }; | ||
| let function_result = guest_func(&ffi_func_call); | ||
| let function_result = (registered_func.function_pointer)(&ffi_func_call); |
There was a problem hiding this comment.
Is this borrow right here?
There was a problem hiding this comment.
good observation, but yes it is correct. The guest c-api has it's own function signature that needs to be hl_Vec *c_guest_dispatch_function(const hl_FunctionCall *function_call)
- Rename guest_dispatch_function to guest_dispatch_function_v2 to force linker errors for out-of-date downstream code - Add guest_dispatch! macro so users don't define the symbol by hand; future signature changes will produce compile errors automatically - Parameterize GuestFunctionDefinition<F: Copy> over the function pointer type, eliminating transmutes in the C API dispatch path - Remove redundant clone in print_output_with_host_print now that FunctionCall is passed by value Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
4dec0e4 to
fa5bf10
Compare
vs main:

Only affects registered guest functions (not c api, nor when someone implements their own
guest_dispatch_function).Note that this is a breaking change for downstream users who manually register guest functions (hyperlight-wasm), but even more scary is that it will break silently, since the function signature is not type-checked😱. We should probably address this by exporting the type as
pub, and add const time assertions in the downstream libraries. Or make it a macro that users use, which provides the function signature, and let the user provide the function body