gsys/
lib.rs

1// This file is part of Gear.
2
3// Copyright (C) 2022-2025 Gear Technologies Inc.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Declares gear protocol syscalls for WASM.
20
21#![no_std]
22
23/// Represents error code type.
24pub type ErrorCode = u32;
25
26/// Represents block number type.
27pub type BlockNumber = u32;
28
29/// Represents block count type.
30pub type BlockCount = u32;
31
32/// Represents block number type.
33pub type BlockTimestamp = u64;
34
35/// Represents byte type, which is a start of a buffer.
36pub type BufferStart = u8;
37
38/// Represents byte type, which is a start of a sized buffer.
39///
40/// This usually goes along with `Length` param.`
41pub type SizedBufferStart = u8;
42
43/// Represents gas type.
44pub type Gas = u64;
45
46/// Represents handle type.
47pub type Handle = u32;
48
49/// Represents hash type.
50pub type Hash = [u8; 32];
51
52/// Represents offset type.
53pub type Offset = u32;
54
55/// Represents length type.
56pub type Length = u32;
57
58/// Represents reply code type.
59pub type ReplyCode = [u8; 4];
60
61/// Represents signal code type.
62pub type SignalCode = u32;
63
64/// Represents value type.
65pub type Value = u128;
66
67/// Represents type defining concatenated block number with hash. 36 bytes.
68#[repr(C, packed)]
69#[derive(Default, Debug)]
70pub struct BlockNumberWithHash {
71    pub bn: BlockNumber,
72    pub hash: Hash,
73}
74
75impl BlockNumberWithHash {
76    pub fn as_mut_ptr(&mut self) -> *mut Self {
77        self as _
78    }
79}
80
81/// Represents type defining concatenated hash with value. 48 bytes.
82#[repr(C, packed)]
83#[derive(Default, Debug, Clone)]
84pub struct HashWithValue {
85    pub hash: Hash,
86    pub value: Value,
87}
88
89impl HashWithValue {
90    pub const fn as_ptr(&self) -> *const Self {
91        self as _
92    }
93}
94
95/// Represents type defining concatenated reply code with error code. 8 bytes.
96#[repr(C, packed)]
97#[derive(Default, Debug)]
98pub struct ErrorWithReplyCode {
99    pub error_code: ErrorCode,
100    pub reply_code: ReplyCode,
101}
102
103impl ErrorWithReplyCode {
104    pub fn as_mut_ptr(&mut self) -> *mut Self {
105        self as _
106    }
107}
108
109impl From<Result<ReplyCode, ErrorCode>> for ErrorWithReplyCode {
110    fn from(result: Result<ReplyCode, ErrorCode>) -> Self {
111        let mut res: Self = Default::default();
112
113        match result {
114            Ok(code) => res.reply_code = code,
115            Err(length) => res.error_code = length,
116        }
117
118        res
119    }
120}
121
122/// Represents type defining concatenated signal code with length. 8 bytes.
123#[repr(C, packed)]
124#[derive(Default, Debug)]
125pub struct ErrorWithSignalCode {
126    pub error_code: ErrorCode,
127    pub signal_code: SignalCode,
128}
129
130impl ErrorWithSignalCode {
131    pub fn as_mut_ptr(&mut self) -> *mut Self {
132        self as _
133    }
134}
135
136impl From<Result<SignalCode, ErrorCode>> for ErrorWithSignalCode {
137    fn from(result: Result<SignalCode, ErrorCode>) -> Self {
138        let mut res: Self = Default::default();
139
140        match result {
141            Ok(code) => res.signal_code = code,
142            Err(code) => res.error_code = code,
143        }
144
145        res
146    }
147}
148
149/// Represents type defining concatenated error code with gas. 12 bytes.
150#[repr(C, packed)]
151#[derive(Default, Debug)]
152pub struct ErrorWithGas {
153    pub error_code: ErrorCode,
154    pub gas: Gas,
155}
156
157impl ErrorWithGas {
158    pub fn as_mut_ptr(&mut self) -> *mut Self {
159        self as _
160    }
161}
162
163impl From<Result<Gas, ErrorCode>> for ErrorWithGas {
164    fn from(result: Result<Gas, ErrorCode>) -> Self {
165        let mut res: Self = Default::default();
166
167        match result {
168            Ok(gas) => res.gas = gas,
169            Err(code) => res.error_code = code,
170        }
171
172        res
173    }
174}
175
176/// Represents type defining concatenated length with handle. 8 bytes.
177#[repr(C, packed)]
178#[derive(Default, Debug)]
179pub struct ErrorWithHandle {
180    pub error_code: ErrorCode,
181    pub handle: Handle,
182}
183
184impl ErrorWithHandle {
185    pub fn as_mut_ptr(&mut self) -> *mut Self {
186        self as _
187    }
188}
189
190impl From<Result<Handle, ErrorCode>> for ErrorWithHandle {
191    fn from(result: Result<Handle, ErrorCode>) -> Self {
192        let mut res: Self = Default::default();
193
194        match result {
195            Ok(handle) => res.handle = handle,
196            Err(code) => res.error_code = code,
197        }
198
199        res
200    }
201}
202
203#[repr(C, packed)]
204#[derive(Default, Debug)]
205pub struct ErrorBytes([u8; size_of::<ErrorCode>()]);
206
207impl From<Result<(), ErrorCode>> for ErrorBytes {
208    fn from(value: Result<(), ErrorCode>) -> Self {
209        Self(value.err().unwrap_or_default().to_le_bytes())
210    }
211}
212
213/// Represents type defining concatenated hash with error code. 36 bytes.
214#[repr(C, packed)]
215#[derive(Default, Debug)]
216pub struct ErrorWithHash {
217    pub error_code: ErrorCode,
218    pub hash: Hash,
219}
220
221impl ErrorWithHash {
222    pub fn as_mut_ptr(&mut self) -> *mut Self {
223        self as _
224    }
225}
226
227impl<T: Into<[u8; 32]>> From<Result<T, ErrorCode>> for ErrorWithHash {
228    fn from(result: Result<T, ErrorCode>) -> Self {
229        let mut res: Self = Default::default();
230
231        match result {
232            Ok(v) => res.hash = v.into(),
233            Err(code) => res.error_code = code,
234        }
235
236        res
237    }
238}
239
240/// Represents type defining concatenated two hashes with error code. 68 bytes.
241#[repr(C, packed)]
242#[derive(Default, Debug)]
243pub struct ErrorWithTwoHashes {
244    pub error_code: ErrorCode,
245    pub hash1: Hash,
246    pub hash2: Hash,
247}
248
249impl ErrorWithTwoHashes {
250    pub fn as_mut_ptr(&mut self) -> *mut Self {
251        self as _
252    }
253}
254
255impl<T1, T2> From<Result<(T1, T2), ErrorCode>> for ErrorWithTwoHashes
256where
257    T1: Into<[u8; 32]>,
258    T2: Into<[u8; 32]>,
259{
260    fn from(result: Result<(T1, T2), ErrorCode>) -> Self {
261        let mut res: Self = Default::default();
262
263        match result {
264            Ok((v1, v2)) => {
265                res.hash1 = v1.into();
266                res.hash2 = v2.into();
267            }
268            Err(code) => res.error_code = code,
269        }
270
271        res
272    }
273}
274
275/// Represents type defining concatenated two hashes. 64 bytes.
276#[repr(C, packed)]
277#[derive(Default, Debug)]
278pub struct TwoHashes {
279    pub hash1: Hash,
280    pub hash2: Hash,
281}
282
283impl TwoHashes {
284    pub const fn as_ptr(&self) -> *const Self {
285        self as _
286    }
287}
288
289/// Represents type defining concatenated two hashes with value. 80 bytes.
290#[repr(C, packed)]
291#[derive(Default, Debug)]
292pub struct TwoHashesWithValue {
293    pub hash1: Hash,
294    pub hash2: Hash,
295    pub value: Value,
296}
297
298impl TwoHashesWithValue {
299    pub const fn as_ptr(&self) -> *const Self {
300        self as _
301    }
302}
303
304/// Current version of execution settings.
305///
306/// Backend maintains backward compatibility with previous versions of execution
307/// settings. This structure matches to the most recent version of execution
308/// settings supported by backend.
309#[repr(C, packed)]
310#[derive(Debug, Clone, Copy)]
311pub struct EnvVars {
312    /// Current performance multiplier.
313    pub performance_multiplier: Percent,
314    /// Current value of existential deposit.
315    pub existential_deposit: Value,
316    /// Current value of mailbox threshold.
317    pub mailbox_threshold: Gas,
318    /// Current gas multiplier.
319    pub gas_multiplier: GasMultiplier,
320}
321
322/// Basic struct for working with integer percentages allowing
323/// values greater than 100.
324// This is a "copy-paste" of the similar struct from the `core` crate
325// which can't be used here due to its dependencies from codec and TypeInfo.
326#[repr(C, packed)]
327#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
328pub struct Percent(u32);
329
330impl Percent {
331    pub fn new(value: u32) -> Self {
332        Self(value)
333    }
334
335    pub fn value(&self) -> u32 {
336        self.0
337    }
338}
339
340/// Type representing converter between gas and value.
341// This is an FFI-friendly "copy-paste" of the similar enum from the `common` crate
342// which can't be used here due to its dependencies from codec and TypeInfo as well
343// as FFI.
344#[repr(C, packed)]
345#[derive(Debug, Clone, Copy)]
346pub struct GasMultiplier {
347    gas_per_value: Gas,
348    value_per_gas: Value,
349}
350
351// TODO: make implementation safer, check overflows and division remaining (#4137).
352impl GasMultiplier {
353    /// Creates GasMultiplier with gas == value.
354    pub const fn one() -> Self {
355        Self {
356            gas_per_value: 1,
357            value_per_gas: 1,
358        }
359    }
360
361    /// Creates GasMultiplier from gas per value multiplier.
362    pub fn from_gas_per_value(gas_per_value: Gas) -> Self {
363        if gas_per_value == 1 {
364            Self::one()
365        } else {
366            Self {
367                gas_per_value,
368                value_per_gas: 0,
369            }
370        }
371    }
372
373    /// Creates GasMultiplier from value per gas multiplier.
374    pub fn from_value_per_gas(value_per_gas: Value) -> Self {
375        if value_per_gas == 1 {
376            Self::one()
377        } else {
378            Self {
379                gas_per_value: 0,
380                value_per_gas,
381            }
382        }
383    }
384
385    /// Converts given gas amount into its value equivalent, rounding to upper, if Gas > Value.
386    pub fn gas_to_value(&self, gas: Gas) -> Value {
387        if self.value_per_gas != 0 {
388            (gas as Value).saturating_mul(self.value_per_gas)
389        } else {
390            gas.div_ceil(self.gas_per_value) as _
391        }
392    }
393
394    /// Converts given value amount into its gas equivalent, rounding to lower, if Gas > Value.
395    pub fn value_to_gas(&self, value: Value) -> Gas {
396        if self.gas_per_value != 0 {
397            (value as Gas).saturating_mul(self.gas_per_value)
398        } else {
399            (value / self.value_per_gas) as _
400        }
401    }
402}
403
404macro_rules! syscalls {
405    (
406        $(
407            $(#[$attrs:meta])*
408            $vis:vis fn $symbol:ident(
409                $($arg_name:ident: $arg_ty:ty),* $(,)?
410            ) $(-> $ret_ty:ty)?;
411        )*
412    ) => {
413        #[allow(improper_ctypes)]
414        unsafe extern "C" {
415            $(
416                $(#[$attrs])*
417                $vis fn $symbol($($arg_name: $arg_ty),*) $(-> $ret_ty)?;
418            )*
419        }
420
421        #[cfg(not(target_arch = "wasm32"))]
422        mod declarations {
423            use $crate::*;
424
425            $(
426                #[unsafe(no_mangle)]
427                $vis extern "C" fn $symbol($(_: $arg_ty),*) $(-> $ret_ty)? {
428                    unimplemented!(concat!(
429                        stringify!($symbol),
430                        " syscall is only available for wasm32 architecture"
431                    ))
432                }
433            )*
434        }
435    };
436}
437
438syscalls! {
439    /// Infallible `gr_env_vars` get syscall.
440    /// It leaves backend with unrecoverable error if incorrect version is passed.
441    ///
442    /// Arguments type:
443    /// - `version`: `u32` defining version of vars to get.
444    /// - `vars`: `mut ptr` for buffer to store requested version of vars.
445    pub fn gr_env_vars(version: u32, vars: *mut BufferStart);
446
447    /// Infallible `gr_block_height` get syscall.
448    ///
449    /// Arguments type:
450    /// - `height`: `mut ptr` for `u32`.
451    pub fn gr_block_height(height: *mut BlockNumber);
452
453    /// Infallible `gr_block_timestamp` get syscall.
454    ///
455    /// Arguments type:
456    /// - `timestamp`: `mut ptr` for `u64`.
457    pub fn gr_block_timestamp(timestamp: *mut BlockTimestamp);
458
459    /// Fallible `gr_create_program_wgas` send syscall.
460    ///
461    /// Arguments type:
462    /// - `cid_value`: `const ptr` for concatenated code id and value.
463    /// - `salt`: `const ptr` for the begging of the salt buffer.
464    /// - `salt_len`: `u32` length of the salt buffer.
465    /// - `payload`: `const ptr` for the begging of the payload buffer.
466    /// - `payload_len`: `u32` length of the payload buffer.
467    /// - `gas_limit`: `u64` defining gas limit for sending.
468    /// - `delay`: `u32` amount of blocks to delay.
469    /// - `err_mid_pid`: `mut ptr` for concatenated error code, message id
470    ///   and program id.
471    #[cfg(not(feature = "ethexe"))]
472    pub fn gr_create_program_wgas(
473        cid_value: *const HashWithValue,
474        salt: *const SizedBufferStart,
475        salt_len: Length,
476        payload: *const SizedBufferStart,
477        payload_len: Length,
478        gas_limit: Gas,
479        delay: BlockNumber,
480        err_mid_pid: *mut ErrorWithTwoHashes,
481    );
482
483    /// Fallible `gr_create_program` send syscall.
484    ///
485    /// Arguments type:
486    /// - `cid_value`: `const ptr` for concatenated code id and value.
487    /// - `salt`: `const ptr` for the begging of the salt buffer.
488    /// - `salt_len`: `u32` length of the salt buffer.
489    /// - `payload`: `const ptr` for the begging of the payload buffer.
490    /// - `payload_len`: `u32` length of the payload buffer.
491    /// - `delay`: `u32` amount of blocks to delay.
492    /// - `err_mid_pid`: `mut ptr` for concatenated error code, message id
493    ///   and program id.
494    pub fn gr_create_program(
495        cid_value: *const HashWithValue,
496        salt: *const SizedBufferStart,
497        salt_len: Length,
498        payload: *const SizedBufferStart,
499        payload_len: Length,
500        delay: BlockNumber,
501        err_mid_pid: *mut ErrorWithTwoHashes,
502    );
503
504    /// Fallible `gr_reply_deposit` control syscall.
505    ///
506    /// Arguments type:
507    /// - `message_id`: `const ptr` for message id.
508    /// - `gas`: `u64` defining gas limit to deposit.
509    /// - `err`: `mut ptr` for error code.
510    #[cfg(not(feature = "ethexe"))]
511    pub fn gr_reply_deposit(message_id: *const Hash, gas: Gas, err: *mut ErrorCode);
512
513    /// Infallible `gr_debug` info syscall.
514    ///
515    /// Arguments type:
516    /// - `payload`: `const ptr` for the begging of the payload buffer.
517    /// - `len`: `u32` length of the payload buffer.
518    pub fn gr_debug(payload: *const SizedBufferStart, len: Length);
519
520    /// Infallible `gr_panic` control syscall.
521    ///
522    /// Stops the execution.
523    ///
524    /// Arguments type:
525    /// - `payload`: `const ptr` for the begging of the payload buffer.
526    /// - `len`: `u32` length of the payload buffer.
527    pub fn gr_panic(payload: *const SizedBufferStart, len: Length) -> !;
528
529    /// Infallible `gr_oom_panic` control syscall.
530    pub fn gr_oom_panic() -> !;
531
532    /// Fallible `gr_reply_code` get syscall.
533    ///
534    /// Arguments type:
535    /// - `err_code`: `mut ptr` for concatenated error code and reply code.
536    pub fn gr_reply_code(err_code: *mut ErrorWithReplyCode);
537
538    /// Fallible `gr_signal_code` get syscall.
539    ///
540    /// Arguments type:
541    /// - `err_code`: `mut ptr` for concatenated error code and signal code.
542    #[cfg(not(feature = "ethexe"))]
543    pub fn gr_signal_code(err_code: *mut ErrorWithSignalCode);
544
545    /// Infallible `gr_exit` control syscall.
546    ///
547    /// Arguments type:
548    /// - `inheritor_id`: `const ptr` for program id.
549    pub fn gr_exit(inheritor_id: *const Hash) -> !;
550
551    /// Infallible `gr_gas_available` get syscall.
552    ///
553    /// Arguments type:
554    /// - `gas`: `mut ptr` for `u64`.
555    pub fn gr_gas_available(gas: *mut Gas);
556
557    /// Infallible `gr_leave` control syscall.
558    pub fn gr_leave() -> !;
559
560    /// Infallible `gr_message_id` get syscall.
561    ///
562    /// Arguments type:
563    /// - `message_id`: `const ptr` for message id.
564    pub fn gr_message_id(message_id: *mut Hash);
565
566    /// Infallible `gr_program_id` get syscall.
567    ///
568    /// Arguments type:
569    /// - `program_id`: `const ptr` for program id.
570    pub fn gr_program_id(program_id: *mut Hash);
571
572    /// Infallible `gr_random` calculate syscall.
573    ///
574    /// Arguments type:
575    /// - `subject`: `const ptr` for the subject.
576    /// - `bn_random`: `mut ptr` for concatenated block number with hash.
577    pub fn gr_random(subject: *const Hash, bn_random: *mut BlockNumberWithHash);
578
579    // TODO: issue #1859
580    /// Fallible `gr_read` get syscall.
581    ///
582    /// Arguments type:
583    /// - `at`: `u32` defining offset in the input buffer to read from.
584    /// - `len`: `u32` length of the buffer to read.
585    /// - `buffer`: `mut ptr` for buffer to store requested data.
586    /// - `err`: `mut ptr` for `u32` error code.
587    pub fn gr_read(at: Offset, len: Length, buffer: *mut SizedBufferStart, err: *mut ErrorCode);
588
589    /// Fallible `gr_reply_commit_wgas` send syscall.
590    ///
591    /// Arguments type:
592    /// - `gas_limit`: `u64` defining gas limit for sending.
593    /// - `value`: `const ptr` for `u128` defining amount of value to apply.
594    ///   Ignored if equals u32::MAX (use this for zero value for optimization).
595    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
596    #[cfg(not(feature = "ethexe"))]
597    pub fn gr_reply_commit_wgas(gas_limit: Gas, value: *const Value, err_mid: *mut ErrorWithHash);
598
599    /// Fallible `gr_reply_commit` send syscall.
600    ///
601    /// Arguments type:
602    /// - `value`: `const ptr` for `u128` defining amount of value to apply.
603    ///   Ignored if equals u32::MAX (use this for zero value for optimization).
604    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
605    pub fn gr_reply_commit(value: *const Value, err_mid: *mut ErrorWithHash);
606
607    /// Fallible `gr_reply_push` send syscall.
608    ///
609    /// Arguments type:
610    /// - `payload`: `const ptr` for the begging of the payload buffer.
611    /// - `len`: `u32` length of the payload buffer.
612    /// - `err`: `mut ptr` for error code.
613    pub fn gr_reply_push(payload: *const SizedBufferStart, len: Length, err: *mut ErrorCode);
614
615    /// Fallible `gr_reply_push_input` send syscall.
616    ///
617    /// Arguments type:
618    /// - `offset`: `u32` defining start index of the input buffer to use.
619    /// - `len`: `u32` defining slice length of the input buffer to use.
620    /// - `err`: `mut ptr` for error code.
621    pub fn gr_reply_push_input(offset: Offset, len: Length, err: *mut ErrorCode);
622
623    /// Fallible `gr_reply_to` get syscall.
624    ///
625    /// Arguments type:
626    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
627    pub fn gr_reply_to(err_mid: *mut ErrorWithHash);
628
629    /// Fallible `gr_signal_from` get syscall.
630    ///
631    /// Arguments type:
632    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
633    #[cfg(not(feature = "ethexe"))]
634    pub fn gr_signal_from(err_mid: *mut ErrorWithHash);
635
636    /// Fallible `gr_reply_input_wgas` send syscall.
637    ///
638    /// Arguments type:
639    /// - `offset`: `u32` defining start index of the input buffer to use.
640    /// - `len`: `u32` defining slice length of the input buffer to use.
641    /// - `gas_limit`: `u64` defining gas limit for sending.
642    /// - `value`: `const ptr` for `u128` defining amount of value to apply.
643    ///   Ignored if equals u32::MAX (use this for zero value for optimization).
644    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
645    #[cfg(not(feature = "ethexe"))]
646    pub fn gr_reply_input_wgas(
647        offset: Offset,
648        len: Length,
649        gas_limit: Gas,
650        value: *const Value,
651        err_mid: *mut ErrorWithHash,
652    );
653
654    /// Fallible `gr_reply_wgas` send syscall.
655    ///
656    /// Arguments type:
657    /// - `payload`: `const ptr` for the begging of the payload buffer.
658    /// - `len`: `u32` length of the payload buffer.
659    /// - `gas_limit`: `u64` defining gas limit for sending.
660    /// - `value`: `const ptr` for `u128` defining amount of value to apply.
661    ///   Ignored if equals u32::MAX (use this for zero value for optimization).
662    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
663    #[cfg(not(feature = "ethexe"))]
664    pub fn gr_reply_wgas(
665        payload: *const SizedBufferStart,
666        len: Length,
667        gas_limit: Gas,
668        value: *const Value,
669        err_mid: *mut ErrorWithHash,
670    );
671
672    /// Fallible `gr_reply` send syscall.
673    ///
674    /// Arguments type:
675    /// - `payload`: `const ptr` for the begging of the payload buffer.
676    /// - `len`: `u32` length of the payload buffer.
677    /// - `value`: `const ptr` for `u128` defining amount of value to apply.
678    ///   Ignored if equals u32::MAX (use this for zero value for optimization).
679    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
680    pub fn gr_reply(
681        payload: *const SizedBufferStart,
682        len: Length,
683        value: *const Value,
684        err_mid: *mut ErrorWithHash,
685    );
686
687    /// Fallible `gr_reply_input` send syscall.
688    ///
689    /// Arguments type:
690    /// - `offset`: `u32` defining start index of the input buffer to use.
691    /// - `len`: `u32` defining slice length of the input buffer to use.
692    /// - `value`: `const ptr` for `u128` defining amount of value to apply.
693    ///   Ignored if equals u32::MAX (use this for zero value for optimization).
694    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
695    pub fn gr_reply_input(
696        offset: Offset,
697        len: Length,
698        value: *const Value,
699        err_mid: *mut ErrorWithHash,
700    );
701
702    /// Fallible `gr_reservation_reply_commit` send syscall.
703    ///
704    /// Arguments type:
705    /// - `rid_value`: `const ptr` for concatenated reservation id and value.
706    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
707    #[cfg(not(feature = "ethexe"))]
708    pub fn gr_reservation_reply_commit(
709        rid_value: *const HashWithValue,
710        err_mid: *mut ErrorWithHash,
711    );
712
713    /// Fallible `gr_reservation_reply` send syscall.
714    ///
715    /// Arguments type:
716    /// - `rid_value`: `const ptr` for concatenated reservation id and value.
717    /// - `payload`: `const ptr` for the begging of the payload buffer.
718    /// - `len`: `u32` length of the payload buffer.
719    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
720    #[cfg(not(feature = "ethexe"))]
721    pub fn gr_reservation_reply(
722        rid_value: *const HashWithValue,
723        payload: *const SizedBufferStart,
724        len: Length,
725        err_mid: *mut ErrorWithHash,
726    );
727
728    /// Fallible `gr_reservation_send_commit` send syscall.
729    ///
730    /// Arguments type:
731    /// - `handle`: `u32` defining handle of the message to commit.
732    /// - `rid_pid_value`: `const ptr` for concatenated reservation id,
733    ///   program id and value.
734    /// - `delay`: `u32` amount of blocks to delay.
735    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
736    #[cfg(not(feature = "ethexe"))]
737    pub fn gr_reservation_send_commit(
738        handle: Handle,
739        rid_pid_value: *const TwoHashesWithValue,
740        delay: BlockNumber,
741        err_mid: *mut ErrorWithHash,
742    );
743
744    /// Fallible `gr_reservation_send` send syscall.
745    ///
746    /// Arguments type:
747    /// - `rid_pid_value`: `const ptr` for concatenated reservation id,
748    ///   program id and value.
749    /// - `payload`: `const ptr` for the begging of the payload buffer.
750    /// - `len`: `u32` length of the payload buffer.
751    /// - `delay`: `u32` amount of blocks to delay.
752    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
753    #[cfg(not(feature = "ethexe"))]
754    pub fn gr_reservation_send(
755        rid_pid_value: *const TwoHashesWithValue,
756        payload: *const SizedBufferStart,
757        len: Length,
758        delay: BlockNumber,
759        err_mid: *mut ErrorWithHash,
760    );
761
762    /// Fallible `gr_reserve_gas` control syscall.
763    ///
764    /// Arguments type:
765    /// - `gas`: `u64` defining amount of gas to reserve.
766    /// - `duration`: `u32` reservation duration.
767    /// - `err_rid`: `mut ptr` for concatenated error code and reservation id.
768    #[cfg(not(feature = "ethexe"))]
769    pub fn gr_reserve_gas(gas: Gas, duration: BlockNumber, err_rid: *mut ErrorWithHash);
770
771    /// Fallible `gr_send_commit_wgas` send syscall.
772    ///
773    /// Arguments type:
774    /// - `handle`: `u32` defining handle of the message to commit.
775    /// - `pid_value`: `const ptr` for concatenated program id and value.
776    /// - `gas_limit`: `u64` defining gas limit for sending.
777    /// - `delay`: `u32` amount of blocks to delay.
778    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
779    #[cfg(not(feature = "ethexe"))]
780    pub fn gr_send_commit_wgas(
781        handle: Handle,
782        pid_value: *const HashWithValue,
783        gas_limit: Gas,
784        delay: BlockNumber,
785        err_mid: *mut ErrorWithHash,
786    );
787
788    /// Fallible `gr_send_commit` send syscall.
789    ///
790    /// Arguments type:
791    /// - `handle`: `u32` defining handle of the message to commit.
792    /// - `pid_value`: `const ptr` for concatenated program id and value.
793    /// - `delay`: `u32` amount of blocks to delay.
794    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
795    pub fn gr_send_commit(
796        handle: Handle,
797        pid_value: *const HashWithValue,
798        delay: BlockNumber,
799        err_mid: *mut ErrorWithHash,
800    );
801
802    /// Fallible `gr_send_init` send syscall.
803    ///
804    /// Arguments type:
805    /// - `err_handle`: `mut ptr` for concatenated error code and handle.
806    pub fn gr_send_init(err_handle: *mut ErrorWithHandle);
807
808    /// Fallible `gr_send_push` send syscall.
809    ///
810    /// Arguments type:
811    /// - `handle`: `u32` defining handle of the message to push into.
812    /// - `payload`: `const ptr` for the begging of the payload buffer.
813    /// - `len`: `u32` length of the payload buffer.
814    /// - `err`: `mut ptr` for error code.
815    pub fn gr_send_push(
816        handle: Handle,
817        payload: *const SizedBufferStart,
818        len: Length,
819        err: *mut ErrorCode,
820    );
821
822    /// Fallible `gr_send_push_input` send syscall.
823    ///
824    /// Arguments type:
825    /// - `handle`: `u32` defining handle of the message to push into.
826    /// - `offset`: `u32` defining start index of the input buffer to use.
827    /// - `len`: `u32` defining slice length of the input buffer to use.
828    /// - `err`: `mut ptr` for error code.
829    pub fn gr_send_push_input(handle: Handle, offset: Offset, len: Length, err: *mut ErrorCode);
830
831    /// Fallible `gr_send_input_wgas` send syscall.
832    ///
833    /// Arguments type:
834    /// - `pid_value`: `const ptr` for concatenated program id and value.
835    /// - `offset`: `u32` defining start index of the input buffer to use.
836    /// - `len`: `u32` defining slice length of the input buffer to use.
837    /// - `gas_limit`: `u64` defining gas limit for sending.
838    /// - `delay`: `u32` amount of blocks to delay.
839    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
840    #[cfg(not(feature = "ethexe"))]
841    pub fn gr_send_input_wgas(
842        pid_value: *const HashWithValue,
843        offset: Offset,
844        len: Length,
845        gas_limit: Gas,
846        delay: BlockNumber,
847        err_mid: *mut ErrorWithHash,
848    );
849
850    /// Fallible `gr_send_wgas` send syscall.
851    ///
852    /// Arguments type:
853    /// - `pid_value`: `const ptr` for concatenated program id and value.
854    /// - `payload`: `const ptr` for the begging of the payload buffer.
855    /// - `len`: `u32` length of the payload buffer.
856    /// - `gas_limit`: `u64` defining gas limit for sending.
857    /// - `delay`: `u32` amount of blocks to delay.
858    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
859    #[cfg(not(feature = "ethexe"))]
860    pub fn gr_send_wgas(
861        pid_value: *const HashWithValue,
862        payload: *const SizedBufferStart,
863        len: Length,
864        gas_limit: Gas,
865        delay: BlockNumber,
866        err_mid: *mut ErrorWithHash,
867    );
868
869    /// Fallible `gr_send` send syscall.
870    ///
871    /// Arguments type:
872    /// - `pid_value`: `const ptr` for concatenated program id and value.
873    /// - `payload`: `const ptr` for the begging of the payload buffer.
874    /// - `len`: `u32` length of the payload buffer.
875    /// - `delay`: `u32` amount of blocks to delay.
876    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
877    pub fn gr_send(
878        pid_value: *const HashWithValue,
879        payload: *const SizedBufferStart,
880        len: Length,
881        delay: BlockNumber,
882        err_mid: *mut ErrorWithHash,
883    );
884
885    /// Fallible `gr_send_input` send syscall.
886    ///
887    /// Arguments type:
888    /// - `pid_value`: `const ptr` for concatenated program id and value.
889    /// - `offset`: `u32` defining start index of the input buffer to use.
890    /// - `len`: `u32` length of the payload buffer.
891    /// - `delay`: `u32` amount of blocks to delay.
892    /// - `err_mid`: `mut ptr` for concatenated error code and message id.
893    pub fn gr_send_input(
894        pid_value: *const HashWithValue,
895        offset: Offset,
896        len: Length,
897        delay: BlockNumber,
898        err_mid: *mut ErrorWithHash,
899    );
900
901    /// Infallible `gr_size` get syscall.
902    ///
903    /// Arguments type:
904    /// - `length`: `mut ptr` for length of the incoming payload.
905    pub fn gr_size(length: *mut Length);
906
907    /// Infallible `gr_source` get syscall.
908    ///
909    /// Arguments type:
910    /// - `program_id`: `const ptr` for program id.
911    pub fn gr_source(program_id: *mut Hash);
912
913    /// Fallible `gr_system_reserve_gas` control syscall.
914    ///
915    /// Arguments type:
916    /// - `gas`: `u64` defining amount of gas to reserve.
917    /// - `err`: `mut ptr` for error code.
918    #[cfg(not(feature = "ethexe"))]
919    pub fn gr_system_reserve_gas(gas: Gas, err: *mut ErrorCode);
920
921    /// Fallible `gr_unreserve_gas` control syscall.
922    ///
923    /// Arguments type:
924    /// - `reservation_id`: `const ptr` for reservation id.
925    /// - `err_unreserved`: `mut ptr` for concatenated error code and
926    ///   unreserved gas amount.
927    #[cfg(not(feature = "ethexe"))]
928    pub fn gr_unreserve_gas(reservation_id: *const Hash, err_unreserved: *mut ErrorWithGas);
929
930    /// Infallible `gr_value_available` get syscall.
931    ///
932    /// Arguments type:
933    /// - `value`: `mut ptr` for total value of the program.
934    pub fn gr_value_available(value: *mut Value);
935
936    /// Infallible `gr_value` get syscall.
937    ///
938    /// Arguments type:
939    /// - `value`: `mut ptr` for incoming value of the message.
940    pub fn gr_value(value: *mut Value);
941
942    /// Infallible `gr_wait_for` control syscall.
943    ///
944    /// Arguments type:
945    /// - `duration`: `u32` defining amount of blocks to wait.
946    pub fn gr_wait_for(duration: BlockNumber) -> !;
947
948    /// Infallible `gr_wait_up_to` control syscall.
949    ///
950    /// Arguments type:
951    /// - `duration`: `u32` defining amount of blocks to wait.
952    pub fn gr_wait_up_to(duration: BlockNumber) -> !;
953
954    /// Infallible `gr_wait` control syscall.
955    pub fn gr_wait() -> !;
956
957    /// Fallible `gr_wake` control syscall.
958    ///
959    /// Arguments type:
960    /// - `message_id`: `const ptr` for message id.
961    /// - `delay`: `u32` amount of blocks to delay.
962    /// - `err_mid`: `mut ptr` for error code.
963    pub fn gr_wake(message_id: *const Hash, delay: BlockNumber, err: *mut ErrorCode);
964}