@@ -100,6 +100,7 @@ pub(crate) struct SandboxMemoryLayout {
100
100
pub ( super ) peb_host_function_definitions_offset : usize ,
101
101
peb_input_data_offset : usize ,
102
102
peb_output_data_offset : usize ,
103
+ peb_init_data_offset : usize ,
103
104
peb_heap_data_offset : usize ,
104
105
peb_guest_stack_data_offset : usize ,
105
106
@@ -163,6 +164,10 @@ impl Debug for SandboxMemoryLayout {
163
164
"Output Data Offset" ,
164
165
& format_args ! ( "{:#x}" , self . peb_output_data_offset) ,
165
166
)
167
+ . field (
168
+ "Init Data Offset" ,
169
+ & format_args ! ( "{:#x}" , self . peb_init_data_offset) ,
170
+ )
166
171
. field (
167
172
"Guest Heap Offset" ,
168
173
& format_args ! ( "{:#x}" , self . peb_heap_data_offset) ,
@@ -264,6 +269,7 @@ impl SandboxMemoryLayout {
264
269
let peb_code_pointer_offset = peb_offset + offset_of ! ( HyperlightPEB , code_ptr) ;
265
270
let peb_input_data_offset = peb_offset + offset_of ! ( HyperlightPEB , input_stack) ;
266
271
let peb_output_data_offset = peb_offset + offset_of ! ( HyperlightPEB , output_stack) ;
272
+ let peb_init_data_offset = peb_offset + offset_of ! ( HyperlightPEB , init_data) ;
267
273
let peb_heap_data_offset = peb_offset + offset_of ! ( HyperlightPEB , guest_heap) ;
268
274
let peb_guest_stack_data_offset = peb_offset + offset_of ! ( HyperlightPEB , guest_stack) ;
269
275
let peb_host_function_definitions_offset =
@@ -307,6 +313,7 @@ impl SandboxMemoryLayout {
307
313
peb_host_function_definitions_offset,
308
314
peb_input_data_offset,
309
315
peb_output_data_offset,
316
+ peb_init_data_offset,
310
317
peb_heap_data_offset,
311
318
peb_guest_stack_data_offset,
312
319
sandbox_memory_config : cfg,
@@ -349,6 +356,13 @@ impl SandboxMemoryLayout {
349
356
self . peb_host_function_definitions_offset + size_of :: < u64 > ( )
350
357
}
351
358
359
+ /// Get the offset in guest memory to the init data size
360
+ #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
361
+ pub ( super ) fn get_init_data_size_offset ( & self ) -> usize {
362
+ // The init data size is the first field in the `GuestMemoryRegion` struct
363
+ self . peb_init_data_offset
364
+ }
365
+
352
366
/// Get the offset in guest memory to the minimum guest stack address.
353
367
#[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
354
368
fn get_min_guest_stack_address_offset ( & self ) -> usize {
@@ -385,6 +399,14 @@ impl SandboxMemoryLayout {
385
399
self . get_output_data_size_offset ( ) + size_of :: < u64 > ( )
386
400
}
387
401
402
+ /// Get the offset in guest memory to the init data pointer.
403
+ #[ instrument( skip_all, parent = Span :: current( ) , level= "Trace" ) ]
404
+ pub ( super ) fn get_init_data_pointer_offset ( & self ) -> usize {
405
+ // The init data pointer is immediately after the init data size field,
406
+ // which is a `u64`.
407
+ self . get_init_data_size_offset ( ) + size_of :: < u64 > ( )
408
+ }
409
+
388
410
/// Get the offset in guest memory to the start of output data.
389
411
///
390
412
/// This function exists to accommodate the macro that generates C API
@@ -820,6 +842,14 @@ impl SandboxMemoryLayout {
820
842
let addr = get_address ! ( output_data_buffer_offset) ;
821
843
shared_mem. write_u64 ( self . get_output_data_pointer_offset ( ) , addr) ?;
822
844
845
+ // Set up init data pointer
846
+ shared_mem. write_u64 (
847
+ self . get_init_data_size_offset ( ) ,
848
+ ( self . get_unaligned_memory_size ( ) - self . init_data_offset ) . try_into ( ) ?,
849
+ ) ?;
850
+ let addr = get_address ! ( init_data_offset) ;
851
+ shared_mem. write_u64 ( self . get_init_data_pointer_offset ( ) , addr) ?;
852
+
823
853
// Set up heap buffer pointer
824
854
let addr = get_address ! ( guest_heap_buffer_offset) ;
825
855
shared_mem. write_u64 ( self . get_heap_size_offset ( ) , self . heap_size . try_into ( ) ?) ?;
0 commit comments