home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / vdmdbg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  13.4 KB  |  544 lines

  1. /*++ BUILD Version: 0001    // Increment this if a change has global effects
  2.  
  3. Copyright (c) 1985-1996, Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     vdmdbg.h
  8.  
  9. Abstract:
  10.  
  11.     Prodecure declarations, constant definitions, type definition and macros
  12.     for the VDMDBG.DLL VDM Debugger interface.
  13.  
  14. --*/
  15.  
  16. /*
  17.  *      C/C++ Run Time Library - Version 9.0
  18.  *
  19.  *      Copyright (c) 1997, 1998 by Borland International
  20.  *      All Rights Reserved.
  21.  *
  22.  */
  23.  
  24. #ifndef _VDMDBG_
  25. #define _VDMDBG_
  26. #pragma option push -b
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32.  
  33. #include <pshpack4.h>
  34.  
  35.  
  36. #define STATUS_VDM_EVENT    STATUS_SEGMENT_NOTIFICATION
  37.  
  38. #ifndef DBG_SEGLOAD
  39. #define DBG_SEGLOAD     0
  40. #define DBG_SEGMOVE     1
  41. #define DBG_SEGFREE     2
  42. #define DBG_MODLOAD     3
  43. #define DBG_MODFREE     4
  44. #define DBG_SINGLESTEP  5
  45. #define DBG_BREAK       6
  46. #define DBG_GPFAULT     7
  47. #define DBG_DIVOVERFLOW 8
  48. #define DBG_INSTRFAULT  9
  49. #define DBG_TASKSTART   10
  50. #define DBG_TASKSTOP    11
  51. #define DBG_DLLSTART    12
  52. #define DBG_DLLSTOP     13
  53. #define DBG_ATTACH      14
  54. #endif
  55.  
  56. //
  57. // The following flags control the contents of the CONTEXT structure.
  58. //
  59.  
  60. #define VDMCONTEXT_i386    0x00010000    // this assumes that i386 and
  61. #define VDMCONTEXT_i486    0x00010000    // i486 have identical context records
  62.  
  63. #define VDMCONTEXT_CONTROL         (VDMCONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
  64. #define VDMCONTEXT_INTEGER         (VDMCONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
  65. #define VDMCONTEXT_SEGMENTS        (VDMCONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
  66. #define VDMCONTEXT_FLOATING_POINT  (VDMCONTEXT_i386 | 0x00000008L) // 387 state
  67. #define VDMCONTEXT_DEBUG_REGISTERS (VDMCONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
  68.  
  69. #define VDMCONTEXT_FULL (VDMCONTEXT_CONTROL | VDMCONTEXT_INTEGER |\
  70.                       VDMCONTEXT_SEGMENTS)
  71.  
  72.  
  73. #ifdef _X86_
  74.  
  75. // On x86 machines, just copy the definition of the CONTEXT and LDT_ENTRY
  76. // structures.
  77. typedef struct _CONTEXT VDMCONTEXT;
  78. typedef struct _LDT_ENTRY VDMLDT_ENTRY;
  79.  
  80. #else // _X86_
  81.  
  82. //
  83. //  Define the size of the 80387 save area, which is in the context frame.
  84. //
  85.  
  86. #define SIZE_OF_80387_REGISTERS      80
  87.  
  88. typedef struct _FLOATING_SAVE_AREA {
  89.     ULONG   ControlWord;
  90.     ULONG   StatusWord;
  91.     ULONG   TagWord;
  92.     ULONG   ErrorOffset;
  93.     ULONG   ErrorSelector;
  94.     ULONG   DataOffset;
  95.     ULONG   DataSelector;
  96.     UCHAR   RegisterArea[SIZE_OF_80387_REGISTERS];
  97.     ULONG   Cr0NpxState;
  98. } FLOATING_SAVE_AREA;
  99.  
  100. //
  101. // Simulated context structure for the 16-bit environment
  102. //
  103.  
  104. typedef struct _VDMCONTEXT {
  105.  
  106.     //
  107.     // The flags values within this flag control the contents of
  108.     // a CONTEXT record.
  109.     //
  110.     // If the context record is used as an input parameter, then
  111.     // for each portion of the context record controlled by a flag
  112.     // whose value is set, it is assumed that that portion of the
  113.     // context record contains valid context. If the context record
  114.     // is being used to modify a threads context, then only that
  115.     // portion of the threads context will be modified.
  116.     //
  117.     // If the context record is used as an IN OUT parameter to capture
  118.     // the context of a thread, then only those portions of the thread's
  119.     // context corresponding to set flags will be returned.
  120.     //
  121.     // The context record is never used as an OUT only parameter.
  122.     //
  123.     // CONTEXT_FULL on some systems (MIPS namely) does not contain the
  124.     // CONTEXT_SEGMENTS definition.  VDMDBG assumes that CONTEXT_INTEGER also
  125.     // includes CONTEXT_SEGMENTS to account for this.
  126.     //
  127.  
  128.     ULONG ContextFlags;
  129.  
  130.     //
  131.     // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  132.     // set in ContextFlags.  Note that CONTEXT_DEBUG_REGISTERS is NOT
  133.     // included in CONTEXT_FULL.
  134.     //
  135.  
  136.     ULONG   Dr0;
  137.     ULONG   Dr1;
  138.     ULONG   Dr2;
  139.     ULONG   Dr3;
  140.     ULONG   Dr6;
  141.     ULONG   Dr7;
  142.  
  143.     //
  144.     // This section is specified/returned if the
  145.     // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
  146.     //
  147.  
  148.     FLOATING_SAVE_AREA FloatSave;
  149.  
  150.     //
  151.     // This section is specified/returned if the
  152.     // ContextFlags word contians the flag CONTEXT_SEGMENTS.
  153.     //
  154.  
  155.     ULONG   SegGs;
  156.     ULONG   SegFs;
  157.     ULONG   SegEs;
  158.     ULONG   SegDs;
  159.  
  160.     //
  161.     // This section is specified/returned if the
  162.     // ContextFlags word contians the flag CONTEXT_INTEGER.
  163.     //
  164.  
  165.     ULONG   Edi;
  166.     ULONG   Esi;
  167.     ULONG   Ebx;
  168.     ULONG   Edx;
  169.     ULONG   Ecx;
  170.     ULONG   Eax;
  171.  
  172.     //
  173.     // This section is specified/returned if the
  174.     // ContextFlags word contians the flag CONTEXT_CONTROL.
  175.     //
  176.  
  177.     ULONG   Ebp;
  178.     ULONG   Eip;
  179.     ULONG   SegCs;              // MUST BE SANITIZED
  180.     ULONG   EFlags;             // MUST BE SANITIZED
  181.     ULONG   Esp;
  182.     ULONG   SegSs;
  183.  
  184. } VDMCONTEXT;
  185.  
  186. //
  187. //  LDT descriptor entry
  188. //
  189.  
  190. typedef struct _VDMLDT_ENTRY {
  191.     USHORT  LimitLow;
  192.     USHORT  BaseLow;
  193.     union {
  194.         struct {
  195.             UCHAR   BaseMid;
  196.             UCHAR   Flags1;     // Declare as bytes to avoid alignment
  197.             UCHAR   Flags2;     // Problems.
  198.             UCHAR   BaseHi;
  199.         } Bytes;
  200.         struct {
  201.             ULONG   BaseMid : 8;
  202.             ULONG   Type : 5;
  203.             ULONG   Dpl : 2;
  204.             ULONG   Pres : 1;
  205.             ULONG   LimitHi : 4;
  206.             ULONG   Sys : 1;
  207.             ULONG   Reserved_0 : 1;
  208.             ULONG   Default_Big : 1;
  209.             ULONG   Granularity : 1;
  210.             ULONG   BaseHi : 8;
  211.         } Bits;
  212.     } HighWord;
  213. } VDMLDT_ENTRY;
  214.  
  215.  
  216. #endif // _X86_
  217.  
  218. typedef VDMCONTEXT *LPVDMCONTEXT;
  219. typedef VDMLDT_ENTRY *LPVDMLDT_ENTRY;
  220.  
  221. #define VDMCONTEXT_TO_PROGRAM_COUNTER(Context) (PVOID)((Context)->Eip)
  222.  
  223. #define VDMCONTEXT_LENGTH  (sizeof(VDMCONTEXT))
  224. #define VDMCONTEXT_ALIGN   (sizeof(ULONG))
  225. #define VDMCONTEXT_ROUND   (VDMCONTEXT_ALIGN - 1)
  226.  
  227. #define V86FLAGS_CARRY      0x00001
  228. #define V86FLAGS_PARITY     0x00004
  229. #define V86FLAGS_AUXCARRY   0x00010
  230. #define V86FLAGS_ZERO       0x00040
  231. #define V86FLAGS_SIGN       0x00080
  232. #define V86FLAGS_TRACE      0x00100
  233. #define V86FLAGS_INTERRUPT  0x00200
  234. #define V86FLAGS_DIRECTION  0x00400
  235. #define V86FLAGS_OVERFLOW   0x00800
  236. #define V86FLAGS_IOPL       0x03000
  237. #define V86FLAGS_IOPL_BITS  0x12
  238. #define V86FLAGS_RESUME     0x10000
  239. #define V86FLAGS_V86        0x20000     // Used to detect RealMode v. ProtMode
  240. #define V86FLAGS_ALIGNMENT  0x40000
  241.  
  242. #define MAX_MODULE_NAME  8 + 1
  243. #define MAX_PATH16      255
  244.  
  245. typedef struct _SEGMENT_NOTE {
  246.     WORD    Selector1;                      // Selector of operation
  247.     WORD    Selector2;                      // Dest. Sel. for moving segments
  248.     WORD    Segment;                        // Segment within Module
  249.     CHAR    Module[MAX_MODULE_NAME+1];      // Module name
  250.     CHAR    FileName[MAX_PATH16+1];         // PathName to executable image
  251.     WORD    Type;                           // Code / Data, etc.
  252.     DWORD   Length;                         // Length of image
  253. } SEGMENT_NOTE;
  254.  
  255. typedef struct _IMAGE_NOTE {
  256.     CHAR    Module[MAX_MODULE_NAME+1];      // Module
  257.     CHAR    FileName[MAX_PATH16+1];         // Path to executable image
  258.     WORD    hModule;                        // 16-bit hModule
  259.     WORD    hTask;                          // 16-bit hTask
  260. } IMAGE_NOTE;
  261.  
  262. typedef struct {
  263.     DWORD   dwSize;
  264.     char    szModule[MAX_MODULE_NAME+1];
  265.     HANDLE  hModule;
  266.     WORD    wcUsage;
  267.     char    szExePath[MAX_PATH16+1];
  268.     WORD    wNext;
  269. } MODULEENTRY, *LPMODULEENTRY;
  270.  
  271. /* GlobalFirst()/GlobalNext() flags */
  272. #define GLOBAL_ALL      0
  273. #define GLOBAL_LRU      1
  274. #define GLOBAL_FREE     2
  275.  
  276. /* GLOBALENTRY.wType entries */
  277. #define GT_UNKNOWN      0
  278. #define GT_DGROUP       1
  279. #define GT_DATA         2
  280. #define GT_CODE         3
  281. #define GT_TASK         4
  282. #define GT_RESOURCE     5
  283. #define GT_MODULE       6
  284. #define GT_FREE         7
  285. #define GT_INTERNAL     8
  286. #define GT_SENTINEL     9
  287. #define GT_BURGERMASTER 10
  288.  
  289. /* If GLOBALENTRY.wType==GT_RESOURCE, the following is GLOBALENTRY.wData: */
  290. #define GD_USERDEFINED      0
  291. #define GD_CURSORCOMPONENT  1
  292. #define GD_BITMAP           2
  293. #define GD_ICONCOMPONENT    3
  294. #define GD_MENU             4
  295. #define GD_DIALOG           5
  296. #define GD_STRING           6
  297. #define GD_FONTDIR          7
  298. #define GD_FONT             8
  299. #define GD_ACCELERATORS     9
  300. #define GD_RCDATA           10
  301. #define GD_ERRTABLE         11
  302. #define GD_CURSOR           12
  303. #define GD_ICON             14
  304. #define GD_NAMETABLE        15
  305. #define GD_MAX_RESOURCE     15
  306.  
  307. typedef struct {
  308.     DWORD   dwSize;
  309.     DWORD   dwAddress;
  310.     DWORD   dwBlockSize;
  311.     HANDLE  hBlock;
  312.     WORD    wcLock;
  313.     WORD    wcPageLock;
  314.     WORD    wFlags;
  315.     BOOL    wHeapPresent;
  316.     HANDLE  hOwner;
  317.     WORD    wType;
  318.     WORD    wData;
  319.     DWORD   dwNext;
  320.     DWORD   dwNextAlt;
  321. } GLOBALENTRY, *LPGLOBALENTRY;
  322.  
  323. typedef DWORD (CALLBACK* DEBUGEVENTPROC)( LPDEBUG_EVENT, LPVOID );
  324.  
  325. // Macros to access VDM_EVENT parameters
  326. #define W1(x) ((USHORT)(x.ExceptionInformation[0]))
  327. #define W2(x) ((USHORT)(x.ExceptionInformation[0] >> 16))
  328. #define W3(x) ((USHORT)(x.ExceptionInformation[1]))
  329. #define W4(x) ((USHORT)(x.ExceptionInformation[1] >> 16))
  330. #define DW3(x) (x.ExceptionInformation[2])
  331. #define DW4(x) (x.ExceptionInformation[3])
  332.  
  333.  
  334. #include <poppack.h>
  335.  
  336.  
  337. BOOL
  338. WINAPI
  339. VDMProcessException(
  340.     LPDEBUG_EVENT   lpDebugEvent
  341.     );
  342.  
  343. BOOL
  344. WINAPI
  345. VDMGetThreadSelectorEntry(
  346.     HANDLE          hProcess,
  347.     HANDLE          hThread,
  348.     WORD            wSelector,
  349.     LPVDMLDT_ENTRY  lpSelectorEntry
  350.     );
  351.  
  352. ULONG
  353. WINAPI
  354. VDMGetPointer(
  355.     HANDLE          hProcess,
  356.     HANDLE          hThread,
  357.     WORD            wSelector,
  358.     DWORD           dwOffset,
  359.     BOOL            fProtMode
  360.     );
  361.  
  362. BOOL
  363. WINAPI
  364. VDMGetThreadContext(
  365.     LPDEBUG_EVENT   lpDebugEvent,
  366.     LPVDMCONTEXT    lpVDMContext
  367. );
  368.  
  369. BOOL
  370. WINAPI
  371. VDMSetThreadContext(
  372.     LPDEBUG_EVENT   lpDebugEvent,
  373.     LPVDMCONTEXT    lpVDMContext
  374. );
  375.  
  376. BOOL
  377. WINAPI
  378. VDMGetSelectorModule(
  379.     HANDLE          hProcess,
  380.     HANDLE          hThread,
  381.     WORD            wSelector,
  382.     PUINT           lpSegmentNumber,
  383.     LPSTR           lpModuleName,
  384.     UINT            nNameSize,
  385.     LPSTR           lpModulePath,
  386.     UINT            nPathSize
  387. );
  388.  
  389. BOOL
  390. WINAPI
  391. VDMGetModuleSelector(
  392.     HANDLE          hProcess,
  393.     HANDLE          hThread,
  394.     UINT            wSegmentNumber,
  395.     LPSTR           lpModuleName,
  396.     LPWORD          lpSelector
  397. );
  398.  
  399. BOOL
  400. WINAPI
  401. VDMModuleFirst(
  402.     HANDLE          hProcess,
  403.     HANDLE          hThread,
  404.     LPMODULEENTRY   lpModuleEntry,
  405.     DEBUGEVENTPROC  lpEventProc,
  406.     LPVOID          lpData
  407. );
  408.  
  409. BOOL
  410. WINAPI
  411. VDMModuleNext(
  412.     HANDLE          hProcess,
  413.     HANDLE          hThread,
  414.     LPMODULEENTRY   lpModuleEntry,
  415.     DEBUGEVENTPROC  lpEventProc,
  416.     LPVOID          lpData
  417. );
  418.  
  419. BOOL
  420. WINAPI
  421. VDMGlobalFirst(
  422.     HANDLE          hProcess,
  423.     HANDLE          hThread,
  424.     LPGLOBALENTRY   lpGlobalEntry,
  425.     WORD            wFlags,
  426.     DEBUGEVENTPROC  lpEventProc,
  427.     LPVOID          lpData
  428. );
  429.  
  430. BOOL
  431. WINAPI
  432. VDMGlobalNext(
  433.     HANDLE          hProcess,
  434.     HANDLE          hThread,
  435.     LPGLOBALENTRY   lpGlobalEntry,
  436.     WORD            wFlags,
  437.     DEBUGEVENTPROC  lpEventProc,
  438.     LPVOID          lpData
  439. );
  440.  
  441. typedef BOOL (WINAPI *PROCESSENUMPROC)( DWORD dwProcessId, DWORD dwAttributes, LPARAM lpUserDefined );
  442. typedef BOOL (WINAPI *TASKENUMPROC)( DWORD dwThreadId, WORD hMod16, WORD hTask16, LPARAM lpUserDefined );
  443. typedef BOOL (WINAPI *TASKENUMPROCEX)( DWORD dwThreadId, WORD hMod16, WORD hTask16,
  444.                                        PSZ pszModName, PSZ pszFileName, LPARAM lpUserDefined );
  445.  
  446. #define WOW_SYSTEM  (DWORD)0x0001
  447.  
  448. INT
  449. WINAPI
  450. VDMEnumProcessWOW(
  451.     PROCESSENUMPROC fp,
  452.     LPARAM          lparam
  453. );
  454.  
  455. INT
  456. WINAPI
  457. VDMEnumTaskWOW(
  458.     DWORD           dwProcessId,
  459.     TASKENUMPROC    fp,
  460.     LPARAM          lparam
  461. );
  462.  
  463. //
  464. // VDMEnumTaskWOWEx is the same as VDMEnumTaskWOW except
  465. // the callback procedure gets two more parameters,
  466. // the module name of the EXE and the full path to the
  467. // EXE.
  468. //
  469.  
  470. INT
  471. WINAPI
  472. VDMEnumTaskWOWEx(
  473.     DWORD           dwProcessId,
  474.     TASKENUMPROCEX  fp,
  475.     LPARAM          lparam
  476. );
  477.  
  478. //
  479. // VDMTerminateTaskWOW rudely terminates a 16-bit WOW task
  480. // similar to the way TerminateProcess kills a Win32
  481. // process.
  482. //
  483.  
  484. BOOL
  485. WINAPI
  486. VDMTerminateTaskWOW(
  487.     DWORD           dwProcessId,
  488.     WORD            htask
  489. );
  490.  
  491. //
  492. // VDMStartTaskInWOW launches a Win16 task in a pre-existing
  493. // WOW VDM.  Note that the caller is responsible for ensuring
  494. // the program is a 16-bit Windows program.  If it is a DOS
  495. // or Win32 program, it will still be launched from within
  496. // the target WOW VDM.
  497. //
  498. // The supplied command line and show command are passed
  499. // unchanged to the 16-bit WinExec API in the target WOW VDM.
  500. //
  501. // Note this routine is ANSI-only.
  502. //
  503.  
  504. BOOL
  505. VDMStartTaskInWOW(
  506.     DWORD           dwProcessId,
  507.     LPSTR           lpCommandLine,
  508.     WORD            wShow
  509. );
  510.  
  511. //
  512. // VDMKillWOW is not implemented.
  513. //
  514.  
  515. BOOL
  516. WINAPI
  517. VDMKillWOW(
  518.     VOID
  519. );
  520.  
  521. //
  522. // VDMDetectWOW is not implemented.
  523. //
  524.  
  525. BOOL
  526. WINAPI
  527. VDMDetectWOW(
  528.     VOID
  529. );
  530.  
  531. BOOL
  532. WINAPI
  533. VDMBreakThread(
  534.     HANDLE          hProcess,
  535.     HANDLE          hThread
  536. );
  537.  
  538. #ifdef __cplusplus
  539. }
  540. #endif
  541.  
  542. #pragma option pop
  543. #endif // _VDMDBG_
  544.