Changeset 1199 in vbox
- Timestamp:
- Mar 4, 2007 10:48:45 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 19123
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
r1193 r1199 61 61 #include <iprt/process.h> 62 62 #include <iprt/string.h> 63 #include <iprt/env.h> 63 64 64 65 #include "SUPLibInternal.h" 65 66 #include "SUPDRVIOC.h" 66 67 #include <stdlib.h>68 67 69 68 … … 126 125 * Internal Functions * 127 126 *******************************************************************************/ 127 static int supInitFake(PSUPDRVSESSION *ppSession); 128 128 static int supLoadModule(const char *pszFilename, const char *pszModule, void **ppvImageBase); 129 129 #ifndef VBOX_WITHOUT_IDT_PATCHING … … 157 157 /* 158 158 * Check for fake mode. 159 * 159 160 * Fake mode is used when we're doing smoke testing and debugging. 160 161 * It's also useful on platforms where we haven't root access or which … … 163 164 if (g_u32FakeMode == ~0U) 164 165 { 165 const char *psz = getenv("VBOX_SUPLIB_FAKE");166 const char *psz = RTEnvGet("VBOX_SUPLIB_FAKE"); 166 167 if (psz && !strcmp(psz, "fake")) 167 168 ASMAtomicCmpXchgU32(&g_u32FakeMode, 1, ~0U); … … 169 170 ASMAtomicCmpXchgU32(&g_u32FakeMode, 0, ~0U); 170 171 } 171 if (g_u32FakeMode) 172 { 173 Log(("SUP: Fake mode!\n")); 174 175 /* fake r0 functions. */ 176 g_pFunctions = (PSUPQUERYFUNCS_OUT)RTMemAllocZ(RT_OFFSETOF(SUPQUERYFUNCS_OUT, aFunctions[8])); 177 if (g_pFunctions) 178 { 179 g_pFunctions->aFunctions[0].pfn = (void *)0xefefefef; 180 strcpy(g_pFunctions->aFunctions[0].szName, "SUPR0ContAlloc"); 181 g_pFunctions->aFunctions[1].pfn = (void *)0xefefefdf; 182 strcpy(g_pFunctions->aFunctions[1].szName, "SUPR0ContFree"); 183 g_pFunctions->aFunctions[2].pfn = (void *)0xefefefcf; 184 strcpy(g_pFunctions->aFunctions[2].szName, "SUPR0LockMem"); 185 g_pFunctions->aFunctions[3].pfn = (void *)0xefefefbf; 186 strcpy(g_pFunctions->aFunctions[3].szName, "SUPR0UnlockMem"); 187 g_pFunctions->aFunctions[4].pfn = (void *)0xefefefaf; 188 strcpy(g_pFunctions->aFunctions[4].szName, "SUPR0LockedAlloc"); 189 g_pFunctions->aFunctions[5].pfn = (void *)0xefefef9f; 190 strcpy(g_pFunctions->aFunctions[5].szName, "SUPR0LockedFree"); 191 g_pFunctions->aFunctions[6].pfn = (void *)0xefefef8f; 192 strcpy(g_pFunctions->aFunctions[6].szName, "SUPR0Printf"); 193 g_pFunctions->cFunctions = 7; 194 g_pSession = (PSUPDRVSESSION)(void *)g_pFunctions; 195 if (ppSession) 196 *ppSession = g_pSession; 197 #ifndef VBOX_WITHOUT_IDT_PATCHING 198 Assert(g_u8Interrupt == 3); 199 #endif 200 /* fake the GIP. */ 201 g_pSUPGlobalInfoPage = (PCSUPGLOBALINFOPAGE)RTMemPageAlloc(PAGE_SIZE); 202 if (g_pSUPGlobalInfoPage) 203 { 204 g_pSUPGlobalInfoPageR0 = g_pSUPGlobalInfoPage; 205 g_HCPhysSUPGlobalInfoPage = NIL_RTHCPHYS & ~(RTHCPHYS)PAGE_OFFSET_MASK; 206 /* the page is supposed to be invalid, so don't set a correct magic. */ 207 return VINF_SUCCESS; 208 } 209 RTMemFree(g_pFunctions); 210 g_pFunctions = NULL; 211 } 212 return VERR_NO_MEMORY; 213 } 172 if (RT_UNLIKELY(g_u32FakeMode)) 173 return supInitFake(ppSession); 214 174 215 175 /** … … 290 250 } 291 251 252 /** 253 * Fake mode init. 254 */ 255 static int supInitFake(PSUPDRVSESSION *ppSession) 256 { 257 Log(("SUP: Fake mode!\n")); 258 static const SUPFUNC s_aFakeFunctions[] = 259 { 260 /* name function */ 261 { "SUPR0ObjRegister", (void *)0xefef0000 }, 262 { "SUPR0ObjAddRef", (void *)0xefef0001 }, 263 { "SUPR0ObjRelease", (void *)0xefef0002 }, 264 { "SUPR0ObjVerifyAccess", (void *)0xefef0003 }, 265 { "SUPR0LockMem", (void *)0xefef0004 }, 266 { "SUPR0UnlockMem", (void *)0xefef0005 }, 267 { "SUPR0ContAlloc", (void *)0xefef0006 }, 268 { "SUPR0ContFree", (void *)0xefef0007 }, 269 { "SUPR0MemAlloc", (void *)0xefef0008 }, 270 { "SUPR0MemGetPhys", (void *)0xefef0009 }, 271 { "SUPR0MemFree", (void *)0xefef000a }, 272 { "SUPR0Printf", (void *)0xefef000b }, 273 { "RTMemAlloc", (void *)0xefef000c }, 274 { "RTMemAllocZ", (void *)0xefef000d }, 275 { "RTMemFree", (void *)0xefef000e }, 276 { "RTSemFastMutexCreate", (void *)0xefef000f }, 277 { "RTSemFastMutexDestroy", (void *)0xefef0010 }, 278 { "RTSemFastMutexRequest", (void *)0xefef0011 }, 279 { "RTSemFastMutexRelease", (void *)0xefef0012 }, 280 { "RTSemEventCreate", (void *)0xefef0013 }, 281 { "RTSemEventSignal", (void *)0xefef0014 }, 282 { "RTSemEventWait", (void *)0xefef0015 }, 283 { "RTSemEventDestroy", (void *)0xefef0016 }, 284 { "RTSpinlockCreate", (void *)0xefef0017 }, 285 { "RTSpinlockDestroy", (void *)0xefef0018 }, 286 { "RTSpinlockAcquire", (void *)0xefef0019 }, 287 { "RTSpinlockRelease", (void *)0xefef001a }, 288 { "RTSpinlockAcquireNoInts", (void *)0xefef001b }, 289 { "RTSpinlockReleaseNoInts", (void *)0xefef001c }, 290 { "RTThreadNativeSelf", (void *)0xefef001d }, 291 { "RTThreadSleep", (void *)0xefef001e }, 292 { "RTThreadYield", (void *)0xefef001f }, 293 { "RTLogDefaultInstance", (void *)0xefef0020 }, 294 { "RTLogRelDefaultInstance", (void *)0xefef0021 }, 295 { "RTLogSetDefaultInstanceThread", (void *)0xefef0022 }, 296 { "RTLogLogger", (void *)0xefef0023 }, 297 { "RTLogLoggerEx", (void *)0xefef0024 }, 298 { "RTLogLoggerExV", (void *)0xefef0025 }, 299 { "AssertMsg1", (void *)0xefef0026 }, 300 { "AssertMsg2", (void *)0xefef0027 }, 301 }; 302 303 /* fake r0 functions. */ 304 g_pFunctions = (PSUPQUERYFUNCS_OUT)RTMemAllocZ(RT_OFFSETOF(SUPQUERYFUNCS_OUT, aFunctions[RT_ELEMENTS(s_aFakeFunctions)])); 305 if (g_pFunctions) 306 { 307 g_pFunctions->cFunctions = RT_ELEMENTS(s_aFakeFunctions); 308 memcpy(&g_pFunctions->aFunctions[0], &s_aFakeFunctions[0], sizeof(s_aFakeFunctions)); 309 g_pSession = (PSUPDRVSESSION)(void *)g_pFunctions; 310 if (ppSession) 311 *ppSession = g_pSession; 312 #ifndef VBOX_WITHOUT_IDT_PATCHING 313 Assert(g_u8Interrupt == 3); 314 #endif 315 316 /* fake the GIP. */ 317 g_pSUPGlobalInfoPage = (PCSUPGLOBALINFOPAGE)RTMemPageAlloc(PAGE_SIZE); 318 if (g_pSUPGlobalInfoPage) 319 { 320 g_pSUPGlobalInfoPageR0 = g_pSUPGlobalInfoPage; 321 g_HCPhysSUPGlobalInfoPage = NIL_RTHCPHYS & ~(RTHCPHYS)PAGE_OFFSET_MASK; 322 /* the page is supposed to be invalid, so don't set the magic. */ 323 return VINF_SUCCESS; 324 } 325 326 RTMemFree(g_pFunctions); 327 g_pFunctions = NULL; 328 } 329 return VERR_NO_MEMORY; 330 } 331 292 332 293 333 SUPR3DECL(int) SUPTerm(bool fForced) … … 409 449 In.u32SessionCookie = g_u32SessionCookie; 410 450 In.pVMR0 = pVMR0; 411 Assert(!g_u32FakeMode); 412 return suplibOsIOCtl(SUP_IOCTL_SET_VM_FOR_FAST, &In, sizeof(In), NULL, 0); 451 int rc; 452 if (RT_LIKELY(!g_u32FakeMode)) 453 rc = suplibOsIOCtl(SUP_IOCTL_SET_VM_FOR_FAST, &In, sizeof(In), NULL, 0); 454 else 455 rc = VINF_SUCCESS; 456 return rc; 413 457 } 414 458 … … 1295 1339 pIn->pvImageBase = pvImageBase; 1296 1340 memcpy(pIn->szSymbol, pszSymbol, cchSymbol + 1); 1297 int rc = suplibOsIOCtl(SUP_IOCTL_LDR_GET_SYMBOL, pIn, cbIn, &Out, sizeof(Out)); 1341 int rc; 1342 if (RT_LIKELY(!g_u32FakeMode)) 1343 rc = suplibOsIOCtl(SUP_IOCTL_LDR_GET_SYMBOL, pIn, cbIn, &Out, sizeof(Out)); 1344 else 1345 { 1346 rc = VINF_SUCCESS; 1347 Out.pvSymbol = (void *)0xdeadf00d; 1348 } 1298 1349 if (VBOX_SUCCESS(rc)) 1299 1350 *ppvValue = Out.pvSymbol;
Note:
See TracChangeset
for help on using the changeset viewer.