To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 5e05fd11 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano
Browse files

Changed MuName and CName to Arc<String>

parent 2e8bb439
// 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.
......
......@@ -377,7 +377,7 @@ pub fn compile_fncs<'a>(
/// gets the path for the generated code of a Mu function
fn get_path_for_mu_func(f: MuName, vm: &VM) -> PathBuf {
let mut ret = PathBuf::from(&vm.vm_options.flag_aot_emit_dir);
ret.push(f + ".S");
ret.push((*f).clone() + ".S");
ret
}
......@@ -393,7 +393,10 @@ fn get_path_for_mu_context(vm: &VM) -> PathBuf {
pub fn run_test(vm: &VM, test_name: &str, tester_name: &str) {
let output_name = test_name.to_string() + "_" + tester_name;
let executable = link_test_primordial(
vec![test_name.to_string(), tester_name.to_string()],
vec![
Arc::new(test_name.to_string()),
Arc::new(tester_name.to_string()),
],
output_name.as_str(),
vm
);
......@@ -655,9 +658,9 @@ pub fn run_test_2f(vm: &VM, test_name: &str, dep_name: &str, tester_name: &str)
let output_name = test_name.to_string() + "_" + tester_name;
let executable = link_test_primordial(
vec![
dep_name.to_string(),
test_name.to_string(),
tester_name.to_string(),
Arc::new(dep_name.to_string()),
Arc::new(test_name.to_string()),
Arc::new(tester_name.to_string()),
],
output_name.as_str(),
vm
......
This diff is collapsed.
......@@ -42,7 +42,9 @@ pub mod entrypoints;
/// exception handling
pub mod exception;
lazy_static!{
static ref UNKNOWN_FUNCTION_NAME : CName = Arc::new("UNKOWN".to_string());
}
/// returns name for a function address
// FIXME: this actually returns the name and address of the nearest symbol (of any type)
// that starts before function_addr (instead we want the nearest function symbol)
......@@ -62,14 +64,19 @@ pub fn get_function_info(function_addr: Address) -> (CName, Address) {
}
if !info.dli_sname.is_null() {
(
unsafe { CStr::from_ptr(info.dli_sname) }
.to_str()
.unwrap()
.to_string(),
Arc::new(
unsafe { CStr::from_ptr(info.dli_sname) }
.to_str()
.unwrap()
.to_string()
),
Address::from_ptr(info.dli_saddr)
)
} else {
("UNKOWN".to_string(), Address::from_ptr(info.dli_saddr))
(
UNKNOWN_FUNCTION_NAME.clone(),
Address::from_ptr(info.dli_saddr)
)
}
}
......
......@@ -24,7 +24,7 @@ crate-type = ["rlib"]
memmap = "*"
memsec = "0.1.9"
byteorder = "*"
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = ">= 0.0.5" }
rodal = { git = "https://gitlab.anu.edu.au/mu/rodal", version = ">= 0.0.10" }
#rodal = { path = "../../../rodal_test/rodal", version = ">= 0.0.5" }
log = "*"
doubly = "1.1.3"
......@@ -29,7 +29,7 @@ use std::ptr;
use std::os::raw::*;
use std::ffi::CStr;
use std::slice;
use std::sync::Arc;
use super::api_c::*;
use super::api_impl::*;
use super::deps::*;
......@@ -69,7 +69,7 @@ fn from_MuIRBuilder_ptr<'c>(ptr: *mut CMuIRBuilder) -> *mut MuIRBuilder {
#[inline(always)]
fn from_MuName(cname: CMuName) -> MuName {
from_MuCString(cname)
Arc::new(from_MuCString(cname))
}
#[inline(always)]
......@@ -89,6 +89,15 @@ fn from_MuCString_optional(cstring: CMuCString) -> Option<String> {
}
}
#[inline(always)]
fn from_MuName_optional(cstring: CMuName) -> Option<MuName> {
if cstring.is_null() {
None
} else {
Some(from_MuName(cstring))
}
}
#[inline(always)]
fn from_MuID(cmuid: CMuID) -> MuID {
debug_assert!(cmuid != 0);
......@@ -183,6 +192,13 @@ fn from_MuCString_array<'a>(ptr: *const CMuCString, len: usize) -> Vec<String> {
slc.iter().map(|&e| from_MuCString(e)).collect::<Vec<_>>()
}
#[inline(always)]
fn from_MuName_array<'a>(ptr: *const CMuName, len: usize) -> Vec<MuName> {
let slc = from_array_direct(ptr, len);
slc.iter().map(|&e| from_MuName(e)).collect::<Vec<_>>()
}
// The following functions `to_*` converts high-level types to C-like types.
#[inline(always)]
......@@ -1189,9 +1205,9 @@ extern "C" fn _forwarder__MuCtx__make_boot_image(
let mut _arg_primordial_stack = from_handle_optional(primordial_stack);
let mut _arg_primordial_threadlocal = from_handle_optional(primordial_threadlocal);
let mut _arg_sym_fields = from_handle_array(sym_fields, nsyms);
let mut _arg_sym_strings = from_MuCString_array(sym_strings, nsyms);
let mut _arg_sym_strings = from_MuName_array(sym_strings, nsyms);
let mut _arg_reloc_fields = from_handle_array(reloc_fields, nrelocs);
let mut _arg_reloc_strings = from_MuCString_array(reloc_strings, nrelocs);
let mut _arg_reloc_strings = from_MuName_array(reloc_strings, nrelocs);
let mut _arg_output_file = from_MuCString(output_file);
unsafe {
(*_arg_ctx).make_boot_image(
......@@ -1220,7 +1236,7 @@ extern "C" fn _forwarder__MuIRBuilder__abort(b: *mut CMuIRBuilder) {
extern "C" fn _forwarder__MuIRBuilder__gen_sym(b: *mut CMuIRBuilder, name: CMuCString) -> CMuID {
let mut _arg_b = from_MuIRBuilder_ptr(b);
let mut _arg_name = from_MuCString_optional(name);
let mut _arg_name = from_MuName_optional(name);
let _rv = unsafe { (*_arg_b).gen_sym(_arg_name) };
let _rv_prep = to_MuID(_rv);
_rv_prep
......@@ -1501,7 +1517,7 @@ extern "C" fn _forwarder__MuIRBuilder__new_const_extern(
let mut _arg_b = from_MuIRBuilder_ptr(b);
let mut _arg_id = from_MuID(id);
let mut _arg_ty = from_MuID(ty);
let mut _arg_symbol = from_MuCString(symbol);
let mut _arg_symbol = from_MuName(symbol);
unsafe { (*_arg_b).new_const_extern(_arg_id, _arg_ty, _arg_symbol) };
}
......
......@@ -121,7 +121,7 @@ pub enum NodeConst {
ConstExtern {
id: MuID,
ty: MuTypeNode,
symbol: String
symbol: CName
}
}
......
......@@ -517,9 +517,9 @@ impl MuCtx {
primordial_stack: Option<&APIHandle>,
primordial_threadlocal: Option<&APIHandle>,
sym_fields: Vec<&APIHandle>,
sym_strings: Vec<String>,
sym_strings: Vec<MuName>,
reloc_fields: Vec<&APIHandle>,
reloc_strings: Vec<String>,
reloc_strings: Vec<MuName>,
output_file: String
) {
self.get_mvm().vm.make_boot_image(
......
......@@ -124,7 +124,7 @@ impl MuIRBuilder {
self.deallocate();
}
pub fn gen_sym(&mut self, name: Option<String>) -> MuID {
pub fn gen_sym(&mut self, name: Option<MuName>) -> MuID {
let my_id = self.next_id();
trace!("gen_sym({:?}) -> {}", name, my_id);
......@@ -351,7 +351,7 @@ impl MuIRBuilder {
);
}
pub fn new_const_extern(&mut self, id: MuID, ty: MuID, symbol: String) {
pub fn new_const_extern(&mut self, id: MuID, ty: MuID, symbol: MuName) {
self.bundle.consts.insert(
id,
Box::new(NodeConst::ConstExtern {
......@@ -1705,13 +1705,13 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
fn ensure_name(&mut self, id: MuID, parent_id: Option<MuID>) {
let prefix = match parent_id {
Some(parent_id) => self.get_name(parent_id) + ".",
Some(parent_id) => (*self.get_name(parent_id)).clone() + ".",
None => "".to_string()
};
self.id_name_map.entry(id).or_insert_with(|| {
let name = format!("{}#{}", prefix, id);
trace!("Making name for ID {} : {}", id, name);
name
Arc::new(name)
});
}
......@@ -1830,11 +1830,11 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
}
}
fn get_name(&self, id: MuID) -> String {
fn get_name(&self, id: MuID) -> MuName {
self.id_name_map.get(&id).unwrap().clone()
}
fn maybe_get_name(&self, id: MuID) -> Option<String> {
fn maybe_get_name(&self, id: MuID) -> Option<MuName> {
self.id_name_map.get(&id).cloned()
}
......@@ -2183,7 +2183,7 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
let hdr = self.make_mu_entity_header(id);
let impl_ty = self.ensure_type_rec(global.ty); // global type
assert_ir!(!impl_ty.is_hybrid( ));
assert_ir!(!impl_ty.is_hybrid());
let impl_val = Value {
hdr: hdr,
ty: self.ensure_iref(impl_ty.id()), // iref to global
......
......@@ -80,7 +80,7 @@ impl MuVM {
let cname = map.entry(id).or_insert_with(|| {
let rustname = self.vm.name_of(id);
CString::new(rustname).unwrap()
CString::new((*rustname).clone()).unwrap()
});
cname.as_ptr()
......
......@@ -515,7 +515,7 @@ impl<'a> VM {
/// due to removal of some special symbols in the MuName. See name_check() in ir.rs
pub fn id_of(&self, name: &str) -> MuID {
let map = self.name_id_map.read().unwrap();
match map.get(name) {
match map.get(&name.to_string()) {
Some(id) => *id,
None => panic!("cannot find id for name: {}", name)
}
......@@ -572,7 +572,7 @@ impl<'a> VM {
let id = val.id();
let name = format!("CONST_{}_{}", id, val.name());
ValueLocation::Relocatable(backend::RegGroup::GPR, name)
ValueLocation::Relocatable(backend::RegGroup::GPR, Arc::new(name))
}
/// declares a global
......@@ -1073,9 +1073,9 @@ impl<'a> VM {
primordial_stack: Option<&APIHandle>,
primordial_threadlocal: Option<&APIHandle>,
sym_fields: Vec<&APIHandle>,
sym_strings: Vec<String>,
sym_strings: Vec<MuName>,
reloc_fields: Vec<&APIHandle>,
reloc_strings: Vec<String>,
reloc_strings: Vec<MuName>,
output_file: String
) {
self.make_boot_image_internal(
......@@ -1103,9 +1103,9 @@ impl<'a> VM {
primordial_stack: Option<&APIHandle>,
primordial_threadlocal: Option<&APIHandle>,
sym_fields: Vec<&APIHandle>,
sym_strings: Vec<String>,
sym_strings: Vec<MuName>,
reloc_fields: Vec<&APIHandle>,
reloc_strings: Vec<String>,
reloc_strings: Vec<MuName>,
extra_sources_to_link: Vec<String>,
output_file: String
) {
......
......@@ -55,7 +55,11 @@ fn test_ccall_exit() {
vm.set_primordial_thread(func_id, true, vec![]);
backend::emit_context(&vm);
let executable = aot::link_primordial(vec!["ccall_exit".to_string()], "ccall_exit_test", &vm);
let executable = aot::link_primordial(
vec![Arc::new("ccall_exit".to_string())],
"ccall_exit_test",
&vm
);
let output = linkutils::exec_path_nocheck(executable);
assert!(output.status.code().is_some());
......
......@@ -366,8 +366,11 @@ fn test_struct() {
vm.set_primordial_thread(func_id, true, vec![]);
backend::emit_context(&vm);
let executable =
aot::link_primordial(vec!["struct_insts".to_string()], "struct_insts_test", &vm);
let executable = aot::link_primordial(
vec![Arc::new("struct_insts".to_string())],
"struct_insts_test",
&vm
);
let output = linkutils::exec_path_nocheck(executable);
assert!(output.status.code().is_some());
......@@ -628,7 +631,7 @@ fn test_hybrid_fix_part() {
backend::emit_context(&vm);
let executable = aot::link_primordial(
vec!["hybrid_fix_part_insts".to_string()],
vec![Arc::new("hybrid_fix_part_insts".to_string())],
"hybrid_fix_part_insts_test",
&vm
);
......@@ -793,7 +796,7 @@ fn test_hybrid_var_part() {
backend::emit_context(&vm);
let executable = aot::link_primordial(
vec!["hybrid_var_part_insts".to_string()],
vec![Arc::new("hybrid_var_part_insts".to_string())],
"hybrid_var_part_insts_test",
&vm
);
......
......@@ -55,7 +55,7 @@ fn test_thread_create() {
backend::emit_context(&vm);
let executable = aot::link_primordial(
vec!["primordial_main".to_string()],
vec![Arc::new("primordial_main".to_string())],
"primordial_main_test",
&vm
);
......
......@@ -17,6 +17,7 @@ extern crate mu;
use self::mu::ast::ir::MuEntityHeader;
use self::mu::ast::ptr::*;
use self::mu::ast::types::*;
use std::sync::Arc;
macro_rules! assert_type (
($test:expr, $expect: expr) => (
......@@ -52,7 +53,7 @@ fn create_types() -> Vec<P<MuType>> {
let t7 = MuType::new(
7,
MuType_::mustruct(
"MyStructTag1".to_string(),
Arc::new("MyStructTag1".to_string()),
vec![types[0].clone(), types[1].clone()]
)
);
......@@ -64,7 +65,7 @@ fn create_types() -> Vec<P<MuType>> {
let t9 = MuType::new(
9,
MuType_::hybrid(
"MyHybridTag1".to_string(),
Arc::new("MyHybridTag1".to_string()),
vec![types[7].clone(), types[1].clone()],
types[0].clone()
)
......@@ -116,7 +117,7 @@ fn test_type_constructors() {
assert_type!(*types[7], "MyStructTag1(struct)");
{
let map = STRUCT_TAG_MAP.read().unwrap();
let t7_struct_ty = map.get("MyStructTag1").unwrap();
let t7_struct_ty = map.get(&"MyStructTag1".to_string()).unwrap();
assert_type!(t7_struct_ty, "struct<int<8> float>");
}
assert_type!(*types[8], "array<int<8> 5>");
......@@ -135,7 +136,7 @@ fn test_cyclic_struct() {
// .typedef @cyclic_struct_ty = struct<ref<@cyclic_struct_ty> int<32>>
let ty = P(MuType::new(
0,
MuType_::mustruct_empty("MyStructTag2".to_string())
MuType_::mustruct_empty(Arc::new("MyStructTag2".to_string()))
));
let ref_ty = P(MuType::new(1, MuType_::muref(ty.clone())));
let i32_ty = P(MuType::new(2, MuType_::int(32)));
......@@ -144,13 +145,13 @@ fn test_cyclic_struct() {
STRUCT_TAG_MAP
.write()
.unwrap()
.get_mut("MyStructTag2")
.get_mut(&"MyStructTag2".to_string())
.unwrap()
.set_tys(vec![ref_ty.clone(), i32_ty.clone()]);
}
let map = STRUCT_TAG_MAP.read().unwrap();
let struct_ty = map.get("MyStructTag2").unwrap();
let struct_ty = map.get(&"MyStructTag2".to_string()).unwrap();
assert_type!(struct_ty, "struct<ref<MyStructTag2(struct)> int<32>>");
}
......@@ -169,7 +170,7 @@ fn test_is_traced() {
let struct3 = MuType::new(
100,
MuType_::mustruct(
"MyStructTag3".to_string(),
Arc::new("MyStructTag3".to_string()),
vec![types[3].clone(), types[0].clone()]
)
);
......@@ -177,7 +178,7 @@ fn test_is_traced() {
let struct4 = MuType::new(
101,
MuType_::mustruct(
"MyStructTag4".to_string(),
Arc::new("MyStructTag4".to_string()),
vec![types[3].clone(), types[4].clone()]
)
);
......@@ -189,7 +190,7 @@ fn test_is_traced() {
let fix_ref_hybrid = MuType::new(
103,
MuType_::hybrid(
"FixRefHybrid".to_string(),
Arc::new("FixRefHybrid".to_string()),
vec![types[3].clone(), types[0].clone()],
types[0].clone()
)
......@@ -198,7 +199,7 @@ fn test_is_traced() {
let var_ref_hybrid = MuType::new(
104,
MuType_::hybrid(
"VarRefHybrid".to_string(),
Arc::new("VarRefHybrid".to_string()),
vec![types[0].clone(), types[1].clone()],
types[3].clone()
)
......@@ -228,7 +229,7 @@ fn test_is_native_safe() {
let struct3 = MuType::new(
100,
MuType_::mustruct(
"MyStructTag3".to_string(),
Arc::new("MyStructTag3".to_string()),
vec![types[3].clone(), types[0].clone()]
)
);
......@@ -236,7 +237,7 @@ fn test_is_native_safe() {
let struct4 = MuType::new(
101,
MuType_::mustruct(
"MyStructTag4".to_string(),
Arc::new("MyStructTag4".to_string()),
vec![types[3].clone(), types[4].clone()]
)
);
......@@ -248,7 +249,7 @@ fn test_is_native_safe() {
let fix_ref_hybrid = MuType::new(
103,
MuType_::hybrid(
"FixRefHybrid".to_string(),
Arc::new("FixRefHybrid".to_string()),
vec![types[3].clone(), types[0].clone()],
types[0].clone()
)
......@@ -257,7 +258,7 @@ fn test_is_native_safe() {
let var_ref_hybrid = MuType::new(
104,
MuType_::hybrid(
"VarRefHybrid".to_string(),
Arc::new("VarRefHybrid".to_string()),
vec![types[0].clone(), types[1].clone()],
types[3].clone()
)
......
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