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
// This file is generated from ic0.txt.
// Don't manually modify it.
#[cfg(all(target_arch = "wasm32", not(feature = "wasi")))]
#[link(wasm_import_module = "ic0")]
extern "C" {
    pub fn msg_arg_data_size() -> i32;
    pub fn msg_arg_data_copy(dst: i32, offset: i32, size: i32);
    pub fn msg_caller_size() -> i32;
    pub fn msg_caller_copy(dst: i32, offset: i32, size: i32);
    pub fn msg_reject_code() -> i32;
    pub fn msg_reject_msg_size() -> i32;
    pub fn msg_reject_msg_copy(dst: i32, offset: i32, size: i32);
    pub fn msg_reply_data_append(src: i32, size: i32);
    pub fn msg_reply();
    pub fn msg_reject(src: i32, size: i32);
    pub fn msg_cycles_available() -> i64;
    pub fn msg_cycles_available128(dst: i32);
    pub fn msg_cycles_refunded() -> i64;
    pub fn msg_cycles_refunded128(dst: i32);
    pub fn msg_cycles_accept(max_amount: i64) -> i64;
    pub fn msg_cycles_accept128(max_amount_high: i64, max_amount_low: i64, dst: i32);
    pub fn canister_self_size() -> i32;
    pub fn canister_self_copy(dst: i32, offset: i32, size: i32);
    pub fn canister_cycle_balance() -> i64;
    pub fn canister_cycle_balance128(dst: i32);
    pub fn canister_status() -> i32;
    pub fn canister_version() -> i64;
    pub fn msg_method_name_size() -> i32;
    pub fn msg_method_name_copy(dst: i32, offset: i32, size: i32);
    pub fn accept_message();
    pub fn call_new(
        callee_src: i32,
        callee_size: i32,
        name_src: i32,
        name_size: i32,
        reply_fun: i32,
        reply_env: i32,
        reject_fun: i32,
        reject_env: i32,
    );
    pub fn call_on_cleanup(fun: i32, env: i32);
    pub fn call_data_append(src: i32, size: i32);
    pub fn call_cycles_add(amount: i64);
    pub fn call_cycles_add128(amount_high: i64, amount_low: i64);
    pub fn call_perform() -> i32;
    pub fn stable_size() -> i32;
    pub fn stable_grow(new_pages: i32) -> i32;
    pub fn stable_write(offset: i32, src: i32, size: i32);
    pub fn stable_read(dst: i32, offset: i32, size: i32);
    pub fn stable64_size() -> i64;
    pub fn stable64_grow(new_pages: i64) -> i64;
    pub fn stable64_write(offset: i64, src: i64, size: i64);
    pub fn stable64_read(dst: i64, offset: i64, size: i64);
    pub fn certified_data_set(src: i32, size: i32);
    pub fn data_certificate_present() -> i32;
    pub fn data_certificate_size() -> i32;
    pub fn data_certificate_copy(dst: i32, offset: i32, size: i32);
    pub fn time() -> i64;
    pub fn global_timer_set(timestamp: i64) -> i64;
    pub fn performance_counter(counter_type: i32) -> i64;
    pub fn is_controller(src: i32, size: i32) -> i32;
    pub fn debug_print(src: i32, size: i32);
    pub fn trap(src: i32, size: i32);
}

