Print this page
smatch clean rtld


1703         /*
1704          * Determine the number of PT_DYNAMIC entries for the DYNINFO()
1705          * allocation.  Sadly, this is a little larger than we really need,
1706          * as there are typically padding DT_NULL entries.  However, adding
1707          * this data to the initial link-map allocation is a win.
1708          */
1709         if (dyn) {
1710                 dyncnt = dphdr->p_filesz / sizeof (Dyn);
1711                 dynsz = dyncnt * sizeof (Dyninfo);
1712         }
1713 
1714         /*
1715          * Allocate space for the link-map, private elf information, and
1716          * DYNINFO() data.  Once these are allocated and initialized,
1717          * remove_so(0, lmp) can be used to tear down the link-map allocation
1718          * should any failures occur.
1719          */
1720         rtsz = S_DROUND(sizeof (Rt_map));
1721         epsz = S_DROUND(sizeof (Rt_elfp));
1722         lmsz = rtsz + epsz + dynsz;
1723         if ((lmp = calloc(lmsz, 1)) == NULL)
1724                 return (NULL);
1725         ELFPRV(lmp) = (void *)((uintptr_t)lmp + rtsz);
1726         DYNINFO(lmp) = (Dyninfo *)((uintptr_t)lmp + rtsz + epsz);
1727         LMSIZE(lmp) = lmsz;
1728 
1729         /*
1730          * All fields not filled in were set to 0 by calloc.
1731          */
1732         NAME(lmp) = (char *)name;
1733         ADDR(lmp) = addr;
1734         MSIZE(lmp) = msize;
1735         SYMINTP(lmp) = elf_find_sym;
1736         FCT(lmp) = &elf_fct;
1737         LIST(lmp) = lml;
1738         OBJFLTRNDX(lmp) = FLTR_DISABLED;
1739         SORTVAL(lmp) = -1;
1740         DYN(lmp) = dyn;
1741         DYNINFOCNT(lmp) = dyncnt;
1742         PTUNWIND(lmp) = uphdr;
1743 


2338                         case CA_SUNW_MACH:
2339                                 CAPSET(lmp).sc_mach = STRTAB(lmp) +
2340                                     cap->c_un.c_ptr;
2341                                 break;
2342                         }
2343                         cap++;
2344                 }
2345         }
2346 
2347         /*
2348          * If a capabilities chain table exists, duplicate it.  The chain table
2349          * is inspected for each initial call to a capabilities family lead
2350          * symbol.  From this chain, each family member is inspected to
2351          * determine the 'best' family member.  The chain table is then updated
2352          * so that the best member is immediately selected for any further
2353          * family searches.
2354          */
2355         if (CAPCHAIN(lmp)) {
2356                 Capchain        *capchain;
2357 
2358                 if ((capchain = calloc(CAPCHAINSZ(lmp), 1)) == NULL)
2359                         return (NULL);
2360                 (void) memcpy(capchain, CAPCHAIN(lmp), CAPCHAINSZ(lmp));
2361                 CAPCHAIN(lmp) = capchain;
2362         }
2363 
2364         /*
2365          * Add the mapped object to the end of the link map list.
2366          */
2367         lm_append(lml, lmco, lmp);
2368 
2369         /*
2370          * Start the system loading in the ELF information we'll be processing.
2371          */
2372         if (REL(lmp)) {
2373                 (void) madvise((void *)ADDR(lmp), (uintptr_t)REL(lmp) +
2374                     (uintptr_t)RELSZ(lmp) - (uintptr_t)ADDR(lmp),
2375                     MADV_WILLNEED);
2376         }
2377         return (lmp);
2378 }




1703         /*
1704          * Determine the number of PT_DYNAMIC entries for the DYNINFO()
1705          * allocation.  Sadly, this is a little larger than we really need,
1706          * as there are typically padding DT_NULL entries.  However, adding
1707          * this data to the initial link-map allocation is a win.
1708          */
1709         if (dyn) {
1710                 dyncnt = dphdr->p_filesz / sizeof (Dyn);
1711                 dynsz = dyncnt * sizeof (Dyninfo);
1712         }
1713 
1714         /*
1715          * Allocate space for the link-map, private elf information, and
1716          * DYNINFO() data.  Once these are allocated and initialized,
1717          * remove_so(0, lmp) can be used to tear down the link-map allocation
1718          * should any failures occur.
1719          */
1720         rtsz = S_DROUND(sizeof (Rt_map));
1721         epsz = S_DROUND(sizeof (Rt_elfp));
1722         lmsz = rtsz + epsz + dynsz;
1723         if ((lmp = calloc(1, lmsz)) == NULL)
1724                 return (NULL);
1725         ELFPRV(lmp) = (void *)((uintptr_t)lmp + rtsz);
1726         DYNINFO(lmp) = (Dyninfo *)((uintptr_t)lmp + rtsz + epsz);
1727         LMSIZE(lmp) = lmsz;
1728 
1729         /*
1730          * All fields not filled in were set to 0 by calloc.
1731          */
1732         NAME(lmp) = (char *)name;
1733         ADDR(lmp) = addr;
1734         MSIZE(lmp) = msize;
1735         SYMINTP(lmp) = elf_find_sym;
1736         FCT(lmp) = &elf_fct;
1737         LIST(lmp) = lml;
1738         OBJFLTRNDX(lmp) = FLTR_DISABLED;
1739         SORTVAL(lmp) = -1;
1740         DYN(lmp) = dyn;
1741         DYNINFOCNT(lmp) = dyncnt;
1742         PTUNWIND(lmp) = uphdr;
1743 


2338                         case CA_SUNW_MACH:
2339                                 CAPSET(lmp).sc_mach = STRTAB(lmp) +
2340                                     cap->c_un.c_ptr;
2341                                 break;
2342                         }
2343                         cap++;
2344                 }
2345         }
2346 
2347         /*
2348          * If a capabilities chain table exists, duplicate it.  The chain table
2349          * is inspected for each initial call to a capabilities family lead
2350          * symbol.  From this chain, each family member is inspected to
2351          * determine the 'best' family member.  The chain table is then updated
2352          * so that the best member is immediately selected for any further
2353          * family searches.
2354          */
2355         if (CAPCHAIN(lmp)) {
2356                 Capchain        *capchain;
2357 
2358                 if ((capchain = calloc(1, CAPCHAINSZ(lmp))) == NULL)
2359                         return (NULL);
2360                 (void) memcpy(capchain, CAPCHAIN(lmp), CAPCHAINSZ(lmp));
2361                 CAPCHAIN(lmp) = capchain;
2362         }
2363 
2364         /*
2365          * Add the mapped object to the end of the link map list.
2366          */
2367         lm_append(lml, lmco, lmp);
2368 
2369         /*
2370          * Start the system loading in the ELF information we'll be processing.
2371          */
2372         if (REL(lmp)) {
2373                 (void) madvise((void *)ADDR(lmp), (uintptr_t)REL(lmp) +
2374                     (uintptr_t)RELSZ(lmp) - (uintptr_t)ADDR(lmp),
2375                     MADV_WILLNEED);
2376         }
2377         return (lmp);
2378 }