test_threadlocal.rs 1.44 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1
// Copyright 2017 The Australian National University
qinsoon's avatar
qinsoon committed
2
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
3 4 5
// 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
qinsoon's avatar
qinsoon committed
6
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
7
//     http://www.apache.org/licenses/LICENSE-2.0
qinsoon's avatar
qinsoon committed
8
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
9 10 11 12 13 14
// 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.

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use utils::Address;
use mu::runtime::thread;
use mu::runtime::thread::MuThread;
use mu::vm::VM;

use std::usize;
use std::sync::Arc;

#[test]
fn test_access_exception_obj() {
    let vm = Arc::new(VM::new());

    unsafe {
        MuThread::current_thread_as_mu_thread(Address::max(), vm.clone());
    }

    let cur = MuThread::current();
    println!("{}", cur);
    println!("reference = {:?}", cur as *const MuThread);

qinsoon's avatar
qinsoon committed
35
    assert_eq!(cur.exception_obj, unsafe { Address::zero() });
36 37

    // set exception obj using offset
qinsoon's avatar
qinsoon committed
38
    let tl_addr = unsafe { thread::muentry_get_thread_local() };
39
    let exc_obj_addr = tl_addr + *thread::EXCEPTION_OBJ_OFFSET;
40
    println!("storing exception obj Address::max() to {}", exc_obj_addr);
qinsoon's avatar
qinsoon committed
41
    unsafe { exc_obj_addr.store(usize::MAX) };
42 43

    println!("{}", cur);
qinsoon's avatar
qinsoon committed
44 45
    assert_eq!(cur.exception_obj, unsafe { Address::max() });
}