VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/util/htable.cpp@ 78263

Last change on this file since 78263 was 78190, checked in by vboxsync, 6 years ago

Merge first stage of the Chromium cleanup from the branch:

  • r129818 (Remove VBOX_WITH_CR_DISPLAY_LISTS and accompanying code as it was disabled since r108676 and was never brought back (see ​bugref:3456 and ​bugref:8485))
  • r129819 (HostServices/SharedOpenGL: Remove unused main entry point from upstream server process based implementation)
  • r129820 (HostServices/SharedOpenGL: Started eliminating all backends other than HGCM. They are not used and probably wouldn't work anymore anyway)
  • r129821 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crTimer* API as it is not used anywhere)
  • r129822 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill most from cr_process.h apart from two used methods)
  • r129823 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crList* API as it is unused)
  • r129824 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crHullInteriorBox API as it is unused)
  • r129825 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crWarpPoint API as it is unused)
  • r129826 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill CrSa* API as it is unused and not even compiled in)
  • r129827 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill cr_bbox.h as it is unused)
  • r129828 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove a few crParseUrl() two uses)
  • r129829 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove last crParseURL() use)
  • r129830 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove crParseURL())
  • r129831 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove VBOX_WITH_COCOA_QT and related code when not set as it is the default for years now and we don't support anything else anymore)
  • r129832 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_logo.h)
  • r129833 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused crut_api.h and crut_clientapi.h)
  • r129834 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_dmx.h)
  • r129835 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_perf.h)
  • r129836 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove cr_rand.h and friends as it is not actively used anywhere)
  • r129837 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of all the swapped versions in the packer SPU, we never change endianess from guest to host and don't need it)
  • r129838 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129839 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129840 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused pack_pica.c)
  • r129841 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129842 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_endianess.h and friends)
  • r129843 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused lowercase.py)
  • r129844 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_calllists.h and friends)
  • r129845 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of completely unused idpool.c, not even compiled in)
  • r129846 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_debugopcodes.h and friends)
  • r129847 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the cr_mem.h API inline and get rid of the implementation in the util library)
  • r129848 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of SPUOptions and related code as it is of no use for us)
  • r129849 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_environment.h and friends and convert usage to RTEnv* APIs)
  • r129850 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused renderspu_agl.c)
  • r129851 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused code in cr_htable.h)
  • r129853 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Introduce a state paremeter for the unpacker workers instead of reyling on global variables, work in progress)
  • r129854 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Let the caller of crUnpack set up the initial state. This allows to get rid of the global return_ptr and writeback_ptr as they get supplied in the unpacker state by the server)
  • r129855 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the cr_lastDispatch and cr_unpackDispatch as they are of no use now)
  • r129856 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the global cr_unpackData and cr_unpackDataEnd symbols by indtroducing another hack to make it possible for certail server dispatch callbacks to access the data buffer)
  • r129857 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: build fix for release builds)
  • r129858 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the pointer to the unpacker state non const (is required for the access verification))
  • r129859 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: First iteration of the buffer size validation to prevent out of bound read access + added todos for places where additional checks are needed)
  • r129860 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129861 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129871 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129872 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Stop as soon as the unpacker encountered an error)
  • r129876 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129880 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129882 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Fixed some offsets in unpack_texture.c, 3DMark03 renders correctly again)
  • r130013 (HostServices/SharedOpenGL: Convert files to C++ so we can use C99 featuers on Windows with cl.exe)
  • r130014 (HostServices/SharedOpenGL,GuestHost/OpenGL: WIndows build fixes)
  • r130015 (HostServices/SharedOpenGL,GuestHost/OpenGL: More Windows build fixes)
  • r130036 (Config.kmk: Fix linker error on Windows by temporarily disabling the use of VBoxGuestR3DllMinW2K)
  • r130094 (src/VBox/GuestHost/OpenGL: Revert inlining the allocation/free functions in R3 completely as it doesn't work on Windows if memory is allocated and freed across different DLLs which don't share a common CRT, causes crashes in RtlValidtaeHeap())
  • r130095 (src/VBox/GuestHost/OpenGL,src/VBox/Additions/common/crOpenGL/pack: Don't use floating point specifiers in packspu_GetString() to avoid R6002 errors (couldn't fully understand why they occur suddenly after the rework but this gets rid of it))
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: htable.cpp 78190 2019-04-18 00:07:07Z vboxsync $ */
2/** @file
3 * uint32_t handle to void simple table impl
4 *
5 * @todo Why couldn't you simply use iprt/handletable.h?
6 */
7
8/*
9 * Copyright (C) 2013-2019 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include <iprt/cdefs.h>
21#include <iprt/asm.h>
22#include "cr_spu.h"
23#include "cr_vreg.h"
24
25#include "cr_htable.h"
26#include "cr_spu.h"
27#include "chromium.h"
28#include "cr_error.h"
29#include "cr_net.h"
30#include "cr_mem.h"
31#include "cr_string.h"
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35#include <iprt/mem.h>
36#include <iprt/errcore.h>
37
38VBOXHTABLEDECL(int) CrHTableCreate(PCRHTABLE pTbl, uint32_t cSize)
39{
40 memset(pTbl, 0, sizeof (*pTbl));
41 if (!cSize)
42 return VINF_SUCCESS;
43 pTbl->paData = (void**)RTMemAllocZ(sizeof (pTbl->paData[0]) * cSize);
44 if (pTbl->paData)
45 {
46 pTbl->cSize = cSize;
47 return VINF_SUCCESS;
48 }
49 WARN(("RTMemAllocZ failed!"));
50 return VERR_NO_MEMORY;
51}
52
53VBOXHTABLEDECL(void) CrHTableDestroy(PCRHTABLE pTbl)
54{
55 if (!pTbl->paData)
56 return;
57
58 RTMemFree(pTbl->paData);
59}
60
61int crHTableRealloc(PCRHTABLE pTbl, uint32_t cNewSize)
62{
63 Assert(cNewSize > pTbl->cSize);
64 if (cNewSize > pTbl->cSize)
65 {
66 void **pvNewData = (void**)RTMemAllocZ(sizeof (pTbl->paData[0]) * cNewSize);
67 if (!pvNewData)
68 {
69 WARN(("RTMemAllocZ failed for size (%d)", (int)(sizeof (pTbl->paData[0]) * cNewSize)));
70 return VERR_NO_MEMORY;
71 }
72 memcpy(pvNewData, pTbl->paData, sizeof (pTbl->paData[0]) * pTbl->cSize);
73 RTMemFree(pTbl->paData);
74 pTbl->iNext2Search = pTbl->cSize;
75 pTbl->cSize = cNewSize;
76 pTbl->paData = pvNewData;
77 return VINF_SUCCESS;
78 }
79 else if (cNewSize >= pTbl->cData)
80 {
81 WARN(("not implemented"));
82 return VERR_NOT_IMPLEMENTED;
83 }
84 WARN(("invalid parameter"));
85 return VERR_INVALID_PARAMETER;
86
87}
88
89VBOXHTABLEDECL(int) CrHTableRealloc(PCRHTABLE pTbl, uint32_t cNewSize)
90{
91 return crHTableRealloc(pTbl, cNewSize);
92}
93
94VBOXHTABLEDECL(void) CrHTableEmpty(PCRHTABLE pTbl)
95{
96 pTbl->cData = 0;
97 pTbl->iNext2Search = 0;
98 if (pTbl->cSize)
99 memset(pTbl->paData, 0, sizeof (pTbl->paData[0]) * pTbl->cSize);
100}
101
102static void* crHTablePutToSlot(PCRHTABLE pTbl, uint32_t iSlot, void* pvData)
103{
104 Assert(pvData);
105 void* pvOld = pTbl->paData[iSlot];
106 pTbl->paData[iSlot] = pvData;
107 if (!pvOld)
108 ++pTbl->cData;
109 Assert(pTbl->cData <= pTbl->cSize);
110 return pvOld;
111}
112
113VBOXHTABLEDECL(int) CrHTablePutToSlot(PCRHTABLE pTbl, CRHTABLE_HANDLE hHandle, void* pvData)
114{
115 AssertReturn(pvData, VERR_INVALID_PARAMETER);
116 uint32_t iIndex = crHTableHandle2Index(hHandle);
117 if (iIndex >= pTbl->cSize)
118 {
119 int rc = crHTableRealloc(pTbl, iIndex + RT_MAX(10, pTbl->cSize/4));
120 if (!RT_SUCCESS(rc))
121 {
122 WARN(("crHTableRealloc failed rc %d", rc));
123 return CRHTABLE_HANDLE_INVALID;
124 }
125 }
126
127 crHTablePutToSlot(pTbl, iIndex, pvData);
128
129 return VINF_SUCCESS;
130}
131
132VBOXHTABLEDECL(CRHTABLE_HANDLE) CrHTablePut(PCRHTABLE pTbl, void* pvData)
133{
134 AssertReturn(pvData, CRHTABLE_HANDLE_INVALID);
135
136 if (pTbl->cSize == pTbl->cData)
137 {
138 int rc = crHTableRealloc(pTbl, pTbl->cSize + RT_MAX(10, pTbl->cSize/4));
139 if (!RT_SUCCESS(rc))
140 {
141 WARN(("crHTableRealloc failed rc %d", rc));
142 return CRHTABLE_HANDLE_INVALID;
143 }
144 }
145 for (uint32_t i = pTbl->iNext2Search; ; ++i, i %= pTbl->cSize)
146 {
147 Assert(i < pTbl->cSize);
148 if (!pTbl->paData[i])
149 {
150 void *pvOld = crHTablePutToSlot(pTbl, i, pvData);
151 Assert(!pvOld); NOREF(pvOld);
152 pTbl->iNext2Search = i+1;
153 pTbl->iNext2Search %= pTbl->cSize;
154 return crHTableIndex2Handle(i);
155 }
156 }
157 /* not reached */
158}
159
160VBOXHTABLEDECL(void*) CrHTableRemove(PCRHTABLE pTbl, CRHTABLE_HANDLE hHandle)
161{
162 uint32_t iIndex = crHTableHandle2Index(hHandle);
163 Assert(iIndex < pTbl->cSize);
164 if (iIndex < pTbl->cSize)
165 {
166 void* pvData = pTbl->paData[iIndex];
167 if (pvData)
168 {
169 pTbl->paData[iIndex] = NULL;
170 --pTbl->cData;
171 Assert(pTbl->cData <= pTbl->cSize);
172 pTbl->iNext2Search = iIndex;
173 }
174 return pvData;
175 }
176 WARN(("invalid handle supplied %d", hHandle));
177 return NULL;
178}
179
180VBOXHTABLEDECL(void*) CrHTableGet(PCRHTABLE pTbl, CRHTABLE_HANDLE hHandle)
181{
182 uint32_t iIndex = crHTableHandle2Index(hHandle);
183 if (iIndex < pTbl->cSize)
184 return pTbl->paData[iIndex];
185 LOG(("invalid handle supplied %d", hHandle));
186 return NULL;
187}
Note: See TracBrowser for help on using the repository browser.

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