-
Notifications
You must be signed in to change notification settings - Fork 134
Make common and guest libs portable #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make common and guest libs portable #524
Conversation
4dec35f
to
30dd928
Compare
We no longer have kernel stack and boot stacks, so we can remove these fields. Also, removed some legacy comment. Signed-off-by: danbugs <danilochiarlone@gmail.com>
If the guest and host are compiled for different architectures, there will be a mismatch in usage of the PEB. Using u64s, just like we do for pCode, makes our PEB portable. Signed-off-by: danbugs <danilochiarlone@gmail.com>
It's useful for a library to provide implementaitons of these traits for its structures. Signed-off-by: danbugs <danilochiarlone@gmail.com>
- InputData, OutputData, and GuestHeapData were functionally the same and so they were combined into a single GuestMemoryRegion struct. - removed the allow_non_snake_case attribute. - general housekeeping. Signed-off-by: danbugs <danilochiarlone@gmail.com>
If we use usize and the guest and host are compiled for different architectures, there will be a mismatch in sizing between the guest and host, so we should use u64s to address that (tested w/ Nanvix already). Signed-off-by: danbugs <danilochiarlone@gmail.com>
30dd928
to
0f91d6c
Compare
from one of the commits:
What happens if one side is 32 bit? could a cast down to the smaller pointer lose information? |
This made it really easy to review. Thanks! |
We don't support 32-bit hosts currently, our shared-mem abstraction is built on the assumption of a 64-bit architecture. Currently, using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I will reserve a bit of concern about the assumptions made in this PR about the host targeting u64 and casting into usize. We do not intend on targeting Hyperlight host to 32 bit. If we were to pursue that, this code would likely not work as intended.
Just to elaborate on this... Before this PR, the guest writes a W/ this PR in, regardless of architecture, the guest now also always writes a 64-bit stack ptr matching the expectation of the host. The problem @devigned is pointing out occurs when we try to run a host on a 32-bit architecture. Currently, the host does this when reading the stack ptr:
... which, on a 32-bit architecture, this could cause a silent truncation and UB. That said, as things are currently, it's unlikely we could ever get any meaningful truncation because the ptr would have to be bigger than the maximum memory size we support. In any case, this is a good reminder we definitely don't support 32-bit hosts :) |
Thanks for this, I understand now these aren't actual stack pointers in the guest/host but addresses within a shared memory buffer for passing function information back and forth, such as a flatbuffer of I guess it would be nice to make sure we have an invariant somewhere to force this incase somehow that assumption changes (maybe there already is?) |
This PR changes our pointer usage in the guest and common lib to be portable (i.e., using
u64s
instead ofusize
or pointer types that vary between architectures).Plus, I did some general housekeeping like removing legacy fields/comments, refactored the PEB structs to avoid code duplication, and madeour PEB related struct items snake case.
Reviews can be made commit-by-commit, if you preferred.