WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

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 54ce8e1c authored by qinsoon's avatar qinsoon
Browse files

change MuID to an opaque type

parent b12737c0
......@@ -7,12 +7,56 @@ use utils::vec_utils;
use utils::LinkedHashMap;
use std::fmt;
use std::convert;
use std::ops;
use std::default;
use std::sync::RwLock;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
pub type WPID = usize;
pub type MuID = usize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, RustcDecodable, RustcEncodable, Hash)]
pub struct MuID(pub usize);
impl fmt::Display for MuID {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "#{}", self.0)
}
}
impl convert::From<usize> for MuID {
fn from(val: usize) -> Self { MuID(val) }
}
impl convert::From<u64> for MuID {
fn from(val: u64) -> Self { MuID(val as usize) }
}
impl convert::From<u32> for MuID {
fn from(val: u32) -> Self { MuID(val as usize) }
}
impl convert::Into<usize> for MuID {
fn into(self) -> usize { self.0 }
}
impl convert::Into<u64> for MuID {
fn into(self) -> u64 { self.0 as u64 }
}
impl convert::Into<u32> for MuID {
fn into(self) -> u32 { self.0 as u32 }
}
impl ops::Add<usize> for MuID {
type Output = MuID;
fn add(self, other: usize) -> MuID {
MuID(self.0 + other)
}
}
impl ops::AddAssign<usize> for MuID {
fn add_assign(&mut self, rhs: usize) {
self.0 = self.0 + rhs;
}
}
impl MuID {
#[inline(always)]
pub fn as_num(&self) -> usize { self.0 }
}
pub type WPID = MuID;
pub type MuName = String;
pub type CName = MuName;
......@@ -26,21 +70,24 @@ pub type OpIndex = usize;
lazy_static! {
pub static ref MACHINE_ID : AtomicUsize = {
let a = ATOMIC_USIZE_INIT;
a.store(MACHINE_ID_START, Ordering::SeqCst);
a.store(MACHINE_ID_START.as_num(), Ordering::SeqCst);
a
};
pub static ref INTERNAL_ID : AtomicUsize = {
let a = ATOMIC_USIZE_INIT;
a.store(INTERNAL_ID_START, Ordering::SeqCst);
a.store(INTERNAL_ID_START.as_num(), Ordering::SeqCst);
a
};
}
pub const MACHINE_ID_START : usize = 0;
pub const MACHINE_ID_END : usize = 200;
}
pub const INVALID_MUID : MuID = MuID(0);
pub const MACHINE_ID_START : MuID = MuID(1);
pub const MACHINE_ID_END : MuID = MuID(200);
pub const INTERNAL_ID_START: usize = 201;
pub const INTERNAL_ID_END : usize = 500;
pub const USER_ID_START : usize = 1001;
pub const INTERNAL_ID_START: MuID = MuID(201);
pub const INTERNAL_ID_END : MuID = MuID(500);
pub const USER_ID_START : MuID = MuID(1001);
#[deprecated]
#[allow(dead_code)]
......@@ -49,18 +96,18 @@ pub const USER_ID_START : usize = 1001;
/// currently I hand-write fixed ID for each machine register
pub fn new_machine_id() -> MuID {
let ret = MACHINE_ID.fetch_add(1, Ordering::SeqCst);
if ret >= MACHINE_ID_END {
if ret >= MACHINE_ID_END.as_num() {
panic!("machine id overflow")
}
ret
MuID(ret)
}
pub fn new_internal_id() -> MuID {
let ret = INTERNAL_ID.fetch_add(1, Ordering::SeqCst);
if ret >= INTERNAL_ID_END {
if ret >= INTERNAL_ID_END.as_num() {
panic!("internal id overflow")
}
ret
MuID(ret)
}
#[derive(Debug, RustcEncodable, RustcDecodable)]
......@@ -1029,7 +1076,7 @@ impl Decodable for MuEntityHeader {
let name = try!(d.read_struct_field("name", 1, |d| Decodable::decode(d)));
Ok(MuEntityHeader{
id: id,
id: MuID(id),
name: RwLock::new(name)
})
})
......
......@@ -109,7 +109,7 @@ impl <'a> InstructionSelection {
name: "Instruction Selection (x64)",
backend: Box::new(ASMCodeGen::new()),
current_fv_id: 0,
current_fv_id: INVALID_MUID,
current_callsite_id: 0,
current_frame: None,
current_block: None,
......
......@@ -79,23 +79,23 @@ macro_rules! FPR {
};
}
GPR_ALIAS!(RAX_ALIAS: (0, RAX) -> EAX, AX , AL, AH);
GPR_ALIAS!(RCX_ALIAS: (5, RCX) -> ECX, CX , CL, CH);
GPR_ALIAS!(RDX_ALIAS: (10, RDX) -> EDX, DX , DL, DH);
GPR_ALIAS!(RBX_ALIAS: (15,RBX) -> EBX, BX , BL, BH);
GPR_ALIAS!(RSP_ALIAS: (20,RSP) -> ESP, SP , SPL);
GPR_ALIAS!(RBP_ALIAS: (24,RBP) -> EBP, BP , BPL);
GPR_ALIAS!(RSI_ALIAS: (28,RSI) -> ESI, SI , SIL);
GPR_ALIAS!(RDI_ALIAS: (32,RDI) -> EDI, DI , DIL);
GPR_ALIAS!(R8_ALIAS : (36,R8 ) -> R8D, R8W, R8B);
GPR_ALIAS!(R9_ALIAS : (40,R9 ) -> R9D, R9W, R9B);
GPR_ALIAS!(R10_ALIAS: (44,R10) -> R10D,R10W,R10B);
GPR_ALIAS!(R11_ALIAS: (48,R11) -> R11D,R11W,R11B);
GPR_ALIAS!(R12_ALIAS: (52,R12) -> R12D,R12W,R12B);
GPR_ALIAS!(R13_ALIAS: (56,R13) -> R13D,R13W,R13B);
GPR_ALIAS!(R14_ALIAS: (60,R14) -> R14D,R14W,R14B);
GPR_ALIAS!(R15_ALIAS: (64,R15) -> R15D,R15W,R15B);
GPR_ALIAS!(RIP_ALIAS: (68,RIP));
GPR_ALIAS!(RAX_ALIAS: (MuID(0), RAX) -> EAX, AX , AL, AH);
GPR_ALIAS!(RCX_ALIAS: (MuID(5), RCX) -> ECX, CX , CL, CH);
GPR_ALIAS!(RDX_ALIAS: (MuID(10),RDX) -> EDX, DX , DL, DH);
GPR_ALIAS!(RBX_ALIAS: (MuID(15),RBX) -> EBX, BX , BL, BH);
GPR_ALIAS!(RSP_ALIAS: (MuID(20),RSP) -> ESP, SP , SPL);
GPR_ALIAS!(RBP_ALIAS: (MuID(24),RBP) -> EBP, BP , BPL);
GPR_ALIAS!(RSI_ALIAS: (MuID(28),RSI) -> ESI, SI , SIL);
GPR_ALIAS!(RDI_ALIAS: (MuID(32),RDI) -> EDI, DI , DIL);
GPR_ALIAS!(R8_ALIAS : (MuID(36),R8 ) -> R8D, R8W, R8B);
GPR_ALIAS!(R9_ALIAS : (MuID(40),R9 ) -> R9D, R9W, R9B);
GPR_ALIAS!(R10_ALIAS: (MuID(44),R10) -> R10D,R10W,R10B);
GPR_ALIAS!(R11_ALIAS: (MuID(48),R11) -> R11D,R11W,R11B);
GPR_ALIAS!(R12_ALIAS: (MuID(52),R12) -> R12D,R12W,R12B);
GPR_ALIAS!(R13_ALIAS: (MuID(56),R13) -> R13D,R13W,R13B);
GPR_ALIAS!(R14_ALIAS: (MuID(60),R14) -> R14D,R14W,R14B);
GPR_ALIAS!(R15_ALIAS: (MuID(64),R15) -> R15D,R15W,R15B);
GPR_ALIAS!(RIP_ALIAS: (MuID(68),RIP));
lazy_static! {
pub static ref GPR_ALIAS_TABLE : LinkedHashMap<MuID, Vec<P<Value>>> = {
......@@ -270,7 +270,7 @@ lazy_static! {
];
}
pub const FPR_ID_START : usize = 100;
pub const FPR_ID_START : MuID = MuID(100);
lazy_static!{
pub static ref XMM0 : P<Value> = FPR!(FPR_ID_START, "xmm0");
......
......@@ -88,7 +88,7 @@ fn from_MuCString_optional(cstring: CMuCString) -> Option<String> {
#[inline(always)]
fn from_MuID(cmuid: CMuID) -> MuID {
debug_assert!(cmuid != 0);
cmuid as MuID // just zero extend
MuID(cmuid as usize) // just zero extend
}
#[inline(always)]
......@@ -171,7 +171,7 @@ fn from_MuID_array<'a>(ptr: *const CMuID, len: usize) -> Vec<MuID> {
let slc = from_array_direct(ptr, len);
slc.iter().map(|&e| {
debug_assert!(e != 0);
e as MuID
MuID(e as usize)
}).collect::<Vec<_>>()
}
......@@ -185,8 +185,8 @@ fn from_MuCString_array<'a>(ptr: *const CMuCString, len: usize) -> Vec<String> {
#[inline(always)]
fn to_MuID(value: MuID) -> CMuID {
debug_assert!(value <= 0xFFFFFFFFusize);
value as CMuID
debug_assert!(value.as_num() <= 0xFFFFFFFFusize);
value.as_num() as CMuID
}
#[inline(always)]
......@@ -1963,7 +1963,7 @@ extern fn _forwarder__MuIRBuilder__new_trap(b: *mut CMuIRBuilder, id: CMuID, res
extern fn _forwarder__MuIRBuilder__new_watchpoint(b: *mut CMuIRBuilder, id: CMuID, wpid: CMuWPID, result_ids: *mut CMuID, rettys: *mut CMuTypeNode, nretvals: CMuArraySize, dis: CMuDestClause, ena: CMuDestClause, exc: CMuDestClause, keepalive_clause: CMuKeepaliveClause) {
let mut _arg_b = from_MuIRBuilder_ptr(b);
let mut _arg_id = from_MuID(id);
let mut _arg_wpid = wpid;
let mut _arg_wpid = from_MuID(wpid);
let mut _arg_result_ids = from_MuID_array(result_ids, nretvals);
let mut _arg_rettys = from_MuID_array(rettys, nretvals);
let mut _arg_dis = from_MuID(dis);
......@@ -1978,7 +1978,7 @@ extern fn _forwarder__MuIRBuilder__new_watchpoint(b: *mut CMuIRBuilder, id: CMuI
extern fn _forwarder__MuIRBuilder__new_wpbranch(b: *mut CMuIRBuilder, id: CMuID, wpid: CMuWPID, dis: CMuDestClause, ena: CMuDestClause) {
let mut _arg_b = from_MuIRBuilder_ptr(b);
let mut _arg_id = from_MuID(id);
let mut _arg_wpid = wpid;
let mut _arg_wpid = from_MuID(wpid);
let mut _arg_dis = from_MuID(dis);
let mut _arg_ena = from_MuID(ena);
unsafe {
......
......@@ -502,15 +502,15 @@ impl MuIRBuilder {
});
}
pub fn new_watchpoint(&mut self, id: MuID, wpid: CMuWPID, result_ids: Vec<MuID>, rettys: Vec<MuID>, dis: MuID, ena: MuID, exc: Option<MuID>, keepalive_clause: Option<MuID>) {
pub fn new_watchpoint(&mut self, id: MuID, wpid: WPID, result_ids: Vec<MuID>, rettys: Vec<MuID>, dis: MuID, ena: MuID, exc: Option<MuID>, keepalive_clause: Option<MuID>) {
self.add_inst(id, NodeInst::NodeWatchPoint {
id: id, wpid: wpid as MuID, result_ids: result_ids, rettys: rettys, dis: dis, ena: ena, exc: exc, keepalive_clause: keepalive_clause
id: id, wpid: wpid, result_ids: result_ids, rettys: rettys, dis: dis, ena: ena, exc: exc, keepalive_clause: keepalive_clause
});
}
pub fn new_wpbranch(&mut self, id: MuID, wpid: CMuWPID, dis: MuID, ena: MuID) {
pub fn new_wpbranch(&mut self, id: MuID, wpid: WPID, dis: MuID, ena: MuID) {
self.add_inst(id, NodeInst::NodeWPBranch {
id: id, wpid: wpid as MuID, dis: dis, ena: ena
id: id, wpid: wpid, dis: dis, ena: ena
});
}
......
......@@ -452,7 +452,7 @@ impl <'a> VM {
//
// If the client needs to create client-level threads, however, the client should properly
// synchronise at the time of inter-thread communication, rather than creation of the VM.
ret.next_id.store(USER_ID_START, Ordering::Relaxed);
ret.next_id.store(USER_ID_START.as_num(), Ordering::Relaxed);
// init types
types::init_types();
......@@ -550,7 +550,7 @@ impl <'a> VM {
// This only needs to be atomic, and does not need to be a synchronisation operation. The
// only requirement for IDs is that all IDs obtained from `next_id()` are different. So
// `Ordering::Relaxed` is sufficient.
self.next_id.fetch_add(1, Ordering::Relaxed)
MuID(self.next_id.fetch_add(1, Ordering::Relaxed))
}
pub fn run_vm(&self) {
......
......@@ -6,7 +6,6 @@ use mu::ast::inst::*;
use mu::ast::op::*;
use mu::vm::*;
use mu::compiler::*;
use mu::runtime::mm::objectmodel::OBJECT_HEADER_OFFSET;
use mu::utils::LinkedHashMap;
use std::sync::Arc;
......
extern crate mu;
use self::mu::ast::ir::*;
use self::mu::ast::ir::MuEntityHeader;
use self::mu::ast::ptr::*;
use self::mu::ast::types::*;
......@@ -20,57 +21,57 @@ macro_rules! println_type (
fn create_types() -> Vec<P<MuType>> {
let mut types = vec![];
let t0 = MuType::new(0, MuType_::int(8));
let t0 = MuType::new(MuID(0), MuType_::int(8));
types.push(P(t0));
let t1 = MuType::new(1, MuType_::float());
let t1 = MuType::new(MuID(1), MuType_::float());
types.push(P(t1));
let t2 = MuType::new(2, MuType_::double());
let t2 = MuType::new(MuID(2), MuType_::double());
types.push(P(t2));
let t3 = MuType::new(3, MuType_::muref(types[0].clone()));
let t3 = MuType::new(MuID(3), MuType_::muref(types[0].clone()));
types.push(P(t3));
let t4 = MuType::new(4, MuType_::iref(types[0].clone()));
let t4 = MuType::new(MuID(4), MuType_::iref(types[0].clone()));
types.push(P(t4));
let t5 = MuType::new(5, MuType_::weakref(types[0].clone()));
let t5 = MuType::new(MuID(5), MuType_::weakref(types[0].clone()));
types.push(P(t5));
let t6 = MuType::new(6, MuType_::uptr(types[0].clone()));
let t6 = MuType::new(MuID(6), MuType_::uptr(types[0].clone()));
types.push(P(t6));
let t7 = MuType::new(7, MuType_::mustruct("MyStructTag1".to_string(), vec![types[0].clone(), types[1].clone()]));
let t7 = MuType::new(MuID(7), MuType_::mustruct("MyStructTag1".to_string(), vec![types[0].clone(), types[1].clone()]));
types.push(P(t7));
let t8 = MuType::new(8, MuType_::array(types[0].clone(), 5));
let t8 = MuType::new(MuID(8), MuType_::array(types[0].clone(), 5));
types.push(P(t8));
let t9 = MuType::new(9, MuType_::hybrid("MyHybridTag1".to_string(), vec![types[7].clone(), types[1].clone()], types[0].clone()));
let t9 = MuType::new(MuID(9), MuType_::hybrid("MyHybridTag1".to_string(), vec![types[7].clone(), types[1].clone()], types[0].clone()));
types.push(P(t9));
let t10 = MuType::new(10, MuType_::void());
let t10 = MuType::new(MuID(10), MuType_::void());
types.push(P(t10));
let t11 = MuType::new(11, MuType_::threadref());
let t11 = MuType::new(MuID(11), MuType_::threadref());
types.push(P(t11));
let t12 = MuType::new(12, MuType_::stackref());
let t12 = MuType::new(MuID(12), MuType_::stackref());
types.push(P(t12));
let t13 = MuType::new(13, MuType_::tagref64());
let t13 = MuType::new(MuID(13), MuType_::tagref64());
types.push(P(t13));
let t14 = MuType::new(14, MuType_::vector(types[0].clone(), 5));
let t14 = MuType::new(MuID(14), MuType_::vector(types[0].clone(), 5));
types.push(P(t14));
let sig = P(MuFuncSig{hdr: MuEntityHeader::unnamed(20), ret_tys: vec![types[10].clone()], arg_tys: vec![types[0].clone(), types[0].clone()]});
let sig = P(MuFuncSig{hdr: MuEntityHeader::unnamed(MuID(20)), ret_tys: vec![types[10].clone()], arg_tys: vec![types[0].clone(), types[0].clone()]});
let t15 = MuType::new(15, MuType_::funcref(sig.clone()));
let t15 = MuType::new(MuID(15), MuType_::funcref(sig.clone()));
types.push(P(t15));
let t16 = MuType::new(16, MuType_::ufuncptr(sig.clone()));
let t16 = MuType::new(MuID(16), MuType_::ufuncptr(sig.clone()));
types.push(P(t16));
types
......@@ -108,9 +109,9 @@ fn test_type_constructors() {
#[test]
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())));
let ref_ty = P(MuType::new(1, MuType_::muref(ty.clone())));
let i32_ty = P(MuType::new(2, MuType_::int(32)));
let ty = P(MuType::new(MuID(0), MuType_::mustruct_empty("MyStructTag2".to_string())));
let ref_ty = P(MuType::new(MuID(1), MuType_::muref(ty.clone())));
let i32_ty = P(MuType::new(MuID(2), MuType_::int(32)));
{
STRUCT_TAG_MAP.write().unwrap().
......@@ -134,17 +135,17 @@ fn test_is_traced() {
assert_eq!(is_traced(&types[5]), true);
assert_eq!(is_traced(&types[6]), false);
assert_eq!(is_traced(&types[7]), false);
let struct3 = MuType::new(100, MuType_::mustruct("MyStructTag3".to_string(), vec![types[3].clone(), types[0].clone()]));
let struct3 = MuType::new(MuID(100), MuType_::mustruct("MyStructTag3".to_string(), vec![types[3].clone(), types[0].clone()]));
assert_eq!(is_traced(&struct3), true);
let struct4 = MuType::new(101, MuType_::mustruct("MyStructTag4".to_string(), vec![types[3].clone(), types[4].clone()]));
let struct4 = MuType::new(MuID(101), MuType_::mustruct("MyStructTag4".to_string(), vec![types[3].clone(), types[4].clone()]));
assert_eq!(is_traced(&struct4), true);
assert_eq!(is_traced(&types[8]), false);
let ref_array = MuType::new(102, MuType_::array(types[3].clone(), 5));
let ref_array = MuType::new(MuID(102), MuType_::array(types[3].clone(), 5));
assert_eq!(is_traced(&ref_array), true);
assert_eq!(is_traced(&types[9]), false);
let fix_ref_hybrid = MuType::new(103, MuType_::hybrid("FixRefHybrid".to_string(), vec![types[3].clone(), types[0].clone()], types[0].clone()));
let fix_ref_hybrid = MuType::new(MuID(103), MuType_::hybrid("FixRefHybrid".to_string(), vec![types[3].clone(), types[0].clone()], types[0].clone()));
assert_eq!(is_traced(&fix_ref_hybrid), true);
let var_ref_hybrid = MuType::new(104, MuType_::hybrid("VarRefHybrid".to_string(), vec![types[0].clone(), types[1].clone()], types[3].clone()));
let var_ref_hybrid = MuType::new(MuID(104), MuType_::hybrid("VarRefHybrid".to_string(), vec![types[0].clone(), types[1].clone()], types[3].clone()));
assert_eq!(is_traced(&var_ref_hybrid), true);
assert_eq!(is_traced(&types[10]), false);
assert_eq!(is_traced(&types[11]), true);
......@@ -167,17 +168,22 @@ fn test_is_native_safe() {
assert_eq!(is_native_safe(&types[5]), false);
assert_eq!(is_native_safe(&types[6]), true);
assert_eq!(is_native_safe(&types[7]), true);
let struct3 = MuType::new(100, MuType_::mustruct("MyStructTag3".to_string(), vec![types[3].clone(), types[0].clone()]));
let struct3 = MuType::new(MuID(100), MuType_::mustruct("MyStructTag3".to_string(), vec![types[3].clone(), types[0].clone()]));
assert_eq!(is_native_safe(&struct3), false);
let struct4 = MuType::new(101, MuType_::mustruct("MyStructTag4".to_string(), vec![types[3].clone(), types[4].clone()]));
let struct4 = MuType::new(MuID(101), MuType_::mustruct("MyStructTag4".to_string(), vec![types[3].clone(), types[4].clone()]));
assert_eq!(is_native_safe(&struct4), false);
assert_eq!(is_native_safe(&types[8]), true);
let ref_array = MuType::new(102, MuType_::array(types[3].clone(), 5));
let ref_array = MuType::new(MuID(102), MuType_::array(types[3].clone(), 5));
assert_eq!(is_native_safe(&ref_array), false);
assert_eq!(is_native_safe(&types[9]), true);
let fix_ref_hybrid = MuType::new(103, MuType_::hybrid("FixRefHybrid".to_string(), vec![types[3].clone(), types[0].clone()], types[0].clone()));
let fix_ref_hybrid = MuType::new(MuID(103), MuType_::hybrid("FixRefHybrid".to_string(), vec![types[3].clone(), types[0].clone()], types[0].clone()));
assert_eq!(is_native_safe(&fix_ref_hybrid), false);
let var_ref_hybrid = MuType::new(104, MuType_::hybrid("VarRefHybrid".to_string(), vec![types[0].clone(), types[1].clone()], types[3].clone()));
let var_ref_hybrid = MuType::new(MuID(104), MuType_::hybrid("VarRefHybrid".to_string(), vec![types[0].clone(), types[1].clone()], types[3].clone()));
assert_eq!(is_native_safe(&var_ref_hybrid), false);
assert_eq!(is_native_safe(&types[10]), true);
assert_eq!(is_native_safe(&types[11]), false);
......
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