model/elf-cache.cc
changeset 669 cb779a3844be
parent 482 8ae3af4c090a
child 678 8c9aece65bf9
equal deleted inserted replaced
668:06b23f4d262c 669:cb779a3844be
   161   ElfW (Dyn) * dyn = 0;
   161   ElfW (Dyn) * dyn = 0;
   162   long base_address = GetBaseAddress (phdr, header->e_phnum);
   162   long base_address = GetBaseAddress (phdr, header->e_phnum);
   163 
   163 
   164   // find DYNAMIC and fill DataSection
   164   // find DYNAMIC and fill DataSection
   165   struct FileInfo fileInfo;
   165   struct FileInfo fileInfo;
       
   166 
       
   167   if (header->e_type != ET_DYN)
       
   168     {
       
   169       fileInfo.p_vaddr = -1;
       
   170       return fileInfo;
       
   171     }
       
   172 
   166   ElfW (Phdr) * pt_load_rw = 0;
   173   ElfW (Phdr) * pt_load_rw = 0;
   167   ElfW (Phdr) * pt_gnu_relro = 0;
   174   ElfW (Phdr) * pt_gnu_relro = 0;
   168   for (uint32_t i = 0; i < header->e_phnum; i++, phdr++)
   175   for (uint32_t i = 0; i < header->e_phnum; i++, phdr++)
   169     {
   176     {
   170       switch (phdr->p_type)
   177       switch (phdr->p_type)
   255   uint8_t *buffer = (uint8_t *) ::mmap (0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
   262   uint8_t *buffer = (uint8_t *) ::mmap (0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
   256   NS_ASSERT_MSG (buffer != MAP_FAILED, "unable to mmap file=" << filename << " error=" << strerror (errno));
   263   NS_ASSERT_MSG (buffer != MAP_FAILED, "unable to mmap file=" << filename << " error=" << strerror (errno));
   257   close (fd);
   264   close (fd);
   258 
   265 
   259   struct FileInfo fileInfo = EditBuffer (buffer, selfId);
   266   struct FileInfo fileInfo = EditBuffer (buffer, selfId);
       
   267   if (fileInfo.p_vaddr == -1)
       
   268     {
       
   269       NS_LOG_UNCOND ("*** unable to open non-shared object file=" << filename << " ***");
       
   270       NS_ASSERT_MSG (false, "make it sure that DCE binrary file " << filename 
       
   271                      << " was built with correct options: (CFLAGS=-fPIC, LDFLAGS=-pie -rdynamic)");
       
   272     }
   260 
   273 
   261   // write back changes to hard disk
   274   // write back changes to hard disk
   262   retval = ::msync (buffer, size, MS_SYNC);
   275   retval = ::msync (buffer, size, MS_SYNC);
   263   NS_ASSERT_MSG (retval == 0, "msync failed " << strerror (errno));
   276   NS_ASSERT_MSG (retval == 0, "msync failed " << strerror (errno));
   264 
   277