VOID DrvDisablePDEV(DHPDEV dhpdev) { PPDEV ppdev; ppdev = (PPDEV) dhpdev; DISPDBG((2, "disabling PDEV\n")); EngDeletePalette(devinfoVGA.hpalDefault); // Free the preallocated saved screen bits buffer, if there is one. if (ppdev->pjPreallocSSBBuffer != NULL) { EngFreeMem(ppdev->pjPreallocSSBBuffer); } // Free the conversion table buffer if (ppdev->pucDIB4ToVGAConvBuffer != NULL) { EngFreeMem(ppdev->pucDIB4ToVGAConvBuffer); } // Delete the PDEV EngFreeMem(dhpdev); DISPDBG((2, "disabled PDEV\n")); }
BOOL APIENTRY FtfdUnloadFontFile( IN ULONG_PTR iFile) { PFTFD_FILE pfile = (PFTFD_FILE)iFile; ULONG i; DbgPrint("FtfdUnloadFontFile()\n"); // HACK!!! EngFreeMem(pfile->pvView); /* Cleanup faces */ for (i = 0; i < pfile->cNumFaces; i++) { FT_Done_Face(pfile->aftface[i]); } /* Unmap the font file */ EngUnmapFontFileFD(pfile->iFile); /* Free the memory that was allocated for the font */ EngFreeMem(pfile); return TRUE; }
ULONG APIENTRY DrvGetModes( IN HANDLE hDriver, IN ULONG cjSize, OUT DEVMODEW *pdm) { ULONG ModeCount; ULONG ModeInfoSize; PVIDEO_MODE_INFORMATION ModeInfo, ModeInfoPtr; ULONG OutputSize; ModeCount = GetAvailableModes(hDriver, &ModeInfo, &ModeInfoSize); if (ModeCount == 0) { return 0; } if (pdm == NULL) { EngFreeMem(ModeInfo); return ModeCount * sizeof(DEVMODEW); } /* * Copy the information about supported modes into the output buffer. */ OutputSize = 0; ModeInfoPtr = ModeInfo; while (ModeCount-- > 0) { if (ModeInfoPtr->Length == 0) { ModeInfoPtr = (PVIDEO_MODE_INFORMATION)(((ULONG_PTR)ModeInfoPtr) + ModeInfoSize); continue; } memset(pdm, 0, sizeof(DEVMODEW)); memcpy(pdm->dmDeviceName, DEVICE_NAME, sizeof(DEVICE_NAME)); pdm->dmSpecVersion = pdm->dmDriverVersion = DM_SPECVERSION; pdm->dmSize = sizeof(DEVMODEW); pdm->dmDriverExtra = 0; pdm->dmBitsPerPel = ModeInfoPtr->NumberOfPlanes * ModeInfoPtr->BitsPerPlane; pdm->dmPelsWidth = ModeInfoPtr->VisScreenWidth; pdm->dmPelsHeight = ModeInfoPtr->VisScreenHeight; pdm->dmDisplayFrequency = ModeInfoPtr->Frequency; pdm->dmDisplayFlags = 0; pdm->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS; ModeInfoPtr = (PVIDEO_MODE_INFORMATION)(((ULONG_PTR)ModeInfoPtr) + ModeInfoSize); pdm = (LPDEVMODEW)(((ULONG_PTR)pdm) + sizeof(DEVMODEW)); OutputSize += sizeof(DEVMODEW); } EngFreeMem(ModeInfo); return OutputSize; }
BOOL APIENTRY EngFreeSectionMem( IN PVOID pvSection OPTIONAL, IN PVOID pvMappedBase OPTIONAL) { NTSTATUS Status; PENGSECTION pSection = pvSection; BOOL bResult = TRUE; /* Did the caller give us a mapping base? */ if (pvMappedBase) { Status = MmUnmapViewInSessionSpace(pvMappedBase); if (!NT_SUCCESS(Status)) { DPRINT1("MmUnmapViewInSessionSpace failed: 0x%lx\n", Status); bResult = FALSE; } } /* Check if we should free the section as well */ if (pSection) { /* Dereference the kernel section */ ObDereferenceObject(pSection->pvSectionObject); /* Finally free the section memory itself */ EngFreeMem(pSection); } return bResult; }
VOID NTAPI GdiPoolDestroy(PGDI_POOL pPool) { PGDI_POOL_SECTION pSection; PLIST_ENTRY ple; /* Loop all empty sections, removing them */ while (!IsListEmpty(&pPool->leEmptyList)) { /* Delete the section */ ple = RemoveHeadList(&pPool->leEmptyList); pSection = CONTAINING_RECORD(ple, GDI_POOL_SECTION, leInUseLink); GdiPoolDeleteSection(pPool, pSection); } /* Loop all ready sections, removing them */ while (!IsListEmpty(&pPool->leInUseList)) { /* Delete the section */ ple = RemoveHeadList(&pPool->leInUseList); pSection = CONTAINING_RECORD(ple, GDI_POOL_SECTION, leInUseLink); GdiPoolDeleteSection(pPool, pSection); } DBG_CLEANUP_EVENT_LIST(&pPool->slhLog); EngFreeMem(pPool); }
VOID DrvDisableDriver( VOID ) { EngFreeMem(gpgset); }
static VOID GdiPoolDeleteSection(PGDI_POOL pPool, PGDI_POOL_SECTION pSection) { NTSTATUS status; SIZE_T cjSize = 0; /* Should not have any allocations */ if (pSection->cAllocCount != 0) { DPRINT1("There are %lu allocations left, section=%p, pool=%p\n", pSection->cAllocCount, pSection, pPool); DBG_DUMP_EVENT_LIST(&pPool->slhLog); ASSERT(FALSE); } /* Release the virtual memory */ status = ZwFreeVirtualMemory(NtCurrentProcess(), &pSection->pvBaseAddress, &cjSize, MEM_RELEASE); ASSERT(NT_SUCCESS(status)); /* Free the section object */ EngFreeMem(pSection); }
VOID DrvDeleteDeviceBitmap( DHSURF dhsurf) { DSURF* pdsurf; PDEV* ppdev; SURFOBJ* psoDib; HSURF hsurfDib; pdsurf = (DSURF*) dhsurf; ppdev = pdsurf->ppdev; if (pdsurf->dt == DT_SCREEN) { pohFree(ppdev, pdsurf->poh); } else { ASSERTDD(pdsurf->dt == DT_DIB, "Expected DIB type"); psoDib = pdsurf->pso; // Get the hsurf from the SURFOBJ before we unlock it (it's not // legal to dereference psoDib when it's unlocked): hsurfDib = psoDib->hsurf; EngUnlockSurface(psoDib); EngDeleteSurface(hsurfDib); } EngFreeMem(pdsurf); }
/* * @implemented */ VOID APIENTRY EngDeleteClip( _In_ _Post_ptr_invalid_ CLIPOBJ *pco) { EngFreeMem(ObjToGDI(pco, CLIP)); }
VOID NTAPI EBRUSHOBJ_vCleanup(EBRUSHOBJ *pebo) { /* Check if there's a GDI realisation */ if (pebo->pengbrush) { /* Unlock the bitmap again */ SURFACE_ShareUnlockSurface(pebo->pengbrush); pebo->pengbrush = NULL; } /* Check if there's a driver's realisation */ if (pebo->BrushObject.pvRbrush) { /* Free allocated driver memory */ EngFreeMem(pebo->BrushObject.pvRbrush); pebo->BrushObject.pvRbrush = NULL; } if (pebo->psoMask != NULL) { SURFACE_ShareUnlockSurface(pebo->psoMask); pebo->psoMask = NULL; } /* Dereference the palettes */ PALETTE_ShareUnlockPalette(pebo->ppalSurf); PALETTE_ShareUnlockPalette(pebo->ppalDC); if (pebo->ppalDIB) PALETTE_ShareUnlockPalette(pebo->ppalDIB); }
VOID FASTCALL IntEngUpdateClipRegion( XCLIPOBJ* Clip, ULONG count, const RECTL* pRect, const RECTL* rcBounds) { if(count > 1) { RECTL* NewRects = EngAllocMem(0, FIELD_OFFSET(ENUMRECTS, arcl[count]), GDITAG_CLIPOBJ); if(NewRects != NULL) { Clip->RectCount = count; Clip->EnumOrder = CD_ANY; RtlCopyMemory(NewRects, pRect, count * sizeof(RECTL)); Clip->ClipObj.iDComplexity = DC_COMPLEX; Clip->ClipObj.iFComplexity = ((Clip->RectCount <= 4) ? FC_RECT4 : FC_COMPLEX); Clip->ClipObj.iMode = TC_RECTANGLES; Clip->ClipObj.rclBounds = *rcBounds; if (Clip->Rects != &Clip->ClipObj.rclBounds) EngFreeMem(Clip->Rects); Clip->Rects = NewRects; } } else { Clip->EnumOrder = CD_ANY; Clip->ClipObj.iDComplexity = (((rcBounds->top == rcBounds->bottom) && (rcBounds->left == rcBounds->right)) ? DC_TRIVIAL : DC_RECT); Clip->ClipObj.iFComplexity = FC_RECT; Clip->ClipObj.iMode = TC_RECTANGLES; Clip->ClipObj.rclBounds = *rcBounds; Clip->RectCount = 1; if (Clip->Rects != &Clip->ClipObj.rclBounds) EngFreeMem(Clip->Rects); Clip->Rects = &Clip->ClipObj.rclBounds; } }
VOID APIENTRY BmfdDestroyFont( IN FONTOBJ *pfo) { /* Free the font realization info */ EngFreeMem(pfo->pvProducer); pfo->pvProducer = NULL; }
FASTCALL POLYGONFILL_MakeEdgeList(PPOINT Points, int Count) { int CurPt = 0; FILL_EDGE_LIST* list = 0; FILL_EDGE* e = 0; if ( 0 == Points || 2 > Count ) return 0; list = (FILL_EDGE_LIST*)EngAllocMem(FL_ZERO_MEMORY, sizeof(FILL_EDGE_LIST), FILL_EDGE_ALLOC_TAG); if ( 0 == list ) goto fail; list->Count = 0; list->Edges = (FILL_EDGE**)EngAllocMem(FL_ZERO_MEMORY, Count*sizeof(FILL_EDGE*), FILL_EDGE_ALLOC_TAG); if ( !list->Edges ) goto fail; memset ( list->Edges, 0, Count * sizeof(FILL_EDGE*) ); for ( CurPt = 1; CurPt < Count; ++CurPt ) { e = POLYGONFILL_MakeEdge ( Points[CurPt-1], Points[CurPt] ); if ( !e ) goto fail; // if a straight horizontal line - who cares? if ( !e->absdy ) EngFreeMem ( e ); else list->Edges[list->Count++] = e; } e = POLYGONFILL_MakeEdge ( Points[CurPt-1], Points[0] ); if ( !e ) goto fail; if ( !e->absdy ) EngFreeMem ( e ); else list->Edges[list->Count++] = e; return list; fail: DPRINT1("Out Of MEMORY!!\n"); POLYGONFILL_DestroyEdgeList ( list ); return 0; }
BOOL TestFdUnloadFontFileTE ( HFF hff ) { if (hff) EngFreeMem((PVOID)hff); return TRUE; }
/* Called to free resources allocated for device in VBoxDispDrvEnablePDEV */ VOID APIENTRY VBoxDispDrvDisablePDEV(DHPDEV dhpdev) { LOGF_ENTER(); VBoxDispDestroyPalette((PVBOXDISPDEV) dhpdev); EngFreeMem(dhpdev); LOGF_LEAVE(); }
VOID DrvDisablePDEV( DHPDEV dhpdev) { PDEV* ppdev; ppdev = (PDEV*) dhpdev; vUninitializePalette(ppdev); EngFreeMem(ppdev); }
/* * @implemented */ VOID APIENTRY EngDeleteClip( _In_ _Post_ptr_invalid_ CLIPOBJ *pco) { XCLIPOBJ* Clip = CONTAINING_RECORD(pco, XCLIPOBJ, ClipObj); TRACE("Deleting %p.\n"); IntEngFreeClipResources(Clip); EngFreeMem(Clip); }
VOID vUninitializePalette(PDEV* ppdev) { // Delete the default palette if we created one: if (ppdev->hpalDefault != 0) EngDeletePalette(ppdev->hpalDefault); if (ppdev->pPal != (PALETTEENTRY*) NULL) EngFreeMem(ppdev->pPal); }
/* Returns video modes supported by our device/driver * Note: If we fail here we'd be asked to enter 800x600@4bpp mode later in VBoxDispDrvEnablePDEV. */ ULONG APIENTRY VBoxDispDrvGetModes(HANDLE hDriver, ULONG cjSize, DEVMODEW *pdm) { int rc; VIDEO_MODE_INFORMATION *pModesTable; ULONG cModes; LOGF_ENTER(); rc = VBoxDispMPGetVideoModes(hDriver, &pModesTable, &cModes); VBOX_WARNRC_RETV(rc, 0); if (!pdm) /* return size of buffer required to store all supported modes */ { EngFreeMem(pModesTable); LOGF_LEAVE(); return cModes * sizeof(DEVMODEW); } ULONG mode, cMaxNodes=cjSize/sizeof(DEVMODEW); for (mode=0; mode<cModes && mode<cMaxNodes; ++mode, ++pdm) { memset(pdm, 0, sizeof(DEVMODEW)); memcpy(pdm->dmDeviceName, VBOXDISP_DEVICE_NAME, sizeof(VBOXDISP_DEVICE_NAME)); pdm->dmSpecVersion = DM_SPECVERSION; pdm->dmDriverVersion = DM_SPECVERSION; pdm->dmSize = sizeof(DEVMODEW); pdm->dmDriverExtra = 0; pdm->dmBitsPerPel = pModesTable[mode].NumberOfPlanes*pModesTable[mode].BitsPerPlane; pdm->dmPelsWidth = pModesTable[mode].VisScreenWidth; pdm->dmPelsHeight = pModesTable[mode].VisScreenHeight; pdm->dmDisplayFrequency = pModesTable[mode].Frequency; pdm->dmDisplayFlags = 0; pdm->dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY|DM_DISPLAYFLAGS; } EngFreeMem(pModesTable); LOG(("%d mode(s) reported", mode)); LOGF_LEAVE(); return mode * sizeof(DEVMODEW); }
HANDLE OpenPlotFile( LPWSTR pFileName ) /*++ Routine Description: Arguments: Return Value: Author: 24-Oct-1995 Tue 14:16:46 created -by- Daniel Chou (danielc) Revision History: --*/ { PPLOTFILE pPF; DWORD cbSize; if ((pPF = (PPLOTFILE)EngAllocMem(FL_ZERO_MEMORY, sizeof(PLOTFILE), 'tolp')) && (pPF->hModule = EngLoadModule((LPWSTR)pFileName)) && (pPF->pbBeg = EngMapModule(pPF->hModule, &cbSize))) { pPF->pbEnd = (pPF->pbCur = pPF->pbBeg) + cbSize; return((HANDLE)pPF); } if (pPF) { EngFreeMem((PVOID)pPF); } return((HANDLE)INVALID_HANDLE_VALUE); }
/* ** Hide memory clean up. */ static void FASTCALL POLYGONFILL_DestroyEdgeList(FILL_EDGE_LIST* list) { int i; if ( list ) { if ( list->Edges ) { for ( i = 0; i < list->Count; i++ ) { if ( list->Edges[i] ) EngFreeMem ( list->Edges[i] ); } EngFreeMem ( list->Edges ); } EngFreeMem ( list ); } }
static void ssbDiscardTopSlot(PVBOXDISPDEV pDev) { SSB *pSSB = &pDev->aSSB[--pDev->cSSB]; if (pSSB->pBuffer) { EngFreeMem (pSSB->pBuffer); pSSB->pBuffer = NULL; } pSSB->ident = 0; }
VOID APIENTRY FtfdFree( PVOID pv, ULONG_PTR id) { DbgPrint("FtfdFree()\n"); if (id) { EngFreeMem((PVOID)id); } }
VOID NTAPI DbgCleanupEventList(PSLIST_HEADER pslh) { PSLIST_ENTRY psle; PLOGENTRY pLogEntry; while ((psle = InterlockedPopEntrySList(pslh))) { pLogEntry = CONTAINING_RECORD(psle, LOGENTRY, sleLink); EngFreeMem(pLogEntry); } }
VOID vDisablePalette(PPDEV ppdev) { // Delete the default palette if we created one. if (ppdev->hpalDefault) { EngDeletePalette(ppdev->hpalDefault); ppdev->hpalDefault = (HPALETTE) 0; } if (ppdev->pPal != (PPALETTEENTRY)NULL) EngFreeMem((PVOID)ppdev->pPal); }
void VBoxDispDestroyPalette(PVBOXDISPDEV pDev) { if (pDev->hDefaultPalette) { EngDeletePalette(pDev->hDefaultPalette); pDev->hDefaultPalette = 0; } if (pDev->pPalette) { EngFreeMem(pDev->pPalette); } }
BOOL MoveAllSurfacesToRam(PDev *pdev) { UINT32 surface_id; SurfaceInfo *surface_info; SURFOBJ *surf_obj; UINT8 *copy; UINT8 *line0; int size; QXLPHYSICAL phys_mem; for (surface_id = 1 ; surface_id < pdev->n_surfaces ; ++surface_id) { surface_info = GetSurfaceInfo(pdev, surface_id); if (!surface_info->draw_area.base_mem) { continue; } surf_obj = surface_info->draw_area.surf_obj; if (!surf_obj) { DEBUG_PRINT((pdev, 3, "%s: %d: no surfobj, not copying\n", __FUNCTION__, surface_id)); continue; } size = surf_obj->sizlBitmap.cy * abs(surf_obj->lDelta); copy = EngAllocMem(0, size, ALLOC_TAG); DEBUG_PRINT((pdev, 3, "%s: %d: copying #%d to %p (%d)\n", __FUNCTION__, surface_id, size, copy, surf_obj->lDelta)); RtlCopyMemory(copy, surface_info->draw_area.base_mem, size); surface_info->copy = copy; line0 = surf_obj->lDelta > 0 ? copy : copy + abs(surf_obj->lDelta) * (surf_obj->sizlBitmap.cy - 1); if (!EngModifySurface((HSURF)surface_info->hbitmap, pdev->eng, 0, /* from the example: used to monitor memory HOOK_COPYBITS | HOOK_BITBLT, */ 0, /* It's system-memory */ (DHSURF)surface_info, line0, surf_obj->lDelta, NULL)) { /* Send a create messsage for this surface - we previously did a destroy all. */ EngFreeMem(surface_info->copy); surface_info->copy = NULL; DEBUG_PRINT((pdev, 0, "%s: %d: EngModifySurface failed, sending create for %d-%d\n", __FUNCTION__, surface_id, surface_id, pdev->n_surfaces - 1)); SendSurfaceRangeCreateCommand(pdev, surface_id, pdev->n_surfaces); return FALSE; } QXLDelSurface(pdev, surface_info->draw_area.base_mem, DEVICE_BITMAP_ALLOCATION_TYPE_VRAM); surface_info->draw_area.base_mem = copy; FreeDrawArea(&surface_info->draw_area); } return TRUE; }
VOID vDisableOffscreenHeap( PDEV* ppdev) { OHALLOC* poha; OHALLOC* pohaNext; poha = ppdev->heap.pohaChain; while (poha != NULL) { pohaNext = poha->pohaNext; // Grab the next pointer before it's freed EngFreeMem(poha); poha = pohaNext; } }
VOID DrvDisableSurface(DHPDEV dhpdev) { PPDEV ppdev = (PPDEV) dhpdev; PDEVSURF pdsurf = ppdev->pdsurf; PSAVED_SCREEN_BITS pSSB, pSSBNext; DISPDBG((2, "disabling surface\n")); // Free up banking-related stuff. EngFreeMem(pdsurf->pBankSelectInfo); if (pdsurf->pbiBankInfo != NULL) { EngFreeMem(pdsurf->pbiBankInfo); } if (pdsurf->pbiBankInfo2RW != NULL) { EngFreeMem(pdsurf->pbiBankInfo2RW); } if (pdsurf->pvBankBufferPlane0 != NULL) { EngFreeMem(pdsurf->pvBankBufferPlane0); } if (ppdev->pPointerAttributes != NULL) { EngFreeMem(ppdev->pPointerAttributes); } // Free any pending saved screen bit blocks. pSSB = pdsurf->ssbList; while (pSSB != (PSAVED_SCREEN_BITS) NULL) { // // Point to the next saved screen bits block // pSSBNext = (PSAVED_SCREEN_BITS) pSSB->pvNextSSB; // // Free the current block // EngFreeMem(pSSB); pSSB = pSSBNext; } EngDeleteSurface((HSURF) ppdev->hsurfEng); EngFreeMem(pdsurf); // free the surface DISPDBG((2, "disabled surface\n")); }
VOID NTAPI SURFACE_vCleanup(PVOID ObjectBody) { PSURFACE psurf = (PSURFACE)ObjectBody; PVOID pvBits = psurf->SurfObj.pvBits; /* Check if the surface has bits */ if (pvBits) { /* Only bitmaps can have bits */ ASSERT(psurf->SurfObj.iType == STYPE_BITMAP); /* Check if it is a DIB section */ if (psurf->hDIBSection) { /* Unmap the section view */ EngUnmapSectionView(pvBits, psurf->dwOffset, psurf->hSecure); } else if (psurf->SurfObj.fjBitmap & BMF_USERMEM) { /* Bitmap was allocated from usermode memory */ EngFreeUserMem(pvBits); } else if (psurf->SurfObj.fjBitmap & BMF_KMSECTION) { /* Bitmap was allocated from a kernel section */ if (!EngFreeSectionMem(NULL, pvBits)) { DPRINT1("EngFreeSectionMem failed for %p!\n", pvBits); // Should we BugCheck here? ASSERT(FALSE); } } else if (psurf->SurfObj.fjBitmap & BMF_POOLALLOC) { /* Free a pool allocation */ EngFreeMem(pvBits); } } /* Free palette */ if(psurf->ppal) { PALETTE_ShareUnlockPalette(psurf->ppal); } }