#[cfg(not(all(target_arch = "wasm32", not(feature = "wasi"))))]
#[allow(unused_variables)]
#[allow(clippy::missing_safety_doc)]
#[allow(clippy::too_many_arguments)]
mod non_wasm {
    pub unsafe fn msg_arg_data_size() -> i32 {
        panic!("msg_arg_data_size should only be called inside canisters.");
    }
    pub unsafe fn msg_arg_data_copy(dst: i32, offset: i32, size: i32) {
        panic!("msg_arg_data_copy should only be called inside canisters.");
    }
    pub unsafe fn msg_caller_size() -> i32 {
        panic!("msg_caller_size should only be called inside canisters.");
    }
    pub unsafe fn msg_caller_copy(dst: i32, offset: i32, size: i32) {
        panic!("msg_caller_copy should only be called inside canisters.");
    }
    pub unsafe fn msg_reject_code() -> i32 {
        panic!("msg_reject_code should only be called inside canisters.");
    }
    pub unsafe fn msg_reject_msg_size() -> i32 {
        panic!("msg_reject_msg_size should only be called inside canisters.");
    }
    pub unsafe fn msg_reject_msg_copy(dst: i32, offset: i32, size: i32) {
        panic!("msg_reject_msg_copy should only be called inside canisters.");
    }
    pub unsafe fn msg_reply_data_append(src: i32, size: i32) {
        panic!("msg_reply_data_append should only be called inside canisters.");
    }
    pub unsafe fn msg_reply() {
        panic!("msg_reply should only be called inside canisters.");
    }
    pub unsafe fn msg_reject(src: i32, size: i32) {
        panic!("msg_reject should only be called inside canisters.");
    }
    pub unsafe fn msg_cycles_available() -> i64 {
        panic!("msg_cycles_available should only be called inside canisters.");
    }
    pub unsafe fn msg_cycles_available128(dst: i32) {
        panic!("msg_cycles_available128 should only be called inside canisters.");
    }
    pub unsafe fn msg_cycles_refunded() -> i64 {
        panic!("msg_cycles_refunded should only be called inside canisters.");
    }
    pub unsafe fn msg_cycles_refunded128(dst: i32) {
        panic!("msg_cycles_refunded128 should only be called inside canisters.");
    }
    pub unsafe fn msg_cycles_accept(max_amount: i64) -> i64 {
        panic!("msg_cycles_accept should only be called inside canisters.");
    }
    pub unsafe fn msg_cycles_accept128(max_amount_high: i64, max_amount_low: i64, dst: i32) {
        panic!("msg_cycles_accept128 should only be called inside canisters.");
    }
    pub unsafe fn canister_self_size() -> i32 {
        panic!("canister_self_size should only be called inside canisters.");
    }
    pub unsafe fn canister_self_copy(dst: i32, offset: i32, size: i32) {
        panic!("canister_self_copy should only be called inside canisters.");
    }
    pub unsafe fn canister_cycle_balance() -> i64 {
        panic!("canister_cycle_balance should only be called inside canisters.");
    }
    pub unsafe fn canister_cycle_balance128(dst: i32) {
        panic!("canister_cycle_balance128 should only be called inside canisters.");
    }
    pub unsafe fn canister_status() -> i32 {
        panic!("canister_status should only be called inside canisters.");
    }
    pub unsafe fn canister_version() -> i64 {
        panic!("canister_version should only be called inside canisters.");
    }
    pub unsafe fn msg_method_name_size() -> i32 {
        panic!("msg_method_name_size should only be called inside canisters.");
    }
    pub unsafe fn msg_method_name_copy(dst: i32, offset: i32, size: i32) {
        panic!("msg_method_name_copy should only be called inside canisters.");
    }
    pub unsafe fn accept_message() {
        panic!("accept_message should only be called inside canisters.");
    }
    pub unsafe fn call_new(
        callee_src: i32,
        callee_size: i32,
        name_src: i32,
        name_size: i32,
        reply_fun: i32,
        reply_env: i32,
        reject_fun: i32,
        reject_env: i32,
    ) {
        panic!("call_new should only be called inside canisters.");
    }
    pub unsafe fn call_on_cleanup(fun: i32, env: i32) {
        panic!("call_on_cleanup should only be called inside canisters.");
    }
    pub unsafe fn call_data_append(src: i32, size: i32) {
        panic!("call_data_append should only be called inside canisters.");
    }
    pub unsafe fn call_cycles_add(amount: i64) {
        panic!("call_cycles_add should only be called inside canisters.");
    }
    pub unsafe fn call_cycles_add128(amount_high: i64, amount_low: i64) {
        panic!("call_cycles_add128 should only be called inside canisters.");
    }
    pub unsafe fn call_perform() -> i32 {
        panic!("call_perform should only be called inside canisters.");
    }
    pub unsafe fn stable_size() -> i32 {
        panic!("stable_size should only be called inside canisters.");
    }
    pub unsafe fn stable_grow(new_pages: i32) -> i32 {
        panic!("stable_grow should only be called inside canisters.");
    }
    pub unsafe fn stable_write(offset: i32, src: i32, size: i32) {
        panic!("stable_write should only be called inside canisters.");
    }
    pub unsafe fn stable_read(dst: i32, offset: i32, size: i32) {
        panic!("stable_read should only be called inside canisters.");
    }
    pub unsafe fn stable64_size() -> i64 {
        panic!("stable64_size should only be called inside canisters.");
    }
    pub unsafe fn stable64_grow(new_pages: i64) -> i64 {
        panic!("stable64_grow should only be called inside canisters.");
    }
    pub unsafe fn stable64_write(offset: i64, src: i64, size: i64) {
        panic!("stable64_write should only be called inside canisters.");
    }
    pub unsafe fn stable64_read(dst: i64, offset: i64, size: i64) {
        panic!("stable64_read should only be called inside canisters.");
    }
    pub unsafe fn certified_data_set(src: i32, size: i32) {
        panic!("certified_data_set should only be called inside canisters.");
    }
    pub unsafe fn data_certificate_present() -> i32 {
        panic!("data_certificate_present should only be called inside canisters.");
    }
    pub unsafe fn data_certificate_size() -> i32 {
        panic!("data_certificate_size should only be called inside canisters.");
    }
    pub unsafe fn data_certificate_copy(dst: i32, offset: i32, size: i32) {
        panic!("data_certificate_copy should only be called inside canisters.");
    }
    pub unsafe fn time() -> i64 {
        panic!("time should only be called inside canisters.");
    }
    pub unsafe fn global_timer_set(timestamp: i64) -> i64 {
        panic!("global_timer_set should only be called inside canisters.");
    }
    pub unsafe fn performance_counter(counter_type: i32) -> i64 {
        panic!("performance_counter should only be called inside canisters.");
    }
    pub unsafe fn is_controller(src: i32, size: i32) -> i32 {
        panic!("is_controller should only be called inside canisters.");
    }
    pub unsafe fn debug_print(src: i32, size: i32) {
        panic!("debug_print should only be called inside canisters.");
    }
    pub unsafe fn trap(src: i32, size: i32) {
        panic!("trap should only be called inside canisters.");
    }
}

#[cfg(not(all(target_arch = "wasm32", not(feature = "wasi"))))]
pub use non_wasm::*;