1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#![allow(dead_code)]
use crate::context::Bits::{SixtyFour, ThirtyTwo};
use crate::context::Endianness::Little;
use std::cell::RefCell;
#[derive(Copy, Clone, Debug, PartialEq)]
#[allow(missing_docs)]
pub enum Endianness {
Little,
Big,
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum Bits {
Eight = 8,
Sixteen = 16,
ThirtyTwo = 32,
SixtyFour = 64,
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[allow(missing_docs)]
pub struct Arch {
pub endian: Endianness,
pub bits: Bits,
}
pub const AMD64: Arch = Arch {
endian: Little,
bits: SixtyFour,
};
pub const I386: Arch = Arch {
endian: Little,
bits: ThirtyTwo,
};
#[derive(Copy, Clone, Debug, PartialEq)]
#[allow(missing_docs)]
pub struct Context {
arch: Arch,
}
impl Default for Context {
fn default() -> Self {
Self { arch: I386 }
}
}
thread_local! {
static CONTEXT: RefCell<Context> = Default::default();
}
pub fn set_arch(a: Arch) {
CONTEXT.with(|c| c.borrow_mut().arch = a)
}
pub fn set_endianess(e: Endianness) {
CONTEXT.with(|c| c.borrow_mut().arch.endian = e)
}
pub fn set_bits(b: Bits) {
CONTEXT.with(|c| c.borrow_mut().arch.bits = b)
}
pub fn get_arch() -> Arch {
CONTEXT.with(|c| c.borrow().arch)
}
pub fn get_endianess() -> Endianness {
CONTEXT.with(|c| c.borrow().arch.endian)
}
pub fn get_bits() -> Bits {
CONTEXT.with(|c| c.borrow().arch.bits)
}