VirtualBox

source: vbox/trunk/src/VBox/Devices/testcase/tstDeviceInternal.h@ 92000

最後變更 在這個檔案從92000是 92000,由 vboxsync 提交於 3 年 前

Devices/testcase/tstDevice: Some basic MMIO fuzzing, bugref:9006

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 17.5 KB
 
1/** @file
2 * tstDevice: Shared definitions between the framework and the shim library.
3 */
4
5/*
6 * Copyright (C) 2017-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h
18#define VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h
19#ifndef RT_WITHOUT_PRAGMA_ONCE
20# pragma once
21#endif
22
23#include <VBox/param.h>
24#include <VBox/types.h>
25#include <iprt/assert.h>
26#include <iprt/list.h>
27#include <iprt/semaphore.h>
28#include <iprt/critsect.h>
29
30#include "tstDeviceCfg.h"
31#include "tstDevicePlugin.h"
32
33RT_C_DECLS_BEGIN
34
35
36/** Converts PDM device instance to the device under test structure. */
37#define TSTDEV_PDMDEVINS_2_DUT(a_pDevIns) ((a_pDevIns)->Internal.s.pDut)
38
39/** Forward declaration of internal test device instance data. */
40typedef struct TSTDEVDUTINT *PTSTDEVDUTINT;
41
42
43/**
44 * CFGM node structure.
45 */
46typedef struct CFGMNODE
47{
48 /** Device under test this CFGM node is for. */
49 PTSTDEVDUTINT pDut;
50 /** @todo: */
51} CFGMNODE;
52
53
54/**
55 * Private device instance data.
56 */
57typedef struct PDMDEVINSINTR3
58{
59 /** Pointer to the device under test the PDM device instance is for. */
60 PTSTDEVDUTINT pDut;
61} PDMDEVINSINTR3;
62AssertCompile(sizeof(PDMDEVINSINTR3) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
63
64/**
65 * Private device instance data.
66 */
67typedef struct PDMDEVINSINTR0
68{
69 /** Pointer to the device under test the PDM device instance is for. */
70 PTSTDEVDUTINT pDut;
71} PDMDEVINSINTR0;
72AssertCompile(sizeof(PDMDEVINSINTR0) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
73
74/**
75 * Private device instance data.
76 */
77typedef struct PDMDEVINSINTRC
78{
79 /** Pointer to the device under test the PDM device instance is for. */
80 PTSTDEVDUTINT pDut;
81} PDMDEVINSINTRC;
82AssertCompile(sizeof(PDMDEVINSINTRC) <= (HC_ARCH_BITS == 32 ? 72 : 112 + 0x28));
83
84typedef struct PDMPCIDEVINT
85{
86 bool fRegistered;
87} PDMPCIDEVINT;
88
89
90/**
91 * Internal PDM critical section structure.
92 */
93typedef struct PDMCRITSECTINT
94{
95 /** The actual critical section used for emulation. */
96 RTCRITSECT CritSect;
97} PDMCRITSECTINT;
98AssertCompile(sizeof(PDMCRITSECTINT) <= (HC_ARCH_BITS == 32 ? 0x80 : 0xc0));
99
100
101/**
102 * SSM handle state.
103 */
104typedef struct SSMHANDLE
105{
106 /** Pointer to the device under test the handle is for. */
107 PTSTDEVDUTINT pDut;
108 /** The saved state data buffer. */
109 uint8_t *pbSavedState;
110 /** Size of the saved state. */
111 size_t cbSavedState;
112 /** Current offset into the data buffer. */
113 uint32_t offDataBuffer;
114 /** Current unit version. */
115 uint32_t uCurUnitVer;
116 /** Status code. */
117 int rc;
118} SSMHANDLE;
119
120
121/**
122 * MM Heap allocation.
123 */
124typedef struct TSTDEVMMHEAPALLOC
125{
126 /** Node for the list of allocations. */
127 RTLISTNODE NdMmHeap;
128 /** Pointer to the device under test the allocation was made for. */
129 PTSTDEVDUTINT pDut;
130 /** Size of the allocation. */
131 size_t cbAlloc;
132 /** Start of the real allocation. */
133 RT_FLEXIBLE_ARRAY_EXTENSION
134 uint8_t abAlloc[RT_FLEXIBLE_ARRAY];
135} TSTDEVMMHEAPALLOC;
136/** Pointer to a MM Heap allocation. */
137typedef TSTDEVMMHEAPALLOC *PTSTDEVMMHEAPALLOC;
138/** Pointer to a const MM Heap allocation. */
139typedef const TSTDEVMMHEAPALLOC *PCTSTDEVMMHEAPALLOC;
140
141AssertCompileMemberAlignment(TSTDEVMMHEAPALLOC, abAlloc, HC_ARCH_BITS == 64 ? 16 : 8);
142
143
144/**
145 * The usual device/driver/internal/external stuff.
146 */
147typedef enum
148{
149 /** The usual invalid entry. */
150 PDMTHREADTYPE_INVALID = 0,
151 /** Device type. */
152 PDMTHREADTYPE_DEVICE,
153 /** USB Device type. */
154 PDMTHREADTYPE_USB,
155 /** Driver type. */
156 PDMTHREADTYPE_DRIVER,
157 /** Internal type. */
158 PDMTHREADTYPE_INTERNAL,
159 /** External type. */
160 PDMTHREADTYPE_EXTERNAL,
161 /** The usual 32-bit hack. */
162 PDMTHREADTYPE_32BIT_HACK = 0x7fffffff
163} PDMTHREADTYPE;
164
165
166/**
167 * The internal structure for the thread.
168 */
169typedef struct PDMTHREADINT
170{
171 /** Node for the list of threads. */
172 RTLISTNODE NdPdmThrds;
173 /** Pointer to the device under test the allocation was made for. */
174 PTSTDEVDUTINT pDut;
175 /** The event semaphore the thread blocks on when not running. */
176 RTSEMEVENTMULTI BlockEvent;
177 /** The event semaphore the thread sleeps on while running. */
178 RTSEMEVENTMULTI SleepEvent;
179 /** The thread type. */
180 PDMTHREADTYPE enmType;
181} PDMTHREADINT;
182
183
184#define PDMTHREADINT_DECLARED
185#define PDMCRITSECTINT_DECLARED
186#define PDMDEVINSINT_DECLARED
187#define PDMPCIDEVINT_DECLARED
188#define VMM_INCLUDED_SRC_include_VMInternal_h
189#define VMM_INCLUDED_SRC_include_VMMInternal_h
190RT_C_DECLS_END
191#include <VBox/vmm/pdmcritsect.h>
192#include <VBox/vmm/pdmthread.h>
193#include <VBox/vmm/pdmdev.h>
194#include <VBox/vmm/pdmpci.h>
195#include <VBox/vmm/pdmdrv.h>
196#include <VBox/vmm/tm.h>
197RT_C_DECLS_BEGIN
198
199
200/**
201 * TM timer structure.
202 */
203typedef struct TMTIMER
204{
205 /** List of timers created by the device. */
206 RTLISTNODE NdDevTimers;
207 /** Clock this timer belongs to. */
208 TMCLOCK enmClock;
209 /** Callback to call when the timer expires. */
210 PFNTMTIMERDEV pfnCallbackDev;
211 /** Opaque user data to pass to the callback. */
212 void *pvUser;
213 /** Flags. */
214 uint32_t fFlags;
215 /** Assigned critical section. */
216 PPDMCRITSECT pCritSect;
217 /** @todo: */
218} TMTIMER;
219
220
221/**
222 * PDM module descriptor type.
223 */
224typedef enum TSTDEVPDMMODTYPE
225{
226 /** Invalid module type. */
227 TSTDEVPDMMODTYPE_INVALID = 0,
228 /** Ring 3 module. */
229 TSTDEVPDMMODTYPE_R3,
230 /** Ring 0 module. */
231 TSTDEVPDMMODTYPE_R0,
232 /** Raw context module. */
233 TSTDEVPDMMODTYPE_RC,
234 /** 32bit hack. */
235 TSTDEVPDMMODTYPE_32BIT_HACK = 0x7fffffff
236} TSTDEVPDMMODTYPE;
237
238/**
239 * Registered I/O port access handler.
240 */
241typedef struct RTDEVDUTIOPORT
242{
243 /** Node for the list of registered handlers. */
244 RTLISTNODE NdIoPorts;
245 /** Start I/O port the handler is for. */
246 RTIOPORT PortStart;
247 /** Number of ports handled. */
248 RTIOPORT cPorts;
249 /** Opaque user data - R3. */
250 void *pvUserR3;
251 /** Out handler - R3. */
252 PFNIOMIOPORTNEWOUT pfnOutR3;
253 /** In handler - R3. */
254 PFNIOMIOPORTNEWIN pfnInR3;
255 /** Out string handler - R3. */
256 PFNIOMIOPORTNEWOUTSTRING pfnOutStrR3;
257 /** In string handler - R3. */
258 PFNIOMIOPORTNEWINSTRING pfnInStrR3;
259
260 /** Opaque user data - R0. */
261 void *pvUserR0;
262 /** Out handler - R0. */
263 PFNIOMIOPORTNEWOUT pfnOutR0;
264 /** In handler - R0. */
265 PFNIOMIOPORTNEWIN pfnInR0;
266 /** Out string handler - R0. */
267 PFNIOMIOPORTNEWOUTSTRING pfnOutStrR0;
268 /** In string handler - R0. */
269 PFNIOMIOPORTNEWINSTRING pfnInStrR0;
270
271#ifdef TSTDEV_SUPPORTS_RC
272 /** Opaque user data - RC. */
273 void *pvUserRC;
274 /** Out handler - RC. */
275 PFNIOMIOPORTNEWOUT pfnOutRC;
276 /** In handler - RC. */
277 PFNIOMIOPORTNEWIN pfnInRC;
278 /** Out string handler - RC. */
279 PFNIOMIOPORTNEWOUTSTRING pfnOutStrRC;
280 /** In string handler - RC. */
281 PFNIOMIOPORTNEWINSTRING pfnInStrRC;
282#endif
283} RTDEVDUTIOPORT;
284/** Pointer to a registered I/O port handler. */
285typedef RTDEVDUTIOPORT *PRTDEVDUTIOPORT;
286/** Pointer to a const I/O port handler. */
287typedef const RTDEVDUTIOPORT *PCRTDEVDUTIOPORT;
288
289
290/**
291 * Registered MMIO port access handler.
292 */
293typedef struct RTDEVDUTMMIO
294{
295 /** Node for the list of registered handlers. */
296 RTLISTNODE NdMmio;
297 /** Start address of the MMIO region when mapped. */
298 RTGCPHYS GCPhysStart;
299 /** Size of the MMIO region in bytes. */
300 RTGCPHYS cbRegion;
301 /** Opaque user data - R3. */
302 void *pvUserR3;
303 /** Write handler - R3. */
304 PFNIOMMMIONEWWRITE pfnWriteR3;
305 /** Read handler - R3. */
306 PFNIOMMMIONEWREAD pfnReadR3;
307 /** Fill handler - R3. */
308 PFNIOMMMIONEWFILL pfnFillR3;
309
310 /** Opaque user data - R0. */
311 void *pvUserR0;
312 /** Write handler - R0. */
313 PFNIOMMMIONEWWRITE pfnWriteR0;
314 /** Read handler - R0. */
315 PFNIOMMMIONEWREAD pfnReadR0;
316 /** Fill handler - R0. */
317 PFNIOMMMIONEWFILL pfnFillR0;
318
319#ifdef TSTDEV_SUPPORTS_RC
320 /** Opaque user data - RC. */
321 void *pvUserRC;
322 /** Write handler - RC. */
323 PFNIOMMMIONEWWRITE pfnWriteRC;
324 /** Read handler - RC. */
325 PFNIOMMMIONEWREAD pfnReadRC;
326 /** Fill handler - RC. */
327 PFNIOMMMIONEWFILL pfnFillRC;
328#endif
329} RTDEVDUTMMIO;
330/** Pointer to a registered MMIO handler. */
331typedef RTDEVDUTMMIO *PRTDEVDUTMMIO;
332/** Pointer to a const MMIO handler. */
333typedef const RTDEVDUTMMIO *PCRTDEVDUTMMIO;
334
335
336/**
337 * Registered SSM handlers.
338 */
339typedef struct TSTDEVDUTSSM
340{
341 /** Node for the list of registered SSM handlers. */
342 RTLISTNODE NdSsm;
343 /** Version */
344 uint32_t uVersion;
345 PFNSSMDEVLIVEPREP pfnLivePrep;
346 PFNSSMDEVLIVEEXEC pfnLiveExec;
347 PFNSSMDEVLIVEVOTE pfnLiveVote;
348 PFNSSMDEVSAVEPREP pfnSavePrep;
349 PFNSSMDEVSAVEEXEC pfnSaveExec;
350 PFNSSMDEVSAVEDONE pfnSaveDone;
351 PFNSSMDEVLOADPREP pfnLoadPrep;
352 PFNSSMDEVLOADEXEC pfnLoadExec;
353 PFNSSMDEVLOADDONE pfnLoadDone;
354} TSTDEVDUTSSM;
355/** Pointer to the registered SSM handlers. */
356typedef TSTDEVDUTSSM *PTSTDEVDUTSSM;
357/** Pointer to a const SSM handler. */
358typedef const TSTDEVDUTSSM *PCTSTDEVDUTSSM;
359
360
361/**
362 * The Support Driver session state.
363 */
364typedef struct TSTDEVSUPDRVSESSION
365{
366 /** Pointer to the owning device under test instance. */
367 PTSTDEVDUTINT pDut;
368 /** List of event semaphores. */
369 RTLISTANCHOR LstSupSem;
370} TSTDEVSUPDRVSESSION;
371/** Pointer to the Support Driver session state. */
372typedef TSTDEVSUPDRVSESSION *PTSTDEVSUPDRVSESSION;
373
374/** Converts a Support Driver session handle to the internal state. */
375#define TSTDEV_PSUPDRVSESSION_2_PTSTDEVSUPDRVSESSION(a_pSession) ((PTSTDEVSUPDRVSESSION)(a_pSession))
376/** Converts the internal session state to a Support Driver session handle. */
377#define TSTDEV_PTSTDEVSUPDRVSESSION_2_PSUPDRVSESSION(a_pSession) ((PSUPDRVSESSION)(a_pSession))
378
379/**
380 * Support driver event semaphore.
381 */
382typedef struct TSTDEVSUPSEMEVENT
383{
384 /** Node for the event semaphore list. */
385 RTLISTNODE NdSupSem;
386 /** Flag whether this is multi event semaphore. */
387 bool fMulti;
388 /** Event smeaphore handles depending on the flag above. */
389 union
390 {
391 RTSEMEVENT hSemEvt;
392 RTSEMEVENTMULTI hSemEvtMulti;
393 } u;
394} TSTDEVSUPSEMEVENT;
395/** Pointer to a support event semaphore state. */
396typedef TSTDEVSUPSEMEVENT *PTSTDEVSUPSEMEVENT;
397
398/** Converts a Support event semaphore handle to the internal state. */
399#define TSTDEV_SUPSEMEVENT_2_PTSTDEVSUPSEMEVENT(a_pSupSemEvt) ((PTSTDEVSUPSEMEVENT)(a_pSupSemEvt))
400/** Converts the internal session state to a Support event semaphore handle. */
401#define TSTDEV_PTSTDEVSUPSEMEVENT_2_SUPSEMEVENT(a_pSupSemEvt) ((SUPSEMEVENT)(a_pSupSemEvt))
402
403/**
404 * The contex the device under test is currently in.
405 */
406typedef enum TSTDEVDUTCTX
407{
408 /** Invalid context. */
409 TSTDEVDUTCTX_INVALID = 0,
410 /** R3 context. */
411 TSTDEVDUTCTX_R3,
412 /** R0 context. */
413 TSTDEVDUTCTX_R0,
414 /** RC context. */
415 TSTDEVDUTCTX_RC,
416 /** 32bit hack. */
417 TSTDEVDUTCTX_32BIT_HACK = 0x7fffffff
418} TSTDEVDUTCTX;
419
420/**
421 * PCI region descriptor.
422 */
423typedef struct TSTDEVDUTPCIREGION
424{
425 /** Size of the region. */
426 RTGCPHYS cbRegion;
427 /** Address space type. */
428 PCIADDRESSSPACE enmType;
429 /** Region mapping callback. */
430 PFNPCIIOREGIONMAP pfnRegionMap;
431} TSTDEVDUTPCIREGION;
432/** Pointer to a PCI region descriptor. */
433typedef TSTDEVDUTPCIREGION *PTSTDEVDUTPCIREGION;
434/** Pointer to a const PCI region descriptor. */
435typedef const TSTDEVDUTPCIREGION *PCTSTDEVDUTPCIREGION;
436
437/**
438 * Device under test instance data.
439 */
440typedef struct TSTDEVDUTINT
441{
442 /** Pointer to the test this device is running under. */
443 PCTSTDEVTEST pTest;
444 /** Pointer to the PDM device instance. */
445 PPDMDEVINS pDevIns;
446 /** CFGM root config node for the device. */
447 CFGMNODE Cfg;
448 /** Current device context. */
449 TSTDEVDUTCTX enmCtx;
450 /** Critical section protecting the lists below. */
451 RTCRITSECTRW CritSectLists;
452 /** List of registered I/O port handlers. */
453 RTLISTANCHOR LstIoPorts;
454 /** List of timers registered. */
455 RTLISTANCHOR LstTimers;
456 /** List of registered MMIO regions. */
457 RTLISTANCHOR LstMmio;
458 /** List of MM Heap allocations. */
459 RTLISTANCHOR LstMmHeap;
460 /** List of PDM threads. */
461 RTLISTANCHOR LstPdmThreads;
462 /** List of SSM handlers (just one normally). */
463 RTLISTANCHOR LstSsmHandlers;
464 /** The SUP session we emulate. */
465 TSTDEVSUPDRVSESSION SupSession;
466 /** The NOP critical section. */
467 PDMCRITSECT CritSectNop;
468 /** The VM state associated with this device. */
469 PVM pVm;
470 /** The registered PCI device instance if this is a PCI device. */
471 PPDMPCIDEV pPciDev;
472 /** PCI Region descriptors. */
473 TSTDEVDUTPCIREGION aPciRegions[VBOX_PCI_NUM_REGIONS];
474 /** The status port interface we implement. */
475 PDMIBASE IBaseSts;
476 /** */
477} TSTDEVDUTINT;
478
479
480extern const PDMDEVHLPR3 g_tstDevPdmDevHlpR3;
481
482
483DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PTSTDEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType,
484 const char *pszSymbol, PFNRT *ppfn);
485
486
487DECLINLINE(int) tstDevDutLockShared(PTSTDEVDUTINT pThis)
488{
489 return RTCritSectRwEnterShared(&pThis->CritSectLists);
490}
491
492DECLINLINE(int) tstDevDutUnlockShared(PTSTDEVDUTINT pThis)
493{
494 return RTCritSectRwLeaveShared(&pThis->CritSectLists);
495}
496
497DECLINLINE(int) tstDevDutLockExcl(PTSTDEVDUTINT pThis)
498{
499 return RTCritSectRwEnterExcl(&pThis->CritSectLists);
500}
501
502DECLINLINE(int) tstDevDutUnlockExcl(PTSTDEVDUTINT pThis)
503{
504 return RTCritSectRwLeaveExcl(&pThis->CritSectLists);
505}
506
507DECLHIDDEN(int) tstDevPdmR3ThreadCreateDevice(PTSTDEVDUTINT pDut, PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
508 PFNPDMTHREADWAKEUPDEV pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
509DECLHIDDEN(int) tstDevPdmR3ThreadCreateUsb(PTSTDEVDUTINT pDut, PPDMUSBINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
510 PFNPDMTHREADWAKEUPUSB pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
511DECLHIDDEN(int) tstDevPdmR3ThreadCreateDriver(PTSTDEVDUTINT pDut, PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
512 PFNPDMTHREADWAKEUPDRV pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
513DECLHIDDEN(int) tstDevPdmR3ThreadCreate(PTSTDEVDUTINT pDut, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADINT pfnThread,
514 PFNPDMTHREADWAKEUPINT pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
515DECLHIDDEN(int) tstDevPdmR3ThreadCreateExternal(PTSTDEVDUTINT pDut, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADEXT pfnThread,
516 PFNPDMTHREADWAKEUPEXT pfnWakeUp, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
517DECLHIDDEN(int) tstDevPdmR3ThreadDestroy(PPDMTHREAD pThread, int *pRcThread);
518DECLHIDDEN(int) tstDevPdmR3ThreadDestroyDevice(PTSTDEVDUTINT pDut, PPDMDEVINS pDevIns);
519DECLHIDDEN(int) tstDevPdmR3ThreadDestroyUsb(PTSTDEVDUTINT pDut, PPDMUSBINS pUsbIns);
520DECLHIDDEN(int) tstDevPdmR3ThreadDestroyDriver(PTSTDEVDUTINT pDut, PPDMDRVINS pDrvIns);
521DECLHIDDEN(void) tstDevPdmR3ThreadDestroyAll(PTSTDEVDUTINT pDut);
522DECLHIDDEN(int) tstDevPdmR3ThreadIAmSuspending(PPDMTHREAD pThread);
523DECLHIDDEN(int) tstDevPdmR3ThreadIAmRunning(PPDMTHREAD pThread);
524DECLHIDDEN(int) tstDevPdmR3ThreadSleep(PPDMTHREAD pThread, RTMSINTERVAL cMillies);
525DECLHIDDEN(int) tstDevPdmR3ThreadSuspend(PPDMTHREAD pThread);
526DECLHIDDEN(int) tstDevPdmR3ThreadResume(PPDMTHREAD pThread);
527
528
529RT_C_DECLS_END
530
531#endif /* !VBOX_INCLUDED_SRC_testcase_tstDeviceInternal_h */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette