Changeset 53668 in vbox
- Timestamp:
- Jan 2, 2015 12:33:14 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 97445
- Location:
- trunk/src/VBox/ExtPacks/VBoxDTrace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ExtPacks/VBoxDTrace/VBoxDTraceR0/VBoxDTraceR0.cpp
r53667 r53668 42 42 #include <iprt/mem.h> 43 43 #include <iprt/mp.h> 44 #include <iprt/semaphore.h> 44 45 #include <iprt/spinlock.h> 45 46 #include <iprt/string.h> 47 #include <iprt/thread.h> 46 48 #include <iprt/time.h> 47 49 … … 677 679 678 680 681 /* 682 * 683 * Virtual Memory / Resource Allocator. 684 * Virtual Memory / Resource Allocator. 685 * Virtual Memory / Resource Allocator. 686 * 687 */ 688 689 679 690 /** The number of bits per chunk. 680 691 * @remarks The 32 bytes are for heap headers and such like. */ … … 941 952 } 942 953 954 955 /* 956 * 957 * Memory Allocators. 958 * Memory Allocators. 959 * Memory Allocators. 960 * 961 */ 962 963 964 /* kmem_alloc implementation */ 965 void *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 */ 976 void *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 */ 989 void 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 */ 999 struct VBoxDtMemCache 1000 { 1001 uint32_t u32Magic; 1002 size_t cbBuf; 1003 size_t cbAlign; 1004 }; 1005 1006 1007 /* Limited kmem_cache_create implementation. */ 1008 struct 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. */ 1039 void VBoxDtKMemCacheDestroy(struct VBoxDtMemCache *pThis) 1040 { 1041 RTMemFree(pThis); 1042 } 1043 1044 1045 /* kmem_cache_alloc implementation. */ 1046 void *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. */ 1060 void VBoxDtKMemCacheFree(struct VBoxDtMemCache *pThis, void *pvMem) 1061 { 1062 RTMemFreeEx(pvMem, pThis->cbBuf); 1063 } 1064 1065 943 1066 #if 0 944 VBoxDtMutexIsOwner945 VBoxDtMutexExit946 VBoxDtMutexEnter947 948 VBoxDtKMemFree949 VBoxDtKMemCacheFree950 VBoxDtKMemCacheDestroy951 VBoxDtKMemCacheCreate952 VBoxDtKMemCacheAlloc953 954 VBoxDtKMemAllocZ955 VBoxDtKMemAlloc956 957 1067 VBoxDtGetKernelBase 958 1068 VBoxDtGetCurrentThread 959 VBoxDtGetCurrentProc960 1069 #endif 1070 1071 1072 1073 /* 1074 * 1075 * Mutex Sempahore Wrappers. 1076 * 1077 */ 1078 1079 1080 /** Initializes a mutex. */ 1081 int 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. */ 1096 void 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 */ 1110 void 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 */ 1127 void 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 */ 1142 bool VBoxDtMutexIsOwner(struct VBoxDtMutex *pMtx) 1143 { 1144 AssertPtrReturn(pMtx, false); 1145 if (pMtx == &g_DummyMtx) 1146 return true; 1147 return pMtx->hOwner == RTThreadNativeSelf(); 1148 } 1149 961 1150 962 1151 … … 1106 1295 AssertCompile(sizeof(pProbeLoc->idProbe) == sizeof(dtrace_id_t)); 1107 1296 pProbeLoc->idProbe = dtrace_probe_create(idProvider, pProv->pszModName, pszFnNmBuf, pszPrbName, 1108 0/*aframes*/, pProbeLoc);1297 1 /*aframes*/, pProbeLoc); 1109 1298 pProv->TracerData.DTrace.cProvidedProbes++; 1110 1299 } -
trunk/src/VBox/ExtPacks/VBoxDTrace/include/VBoxDTraceTypes.h
r53667 r53668 247 247 typedef struct VBoxDtMutex 248 248 { 249 RTSPINLOCK hSpinlock; 249 RTSEMMUTEX hMtx; 250 RTNATIVETHREAD volatile hOwner; 250 251 } kmutex_t; 251 252 #define mutex_enter VBoxDtMutexEnter … … 255 256 #define mod_lock g_DummyMtx 256 257 #define cpu_lock g_DummyMtx 258 int VBoxDtMutexInit(struct VBoxDtMutex *pMtx); 259 void VBoxDtMutexDelete(struct VBoxDtMutex *pMtx); 257 260 void VBoxDtMutexEnter(struct VBoxDtMutex *pMtx); 258 261 void VBoxDtMutexExit(struct VBoxDtMutex *pMtx); -
trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/uts/common/dtrace/dtrace.c
r53667 r53668 12511 12511 #endif 12512 12512 { 12513 #ifndef VBOX 12513 12514 minor_t minor; 12514 12515 major_t major; 12516 #endif 12515 12517 char c[30]; 12516 12518 dtrace_state_t *state; … … 12539 12541 state->dts_epid = DTRACE_EPIDNONE + 1; 12540 12542 12543 #ifndef VBOX 12541 12544 (void) snprintf(c, sizeof (c), "dtrace_aggid_%d", minor); 12545 #else 12546 (void) snprintf(c, sizeof (c), "dtrace_aggid_%p", state); 12547 #endif 12542 12548 state->dts_aggid_arena = vmem_create(c, (void *)1, UINT32_MAX, 1, 12543 12549 NULL, NULL, NULL, 0, VM_SLEEP | VMC_IDENTIFIER); … … 14785 14791 dtrace_enabling_t *enab; 14786 14792 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 14787 14804 mutex_enter(&cpu_lock); 14788 14805 mutex_enter(&dtrace_provider_lock);
Note:
See TracChangeset
for help on using the changeset viewer.