Changeset 99417 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 17, 2023 12:49:02 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/NvramStoreImpl.cpp
r98262 r99417 919 919 /* 920 920 * Only store the NVRAM content if the path is not empty, if it is 921 * this means the VM was just created and the store was n not saved yet,921 * this means the VM was just created and the store was not saved yet, 922 922 * see @bugref{10191}. 923 923 */ … … 931 931 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 932 932 if ( m->bd->mapNvram.size() == 1 933 && m->bd->mapNvram. find(Utf8Str("efi/nvram")) != m->bd->mapNvram.end())934 { 935 RTVFSFILE hVfsFileNvram = m->bd->mapNvram [Utf8Str("efi/nvram")];933 && m->bd->mapNvram.begin()->first == "efi/nvram") 934 { 935 RTVFSFILE hVfsFileNvram = m->bd->mapNvram.begin()->second; 936 936 937 937 vrc = RTVfsFileSeek(hVfsFileNvram, 0 /*offSeek*/, RTFILE_SEEK_BEGIN, NULL /*poffActual*/); 938 Assert RC(vrc); RT_NOREF(vrc);938 AssertLogRelRC(vrc); 939 939 940 940 RTVFSIOSTREAM hVfsIosDst; … … 1060 1060 1061 1061 #ifndef VBOX_COM_INPROC 1062 1062 1063 HRESULT NvramStore::i_retainUefiVarStore(PRTVFS phVfs, bool fReadonly) 1063 1064 { … … 1262 1263 } 1263 1264 1264 #else 1265 #else /* VBOX_COM_INPROC */ 1266 1265 1267 // 1266 1268 // private methods … … 1272 1274 PDRVMAINNVRAMSTORE pThis = RT_FROM_MEMBER(pInterface, DRVMAINNVRAMSTORE, IVfs); 1273 1275 1276 Utf8Str strKey; 1277 int vrc = strKey.printfNoThrow("%s/%s", pszNamespace, pszPath); 1278 AssertRCReturn(vrc, vrc); 1279 1274 1280 AutoReadLock rlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS); 1275 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find( Utf8StrFmt("%s/%s", pszNamespace, pszPath));1281 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey); 1276 1282 if (it != pThis->pNvramStore->m->bd->mapNvram.end()) 1277 1283 { … … 1290 1296 PDRVMAINNVRAMSTORE pThis = RT_FROM_MEMBER(pInterface, DRVMAINNVRAMSTORE, IVfs); 1291 1297 1298 Utf8Str strKey; 1299 int vrc = strKey.printfNoThrow("%s/%s", pszNamespace, pszPath); 1300 AssertRCReturn(vrc, vrc); 1301 1292 1302 AutoReadLock rlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS); 1293 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find( Utf8StrFmt("%s/%s", pszNamespace, pszPath));1303 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey); 1294 1304 if (it != pThis->pNvramStore->m->bd->mapNvram.end()) 1295 1305 { 1296 1306 RTVFSFILE hVfsFile = it->second; 1297 1307 1298 intvrc = RTVfsFileSeek(hVfsFile, 0 /*offSeek*/, RTFILE_SEEK_BEGIN, NULL /*poffActual*/);1299 Assert RC(vrc); RT_NOREF(vrc);1308 vrc = RTVfsFileSeek(hVfsFile, 0 /*offSeek*/, RTFILE_SEEK_BEGIN, NULL /*poffActual*/); 1309 AssertLogRelRC(vrc); 1300 1310 1301 1311 return RTVfsFileRead(hVfsFile, pvBuf, cbRead, NULL /*pcbRead*/); … … 1312 1322 PDRVMAINNVRAMSTORE pThis = RT_FROM_MEMBER(pInterface, DRVMAINNVRAMSTORE, IVfs); 1313 1323 1324 Utf8Str strKey; 1325 int vrc = strKey.printfNoThrow("%s/%s", pszNamespace, pszPath); 1326 AssertRCReturn(vrc, vrc); 1327 1314 1328 AutoWriteLock wlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS); 1315 1329 1316 int vrc = VINF_SUCCESS; 1317 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(Utf8StrFmt("%s/%s", pszNamespace, pszPath)); 1330 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey); 1318 1331 if (it != pThis->pNvramStore->m->bd->mapNvram.end()) 1319 1332 { … … 1321 1334 1322 1335 vrc = RTVfsFileSeek(hVfsFile, 0 /*offSeek*/, RTFILE_SEEK_BEGIN, NULL /*poffActual*/); 1323 Assert RC(vrc);1336 AssertLogRelRC(vrc); 1324 1337 vrc = RTVfsFileSetSize(hVfsFile, cbWrite, RTVFSFILE_SIZE_F_NORMAL); 1325 1338 if (RT_SUCCESS(vrc)) … … 1332 1345 vrc = RTVfsFileFromBuffer(RTFILE_O_READ | RTFILE_O_WRITE, pvBuf, cbWrite, &hVfsFile); 1333 1346 if (RT_SUCCESS(vrc)) 1334 pThis->pNvramStore->m->bd->mapNvram[Utf8StrFmt("%s/%s", pszNamespace, pszPath)] = hVfsFile; 1347 { 1348 try 1349 { 1350 pThis->pNvramStore->m->bd->mapNvram[strKey] = hVfsFile; 1351 } 1352 catch (...) 1353 { 1354 AssertLogRelFailed(); 1355 RTVfsFileRelease(hVfsFile); 1356 vrc = VERR_UNEXPECTED_EXCEPTION; 1357 } 1358 } 1335 1359 } 1336 1360 … … 1344 1368 PDRVMAINNVRAMSTORE pThis = RT_FROM_MEMBER(pInterface, DRVMAINNVRAMSTORE, IVfs); 1345 1369 1370 Utf8Str strKey; 1371 int vrc = strKey.printfNoThrow("%s/%s", pszNamespace, pszPath); 1372 AssertRCReturn(vrc, vrc); 1373 1346 1374 AutoWriteLock wlock(pThis->pNvramStore COMMA_LOCKVAL_SRC_POS); 1347 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find( Utf8StrFmt("%s/%s", pszNamespace, pszPath));1375 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.find(strKey); 1348 1376 if (it != pThis->pNvramStore->m->bd->mapNvram.end()) 1349 1377 { … … 1373 1401 void *pvData = NULL; 1374 1402 size_t cbDataMax = 0; 1375 NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.begin(); 1376 1377 while (it != pThis->pNvramStore->m->bd->mapNvram.end()) 1403 int vrc = i_SsmSaveExecInner(pThis, pHlp, pSSM, &pvData, &cbDataMax); 1404 if (pvData) 1405 RTMemFree(pvData); 1406 AssertRCReturn(vrc, vrc); 1407 1408 pThis->pNvramStore->m->fSsmSaved = true; 1409 return pHlp->pfnSSMPutU32(pSSM, UINT32_MAX); /* sanity/terminator */ 1410 } 1411 1412 1413 /*static*/ 1414 int NvramStore::i_SsmSaveExecInner(PDRVMAINNVRAMSTORE pThis, PCPDMDRVHLPR3 pHlp, PSSMHANDLE pSSM, 1415 void **ppvData, size_t *pcbDataMax) RT_NOEXCEPT 1416 { 1417 for (NvramStoreIter it = pThis->pNvramStore->m->bd->mapNvram.begin(); it != pThis->pNvramStore->m->bd->mapNvram.end(); ++it) 1378 1418 { 1379 1419 RTVFSFILE hVfsFile = it->second; 1420 1380 1421 uint64_t cbFile; 1381 1382 1422 int vrc = RTVfsFileQuerySize(hVfsFile, &cbFile); 1383 1423 AssertRCReturn(vrc, vrc); 1384 1424 AssertReturn(cbFile < _1M, VERR_OUT_OF_RANGE); 1385 1425 1386 if (cbDataMax < cbFile) 1387 { 1388 pvData = RTMemRealloc(pvData, cbFile); 1389 AssertPtrReturn(pvData, VERR_NO_MEMORY); 1390 cbDataMax = cbFile; 1391 } 1392 1393 vrc = RTVfsFileReadAt(hVfsFile, 0 /*off*/, pvData, cbFile, NULL /*pcbRead*/); 1426 if (*pcbDataMax < cbFile) 1427 { 1428 void *pvNew = RTMemRealloc(*ppvData, cbFile); 1429 AssertPtrReturn(pvNew, VERR_NO_MEMORY); 1430 *ppvData = pvNew; 1431 *pcbDataMax = cbFile; 1432 } 1433 1434 vrc = RTVfsFileReadAt(hVfsFile, 0 /*off*/, *ppvData, cbFile, NULL /*pcbRead*/); 1394 1435 AssertRCReturn(vrc, vrc); 1395 1436 1396 1437 pHlp->pfnSSMPutStrZ(pSSM, it->first.c_str()); 1397 1438 pHlp->pfnSSMPutU64(pSSM, cbFile); 1398 pHlp->pfnSSMPutMem(pSSM, pvData, cbFile); 1399 it++; 1400 } 1401 1402 if (pvData) 1403 RTMemFree(pvData); 1404 1405 pThis->pNvramStore->m->fSsmSaved = true; 1406 return pHlp->pfnSSMPutU32(pSSM, UINT32_MAX); /* sanity/terminator */ 1439 pHlp->pfnSSMPutMem(pSSM, *ppvData, cbFile); 1440 } 1441 return VINF_SUCCESS; 1407 1442 } 1408 1443 … … 1439 1474 void *pvData = NULL; 1440 1475 size_t cbDataMax = 0; 1441 while (cEntries--) 1442 { 1443 char szId[_1K]; /* Lazy developer */ 1444 uint64_t cbFile = 0; 1445 1446 vrc = pHlp->pfnSSMGetStrZ(pSSM, &szId[0], sizeof(szId)); 1447 AssertRCReturn(vrc, vrc); 1448 1449 vrc = pHlp->pfnSSMGetU64(pSSM, &cbFile); 1450 AssertRCReturn(vrc, vrc); 1451 AssertReturn(cbFile < _1M, VERR_OUT_OF_RANGE); 1452 1453 if (cbDataMax < cbFile) 1454 { 1455 pvData = RTMemRealloc(pvData, cbFile); 1456 AssertPtrReturn(pvData, VERR_NO_MEMORY); 1457 cbDataMax = cbFile; 1458 } 1459 1460 vrc = pHlp->pfnSSMGetMem(pSSM, pvData, cbFile); 1461 AssertRCReturn(vrc, vrc); 1462 1463 RTVFSFILE hVfsFile; 1464 vrc = RTVfsFileFromBuffer(RTFILE_O_READWRITE, pvData, cbFile, &hVfsFile); 1465 AssertRCReturn(vrc, vrc); 1466 1467 pThis->pNvramStore->m->bd->mapNvram[Utf8Str(szId)] = hVfsFile; 1468 } 1469 1476 vrc = i_SsmLoadExecInner(pThis, pHlp, pSSM, cEntries, &pvData, &cbDataMax); 1470 1477 if (pvData) 1471 1478 RTMemFree(pvData); 1479 AssertRCReturn(vrc, vrc); 1472 1480 1473 1481 /* The marker. */ … … 1482 1490 1483 1491 1492 /*static*/ 1493 int NvramStore::i_SsmLoadExecInner(PDRVMAINNVRAMSTORE pThis, PCPDMDRVHLPR3 pHlp, PSSMHANDLE pSSM, 1494 uint32_t cEntries, void **ppvData, size_t *pcbDataMax) RT_NOEXCEPT 1495 { 1496 while (cEntries-- > 0) 1497 { 1498 char szId[_1K]; /* Lazy developer */ 1499 int vrc = pHlp->pfnSSMGetStrZ(pSSM, &szId[0], sizeof(szId)); 1500 AssertRCReturn(vrc, vrc); 1501 1502 uint64_t cbFile = 0; 1503 vrc = pHlp->pfnSSMGetU64(pSSM, &cbFile); 1504 AssertRCReturn(vrc, vrc); 1505 AssertReturn(cbFile < _1M, VERR_OUT_OF_RANGE); 1506 1507 if (*pcbDataMax < cbFile) 1508 { 1509 void *pvNew = RTMemRealloc(*ppvData, cbFile); 1510 AssertPtrReturn(pvNew, VERR_NO_MEMORY); 1511 *ppvData = pvNew; 1512 *pcbDataMax = cbFile; 1513 } 1514 1515 vrc = pHlp->pfnSSMGetMem(pSSM, *ppvData, cbFile); 1516 AssertRCReturn(vrc, vrc); 1517 1518 RTVFSFILE hVfsFile; 1519 vrc = RTVfsFileFromBuffer(RTFILE_O_READWRITE, *ppvData, cbFile, &hVfsFile); 1520 AssertRCReturn(vrc, vrc); 1521 1522 try 1523 { 1524 pThis->pNvramStore->m->bd->mapNvram[Utf8Str(szId)] = hVfsFile; 1525 } 1526 catch (...) 1527 { 1528 AssertLogRelFailed(); 1529 RTVfsFileRelease(hVfsFile); 1530 return VERR_UNEXPECTED_EXCEPTION; 1531 } 1532 } 1533 1534 return VINF_SUCCESS; 1535 } 1536 1537 1484 1538 /** 1485 1539 * @interface_method_impl{PDMIBASE,pfnQueryInterface} … … 1514 1568 && !pThis->pNvramStore->m->fSsmSaved) 1515 1569 { 1516 int vrc = pThis->pNvramStore->i_saveStore(); 1517 AssertRC(vrc); /** @todo Disk full error? */ 1570 try 1571 { 1572 int vrc = pThis->pNvramStore->i_saveStore(); 1573 AssertLogRelRC(vrc); /** @todo Disk full error? */ 1574 } 1575 catch (...) 1576 { 1577 AssertLogRelFailed(); 1578 } 1518 1579 } 1519 1580 } … … 1578 1639 if (cRefs == 1) 1579 1640 { 1580 int vrc = pThis->pNvramStore->i_loadStore(pThis->pNvramStore->m->bd->strNvramPath.c_str()); 1641 int vrc; 1642 try 1643 { 1644 vrc = pThis->pNvramStore->i_loadStore(pThis->pNvramStore->m->bd->strNvramPath.c_str()); 1645 } 1646 catch (...) 1647 { 1648 vrc = VERR_UNEXPECTED_EXCEPTION; 1649 } 1581 1650 if (RT_FAILURE(vrc)) 1582 1651 { … … 1641 1710 PDM_DRVREG_VERSION 1642 1711 }; 1643 #endif /* !VBOX_COM_INPROC */ 1712 1713 #endif /* VBOX_COM_INPROC */ 1644 1714 1645 1715 /* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note:
See TracChangeset
for help on using the changeset viewer.