Changeset 90858 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Aug 24, 2021 9:21:53 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/log/log.cpp
r90857 r90858 1202 1202 1203 1203 1204 # if 0 /* obsolete */1205 /**1206 * Create a logger instance clone for RC usage.1207 *1208 * @returns iprt status code.1209 *1210 * @param pLogger The logger instance to be cloned.1211 * @param pLoggerRC Where to create the RC logger instance.1212 * @param cbLoggerRC Amount of memory allocated to for the RC logger1213 * instance clone.1214 * @param pfnLoggerRCPtr Pointer to logger wrapper function for this1215 * instance (RC Ptr).1216 * @param pfnFlushRCPtr Pointer to flush function (RC Ptr).1217 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.1218 */1219 RTDECL(int) RTLogCloneRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC, size_t cbLoggerRC,1220 RTRCPTR pfnLoggerRCPtr, RTRCPTR pfnFlushRCPtr, uint32_t fFlags)1221 {1222 /*1223 * Validate input.1224 */1225 if ( !pLoggerRC1226 || !pfnFlushRCPtr1227 || !pfnLoggerRCPtr)1228 {1229 AssertMsgFailed(("Invalid parameters!\n"));1230 return VERR_INVALID_PARAMETER;1231 }1232 if (cbLoggerRC < sizeof(*pLoggerRC))1233 {1234 AssertMsgFailed(("%d min=%d\n", cbLoggerRC, sizeof(*pLoggerRC)));1235 return VERR_INVALID_PARAMETER;1236 }1237 1238 /*1239 * Initialize GC instance.1240 */1241 pLoggerRC->offScratch = 0;1242 pLoggerRC->fPendingPrefix = false;1243 pLoggerRC->pfnLogger = pfnLoggerRCPtr;1244 pLoggerRC->pfnFlush = pfnFlushRCPtr;1245 pLoggerRC->u32Magic = RTLOGGERRC_MAGIC;1246 pLoggerRC->fFlags = fFlags | RTLOGFLAGS_DISABLED;1247 pLoggerRC->cGroups = 1;1248 pLoggerRC->afGroups[0] = 0;1249 1250 /*1251 * Resolve defaults.1252 */1253 if (!pLogger)1254 {1255 pLogger = RTLogDefaultInstance();1256 if (!pLogger)1257 return VINF_SUCCESS;1258 }1259 1260 /*1261 * Check if there's enough space for the groups.1262 */1263 if (cbLoggerRC < (size_t)RT_UOFFSETOF_DYN(RTLOGGERRC, afGroups[pLogger->cGroups]))1264 {1265 AssertMsgFailed(("%zu req=%zu cGroups=%d\n", cbLoggerRC, RT_UOFFSETOF_DYN(RTLOGGERRC, afGroups[pLogger->cGroups]), pLogger->cGroups));1266 return VERR_BUFFER_OVERFLOW;1267 }1268 memcpy(&pLoggerRC->afGroups[0], &pLogger->afGroups[0], pLogger->cGroups * sizeof(pLoggerRC->afGroups[0]));1269 pLoggerRC->cGroups = pLogger->cGroups;1270 1271 /*1272 * Copy bits from the HC instance.1273 */1274 pLoggerRC->fPendingPrefix = pLogger->pInt->fPendingPrefix;1275 pLoggerRC->fFlags |= pLogger->fFlags;1276 1277 /*1278 * Check if we can remove the disabled flag.1279 */1280 if ( pLogger->fDestFlags1281 && !((pLogger->fFlags | fFlags) & RTLOGFLAGS_DISABLED))1282 pLoggerRC->fFlags &= ~RTLOGFLAGS_DISABLED;1283 1284 return VINF_SUCCESS;1285 }1286 RT_EXPORT_SYMBOL(RTLogCloneRC);1287 # endif1288 1289 1290 # if 0 /* obsolete */1291 /**1292 * Flushes a RC logger instance to a R3 logger.1293 *1294 *1295 * @returns iprt status code.1296 * @param pLogger The R3 logger instance to flush pLoggerRC to. If NULL1297 * the default logger is used.1298 * @param pLoggerRC The RC logger instance to flush.1299 */1300 RTDECL(void) RTLogFlushRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC)1301 {1302 /*1303 * Resolve defaults.1304 */1305 if (!pLogger)1306 {1307 pLogger = RTLogDefaultInstance();1308 if (!pLogger)1309 {1310 pLoggerRC->offScratch = 0;1311 return;1312 }1313 }1314 1315 /*1316 * Any thing to flush?1317 */1318 if ( pLogger->offScratch1319 || pLoggerRC->offScratch)1320 {1321 /*1322 * Acquire logger instance sem.1323 */1324 int rc = rtlogLock(pLogger);1325 if (RT_FAILURE(rc))1326 return;1327 1328 /*1329 * Write whatever the GC instance contains to the HC one, and then1330 * flush the HC instance.1331 */1332 if (pLoggerRC->offScratch)1333 {1334 rtLogOutput(pLogger, pLoggerRC->achScratch, pLoggerRC->offScratch);1335 rtLogOutput(pLogger, NULL, 0);1336 pLoggerRC->offScratch = 0;1337 }1338 1339 /*1340 * Release the semaphore.1341 */1342 rtlogUnlock(pLogger);1343 }1344 }1345 RT_EXPORT_SYMBOL(RTLogFlushRC);1346 # endif1347 1348 # ifdef IN_RING31349 # if 0 /* obsolete */1350 RTDECL(int) RTLogCreateForR0(PRTLOGGER pLogger, size_t cbLogger,1351 RTR0PTR pLoggerR0Ptr, RTR0PTR pfnLoggerR0Ptr, RTR0PTR pfnFlushR0Ptr,1352 uint32_t fFlags, uint32_t fDestFlags, char const *pszThreadName)1353 {1354 /*1355 * Validate input.1356 */1357 AssertPtrReturn(pLogger, VERR_INVALID_PARAMETER);1358 size_t const cbRequired = sizeof(*pLogger) + RTLOGGERINTERNAL_R0_SIZE;1359 AssertReturn(cbLogger >= cbRequired, VERR_BUFFER_OVERFLOW);1360 AssertReturn(pLoggerR0Ptr != NIL_RTR0PTR, VERR_INVALID_PARAMETER);1361 AssertReturn(pfnLoggerR0Ptr != NIL_RTR0PTR, VERR_INVALID_PARAMETER);1362 size_t const cchThreadName = pszThreadName ? strlen(pszThreadName) : 0;1363 AssertReturn(cchThreadName < sizeof(pLogger->pInt->szR0ThreadName), VERR_INVALID_NAME);1364 1365 /*1366 * Initialize the ring-0 instance.1367 */1368 pLogger->achScratch[0] = 0;1369 pLogger->offScratch = 0;1370 pLogger->pfnLogger = (PFNRTLOGGER)pfnLoggerR0Ptr;1371 pLogger->fFlags = fFlags;1372 pLogger->fDestFlags = fDestFlags & ~RTLOGDEST_FILE;1373 pLogger->pInt = NULL;1374 pLogger->cGroups = 1;1375 pLogger->afGroups[0] = 0;1376 1377 uint32_t cMaxGroups = (uint32_t)((cbLogger - cbRequired) / sizeof(pLogger->afGroups[0]));1378 if (fFlags & RTLOGFLAGS_RESTRICT_GROUPS)1379 cMaxGroups /= 2;1380 PRTLOGGERINTERNAL pInt;1381 for (;;)1382 {1383 AssertReturn(cMaxGroups > 0, VERR_BUFFER_OVERFLOW);1384 pInt = (PRTLOGGERINTERNAL)&pLogger->afGroups[cMaxGroups];1385 if (!((uintptr_t)pInt & (sizeof(uint64_t) - 1)))1386 break;1387 cMaxGroups--;1388 }1389 pLogger->pInt = (PRTLOGGERINTERNAL)(pLoggerR0Ptr + (uintptr_t)pInt - (uintptr_t)pLogger);1390 pInt->uRevision = RTLOGGERINTERNAL_REV;1391 pInt->cbSelf = RTLOGGERINTERNAL_R0_SIZE;1392 pInt->hSpinMtx = NIL_RTSEMSPINMUTEX; /* Not serialized. */1393 pInt->pfnFlush = (PFNRTLOGFLUSH)pfnFlushR0Ptr;1394 pInt->pfnPrefix = NULL;1395 pInt->pvPrefixUserArg = NULL;1396 pInt->fPendingPrefix = true;1397 pInt->cMaxGroups = cMaxGroups;1398 pInt->papszGroups = NULL;1399 pInt->cMaxEntriesPerGroup = UINT32_MAX;1400 if (fFlags & RTLOGFLAGS_RESTRICT_GROUPS)1401 {1402 memset(pInt + 1, 0, sizeof(uint32_t) * cMaxGroups);1403 pInt->pacEntriesPerGroup= (uint32_t *)(pLogger->pInt + 1);1404 }1405 else1406 pInt->pacEntriesPerGroup= NULL;1407 pInt->nsR0ProgramStart = RTTimeProgramStartNanoTS();1408 RT_ZERO(pInt->szR0ThreadName);1409 if (cchThreadName)1410 memcpy(pInt->szR0ThreadName, pszThreadName, cchThreadName);1411 1412 pInt->fCreated = true;1413 pLogger->u32Magic = RTLOGGER_MAGIC;1414 return VINF_SUCCESS;1415 }1416 RT_EXPORT_SYMBOL(RTLogCreateForR0);1417 1418 1419 RTDECL(size_t) RTLogCalcSizeForR0(uint32_t cGroups, uint32_t fFlags)1420 {1421 size_t cb = RT_UOFFSETOF_DYN(RTLOGGER, afGroups[cGroups]);1422 cb = RT_ALIGN_Z(cb, sizeof(uint64_t));1423 cb += sizeof(RTLOGGERINTERNAL);1424 if (fFlags & RTLOGFLAGS_RESTRICT_GROUPS)1425 cb += sizeof(uint32_t) * cGroups;1426 return cb;1427 }1428 RT_EXPORT_SYMBOL(RTLogCalcSizeForR0);1429 1430 1431 RTDECL(int) RTLogCopyGroupsAndFlagsForR0(PRTLOGGER pDstLogger, RTR0PTR pDstLoggerR0Ptr,1432 PCRTLOGGER pSrcLogger, uint32_t fFlagsOr, uint32_t fFlagsAnd)1433 {1434 /*1435 * Validate input.1436 */1437 AssertPtrReturn(pDstLogger, VERR_INVALID_PARAMETER);1438 AssertPtrNullReturn(pSrcLogger, VERR_INVALID_PARAMETER);1439 1440 /*1441 * Resolve defaults.1442 */1443 if (!pSrcLogger)1444 {1445 pSrcLogger = RTLogDefaultInstance();1446 if (!pSrcLogger)1447 {1448 pDstLogger->fFlags |= RTLOGFLAGS_DISABLED | fFlagsOr;1449 pDstLogger->cGroups = 1;1450 pDstLogger->afGroups[0] = 0;1451 return VINF_SUCCESS;1452 }1453 }1454 1455 /*1456 * Copy flags and group settings.1457 */1458 pDstLogger->fFlags = (pSrcLogger->fFlags & fFlagsAnd & ~RTLOGFLAGS_RESTRICT_GROUPS) | fFlagsOr;1459 1460 PRTLOGGERINTERNAL pDstInt = (PRTLOGGERINTERNAL)((uintptr_t)pDstLogger->pInt - pDstLoggerR0Ptr + (uintptr_t)pDstLogger);1461 int rc = VINF_SUCCESS;1462 uint32_t cGroups = pSrcLogger->cGroups;1463 if (cGroups > pDstInt->cMaxGroups)1464 {1465 AssertMsgFailed(("cMaxGroups=%zd cGroups=%zd (min size %d)\n", pDstInt->cMaxGroups,1466 pSrcLogger->cGroups, RT_UOFFSETOF_DYN(RTLOGGER, afGroups[pSrcLogger->cGroups]) + RTLOGGERINTERNAL_R0_SIZE));1467 rc = VERR_INVALID_PARAMETER;1468 cGroups = pDstInt->cMaxGroups;1469 }1470 memcpy(&pDstLogger->afGroups[0], &pSrcLogger->afGroups[0], cGroups * sizeof(pDstLogger->afGroups[0]));1471 pDstLogger->cGroups = cGroups;1472 1473 return rc;1474 }1475 RT_EXPORT_SYMBOL(RTLogCopyGroupsAndFlagsForR0);1476 1477 1478 RTDECL(void) RTLogFlushR0(PRTLOGGER pLogger, PRTLOGGER pLoggerR0)1479 {1480 /*1481 * Resolve defaults.1482 */1483 if (!pLogger)1484 {1485 pLogger = RTLogDefaultInstance();1486 if (!pLogger)1487 {1488 /* flushing to "/dev/null". */1489 if (pLoggerR0->offScratch)1490 pLoggerR0->offScratch = 0;1491 return;1492 }1493 }1494 1495 /*1496 * Anything to flush?1497 */1498 if ( pLoggerR0->offScratch1499 || pLogger->offScratch)1500 {1501 /*1502 * Acquire logger semaphores.1503 */1504 int rc = rtlogLock(pLogger);1505 if (RT_FAILURE(rc))1506 return;1507 if (RT_SUCCESS(rc))1508 {1509 /*1510 * Write whatever the GC instance contains to the HC one, and then1511 * flush the HC instance.1512 */1513 if (pLoggerR0->offScratch)1514 {1515 rtLogOutput(pLogger, pLoggerR0->achScratch, pLoggerR0->offScratch);1516 rtLogOutput(pLogger, NULL, 0);1517 pLoggerR0->offScratch = 0;1518 }1519 }1520 rtlogUnlock(pLogger);1521 }1522 }1523 RT_EXPORT_SYMBOL(RTLogFlushR0);1524 1525 # endif /* obsolete */1526 # endif /* IN_RING3 */1527 1528 1529 #if 01530 /**1531 * Flushes the buffer in one logger instance onto another logger.1532 *1533 * @returns iprt status code.1534 *1535 * @param pSrcLogger The logger instance to flush.1536 * @param pDstLogger The logger instance to flush onto.1537 * If NULL the default logger will be used.1538 */1539 RTDECL(void) RTLogFlushToLogger(PRTLOGGER pSrcLogger, PRTLOGGER pDstLogger)1540 {1541 PRTLOGGERINTERNAL pSrcLoggerInt = (PRTLOGGERINTERNAL)pSrcLogger;1542 PRTLOGGERINTERNAL pDstLoggerInt = (PRTLOGGERINTERNAL)pDstLogger;1543 1544 /*1545 * Resolve defaults.1546 */1547 if (!pDstLoggerInt)1548 {1549 pDstLoggerInt = (PRTLOGGERINTERNAL)RTLogDefaultInstance();1550 if (!pDstLoggerInt)1551 {1552 /* flushing to "/dev/null". */1553 if (pSrcLoggerInt->offScratch)1554 {1555 int rc = rtlogLock(pSrcLoggerInt);1556 if (RT_SUCCESS(rc))1557 {1558 pSrcLoggerInt->offScratch = 0;1559 rtlogUnlock(pSrcLoggerInt);1560 }1561 }1562 return;1563 }1564 }1565 1566 /*1567 * Any thing to flush?1568 */1569 if ( pSrcLoggerInt->offScratch1570 || pDstLoggerInt->offScratch)1571 {1572 /*1573 * Acquire logger semaphores.1574 */1575 int rc = rtlogLock(pDstLoggerInt);1576 if (RT_FAILURE(rc))1577 return;1578 rc = rtlogLock(pSrcLoggerInt);1579 if (RT_SUCCESS(rc))1580 {1581 /*1582 * Write whatever the GC instance contains to the HC one, and then1583 * flush the HC instance.1584 */1585 if (pSrcLoggerInt->offScratch)1586 {1587 rtLogOutput(pDstLoggerInt, pSrcLoggerInt->achScratch, pSrcLoggerInt->offScratch);1588 rtLogOutput(pDstLoggerInt, NULL, 0);1589 pSrcLoggerInt->offScratch = 0;1590 }1591 1592 /*1593 * Release the semaphores.1594 */1595 rtlogUnlock(pSrcLoggerInt);1596 }1597 rtlogUnlock(pDstLoggerInt);1598 }1599 }1600 RT_EXPORT_SYMBOL(RTLogFlushToLogger);1601 #endif1602 1603 1604 1204 /** 1605 1205 * Sets the custom prefix callback. … … 1635 1235 } 1636 1236 RT_EXPORT_SYMBOL(RTLogSetCustomPrefixCallback); 1237 1238 /** 1239 * Sets the custom prefix callback. 1240 * 1241 * @returns IPRT status code. 1242 * @param pLogger The logger instance. 1243 * @param pfnCallback The callback. 1244 * @param pvUser The user argument for the callback. 1245 * */ 1246 RTDECL(int) RTLogSetFlushCallback(PRTLOGGER pLogger, PFNRTLOGFLUSH pfnFlush, PFNRTLOGFLUSH *ppfnOldFlush) 1247 { 1248 /* 1249 * Resolve defaults. 1250 */ 1251 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pLogger; 1252 if (!pLoggerInt) 1253 { 1254 pLoggerInt = (PRTLOGGERINTERNAL)RTLogDefaultInstance(); 1255 if (!pLoggerInt) 1256 return VINF_SUCCESS; 1257 } 1258 AssertReturn(pLoggerInt->Core.u32Magic == RTLOGGER_MAGIC, VERR_INVALID_MAGIC); 1259 1260 /* 1261 * Do the work. 1262 */ 1263 rtlogLock(pLoggerInt); 1264 if (ppfnOldFlush) 1265 *ppfnOldFlush = pLoggerInt->pfnFlush; 1266 pLoggerInt->pfnFlush = pfnFlush; 1267 rtlogUnlock(pLoggerInt); 1268 1269 return VINF_SUCCESS; 1270 } 1271 RT_EXPORT_SYMBOL(RTLogSetFlushCallback); 1637 1272 1638 1273
Note:
See TracChangeset
for help on using the changeset viewer.