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