VirtualBox

Changeset 53668 in vbox


Ignore:
Timestamp:
Jan 2, 2015 12:33:14 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
97445
Message:

VBoxDTrace: More unresolved ring-0 stuff. (r45)

Location:
trunk/src/VBox/ExtPacks/VBoxDTrace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ExtPacks/VBoxDTrace/VBoxDTraceR0/VBoxDTraceR0.cpp

    r53667 r53668  
    4242#include <iprt/mem.h>
    4343#include <iprt/mp.h>
     44#include <iprt/semaphore.h>
    4445#include <iprt/spinlock.h>
    4546#include <iprt/string.h>
     47#include <iprt/thread.h>
    4648#include <iprt/time.h>
    4749
     
    677679
    678680
     681/*
     682 *
     683 * Virtual Memory / Resource Allocator.
     684 * Virtual Memory / Resource Allocator.
     685 * Virtual Memory / Resource Allocator.
     686 *
     687 */
     688
     689
    679690/** The number of bits per chunk.
    680691 * @remarks The 32 bytes are for heap headers and such like.  */
     
    941952}
    942953
     954
     955/*
     956 *
     957 * Memory Allocators.
     958 * Memory Allocators.
     959 * Memory Allocators.
     960 *
     961 */
     962
     963
     964/* kmem_alloc implementation */
     965void *VBoxDtKMemAlloc(size_t cbMem, uint32_t fFlags)
     966{
     967    void *pvMem;
     968    int rc = RTMemAllocEx(cbMem, 0, fFlags & KM_NOSLEEP ? RTMEMALLOCEX_FLAGS_ANY_CTX : 0, &pvMem);
     969    AssertRCReturn(rc, NULL);
     970    AssertPtr(pvMem);
     971    return pvMem;
     972}
     973
     974
     975/* kmem_zalloc implementation */
     976void *VBoxDtKMemAllocZ(size_t cbMem, uint32_t fFlags)
     977{
     978    void *pvMem;
     979    int rc = RTMemAllocEx(cbMem, 0,
     980                          (fFlags & KM_NOSLEEP ? RTMEMALLOCEX_FLAGS_ANY_CTX : 0) | RTMEMALLOCEX_FLAGS_ZEROED,
     981                          &pvMem);
     982    AssertRCReturn(rc, NULL);
     983    AssertPtr(pvMem);
     984    return pvMem;
     985}
     986
     987
     988/* kmem_free implementation */
     989void  VBoxDtKMemFree(void *pvMem, size_t cbMem)
     990{
     991    RTMemFreeEx(pvMem, cbMem);
     992}
     993
     994
     995/**
     996 * Memory cache mockup structure.
     997 * No slab allocator here!
     998 */
     999struct VBoxDtMemCache
     1000{
     1001    uint32_t u32Magic;
     1002    size_t cbBuf;
     1003    size_t cbAlign;
     1004};
     1005
     1006
     1007/* Limited kmem_cache_create implementation. */
     1008struct VBoxDtMemCache *VBoxDtKMemCacheCreate(const char *pszName, size_t cbBuf, size_t cbAlign,
     1009                                             PFNRT pfnCtor, PFNRT pfnDtor, PFNRT pfnReclaim,
     1010                                             void *pvUser, void *pvVM, uint32_t fFlags)
     1011{
     1012    /*
     1013     * Check the input.
     1014     */
     1015    AssertReturn(cbBuf > 0 && cbBuf < _1G, NULL);
     1016    AssertReturn(RT_IS_POWER_OF_TWO(cbAlign), NULL);
     1017    AssertReturn(!pfnCtor, NULL);
     1018    AssertReturn(!pfnDtor, NULL);
     1019    AssertReturn(!pfnReclaim, NULL);
     1020    AssertReturn(!pvUser, NULL);
     1021    AssertReturn(!pvVM, NULL);
     1022    AssertReturn(!fFlags, NULL);
     1023
     1024    /*
     1025     * Create a parameter container. Don't bother with anything fancy here yet,
     1026     * just get something working.
     1027     */
     1028    struct VBoxDtMemCache *pThis = (struct VBoxDtMemCache *)RTMemAlloc(sizeof(*pThis));
     1029    if (!pThis)
     1030        return NULL;
     1031
     1032    pThis->cbAlign = cbAlign;
     1033    pThis->cbBuf   = cbBuf;
     1034    return pThis;
     1035}
     1036
     1037
     1038/* Limited kmem_cache_destroy implementation. */
     1039void  VBoxDtKMemCacheDestroy(struct VBoxDtMemCache *pThis)
     1040{
     1041    RTMemFree(pThis);
     1042}
     1043
     1044
     1045/* kmem_cache_alloc implementation. */
     1046void *VBoxDtKMemCacheAlloc(struct VBoxDtMemCache *pThis, uint32_t fFlags)
     1047{
     1048    void *pvMem;
     1049    int rc = RTMemAllocEx(pThis->cbBuf,
     1050                          pThis->cbAlign,
     1051                          (fFlags & KM_NOSLEEP ? RTMEMALLOCEX_FLAGS_ANY_CTX : 0) | RTMEMALLOCEX_FLAGS_ZEROED,
     1052                          &pvMem);
     1053    AssertRCReturn(rc, NULL);
     1054    AssertPtr(pvMem);
     1055    return pvMem;
     1056}
     1057
     1058
     1059/* kmem_cache_free implementation. */
     1060void  VBoxDtKMemCacheFree(struct VBoxDtMemCache *pThis, void *pvMem)
     1061{
     1062    RTMemFreeEx(pvMem, pThis->cbBuf);
     1063}
     1064
     1065
    9431066#if 0
    944 VBoxDtMutexIsOwner
    945 VBoxDtMutexExit
    946 VBoxDtMutexEnter
    947 
    948 VBoxDtKMemFree
    949 VBoxDtKMemCacheFree
    950 VBoxDtKMemCacheDestroy
    951 VBoxDtKMemCacheCreate
    952 VBoxDtKMemCacheAlloc
    953 
    954 VBoxDtKMemAllocZ
    955 VBoxDtKMemAlloc
    956 
    9571067VBoxDtGetKernelBase
    9581068VBoxDtGetCurrentThread
    959 VBoxDtGetCurrentProc
    9601069#endif
     1070
     1071
     1072
     1073/*
     1074 *
     1075 * Mutex Sempahore Wrappers.
     1076 *
     1077 */
     1078
     1079
     1080/** Initializes a mutex. */
     1081int VBoxDtMutexInit(struct VBoxDtMutex *pMtx)
     1082{
     1083    AssertReturn(pMtx != &g_DummyMtx, -1);
     1084    AssertPtr(pMtx);
     1085
     1086    pMtx->hOwner = NIL_RTNATIVETHREAD;
     1087    pMtx->hMtx   = NIL_RTSEMMUTEX;
     1088    int rc = RTSemMutexCreate(&pMtx->hMtx);
     1089    if (RT_SUCCESS(rc))
     1090        return 0;
     1091    return -1;
     1092}
     1093
     1094
     1095/** Deletes a mutex. */
     1096void VBoxDtMutexDelete(struct VBoxDtMutex *pMtx)
     1097{
     1098    AssertReturnVoid(pMtx != &g_DummyMtx);
     1099    AssertPtr(pMtx);
     1100    if (pMtx->hMtx == NIL_RTSEMMUTEX || pMtx->hMtx == NULL)
     1101        return;
     1102
     1103    Assert(pMtx->hOwner == NIL_RTNATIVETHREAD);
     1104    int rc = RTSemMutexDestroy(pMtx->hMtx); AssertRC(rc);
     1105    pMtx->hMtx = NIL_RTSEMMUTEX;
     1106}
     1107
     1108
     1109/* mutex_enter implementation */
     1110void VBoxDtMutexEnter(struct VBoxDtMutex *pMtx)
     1111{
     1112    AssertPtr(pMtx);
     1113    if (pMtx == &g_DummyMtx)
     1114        return;
     1115
     1116    RTNATIVETHREAD hSelf = RTThreadNativeSelf();
     1117
     1118    int rc = RTSemMutexRequest(pMtx->hMtx, RT_INDEFINITE_WAIT);
     1119    AssertFatalRC(rc);
     1120
     1121    Assert(pMtx->hOwner == NIL_RTNATIVETHREAD);
     1122    pMtx->hOwner = hSelf;
     1123}
     1124
     1125
     1126/* mutex_exit implementation */
     1127void VBoxDtMutexExit(struct VBoxDtMutex *pMtx)
     1128{
     1129    AssertPtr(pMtx);
     1130    if (pMtx == &g_DummyMtx)
     1131        return;
     1132
     1133    Assert(pMtx->hOwner == RTThreadNativeSelf());
     1134
     1135    pMtx->hOwner = NIL_RTNATIVETHREAD;
     1136    int rc = RTSemMutexRelease(pMtx->hMtx);
     1137    AssertFatalRC(rc);
     1138}
     1139
     1140
     1141/* MUTEX_HELD implementation */
     1142bool VBoxDtMutexIsOwner(struct VBoxDtMutex *pMtx)
     1143{
     1144    AssertPtrReturn(pMtx, false);
     1145    if (pMtx == &g_DummyMtx)
     1146        return true;
     1147    return pMtx->hOwner == RTThreadNativeSelf();
     1148}
     1149
    9611150
    9621151
     
    11061295             AssertCompile(sizeof(pProbeLoc->idProbe) == sizeof(dtrace_id_t));
    11071296             pProbeLoc->idProbe = dtrace_probe_create(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName,
    1108                                                       0 /*aframes*/, pProbeLoc);
     1297                                                      1 /*aframes*/, pProbeLoc);
    11091298             pProv->TracerData.DTrace.cProvidedProbes++;
    11101299         }
  • trunk/src/VBox/ExtPacks/VBoxDTrace/include/VBoxDTraceTypes.h

    r53667 r53668  
    247247typedef struct VBoxDtMutex
    248248{
    249     RTSPINLOCK hSpinlock;
     249    RTSEMMUTEX              hMtx;
     250    RTNATIVETHREAD volatile hOwner;
    250251} kmutex_t;
    251252#define mutex_enter             VBoxDtMutexEnter
     
    255256#define mod_lock                g_DummyMtx
    256257#define cpu_lock                g_DummyMtx
     258int  VBoxDtMutexInit(struct VBoxDtMutex *pMtx);
     259void VBoxDtMutexDelete(struct VBoxDtMutex *pMtx);
    257260void VBoxDtMutexEnter(struct VBoxDtMutex *pMtx);
    258261void VBoxDtMutexExit(struct VBoxDtMutex *pMtx);
  • trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/uts/common/dtrace/dtrace.c

    r53667 r53668  
    1251112511#endif
    1251212512{
     12513#ifndef VBOX
    1251312514        minor_t minor;
    1251412515        major_t major;
     12516#endif
    1251512517        char c[30];
    1251612518        dtrace_state_t *state;
     
    1253912541        state->dts_epid = DTRACE_EPIDNONE + 1;
    1254012542
     12543#ifndef VBOX
    1254112544        (void) snprintf(c, sizeof (c), "dtrace_aggid_%d", minor);
     12545#else
     12546        (void) snprintf(c, sizeof (c), "dtrace_aggid_%p", state);
     12547#endif
    1254212548        state->dts_aggid_arena = vmem_create(c, (void *)1, UINT32_MAX, 1,
    1254312549            NULL, NULL, NULL, 0, VM_SLEEP | VMC_IDENTIFIER);
     
    1478514791        dtrace_enabling_t *enab;
    1478614792
     14793#ifndef VBOX
     14794        if (   VBoxDtMutexInit(&dtrace_lock)
     14795            || VBoxDtMutexInit(&dtrace_provider_lock)
     14796            || VBoxDtMutexInit(&dtrace_meta_lock)
     14797# ifdef DEBUG
     14798            || VBoxDtMutexInit(&dtrace_errlock);
     14799# endif
     14800            )
     14801            return (DDI_FAILURE);
     14802#endif
     14803
    1478714804        mutex_enter(&cpu_lock);
    1478814805        mutex_enter(&dtrace_provider_lock);
Note: See TracChangeset for help on using the changeset viewer.

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