VirtualBox

Changeset 52022 in vbox


Ignore:
Timestamp:
Jul 14, 2014 8:28:39 PM (10 years ago)
Author:
vboxsync
Message:

vd-ifs.h: Remove VDCFG* API which uses RTMemLocked*

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vd-ifs.h

    r51752 r52022  
    988988}
    989989
    990 /**
    991  * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
    992  * character value - the memory is locked to prevent paging to disk,
    993  * useful for memory which holds keys, passwords, etc.
    994  *
    995  * @return  VBox status code.
    996  * @param   pCfgIf      Pointer to configuration callback table.
    997  * @param   pszName     Name of an zero terminated character value
    998  * @param   ppszString  Where to store the string pointer. Not set on failure.
    999  *                      Free this using RTMemFree().
    1000  */
    1001 DECLINLINE(int) VDCFGQueryStringAllocLocked(PVDINTERFACECONFIG pCfgIf,
    1002                                             const char *pszName, char **ppszString)
    1003 {
    1004     size_t cb;
    1005     int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
    1006     if (RT_SUCCESS(rc))
    1007     {
    1008         char *pszString = (char *)RTMemLockedAlloc(cb);
    1009         if (pszString)
    1010         {
    1011             rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb);
    1012             if (RT_SUCCESS(rc))
    1013                 *ppszString = pszString;
    1014             else
    1015                 RTMemFree(pszString);
    1016         }
    1017         else
    1018             rc = VERR_NO_MEMORY;
    1019     }
    1020     return rc;
    1021 }
    1022 
    1023 /**
    1024  * Query configuration, dynamically allocated (RTMemAlloc) zero terminated
    1025  * character value with default - the memory is locked to prevent paging to disk,
    1026  * useful for memory which holds keys, passwords, etc.
    1027  *
    1028  * @return  VBox status code.
    1029  * @param   pCfgIf      Pointer to configuration callback table.
    1030  * @param   pszName     Name of an zero terminated character value
    1031  * @param   ppszString  Where to store the string pointer. Not set on failure.
    1032  *                      Free this using RTMemFree().
    1033  * @param   pszDef      The default value.
    1034  */
    1035 DECLINLINE(int) VDCFGQueryStringAllocLockedDef(PVDINTERFACECONFIG pCfgIf,
    1036                                                const char *pszName,
    1037                                                char **ppszString,
    1038                                                const char *pszDef)
    1039 {
    1040     size_t cb;
    1041     int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
    1042     if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
    1043     {
    1044         cb = strlen(pszDef) + 1;
    1045         rc = VINF_SUCCESS;
    1046     }
    1047     if (RT_SUCCESS(rc))
    1048     {
    1049         char *pszString = (char *)RTMemLockedAlloc(cb);
    1050         if (pszString)
    1051         {
    1052             rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pszString, cb);
    1053             if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
    1054             {
    1055                 memcpy(pszString, pszDef, cb);
    1056                 rc = VINF_SUCCESS;
    1057             }
    1058             if (RT_SUCCESS(rc))
    1059                 *ppszString = pszString;
    1060             else
    1061                 RTMemFree(pszString);
    1062         }
    1063         else
    1064             rc = VERR_NO_MEMORY;
    1065     }
    1066     return rc;
    1067 }
    1068 
    1069 /**
    1070  * Query configuration, dynamically allocated (RTMemAlloc) byte string value -
    1071  * the memory is locked to prevent paging to disk, useful for memory which holds
    1072  * keys, passwords, etc..
    1073  *
    1074  * @return  VBox status code.
    1075  * @param   pCfgIf      Pointer to configuration callback table.
    1076  * @param   pszName     Name of an zero terminated character value
    1077  * @param   ppvData     Where to store the byte string pointer. Not set on failure.
    1078  *                      Free this using RTMemFree().
    1079  * @param   pcbData     Where to store the byte string length.
    1080  */
    1081 DECLINLINE(int) VDCFGQueryBytesAllocLocked(PVDINTERFACECONFIG pCfgIf,
    1082                                            const char *pszName, void **ppvData, size_t *pcbData)
    1083 {
    1084     size_t cb;
    1085     int rc = pCfgIf->pfnQuerySize(pCfgIf->Core.pvUser, pszName, &cb);
    1086     if (RT_SUCCESS(rc))
    1087     {
    1088         char *pbData;
    1089         Assert(cb);
    1090 
    1091         pbData = (char *)RTMemLockedAlloc(cb);
    1092         if (pbData)
    1093         {
    1094             if(pCfgIf->pfnQueryBytes)
    1095                 rc = pCfgIf->pfnQueryBytes(pCfgIf->Core.pvUser, pszName, pbData, cb);
    1096             else
    1097                 rc = pCfgIf->pfnQuery(pCfgIf->Core.pvUser, pszName, pbData, cb);
    1098 
    1099             if (RT_SUCCESS(rc))
    1100             {
    1101                 *ppvData = pbData;
    1102                 /* Exclude terminator if the byte data was obtained using the string query callback. */
    1103                 *pcbData = cb;
    1104                 if (!pCfgIf->pfnQueryBytes)
    1105                     (*pcbData)--;
    1106             }
    1107             else
    1108                 RTMemFree(pbData);
    1109         }
    1110         else
    1111             rc = VERR_NO_MEMORY;
    1112     }
    1113     return rc;
    1114 }
    1115 
    1116 /**
    1117  * Frees memory allocated using one of the VDCFGQuery*AllocLocked methods.
    1118  */
    1119 DECLINLINE(void) VDCFGMemLockedFree(void *pvData)
    1120 {
    1121     RTMemLockedFree(pvData);
    1122 }
    1123 
    1124990/** Forward declaration of a VD socket. */
    1125991typedef struct VDSOCKETINT *VDSOCKET;
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