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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use crate::raw::functions;
macro_rules! impl_export {
($name:ident) => {
pub struct $name;
impl Export for $name {
type Output = functions::$name;
const OFFSET: isize = Exports::$name as isize;
#[inline(always)]
fn from_table(fn_table: usize) -> Self::Output {
let table = fn_table as *const usize;
unsafe {
let ptr = table.offset(Self::OFFSET);
(ptr as *const Self::Output).read()
}
}
}
};
}
pub trait Export {
type Output;
const OFFSET: isize;
fn from_table(fn_table: usize) -> Self::Output;
}
impl_export!(Align16);
impl_export!(Align32);
impl_export!(Allot);
impl_export!(Callback);
impl_export!(Cleanup);
impl_export!(Clone);
impl_export!(Exec);
impl_export!(FindNative);
impl_export!(FindPublic);
impl_export!(FindPubVar);
impl_export!(FindTagId);
impl_export!(Flags);
impl_export!(GetAddr);
impl_export!(GetNative);
impl_export!(GetPublic);
impl_export!(GetPubVar);
impl_export!(GetString);
impl_export!(GetTag);
impl_export!(GetUserData);
impl_export!(Init);
impl_export!(InitJIT);
impl_export!(MemInfo);
impl_export!(NameLength);
impl_export!(NativeInfo);
impl_export!(NumNatives);
impl_export!(NumPublics);
impl_export!(NumPubVars);
impl_export!(NumTags);
impl_export!(Push);
impl_export!(PushArray);
impl_export!(PushString);
impl_export!(RaiseError);
impl_export!(Register);
impl_export!(Release);
impl_export!(SetCallback);
impl_export!(SetDebugHook);
impl_export!(SetString);
impl_export!(SetUserData);
impl_export!(StrLen);
impl_export!(UTF8Check);
impl_export!(UTF8Get);
impl_export!(UTF8Len);
impl_export!(UTF8Put);
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Exports {
Align16 = 0,
Align32 = 1,
Align64 = 2,
Allot = 3,
Callback = 4,
Cleanup = 5,
Clone = 6,
Exec = 7,
FindNative = 8,
FindPublic = 9,
FindPubVar = 10,
FindTagId = 11,
Flags = 12,
GetAddr = 13,
GetNative = 14,
GetPublic = 15,
GetPubVar = 16,
GetString = 17,
GetTag = 18,
GetUserData = 19,
Init = 20,
InitJIT = 21,
MemInfo = 22,
NameLength = 23,
NativeInfo = 24,
NumNatives = 25,
NumPublics = 26,
NumPubVars = 27,
NumTags = 28,
Push = 29,
PushArray = 30,
PushString = 31,
RaiseError = 32,
Register = 33,
Release = 34,
SetCallback = 35,
SetDebugHook = 36,
SetString = 37,
SetUserData = 38,
StrLen = 39,
UTF8Check = 40,
UTF8Get = 41,
UTF8Len = 42,
UTF8Put = 43,
}
impl From<Exports> for isize {
fn from(exports: Exports) -> isize {
exports as isize
}
}