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
/// A registry where local variables of a function are registered and resolved.
///
/// # Note
///
/// Note that in WebAssembly function parameters are also local variables.
///
/// The locals registry efficiently registers and resolves local variables.
/// The problem is that the Wasm specification allows to encode up to `u32::MAX`
/// local variables in a small and constant space via the binary encoding.
/// Therefore we need a way to efficiently cope with this worst-case scenario
/// in order to protect the `wasmi` interpreter against exploitations.
///
/// This implementation allows to access local variables in this worst-case
/// scenario with a worst time complexity of O(log n) and space requirement
/// of O(m + n) where n is the number of registered groups of local variables
/// and m is the number of actually used local variables.
///
/// Besides that local variable usages are cached to further minimize potential
/// exploitation impact.