Changeset 2889 for trunk/kLdr/kLdrModLX.c
- Timestamp:
- Nov 20, 2006, 11:27:03 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrModLX.c
r2888 r2889 119 119 static const uint8_t *kldrModLXDoNameTableLookupByOrdinal(const uint8_t *pbNameTable, int32_t cbNameTable, uint32_t iOrdinal); 120 120 static int kldrModLXDoNameLookup(PKLDRMODLX pModLX, const char *pszSymbol, uint32_t *piSymbol); 121 #if 0 121 122 static const uint8_t *kldrModLXDoNameTableLookupByName(const uint8_t *pbNameTable, int32_t cbNameTable, 122 123 char *pchSymbol, size_t cchSymbol); 124 #endif 123 125 static int kldrModLXDoLoadBits(PKLDRMODLX pModLX, void *pvBits); 124 126 static int kldrModLXDoIterDataUnpacking(uint8_t *pbDst, const uint8_t *pbSrc, int cbSrc); … … 131 133 static int kldrModLXDoLoadFixupSection(PKLDRMODLX pModLX); 132 134 static int32_t kldrModLXDoCall(uintptr_t uEntrypoint, uintptr_t uHandle, uint32_t uOp, void *pvReserved); 135 static int kldrModLXDoReloc(uint8_t *pbPage, int off, KLDRADDR uValue, uint32_t fKind); 133 136 134 137 … … 668 671 669 672 673 #if 0 670 674 /** 671 675 * Hash a symbol using the algorithm from sdbm. … … 738 742 return NULL; 739 743 } 744 #endif 740 745 741 746 … … 791 796 pbName = pModLX->pbImportProcs + pEntry->e32_variant.e32_fwd.value; 792 797 if ( pbName >= pModLX->pbFixupSectionLast 793 || pbName < pModLX->pbFixupSection Last798 || pbName < pModLX->pbFixupSection 794 799 || !*pbName) 795 800 return KLDR_ERR_LX_BAD_FORWARDER; … … 1931 1936 PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser) 1932 1937 { 1933 /*PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData; 1934 int rc;*/ 1935 1936 /** @todo Implement this. */ 1937 1938 return -1; 1938 PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData; 1939 uint32_t i; 1940 int rc; 1941 1942 /* 1943 * Do we need to to *anything*? 1944 */ 1945 if ( NewBaseAddress == OldBaseAddress 1946 && NewBaseAddress == pModLX->paObjs[0].o32_base 1947 && !pModLX->Hdr.e32_impmodcnt) 1948 return 0; 1949 1950 /* 1951 * Load the fixup section. 1952 */ 1953 if (!pModLX->pbFixupSection) 1954 { 1955 rc = kldrModLXDoLoadFixupSection(pModLX); 1956 if (rc) 1957 return rc; 1958 } 1959 1960 /* 1961 * Iterate the segments. 1962 */ 1963 for (i = 0; i < pModLX->Hdr.e32_objcnt; i++) 1964 { 1965 const struct o32_obj * const pObj = &pModLX->paObjs[i]; 1966 uint32_t iPage; 1967 uint8_t *pbPage = (uint8_t *)pvBits + (uintptr_t)pModLX->pMod->aSegments[i].RVA; 1968 1969 /* 1970 * Iterate the page map pages. 1971 */ 1972 for (iPage = 0; !rc && iPage < pObj->o32_mapsize; iPage++, pbPage += OBJPAGELEN) 1973 { 1974 const uint8_t * const pbFixupRecEnd = pModLX->pbFixupRecs + pModLX->paoffPageFixups[iPage + pObj->o32_pagemap]; 1975 const uint8_t *pb = pModLX->pbFixupRecs + pModLX->paoffPageFixups[iPage + pObj->o32_pagemap - 1]; 1976 KLDRADDR uValue; 1977 uint32_t fKind; 1978 1979 /* sanity */ 1980 if (pbFixupRecEnd < pb) 1981 return KLDR_ERR_BAD_FIXUP; 1982 if (pbFixupRecEnd - 1 > pModLX->pbFixupSectionLast) 1983 return KLDR_ERR_BAD_FIXUP; 1984 if (pb < pModLX->pbFixupSection) 1985 return KLDR_ERR_BAD_FIXUP; 1986 1987 /* 1988 * Iterate the fixup record. 1989 */ 1990 while (pb < pbFixupRecEnd) 1991 { 1992 union _rel 1993 { 1994 const uint8_t * pb; 1995 const struct r32_rlc *prlc; 1996 } u; 1997 1998 u.pb = pb; 1999 pb += 3 + (u.prlc->nr_stype & NRCHAIN ? 0 : 1); /* place pch at the 4th member. */ 2000 2001 /* 2002 * Figure out the target. 2003 */ 2004 switch (u.prlc->nr_flags & NRRTYP) 2005 { 2006 /* 2007 * Internal fixup. 2008 */ 2009 case NRRINT: 2010 { 2011 uint16_t iTrgObject; 2012 uint32_t offTrgObject; 2013 2014 /* the object */ 2015 if (u.prlc->nr_flags & NR16OBJMOD) 2016 { 2017 iTrgObject = *(const uint16_t *)pb; 2018 pb += 2; 2019 } 2020 else 2021 iTrgObject = *pb++; 2022 iTrgObject--; 2023 if (iTrgObject >= pModLX->Hdr.e32_objcnt) 2024 return KLDR_ERR_BAD_FIXUP; 2025 2026 /* the target */ 2027 if (u.prlc->nr_flags & NR32BITOFF) 2028 { 2029 offTrgObject = *(const uint32_t *)pb; 2030 pb += 4; 2031 } 2032 else 2033 { 2034 offTrgObject = *(const uint16_t *)pb; 2035 pb += 2; 2036 } 2037 2038 /* calculate the symbol info. */ 2039 uValue = offTrgObject + pMod->aSegments[i].MapAddress; 2040 fKind = 0; 2041 break; 2042 } 2043 2044 /* 2045 * Import by symbol ordinal. 2046 */ 2047 case NRRORD: 2048 { 2049 uint16_t iModule; 2050 uint32_t iSymbol; 2051 2052 /* the module ordinal */ 2053 if (u.prlc->nr_flags & NR16OBJMOD) 2054 { 2055 iModule = *(const uint16_t *)pb; 2056 pb += 2; 2057 } 2058 else 2059 iModule = *pb++; 2060 iModule--; 2061 if (iModule >= pModLX->Hdr.e32_impmodcnt) 2062 return KLDR_ERR_BAD_FIXUP; 2063 2064 /* . */ 2065 if (u.prlc->nr_flags & NR32BITOFF) 2066 { 2067 iSymbol = *(const uint32_t *)pb; 2068 pb += 4; 2069 } 2070 else if (!(u.prlc->nr_flags & NR8BITORD)) 2071 { 2072 iSymbol = *(const uint16_t *)pb; 2073 pb += 2; 2074 } 2075 else 2076 iSymbol = *pb++; 2077 2078 /* resolve it. */ 2079 rc = pfnGetImport(pMod, iModule, iSymbol, NULL, &uValue, &fKind, pvUser); 2080 if (rc) 2081 return rc; 2082 break; 2083 } 2084 2085 /* 2086 * Import by symbol name. 2087 */ 2088 case NRRNAM: 2089 { 2090 uint32_t iModule; 2091 uint16_t offSymbol; 2092 const uint8_t *pbSymbol; 2093 char szSymbol[260]; 2094 2095 /* the module ordinal */ 2096 if (u.prlc->nr_flags & NR16OBJMOD) 2097 { 2098 iModule = *(const uint16_t *)pb; 2099 pb += 2; 2100 } 2101 else 2102 iModule = *pb++; 2103 iModule--; 2104 if (iModule >= pModLX->Hdr.e32_impmodcnt) 2105 return KLDR_ERR_BAD_FIXUP; 2106 #if 1 2107 if (u.prlc->nr_flags & NRCHAIN) 2108 return KLDR_ERR_BAD_FIXUP; 2109 #endif 2110 2111 /* . */ 2112 if (u.prlc->nr_flags & NR32BITOFF) 2113 { 2114 offSymbol = *(const uint32_t *)pb; 2115 pb += 4; 2116 } 2117 else if (!(u.prlc->nr_flags & NR8BITORD)) 2118 { 2119 offSymbol = *(const uint16_t *)pb; 2120 pb += 2; 2121 } 2122 else 2123 offSymbol = *pb++; 2124 pbSymbol = pModLX->pbImportProcs + offSymbol; 2125 if ( pbSymbol < pModLX->pbImportProcs 2126 || pbSymbol > pModLX->pbFixupSectionLast) 2127 return KLDR_ERR_BAD_FIXUP; 2128 2129 /* resolve it. */ 2130 kLdrHlpMemCopy(szSymbol, pbSymbol + 1, *pbSymbol); 2131 szSymbol[*pbSymbol] = '\0'; 2132 rc = pfnGetImport(pMod, iModule, NIL_KLDRMOD_SYM_ORDINAL, szSymbol, &uValue, &fKind, pvUser); 2133 if (rc) 2134 return rc; 2135 break; 2136 } 2137 2138 case NRRENT: 2139 KLDRMODLX_ASSERT(!"NRRENT"); 2140 default: 2141 break; 2142 } 2143 2144 /* addend */ 2145 if (u.prlc->nr_flags & NRADD) 2146 { 2147 if (u.prlc->nr_flags & NR32BITADD) 2148 { 2149 uValue += *(const uint32_t *)pb; 2150 pb += 4; 2151 } 2152 else 2153 { 2154 uValue += *(const uint16_t *)pb; 2155 pb += 2; 2156 } 2157 } 2158 2159 /* 2160 * Deal with the 'source' (i.e. the place that should be modified (very logical). 2161 */ 2162 if (!(u.prlc->nr_flags & NRCHAIN)) 2163 { 2164 rc = kldrModLXDoReloc(pbPage, u.prlc->r32_soff, uValue, fKind); 2165 if (rc) 2166 return rc; 2167 } 2168 else if (!(u.prlc->nr_flags & NRICHAIN)) 2169 { 2170 const uint16_t *poffSrc = (const uint16_t *)pb; 2171 uint8_t c = u.pb[2]; 2172 while (c-- > 0) 2173 { 2174 rc = kldrModLXDoReloc(pbPage, *poffSrc++, uValue, fKind); 2175 if (rc) 2176 return rc; 2177 } 2178 } 2179 else 2180 { 2181 KLDRMODLX_ASSERT(!"NRICHAIN"); 2182 return KLDR_ERR_LX_NRICHAIN_NOT_SUPPORTED; 2183 } 2184 } 2185 } 2186 } 2187 2188 return 0; 2189 } 2190 2191 2192 /** 2193 * Applies the relocation to one 'source' in a page. 2194 * 2195 * @returns 0 on success, non-zero kLdr status code on failure. 2196 * @param pbPage The page in which to apply the fixup. 2197 * @param off Page relative offset of where to apply the offset. 2198 * @param uValue The target value. 2199 * @param fKind The target kind. 2200 * @todo inline this. 2201 */ 2202 static int kldrModLXDoReloc(uint8_t *pbPage, int off, KLDRADDR uValue, uint32_t fKind) 2203 { 2204 2205 2206 return 0; 1939 2207 } 1940 2208
Note:
See TracChangeset
for help on using the changeset viewer.