@@ -34,6 +34,7 @@ pub(crate) struct GpRegs {
3434 r14 : u64 ,
3535 r15 : u64 ,
3636 pub ( crate ) rsi : u64 ,
37+ r8 : u64 ,
3738}
3839
3940impl GpRegs {
@@ -48,6 +49,7 @@ impl GpRegs {
4849 r14 : 0 ,
4950 r15 : 0 ,
5051 rsi : 0 ,
52+ r8 : 0 ,
5153 }
5254 }
5355}
@@ -208,9 +210,10 @@ impl ContextHandle {
208210 stack : & mut [ u64 ] ,
209211 fptr : usize ,
210212 args : & [ Val ] ,
213+ heap : * mut core:: ffi:: c_void ,
211214 ) -> Result < ContextHandle , Error > {
212215 let mut child = ContextHandle :: new ( ) ;
213- Context :: init ( stack, & mut child, fptr, args) ?;
216+ Context :: init ( stack, & mut child, fptr, args, heap ) ?;
214217 Ok ( child)
215218 }
216219}
@@ -303,6 +306,7 @@ impl Context {
303306 /// &mut child,
304307 /// entrypoint as usize,
305308 /// &[Val::U64(120), Val::F32(3.14)],
309+ /// std::ptr::null_mut(),
306310 /// );
307311 /// assert!(res.is_ok());
308312 /// ```
@@ -326,6 +330,7 @@ impl Context {
326330 /// &mut child,
327331 /// entrypoint as usize,
328332 /// &[Val::U64(120), Val::F32(3.14)],
333+ /// std::ptr::null_mut(),
329334 /// );
330335 /// assert!(res.is_ok());
331336 /// ```
@@ -367,6 +372,7 @@ impl Context {
367372 child : & mut Context ,
368373 fptr : usize ,
369374 args : & [ Val ] ,
375+ heap : * mut core:: ffi:: c_void ,
370376 ) -> Result < ( ) , Error > {
371377 Context :: init_with_callback (
372378 stack,
@@ -375,6 +381,7 @@ impl Context {
375381 ptr:: null_mut ( ) ,
376382 fptr,
377383 args,
384+ heap,
378385 )
379386 }
380387
@@ -393,6 +400,7 @@ impl Context {
393400 callback_data : * mut Instance ,
394401 fptr : usize ,
395402 args : & [ Val ] ,
403+ heap : * mut core:: ffi:: c_void ,
396404 ) -> Result < ( ) , Error > {
397405 if !stack_is_aligned ( stack) {
398406 return Err ( Error :: UnalignedStack ) ;
@@ -475,6 +483,10 @@ impl Context {
475483 // even at the entrypoint of the guest.
476484 child. gpr . rbp = child as * const Context as u64 ;
477485
486+ // Heap pinning: r15 is not used to pass any parameters on Windows/POSIX abis, we simply set this to be the value of the heap always.
487+ // This value will be used only when the lucet module loaded is compiled requiring use of the pinned heap register.
488+ child. gpr . r15 = heap as u64 ;
489+
478490 Ok ( ( ) )
479491 }
480492
@@ -547,6 +559,7 @@ impl Context {
547559 /// &mut child,
548560 /// entrypoint as usize,
549561 /// &[],
562+ /// std::ptr::null_mut(),
550563 /// ).unwrap();
551564 ///
552565 /// unsafe { Context::swap(&mut parent, &mut child); }
0 commit comments