Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

static int BasicTestsSub2 ( PKLDRMOD  pMod,
void *  pvBits 
) [static]

Performs the basic module loader test on the specified module and image bits.

Definition at line 280 of file tstkLdrMod.c.

References KLDRSTACKINFO::Address, BasicTestEnumDbgInfoCallback(), BasicTestsEnumSymCallback(), KLDRSTACKINFO::cbStack, KLDRSTACKINFO::cbStackThread, Failure(), KLDR_ERR_NO_DEBUG_INFO, kLdrModEnumDbgInfo(), kLdrModEnumSymbols(), kLdrModGetImport(), kLdrModGetStackInfo(), kLdrModHasDbgInfo(), kLdrModNumberOfImports(), kLdrModQueryMainEntrypoint(), kLdrModQuerySymbol(), kLdrModSize(), KLDRSTACKINFO::LinkAddress, MY_BASEADDRESS, NIL_KLDRADDR, NIL_KLDRMOD_SYM_ORDINAL, NULL, PRI_KLDRADDR, and PRI_KLDRSIZE.

Referenced by BasicTests(), BasicTestsSub(), and BasicTestsSubMap2().

{
    KI32 cImports;
    KI32 i;
    int rc;
    KU32 fKind;
    KLDRADDR Value;
    KLDRADDR MainEPAddress;
    KLDRSTACKINFO StackInfo;

    printf("* Testing queries with pvBits=%p...\n", pvBits);

    /*
     * Get the import modules.
     */
    cImports = kLdrModNumberOfImports(pMod, pvBits);
    printf("cImports=%d\n", cImports);
    if (cImports < 0)
        return Failure("failed to query the number of import, cImports=%d", cImports);
    for (i = 0; i < cImports; i++)
    {
        char szImportModule[260];
        rc = kLdrModGetImport(pMod, pvBits, i, szImportModule, sizeof(szImportModule));
        if (rc)
            return Failure("failed to get import module name, rc=%d (%s). (%.260s)", rc, kErrName(rc), szImportModule);
        printf("import #%d: '%s'\n", i, szImportModule);
    }

    /*
     * Query stack info.
     */
    StackInfo.Address = ~(KLDRADDR)42;
    StackInfo.LinkAddress = ~(KLDRADDR)42;
    StackInfo.cbStack = ~(KLDRSIZE)42;
    StackInfo.cbStackThread = ~(KLDRSIZE)42;
    rc = kLdrModGetStackInfo(pMod, pvBits, MY_BASEADDRESS, &StackInfo);
    if (rc)
        return Failure("kLdrModGetStackInfo failed with rc=%d (%s)", rc, kErrName(rc));
    printf("Stack: Address=%016" PRI_KLDRADDR "   LinkAddress=%016" PRI_KLDRADDR "\n"
           "       cbStack=%016" PRI_KLDRSIZE " cbStackThread=%016" PRI_KLDRSIZE "\n",
           StackInfo.Address, StackInfo.LinkAddress, StackInfo.cbStack, StackInfo.cbStackThread);
    if (StackInfo.Address == ~(KLDRADDR)42)
        return Failure("Bad StackInfo.Address");
    if (StackInfo.LinkAddress == ~(KLDRADDR)42)
        return Failure("Bad StackInfo.LinkAddress");
    if (StackInfo.cbStack == ~(KLDRSIZE)42)
        return Failure("Bad StackInfo.cbStack");
    if (StackInfo.cbStackThread == ~(KLDRSIZE)42)
        return Failure("Bad StackInfo.cbStackThread");

    /*
     * Query entrypoint.
     */
    MainEPAddress = ~(KLDRADDR)42;
    rc = kLdrModQueryMainEntrypoint(pMod, pvBits, MY_BASEADDRESS, &MainEPAddress);
    if (rc)
        return Failure("kLdrModQueryMainEntrypoint failed with rc=%d (%s)", rc, kErrName(rc));
    printf("Entrypoint: %016" PRI_KLDRADDR "\n", MainEPAddress);
    if (MainEPAddress == ~(KLDRADDR)42)
        return Failure("MainEPAddress wasn't set.");
    if (MainEPAddress != NIL_KLDRADDR && MainEPAddress < MY_BASEADDRESS)
        return Failure("Bad MainEPAddress (a).");
    if (MainEPAddress != NIL_KLDRADDR && MainEPAddress >= MY_BASEADDRESS + kLdrModSize(pMod))
        return Failure("Bad MainEPAddress (b).");

    /*
     * Debugger information.
     */
    rc = kLdrModHasDbgInfo(pMod, pvBits);
    if (!rc)
        printf("Has Debugger Information\n");
    else if (rc == KLDR_ERR_NO_DEBUG_INFO)
        printf("NO Debugger Information\n");
    else
        return Failure("kLdrModHasDbgInfo failed with rc=%d (%s)", rc, kErrName(rc));
    rc = kLdrModEnumDbgInfo(pMod, pvBits, BasicTestEnumDbgInfoCallback, NULL);
    if (rc)
        return Failure("kLdrModEnumDbgInfo failed with rc=%d (%s)", rc, kErrName(rc));


    /*
     * Negative symbol query tests.
     */
    fKind = 0;
    Value = 0x0badc0de;
    rc = kLdrModQuerySymbol(pMod, pvBits, MY_BASEADDRESS, NIL_KLDRMOD_SYM_ORDINAL - 20, NULL, 0, NULL, NULL, NULL,
                            &Value, &fKind);
    if (rc)
    {
        if (Value != 0)
            return Failure("Value wasn't cleared on failure.");
    }

    fKind = 0;
    Value = 0x0badc0de;
    rc = kLdrModQuerySymbol(pMod, pvBits, MY_BASEADDRESS, NIL_KLDRMOD_SYM_ORDINAL, NULL, 0, NULL, NULL, NULL,
                            &Value, &fKind);
    if (!rc)
        return Failure("NIL ordinal succeeded!");
    if (Value != 0)
        return Failure("Value wasn't cleared on failure.");

    /*
     * Enumerate and query all symbols.
     */
    printf("\n"
           "Symbols:\n");
    rc = kLdrModEnumSymbols(pMod, pvBits, MY_BASEADDRESS, 0, BasicTestsEnumSymCallback, pvBits);
    if (rc)
        return Failure("kLdrModEnumSymbols failed with rc=%d (%s)", rc, kErrName(rc));


/*int     kLdrModCanExecuteOn(PKLDRMOD pMod, const void *pvBits, KCPUARCH enmArch, KCPU enmCpu);
*/

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index