@@ -1719,12 +1719,14 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
1719
1719
mod tests {
1720
1720
use super :: * ;
1721
1721
use crate :: {
1722
+ disassembler:: disassemble_instruction,
1722
1723
program:: { BuiltinProgram , FunctionRegistry , SBPFVersion } ,
1724
+ static_analysis:: CfgNode ,
1723
1725
syscalls,
1724
1726
vm:: TestContextObject ,
1725
1727
} ;
1726
1728
use byteorder:: { ByteOrder , LittleEndian } ;
1727
- use std:: sync:: Arc ;
1729
+ use std:: { collections :: BTreeMap , sync:: Arc } ;
1728
1730
1729
1731
#[ test]
1730
1732
fn test_runtime_environment_slots ( ) {
@@ -1838,35 +1840,45 @@ mod tests {
1838
1840
<= MACHINE_CODE_PER_INSTRUCTION_METER_CHECKPOINT
1839
1841
) ;
1840
1842
1843
+ let mut cfg_nodes = BTreeMap :: new ( ) ;
1844
+ cfg_nodes. insert (
1845
+ 8 ,
1846
+ CfgNode {
1847
+ label : std:: string:: String :: from ( "label" ) ,
1848
+ ..CfgNode :: default ( )
1849
+ } ,
1850
+ ) ;
1851
+
1841
1852
for sbpf_version in [ SBPFVersion :: V0 , SBPFVersion :: V3 ] {
1853
+ println ! ( "opcode;machine_code_length_per_instruction;assembly" ) ;
1842
1854
let empty_program_machine_code_length =
1843
1855
empty_program_machine_code_length_per_version[ sbpf_version as usize ] ;
1844
1856
1845
1857
for mut opcode in 0x00 ..=0xFF {
1846
1858
let ( registers, immediate) = match opcode {
1847
- 0x85 | 0x8D => ( 0x88 , 8 ) ,
1848
- 0x86 => {
1859
+ 0x85 if !sbpf_version. static_syscalls ( ) => ( 0x00 , Some ( 8 ) ) ,
1860
+ 0x85 if sbpf_version. static_syscalls ( ) => ( 0x00 , None ) ,
1861
+ 0x8D => ( 0x88 , Some ( 0 ) ) ,
1862
+ 0x95 if sbpf_version. static_syscalls ( ) => ( 0x00 , Some ( 1 ) ) ,
1863
+ 0xE5 if !sbpf_version. static_syscalls ( ) => {
1849
1864
// Put external function calls on a separate loop iteration
1850
1865
opcode = 0x85 ;
1851
- ( 0x00 , 0x91020CDD )
1866
+ ( 0x00 , Some ( 0x91020CDD ) )
1852
1867
}
1853
- 0x87 => {
1868
+ 0xF5 => {
1854
1869
// Put invalid function calls on a separate loop iteration
1855
1870
opcode = 0x85 ;
1856
- ( 0x88 , 0x91020CDD )
1871
+ ( 0x00 , Some ( 0x91020CD0 ) )
1857
1872
}
1858
- 0x95 => {
1859
- // Put a valid syscall
1860
- ( 0 , 1 )
1861
- }
1862
- 0xD4 | 0xDC => ( 0x88 , 16 ) ,
1863
- _ => ( 0x88 , 0xFFFFFFFF ) ,
1873
+ 0xD4 | 0xDC => ( 0x88 , Some ( 16 ) ) ,
1874
+ _ => ( 0x88 , Some ( 0xFFFFFFFF ) ) ,
1864
1875
} ;
1865
1876
for pc in 0 ..INSTRUCTION_COUNT {
1866
1877
prog[ pc * ebpf:: INSN_SIZE ] = opcode;
1867
1878
prog[ pc * ebpf:: INSN_SIZE + 1 ] = registers;
1868
- prog[ pc * ebpf:: INSN_SIZE + 2 ] = 0xFF ;
1869
- prog[ pc * ebpf:: INSN_SIZE + 3 ] = 0xFF ;
1879
+ let offset = 7_u16 . wrapping_sub ( pc as u16 ) ;
1880
+ LittleEndian :: write_u16 ( & mut prog[ pc * ebpf:: INSN_SIZE + 2 ..] , offset) ;
1881
+ let immediate = immediate. unwrap_or_else ( || 7_u32 . wrapping_sub ( pc as u32 ) ) ;
1870
1882
LittleEndian :: write_u32 ( & mut prog[ pc * ebpf:: INSN_SIZE + 4 ..] , immediate) ;
1871
1883
}
1872
1884
let config = Config {
@@ -1900,12 +1912,19 @@ mod tests {
1900
1912
( machine_code_length_per_instruction + 0.5 ) as usize
1901
1913
<= MAX_MACHINE_CODE_LENGTH_PER_INSTRUCTION
1902
1914
) ;
1903
- /*println!("opcode={:02X} machine_code_length_per_instruction={}", opcode, machine_code_length_per_instruction);
1904
- let analysis = crate::static_analysis::Analysis::from_executable(&executable).unwrap();
1905
- {
1906
- let stdout = std::io::stdout();
1907
- analysis.disassemble(&mut stdout.lock()).unwrap();
1908
- }*/
1915
+ let insn = ebpf:: get_insn_unchecked ( & prog, 0 ) ;
1916
+ let assembly = disassemble_instruction (
1917
+ & insn,
1918
+ 0 ,
1919
+ & cfg_nodes,
1920
+ executable. get_function_registry ( ) ,
1921
+ executable. get_loader ( ) ,
1922
+ executable. get_sbpf_version ( ) ,
1923
+ ) ;
1924
+ println ! (
1925
+ "{:02X};{:>7.3};{}" ,
1926
+ opcode, machine_code_length_per_instruction, assembly
1927
+ ) ;
1909
1928
}
1910
1929
}
1911
1930
}
0 commit comments