VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/spu_loader/spuload.c@ 78374

Last change on this file since 78374 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 Id Revision
File size: 8.8 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "cr_mem.h"
8#include "cr_string.h"
9#include "cr_dll.h"
10#include "cr_error.h"
11#include "cr_spu.h"
12
13
14#include <iprt/param.h>
15#include <iprt/string.h>
16#include <iprt/path.h>
17
18#include <stdio.h>
19
20#ifdef WINDOWS
21#ifdef VBOX_WDDM_WOW64
22#define DLL_SUFFIX "-x86.dll"
23#else
24#define DLL_SUFFIX ".dll"
25#endif
26#define DLL_PREFIX "VBoxOGL"
27#define snprintf _snprintf
28#elif defined(DARWIN)
29#define DLL_SUFFIX ".dylib"
30#define DLL_PREFIX "VBoxOGL"
31/*
32#define DLL_SUFFIX ".bundle"
33#define DLL_PREFIX ""
34*/
35#else
36#ifdef AIX
37#define DLL_SUFFIX ".o"
38#define DLL_PREFIX "VBoxOGL"
39#else
40#define DLL_SUFFIX ".so"
41#define DLL_PREFIX "VBoxOGL"
42#endif
43#endif
44
45extern void __buildDispatch( SPU *spu );
46
47static char *__findDLL( char *name, char *dir )
48{
49 static char path[8092];
50
51 if (!dir)
52 {
53#if defined(DARWIN)
54 char szSharedLibPath[8092];
55 int rc = RTPathAppPrivateArch (szSharedLibPath, sizeof(szSharedLibPath));
56 if (RT_SUCCESS(rc))
57 sprintf ( path, "%s/%s%sspu%s", szSharedLibPath, DLL_PREFIX, name, DLL_SUFFIX );
58 else
59#endif /* DARWIN */
60#ifdef VBOX
61 snprintf ( path, sizeof(path), "%s%sspu%s", DLL_PREFIX, name, DLL_SUFFIX );
62#else
63 sprintf ( path, "%s%sspu%s", DLL_PREFIX, name, DLL_SUFFIX );
64#endif
65 }
66 else
67 {
68#ifdef VBOX
69 snprintf ( path, sizeof(path), "%s/%s%sspu%s", dir, DLL_PREFIX, name, DLL_SUFFIX );
70#else
71 sprintf ( path, "%s/%s%sspu%s", dir, DLL_PREFIX, name, DLL_SUFFIX );
72#endif
73 }
74 return path;
75}
76
77/**
78 * Load a single SPU from disk and initialize it. Is there any reason
79 * to export this from the SPU loader library? */
80
81SPU * crSPULoad( SPU *child, int id, char *name, char *dir, void *server )
82{
83 SPU *the_spu;
84 char *path;
85 bool fNeedSuperSPU = false;
86
87 CRASSERT( name != NULL );
88
89 the_spu = (SPU*)crAlloc( sizeof( *the_spu ) );
90 /* ensure all fields are initially zero,
91 * NOTE: what actually MUST be zero at this point is the_spu->superSPU, otherwise
92 * crSPUUnloadChain in the failure branches below will misbehave */
93 crMemset(the_spu, 0, sizeof (*the_spu));
94 the_spu->id = id;
95 the_spu->privatePtr = NULL;
96 path = __findDLL( name, dir );
97 the_spu->dll = crDLLOpen( path, 0/*resolveGlobal*/ );
98 if (the_spu->dll == NULL)
99 {
100 crError("Couldn't load the DLL \"%s\"!\n", path);
101 crFree(the_spu);
102 return NULL;
103 }
104#if defined(DEBUG_misha) && defined(RT_OS_WINDOWS)
105 crDbgCmdSymLoadPrint(path, the_spu->dll->hinstLib);
106#endif
107 the_spu->entry_point =
108 (SPULoadFunction) crDLLGetNoError( the_spu->dll, SPU_ENTRY_POINT_NAME );
109 if (!the_spu->entry_point)
110 {
111 crError( "Couldn't load the SPU entry point \"%s\" from SPU \"%s\"!",
112 SPU_ENTRY_POINT_NAME, name );
113 crSPUUnloadChain(the_spu);
114 return NULL;
115 }
116
117 /* This basically calls the SPU's SPULoad() function */
118 if (!the_spu->entry_point( &(the_spu->name), &(the_spu->super_name),
119 &(the_spu->init), &(the_spu->self),
120 &(the_spu->cleanup),
121 &(the_spu->spu_flags)) )
122 {
123 crError( "I found the SPU \"%s\", but loading it failed!", name );
124 crSPUUnloadChain(the_spu);
125 return NULL;
126 }
127#ifdef IN_GUEST
128 if (crStrcmp(the_spu->name,"error"))
129 {
130 /* the default super/base class for an SPU is the error SPU */
131 if (the_spu->super_name == NULL)
132 {
133 the_spu->super_name = "error";
134 }
135 the_spu->superSPU = crSPULoad( child, id, the_spu->super_name, dir, server );
136 fNeedSuperSPU = true;
137 }
138#else
139 if (crStrcmp(the_spu->name,"hosterror"))
140 {
141 /* the default super/base class for an SPU is the error SPU */
142 if (the_spu->super_name == NULL)
143 {
144 the_spu->super_name = "hosterror";
145 }
146 the_spu->superSPU = crSPULoad( child, id, the_spu->super_name, dir, server );
147 fNeedSuperSPU = true;
148 }
149#endif
150 else
151 {
152 the_spu->superSPU = NULL;
153 }
154 if (fNeedSuperSPU && !the_spu->superSPU)
155 {
156 crError( "Unable to load super SPU \"%s\" of \"%s\"!", the_spu->super_name, name );
157 crSPUUnloadChain(the_spu);
158 return NULL;
159 }
160 crDebug("Initializing %s SPU", name);
161 the_spu->function_table = the_spu->init( id, child, the_spu, 0, 1 );
162 if (!the_spu->function_table) {
163 crDebug("Failed to init %s SPU", name);
164 crSPUUnloadChain(the_spu);
165 return NULL;
166 }
167 __buildDispatch( the_spu );
168 /*crDebug( "initializing dispatch table %p (for SPU %s)", (void*)&(the_spu->dispatch_table), name );*/
169 crSPUInitDispatchTable( &(the_spu->dispatch_table) );
170 /*crDebug( "Done initializing the dispatch table for SPU %s, calling the self function", name );*/
171
172 the_spu->dispatch_table.server = server;
173 the_spu->self( &(the_spu->dispatch_table) );
174 /*crDebug( "Done with the self function" );*/
175
176 return the_spu;
177}
178
179/**
180 * Load the entire chain of SPUs and initialize all of them.
181 * This function returns the first one in the chain.
182 */
183SPU *
184crSPULoadChain( int count, int *ids, char **names, char *dir, void *server )
185{
186 int i;
187 SPU *child_spu = NULL;
188 CRASSERT( count > 0 );
189
190 for (i = count-1 ; i >= 0 ; i--)
191 {
192 int spu_id = ids[i];
193 char *spu_name = names[i];
194 SPU *the_spu, *temp;
195
196 /* This call passes the previous version of spu, which is the SPU's
197 * "child" in this chain. */
198
199 the_spu = crSPULoad( child_spu, spu_id, spu_name, dir, server );
200 if (!the_spu) {
201 return NULL;
202 }
203
204 if (child_spu != NULL)
205 {
206 /* keep track of this so that people can pass functions through but
207 * still get updated when API's change on the fly. */
208 for (temp = the_spu ; temp ; temp = temp->superSPU )
209 {
210 struct _copy_list_node *node = (struct _copy_list_node *) crAlloc( sizeof( *node ) );
211 node->copy = &(temp->dispatch_table);
212 node->next = child_spu->dispatch_table.copyList;
213 child_spu->dispatch_table.copyList = node;
214 }
215 }
216 child_spu = the_spu;
217 }
218 return child_spu;
219}
220
221
222#if 00
223/* XXXX experimental code - not used at this time */
224/**
225 * Like crSPUChangeInterface(), but don't loop over all functions in
226 * the table to search for 'old_func'.
227 */
228void
229crSPUChangeFunction(SPUDispatchTable *table, unsigned int funcOffset,
230 void *newFunc)
231{
232 SPUGenericFunction *f = (SPUGenericFunction *) table + funcOffset;
233 struct _copy_list_node *temp;
234
235 CRASSERT(funcOffset < sizeof(*table) / sizeof(SPUGenericFunction));
236
237 printf("%s\n", __FUNCTION__);
238 if (table->mark == 1)
239 return;
240 table->mark = 1;
241 *f = newFunc;
242
243 /* update all copies of this table */
244#if 1
245 for (temp = table->copyList ; temp ; temp = temp->next)
246 {
247 crSPUChangeFunction( temp->copy, funcOffset, newFunc );
248 }
249#endif
250 if (table->copy_of != NULL)
251 {
252 crSPUChangeFunction( table->copy_of, funcOffset, newFunc );
253 }
254#if 0
255 for (temp = table->copyList ; temp ; temp = temp->next)
256 {
257 crSPUChangeFunction( temp->copy, funcOffset, newFunc );
258 }
259#endif
260 table->mark = 0;
261}
262#endif
263
264
265
266/**
267 * Call the cleanup() function for each SPU in a chain, close the SPU
268 * DLLs and free the SPU objects.
269 * \param headSPU pointer to the first SPU in the chain
270 */
271void
272crSPUUnloadChain(SPU *headSPU)
273{
274 SPU *the_spu = headSPU, *next_spu;
275
276 while (the_spu)
277 {
278 crDebug("Cleaning up SPU %s", the_spu->name);
279
280 if (the_spu->cleanup)
281 the_spu->cleanup();
282
283 next_spu = the_spu->superSPU;
284 crDLLClose(the_spu->dll);
285 crFree(the_spu);
286 the_spu = next_spu;
287 }
288}
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