VirtualBox

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

最後變更 在這個檔案從51616是 43140,由 vboxsync 提交於 12 年 前

crOpenGL: fix misbehave on SPU init failure

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

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