Research Article

Extension of Research on Security as a Service for VMs in IaaS Platform

Algorithm 2

GuestCodeRelocResv.
Input: hdr, sechdrs, relsec, symindex,strtab, guest_load_addr
Output: Relocated resolved code in memory
rel ⟵ hdr + sechdrs[relsec].sh_offset;
for i ⟵ 0 to sechdrs[relsec].sh_size/sizeof(rel) do
target_sec ⟵ sechdrs[relsec].sh_info;
loc ⟵ hdr + sechdrs[target_sec].sh_offset + rel[i].r_offset;
  fake_loc⟵guest_load_addr +
   sech drs[target_sec].sh_offset + rel[i].r_offset;
  sym ⟵ hdr + sechdrs[symindex].sh_offset +
   ELF_R_SYM(rel[i].r_info);
symname ⟵ strtab + sym->st_name;
val ⟵ sym->st_value + rel[i].r_addend;
rel_type ⟵ ELF_R_TYPE(rel[i].r_info);
switch rel_type do
  case rel_type = R_X86_64_64(u64)loc ⟵ val;
  case rel_type = R_X86_64_32(u32)loc ⟵ val;
  case rel_type = R_X86_64_32S(s32)loc ⟵ val;
  case rel_type = R_X86_64_PC32 val ⟵ val-(u64)fake_loc; (u32)loc ⟵ val;
   otherwise
    Output Unknown;
  endsw
endsw
end