1use crate::MemoryError;
2use crate::{LinearMemory, Table};
3use crate::{MemoryStyle, TableStyle};
4use crate::{VMMemoryDefinition, VMTableDefinition};
5use near_vm_types::{MemoryType, TableType};
6use std::ptr::NonNull;
7use std::sync::Arc;
8
9pub trait Tunables: Sync {
12 fn memory_style(&self, memory: &MemoryType) -> MemoryStyle;
14
15 fn table_style(&self, table: &TableType) -> TableStyle;
17
18 fn create_host_memory(
20 &self,
21 ty: &MemoryType,
22 style: &MemoryStyle,
23 ) -> Result<Arc<LinearMemory>, MemoryError>;
24
25 unsafe fn create_vm_memory(
30 &self,
31 ty: &MemoryType,
32 style: &MemoryStyle,
33 vm_definition_location: NonNull<VMMemoryDefinition>,
34 ) -> Result<Arc<LinearMemory>, MemoryError>;
35
36 fn create_host_table(
38 &self,
39 ty: &TableType,
40 style: &TableStyle,
41 ) -> Result<Arc<dyn Table>, String>;
42
43 unsafe fn create_vm_table(
48 &self,
49 ty: &TableType,
50 style: &TableStyle,
51 vm_definition_location: NonNull<VMTableDefinition>,
52 ) -> Result<Arc<dyn Table>, String>;
53
54 fn stack_limiter_cfg(&self) -> Box<dyn finite_wasm::max_stack::SizeConfig>;
56
57 fn gas_cfg(&self) -> Box<dyn finite_wasm::wasmparser::VisitOperator<Output = u64>>;
59
60 fn stack_init_gas_cost(&self, frame_size: u64) -> u64;
62}
63
64#[doc(hidden)]
65pub struct TestTunables;
66
67impl Tunables for TestTunables {
68 fn memory_style(&self, _memory: &MemoryType) -> MemoryStyle {
69 unimplemented!()
70 }
71
72 fn table_style(&self, _table: &TableType) -> TableStyle {
73 unimplemented!()
74 }
75
76 fn create_host_memory(
77 &self,
78 _ty: &MemoryType,
79 _style: &MemoryStyle,
80 ) -> Result<Arc<LinearMemory>, MemoryError> {
81 unimplemented!()
82 }
83
84 unsafe fn create_vm_memory(
85 &self,
86 _ty: &MemoryType,
87 _style: &MemoryStyle,
88 _vm_definition_location: NonNull<VMMemoryDefinition>,
89 ) -> Result<Arc<LinearMemory>, MemoryError> {
90 unimplemented!()
91 }
92
93 fn create_host_table(
94 &self,
95 _ty: &TableType,
96 _style: &TableStyle,
97 ) -> Result<Arc<dyn Table>, String> {
98 unimplemented!()
99 }
100
101 unsafe fn create_vm_table(
102 &self,
103 _ty: &TableType,
104 _style: &TableStyle,
105 _vm_definition_location: NonNull<VMTableDefinition>,
106 ) -> Result<Arc<dyn Table>, String> {
107 unimplemented!()
108 }
109
110 fn stack_limiter_cfg(&self) -> Box<dyn finite_wasm::max_stack::SizeConfig> {
111 unimplemented!()
112 }
113
114 fn gas_cfg(&self) -> Box<dyn finite_wasm::wasmparser::VisitOperator<Output = u64>> {
115 unimplemented!()
116 }
117
118 fn stack_init_gas_cost(&self, _frame_size: u64) -> u64 {
119 unimplemented!()
120 }
121}