VirtualBox

Ignore:
Timestamp:
Mar 24, 2009 11:12:35 AM (16 years ago)
Author:
vboxsync
Message:

VBoxGuest/win: Moved the bugcheck code into a separate file so we can selectively enable the vista DDK for it.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxGuest/HelperBugCheck.cpp

    r18170 r18171  
    1919 */
    2020
    21 //#define LOG_ENABLED
    22 
     21#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
     22/*******************************************************************************
     23*   Header Files                                                               *
     24*******************************************************************************/
    2325#include "VBoxGuest_Internal.h"
    2426#include "Helper.h"
     
    2729#include <VBox/VBoxGuestLib.h>
    2830
    29 #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
    30 # ifndef TARGET_NT4
    31 #  include <aux_klib.h>
    32 # endif
     31#ifndef TARGET_NT4
     32# include <aux_klib.h>
    3333#endif
    3434
    35 #ifdef ALLOC_PRAGMA
    36 #pragma alloc_text (PAGE, VBoxScanPCIResourceList)
    37 #endif
    3835
    39 /* CM_RESOURCE_MEMORY_* flags which were used on XP or earlier. */
    40 #define VBOX_CM_PRE_VISTA_MASK (0x3f)
    41 
    42 /**
    43  * Helper to scan the PCI resource list and remember stuff.
    44  *
    45  * @param pResList  Resource list
    46  * @param pDevExt   Device extension
    47  */
    48 NTSTATUS VBoxScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXT pDevExt)
    49 {
    50     NTSTATUS rc = STATUS_SUCCESS;
    51     PCM_PARTIAL_RESOURCE_DESCRIPTOR partialData;
    52 
    53     // enumerate the resource list
    54     dprintf(("found %d resources\n", pResList->List->PartialResourceList.Count));
    55     ULONG rangeCount = 0;
    56     ULONG cMMIORange = 0;
    57     PBASE_ADDRESS baseAddress = pDevExt->baseAddress;
    58     for (ULONG i = 0; i < pResList->List->PartialResourceList.Count; i++)
    59     {
    60         partialData = &pResList->List->PartialResourceList.PartialDescriptors[i];
    61         switch (partialData->Type)
    62         {
    63             case CmResourceTypePort:
    64             {
    65                 // overflow protection
    66                 if (rangeCount < PCI_TYPE0_ADDRESSES)
    67                 {
    68                     dprintf(("I/O range:     Base = %08x : %08x   Length = %08x \n",
    69                             partialData->u.Port.Start.HighPart,
    70                             partialData->u.Port.Start.LowPart,
    71                             partialData->u.Port.Length));
    72                     //@todo not so gut
    73                     dprintf(("I got all I want, my dear port, oh!\n"));
    74                     pDevExt->startPortAddress = (ULONG)partialData->u.Port.Start.LowPart;
    75                     // save resource information
    76                     baseAddress->RangeStart     = partialData->u.Port.Start;
    77                     baseAddress->RangeLength    = partialData->u.Port.Length;
    78                     baseAddress->RangeInMemory  = FALSE;
    79                     baseAddress->ResourceMapped = FALSE;
    80                     // next item
    81                     rangeCount++; baseAddress++;
    82                 }
    83                 break;
    84             }
    85 
    86             case CmResourceTypeInterrupt:
    87             {
    88                 dprintf(("Interrupt:  Level = %x    Vector = %x    Mode = %x \n",
    89                         partialData->u.Interrupt.Level,
    90                         partialData->u.Interrupt.Vector,
    91                         partialData->Flags));
    92                 // save information
    93                 pDevExt->interruptLevel    = partialData->u.Interrupt.Level;
    94                 pDevExt->interruptVector   = partialData->u.Interrupt.Vector;
    95                 pDevExt->interruptAffinity = partialData->u.Interrupt.Affinity;
    96                 // check interrupt mode
    97                 if (partialData->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
    98                 {
    99                     pDevExt->interruptMode = Latched;
    100                 }
    101                 else
    102                 {
    103                     pDevExt->interruptMode = LevelSensitive;
    104                 }
    105                 break;
    106             }
    107 
    108             case CmResourceTypeMemory:
    109             {
    110                 // overflow protection
    111                 if (rangeCount < PCI_TYPE0_ADDRESSES)
    112                 {
    113                     dprintf(("Memory range:     Base = %08x : %08x   Length = %08x \n",
    114                             partialData->u.Memory.Start.HighPart,
    115                             partialData->u.Memory.Start.LowPart,
    116                             partialData->u.Memory.Length));
    117                     // we only care about read/write memory
    118                     /** @todo reconsider memory type */
    119                     if (    cMMIORange == 0 /* only care about the first mmio range (!!!) */
    120                         && (partialData->Flags & VBOX_CM_PRE_VISTA_MASK) == CM_RESOURCE_MEMORY_READ_WRITE)
    121                     {
    122                         pDevExt->memoryAddress = partialData->u.Memory.Start;
    123                         pDevExt->memoryLength = (ULONG)partialData->u.Memory.Length;
    124                         // save resource information
    125                         baseAddress->RangeStart     = partialData->u.Memory.Start;
    126                         baseAddress->RangeLength    = partialData->u.Memory.Length;
    127                         baseAddress->RangeInMemory  = TRUE;
    128                         baseAddress->ResourceMapped = FALSE;
    129                         // next item
    130                         rangeCount++; baseAddress++;cMMIORange++;
    131                     } else
    132                     {
    133                         dprintf(("Ignoring memory: flags = %08x \n", partialData->Flags));
    134                     }
    135                 }
    136                 break;
    137             }
    138 
    139             case CmResourceTypeDma:
    140             {
    141                 dprintf(("DMA resource found. Hmm...\n"));
    142                 break;
    143             }
    144 
    145             default:
    146             {
    147                 dprintf(("Unexpected resource found %d. Hmm...\n", partialData->Type));
    148                 break;
    149             }
    150         }
    151     }
    152     // memorize the number of resources found
    153     pDevExt->addressCount = rangeCount;
    154 
    155     return rc;
    156 }
    157 
    158 
    159 NTSTATUS hlpVBoxMapVMMDevMemory (PVBOXGUESTDEVEXT pDevExt)
    160 {
    161     NTSTATUS rc = STATUS_SUCCESS;
    162 
    163     if (pDevExt->memoryLength != 0)
    164     {
    165          pDevExt->pVMMDevMemory = (VMMDevMemory *)MmMapIoSpace (pDevExt->memoryAddress, pDevExt->memoryLength, MmNonCached);
    166          dprintf(("VBoxGuest::VBoxGuestPnp: VMMDevMemory: ptr = 0x%x\n", pDevExt->pVMMDevMemory));
    167          if (pDevExt->pVMMDevMemory)
    168          {
    169              dprintf(("VBoxGuest::VBoxGuestPnp: VMMDevMemory: version = 0x%x, size = %d\n", pDevExt->pVMMDevMemory->u32Version, pDevExt->pVMMDevMemory->u32Size));
    170 
    171              /* Check version of the structure */
    172              if (pDevExt->pVMMDevMemory->u32Version != VMMDEV_MEMORY_VERSION)
    173              {
    174                  /* Not our version, refuse operation and unmap the memory */
    175                  hlpVBoxUnmapVMMDevMemory (pDevExt);
    176 
    177                  rc = STATUS_UNSUCCESSFUL;
    178              }
    179          }
    180          else
    181          {
    182              rc = STATUS_UNSUCCESSFUL;
    183          }
    184     }
    185 
    186     return rc;
    187 }
    188 
    189 void hlpVBoxUnmapVMMDevMemory (PVBOXGUESTDEVEXT pDevExt)
    190 {
    191     if (pDevExt->pVMMDevMemory)
    192     {
    193         MmUnmapIoSpace (pDevExt->pVMMDevMemory, pDevExt->memoryLength);
    194         pDevExt->pVMMDevMemory = NULL;
    195     }
    196 
    197     pDevExt->memoryAddress.QuadPart = 0;
    198     pDevExt->memoryLength = 0;
    199 }
    200 
    201 NTSTATUS hlpVBoxReportGuestInfo (PVBOXGUESTDEVEXT pDevExt)
    202 {
    203     VMMDevReportGuestInfo *req = NULL;
    204 
    205     int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReportGuestInfo), VMMDevReq_ReportGuestInfo);
    206 
    207     dprintf(("hlpVBoxReportGuestInfo: VbglGRAlloc rc = %d\n", rc));
    208 
    209     if (RT_SUCCESS(rc))
    210     {
    211         req->guestInfo.additionsVersion = VMMDEV_VERSION;
    212 
    213         /* we've already determined the Windows product before */
    214         switch (winVersion)
    215         {
    216             case WINNT4:
    217                 req->guestInfo.osType = VBOXOSTYPE_WinNT4;
    218                 break;
    219             case WIN2K:
    220                 req->guestInfo.osType = VBOXOSTYPE_Win2k;
    221                 break;
    222             case WINXP:
    223                 req->guestInfo.osType = VBOXOSTYPE_WinXP;
    224                 break;
    225             case WIN2K3:
    226                 req->guestInfo.osType = VBOXOSTYPE_Win2k3;
    227                 break;
    228             case WINVISTA:
    229                 req->guestInfo.osType = VBOXOSTYPE_WinVista;
    230                 break;
    231             default:
    232                 /* we don't know, therefore NT family */
    233                 req->guestInfo.osType = VBOXOSTYPE_WinNT;
    234                 break;
    235         }
    236 
    237         /** @todo registry lookup for additional information */
    238 
    239 
    240         rc = VbglGRPerform (&req->header);
    241 
    242         if (RT_FAILURE(rc) || RT_FAILURE(req->header.rc))
    243         {
    244             dprintf(("VBoxGuest::hlpVBoxReportGuestInfo: error reporting guest info to VMMDev."
    245                       "rc = %d, VMMDev rc = %Rrc\n", rc, req->header.rc));
    246         }
    247 
    248         rc = RT_SUCCESS(rc) ? req->header.rc : rc;
    249 
    250         VbglGRFree (&req->header);
    251     }
    252 
    253     return RT_FAILURE(rc) ? STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
    254 }
    255 
    256 #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
    25736/**
    25837 * Called when a bug check occurs.
     
    30483}
    30584
    306 NTSTATUS hlpRegisterBugCheckCallback(PVBOXGUESTDEVEXT pDevExt)
     85void hlpRegisterBugCheckCallback(PVBOXGUESTDEVEXT pDevExt)
    30786{
    308     NTSTATUS rc = STATUS_SUCCESS;
    30987    pDevExt->bBugcheckCallbackRegistered = FALSE;
    31088
     
    31391     * This is required for calling AuxKlibGetBugCheckData() in hlpVBoxGuestBugCheckCallback().
    31492     */
    315     rc = AuxKlibInitialize();
     93    NTSTATUS rc = AuxKlibInitialize();
    31694    if (NT_ERROR(rc))
    31795    {
    318         dprintf(("VBoxGuest::hlpRegisterBugCheckCallback: Unabled to initialize AuxKlib! rc=%#x\n", rc));
    319         return STATUS_DRIVER_UNABLE_TO_LOAD;
     96        LogRelBackdoor(("VBoxGuest: Failed to initialize AuxKlib! rc=%#x\n", rc));
     97        return;
    32098    }
    32199# endif
     
    336114    }
    337115    else
    338         LogRelBackdoor(("Could not register bugcheck callback routine!\n"));
    339 
    340     return rc;
     116        LogRelBackdoor(("VBoxGuest: Could not register bugcheck callback routine!\n"));
    341117}
    342118
     
    350126    }
    351127}
    352 #endif
     128
     129#endif /* VBOX_WITH_GUEST_BUGCHECK_DETECTION */
     130
Note: See TracChangeset for help on using the changeset viewer.

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