Modify occlum_entry to be compatible with Linux syscall ABI

This commit is contained in:
LI Qing 2020-04-14 04:33:49 +00:00 committed by Tate, Hongliang Tian
parent 72f2a33e2a
commit 1172c25677
2 changed files with 49 additions and 3 deletions

@ -311,8 +311,8 @@ fn init_auxvec(process_vm: &ProcessVM, exec_elf_file: &ElfFile) -> Result<AuxVec
let ldso_elf_base = process_vm.get_elf_ranges()[1].start() as u64; let ldso_elf_base = process_vm.get_elf_ranges()[1].start() as u64;
auxvec.set(AuxKey::AT_BASE, ldso_elf_base)?; auxvec.set(AuxKey::AT_BASE, ldso_elf_base)?;
let syscall_addr = __occlum_syscall as *const () as u64; let syscall_native_addr = __occlum_syscall_native as *const () as u64;
auxvec.set(AuxKey::AT_OCCLUM_ENTRY, syscall_addr)?; auxvec.set(AuxKey::AT_OCCLUM_ENTRY, syscall_native_addr)?;
// TODO: init AT_EXECFN // TODO: init AT_EXECFN
// auxvec.set_val(AuxKey::AT_EXECFN, "program_name")?; // auxvec.set_val(AuxKey::AT_EXECFN, "program_name")?;
@ -320,6 +320,6 @@ fn init_auxvec(process_vm: &ProcessVM, exec_elf_file: &ElfFile) -> Result<AuxVec
} }
extern "C" { extern "C" {
fn __occlum_syscall(num: i32, arg0: u64, arg1: u64, arg2: u64, arg3: u64, arg4: u64) -> i64; fn __occlum_syscall_native() -> i64;
fn occlum_gdb_hook_load_elf(elf_base: u64, elf_path: *const u8, elf_path_len: u64); fn occlum_gdb_hook_load_elf(elf_base: u64, elf_path: *const u8, elf_path_len: u64);
} }

@ -0,0 +1,46 @@
#define __ASSEMBLY__
#include "task.h"
.file "syscall_entry_native_x86-64.S"
.global __occlum_syscall_native
.type __occlum_syscall_native, @function
__occlum_syscall_native:
push %rbp
movq %rsp,%rbp
// Save registers
pushq %rdi
pushq %rsi
pushq %rdx
pushq %r10
pushq %r8
// arg5
pushq %r9
// arg4--arg0
movq %r8, %r9
movq %r10, %r8
movq %rdx, %rcx
movq %rsi, %rdx
movq %rdi, %rsi
// num
movq %rax, %rdi
// num - %rdi
// arg0 - %rsi
// arg1 - %rdx
// arg2 - %rcx
// arg3 - %r8
// arg4 - %r9
// arg5 - *0x8(%rsp)
call __occlum_syscall
// Restore registers
popq %r9
popq %r8
popq %r10
popq %rdx
popq %rsi
popq %rdi
popq %rbp
ret