To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit f3ca9dc8 authored by Javad Ebrahimian Amiri's avatar Javad Ebrahimian Amiri
Browse files

Merge remote-tracking branch 'origin/sel4-rumprun-devel' into develop

# Conflicts:
#	Cargo.toml
#	build.rs
#	src/ast/src/inst.rs
#	src/ast/src/ir.rs
#	src/ast/src/ir_semantics.rs
#	src/ast/src/op.rs
#	src/compiler/backend/arch/aarch64/inst_sel.rs
#	src/compiler/backend/arch/x86_64/asm_backend.rs
#	src/compiler/backend/arch/x86_64/inst_sel.rs
#	src/compiler/backend/arch/x86_64/mod.rs
#	src/compiler/backend/mod.rs
#	src/lib.rs
#	src/runtime/entrypoints.rs
#	src/runtime/mod.rs
#	src/runtime/thread.rs
#	src/testutil/aot.rs
#	src/testutil/mod.rs
#	src/vm/vm.rs
#	tests/ir_macros.rs
#	tests/test_compiler/test_alloc.rs
#	tests/test_compiler/test_binop.rs
#	tests/test_compiler/test_call.rs
#	tests/test_compiler/test_controlflow.rs
#	tests/test_compiler/test_convop.rs
#	tests/test_compiler/test_exception.rs
#	tests/test_compiler/test_floatingpoint.rs
#	tests/test_compiler/test_inline.rs
#	tests/test_compiler/test_int.rs
#	tests/test_compiler/test_int128.rs
#	tests/test_compiler/test_mem_inst.rs
#	tests/test_compiler/test_regalloc.rs
#	tests/test_compiler/test_thread.rs
parents a2b50bb1 5bd96183
#!/usr/bin/env bash
export ZEBU_TARGET=x86_64-rumprun-netbsd
cd ././../rumprun-sel4/
bash clean_and_build.sh
\ No newline at end of file
......@@ -3574,6 +3574,7 @@ fn write_const_value(f: &mut File, constant: P<Value>) {
}
}
use std::collections::HashMap;
pub fn emit_context_with_reloc(
......
......@@ -24,6 +24,8 @@ crate-type = ["rlib"]
[features]
default = []
use-sidemap = []
sel4-rumprun = []
sel4-rumprun-target-side = []
[build-dependencies]
gcc = "*"
......
......@@ -14,21 +14,61 @@
extern crate gcc;
//#[cfg(not(feature = "sel4-rumprun-target-side"))]
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_arch = "x86_64")]
fn main() {
fn build_libgc(){
println!("detected macos or linux");
gcc::compile_library("libgc_clib_x64.a", &["src/heap/gc/clib_x64.c"]);
}
//#[cfg(not(feature = "sel4-rumprun-target-side"))]
#[cfg(target_os = "linux")]
#[cfg(target_arch = "aarch64")]
fn main() {
fn build_libgc() {
println!("detected linux aarch64");
gcc::compile_library("libgc_clib_aarch64.a", &["src/heap/gc/clib_aarch64.S"]);
}
// This is here to enable cross compiling from windows/x86_64 to linux/aarch64
//#[cfg(not(feature = "sel4-rumprun-target-side"))]
#[cfg(target_os = "windows")]
#[cfg(target_arch = "x86_64")]
fn main() {
fn build_libgc() {
println!("detected windows 64");
gcc::compile_library("libgc_clib_aarch64.a", &["src/heap/gc/clib_aarch64.S"]);
}
//#[cfg(all(target_os = "netbsd", target_vendor = "rumprun"))]
//#[cfg(feature = "sel4-rumprun-target-side")]
//#[cfg(target_arch = "x86_64")]
fn main() {
use std::env;
let mut gc_target = 0; // 1 for rumprun-sel4 and 0 otherwise
for (key, value) in env::vars() {
if key == "ZEBU_TARGET" {
if value == "x86_64-rumprun-netbsd" {
gc_target = 1;
break;
}
else {
gc_target = 0;
break;
}
}
}
// for sel4-rumprun, do (if)
// otherwise, call the related target function
if gc_target == 1 {
use std::path::Path;
println!("detected rumprun-netbsd");
let mut compiler_name = String::new();
compiler_name.push_str("x86_64-rumprun-netbsd-gcc");
gcc::Config::new().flag("-O3").flag("-c")
.compiler(Path::new(compiler_name.as_str()))
.file("src/heap/gc/clib_x64_sel4_rumprun.c")
.compile("libgc_clib_x64.a");
}
else { build_libgc(); }
}
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <pthread.h>
void* malloc_zero(size_t size) {
void* ret = malloc(size);
memset(ret, 0, size);
return ret;
}
uintptr_t immmix_get_stack_ptr() {
uintptr_t rsp;
// get current rsp, rbp (this C func frame)
__asm__(
"mov %%rsp, %0 \n"
: "=rm" (rsp)
);
return rsp;
}
int get_registers_count() {
return 16;
}
uintptr_t* get_registers () {
uintptr_t rax, rbx, rcx, rdx, rbp, rsp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15;
__asm__(
"mov %%rax, %0 \n"
"mov %%rbx, %1 \n"
"mov %%rcx, %2 \n"
"mov %%rdx, %3 \n"
"mov %%rbp, %4 \n"
"mov %%rsp, %5 \n"
"mov %%rsi, %5 \n"
"mov %%rdi, %6 \n"
"mov %%r8, %7 \n"
"mov %%r9, %8 \n"
"mov %%r10, %10\n"
"mov %%r11, %11\n"
"mov %%r12, %12\n"
"mov %%r13, %13\n"
"mov %%r14, %14\n"
"mov %%r15, %15\n"
: "=m" (rax),
"=m" (rbx),
"=m" (rcx),
"=m" (rdx),
"=m" (rbp),
"=m" (rsp),
"=m" (rsi),
"=m" (rdi),
"=m" (r8),
"=m" (r9),
"=m" (r10),
"=m" (r11),
"=m" (r12),
"=m" (r13),
"=m" (r14),
"=m" (r15)
:
:
);
uintptr_t* ret = (uintptr_t*) malloc(sizeof(uintptr_t) * 16);
ret[0] = rax;
ret[1] = rbx;
ret[2] = rcx;
ret[3] = rdx;
ret[4] = rbp;
ret[5] = rsp;
ret[6] = rsi;
ret[7] = rdi;
ret[8] = r8;
ret[9] = r9;
ret[10] = r10;
ret[11] = r11;
ret[12] = r12;
ret[13] = r13;
ret[14] = r14;
ret[15] = r15;
return ret;
}
// __thread uintptr_t low_water_mark;
int lwm_initialized = 0;
static pthread_key_t low_water_mark;
void set_low_water_mark () {
uintptr_t rsp;
if(lwm_initialized == 0){
lwm_initialized = 1;
int result = pthread_key_create(&low_water_mark, NULL);
if(result != 0){
printf("set_low_water_mark(): PThread key create failed with error code = %d\n", result);
assert(0);
}
}
// get current rsp, rbp (this C func frame)
__asm__(
"mov %%rsp, %0 \n"
: "=rm" (rsp)
);
int result = pthread_setspecific(low_water_mark, (const void *) rsp);
if(result != 0){
printf("set_low_water_mark(): PThread set specific failed with error code = %d\n", result);
assert(0);
}
}
uintptr_t get_low_water_mark() {
if(lwm_initialized == 0){
printf("get_low_water_mark(): PThread key MUST be initialized before first use!!\n");
}
void * result = pthread_getspecific(low_water_mark);
if(result == NULL){
printf("get_low_water_mark(): NO pthread key found for current thread!!\n");
assert(0);
}
return (uintptr_t) result;
}
......@@ -12,6 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
mod test_gc_harness;
pub mod test_gc_harness;
mod test_gcbench;
mod test_gc_linked_list;
......@@ -65,7 +65,7 @@ const FIXSIZE_REFx1_ENCODE : u64 = 0xb000000000000001u64;
#[test]
fn test_exhaust_alloc() {
pub fn test_exhaust_alloc() {
gc::gc_init(IMMIX_SPACE_SIZE, LO_SPACE_SIZE, 8, false);
let mut mutator = gc::new_mutator();
......
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
// This file provides a template so that we can define functions in ASM and also
// let the symbols be recognised in both Linux and OSX
#define CNAME(n) n
.macro begin_func n
.text
.globl CNAME(\n)
.type CNAME(\n),@function
.balign 16
CNAME(\n):
.endm
.macro end_func n
.size CNAME(\n), .-CNAME(\n)
.endm
; vim: ft=asm
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
extern void* vm;
extern void mu_main(char*, int, char**);
extern int32_t c_check_result();
int main(int argc, char** argv) {
char* serialize_vm = (char*) &vm;
mu_main(serialize_vm, argc, argv);
assert(c_check_result() == 0);
}
......@@ -73,4 +73,14 @@ void* resolve_symbol(const char* sym) {
// B dlsym
// printf("%s\n", sym);
return dlsym(RTLD_DEFAULT, sym);
}
int32_t mu_retval;
void muentry_set_retval(int32_t x) {
mu_retval = x;
}
int32_t c_check_result() {
return mu_retval;
}
\ No newline at end of file
......@@ -46,3 +46,17 @@ void* resolve_symbol(const char* sym) {
// printf("%s\n", sym);
return dlsym(RTLD_DEFAULT, sym);
}
int32_t mu_retval;
void muentry_set_retval(int32_t x) {
mu_retval = x;
}
int32_t c_check_result() {
return mu_retval;
}
char * alloc_mem(size_t size){
return (char *) malloc(size);
}
// Copyright 2017 The Australian National University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifdef __linux__
// RTLD_DEFAULT is not defined in POSIX. Linux gcc does not define it unless
// _GNU_SOURCE is also defined.
#define _GNU_SOURCE
#endif // __linux__
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <assert.h>
int tls_initialized = 0;
static pthread_key_t mu_tls;
void set_thread_local(void* thread) {
if(tls_initialized == 0){
tls_initialized = 1;
int result = pthread_key_create(&mu_tls, NULL);
if(result != 0){
printf("Set_Thread_Local(): PThread key create failed with error code = %d\n", result);
assert(0);
}
}
int result = pthread_setspecific(mu_tls, thread);
if(result != 0){
printf("Set_Thread_Local(): PThread set specific failed with error code = %d\n", result);
assert(0);
}
}
void* muentry_get_thread_local() {
if(tls_initialized == 0){
printf("Get_Thread_Local(): PThread key MUST be initialized before first use!!\n");
assert(0);
}
void * result = pthread_getspecific(mu_tls);
if(result == NULL){
printf("Get_Thread_Local(): NO pthread key found for current thread!!\n");
assert(0);
}
return result;
}
int32_t mu_retval;
void muentry_set_retval(int32_t x) {
mu_retval = x;
}
int32_t muentry_get_retval() {
return mu_retval;
}
int32_t c_check_result() {
return mu_retval;
}
\ No newline at end of file
# Copyright 2017 The Australian National University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#include "asm_common_x64_sel4_rumprun.S.inc"
# swap_stack_to(new_sp: Address, entry: Address, old_sp_loc: Address)
# %rdi %rsi %rdx
begin_func swap_to_mu_stack
# -- on old stack --
# C calling convention
pushq %rbp
movq %rsp, %rbp
# other callee-saved registers
pushq %rbx
pushq %r12
pushq %r13
pushq %r14
pushq %r15
# save sp to %rbx
movq %rsp, 0(%rdx)
# switch to new stack
movq %rdi, %rsp
# save entry function in %rax
movq %rsi, %rax
# -- on new stack --
# arguments (reverse order of thread.rs - runtime_load_args)
popq %r9
popq %r8
popq %rcx
popq %rdx
popq %rsi
popq %rdi
movsd 0(%rsp), %xmm7
movsd 8(%rsp), %xmm6
movsd 16(%rsp), %xmm5
movsd 24(%rsp), %xmm4
movsd 32(%rsp), %xmm3
movsd 40(%rsp), %xmm2
movsd 48(%rsp), %xmm1
movsd 56(%rsp), %xmm0
add $64, %rsp
# at this point new stack is clean (no intermediate values)
movq %rsp, %rbp
# push an empty pointer to stack, if entry fucntion tries to return, it causes a segfault
pushq $0
# push entry function and start it
pushq %rax
ret
end_func swap_to_mu_stack
# _swap_back_to_native_stack(sp_loc: Address)
# %rdi
begin_func muentry_swap_back_to_native_stack
movq 0(%rdi), %rsp
popq %r15
popq %r14
popq %r13
popq %r12
popq %rbx
popq %rbp
ret
end_func muentry_swap_back_to_native_stack
# _get_current_frame_rbp() -> Address
begin_func get_current_frame_rbp
movq %rbp, %rax
ret
end_func get_current_frame_rbp
# muentry_throw_exception(obj: Address)
# %rdi
begin_func muentry_throw_exception
# save all callee-saved
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbp
pushq %rbx
# %rsp points to %rbx, pass this as 2nd argument
movq %rsp, %rsi
jmp CNAME(throw_exception_internal@PLT)
# won't return
# _exception_restore(dest: Address, callee_saved: *const Word, rsp: Address) -> !
# %rdi %rsi %rdx
# callee_saved: [rbx, rbp, r12, r13, r14, r15]
begin_func exception_restore
movq 0(%rsi), %rbx
movq 8(%rsi), %rbp
movq 16(%rsi),%r12
movq 24(%rsi),%r13
movq 32(%rsi),%r14
movq 40(%rsi),%r15
movq %rdx, %rsp
jmpq *%rdi
end_func exception_restore
# fake_swap_mu_thread(old_sp_loc: Address)
# %rdi
# (we do not actually swap stack, but we make the stack the same
# as if they are native stack that have been swapped out, so that
# when THREADEXIT (swap_back_to_native_stack) is called, we won't panic
# this function is untested!!!
begin_func fake_swap_mu_thread
# save return address
movq (%rsp), %rax
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %r12
pushq %r13
pushq %r14
pushq %r15
# save old sp to thread field
movq %rsp, 0(%rdi)
# return to caller, but preserve those pushed values (since THREADEXIT will pick them up)
pushq %rax
ret
\ No newline at end of file
......@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![feature(i128_type)]
extern crate mu;
extern crate mu_utils as utils;
#[macro_use]
......
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
// a pointer to the symbol table I generate
extern void* mu_sym_table;
//extern int32_t mu_retval;
//
//int32_t muentry_get_retval(){
// return mu_retval;
//}
// a function to resolve symbol names to their address, using mu_sym_table\
// which is valued by the c_resolve_sym function, according to \
// mu_sym_table_root
// actually this function will search for the symbol in one idX_sym_table
void * resolve_symbol_in_current_context(const unsigned char * input_symbol_name){
unsigned long i = 0, j=0;
unsigned long num_of_syms = 0;
unsigned long cur_len = 0;
unsigned long input_len = 0;