VirtualBox

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

Last change on this file since 53426 was 52437, checked in by vboxsync, 10 years ago

crOpenGL: debugging

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.4 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_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#if defined(DEBUG_misha) && defined(RT_OS_WINDOWS)
99 crDbgCmdSymLoadPrint(path, the_spu->dll->hinstLib);
100#endif
101 the_spu->entry_point =
102 (SPULoadFunction) crDLLGetNoError( the_spu->dll, SPU_ENTRY_POINT_NAME );
103 if (!the_spu->entry_point)
104 {
105 crError( "Couldn't load the SPU entry point \"%s\" from SPU \"%s\"!",
106 SPU_ENTRY_POINT_NAME, name );
107 crSPUUnloadChain(the_spu);
108 return NULL;
109 }
110
111 /* This basically calls the SPU's SPULoad() function */
112 if (!the_spu->entry_point( &(the_spu->name), &(the_spu->super_name),
113 &(the_spu->init), &(the_spu->self),
114 &(the_spu->cleanup),
115 &(the_spu->options),
116 &(the_spu->spu_flags)) )
117 {
118 crError( "I found the SPU \"%s\", but loading it failed!", name );
119 crSPUUnloadChain(the_spu);
120 return NULL;
121 }
122#ifdef IN_GUEST
123 if (crStrcmp(the_spu->name,"error"))
124 {
125 /* the default super/base class for an SPU is the error SPU */
126 if (the_spu->super_name == NULL)
127 {
128 the_spu->super_name = "error";
129 }
130 the_spu->superSPU = crSPULoad( child, id, the_spu->super_name, dir, server );
131 }
132#else
133 if (crStrcmp(the_spu->name,"hosterror"))
134 {
135 /* the default super/base class for an SPU is the error SPU */
136 if (the_spu->super_name == NULL)
137 {
138 the_spu->super_name = "hosterror";
139 }
140 the_spu->superSPU = crSPULoad( child, id, the_spu->super_name, dir, server );
141 }
142#endif
143 else
144 {
145 the_spu->superSPU = NULL;
146 }
147 crDebug("Initializing %s SPU", name);
148 the_spu->function_table = the_spu->init( id, child, the_spu, 0, 1 );
149 if (!the_spu->function_table) {
150 crDebug("Failed to init %s SPU", name);
151 crSPUUnloadChain(the_spu);
152 return NULL;
153 }
154 __buildDispatch( the_spu );
155 /*crDebug( "initializing dispatch table %p (for SPU %s)", (void*)&(the_spu->dispatch_table), name );*/
156 crSPUInitDispatchTable( &(the_spu->dispatch_table) );
157 /*crDebug( "Done initializing the dispatch table for SPU %s, calling the self function", name );*/
158
159 the_spu->dispatch_table.server = server;
160 the_spu->self( &(the_spu->dispatch_table) );
161 /*crDebug( "Done with the self function" );*/
162
163 return the_spu;
164}
165
166/**
167 * Load the entire chain of SPUs and initialize all of them.
168 * This function returns the first one in the chain.
169 */
170SPU *
171crSPULoadChain( int count, int *ids, char **names, char *dir, void *server )
172{
173 int i;
174 SPU *child_spu = NULL;
175 CRASSERT( count > 0 );
176
177 for (i = count-1 ; i >= 0 ; i--)
178 {
179 int spu_id = ids[i];
180 char *spu_name = names[i];
181 SPU *the_spu, *temp;
182
183 /* This call passes the previous version of spu, which is the SPU's
184 * "child" in this chain. */
185
186 the_spu = crSPULoad( child_spu, spu_id, spu_name, dir, server );
187 if (!the_spu) {
188 return NULL;
189 }
190
191 if (child_spu != NULL)
192 {
193 /* keep track of this so that people can pass functions through but
194 * still get updated when API's change on the fly. */
195 for (temp = the_spu ; temp ; temp = temp->superSPU )
196 {
197 struct _copy_list_node *node = (struct _copy_list_node *) crAlloc( sizeof( *node ) );
198 node->copy = &(temp->dispatch_table);
199 node->next = child_spu->dispatch_table.copyList;
200 child_spu->dispatch_table.copyList = node;
201 }
202 }
203 child_spu = the_spu;
204 }
205 return child_spu;
206}
207
208
209#if 00
210/* XXXX experimental code - not used at this time */
211/**
212 * Like crSPUChangeInterface(), but don't loop over all functions in
213 * the table to search for 'old_func'.
214 */
215void
216crSPUChangeFunction(SPUDispatchTable *table, unsigned int funcOffset,
217 void *newFunc)
218{
219 SPUGenericFunction *f = (SPUGenericFunction *) table + funcOffset;
220 struct _copy_list_node *temp;
221
222 CRASSERT(funcOffset < sizeof(*table) / sizeof(SPUGenericFunction));
223
224 printf("%s\n", __FUNCTION__);
225 if (table->mark == 1)
226 return;
227 table->mark = 1;
228 *f = newFunc;
229
230 /* update all copies of this table */
231#if 1
232 for (temp = table->copyList ; temp ; temp = temp->next)
233 {
234 crSPUChangeFunction( temp->copy, funcOffset, newFunc );
235 }
236#endif
237 if (table->copy_of != NULL)
238 {
239 crSPUChangeFunction( table->copy_of, funcOffset, newFunc );
240 }
241#if 0
242 for (temp = table->copyList ; temp ; temp = temp->next)
243 {
244 crSPUChangeFunction( temp->copy, funcOffset, newFunc );
245 }
246#endif
247 table->mark = 0;
248}
249#endif
250
251
252
253/**
254 * Call the cleanup() function for each SPU in a chain, close the SPU
255 * DLLs and free the SPU objects.
256 * \param headSPU pointer to the first SPU in the chain
257 */
258void
259crSPUUnloadChain(SPU *headSPU)
260{
261 SPU *the_spu = headSPU, *next_spu;
262
263 while (the_spu)
264 {
265 crDebug("Cleaning up SPU %s", the_spu->name);
266
267 if (the_spu->cleanup)
268 the_spu->cleanup();
269
270 next_spu = the_spu->superSPU;
271 crDLLClose(the_spu->dll);
272 crFree(the_spu);
273 the_spu = next_spu;
274 }
275}
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