Line data Source code
1 : #include "fd_bpf_loader_serialization.h"
2 : #include "../fd_borrowed_account.h"
3 : #include "../fd_runtime.h"
4 : #include "../../vm/fd_vm_base.h"
5 :
6 : /* This file is responsible for serializing and deserializing
7 : the input region of the BPF virtual machine. The input region contains
8 : instruction information, account metadata, and account data. The high level
9 : format is as follows:
10 :
11 : [ account 1 metadata, account 1 data, account 2 metadata, account 2 data, ...,
12 : account N metadata, account N data, instruction info. ]
13 :
14 : This format by no means comprehensive, but it should give an idea of how
15 : the input region is laid out. When direct mapping is not enabled, the input
16 : region is stored as a single contiguous buffer. This buffer in the host
17 : address space is then mapped to the VM virtual address space (the range
18 : starting with 0x400...). This means to serialize into the input region, we
19 : need to copy in the account metadata and account data into the buffer for
20 : each account. Everything must get copied out after execution is complete.
21 : A consequence of this is that a memcpy for the account data is required
22 : for each serialize and deserialize operation: this can potentially become
23 : expensive if there are many accounts and many nested CPI calls. Also, the
24 : entire memory region is treated as writable even though many accounts are
25 : read-only. This means that for all read-only accounts, a memcmp must be done
26 : while deserializing to make sure that the account (meta)data has not changed.
27 :
28 : Direct mapping offers a solution to this by introducing a more sophisticated
29 : memory translation protocol. Now the account data is not copied into a single
30 : contiguous buffer, but instead a borrowed account's data is directly mapped
31 : into the VM's virtual address space. The host memory for the input region is
32 : now represented by a list of fragmented memory regions. These sub regions
33 : also have different write permissions. This should solve the problem of
34 : having to memcpy/memcmp account data regions (which can be up to 10MiB each).
35 : There is some nuance to this, as the account data can be resized. This means
36 : that memcpys for account data regions can't totally be avoided.
37 :
38 : SERIALIZATION BEHAVIOR
39 : ==========================================
40 :
41 : This implementation supports three distinct serialization modes based on two
42 : feature flags: virtual_address_space_adjustments and
43 : account_data_direct_mapping.
44 :
45 : MODE 1
46 : --------------------------------------
47 : virtual_address_space_adjustments = false
48 : account_data_direct_mapping = false
49 :
50 : Memory Layout:
51 : - Single contiguous buffer in host memory
52 : - Buffer contains: [metadata1, data1, realloc_buffer1, metadata2, data2,
53 : realloc_buffer2, ..., metadataN, dataN, realloc_bufferN, instruction_info]
54 : - Each account gets: original data + MAX_PERMITTED_DATA_INCREASE (10KiB)
55 : - Padding added to maintain 16-byte alignment between accounts
56 : - Entire buffer is writable
57 :
58 : Memory Regions:
59 : - The entire input region buffer is mapped as one contiguous VM address
60 : space region
61 :
62 : Serialization Process:
63 : - Account data is memcpy'd into the buffer
64 : - 10KiB realloc buffer is zeroed out and appended after each account's data
65 : - Alignment padding is zeroed and added after realloc buffer
66 :
67 : Deserialization Process:
68 : - Account data must be memcpy'd back from buffer to borrowed account
69 : - For writable accounts: always copy data back
70 : - For read-only accounts: memcmp to verify data unchanged, error if modified
71 : - Account resizing allowed if account permissions permit it
72 :
73 : MODE 2
74 : -------------------------------------------
75 : virtual_address_space_adjustments = true
76 : account_data_direct_mapping = false
77 :
78 : Memory Layout:
79 : - Still uses a single contiguous buffer, but organized into fragmented
80 : regions.
81 : - Each account now has separate regions for metadata and data+realloc.
82 : - Buffer contains: [metadata1, data1+realloc1, metadata2, data2+realloc2, ...,
83 : metadataN, dataN+reallocN, instruction_info].
84 : - Each metadata region and data region tracked separately in
85 : input_mem_regions.
86 :
87 : Memory Regions:
88 : - For each account:
89 : * Region 0: Account metadata (writable)
90 : * Region 1: Account data + realloc space (writable if account is writable)
91 : - If the account is owned by the deprecated loader, no realloc region is
92 : created as the deprecated loader does not support resizing accounts.
93 :
94 : Serialization:
95 : - Account metadata serialized first, added as a memory region.
96 : - Account data memcpy'd into buffer - not directly mapped.
97 : - 10KiB realloc buffer zeroed and appended (not direct mapped).
98 : - Data region created pointing to copied data in buffer.
99 :
100 : MODE 3: Direct Mapping (requires virtual_address_space_adjustments)
101 : -----------------------------------------------
102 : virtual_address_space_adjustments = true
103 : account_data_direct_mapping = true
104 :
105 : This is very similar to virtual_address_space_adjustments, but account
106 : data is NOT copied into the input region buffer.
107 :
108 : Instead, the data region points directly to the staging area for the
109 : account in the transaction account's data. This staging area has enough
110 : space to hold the account data and the realloc buffer. Changes to this
111 : staging area will be written back to the account database in transaction
112 : finalization.
113 : */
114 :
115 : /* Add a new memory region to represent the input region. All of the memory
116 : regions here have sorted virtual addresses. These regions may or may not
117 : correspond to an account's data region. If it corresponds to metadata,
118 : the pubkey for the region will be NULL. */
119 : static void
120 : new_input_mem_region( fd_vm_input_region_t * input_mem_regions,
121 : uint * input_mem_regions_cnt,
122 : const uchar * buffer,
123 : ulong region_sz,
124 : ulong address_space_reserved,
125 : uchar is_writable,
126 8898 : ulong acc_region_meta_idx ) {
127 :
128 : /* The start vaddr of the new region should be equal to start of the previous
129 : region added to the address space reserved for the region. */
130 8898 : ulong vaddr_offset = *input_mem_regions_cnt==0UL ? 0UL : input_mem_regions[ *input_mem_regions_cnt-1U ].vaddr_offset +
131 5376 : input_mem_regions[ *input_mem_regions_cnt-1U ].address_space_reserved;
132 8898 : input_mem_regions[ *input_mem_regions_cnt ].is_writable = is_writable;
133 8898 : input_mem_regions[ *input_mem_regions_cnt ].haddr = (ulong)buffer;
134 8898 : input_mem_regions[ *input_mem_regions_cnt ].region_sz = (uint)region_sz;
135 8898 : input_mem_regions[ *input_mem_regions_cnt ].address_space_reserved = address_space_reserved;
136 8898 : input_mem_regions[ *input_mem_regions_cnt ].vaddr_offset = vaddr_offset;
137 8898 : input_mem_regions[ *input_mem_regions_cnt ].acc_region_meta_idx = acc_region_meta_idx;
138 8898 : (*input_mem_regions_cnt)++;
139 8898 : }
140 :
141 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L128-L190 */
142 : /* This function handles casing for direct mapping being enabled as well as if
143 : the alignment is being stored. In the case where direct mapping is not
144 : enabled, we copy in the account data and a 10KiB buffer into the input region.
145 : These both go into the same memory buffer. With direct mapping, a
146 : single region points to the account data and reserves address space
147 : for growth. In both cases, padding is used to maintain 8 byte
148 : alignment. If alignment is not required, then a resizing buffer is not used
149 : as the deprecated loader doesn't allow for resizing accounts. */
150 : static ulong
151 : write_account( fd_borrowed_account_t * account,
152 : uchar instr_acc_idx,
153 : uchar * * serialized_params,
154 : uchar * * serialized_params_start,
155 : fd_vm_input_region_t * input_mem_regions,
156 : uint * input_mem_regions_cnt,
157 : fd_vm_acc_region_meta_t * acc_region_metas,
158 : int is_loader_v1,
159 : int virtual_address_space_adjustments,
160 5073 : int direct_mapping ) {
161 :
162 5073 : uchar const * data = account ? fd_borrowed_account_get_data( account ) : NULL;
163 5073 : ulong dlen = account ? fd_borrowed_account_get_data_len( account ) : 0UL;
164 :
165 5073 : acc_region_metas[instr_acc_idx].original_data_len = dlen;
166 5073 : acc_region_metas[instr_acc_idx].acc = account->acc;
167 5073 : acc_region_metas[instr_acc_idx].touched = account->touched;
168 :
169 : /* Legacy behavior: no virtual_address_space_adjustments (also implies no direct mapping)
170 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L132-L142 */
171 5073 : if( !virtual_address_space_adjustments ) {
172 : /* Copy the account data into input region buffer */
173 2361 : fd_memcpy( *serialized_params, data, dlen );
174 2361 : *serialized_params += dlen;
175 :
176 2361 : if( FD_LIKELY( !is_loader_v1 ) ) {
177 : /* Zero out padding bytes and max permitted data increase */
178 2241 : ulong align_offset = fd_ulong_align_up( dlen, FD_BPF_ALIGN_OF_U128 ) - dlen;
179 2241 : fd_memset( *serialized_params, 0, MAX_PERMITTED_DATA_INCREASE + align_offset );
180 2241 : *serialized_params += MAX_PERMITTED_DATA_INCREASE + align_offset;
181 2241 : }
182 2361 : acc_region_metas[instr_acc_idx].region_idx = UINT_MAX;
183 2712 : } else { /* virtual_address_space_adjustments == true */
184 :
185 : /* Set up account region metadata */
186 2712 : acc_region_metas[instr_acc_idx].region_idx = *input_mem_regions_cnt;
187 :
188 : /* First, push on the region for the metadata that has just been serialized.
189 : This function will push the metadata in the serialized_params from
190 : serialized_params_start to serialized_params as a region to the input
191 : memory regions array.
192 :
193 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L143 */
194 2712 : ulong region_sz = (ulong)(*serialized_params) - (ulong)(*serialized_params_start);
195 2712 : new_input_mem_region( input_mem_regions, input_mem_regions_cnt, *serialized_params_start, region_sz, region_sz, 1U, ULONG_MAX );
196 :
197 : /* If direct mapping isn't enabled, then copy the account data in directly
198 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L145-L151 */
199 2712 : if( !direct_mapping ) {
200 1287 : fd_memcpy( *serialized_params, data, dlen );
201 1287 : *serialized_params += dlen;
202 1287 : if( FD_LIKELY( !is_loader_v1 ) ) {
203 1167 : fd_memset( *serialized_params, 0, MAX_PERMITTED_DATA_INCREASE );
204 1167 : *serialized_params += MAX_PERMITTED_DATA_INCREASE;
205 1167 : }
206 1287 : }
207 :
208 : /* Calculate address space reserved for account (data + realloc space)
209 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L152-L159 */
210 2712 : ulong address_space_reserved = !is_loader_v1 ?
211 2472 : fd_ulong_sat_add( dlen, MAX_PERMITTED_DATA_INCREASE ) : dlen;
212 :
213 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L160-L170 */
214 2712 : if( address_space_reserved > 0 ) {
215 2664 : int err = 0;
216 2664 : uchar is_writable = !!(fd_borrowed_account_can_data_be_changed( account, &err ) && !err);
217 :
218 2664 : if( !direct_mapping ) {
219 : /* Create region pointing to the copied data in buffer
220 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L161-L165 */
221 1263 : uchar * data_start = *serialized_params - address_space_reserved;
222 1263 : new_input_mem_region( input_mem_regions, input_mem_regions_cnt, data_start, dlen, address_space_reserved, is_writable, instr_acc_idx );
223 1401 : } else {
224 : /* Direct mapping: create region pointing directly to account data */
225 1401 : new_input_mem_region( input_mem_regions, input_mem_regions_cnt, data, dlen, address_space_reserved, is_writable, instr_acc_idx );
226 1401 : }
227 2664 : }
228 :
229 2712 : *serialized_params_start = *serialized_params;
230 :
231 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L171-L187 */
232 2712 : if( FD_LIKELY( !is_loader_v1 ) ) {
233 2472 : ulong align_offset = fd_ulong_align_up( dlen, FD_BPF_ALIGN_OF_U128 ) - dlen;
234 2472 : if( !direct_mapping ) {
235 : /* If direct mapping is not enabled, we do not align the start of each
236 : region metadata to FD_BPF_ALIGN_OF_U128, but we do align the start
237 : of the actual contents of the metadata region.
238 :
239 : This follows Agave's logic
240 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L174-L177 */
241 1167 : fd_memset( *serialized_params, 0, align_offset );
242 1167 : *serialized_params += align_offset;
243 1305 : } else {
244 : /* If direct mapping is enabled, we align the start of each region
245 : metadata to FD_BPF_ALIGN_OF_U128. */
246 1305 : fd_memset( *serialized_params, 0, FD_BPF_ALIGN_OF_U128 );
247 1305 : *serialized_params += FD_BPF_ALIGN_OF_U128;
248 1305 : *serialized_params_start += fd_ulong_sat_sub( FD_BPF_ALIGN_OF_U128, align_offset );
249 1305 : }
250 2472 : }
251 :
252 2712 : return region_sz + address_space_reserved;
253 2712 : }
254 :
255 2361 : return 0UL;
256 5073 : }
257 :
258 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L473 */
259 : static int
260 : fd_bpf_loader_input_serialize_for_abiv1( fd_exec_instr_ctx_t * ctx,
261 : ulong * pre_lens,
262 : fd_vm_input_region_t * input_mem_regions,
263 : uint * input_mem_regions_cnt,
264 : fd_vm_acc_region_meta_t * acc_region_metas,
265 : int virtual_address_space_adjustments,
266 : int direct_mapping,
267 : int direct_account_pointers_in_program_input,
268 : ulong * instr_data_offset,
269 3306 : ulong * serialized_bytes_written ) {
270 : /* Transaction sanitisation limits the number of instruction accounts to
271 : FD_TXN_ACCT_ADDR_MAX. */
272 3306 : uchar acc_idx_seen[ FD_TXN_ACCT_ADDR_MAX ] = {0};
273 3306 : ushort dup_acc_idx[ FD_TXN_ACCT_ADDR_MAX ] = {0};
274 :
275 : /* 16-byte aligned buffer from runtime:
276 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L61 */
277 3306 : uchar * serialized_params = ctx->runtime->bpf_loader_serialization.frame[ ctx->runtime->instr.stack_sz-1UL ];
278 3306 : uchar * serialized_params_start = serialized_params;
279 3306 : uchar * curr_serialized_params_start = serialized_params;
280 3306 : ulong curr_region_vaddr = 0UL;
281 :
282 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L539 */
283 3306 : FD_STORE( ulong, serialized_params, ctx->instr->acct_cnt );
284 3306 : serialized_params += sizeof(ulong);
285 :
286 : /* Iterate over accounts in the instruction to populate input region.
287 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L540-L570 */
288 11757 : for( ushort i=0; i<ctx->instr->acct_cnt; i++ ) {
289 8451 : uchar acc_idx = (uchar)ctx->instr->accounts[i].index_in_transaction;
290 8451 : fd_pubkey_t * acc = &ctx->txn_out->accounts.keys[acc_idx];
291 :
292 8451 : if( FD_UNLIKELY( acc_idx_seen[acc_idx] && dup_acc_idx[acc_idx] != i ) ) {
293 : /* Duplicate. Store 8 byte buffer to maintain alignment but store the
294 : account index in the first byte.
295 :
296 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L564-L568 */
297 3738 : FD_STORE( ulong, serialized_params, 0UL );
298 3738 : FD_STORE( uchar, serialized_params, (uchar)dup_acc_idx[acc_idx] );
299 3738 : serialized_params += sizeof(ulong);
300 :
301 : /* Clone the account metadata from the original account
302 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L372 */
303 3738 : acc_region_metas[i] = acc_region_metas[dup_acc_idx[acc_idx]];
304 4713 : } else {
305 4713 : acc_idx_seen[acc_idx] = 1;
306 4713 : dup_acc_idx[acc_idx] = i;
307 :
308 4713 : acc_region_metas[i].vm_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
309 4713 : (ulong)(serialized_params - curr_serialized_params_start);
310 :
311 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L376 */
312 4713 : FD_STORE( uchar, serialized_params, FD_NON_DUP_MARKER );
313 4713 : serialized_params += sizeof(uchar);
314 :
315 : /* Borrow the account
316 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L245-L258 */
317 4713 : fd_guarded_borrowed_account_t view_acc = {0};
318 4713 : int err = fd_exec_instr_ctx_try_borrow_instr_account( ctx, i, &view_acc );
319 4713 : if( FD_UNLIKELY( err ) ) {
320 0 : return err;
321 0 : }
322 :
323 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L544 */
324 4713 : uchar is_signer = (uchar)fd_instr_acc_is_signer_idx( ctx->instr, (uchar)i, NULL );
325 4713 : FD_STORE( uchar, serialized_params, is_signer );
326 4713 : serialized_params += sizeof(uchar);
327 :
328 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L545 */
329 4713 : uchar is_writable = (uchar)fd_instr_acc_is_writable_idx( ctx->instr, (uchar)i );
330 4713 : FD_STORE( uchar, serialized_params, is_writable );
331 4713 : serialized_params += sizeof(uchar);
332 :
333 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L546-L547 */
334 4713 : uchar is_executable = (uchar)view_acc.acc->executable;
335 4713 : FD_STORE( uchar, serialized_params, is_executable );
336 4713 : serialized_params += sizeof(uchar);
337 :
338 : /* The original data len field is intentionally NOT populated. */
339 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L548 */
340 4713 : uint padding_0 = 0U;
341 4713 : FD_STORE( uint, serialized_params, padding_0 );
342 4713 : serialized_params += sizeof(uint);
343 :
344 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L549 */
345 4713 : fd_pubkey_t key = *acc;
346 4713 : acc_region_metas[i].vm_key_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
347 4713 : (ulong)(serialized_params - curr_serialized_params_start);
348 4713 : FD_STORE( fd_pubkey_t, serialized_params, key );
349 4713 : serialized_params += sizeof(fd_pubkey_t);
350 :
351 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L550 */
352 4713 : fd_pubkey_t owner = *(fd_pubkey_t *)&view_acc.acc->owner;
353 4713 : acc_region_metas[i].vm_owner_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
354 4713 : (ulong)(serialized_params - curr_serialized_params_start);
355 4713 : FD_STORE( fd_pubkey_t, serialized_params, owner );
356 4713 : serialized_params += sizeof(fd_pubkey_t);
357 :
358 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L551 */
359 4713 : ulong lamports = view_acc.acc->lamports;
360 4713 : acc_region_metas[i].vm_lamports_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
361 4713 : (ulong)(serialized_params - curr_serialized_params_start);
362 4713 : FD_STORE( ulong, serialized_params, lamports );
363 4713 : serialized_params += sizeof(ulong);
364 :
365 4713 : ulong acc_data_len = view_acc.acc->data_len;
366 4713 : pre_lens[i] = acc_data_len;
367 :
368 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L552 */
369 4713 : ulong data_len = acc_data_len;
370 4713 : FD_STORE( ulong, serialized_params, data_len );
371 4713 : serialized_params += sizeof(ulong);
372 :
373 : /* vm_data_addr: data is written immediately after the data_len field */
374 4713 : acc_region_metas[i].vm_data_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
375 4713 : (ulong)(serialized_params - curr_serialized_params_start);
376 :
377 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L553 */
378 4713 : write_account(
379 4713 : &view_acc,
380 4713 : (uchar)i,
381 4713 : &serialized_params,
382 4713 : &curr_serialized_params_start,
383 4713 : input_mem_regions,
384 4713 : input_mem_regions_cnt,
385 4713 : acc_region_metas,
386 4713 : 0,
387 4713 : virtual_address_space_adjustments,
388 4713 : direct_mapping );
389 :
390 : /* write_account may have pushed a new region(s) */
391 4713 : curr_region_vaddr = *input_mem_regions_cnt == 0U ? 0UL :
392 4713 : input_mem_regions[*input_mem_regions_cnt-1U].vaddr_offset +
393 2472 : input_mem_regions[*input_mem_regions_cnt-1U].address_space_reserved;
394 :
395 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L554-L555 */
396 4713 : FD_STORE( ulong, serialized_params, ULONG_MAX );
397 4713 : serialized_params += sizeof(ulong);
398 4713 : }
399 :
400 8451 : }
401 :
402 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L571 */
403 3306 : ulong instr_data_len = ctx->instr->data_sz;
404 3306 : FD_STORE( ulong, serialized_params, instr_data_len );
405 3306 : serialized_params += sizeof(ulong);
406 :
407 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L572 */
408 3306 : *instr_data_offset = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
409 3306 : (ulong)(serialized_params - curr_serialized_params_start);
410 :
411 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L571 */
412 3306 : fd_memcpy( serialized_params, ctx->instr->data, instr_data_len );
413 3306 : serialized_params += instr_data_len;
414 :
415 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L400 */
416 3306 : FD_STORE( fd_pubkey_t, serialized_params, ctx->txn_out->accounts.keys[ctx->instr->program_id] );
417 3306 : serialized_params += sizeof(fd_pubkey_t);
418 :
419 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-rc.0/program-runtime/src/serialization.rs#L522-L529 */
420 3306 : if( direct_account_pointers_in_program_input ) {
421 474 : ulong cur_vaddr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
422 474 : (ulong)(serialized_params - curr_serialized_params_start);
423 474 : ulong padding = FD_ULONG_ALIGN_UP( cur_vaddr, FD_BPF_ALIGN_OF_U128 ) - cur_vaddr;
424 474 : fd_memset( serialized_params, 0, padding );
425 474 : serialized_params += padding;
426 4644 : for( ushort i=0; i<ctx->instr->acct_cnt; i++ ) {
427 4170 : FD_STORE( ulong, serialized_params, acc_region_metas[i].vm_addr );
428 4170 : serialized_params += sizeof(ulong);
429 4170 : }
430 474 : }
431 :
432 : /* Write out the final region. */
433 3306 : ulong region_sz = (ulong)(serialized_params - curr_serialized_params_start);
434 3306 : new_input_mem_region( input_mem_regions, input_mem_regions_cnt, curr_serialized_params_start,
435 3306 : region_sz, region_sz, 1U, ULONG_MAX );
436 :
437 3306 : *serialized_bytes_written = (ulong)(serialized_params - serialized_params_start);
438 3306 : return FD_EXECUTOR_INSTR_SUCCESS;
439 3306 : }
440 :
441 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L594-L681 */
442 : static int
443 : fd_bpf_loader_input_deserialize_for_abiv1( fd_exec_instr_ctx_t * ctx,
444 : ulong const * pre_lens,
445 : uchar * buffer,
446 : ulong buffer_sz,
447 : int virtual_address_space_adjustments,
448 3225 : int direct_mapping ) {
449 : /* TODO: An optimization would be to skip ahead through non-writable accounts */
450 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L601 */
451 3225 : ulong start = 0UL;
452 :
453 3225 : uchar acc_idx_seen[256] = {0};
454 :
455 3225 : start += sizeof(ulong); // number of accounts
456 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L602-L679 */
457 11475 : for( ushort i=0; i<ctx->instr->acct_cnt; i++ ) {
458 8370 : uchar acc_idx = (uchar)ctx->instr->accounts[i].index_in_transaction;
459 :
460 8370 : start++; // position
461 :
462 : /* get the borrowed account
463 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L612-L613 */
464 8370 : fd_guarded_borrowed_account_t view_acc = {0};
465 8370 : FD_TRY_BORROW_INSTR_ACCOUNT_DEFAULT_ERR_CHECK( ctx, i, &view_acc );
466 :
467 8370 : if( FD_UNLIKELY( acc_idx_seen[acc_idx] ) ) {
468 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L610 */
469 3738 : start += 7UL;
470 4632 : } else {
471 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L614-L618 */
472 4632 : acc_idx_seen[acc_idx] = 1;
473 4632 : start += sizeof(uchar) // is_signer
474 4632 : + sizeof(uchar) // is_writable
475 4632 : + sizeof(uchar) // executable
476 4632 : + sizeof(uint) // original_data_len
477 4632 : + sizeof(fd_pubkey_t); // key
478 :
479 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L619-L621 */
480 :
481 4632 : fd_pubkey_t * owner = (fd_pubkey_t *)(buffer+start);
482 4632 : start += sizeof(fd_pubkey_t); // owner
483 :
484 4632 : ulong lamports = FD_LOAD( ulong, buffer+start );
485 4632 : if( lamports!=fd_borrowed_account_get_lamports( &view_acc ) ) {
486 9 : int err = fd_borrowed_account_set_lamports( &view_acc, lamports );
487 9 : if( FD_UNLIKELY( err ) ) {
488 0 : return err;
489 0 : }
490 9 : }
491 4632 : start += sizeof(ulong); // lamports
492 :
493 4632 : ulong post_len = FD_LOAD( ulong, buffer+start );
494 4632 : start += sizeof(ulong); // data length
495 :
496 4632 : ulong pre_len = pre_lens[i];
497 4632 : ulong alignment_offset = fd_ulong_align_up( pre_len, FD_BPF_ALIGN_OF_U128 ) - pre_len;
498 :
499 4632 : uchar * post_data = buffer+start;
500 :
501 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L640-L644 */
502 4632 : if( FD_UNLIKELY( fd_ulong_sat_sub( post_len, pre_len )>MAX_PERMITTED_DATA_INCREASE ||
503 4632 : post_len>MAX_PERMITTED_DATA_LENGTH ) ) {
504 96 : return FD_EXECUTOR_INSTR_ERR_INVALID_REALLOC;
505 96 : }
506 :
507 4536 : int can_data_be_changed_err = 0;
508 4536 : if( !virtual_address_space_adjustments ) {
509 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L645-L655 */
510 :
511 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L646-L648 */
512 2160 : if( FD_UNLIKELY( start + post_len > buffer_sz ) ) {
513 0 : return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
514 0 : }
515 :
516 : /* https://github.com/anza-xyz/agave/blob/v4.2.0-beta.0/program-runtime/src/serialization.rs#L648-L652 */
517 2160 : int can_data_be_resized_err = 0;
518 2160 : if( fd_borrowed_account_can_data_be_resized( &view_acc, post_len, &can_data_be_resized_err ) ) {
519 1650 : int set_data_err = fd_borrowed_account_set_data_from_slice( &view_acc, post_data, post_len );
520 1650 : if( FD_UNLIKELY( set_data_err ) ) {
521 0 : return set_data_err;
522 0 : }
523 1650 : } else {
524 510 : if( FD_UNLIKELY( fd_borrowed_account_get_data_len( &view_acc )!=post_len ||
525 510 : memcmp( fd_borrowed_account_get_data( &view_acc ), post_data, post_len ) ) ) {
526 24 : return can_data_be_resized_err;
527 24 : }
528 510 : }
529 :
530 2376 : } else if( !direct_mapping && fd_borrowed_account_can_data_be_changed( &view_acc, &can_data_be_changed_err ) ) {
531 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L657-L659 */
532 909 : if( FD_UNLIKELY( start + post_len > buffer_sz ) ) {
533 0 : return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
534 0 : }
535 :
536 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L655-L661 */
537 909 : int set_data_err = fd_borrowed_account_set_data_from_slice( &view_acc, post_data, post_len );
538 909 : if( FD_UNLIKELY( set_data_err ) ) {
539 0 : return set_data_err;
540 0 : }
541 1467 : } else if( fd_borrowed_account_get_data_len( &view_acc ) != post_len ) {
542 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L661-L663 */
543 156 : int set_data_length_err = fd_borrowed_account_set_data_length( &view_acc, post_len );
544 156 : if( FD_UNLIKELY( set_data_length_err ) ) {
545 0 : return set_data_length_err;
546 0 : }
547 156 : }
548 :
549 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L664-L672 */
550 4512 : if( !( virtual_address_space_adjustments && direct_mapping ) ) {
551 3255 : start += fd_ulong_sat_add( MAX_PERMITTED_DATA_INCREASE, fd_ulong_sat_add( pre_len, alignment_offset ) );
552 3255 : } else {
553 1257 : start += FD_BPF_ALIGN_OF_U128;
554 1257 : }
555 :
556 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L673 */
557 4512 : start += sizeof(ulong); // rent epoch
558 4512 : if( memcmp( fd_borrowed_account_get_owner( &view_acc ), owner, sizeof(fd_pubkey_t) ) ) {
559 0 : int err = fd_borrowed_account_set_owner( &view_acc, owner );
560 0 : if( FD_UNLIKELY( err ) ) {
561 0 : return err;
562 0 : }
563 0 : }
564 4512 : }
565 8370 : }
566 :
567 3105 : return FD_EXECUTOR_INSTR_SUCCESS;
568 3225 : }
569 :
570 : static int
571 : fd_bpf_loader_input_serialize_for_abiv0( fd_exec_instr_ctx_t * ctx,
572 : ulong * pre_lens,
573 : fd_vm_input_region_t * input_mem_regions,
574 : uint * input_mem_regions_cnt,
575 : fd_vm_acc_region_meta_t * acc_region_metas,
576 : int virtual_address_space_adjustments,
577 : int direct_mapping,
578 : ulong * instr_data_offset,
579 216 : ulong * serialized_bytes_written ) {
580 : /* Transaction sanitisation limits the number of instruction accounts to
581 : FD_TXN_ACCT_ADDR_MAX. */
582 216 : uchar acc_idx_seen[ FD_TXN_ACCT_ADDR_MAX ] = {0};
583 216 : ushort dup_acc_idx[ FD_TXN_ACCT_ADDR_MAX ] = {0};
584 :
585 : /* 16-byte aligned buffer:
586 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L61 */
587 216 : uchar * serialized_params = ctx->runtime->bpf_loader_serialization.frame[ ctx->runtime->instr.stack_sz-1UL ];
588 216 : uchar * serialized_params_start = serialized_params;
589 216 : uchar * curr_serialized_params_start = serialized_params;
590 216 : ulong curr_region_vaddr = 0UL;
591 :
592 216 : FD_STORE( ulong, serialized_params, ctx->instr->acct_cnt );
593 216 : serialized_params += sizeof(ulong);
594 :
595 684 : for( ushort i=0; i<ctx->instr->acct_cnt; i++ ) {
596 468 : uchar acc_idx = (uchar)ctx->instr->accounts[i].index_in_transaction;
597 468 : fd_pubkey_t const * acc = &ctx->txn_out->accounts.keys[acc_idx];
598 :
599 468 : if( FD_UNLIKELY( acc_idx_seen[acc_idx] && dup_acc_idx[acc_idx] != i ) ) {
600 : // Duplicate
601 108 : FD_STORE( uchar, serialized_params, (uchar)dup_acc_idx[acc_idx] );
602 108 : serialized_params += sizeof(uchar);
603 :
604 : /* Clone the account metadata from the original account
605 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L382 */
606 108 : acc_region_metas[i] = acc_region_metas[dup_acc_idx[acc_idx]];
607 360 : } else {
608 360 : acc_idx_seen[acc_idx] = 1;
609 360 : dup_acc_idx[acc_idx] = i;
610 :
611 360 : acc_region_metas[i].vm_addr = 0UL; /* abiv0 has no account pointer table */
612 :
613 360 : FD_STORE( uchar, serialized_params, FD_NON_DUP_MARKER );
614 360 : serialized_params += sizeof(uchar);
615 :
616 : /* Borrow the account
617 : https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L253 */
618 360 : fd_guarded_borrowed_account_t view_acc = {0};
619 360 : int err = fd_exec_instr_ctx_try_borrow_instr_account( ctx, i, &view_acc );
620 360 : if( FD_UNLIKELY( err ) ) {
621 0 : return err;
622 0 : }
623 :
624 360 : pre_lens[ i ] = view_acc.acc->data_len;
625 :
626 360 : uchar is_signer = (uchar)fd_instr_acc_is_signer_idx( ctx->instr, (uchar)i, NULL );
627 360 : FD_STORE( uchar, serialized_params, is_signer );
628 360 : serialized_params += sizeof(uchar);
629 :
630 360 : uchar is_writable = (uchar)fd_instr_acc_is_writable_idx( ctx->instr, (uchar)i );
631 360 : FD_STORE( uchar, serialized_params, is_writable );
632 360 : serialized_params += sizeof(uchar);
633 :
634 360 : fd_pubkey_t key = *acc;
635 360 : acc_region_metas[i].vm_key_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
636 360 : (ulong)(serialized_params - curr_serialized_params_start);
637 360 : FD_STORE( fd_pubkey_t, serialized_params, key );
638 360 : serialized_params += sizeof(fd_pubkey_t);
639 :
640 360 : ulong lamports = view_acc.acc->lamports;
641 360 : acc_region_metas[i].vm_lamports_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
642 360 : (ulong)(serialized_params - curr_serialized_params_start);
643 360 : FD_STORE( ulong, serialized_params, lamports );
644 360 : serialized_params += sizeof(ulong);
645 :
646 360 : ulong acc_data_len = view_acc.acc->data_len;
647 360 : FD_STORE( ulong, serialized_params, acc_data_len );
648 360 : serialized_params += sizeof(ulong);
649 :
650 : /* vm_data_addr: data is written immediately after the data_len field */
651 360 : acc_region_metas[i].vm_data_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
652 360 : (ulong)(serialized_params - curr_serialized_params_start);
653 :
654 360 : write_account( &view_acc, (uchar)i,
655 360 : &serialized_params, &curr_serialized_params_start,
656 360 : input_mem_regions, input_mem_regions_cnt, acc_region_metas, 1,
657 360 : virtual_address_space_adjustments, direct_mapping );
658 :
659 : /* write_account may have pushed a new region(s) */
660 360 : curr_region_vaddr = *input_mem_regions_cnt == 0U ? 0UL :
661 360 : input_mem_regions[*input_mem_regions_cnt-1U].vaddr_offset +
662 240 : input_mem_regions[*input_mem_regions_cnt-1U].address_space_reserved;
663 :
664 360 : fd_pubkey_t owner = *(fd_pubkey_t *)&view_acc.acc->owner;
665 360 : acc_region_metas[i].vm_owner_addr = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
666 360 : (ulong)(serialized_params - curr_serialized_params_start);
667 360 : FD_STORE( fd_pubkey_t, serialized_params, owner );
668 360 : serialized_params += sizeof(fd_pubkey_t);
669 :
670 360 : uchar is_executable = (uchar)view_acc.acc->executable;
671 360 : FD_STORE( uchar, serialized_params, is_executable );
672 360 : serialized_params += sizeof(uchar);
673 :
674 360 : FD_STORE( ulong, serialized_params, ULONG_MAX );
675 360 : serialized_params += sizeof(ulong);
676 360 : }
677 468 : }
678 :
679 216 : ulong instr_data_len = ctx->instr->data_sz;
680 216 : FD_STORE( ulong, serialized_params, instr_data_len );
681 216 : serialized_params += sizeof(ulong);
682 :
683 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L399 */
684 216 : *instr_data_offset = FD_VM_MEM_MAP_INPUT_REGION_START + curr_region_vaddr +
685 216 : (ulong)(serialized_params - curr_serialized_params_start);
686 :
687 216 : fd_memcpy( serialized_params, ctx->instr->data, instr_data_len );
688 216 : serialized_params += instr_data_len;
689 :
690 216 : FD_STORE( fd_pubkey_t, serialized_params, ctx->txn_out->accounts.keys[ctx->instr->program_id] );
691 216 : serialized_params += sizeof(fd_pubkey_t);
692 :
693 216 : *serialized_bytes_written = (ulong)(serialized_params - serialized_params_start);
694 :
695 216 : ulong region_sz = (ulong)(serialized_params - curr_serialized_params_start);
696 216 : new_input_mem_region( input_mem_regions, input_mem_regions_cnt, curr_serialized_params_start,
697 216 : region_sz, region_sz, 1U, ULONG_MAX );
698 :
699 216 : return FD_EXECUTOR_INSTR_SUCCESS;
700 216 : }
701 :
702 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L411 */
703 : static int
704 : fd_bpf_loader_input_deserialize_for_abiv0( fd_exec_instr_ctx_t * ctx,
705 : ulong const * pre_lens,
706 : uchar * input,
707 : ulong input_sz,
708 : int virtual_address_space_adjustments,
709 216 : int direct_mapping ) {
710 216 : uchar * input_cursor = input;
711 216 : uchar acc_idx_seen[256] = {0};
712 :
713 216 : input_cursor += sizeof(ulong);
714 :
715 684 : for( ushort i=0; i<ctx->instr->acct_cnt; i++ ) {
716 468 : uchar acc_idx = (uchar)ctx->instr->accounts[i].index_in_transaction;
717 :
718 468 : input_cursor++; /* is_dup */
719 468 : if( FD_UNLIKELY( acc_idx_seen[acc_idx] ) ) {
720 : /* no-op */
721 360 : } else {
722 360 : acc_idx_seen[acc_idx] = 1;
723 360 : input_cursor += sizeof(uchar) + /* is_signer */
724 360 : sizeof(uchar) + /* is_writable */
725 360 : sizeof(fd_pubkey_t); /* key */
726 :
727 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L427-L428 */
728 360 : fd_guarded_borrowed_account_t view_acc = {0};
729 360 : FD_TRY_BORROW_INSTR_ACCOUNT_DEFAULT_ERR_CHECK( ctx, i, &view_acc );
730 :
731 360 : ulong lamports = FD_LOAD( ulong, input_cursor );
732 360 : if( FD_UNLIKELY( fd_borrowed_account_get_lamports( &view_acc )!=lamports ) ) {
733 0 : int err = fd_borrowed_account_set_lamports( &view_acc, lamports );
734 0 : if( FD_UNLIKELY( err ) ) {
735 0 : return err;
736 0 : }
737 0 : }
738 :
739 360 : input_cursor += sizeof(ulong); /* lamports */
740 360 : input_cursor += sizeof(ulong); /* data length */
741 :
742 360 : ulong pre_len = pre_lens[i];
743 360 : uchar * post_data = input_cursor;
744 :
745 : /* https://github.com/anza-xyz/agave/blob/v4.2.0-beta.0/program-runtime/src/serialization.rs#L446-L450 */
746 360 : int can_data_be_changed_err = 0;
747 360 : if( !virtual_address_space_adjustments ) {
748 120 : int can_data_be_resized_err = 0;
749 120 : if( fd_borrowed_account_can_data_be_resized( &view_acc, pre_len, &can_data_be_resized_err ) ) {
750 96 : int set_data_err = fd_borrowed_account_set_data_from_slice( &view_acc, post_data, pre_len );
751 96 : if( FD_UNLIKELY( set_data_err ) ) {
752 0 : return set_data_err;
753 0 : }
754 96 : } else if( fd_borrowed_account_get_data_len( &view_acc ) != pre_len ||
755 24 : memcmp( post_data, fd_borrowed_account_get_data( &view_acc ), pre_len ) ) {
756 0 : return can_data_be_resized_err;
757 0 : }
758 240 : } else if( !direct_mapping && fd_borrowed_account_can_data_be_changed( &view_acc, &can_data_be_changed_err ) ) {
759 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L453-L459 */
760 96 : int set_data_err = fd_borrowed_account_set_data_from_slice( &view_acc, post_data, pre_len );
761 96 : if( FD_UNLIKELY( set_data_err ) ) {
762 0 : return set_data_err;
763 0 : }
764 144 : } else if( fd_borrowed_account_get_data_len( &view_acc ) != pre_len ) {
765 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L459-L461 */
766 0 : int set_data_length_err = fd_borrowed_account_set_data_length( &view_acc, pre_len );
767 0 : if( FD_UNLIKELY( set_data_length_err ) ) {
768 0 : return set_data_length_err;
769 0 : }
770 0 : }
771 :
772 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L462-L464 */
773 360 : if( !( virtual_address_space_adjustments && direct_mapping ) ) {
774 240 : input_cursor += pre_len;
775 240 : }
776 360 : input_cursor += sizeof(fd_pubkey_t) + /* owner */
777 360 : sizeof(uchar) + /* executable */
778 360 : sizeof(ulong); /* rent_epoch*/
779 360 : }
780 468 : }
781 :
782 216 : if( FD_UNLIKELY( input_cursor>input+input_sz ) ) {
783 0 : return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
784 0 : }
785 :
786 216 : return 0;
787 216 : }
788 :
789 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L222 */
790 : int
791 : fd_bpf_loader_input_serialize_parameters( fd_exec_instr_ctx_t * instr_ctx,
792 : ulong * pre_lens,
793 : fd_vm_input_region_t * input_mem_regions,
794 : uint * input_mem_regions_cnt,
795 : fd_vm_acc_region_meta_t * acc_region_metas,
796 : int virtual_address_space_adjustments,
797 : int direct_mapping,
798 : int direct_account_pointers_in_program_input,
799 : uchar is_deprecated,
800 : ulong * instr_data_offset,
801 3522 : ulong * serialized_bytes_written ) {
802 :
803 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L236-L239 */
804 3522 : ulong num_ix_accounts = instr_ctx->instr->acct_cnt;
805 3522 : if( FD_UNLIKELY( num_ix_accounts>FD_TXN_INSTR_ACCT_MAX ) ) {
806 0 : return FD_EXECUTOR_INSTR_ERR_MAX_ACCS_EXCEEDED;
807 0 : }
808 :
809 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L265-L285 */
810 3522 : if( FD_UNLIKELY( is_deprecated ) ) {
811 216 : return fd_bpf_loader_input_serialize_for_abiv0( instr_ctx, pre_lens,
812 216 : input_mem_regions, input_mem_regions_cnt,
813 216 : acc_region_metas, virtual_address_space_adjustments,
814 216 : direct_mapping, instr_data_offset, serialized_bytes_written );
815 3306 : } else {
816 3306 : return fd_bpf_loader_input_serialize_for_abiv1( instr_ctx, pre_lens,
817 3306 : input_mem_regions, input_mem_regions_cnt,
818 3306 : acc_region_metas, virtual_address_space_adjustments,
819 3306 : direct_mapping, direct_account_pointers_in_program_input,
820 3306 : instr_data_offset, serialized_bytes_written );
821 3306 : }
822 3522 : }
823 :
824 : /* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.3/program-runtime/src/serialization.rs#L288-L317 */
825 : int
826 : fd_bpf_loader_input_deserialize_parameters( fd_exec_instr_ctx_t * ctx,
827 : ulong const * pre_lens,
828 : uchar * input,
829 : ulong input_sz,
830 : int virtual_address_space_adjustments,
831 : int direct_mapping,
832 3441 : uchar is_deprecated ) {
833 3441 : if( FD_UNLIKELY( is_deprecated ) ) {
834 216 : return fd_bpf_loader_input_deserialize_for_abiv0(
835 216 : ctx, pre_lens, input, input_sz, virtual_address_space_adjustments, direct_mapping );
836 3225 : } else {
837 3225 : return fd_bpf_loader_input_deserialize_for_abiv1(
838 3225 : ctx, pre_lens, input, input_sz, virtual_address_space_adjustments, direct_mapping );
839 3225 : }
840 3441 : }
|