Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heap_size type to be consistent with request instruction #33354

Merged
merged 4 commits into from
Sep 25, 2023

Conversation

tao-stones
Copy link
Contributor

Problem

RequestHeapFrame(u32) requests heap size as u32, ComputeBudget stores it as usize, it also as into u64 in some loader functions.

Summary of Changes

  • ComputeBudget stores heap_size in same type as instruction defines it
  • replace as with try_from

Fixes #

@@ -171,7 +171,7 @@ impl ComputeBudget {
curve25519_ristretto_multiply_cost: 2_208,
curve25519_ristretto_msm_base_cost: 2303,
curve25519_ristretto_msm_incremental_cost: 788,
heap_size: solana_sdk::entrypoint::HEAP_LENGTH,
heap_size: u32::try_from(solana_sdk::entrypoint::HEAP_LENGTH).unwrap(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this unwrap should be safe since we are converting from a const, otherwise it should panic.

@@ -281,7 +281,7 @@ macro_rules! create_vm {
>::zero_filled(stack_size);
let mut heap = solana_rbpf::aligned_memory::AlignedMemory::<
{ solana_rbpf::ebpf::HOST_ALIGN },
>::zero_filled(heap_size);
>::zero_filled(usize::try_from(heap_size).unwrap());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this unwrap() may fail IF target is 16-bit and heap_size is too large for that. In that case, panic is proper imo

let mut stack = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(config.stack_size());
let mut heap = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(compute_budget.heap_size);
let mut heap = AlignedMemory::<{ ebpf::HOST_ALIGN }>::zero_filled(
usize::try_from(compute_budget.heap_size).unwrap(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit, but think the change overall is good

programs/bpf_loader/src/lib.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #33354 (85d985d) into master (3b1cbae) will decrease coverage by 0.1%.
The diff coverage is 100.0%.

@@            Coverage Diff            @@
##           master   #33354     +/-   ##
=========================================
- Coverage    81.9%    81.9%   -0.1%     
=========================================
  Files         796      796             
  Lines      215861   215858      -3     
=========================================
- Hits       176938   176927     -11     
- Misses      38923    38931      +8     

@tao-stones tao-stones merged commit 57e78a1 into solana-labs:master Sep 25, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants