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