VirtualBox

Changeset 73375 in vbox


Ignore:
Timestamp:
Jul 27, 2018 7:59:25 AM (6 years ago)
Author:
vboxsync
Message:

IPRT: Added RTLDRPROP_UNWIND_INFO to RTLdrQueryPropEx. Added RTDbgModImageQueryProp, RTDbgModImageGetArch, and RTDbgModImageGetFormat.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/dbg.h

    r73359 r73375  
    10891089
    10901090/**
    1091  * Image size when mapped if segments are mapped adjacently.
    1092  *
    1093  * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
    1094  * NE and such it's a bit odder and the answer may not make much sense for them.
    1095  *
    1096  * @returns Image mapped size.
    1097  *          RTUINTPTR_MAX is returned if the handle is invalid.
    1098  *
    1099  * @param   hDbgMod         The module handle.
    1100  */
    1101 RTDECL(RTUINTPTR)   RTDbgModImageSize(RTDBGMOD hDbgMod);
    1102 
    1103 /**
    11041091 * Gets the module tag value if any.
    11051092 *
     
    11241111 */
    11251112RTDECL(int)         RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag);
     1113
     1114
     1115/**
     1116 * Image size when mapped if segments are mapped adjacently.
     1117 *
     1118 * For ELF, PE, and Mach-O images this is (usually) a natural query, for LX and
     1119 * NE and such it's a bit odder and the answer may not make much sense for them.
     1120 *
     1121 * @returns Image mapped size.
     1122 *          RTUINTPTR_MAX is returned if the handle is invalid.
     1123 *
     1124 * @param   hDbgMod         The module handle.
     1125 */
     1126RTDECL(RTUINTPTR)   RTDbgModImageSize(RTDBGMOD hDbgMod);
     1127
     1128/**
     1129 * Gets the image format.
     1130 *
     1131 * @returns Image format.
     1132 * @retval  RTLDRFMT_INVALID if the handle is invalid or if the format isn't known.
     1133 * @param   hDbgMod         The debug module handle.
     1134 * @sa      RTLdrGetFormat
     1135 */
     1136RTDECL(RTLDRFMT)    RTDbgModImageGetFormat(RTDBGMOD hDbgMod);
     1137
     1138/**
     1139 * Gets the image architecture.
     1140 *
     1141 * @returns Image architecture.
     1142 * @retval  RTLDRARCH_INVALID if the handle is invalid.
     1143 * @retval  RTLDRARCH_WHATEVER if unknown.
     1144 * @param   hDbgMod         The debug module handle.
     1145 * @sa      RTLdrGetArch
     1146 */
     1147RTDECL(RTLDRARCH)   RTDbgModImageGetArch(RTDBGMOD hDbgMod);
     1148
     1149/**
     1150 * Generic method for querying image properties.
     1151 *
     1152 * @returns IPRT status code.
     1153 * @retval  VERR_NOT_SUPPORTED if the property query isn't supported (either all
     1154 *          or that specific property).  The caller must handle this result.
     1155 * @retval  VERR_NOT_FOUND the property was not found in the module.  The caller
     1156 *          must also normally deal with this.
     1157 * @retval  VERR_INVALID_FUNCTION if the function value is wrong.
     1158 * @retval  VERR_INVALID_PARAMETER if the fixed buffer size is wrong. Correct
     1159 *          size in @a *pcbRet.
     1160 * @retval  VERR_BUFFER_OVERFLOW if the function doesn't have a fixed size
     1161 *          buffer and the buffer isn't big enough. Correct size in @a *pcbRet.
     1162 * @retval  VERR_INVALID_HANDLE if the handle is invalid.
     1163 *
     1164 * @param   hDbgMod         The debug module handle.
     1165 * @param   enmProp         The property to query.
     1166 * @param   pvBuf           Pointer to the input / output buffer.  In most cases
     1167 *                          it's only used for returning data.
     1168 * @param   cbBuf           The size of the buffer.
     1169 * @param   pcbRet          Where to return the amount of data returned.  On
     1170 *                          buffer size errors, this is set to the correct size.
     1171 *                          Optional.
     1172 * @sa      RTLdrQueryPropEx
     1173 */
     1174RTDECL(int)         RTDbgModImageQueryProp(RTDBGMOD hDbgMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet);
    11261175
    11271176
  • trunk/include/iprt/ldr.h

    r73150 r73375  
    10941094     * Returns zero terminated string. */
    10951095    RTLDRPROP_INTERNAL_NAME,
     1096    /** The raw unwind info if available.
     1097     * For PE this means IMAGE_DIRECTORY_ENTRY_EXCEPTION.  Not implemented any
     1098     * others yet.  */
     1099    RTLDRPROP_UNWIND_INFO,
    10961100
    10971101    /** End of valid properties.  */
  • trunk/include/iprt/mangling.h

    r73334 r73375  
    721721# define RTDbgModCreateFromMachOImage                   RT_MANGLER(RTDbgModCreateFromMachOImage)
    722722# define RTDbgModGetTag                                 RT_MANGLER(RTDbgModGetTag)
     723# define RTDbgModImageGetArch                           RT_MANGLER(RTDbgModImageGetArch)
     724# define RTDbgModImageGetFormat                         RT_MANGLER(RTDbgModImageGetFormat)
    723725# define RTDbgModImageSize                              RT_MANGLER(RTDbgModImageSize)
     726# define RTDbgModImageQueryProp                         RT_MANGLER(RTDbgModImageQueryProp)
    724727# define RTDbgModIsDeferred                             RT_MANGLER(RTDbgModIsDeferred)
    725728# define RTDbgModIsExports                              RT_MANGLER(RTDbgModIsExports)
  • trunk/src/VBox/Runtime/common/dbg/dbgmod.cpp

    r73365 r73375  
    746746            RTUUID  Uuid;
    747747            PRTUUID pUuid = &Uuid;
    748             rc = pDbgMod->pImgVt->pfnQueryProp(pDbgMod, RTLDRPROP_UUID, &Uuid, sizeof(Uuid));
     748            rc = pDbgMod->pImgVt->pfnQueryProp(pDbgMod, RTLDRPROP_UUID, &Uuid, sizeof(Uuid), NULL);
    749749            if (RT_FAILURE(rc))
    750750                pUuid = NULL;
     
    12691269            {
    12701270                RTUUID UuidOpened;
    1271                 rc = pDbgMod->pImgVt->pfnQueryProp(pDbgMod, RTLDRPROP_UUID, &UuidOpened, sizeof(UuidOpened));
     1271                rc = pDbgMod->pImgVt->pfnQueryProp(pDbgMod, RTLDRPROP_UUID, &UuidOpened, sizeof(UuidOpened), NULL);
    12721272                if (RT_SUCCESS(rc))
    12731273                {
     
    16481648
    16491649
     1650RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod)
     1651{
     1652    PRTDBGMODINT pDbgMod = hDbgMod;
     1653    RTDBGMOD_VALID_RETURN_RC(pDbgMod, 0);
     1654    return pDbgMod->uTag;
     1655}
     1656RT_EXPORT_SYMBOL(RTDbgModGetTag);
     1657
     1658
     1659RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag)
     1660{
     1661    PRTDBGMODINT pDbgMod = hDbgMod;
     1662    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
     1663    RTDBGMOD_LOCK(pDbgMod);
     1664
     1665    pDbgMod->uTag = uTag;
     1666
     1667    RTDBGMOD_UNLOCK(pDbgMod);
     1668    return VINF_SUCCESS;
     1669}
     1670RT_EXPORT_SYMBOL(RTDbgModSetTag);
     1671
     1672
    16501673RTDECL(RTUINTPTR) RTDbgModImageSize(RTDBGMOD hDbgMod)
    16511674{
     
    16621685
    16631686
    1664 RTDECL(uint64_t) RTDbgModGetTag(RTDBGMOD hDbgMod)
    1665 {
    1666     PRTDBGMODINT pDbgMod = hDbgMod;
    1667     RTDBGMOD_VALID_RETURN_RC(pDbgMod, 0);
    1668     return pDbgMod->uTag;
    1669 }
    1670 RT_EXPORT_SYMBOL(RTDbgModGetTag);
    1671 
    1672 
    1673 RTDECL(int) RTDbgModSetTag(RTDBGMOD hDbgMod, uint64_t uTag)
     1687RTDECL(RTLDRFMT) RTDbgModImageGetFormat(RTDBGMOD hDbgMod)
     1688{
     1689    PRTDBGMODINT pDbgMod = hDbgMod;
     1690    RTDBGMOD_VALID_RETURN_RC(pDbgMod, RTLDRFMT_INVALID);
     1691    RTDBGMOD_LOCK(pDbgMod);
     1692
     1693    RTLDRFMT enmFmt;
     1694    if (   pDbgMod->pImgVt
     1695        && pDbgMod->pImgVt->pfnGetFormat)
     1696        enmFmt = pDbgMod->pImgVt->pfnGetFormat(pDbgMod);
     1697    else
     1698        enmFmt = RTLDRFMT_INVALID;
     1699
     1700    RTDBGMOD_UNLOCK(pDbgMod);
     1701    return enmFmt;
     1702}
     1703RT_EXPORT_SYMBOL(RTDbgModImageGetFormat);
     1704
     1705
     1706RTDECL(RTLDRARCH) RTDbgModImageGetArch(RTDBGMOD hDbgMod)
     1707{
     1708    PRTDBGMODINT pDbgMod = hDbgMod;
     1709    RTDBGMOD_VALID_RETURN_RC(pDbgMod, RTLDRARCH_INVALID);
     1710    RTDBGMOD_LOCK(pDbgMod);
     1711
     1712    RTLDRARCH enmArch;
     1713    if (   pDbgMod->pImgVt
     1714        && pDbgMod->pImgVt->pfnGetArch)
     1715        enmArch = pDbgMod->pImgVt->pfnGetArch(pDbgMod);
     1716    else
     1717        enmArch = RTLDRARCH_WHATEVER;
     1718
     1719    RTDBGMOD_UNLOCK(pDbgMod);
     1720    return enmArch;
     1721}
     1722RT_EXPORT_SYMBOL(RTDbgModImageGetArch);
     1723
     1724
     1725RTDECL(int) RTDbgModImageQueryProp(RTDBGMOD hDbgMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet)
    16741726{
    16751727    PRTDBGMODINT pDbgMod = hDbgMod;
    16761728    RTDBGMOD_VALID_RETURN_RC(pDbgMod, VERR_INVALID_HANDLE);
     1729    AssertPtrNullReturn(pcbRet, VERR_INVALID_POINTER);
    16771730    RTDBGMOD_LOCK(pDbgMod);
    16781731
    1679     pDbgMod->uTag = uTag;
     1732    int rc;
     1733    if (   pDbgMod->pImgVt
     1734        && pDbgMod->pImgVt->pfnQueryProp)
     1735        rc = pDbgMod->pImgVt->pfnQueryProp(pDbgMod, enmProp, pvBuf, cbBuf, pcbRet);
     1736    else
     1737        rc = VERR_NOT_FOUND;
    16801738
    16811739    RTDBGMOD_UNLOCK(pDbgMod);
    1682     return VINF_SUCCESS;
    1683 }
    1684 RT_EXPORT_SYMBOL(RTDbgModSetTag);
     1740    return rc;
     1741}
     1742RT_EXPORT_SYMBOL(RTDbgModImageQueryProp);
    16851743
    16861744
  • trunk/src/VBox/Runtime/common/dbg/dbgmoddeferred.cpp

    r73359 r73375  
    445445
    446446/** @interface_method_impl{RTDBGMODVTIMG,pfnQueryProp} */
    447 static DECLCALLBACK(int ) rtDbgModDeferredImg_QueryProp(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf)
    448 {
    449     int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
    450     if (RT_SUCCESS(rc))
    451         rc = pMod->pImgVt->pfnQueryProp(pMod, enmProp, pvBuf, cbBuf);
     447static DECLCALLBACK(int)
     448rtDbgModDeferredImg_QueryProp(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet)
     449{
     450    int rc = rtDbgModDeferredDoIt(pMod, false /*fForceRetry*/);
     451    if (RT_SUCCESS(rc))
     452        rc = pMod->pImgVt->pfnQueryProp(pMod, enmProp, pvBuf, cbBuf, pcbRet);
    452453    return rc;
    453454}
  • trunk/src/VBox/Runtime/common/dbg/dbgmodldr.cpp

    r69111 r73375  
    6262
    6363/** @interface_method_impl{RTDBGMODVTIMG,pfnQueryProp} */
    64 static DECLCALLBACK(int) rtDbgModLdr_QueryProp(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf)
    65 {
    66     PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
    67     return RTLdrQueryProp(pThis->hLdrMod, enmProp, pvBuf, cbBuf);
     64static DECLCALLBACK(int) rtDbgModLdr_QueryProp(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet)
     65{
     66    PRTDBGMODLDR pThis = (PRTDBGMODLDR)pMod->pvImgPriv;
     67    return RTLdrQueryPropEx(pThis->hLdrMod, enmProp, NULL /*pvBits*/, pvBuf, cbBuf, pcbRet);
    6868}
    6969
  • trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp

    r73150 r73375  
    635635            break;
    636636        case RTLDRPROP_INTERNAL_NAME:
     637        case RTLDRPROP_UNWIND_INFO:
    637638            *pcbRet = 0;
    638639            break;
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r73150 r73375  
    122122    /** The security directory entry. */
    123123    IMAGE_DATA_DIRECTORY    SecurityDir;
     124    /** The exception data directory entry. */
     125    IMAGE_DATA_DIRECTORY    ExceptionDir;
    124126
    125127    /** Offset of the first PKCS \#7 SignedData signature if present. */
     
    19171919
    19181920/**
    1919  * Worker for rtLdrPE_QueryProp that retrievs the internal module name.
     1921 * Worker for rtLdrPE_QueryProp that retrieves the internal module name.
    19201922 *
    19211923 * @returns IPRT status code. If VERR_BUFFER_OVERFLOW, pcbBuf is required size.
     
    19441946    }
    19451947
     1948    return rc;
     1949}
     1950
     1951
     1952/**
     1953 * Worker for rtLdrPE_QueryProp that retrieves unwind information.
     1954 *
     1955 * @returns IPRT status code. If VERR_BUFFER_OVERFLOW, pcbBuf is required size.
     1956 * @param   pThis           The PE module instance.
     1957 * @param   pvBits          Image bits if the caller had them available, NULL if
     1958 *                          not. Saves a couple of file accesses.
     1959 * @param   pvBuf           The output buffer.
     1960 * @param   cbBuf           The buffer size.
     1961 * @param   pcbRet          Where to return the number of bytes we've returned
     1962 *                          (or in case of VERR_BUFFER_OVERFLOW would have).
     1963 */
     1964static int rtLdrPE_QueryUnwindInfo(PRTLDRMODPE pThis, void const *pvBits, void *pvBuf, size_t cbBuf, size_t *pcbRet)
     1965{
     1966    int rc;
     1967    uint32_t const cbSrc = pThis->ExceptionDir.Size;
     1968    if (   cbSrc > 0
     1969        && pThis->ExceptionDir.VirtualAddress > 0)
     1970    {
     1971        *pcbRet = cbSrc;
     1972        if (cbBuf >= cbSrc)
     1973        {
     1974            void const *pvSrc = NULL;
     1975            rc = rtldrPEReadPartByRva(pThis, pvBits, pThis->ExceptionDir.VirtualAddress, cbSrc, &pvSrc);
     1976            if (RT_SUCCESS(rc))
     1977            {
     1978                memcpy(pvBuf, pvSrc, cbSrc);
     1979                rtldrPEFreePart(pThis, pvBits, pvSrc);
     1980            }
     1981        }
     1982        else
     1983            rc = VERR_BUFFER_OVERFLOW;
     1984    }
     1985    else
     1986    {
     1987        *pcbRet = 0;
     1988        rc = VERR_NOT_FOUND;
     1989    }
    19461990    return rc;
    19471991}
     
    20172061        case RTLDRPROP_INTERNAL_NAME:
    20182062            return rtLdrPE_QueryInternalName(pModPe, pvBits, pvBuf, cbBuf, pcbRet);
     2063
     2064        case RTLDRPROP_UNWIND_INFO:
     2065            return rtLdrPE_QueryUnwindInfo(pModPe, pvBits, pvBuf, cbBuf, pcbRet);
    20192066
    20202067        default:
     
    40334080                pModPe->DebugDir      = OptHdr.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
    40344081                pModPe->SecurityDir   = OptHdr.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY];
     4082                pModPe->ExceptionDir  = OptHdr.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXCEPTION];
    40354083                pModPe->fDllCharacteristics = OptHdr.DllCharacteristics;
    40364084
  • trunk/src/VBox/Runtime/include/internal/dbgmod.h

    r69111 r73375  
    236236     * @param   pvBuf           Pointer to the return buffer.
    237237     * @param   cbBuf           The size of the return buffer.
    238      * @sa      RTLdrQueryProp
    239      */
    240     DECLCALLBACKMEMBER(int, pfnQueryProp)(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf);
     238     * @param   pcbRet          How many bytes was actually returned.  In the
     239     *                          case of VERR_BUFFER_OVERFLOW this will contain
     240     *                          the required buffer size.  Optional.
     241     * @sa      RTLdrQueryPropEx
     242     */
     243    DECLCALLBACKMEMBER(int, pfnQueryProp)(PRTDBGMODINT pMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet);
    241244
    242245    /** For catching initialization errors (RTDBGMODVTIMG_MAGIC). */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette