-
Notifications
You must be signed in to change notification settings - Fork 127
fix: improve write_program logic; add tests #579
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
Merged
+331
−5
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /// Minimal valid SBF ELF (352 bytes) — just returns SUCCESS (r0=0). | ||
| /// | ||
| /// Used as a placeholder in `init_programdata_account` to satisfy LiteSVM's | ||
| /// ELF validation when bootstrapping program accounts. This gets stripped | ||
| /// by `write_program_data_account_with_offset` before actual program data | ||
| /// is written. | ||
| /// | ||
| /// Layout (352 bytes): | ||
| /// 0x000..0x040 ELF64 header (ET_DYN, EM_SBPF=0x107, SBPFv0, entry=0x78) | ||
| /// 0x040..0x078 1× PT_LOAD program header (text at 0x78, 16 bytes, RX) | ||
| /// 0x078..0x088 .text section: mov64 r0,0 ; exit | ||
| /// 0x088..0x099 .shstrtab contents: "\0.text\0.shstrtab\0" | ||
| /// 0x099..0x0A0 padding (7 bytes, align section headers to 8) | ||
| /// 0x0A0..0x0E0 Section header [0]: SHT_NULL | ||
| /// 0x0E0..0x120 Section header [1]: .text | ||
| /// 0x120..0x160 Section header [2]: .shstrtab | ||
| pub const NOOP_PROGRAM_ELF: &[u8] = &[ | ||
| // ===== ELF64 Header (64 bytes) ===== | ||
| // e_ident: EI_MAG0..3, EI_CLASS=2(64-bit), EI_DATA=1(LE), EI_VERSION=1, | ||
| // EI_OSABI=0, padding | ||
| 0x7F, b'E', b'L', b'F', 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| // e_type=ET_DYN(3), e_machine=EM_SBPF(0x107) | ||
| 0x03, 0x00, 0x07, 0x01, // e_version=1 | ||
| 0x01, 0x00, 0x00, 0x00, // e_entry=0x78 (start of .text) | ||
| 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| // e_phoff=0x40 (program headers right after ELF header) | ||
| 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| // e_shoff=0xA0 (section headers at offset 160) | ||
| 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // e_flags=0 (SBPFv0) | ||
| 0x00, 0x00, 0x00, 0x00, // e_ehsize=64 | ||
| 0x40, 0x00, // e_phentsize=56 | ||
| 0x38, 0x00, // e_phnum=1 | ||
| 0x01, 0x00, // e_shentsize=64 | ||
| 0x40, 0x00, // e_shnum=3 | ||
| 0x03, 0x00, // e_shstrndx=2 | ||
| 0x02, 0x00, // ===== Program Header (56 bytes) ===== | ||
| // p_type=PT_LOAD(1) | ||
| 0x01, 0x00, 0x00, 0x00, // p_flags=PF_R|PF_X(5) | ||
| 0x05, 0x00, 0x00, 0x00, // p_offset=0x78 | ||
| 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_vaddr=0x78 | ||
| 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_paddr=0x78 | ||
| 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_filesz=16 | ||
| 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_memsz=16 | ||
| 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // p_align=8 | ||
| 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| // ===== .text section (16 bytes at 0x78) ===== | ||
| // mov64 r0, 0 (opcode=0xb7, dst=r0, src=0, off=0, imm=0) | ||
| 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| // exit (opcode=0x95, dst=0, src=0, off=0, imm=0) | ||
| 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| // ===== .shstrtab contents (17 bytes at 0x88) ===== | ||
| // "\0.text\0.shstrtab\0" | ||
| 0x00, b'.', b't', b'e', b'x', b't', 0x00, b'.', b's', b'h', b's', b't', b'r', b't', b'a', b'b', | ||
| 0x00, // ===== Padding to align section headers to 8 bytes (7 bytes) ===== | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| // ===== Section Header [0]: SHT_NULL (64 bytes at 0xA0) ===== | ||
| 0x00, 0x00, 0x00, 0x00, // sh_name=0 | ||
| 0x00, 0x00, 0x00, 0x00, // sh_type=SHT_NULL(0) | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_flags=0 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addr=0 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_offset=0 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_size=0 | ||
| 0x00, 0x00, 0x00, 0x00, // sh_link=0 | ||
| 0x00, 0x00, 0x00, 0x00, // sh_info=0 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addralign=0 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_entsize=0 | ||
| // ===== Section Header [1]: .text (64 bytes at 0xE0) ===== | ||
| 0x01, 0x00, 0x00, 0x00, // sh_name=1 (index into .shstrtab: ".text") | ||
| 0x01, 0x00, 0x00, 0x00, // sh_type=SHT_PROGBITS(1) | ||
| 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_flags=SHF_ALLOC|SHF_EXECINSTR(6) | ||
| 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addr=0x78 | ||
| 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_offset=0x78 | ||
| 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_size=16 | ||
| 0x00, 0x00, 0x00, 0x00, // sh_link=0 | ||
| 0x00, 0x00, 0x00, 0x00, // sh_info=0 | ||
| 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addralign=8 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_entsize=0 | ||
| // ===== Section Header [2]: .shstrtab (64 bytes at 0x120) ===== | ||
| 0x07, 0x00, 0x00, 0x00, // sh_name=7 (index into .shstrtab: ".shstrtab") | ||
| 0x03, 0x00, 0x00, 0x00, // sh_type=SHT_STRTAB(3) | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_flags=0 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addr=0 | ||
| 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_offset=0x88 | ||
| 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_size=17 | ||
| 0x00, 0x00, 0x00, 0x00, // sh_link=0 | ||
| 0x00, 0x00, 0x00, 0x00, // sh_info=0 | ||
| 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_addralign=1 | ||
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sh_entsize=0 | ||
| ]; | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_noop_program_elf_size() { | ||
| assert_eq!(NOOP_PROGRAM_ELF.len(), 352); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️