Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit edb5a3b

Browse files
wiggle things around to use pinned heap reg
1 parent 930f2b3 commit edb5a3b

4 files changed

Lines changed: 37 additions & 24 deletions

File tree

lucet-runtime/lucet-runtime-internals/src/context/context_asm.S

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ _lucet_context_bootstrap:
4444
mov %r12, %rsi
4545
mov %r13, %rdx
4646
mov %r14, %rcx
47-
mov %r15, %r8
47+
mov %r8, %r8
4848
mov %rbx, %r9
4949
/* the next thing on the stack is the guest function - return to it */
5050
ret
@@ -64,9 +64,9 @@ lucet_context_backstop:
6464
_lucet_context_backstop:
6565
mov -16(%rbp), %rdi /* parent context to arg 1 */
6666
mov -8(%rbp), %rsi /* own context to arg 2 */
67-
mov %rax, (8*8 + 8*16 + 8*0)(%rdi) /* store return values before swapping back -- offset is offsetof(struct lucet_context, retvals) */
68-
mov %rdx, (8*8 + 8*16 + 8*1)(%rdi)
69-
movdqu %xmm0, (8*8 + 8*16 + 8*2)(%rdi) /* floating-point return value */
67+
mov %rax, (10*8 + 8*16 + 8*0)(%rdi) /* store return values before swapping back -- offset is offsetof(struct lucet_context, retvals) */
68+
mov %rdx, (10*8 + 8*16 + 8*1)(%rdi)
69+
movdqu %xmm0, (10*8 + 8*16 + 8*2)(%rdi) /* floating-point return value */
7070
#ifdef __ELF__
7171
jmp lucet_context_swap@PLT
7272
#else
@@ -95,15 +95,16 @@ _lucet_context_swap:
9595
mov %r13, (5*8)(%rdi)
9696
mov %r14, (6*8)(%rdi)
9797
mov %r15, (7*8)(%rdi)
98+
mov %r8, (8*8)(%rdi)
9899

99-
movdqu %xmm0, (8*8 + 0*16)(%rdi)
100-
movdqu %xmm1, (8*8 + 1*16)(%rdi)
101-
movdqu %xmm2, (8*8 + 2*16)(%rdi)
102-
movdqu %xmm3, (8*8 + 3*16)(%rdi)
103-
movdqu %xmm4, (8*8 + 4*16)(%rdi)
104-
movdqu %xmm5, (8*8 + 5*16)(%rdi)
105-
movdqu %xmm6, (8*8 + 6*16)(%rdi)
106-
movdqu %xmm7, (8*8 + 7*16)(%rdi)
100+
movdqu %xmm0, (10*8 + 0*16)(%rdi)
101+
movdqu %xmm1, (10*8 + 1*16)(%rdi)
102+
movdqu %xmm2, (10*8 + 2*16)(%rdi)
103+
movdqu %xmm3, (10*8 + 3*16)(%rdi)
104+
movdqu %xmm4, (10*8 + 4*16)(%rdi)
105+
movdqu %xmm5, (10*8 + 5*16)(%rdi)
106+
movdqu %xmm6, (10*8 + 6*16)(%rdi)
107+
movdqu %xmm7, (10*8 + 7*16)(%rdi)
107108

108109
// load everything from offsets from rsi (2nd arg)
109110
mov (0*8)(%rsi), %rbx
@@ -114,15 +115,16 @@ _lucet_context_swap:
114115
mov (5*8)(%rsi), %r13
115116
mov (6*8)(%rsi), %r14
116117
mov (7*8)(%rsi), %r15
117-
118-
movdqu (8*8 + 0*16)(%rsi), %xmm0
119-
movdqu (8*8 + 1*16)(%rsi), %xmm1
120-
movdqu (8*8 + 2*16)(%rsi), %xmm2
121-
movdqu (8*8 + 3*16)(%rsi), %xmm3
122-
movdqu (8*8 + 4*16)(%rsi), %xmm4
123-
movdqu (8*8 + 5*16)(%rsi), %xmm5
124-
movdqu (8*8 + 6*16)(%rsi), %xmm6
125-
movdqu (8*8 + 7*16)(%rsi), %xmm7
118+
mov (8*8)(%rsi), %r8
119+
120+
movdqu (10*8 + 0*16)(%rsi), %xmm0
121+
movdqu (10*8 + 1*16)(%rsi), %xmm1
122+
movdqu (10*8 + 2*16)(%rsi), %xmm2
123+
movdqu (10*8 + 3*16)(%rsi), %xmm3
124+
movdqu (10*8 + 4*16)(%rsi), %xmm4
125+
movdqu (10*8 + 5*16)(%rsi), %xmm5
126+
movdqu (10*8 + 6*16)(%rsi), %xmm6
127+
movdqu (10*8 + 7*16)(%rsi), %xmm7
126128

