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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#[cfg(windows)]
use unreachable::UncheckedOptionExt;
pub use std::os::raw::{c_int, c_void, c_uint, c_char, c_uchar, c_ulong, c_long, c_double};
use std::os;
#[allow(non_camel_case_types)]
pub type size_t = usize;
use std::option::Option;
#[allow(non_camel_case_types)]
pub type ERL_NIF_UINT = size_t;
#[allow(non_camel_case_types)]
pub type ERL_NIF_TERM = ERL_NIF_UINT;
#[derive(Debug)]
#[allow(missing_copy_implementations)]
#[repr(C)]
pub struct ErlNifEnv {
dummy: *mut c_void,
}
unsafe impl Send for ErlNifEnv {}
#[repr(C)]
pub struct ErlNifFunc {
pub name: *const u8,
pub arity: c_uint,
pub function: unsafe extern "C" fn(env: *mut ErlNifEnv, argc: c_int, argv: *const ERL_NIF_TERM) -> ERL_NIF_TERM,
pub flags: c_uint,
}
#[doc(hidden)]
#[derive(Debug)]
#[repr(C)]
#[allow(non_snake_case)]
pub struct ErlNifEntry {
pub major: c_int,
pub minor: c_int,
pub name: *const u8,
pub num_of_funcs: c_int,
pub funcs: *const ErlNifFunc,
pub load: Option<unsafe extern "C" fn(env: *mut ErlNifEnv, priv_data: *mut *mut c_void, load_info: ERL_NIF_TERM)-> c_int>,
pub reload: Option<unsafe extern "C" fn(env: *mut ErlNifEnv, priv_data: *mut *mut c_void, load_info: ERL_NIF_TERM) -> c_int>,
pub upgrade: Option<unsafe extern "C" fn(env: *mut ErlNifEnv, priv_data: *mut *mut c_void, old_priv_data: *mut *mut c_void, load_info: ERL_NIF_TERM) -> c_int>,
pub unload: Option<unsafe extern "C" fn(env: *mut ErlNifEnv, priv_data: *mut c_void) -> ()>,
pub vm_variant: *const u8,
pub options: c_uint,
pub sizeof_ErlNifResourceTypeInit: usize,
}
pub const ERL_NIF_DIRTY_NIF_OPTION: c_uint = 1;
#[allow(missing_copy_implementations)]
#[derive(Debug)]
#[repr(C)]
pub struct ErlNifBinary {
pub size: size_t,
pub data: *mut u8,
bin_term: ERL_NIF_TERM,
ref_bin: *mut c_void,
}
#[cfg(windows)]
pub type ErlNifEvent = os::windows::raw::HANDLE;
#[cfg(unix)]
pub type ErlNifEvent = os::unix::io::RawFd;
#[allow(missing_copy_implementations)]
#[repr(C)]
pub struct ErlNifResourceType {dummy:c_int}
#[allow(missing_copy_implementations)]
pub type ErlNifResourceDtor = unsafe extern "C" fn(env: *mut ErlNifEnv, obj: *mut c_void) -> ();
#[allow(missing_copy_implementations)]
pub type ErlNifResourceStop = unsafe extern "C" fn(env: *mut ErlNifEnv, obj: *mut c_void, event: ErlNifEvent, is_direct_call: c_int ) -> ();
#[allow(missing_copy_implementations)]
pub type ErlNifResourceDown = unsafe extern "C" fn(env: *mut ErlNifEnv, obj: *mut c_void, pid: *const ErlNifPid, mon: *const ErlNifMonitor) -> ();
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct ErlNifResourceTypeInit {
dtor: *const ErlNifResourceDtor,
stop: *const ErlNifResourceStop,
down: *const ErlNifResourceDown,
}
pub type ErlNifSelectFlags = c_int;
pub const ERL_NIF_SELECT_READ: ErlNifSelectFlags = (1 << 0);
pub const ERL_NIF_SELECT_WRITE: ErlNifSelectFlags = (1 << 1);
pub const ERL_NIF_SELECT_STOP: ErlNifSelectFlags = (1 << 2);
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct ErlNifMonitor {
data: [usize; 4],
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub enum ErlNifResourceFlags {
ERL_NIF_RT_CREATE = 1,
ERL_NIF_RT_TAKEOVER = 2,
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub enum ErlNifCharEncoding {
ERL_NIF_LATIN1 = 1,
DUMMY = 999,
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct ErlNifPid {
pid: ERL_NIF_TERM,
}
pub unsafe fn enif_make_pid(_env: *mut ErlNifEnv, pid: & ErlNifPid) -> ERL_NIF_TERM {
pid.pid
}
#[allow(missing_copy_implementations)]
#[repr(C)]
pub struct ErlNifSysInfo {
pub driver_major_version: c_int,
pub driver_minor_version: c_int,
pub erts_version: *mut c_char,
pub otp_release: *mut c_char,
pub thread_support: c_int,
pub smp_support: c_int,
pub async_threads: c_int,
pub scheduler_threads: c_int,
pub nif_major_version: c_int,
pub nif_minor_version: c_int,
pub dirty_scheduler_support: c_int,
}
pub type ErlNifDirtyTaskFlags = c_uint;
pub const ERL_NIF_DIRTY_JOB_CPU_BOUND: ErlNifDirtyTaskFlags = 1;
pub const ERL_NIF_DIRTY_JOB_IO_BOUND: ErlNifDirtyTaskFlags = 2;
#[allow(missing_copy_implementations)]
#[repr(C)]
pub struct ErlNifMapIterator {
map: ERL_NIF_TERM,
t_limit: ERL_NIF_UINT,
idx: ERL_NIF_UINT,
ks: *mut ERL_NIF_TERM,
vs: *mut ERL_NIF_TERM,
__spare__: [*mut c_void; 2],
}
#[derive(Copy, Clone)]
#[repr(C)]
pub enum ErlNifMapIteratorEntry {
ERL_NIF_MAP_ITERATOR_HEAD = 1,
ERL_NIF_MAP_ITERATOR_TAIL = 2,
}
pub type ErlNifTime = i64;
pub const ERL_NIF_TIME_ERROR: i64 = -9223372036854775808;
#[derive(Copy, Clone)]
#[repr(C)]
pub enum ErlNifTimeUnit {
ERL_NIF_SEC = 0,
ERL_NIF_MSEC = 1,
ERL_NIF_USEC = 2,
ERL_NIF_NSEC = 3,
}
pub type ErlNifUniqueInteger = c_int;
pub const ERL_NIF_UNIQUE_POSITIVE: ErlNifUniqueInteger = (1 << 0);
pub const ERL_NIF_UNIQUE_MONOTONIC: ErlNifUniqueInteger = (1 << 1);
#[derive(Copy, Clone)]
#[repr(C)]
pub struct ErlNifPort {
port_id: ERL_NIF_TERM,
}
pub type ErlNifBinaryToTerm = c_int;
pub const ERL_NIF_BIN2TERM_SAFE: ErlNifBinaryToTerm = 0x20000000;
pub const ERL_NIF_THR_UNDEFINED: c_int = 0;
pub const ERL_NIF_THR_NORMAL_SCHEDULER: c_int = 1;
pub const ERL_NIF_THR_DIRTY_CPU_SCHEDULER: c_int = 2;
pub const ERL_NIF_THR_DIRTY_IO_SCHEDULER: c_int = 3;
#[derive(Copy, Clone)]
#[repr(C)]
pub enum ErlNifHash {
ERL_NIF_INTERNAL_HASH = 1,
ERL_NIF_PHASH2 = 2,
}
include!(concat!(env!("OUT_DIR"), "/nif_api.snippet"));