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

Commit 0b181a27 authored by qinsoon's avatar qinsoon
Browse files

Merge branch 'develop' into swapstack

parents 49cf6e58 8a1a2d3f
// 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.
......@@ -17,20 +17,32 @@ extern crate gcc;
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(target_arch = "x86_64")]
fn build_libgc() {
gcc::Build::new().flag("-O3").flag("-c").file("src/heap/gc/clib_x64.c").compile("libgc_clib_x64.a");
gcc::Build::new()
.flag("-O3")
.flag("-c")
.file("src/heap/gc/clib_x64.c")
.compile("libgc_clib_x64.a");
}
#[cfg(target_os = "linux")]
#[cfg(target_arch = "aarch64")]
fn build_libgc() {
gcc::Build::new().flag("-O3").flag("-c").file("src/heap/gc/clib_aarch64.S").compile("libgc_clib_aarch64.a");
gcc::Build::new()
.flag("-O3")
.flag("-c")
.file("src/heap/gc/clib_aarch64.S")
.compile("libgc_clib_aarch64.a");
}
// This is here to enable cross compiling from windows/x86_64 to linux/aarch64
#[cfg(target_os = "windows")]
#[cfg(target_arch = "x86_64")]
fn build_libgc() {
gcc::Build::new().flag("-O3").flag("-c").file("src/heap/gc/clib_aarch64.S").compile("libgc_clib_aarch64.a");
gcc::Build::new()
.flag("-O3")
.flag("-c")
.file("src/heap/gc/clib_aarch64.S")
.compile("libgc_clib_aarch64.a");
}
// Due to bugs, it is currently not possible to use conditional compilation \
......@@ -56,9 +68,13 @@ fn main() {
use std::path::Path;
let mut compiler_name = String::new();
compiler_name.push_str("x86_64-rumprun-netbsd-gcc");
gcc::Build::new().flag("-O3").flag("-c")
gcc::Build::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(); }
} else {
build_libgc();
}
}
......@@ -16,7 +16,8 @@ use std::mem;
use utils::POINTER_SIZE;
use utils::LOG_POINTER_SIZE;
use utils::Address;
use heap::gc::malloc_zero;
use utils::mem::malloc_zero;
use utils::mem::memsec::free;
#[derive(Clone)]
pub struct AddressMap<T: Copy> {
......@@ -64,3 +65,12 @@ where
unsafe { *self.ptr.offset(index) }
}
}
impl<T> Drop for AddressMap<T>
where
T: Copy
{
fn drop(&mut self) {
unsafe { free(self.ptr) }
}
}
......@@ -13,8 +13,8 @@
// limitations under the License.
use std::mem;
use heap::gc::malloc_zero;
use utils::mem::malloc_zero;
use utils::mem::memsec::free;
#[derive(Clone)]
pub struct Bitmap {
......@@ -136,6 +136,12 @@ impl Bitmap {
}
}
impl Drop for Bitmap {
fn drop(&mut self) {
unsafe { free(self.bitmap) }
}
}
#[cfg(test)]
mod test {
use super::*;
......
......@@ -25,14 +25,6 @@ low_water_mark:
.xword 0
.size low_water_mark, 8
#malloc_zero(size_t size) -> void*
# X0 X0
begin_func malloc_zero
MOV X1, X0 // X1 = size
MOV X0, #1
B calloc // tail call calloc(1, size)
end_func malloc_zero
#immmix_get_stack_ptr() -> uintptr_t
# X0
begin_func immmix_get_stack_ptr
......
......@@ -16,12 +16,6 @@
#include <stdlib.h>
#include <string.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)
......
......@@ -19,12 +19,6 @@
#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)
......
......@@ -64,11 +64,9 @@ pub fn trigger_gc() {
}
}
use std::os::raw::c_void;
#[cfg(target_arch = "x86_64")]
#[link(name = "gc_clib_x64")]
extern "C" {
pub fn malloc_zero(size: usize) -> *const c_void;
fn immmix_get_stack_ptr() -> Address;
pub fn set_low_water_mark();
fn get_low_water_mark() -> Address;
......@@ -79,7 +77,6 @@ extern "C" {
#[cfg(target_arch = "aarch64")]
#[link(name = "gc_clib_aarch64")]
extern "C" {
pub fn malloc_zero(size: usize) -> *const c_void;
fn immmix_get_stack_ptr() -> Address;
pub fn set_low_water_mark();
fn get_low_water_mark() -> Address;
......
......@@ -16,8 +16,7 @@ use heap::immix;
use heap::gc;
use utils::Address;
use common::AddressMap;
use heap::gc::malloc_zero;
use utils::mem::malloc_zero;
use utils::mem::memmap;
use utils::mem::memsec;
......@@ -118,6 +117,12 @@ impl LineMarkTable {
}
}
impl Drop for LineMarkTable {
fn drop(&mut self) {
unsafe { memsec::free(self.ptr) }
}
}
impl LineMarkTableSlice {
#[inline(always)]
pub fn get(&self, index: usize) -> immix::LineMark {
......
......@@ -182,6 +182,12 @@ pub extern "C" fn gc_init(immix_size: usize, lo_size: usize, n_gcthreads: usize,
}
}
/// destroys current GC instance
#[no_mangle]
pub extern "C" fn gc_destoy() {
*MY_GC.write().unwrap() = None;
}
/// creates a mutator
#[no_mangle]
pub extern "C" fn new_mutator() -> ImmixMutatorLocal {
......
......@@ -20,6 +20,18 @@ pub extern crate memsec;
#[allow(unused_imports)] // import both endianness (we may not use big endian though)
use byteorder::{LittleEndian, BigEndian, ReadBytesExt, WriteBytesExt, ByteOrder};
/// malloc's and zeroes the memory
pub unsafe fn malloc_zero(size: usize) -> *mut u8 {
use self::memsec;
match memsec::malloc(size) {
Some(ptr) => {
memsec::memzero(ptr, size);
ptr
}
None => panic!("failed to malloc_zero() {} bytes", size)
}
}
/// returns bit representations for u64
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
pub fn u64_to_raw(val: u64) -> u64 {
......
......@@ -202,6 +202,12 @@ macro_rules! gen_handle_int {
}
}
impl Drop for VM {
fn drop(&mut self) {
self.destroy();
}
}
impl<'a> VM {
/// creates a VM with default options
pub fn new() -> VM {
......@@ -380,6 +386,11 @@ impl<'a> VM {
}
}
/// cleans up currenet VM
fn destroy(&mut self) {
gc::gc_destoy();
}
/// adds an exception callsite and catch block
/// (later we will use this info to build an exception table for unwinding use)
pub fn add_exception_callsite(&self, callsite: Callsite, fv: MuID) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment