Skip to content

Commit 43bcf6e

Browse files
committed
[host/mgr] added note on MSVC's rsp meddling
See #498 for more details. Signed-off-by: danbugs <[email protected]>
1 parent 743ac7b commit 43bcf6e

File tree

1 file changed

+4
-12
lines changed
  • src/hyperlight_host/src/mem

1 file changed

+4
-12
lines changed

src/hyperlight_host/src/mem/mgr.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,13 @@ where
107107
mem_size: u64,
108108
regions: &mut [MemoryRegion],
109109
) -> Result<u64> {
110-
// For MSVC, move rsp down by 0x28. This gives the called 'main'
111-
// function the appearance that rsp was 16 byte aligned before
112-
// the 'call' that calls main (note we don't really have a return value
113-
// on the stack but some assembly instructions are expecting rsp have
114-
// started 0x8 bytes off of 16 byte alignment when 'main' is invoked.
115-
// We do 0x28 instead of 0x8 because MSVC can expect that there are
116-
// 0x20 bytes of space to write to by the called function.
117-
// I am not sure if this happens with the 'main' method, but we do this
118-
// just in case.
119-
//
120-
// NOTE: We do this also for GCC freestanding binaries because we
121-
// specify __attribute__((ms_abi)) on the start method
122110
let rsp: u64 = self.layout.get_top_of_user_stack_offset() as u64
123111
+ SandboxMemoryLayout::BASE_ADDRESS as u64
124112
+ self.layout.stack_size as u64
113+
// TODO: subtracting 0x28 was a requirement for MSVC. It should no longer be
114+
// necessary now, but, for some reason, without this, the `multiple_parameters`
115+
// test from `sandbox_host_tests` fails. We should investigate this further.
116+
// See issue #498 for more details.
125117
- 0x28;
126118

127119
self.shared_mem.with_exclusivity(|shared_mem| {

0 commit comments

Comments
 (0)