Skip to content

Commit

Permalink
flamenco, vm: halve size of physical stack region
Browse files Browse the repository at this point in the history
  • Loading branch information
topointon-jump committed Oct 10, 2024
1 parent 161f74e commit 832f6a3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
dump/test-vectors/syscall/fixtures/cpi/cpi_callee_prog_in_txn_check.fix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c21493260e92093295f69a629426bd90468a2e84
06227823191776a59cb4c097fdb0780d7ba78ee9
2 changes: 1 addition & 1 deletion src/flamenco/vm/fd_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ FD_PROTOTYPES_BEGIN
integer power of 2. FOOTPRINT is a multiple of align.
These are provided to facilitate compile time declarations. */
#define FD_VM_ALIGN (8UL )
#define FD_VM_FOOTPRINT (789408UL)
#define FD_VM_FOOTPRINT (527264UL)

/* fd_vm_{align,footprint} give the needed alignment and footprint
of a memory region suitable to hold an fd_vm_t.
Expand Down
4 changes: 2 additions & 2 deletions src/flamenco/vm/fd_vm_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ FD_PROTOTYPES_END
/* VM stack constants */

#define FD_VM_STACK_FRAME_MAX (64UL)
#define FD_VM_STACK_FRAME_SZ (0x1000UL) /* FIXME: SHOULD THIS MACH FD_VM_STACK_FRAME_SIZE BELOW? */
#define FD_VM_STACK_FRAME_SZ FD_VM_STACK_FRAME_SIZE
#define FD_VM_STACK_GUARD_SZ (0x1000UL)
#define FD_VM_STACK_MAX (FD_VM_STACK_FRAME_MAX*(FD_VM_STACK_FRAME_SZ+FD_VM_STACK_GUARD_SZ))
#define FD_VM_STACK_MAX (FD_VM_STACK_FRAME_MAX*(FD_VM_STACK_FRAME_SZ))

/* VM heap constants */

Expand Down
22 changes: 17 additions & 5 deletions src/flamenco/vm/fd_vm_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,28 @@ fd_vm_mem_haddr( fd_vm_t const * vm,
ulong vaddr_hi = vaddr >> 32;
ulong region = fd_ulong_min( vaddr_hi, 5UL );
ulong offset = vaddr & 0xffffffffUL;
ulong region_sz = (ulong)vm_region_sz[ region ];
ulong sz_max = region_sz - fd_ulong_min( offset, region_sz );

/* Stack memory regions have 4kB unmapped "gaps" in-between each frame.
https://github.com/solana-labs/rbpf/blob/b503a1867a9cfa13f93b4d99679a17fe219831de/src/memory_region.rs#L141
https://github.com/solana-labs/rbpf/blob/b503a1867a9cfa13f93b4d99679a17fe219831de/src/memory_region.rs#L141
*/
if( FD_UNLIKELY( ( region == 2 ) && !!( vaddr & 0x1000 ) ) ) {
return sentinel;
if ( FD_UNLIKELY( region == 2UL ) ) {
/* If an access starts in a gap region, that is an access violation */
if ( !!( vaddr & 0x1000 ) ) {
return sentinel;
}

/* To account for the fact that we have gaps in the virtual address space but not in the
physical address space, we need to subtract from the offset the size of all the virtual
gap frames underneath it.
https://github.com/solana-labs/rbpf/blob/b503a1867a9cfa13f93b4d99679a17fe219831de/src/memory_region.rs#L147-L149 */
ulong gap_mask = 0xFFFFFFFFFFFFF000;
offset = ( ( offset & gap_mask ) >> 1 ) | ( offset & ~gap_mask );
}

ulong region_sz = (ulong)vm_region_sz[ region ];
ulong sz_max = region_sz - fd_ulong_min( offset, region_sz );

if( region==4UL ) {
return fd_vm_find_input_mem_region( vm, offset, sz, write, sentinel, is_multi_region );
}
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/vm/test_vm_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ FD_STATIC_ASSERT( FD_VM_SHADOW_REG_CNT== 4UL, vm_reg );
FD_STATIC_ASSERT( FD_VM_STACK_FRAME_MAX==64UL, vm_stack );
FD_STATIC_ASSERT( FD_VM_STACK_FRAME_SZ ==0x1000UL, vm_stack );
FD_STATIC_ASSERT( FD_VM_STACK_GUARD_SZ ==0x1000UL, vm_stack );
FD_STATIC_ASSERT( FD_VM_STACK_MAX ==64UL*0x2000UL, vm_stack );
FD_STATIC_ASSERT( FD_VM_STACK_MAX ==64UL*0x1000UL, vm_stack );

FD_STATIC_ASSERT( FD_VM_HEAP_DEFAULT== 32UL*1024UL, vm_heap );
FD_STATIC_ASSERT( FD_VM_HEAP_MAX ==256UL*1024UL, vm_heap );
Expand Down

0 comments on commit 832f6a3

Please sign in to comment.