fn relocate(compilation: &mut Compilation, relocations: &[Vec<Relocation>]) {
    // The relocations are relative to the relocation's address plus four bytes
    // TODO: Support architectures other than x64, and other reloc kinds.
    for (i, function_relocs) in relocations.iter().enumerate() {
        for r in function_relocs {
            let target_func_address: isize = match r.reloc_target {
                RelocationTarget::UserFunc(index) => compilation.functions[index].as_ptr() as isize,
                RelocationTarget::GrowMemory => grow_memory as isize,
                RelocationTarget::CurrentMemory => current_memory as isize,
            };

            let body = &mut compilation.functions[i];
            match r.reloc {
                Reloc::Abs8 => unsafe {
                    let reloc_address = body.as_mut_ptr().offset(r.offset as isize) as i64;
                    let reloc_addend = r.addend;
                    let reloc_abs = target_func_address as i64 + reloc_addend;
                    write_unaligned(reloc_address as *mut i64, reloc_abs);
                },
                Reloc::X86PCRel4 => unsafe {
                    let reloc_address = body.as_mut_ptr().offset(r.offset as isize) as isize;
                    let reloc_addend = r.addend as isize;
                    // TODO: Handle overflow.
                    let reloc_delta_i32 =
                        (target_func_address - reloc_address + reloc_addend) as i32;
                    write_unaligned(reloc_address as *mut i32, reloc_delta_i32);
                },
                _ => panic!("unsupported reloc kind"),
            }
        }
    }
}
/// Performs the relocations inside the function bytecode, provided the necessary metadata
Performs the relocations inside the function bytecode, provided the necessary metadata
Performs the relocations inside the function bytecode provided the necessary metadata
fn relocate(compilation: &mut Compilation, relocations: &[Vec<Relocation>]) {
    // The relocations are relative to the relocation's address plus four bytes
    // TODO: Support architectures other than x64, and other reloc kinds.
    for (i, function_relocs) in relocations.iter().enumerate() {
        for r in function_relocs {
            let target_func_address: isize = match r.reloc_target {
                RelocationTarget::UserFunc(index) => compilation.functions[index].as_ptr() as isize,
                RelocationTarget::GrowMemory => grow_memory as isize,
                RelocationTarget::CurrentMemory => current_memory as isize,
            };
            let body = &mut compilation.functions[i];
            match r.reloc {
                Reloc::Abs8 => unsafe {
                    let reloc_address = body.as_mut_ptr().offset(r.offset as isize) as i64;
                    let reloc_addend = r.addend;
                    let reloc_abs = target_func_address as i64 + reloc_addend;
                    write_unaligned(reloc_address as *mut i64, reloc_abs);
                },
                Reloc::X86PCRel4 => unsafe {
                    let reloc_address = body.as_mut_ptr().offset(r.offset as isize) as isize;
                    let reloc_addend = r.addend as isize;
                    // TODO: Handle overflow.
                    let reloc_delta_i32 =
                        (target_func_address - reloc_address + reloc_addend) as i32;
                    write_unaligned(reloc_address as *mut i32, reloc_delta_i32);
                },
                _ => panic!("unsupported reloc kind"),
            }
        }
    }
}
fn relocate ( compilation : & mut Compilation , relocations : & [ Vec < Relocation > ] ) { // The relocations are relative to the relocation's address plus four bytes // TODO: Support architectures other than x64, and other reloc kinds. for ( i , function_relocs ) in relocations . iter ( ) . enumerate ( ) { for r in function_relocs { let target_func_address : isize = match r . reloc_target { RelocationTarget :: UserFunc ( index ) => compilation . functions [ index ] . as_ptr ( ) as isize , RelocationTarget :: GrowMemory => grow_memory as isize , RelocationTarget :: CurrentMemory => current_memory as isize , } ; let body = & mut compilation . functions [ i ] ; match r . reloc { Reloc :: Abs8 => unsafe { let reloc_address = body . as_mut_ptr ( ) . offset ( r . offset as isize ) as i64 ; let reloc_addend = r . addend ; let reloc_abs = target_func_address as i64 + reloc_addend ; write_unaligned ( reloc_address as * mut i64 , reloc_abs ) ; } , Reloc :: X86PCRel4 => unsafe { let reloc_address = body . as_mut_ptr ( ) . offset ( r . offset as isize ) as isize ; let reloc_addend = r . addend as isize ; // TODO: Handle overflow. let reloc_delta_i32 = ( target_func_address - reloc_address + reloc_addend ) as i32 ; write_unaligned ( reloc_address as * mut i32 , reloc_delta_i32 ) ; } , _ => panic ! ( " " ) , } } } }
Performs the relocations inside the function bytecode, provided the necessary metadata
Performs the relocations inside the function bytecode provided the necessary metadata
compilation
&mut Compilation
relocations
&[Vec<Relocation>]
compilation
&mut Compilation
relocations
&[Vec<Relocation>]