1 | /* $Id: SSMInternal.h 33540 2010-10-28 09:27:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SSM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___SSMInternal_h
|
---|
19 | #define ___SSMInternal_h
|
---|
20 |
|
---|
21 | #include <VBox/cdefs.h>
|
---|
22 | #include <VBox/types.h>
|
---|
23 | #include <VBox/ssm.h>
|
---|
24 | #include <iprt/critsect.h>
|
---|
25 |
|
---|
26 | RT_C_DECLS_BEGIN
|
---|
27 |
|
---|
28 | /** @defgroup grp_ssm_int Internals
|
---|
29 | * @ingroup grp_ssm
|
---|
30 | * @internal
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Data unit callback type.
|
---|
37 | */
|
---|
38 | typedef enum SSMUNITTYPE
|
---|
39 | {
|
---|
40 | /** PDM Device . */
|
---|
41 | SSMUNITTYPE_DEV = 1,
|
---|
42 | /** PDM Driver. */
|
---|
43 | SSMUNITTYPE_DRV,
|
---|
44 | /** VM Internal. */
|
---|
45 | SSMUNITTYPE_INTERNAL,
|
---|
46 | /** External Wrapper. */
|
---|
47 | SSMUNITTYPE_EXTERNAL
|
---|
48 | } SSMUNITTYPE;
|
---|
49 |
|
---|
50 | /** Pointer to a data unit descriptor. */
|
---|
51 | typedef struct SSMUNIT *PSSMUNIT;
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Data unit descriptor.
|
---|
55 | */
|
---|
56 | typedef struct SSMUNIT
|
---|
57 | {
|
---|
58 | /** Pointer ot the next one in the list. */
|
---|
59 | PSSMUNIT pNext;
|
---|
60 |
|
---|
61 | /** Called in this save/load operation.
|
---|
62 | * The flag is used to determine whether there is need for a call to
|
---|
63 | * done or not. */
|
---|
64 | bool fCalled;
|
---|
65 | /** Finished its live part.
|
---|
66 | * This is used to handle VERR_SSM_VOTE_FOR_GIVING_UP. */
|
---|
67 | bool fDoneLive;
|
---|
68 | /** Callback interface type. */
|
---|
69 | SSMUNITTYPE enmType;
|
---|
70 | /** Type specific data. */
|
---|
71 | union
|
---|
72 | {
|
---|
73 | /** SSMUNITTYPE_DEV. */
|
---|
74 | struct
|
---|
75 | {
|
---|
76 | /** Prepare live save. */
|
---|
77 | PFNSSMDEVLIVEPREP pfnLivePrep;
|
---|
78 | /** Execute live save. */
|
---|
79 | PFNSSMDEVLIVEEXEC pfnLiveExec;
|
---|
80 | /** Vote live save complete. */
|
---|
81 | PFNSSMDEVLIVEVOTE pfnLiveVote;
|
---|
82 | /** Prepare save. */
|
---|
83 | PFNSSMDEVSAVEPREP pfnSavePrep;
|
---|
84 | /** Execute save. */
|
---|
85 | PFNSSMDEVSAVEEXEC pfnSaveExec;
|
---|
86 | /** Done save. */
|
---|
87 | PFNSSMDEVSAVEDONE pfnSaveDone;
|
---|
88 | /** Prepare load. */
|
---|
89 | PFNSSMDEVLOADPREP pfnLoadPrep;
|
---|
90 | /** Execute load. */
|
---|
91 | PFNSSMDEVLOADEXEC pfnLoadExec;
|
---|
92 | /** Done load. */
|
---|
93 | PFNSSMDEVLOADDONE pfnLoadDone;
|
---|
94 | /** Device instance. */
|
---|
95 | PPDMDEVINS pDevIns;
|
---|
96 | } Dev;
|
---|
97 |
|
---|
98 | /** SSMUNITTYPE_DRV. */
|
---|
99 | struct
|
---|
100 | {
|
---|
101 | /** Prepare live save. */
|
---|
102 | PFNSSMDRVLIVEPREP pfnLivePrep;
|
---|
103 | /** Execute live save. */
|
---|
104 | PFNSSMDRVLIVEEXEC pfnLiveExec;
|
---|
105 | /** Vote live save complete. */
|
---|
106 | PFNSSMDRVLIVEVOTE pfnLiveVote;
|
---|
107 | /** Prepare save. */
|
---|
108 | PFNSSMDRVSAVEPREP pfnSavePrep;
|
---|
109 | /** Execute save. */
|
---|
110 | PFNSSMDRVSAVEEXEC pfnSaveExec;
|
---|
111 | /** Done save. */
|
---|
112 | PFNSSMDRVSAVEDONE pfnSaveDone;
|
---|
113 | /** Prepare load. */
|
---|
114 | PFNSSMDRVLOADPREP pfnLoadPrep;
|
---|
115 | /** Execute load. */
|
---|
116 | PFNSSMDRVLOADEXEC pfnLoadExec;
|
---|
117 | /** Done load. */
|
---|
118 | PFNSSMDRVLOADDONE pfnLoadDone;
|
---|
119 | /** Driver instance. */
|
---|
120 | PPDMDRVINS pDrvIns;
|
---|
121 | } Drv;
|
---|
122 |
|
---|
123 | /** SSMUNITTYPE_INTERNAL. */
|
---|
124 | struct
|
---|
125 | {
|
---|
126 | /** Prepare live save. */
|
---|
127 | PFNSSMINTLIVEPREP pfnLivePrep;
|
---|
128 | /** Execute live save. */
|
---|
129 | PFNSSMINTLIVEEXEC pfnLiveExec;
|
---|
130 | /** Vote live save complete. */
|
---|
131 | PFNSSMINTLIVEVOTE pfnLiveVote;
|
---|
132 | /** Prepare save. */
|
---|
133 | PFNSSMINTSAVEPREP pfnSavePrep;
|
---|
134 | /** Execute save. */
|
---|
135 | PFNSSMINTSAVEEXEC pfnSaveExec;
|
---|
136 | /** Done save. */
|
---|
137 | PFNSSMINTSAVEDONE pfnSaveDone;
|
---|
138 | /** Prepare load. */
|
---|
139 | PFNSSMINTLOADPREP pfnLoadPrep;
|
---|
140 | /** Execute load. */
|
---|
141 | PFNSSMINTLOADEXEC pfnLoadExec;
|
---|
142 | /** Done load. */
|
---|
143 | PFNSSMINTLOADDONE pfnLoadDone;
|
---|
144 | } Internal;
|
---|
145 |
|
---|
146 | /** SSMUNITTYPE_EXTERNAL. */
|
---|
147 | struct
|
---|
148 | {
|
---|
149 | /** Prepare live save. */
|
---|
150 | PFNSSMEXTLIVEPREP pfnLivePrep;
|
---|
151 | /** Execute live save. */
|
---|
152 | PFNSSMEXTLIVEEXEC pfnLiveExec;
|
---|
153 | /** Vote live save complete. */
|
---|
154 | PFNSSMEXTLIVEVOTE pfnLiveVote;
|
---|
155 | /** Prepare save. */
|
---|
156 | PFNSSMEXTSAVEPREP pfnSavePrep;
|
---|
157 | /** Execute save. */
|
---|
158 | PFNSSMEXTSAVEEXEC pfnSaveExec;
|
---|
159 | /** Done save. */
|
---|
160 | PFNSSMEXTSAVEDONE pfnSaveDone;
|
---|
161 | /** Prepare load. */
|
---|
162 | PFNSSMEXTLOADPREP pfnLoadPrep;
|
---|
163 | /** Execute load. */
|
---|
164 | PFNSSMEXTLOADEXEC pfnLoadExec;
|
---|
165 | /** Done load. */
|
---|
166 | PFNSSMEXTLOADDONE pfnLoadDone;
|
---|
167 | /** User data. */
|
---|
168 | void *pvUser;
|
---|
169 | } External;
|
---|
170 |
|
---|
171 | struct
|
---|
172 | {
|
---|
173 | /** Prepare live save. */
|
---|
174 | PFNRT pfnLivePrep;
|
---|
175 | /** Execute live save. */
|
---|
176 | PFNRT pfnLiveExec;
|
---|
177 | /** Vote live save complete. */
|
---|
178 | PFNRT pfnLiveVote;
|
---|
179 | /** Prepare save. */
|
---|
180 | PFNRT pfnSavePrep;
|
---|
181 | /** Execute save. */
|
---|
182 | PFNRT pfnSaveExec;
|
---|
183 | /** Done save. */
|
---|
184 | PFNRT pfnSaveDone;
|
---|
185 | /** Prepare load. */
|
---|
186 | PFNRT pfnLoadPrep;
|
---|
187 | /** Execute load. */
|
---|
188 | PFNRT pfnLoadExec;
|
---|
189 | /** Done load. */
|
---|
190 | PFNRT pfnLoadDone;
|
---|
191 | /** User data. */
|
---|
192 | void *pvKey;
|
---|
193 | } Common;
|
---|
194 | } u;
|
---|
195 | /** Data layout version. */
|
---|
196 | uint32_t u32Version;
|
---|
197 | /** Instance number. */
|
---|
198 | uint32_t u32Instance;
|
---|
199 | /** The offset of the final data unit.
|
---|
200 | * This is used for constructing the directory. */
|
---|
201 | RTFOFF offStream;
|
---|
202 | /** The guessed size of the data unit - used only for progress indication. */
|
---|
203 | size_t cbGuess;
|
---|
204 | /** Name size. (bytes) */
|
---|
205 | size_t cchName;
|
---|
206 | /** Name of this unit. (extends beyond the defined size) */
|
---|
207 | char szName[1];
|
---|
208 | } SSMUNIT;
|
---|
209 |
|
---|
210 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLivePrep, u.Dev.pfnLivePrep);
|
---|
211 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveExec, u.Dev.pfnLiveExec);
|
---|
212 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveVote, u.Dev.pfnLiveVote);
|
---|
213 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSavePrep, u.Dev.pfnSavePrep);
|
---|
214 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveExec, u.Dev.pfnSaveExec);
|
---|
215 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveDone, u.Dev.pfnSaveDone);
|
---|
216 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadPrep, u.Dev.pfnLoadPrep);
|
---|
217 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadExec, u.Dev.pfnLoadExec);
|
---|
218 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadDone, u.Dev.pfnLoadDone);
|
---|
219 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pvKey, u.Dev.pDevIns);
|
---|
220 |
|
---|
221 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLivePrep, u.Drv.pfnLivePrep);
|
---|
222 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveExec, u.Drv.pfnLiveExec);
|
---|
223 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveVote, u.Drv.pfnLiveVote);
|
---|
224 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSavePrep, u.Drv.pfnSavePrep);
|
---|
225 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveExec, u.Drv.pfnSaveExec);
|
---|
226 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveDone, u.Drv.pfnSaveDone);
|
---|
227 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadPrep, u.Drv.pfnLoadPrep);
|
---|
228 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadExec, u.Drv.pfnLoadExec);
|
---|
229 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadDone, u.Drv.pfnLoadDone);
|
---|
230 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pvKey, u.Drv.pDrvIns);
|
---|
231 |
|
---|
232 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLivePrep, u.Internal.pfnLivePrep);
|
---|
233 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveExec, u.Internal.pfnLiveExec);
|
---|
234 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveVote, u.Internal.pfnLiveVote);
|
---|
235 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSavePrep, u.Internal.pfnSavePrep);
|
---|
236 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveExec, u.Internal.pfnSaveExec);
|
---|
237 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveDone, u.Internal.pfnSaveDone);
|
---|
238 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadPrep, u.Internal.pfnLoadPrep);
|
---|
239 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadExec, u.Internal.pfnLoadExec);
|
---|
240 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadDone, u.Internal.pfnLoadDone);
|
---|
241 |
|
---|
242 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLivePrep, u.External.pfnLivePrep);
|
---|
243 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveExec, u.External.pfnLiveExec);
|
---|
244 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLiveVote, u.External.pfnLiveVote);
|
---|
245 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSavePrep, u.External.pfnSavePrep);
|
---|
246 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveExec, u.External.pfnSaveExec);
|
---|
247 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnSaveDone, u.External.pfnSaveDone);
|
---|
248 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadPrep, u.External.pfnLoadPrep);
|
---|
249 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadExec, u.External.pfnLoadExec);
|
---|
250 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pfnLoadDone, u.External.pfnLoadDone);
|
---|
251 | AssertCompile2MemberOffsets(SSMUNIT, u.Common.pvKey, u.External.pvUser);
|
---|
252 |
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * SSM VM Instance data.
|
---|
256 | * Changes to this must checked against the padding of the cfgm union in VM!
|
---|
257 | *
|
---|
258 | * @todo Move this to UVM.
|
---|
259 | */
|
---|
260 | typedef struct SSM
|
---|
261 | {
|
---|
262 | /** Critical section for serializing cancellation (pSSM). */
|
---|
263 | RTCRITSECT CancelCritSect;
|
---|
264 | /** The handle of the current save or load operation.
|
---|
265 | * This is used by SSMR3Cancel. */
|
---|
266 | PSSMHANDLE volatile pSSM;
|
---|
267 |
|
---|
268 | /** FIFO of data entity descriptors. */
|
---|
269 | R3PTRTYPE(PSSMUNIT) pHead;
|
---|
270 | /** The number of register units. */
|
---|
271 | uint32_t cUnits;
|
---|
272 | /** For lazy init. */
|
---|
273 | bool fInitialized;
|
---|
274 | /** Current pass (for STAM). */
|
---|
275 | uint32_t uPass;
|
---|
276 | uint32_t u32Alignment;
|
---|
277 | } SSM;
|
---|
278 | /** Pointer to SSM VM instance data. */
|
---|
279 | typedef SSM *PSSM;
|
---|
280 |
|
---|
281 |
|
---|
282 |
|
---|
283 | /** @} */
|
---|
284 |
|
---|
285 | RT_C_DECLS_END
|
---|
286 |
|
---|
287 | #endif /* !___SSMInternal_h */
|
---|
288 |
|
---|