127129
ret
128130
#ifdef __ELF__

lucet-runtime/lucet-runtime-internals/src/context/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct GpRegs {
3434
r13: u64,
3535
r14: u64,
3636
r15: u64,
37+
r8: u64
3738
}
3839

3940
impl GpRegs {
@@ -47,6 +48,7 @@ impl GpRegs {
4748
r13: 0,
4849
r14: 0,
4950
r15: 0,
51+
r8: 0,
5052
}
5153
}
5254
}
@@ -195,9 +197,10 @@ impl ContextHandle {
195197
parent: &mut ContextHandle,
196198
fptr: usize,
197199
args: &[Val],
200+
heap: *mut core::ffi::c_void,
198201
) -> Result<ContextHandle, Error> {
199202
let mut child = ContextHandle::new();
200-
Context::init(stack, parent, &mut child, fptr, args)?;
203+
Context::init(stack, parent, &mut child, fptr, args, heap)?;
201204
Ok(child)
202205
}
203206
}
@@ -287,6 +290,7 @@ impl Context {
287290
child: &mut Context,
288291
fptr: usize,
289292
args: &[Val],
293+
heap: *mut core::ffi::c_void,
290294
) -> Result<(), Error> {
291295
if !stack_is_aligned(stack) {
292296
xbail!(Error::UnalignedStack);
@@ -365,6 +369,9 @@ impl Context {
365369
// parent arguments set above.
366370
child.gpr.rbp = &mut stack[sp - 2] as *mut u64 as u64;
367371

372+
// testing out heap pinning
373+
child.gpr.r15 = heap as u64;
374+
368375
// Read the sigprocmask to be restored if we ever need to jump out of a signal handler. If
369376
// this isn't possible, die.
370377
signal::sigprocmask(
@@ -569,7 +576,7 @@ impl Context {
569576
// bootstraps into rcx
570577
3 => self.gpr.r14 = arg,
571578
// bootstraps into r8
572-
4 => self.gpr.r15 = arg,
579+
4 => self.gpr.r8 = arg,
573580
// bootstraps into r9
574581
5 => self.gpr.rbx = arg,
575582
_ => panic!("unexpected gp register index {}", ix),

lucet-runtime/lucet-runtime-internals/src/instance.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,8 @@ impl Instance {
797797

798798
self.entrypoint = Some(func.ptr);
799799

800-
let mut args_with_vmctx = vec![Val::from(self.alloc.slot().heap)];
800+
let heap = self.alloc.slot().heap;
801+
let mut args_with_vmctx = vec![Val::from(heap)];
801802
args_with_vmctx.extend_from_slice(args);
802803

803804
HOST_CTX.with(|host_ctx| {
@@ -807,6 +808,7 @@ impl Instance {
807808
&mut self.ctx,
808809
func.ptr.as_usize(),
809810
&args_with_vmctx,
811+
heap,
810812
)
811813
})?;
812814

lucetc/src/compiler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ impl<'a> Compiler<'a> {
196196
cranelift_native::builder().expect("host machine is not a supported target");
197197
flags_builder.enable("enable_verifier").unwrap();
198198
flags_builder.enable("is_pic").unwrap();
199+
flags_builder.enable("enable_pinned_reg");
200+
flags_builder.enable("use_pinned_reg_as_heap_base");
199201
flags_builder.set("opt_level", opt_level.to_flag()).unwrap();
200202
isa_builder.finish(settings::Flags::new(flags_builder))
201203
}

0 commit comments

Comments
 (0)