VirtualBox

Ignore:
Timestamp:
Mar 28, 2012 4:29:41 PM (13 years ago)
Author:
vboxsync
Message:

Runtime/r0drv/solaris: dbg-r0drv addressed todo and some fixes.

Location:
trunk/src/VBox/Runtime/r0drv/solaris
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/solaris/dbg-r0drv-solaris.c

    r40689 r40695  
    2929*   Header Files                                                               *
    3030*******************************************************************************/
     31#include "the-solaris-kernel.h"
     32#include "internal/iprt.h"
     33
    3134#include <iprt/dbg.h>
    32 #include "internal/iprt.h"
    33 
    3435#include <iprt/asm.h>
    3536#include <iprt/assert.h>
     
    3940#include <iprt/string.h>
    4041#include <iprt/thread.h>
    41 
    42 #include <sys/kobj.h>
    43 #include <sys/thread.h>
    44 #include <sys/ctf_api.h>
    45 #include <sys/modctl.h>
    4642
    4743
     
    7066
    7167
     68/**
     69 * Retains a kernel module and opens the CTF data associated with it.
     70 *
     71 * @param pszModule     The name of the module to open.
     72 * @param ppMod         Where to store the module handle.
     73 * @param ppCTF         Where to store the module's CTF handle.
     74 *
     75 * @return IPRT status code.
     76 */
     77static int rtr0DbgKrnlInfoModRetain(char *pszModule, modclt_t **ppMod, ctf_file_t **ppCTF)
     78{
     79    AssertPtrReturn(pszModule, VERR_INVALID_PARAMETER);
     80    AssertPtrReturn(ppMod, VERR_INVALID_PARAMETER);
     81    AssertPtrReturn(ppCTF, VERR_INVALID_PARAMETER);
     82
     83    int rc = VINF_SUCCESS;
     84    modid_t ModId = mod_name_to_modid(pszModule);
     85    if (ModId != -1)
     86    {
     87        *ppMod = mod_hold_by_id(ModId);
     88        if (*ppMod)
     89        {
     90            /*
     91             * Hold mod_lock as ctf_modopen may update the module with uncompressed CTF data.
     92             */
     93            int err;
     94            mutex_enter(&mod_lock);
     95            *ppCTF = ctf_modopen(pThis->pGenUnixMod->mod_mp, &err);
     96            mutex_exit(&mod_lock);
     97
     98            if (*ppCTF)
     99                return VINF_SUCCESS;
     100            else
     101            {
     102                LogRel(("rtr0DbgKrnlInfoModRetain: ctf_modopen failed for '%s' err=%d\n", pszModule, err));
     103                rc = VERR_INTERNAL_ERROR_3;
     104            }
     105
     106            mod_release_mod(*ppMod);
     107        }
     108        else
     109        {
     110            LogRel(("rtr0DbgKrnlInfoModRetain: mod_hold_by_id failed for '%s'\n" pszModule));
     111            rc = VERR_INTERNAL_ERROR_2;
     112        }
     113    }
     114    else
     115    {
     116        LogRel(("rtr0DbgKrnlInfoModRetain: mod_name_to_modid failed for '%s'\n", pszModule));
     117        rc = VERR_INTERNAL_ERROR;
     118    }
     119
     120    return rc;
     121}
     122
     123
     124/**
     125 * Releases the kernel module and closes its CTF data.
     126 *
     127 * @param pMod          Pointer to the module handle.
     128 * @param pCTF          Pointer to the module's CTF handle.
     129 */
     130static void rtr0DbgKrnlInfoModRelease(modctl_t *pMod, ctf_file_t *pCTF)
     131{
     132    AssertPtrReturnVoid(pMod);
     133    AssertPtrReturnVoid(pCTF);
     134
     135    ctf_close(pCTF);
     136    mod_release_mod(pMod);
     137}
     138
     139
    72140RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags)
    73141{
     
    80148        return VERR_NO_MEMORY;
    81149
    82     int rc;
    83     /** @todo r=bird: Where do we release this module? I see other users (crypto) of
    84      * this API mod_release_mod().  Not sure if this is a real issue with a primary
    85      * module like genunix, though.  Another thing, I noticed that mod_hold_by_name
    86      * will (a) allocated a module if not found and (b) replace the filename with
    87      * what you hand in under certain conditions.  These issues doesn't apply with
    88      * genunix, but is worth keeping in mind if other modules needs to be held.  A
    89      * safer alternative would probably be mod_name_to_modid + mod_hold_by_id. */
    90     pThis->pGenUnixMod = mod_hold_by_name("genunix");
    91     if (RT_LIKELY(pThis->pGenUnixMod))
    92     {
    93         /*
    94          * Hold mod_lock as ctf_modopen may update the module with uncompressed CTF data.
    95          */
    96         int err;
    97         mutex_enter(&mod_lock);
    98         pThis->pGenUnixCTF = ctf_modopen(pThis->pGenUnixMod->mod_mp, &err);
    99         mutex_exit(&mod_lock);
    100 
    101         if (RT_LIKELY(pThis->pGenUnixCTF))
    102         {
    103             pThis->u32Magic       = RTDBGKRNLINFO_MAGIC;
    104             pThis->cRefs          = 1;
    105 
    106             *phKrnlInfo = pThis;
    107             return VINF_SUCCESS;
    108         }
    109 
    110         LogRel(("RTR0DbgKrnlInfoOpen: ctf_modopen failed. err=%d\n", err));
    111         rc = VERR_INTERNAL_ERROR_2;
    112     }
    113     else
    114     {
    115         LogRel(("RTR0DbgKrnlInfoOpen: mod_hold_by_name failed for genunix.\n"));
    116         rc = VERR_INTERNAL_ERROR;
    117     }
    118 
     150    char szGenUnixModName[] = "genunix";
     151    int rc = rtr0DbgKrnlInfoModRetain(szGenUnixModName, &pThis->pGenUnixMod, &pThis->pGenUnixCTF);
     152    if (RT_SUCCESS(rc))
     153    {
     154        pThis->u32Magic       = RTDBGKRNLINFO_MAGIC;
     155        pThis->cRefs          = 1;
     156
     157        *phKrnlInfo = pThis;
     158        return VINF_SUCCESS;
     159    }
     160
     161    LogRel(("RTR0DbgKrnlInfoOpen: rtr0DbgKrnlOpenMod failed rc=%d.\n", rc));
     162    RTMemFree(pThis);
    119163    return rc;
    120164}
     
    131175
    132176
    133 static void rtR0DbgKrnlInfoDestroy(PRTDBGKRNLINFOINT pThis)
    134 {
    135     pThis->u32Magic = ~RTDBGKRNLINFO_MAGIC;
    136     ctf_close(pThis->pGenUnixCTF);
    137     mod_release_mod(pThis->pGenUnixMod);
    138     RTMemFree(pThis);
    139 }
    140 
    141 
    142177RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo)
    143178{
     
    149184    uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
    150185    if (cRefs == 0)
    151         rtR0DbgKrnlInfoDestroy(pThis);
     186    {
     187        pThis->u32Magic = ~RTDBGKRNLINFO_MAGIC;
     188        rtr0DbgKrnlInfoModRelease(pThis->pGenUnixCTF, pThis->pGenUnixCTF);
     189        RTMemFree(pThis);
     190    }
    152191    return cRefs;
    153192}
  • trunk/src/VBox/Runtime/r0drv/solaris/the-solaris-kernel.h

    r40669 r40695  
    5555#include <sys/callo.h>
    5656#include <sys/kobj.h>
     57#include <sys/ctf_api.h>
     58#include <sys/modctl.h>
    5759#include "vbi.h"
    5860
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