jam_pvm_common/
imports.rs

1#[polkavm_derive::polkavm_import]
2extern "C" {
3	// NOTE: This is NOT part of the GP.
4	#[polkavm_import(index = 100)]
5	pub fn log(
6		level: u64,
7		target_ptr: *const u8,
8		target_len: u64,
9		text_ptr: *const u8,
10		text_len: u64,
11	);
12
13	#[polkavm_import(index = 0)]
14	pub fn gas() -> u64;
15
16	#[polkavm_import(index = 1)]
17	pub fn fetch(buffer: *mut u8, offset: u64, buffer_len: u64, kind: u64, a: u64, b: u64) -> u64;
18
19	// If `service == u64::MAX`, then use caller service's storage.
20	// Copies up to out_len bytes.
21	// Returns `u64::MAX` if the preimage is unknown. Otherwise the preimage's length.
22	#[polkavm_import(index = 2)]
23	pub fn lookup(
24		service: u64,
25		hash_ptr: *const u8,
26		out: *mut u8,
27		offset: u64,
28		out_len: u64,
29	) -> u64;
30
31	// If `service == u64::MAX`, then use caller service's storage.
32	// Copies up to out_len bytes.
33	// Returns `u64::MAX` if the key is non-existent. Otherwise the value's length.
34	#[polkavm_import(index = 3)]
35	pub fn read(
36		service: u64,
37		key_ptr: *const u8,
38		key_len: u64,
39		out: *mut u8,
40		offset: u64,
41		out_len: u64,
42	) -> u64;
43
44	// Returns the length of the *old* value or u64::MAX if there wasn't one.
45	#[polkavm_import(index = 4)]
46	pub fn write(key_ptr: *const u8, key_len: u64, value: *const u8, value_len: u64) -> u64;
47
48	#[polkavm_import(index = 5)]
49	pub fn info(service: u64, service_info_ptr: *mut u8, offset: u64, len: u64) -> u64;
50
51	#[polkavm_import(index = 6)]
52	pub fn historical_lookup(
53		service_id: u64,
54		ho: *const u8,
55		bo: *mut u8,
56		offset: u64,
57		bz: u64,
58	) -> u64;
59
60	#[polkavm_import(index = 7)]
61	pub fn export(buffer: *const u8, buffer_len: u64) -> u64;
62
63	#[polkavm_import(index = 8)]
64	pub fn machine(code_ptr: *const u8, code_len: u64, program_counter: u64) -> u64;
65
66	#[polkavm_import(index = 9)]
67	pub fn peek(vm_handle: u64, outer_dst: *mut u8, inner_src: u64, length: u64) -> u64;
68
69	#[polkavm_import(index = 10)]
70	pub fn poke(vm_handle: u64, outer_src: *const u8, inner_dst: u64, length: u64) -> u64;
71
72	#[polkavm_import(index = 11)]
73	pub fn pages(vm_handle: u64, page: u64, count: u64, operation: u64) -> u64;
74
75	// When this crate is compiled natively Rust will complain that the tuple
76	// here cannot be used in FFI. This happens because for non-RISC-V targets
77	// the `polkavm_import` macro just passes through the `extern C` block as-is.
78	//
79	// Compiling this natively is nonsense since calling anything would result
80	// in a segfault anyway, so just silence the warning.
81	#[cfg_attr(not(target_env = "polkavm"), allow(improper_ctypes))]
82	#[polkavm_import(index = 12)]
83	pub fn invoke(vm_handle: u64, args: *mut core::ffi::c_void) -> (u64, u64);
84
85	#[polkavm_import(index = 13)]
86	pub fn expunge(vm_handle: u64) -> u64;
87
88	#[polkavm_import(index = 14)]
89	pub fn bless(
90		manager: u64,
91		assigners: *const u8,
92		designate: u64,
93		register: u64,
94		always_acc: *const u8,
95		always_acc_count: u64,
96	) -> u64;
97
98	#[polkavm_import(index = 15)]
99	pub fn assign(core: u64, auth_ptr: *const u8, assigner: u64) -> u64;
100
101	#[polkavm_import(index = 16)]
102	pub fn designate(validator_keys_ptr: *const u8) -> u64;
103
104	#[polkavm_import(index = 17)]
105	pub fn checkpoint() -> u64;
106
107	#[polkavm_import(index = 18)]
108	pub fn new(
109		code_hash_ptr: *const u8,
110		code_len: u64,
111		min_item_gas: u64,
112		min_memo_gas: u64,
113		deposit_offset: u64,
114		new_service_id: u64,
115	) -> u64;
116
117	#[polkavm_import(index = 19)]
118	pub fn upgrade(code_hash_ptr: *const u8, min_item_gas: u64, min_memo_gas: u64) -> u64;
119
120	#[polkavm_import(index = 20)]
121	pub fn transfer(dest: u64, amount: u64, gas_limit: u64, memo_ptr: *const u8) -> u64;
122
123	#[polkavm_import(index = 21)]
124	pub fn eject(target: u64, code_hash: *const u8) -> u64;
125
126	#[cfg_attr(not(target_arch = "riscv64"), allow(improper_ctypes))]
127	#[polkavm_import(index = 22)]
128	pub fn query(hash_ptr: *const u8, preimage_len: u64) -> (u64, u64);
129
130	#[polkavm_import(index = 23)]
131	pub fn solicit(hash_ptr: *const u8, preimage_len: u64) -> u64;
132
133	#[polkavm_import(index = 24)]
134	pub fn forget(hash_ptr: *const u8, preimage_len: u64) -> u64;
135
136	#[polkavm_import(index = 25)]
137	pub fn yield_hash(hash_ptr: *const u8) -> u64;
138
139	#[polkavm_import(index = 26)]
140	pub fn provide(service_id: u64, preimage_ptr: *const u8, preimage_len: u64) -> u64;
141}