fn relocate(
        &mut self,
        entry: &elfloader::Rela<elfloader::P64>,
    ) -> Result<(), elfloader::ElfLoaderErr> {
        // Get the pointer to where the relocation happens in the
        // memory where we loaded the headers
        // The forumla for this is our offset where the kernel is starting,
        // plus the offset of the entry to jump to the code piece
        let addr = self.offset + entry.get_offset();

        if addr >= self.read_only_offset {
            // Don't relocate anything in write-able section, already done
            return Ok(());
        }

        // Translate `addr` into a kernel vaddr we can write to:
        let (paddr, _rights) = self.vspace.resolve(addr).expect("Can't resolve address");
        let kernel_addr: VAddr = paddr_to_kernel_vaddr(paddr);

        debug!(
            "ELF relocation paddr {:#x} kernel_addr {:#x}",
            paddr, kernel_addr
        );

        use elfloader::TypeRela64;
        if let TypeRela64::R_RELATIVE = TypeRela64::from(entry.get_type()) {
            // This is a relative relocation of a 64 bit value, we add the offset (where we put our
            // binary in the vspace) to the addend and we're done:
            unsafe {
                // Scary unsafe changing stuff in random memory locations based on
                // ELF binary values weee!
                *(kernel_addr.as_mut_ptr::<u64>()) = self.offset.as_u64() + entry.get_addend();
            }
            Ok(())
        } else {
            Err(elfloader::ElfLoaderErr::UnsupportedRelocationEntry)
        }
    }
/// Relocating the symbols.
///
/// Since the binary is a position independent executable that is 'statically' linked
/// with all dependencies we only expect to get relocations of type RELATIVE.
/// Otherwise, the build would be broken or you got a garbage ELF file.
/// We return an error in this case.
Relocating the symbols.
Since the binary is a position independent executable that is 'statically' linked
with all dependencies we only expect to get relocations of type RELATIVE.
Otherwise, the build would be broken or you got a garbage ELF file.
We return an error in this case.
Relocating the symbols . Since the binary is a position independent executable that is ' statically ' linked with all dependencies we only expect to get relocations of type RELATIVE . Otherwise the build would be broken or you got a garbage ELF file . We return an error in this case .
fn relocate(
        &mut self,
        entry: &elfloader::Rela<elfloader::P64>,
    ) -> Result<(), elfloader::ElfLoaderErr> {
        // Get the pointer to where the relocation happens in the
        // memory where we loaded the headers
        // The forumla for this is our offset where the kernel is starting,
        // plus the offset of the entry to jump to the code piece
        let addr = self.offset + entry.get_offset();
        if addr >= self.read_only_offset {
            // Don't relocate anything in write-able section, already done
            return Ok(());
        }
        // Translate `addr` into a kernel vaddr we can write to:
        let (paddr, _rights) = self.vspace.resolve(addr).expect("Can't resolve address");
        let kernel_addr: VAddr = paddr_to_kernel_vaddr(paddr);
        debug!(
            "ELF relocation paddr {:#x} kernel_addr {:#x}",
            paddr, kernel_addr
        );
        use elfloader::TypeRela64;
        if let TypeRela64::R_RELATIVE = TypeRela64::from(entry.get_type()) {
            // This is a relative relocation of a 64 bit value, we add the offset (where we put our
            // binary in the vspace) to the addend and we're done:
            unsafe {
                // Scary unsafe changing stuff in random memory locations based on
                // ELF binary values weee!
                *(kernel_addr.as_mut_ptr::<u64>()) = self.offset.as_u64() + entry.get_addend();
            }
            Ok(())
        } else {
            Err(elfloader::ElfLoaderErr::UnsupportedRelocationEntry)
        }
    }
fn relocate ( & mut self , entry : & elfloader :: Rela < elfloader :: P64 > , ) -> Result < ( ) , elfloader :: ElfLoaderErr > { // Get the pointer to where the relocation happens in the // memory where we loaded the headers // The forumla for this is our offset where the kernel is starting, // plus the offset of the entry to jump to the code piece let addr = self . offset + entry . get_offset ( ) ; if addr >= self . read_only_offset { // Don't relocate anything in write-able section, already done return Ok ( ( ) ) ; } // Translate `addr` into a kernel vaddr we can write to: let ( paddr , _rights ) = self . vspace . resolve ( addr ) . expect ( " " ) ; let kernel_addr : VAddr = paddr_to_kernel_vaddr ( paddr ) ; debug ! ( " " paddr kernel_addr ) ; use elfloader :: TypeRela64 ; if let TypeRela64 :: R_RELATIVE = TypeRela64 :: from ( entry . get_type ( ) ) { // This is a relative relocation of a 64 bit value, we add the offset (where we put our // binary in the vspace) to the addend and we're done: unsafe { // Scary unsafe changing stuff in random memory locations based on // ELF binary values weee! * ( kernel_addr . as_mut_ptr :: < u64 > ( ) ) = self . offset . as_u64 ( ) + entry . get_addend ( ) ; } Ok ( ( ) ) } else { Err ( elfloader :: ElfLoaderErr :: UnsupportedRelocationEntry ) } }
Relocating the symbols.
Relocating the symbols .
&mut self
entry
&elfloader::Rela<elfloader::P64>
&mut self
entry
&elfloader::Rela<elfloader::P64>