Changeset 2967 for trunk/kLdr/testcase/tst-3-driver.c
- Timestamp:
- Feb 13, 2007, 11:28:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/testcase/tst-3-driver.c
r2965 r2967 72 72 73 73 74 /** 75 * External symbol used by the testcase module. 76 */ 77 static int Tst3Ext(int iFortyTwo) 78 { 79 if (iFortyTwo != 42) 80 return 256; 81 return 42; 82 } 83 84 85 /** 86 * Callback for resolving the Tst3Ext import. 87 */ 74 88 static int GetImport(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, size_t cchSymbol, 75 89 const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser) 76 90 { 77 /** todo */ 78 return -1; 91 if (*pfKind != KLDRSYMKIND_REQ_FLAT) 92 return -1; 93 94 if ( !strncmp(pchSymbol, "Tst3Ext", strlen("Tst3Ext")) 95 || !strncmp(pchSymbol, "_Tst3Ext", strlen("_Tst3Ext"))) 96 { 97 *puValue = (uintptr_t)&Tst3Ext; 98 *pfKind = KLDRSYMKIND_CODE | (sizeof(pfKind) == 4 ? KLDRSYMKIND_32BIT : KLDRSYMKIND_64BIT); 99 return 0; 100 } 101 102 return -2; 79 103 } 80 104 … … 100 124 /* get bits. */ 101 125 cbImage = kLdrModSize(pMod); 102 pvBits = malloc((size_t)cbImage );126 pvBits = malloc((size_t)cbImage + 0xfff); 103 127 if (pvBits) 104 128 { 105 KLDRADDR BaseAddress = (uintptr_t)pvBits; 106 rc = kLdrModGetBits(pMod, pvBits, BaseAddress, GetImport, NULL); 129 void *pvBits2 = (void *)( ((uintptr_t)pvBits + 0xfff) & ~(uintptr_t)0xfff ); 130 131 KLDRADDR BaseAddress = (uintptr_t)pvBits2; 132 rc = kLdrModGetBits(pMod, pvBits2, BaseAddress, GetImport, NULL); 107 133 if (!rc) 108 134 { 109 const char *pszSym = MY_NAME("Tst3");110 135 KLDRADDR EntryPoint; 111 136 112 137 /* call into it */ 113 rc = kLdrModQuerySymbol(pMod, pvBits , BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, pszSym, strlen(pszSym), NULL, NULL, NULL,138 rc = kLdrModQuerySymbol(pMod, pvBits2, BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, "_Tst3", strlen("_Tst3"), NULL, NULL, NULL, 114 139 &EntryPoint, NULL); 140 if (rc == KLDR_ERR_SYMBOL_NOT_FOUND) 141 rc = kLdrModQuerySymbol(pMod, pvBits2, BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, "Tst3", strlen("Tst3"), NULL, NULL, NULL, 142 &EntryPoint, NULL); 115 143 if (!rc) 116 144 { … … 120 148 { 121 149 /* relocate twice and try again. */ 122 rc = kLdrModRelocateBits(pMod, pvBits , BaseAddress + 0x22000, BaseAddress, GetImport, NULL);150 rc = kLdrModRelocateBits(pMod, pvBits2, BaseAddress + 0x22000, BaseAddress, GetImport, NULL); 123 151 if (!rc) 124 152 { 125 rc = kLdrModRelocateBits(pMod, pvBits , BaseAddress, BaseAddress + 0x22000, GetImport, NULL);153 rc = kLdrModRelocateBits(pMod, pvBits2, BaseAddress, BaseAddress + 0x22000, GetImport, NULL); 126 154 if (!rc) 127 155 { … … 178 206 */ 179 207 if (!g_cErrors) 180 printf("tst- 0-driver: SUCCESS\n");208 printf("tst-3-driver: SUCCESS\n"); 181 209 else 182 printf("tst- 0-driver: FAILURE - %d errors\n", g_cErrors);210 printf("tst-3-driver: FAILURE - %d errors\n", g_cErrors); 183 211 return !!g_cErrors; 184 212 }
Note:
See TracChangeset
for help on using the changeset viewer.