Changeset 23752 in vbox for trunk/src/VBox/VMM/SSM.cpp
- Timestamp:
- Oct 14, 2009 10:12:28 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/SSM.cpp
r23749 r23752 3171 3171 3172 3172 case SSMFIELDTRANS_GCPTR: 3173 AssertMsgReturn(pCur->cb == sizeof(RTGCPTR), ("%#x\n", pCur->cb), VERR_SSM_ INVALID_FIELD_SIZE);3173 AssertMsgReturn(pCur->cb == sizeof(RTGCPTR), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 3174 3174 rc = SSMR3PutGCPtr(pSSM, *(PRTGCPTR)pbField); 3175 3175 break; 3176 3176 3177 3177 case SSMFIELDTRANS_GCPHYS: 3178 AssertMsgReturn(pCur->cb == sizeof(RTGCPHYS), ("%#x\n", pCur->cb), VERR_SSM_ INVALID_FIELD_SIZE);3178 AssertMsgReturn(pCur->cb == sizeof(RTGCPHYS), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 3179 3179 rc = SSMR3PutGCPhys(pSSM, *(PRTGCPHYS)pbField); 3180 3180 break; 3181 3181 3182 3182 default: 3183 AssertMsgFailedReturn(("%#x\n", pCur->pfnGetPutOrTransformer), VERR_SSM_COMPLEX_FIELD); 3184 } 3183 AssertMsgFailedReturn(("%#x\n", pCur->pfnGetPutOrTransformer), VERR_SSM_FIELD_COMPLEX); 3184 } 3185 if (RT_FAILURE(rc)) 3186 return rc; 3185 3187 } 3186 3188 3187 3189 /* end marker */ 3188 3190 return SSMR3PutU32(pSSM, SSMR3STRUCT_END); 3191 } 3192 3193 3194 /** 3195 * Puts a structure, extended API. 3196 * 3197 * @returns VBox status code. 3198 * @param pSSM The saved state handle. 3199 * @param pvStruct The structure address. 3200 * @param cbStruct The size of the struct (use for validation only). 3201 * @param fFlags Combination of SSMSTRUCT_FLAGS_XXX defines. 3202 * @param paFields The array of structure fields descriptions. The 3203 * array must be terminated by a SSMFIELD_ENTRY_TERM(). 3204 * @param pvUser User argument for any callbacks that paFields might 3205 * contain. 3206 */ 3207 VMMR3DECL(int) SSMR3PutStructEx(PSSMHANDLE pSSM, const void *pvStruct, size_t cbStruct, 3208 uint32_t fFlags, PCSSMFIELD paFields, void *pvUser) 3209 { 3210 static uint8_t const s_abZero[_1K] = {0}; 3211 int rc; 3212 3213 /* 3214 * Validation. 3215 */ 3216 AssertMsgReturn(!(fFlags & ~SSMSTRUCT_FLAGS_VALID_MASK), ("%#x\n", fFlags), VERR_INVALID_PARAMETER); 3217 AssertPtr(pvStruct); 3218 AssertPtr(paFields); 3219 3220 3221 /* 3222 * Begin marker. 3223 */ 3224 if (!(fFlags & SSMSTRUCT_FLAGS_NO_MARKERS)) 3225 { 3226 rc = SSMR3PutU32(pSSM, SSMR3STRUCT_BEGIN); 3227 if (RT_FAILURE(rc)) 3228 return rc; 3229 } 3230 3231 /* 3232 * Put the fields 3233 */ 3234 uint32_t off = 0; 3235 for (PCSSMFIELD pCur = paFields; 3236 pCur->cb != UINT32_MAX && pCur->off != UINT32_MAX; 3237 pCur++) 3238 { 3239 AssertMsgReturn( pCur->cb <= cbStruct 3240 && pCur->off + pCur->cb <= cbStruct 3241 && pCur->off + pCur->cb > pCur->off, 3242 ("off=%#x cb=%#x cbStruct=%#x\n", pCur->cb, pCur->off, cbStruct), 3243 VERR_SSM_FIELD_OUT_OF_BOUNDS); 3244 AssertMsgReturn( !(fFlags & SSMSTRUCT_FLAGS_FULL_STRUCT) 3245 || off == pCur->off, 3246 ("off=%#x pCur->off=%#x\n", off, pCur->off), 3247 VERR_SSM_FIELD_NOT_CONSECUTIVE); 3248 3249 uint8_t const *pbField = (uint8_t const *)pvStruct + pCur->off; 3250 switch ((uintptr_t)pCur->pfnGetPutOrTransformer) 3251 { 3252 case SSMFIELDTRANS_NO_TRANSFORMATION: 3253 rc = ssmR3DataWrite(pSSM, pbField, pCur->cb); 3254 break; 3255 3256 case SSMFIELDTRANS_GCPTR: 3257 AssertMsgReturn(pCur->cb == sizeof(RTGCPTR), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 3258 rc = SSMR3PutGCPtr(pSSM, *(PRTGCPTR)pbField); 3259 break; 3260 3261 case SSMFIELDTRANS_GCPHYS: 3262 AssertMsgReturn(pCur->cb == sizeof(RTGCPHYS), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 3263 rc = SSMR3PutGCPhys(pSSM, *(PRTGCPHYS)pbField); 3264 break; 3265 3266 case SSMFIELDTRANS_HCPTR: 3267 AssertMsgReturn(pCur->cb == sizeof(void *), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 3268 if (fFlags & SSMSTRUCT_FLAGS_DONT_IGNORE) 3269 rc = ssmR3DataWrite(pSSM, s_abZero, sizeof(void *)); 3270 break; 3271 3272 case SSMFIELDTRANS_IGNORE: 3273 if (fFlags & SSMSTRUCT_FLAGS_DONT_IGNORE) 3274 { 3275 uint32_t cb; 3276 for (uint32_t cbLeft = pCur->cb; cbLeft > 0 && RT_SUCCESS(rc); cbLeft -= cb) 3277 { 3278 cb = RT_MIN(sizeof(s_abZero), cbLeft); 3279 rc = ssmR3DataWrite(pSSM, s_abZero, cb); 3280 } 3281 } 3282 break; 3283 3284 default: 3285 AssertPtrReturn(pCur->pfnGetPutOrTransformer, VERR_SSM_FIELD_INVALID_CALLBACK); 3286 rc = pCur->pfnGetPutOrTransformer(pSSM, pCur, (void *)pvStruct, fFlags, false /*fGetOrPut*/, pvUser); 3287 break; 3288 } 3289 if (RT_FAILURE(rc)) 3290 return rc; 3291 3292 off = pCur->off + pCur->cb; 3293 } 3294 AssertMsgReturn( !(fFlags & SSMSTRUCT_FLAGS_FULL_STRUCT) 3295 || off == cbStruct, 3296 ("off=%#x cbStruct=%#x\n", off, cbStruct), 3297 VERR_SSM_FIELD_NOT_CONSECUTIVE); 3298 3299 /* 3300 * End marker 3301 */ 3302 if (!(fFlags & SSMSTRUCT_FLAGS_NO_MARKERS)) 3303 { 3304 rc = SSMR3PutU32(pSSM, SSMR3STRUCT_END); 3305 if (RT_FAILURE(rc)) 3306 return rc; 3307 } 3308 3309 return VINF_SUCCESS; 3189 3310 } 3190 3311 … … 5525 5646 if (RT_FAILURE(rc)) 5526 5647 return rc; 5527 if (u32Magic != SSMR3STRUCT_BEGIN) 5528 AssertMsgFailedReturn(("u32Magic=%#RX32\n", u32Magic), VERR_SSM_STRUCTURE_MAGIC); 5648 AssertMsgReturn(u32Magic == SSMR3STRUCT_BEGIN, ("u32Magic=%#RX32\n", u32Magic), VERR_SSM_STRUCTURE_MAGIC); 5529 5649 5530 5650 /* get the fields */ … … 5541 5661 5542 5662 case SSMFIELDTRANS_GCPTR: 5543 AssertMsgReturn(pCur->cb == sizeof(RTGCPTR), ("%#x\n", pCur->cb), VERR_SSM_ INVALID_FIELD_SIZE);5663 AssertMsgReturn(pCur->cb == sizeof(RTGCPTR), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 5544 5664 rc = SSMR3GetGCPtr(pSSM, (PRTGCPTR)pbField); 5545 5665 break; 5546 5666 5547 5667 case SSMFIELDTRANS_GCPHYS: 5548 AssertMsgReturn(pCur->cb == sizeof(RTGCPHYS), ("%#x\n", pCur->cb), VERR_SSM_ INVALID_FIELD_SIZE);5668 AssertMsgReturn(pCur->cb == sizeof(RTGCPHYS), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 5549 5669 rc = SSMR3GetGCPhys(pSSM, (PRTGCPHYS)pbField); 5550 5670 break; 5551 5671 5552 5672 default: 5553 AssertMsgFailedReturn(("%#x\n", pCur->pfnGetPutOrTransformer), VERR_SSM_COMPLEX_FIELD); 5554 } 5673 AssertMsgFailedReturn(("%#x\n", pCur->pfnGetPutOrTransformer), VERR_SSM_FIELD_COMPLEX); 5674 } 5675 if (RT_FAILURE(rc)) 5676 return rc; 5555 5677 } 5556 5678 … … 5559 5681 if (RT_FAILURE(rc)) 5560 5682 return rc; 5561 if (u32Magic != SSMR3STRUCT_END) 5562 AssertMsgFailedReturn(("u32Magic=%#RX32\n", u32Magic), VERR_SSM_STRUCTURE_MAGIC); 5683 AssertMsgReturn(u32Magic == SSMR3STRUCT_END, ("u32Magic=%#RX32\n", u32Magic), VERR_SSM_STRUCTURE_MAGIC); 5563 5684 return rc; 5685 } 5686 5687 5688 /** 5689 * Guts a structure, extended API. 5690 * 5691 * @returns VBox status code. 5692 * @param pSSM The saved state handle. 5693 * @param pvStruct The structure address. 5694 * @param cbStruct The size of the struct (use for validation only). 5695 * @param fFlags Combination of SSMSTRUCT_FLAGS_XXX defines. 5696 * @param paFields The array of structure fields descriptions. The 5697 * array must be terminated by a SSMFIELD_ENTRY_TERM(). 5698 * @param pvUser User argument for any callbacks that paFields might 5699 * contain. 5700 */ 5701 VMMR3DECL(int) SSMR3GetStructEx(PSSMHANDLE pSSM, void *pvStruct, size_t cbStruct, 5702 uint32_t fFlags, PCSSMFIELD paFields, void *pvUser) 5703 { 5704 int rc; 5705 uint32_t u32Magic; 5706 5707 /* 5708 * Validation. 5709 */ 5710 AssertMsgReturn(!(fFlags & ~SSMSTRUCT_FLAGS_VALID_MASK), ("%#x\n", fFlags), VERR_INVALID_PARAMETER); 5711 AssertPtr(pvStruct); 5712 AssertPtr(paFields); 5713 5714 5715 /* 5716 * Begin marker. 5717 */ 5718 if (!(fFlags & SSMSTRUCT_FLAGS_NO_MARKERS)) 5719 { 5720 rc = SSMR3GetU32(pSSM, &u32Magic); 5721 if (RT_FAILURE(rc)) 5722 return rc; 5723 AssertMsgReturn(u32Magic == SSMR3STRUCT_BEGIN, ("u32Magic=%#RX32\n", u32Magic), VERR_SSM_STRUCTURE_MAGIC); 5724 } 5725 5726 /* 5727 * Put the fields 5728 */ 5729 uint32_t off = 0; 5730 for (PCSSMFIELD pCur = paFields; 5731 pCur->cb != UINT32_MAX && pCur->off != UINT32_MAX; 5732 pCur++) 5733 { 5734 AssertMsgReturn( pCur->cb <= cbStruct 5735 && pCur->off + pCur->cb <= cbStruct 5736 && pCur->off + pCur->cb > pCur->off, 5737 ("off=%#x cb=%#x cbStruct=%#x\n", pCur->cb, pCur->off, cbStruct), 5738 VERR_SSM_FIELD_OUT_OF_BOUNDS); 5739 AssertMsgReturn( !(fFlags & SSMSTRUCT_FLAGS_FULL_STRUCT) 5740 || off == pCur->off, 5741 ("off=%#x pCur->off=%#x\n", off, pCur->off), 5742 VERR_SSM_FIELD_NOT_CONSECUTIVE); 5743 5744 uint8_t *pbField = (uint8_t *)pvStruct + pCur->off; 5745 switch ((uintptr_t)pCur->pfnGetPutOrTransformer) 5746 { 5747 case SSMFIELDTRANS_NO_TRANSFORMATION: 5748 rc = ssmR3DataRead(pSSM, pbField, pCur->cb); 5749 break; 5750 5751 case SSMFIELDTRANS_GCPTR: 5752 AssertMsgReturn(pCur->cb == sizeof(RTGCPTR), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 5753 rc = SSMR3GetGCPtr(pSSM, (PRTGCPTR)pbField); 5754 break; 5755 5756 case SSMFIELDTRANS_GCPHYS: 5757 AssertMsgReturn(pCur->cb == sizeof(RTGCPHYS), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 5758 rc = SSMR3GetGCPhys(pSSM, (PRTGCPHYS)pbField); 5759 break; 5760 5761 case SSMFIELDTRANS_HCPTR: 5762 AssertMsgReturn(pCur->cb == sizeof(void *), ("%#x\n", pCur->cb), VERR_SSM_FIELD_INVALID_SIZE); 5763 if (fFlags & SSMSTRUCT_FLAGS_DONT_IGNORE) 5764 rc = SSMR3Skip(pSSM, pSSM->u.Read.cHostBits / 8); 5765 break; 5766 5767 case SSMFIELDTRANS_IGNORE: 5768 if (fFlags & SSMSTRUCT_FLAGS_DONT_IGNORE) 5769 rc = SSMR3Skip(pSSM, pCur->cb); 5770 break; 5771 5772 default: 5773 AssertPtrReturn(pCur->pfnGetPutOrTransformer, VERR_SSM_FIELD_INVALID_CALLBACK); 5774 rc = pCur->pfnGetPutOrTransformer(pSSM, pCur, pvStruct, fFlags, true /*fGetOrPut*/, pvUser); 5775 break; 5776 } 5777 if (RT_FAILURE(rc)) 5778 return rc; 5779 5780 off = pCur->off + pCur->cb; 5781 } 5782 AssertMsgReturn( !(fFlags & SSMSTRUCT_FLAGS_FULL_STRUCT) 5783 || off == cbStruct, 5784 ("off=%#x cbStruct=%#x\n", off, cbStruct), 5785 VERR_SSM_FIELD_NOT_CONSECUTIVE); 5786 5787 /* 5788 * End marker 5789 */ 5790 if (!(fFlags & SSMSTRUCT_FLAGS_NO_MARKERS)) 5791 { 5792 rc = SSMR3GetU32(pSSM, &u32Magic); 5793 if (RT_FAILURE(rc)) 5794 return rc; 5795 AssertMsgReturn(u32Magic == SSMR3STRUCT_END, ("u32Magic=%#RX32\n", u32Magic), VERR_SSM_STRUCTURE_MAGIC); 5796 } 5797 5798 return VINF_SUCCESS; 5564 5799 } 5565 5800
Note:
See TracChangeset
for help on using the changeset viewer.