VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/unpacker/unpack.py@ 78225

Last change on this file since 78225 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: 11.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
6from __future__ import print_function
7import sys
8
9import apiutil
10
11
12apiutil.CopyrightC()
13
14print("""/* DO NOT EDIT! THIS CODE IS AUTOGENERATED BY unpack.py */
15
16#include "unpacker.h"
17#include "cr_opcodes.h"
18#include "cr_error.h"
19#include "cr_mem.h"
20#include "cr_spu.h"
21#include "unpack_extend.h"
22#include <stdio.h>
23#include <memory.h>
24
25#include <iprt/cdefs.h>
26
27DECLEXPORT(const unsigned char *) cr_unpackData = NULL;
28DECLEXPORT(const unsigned char *) cr_unpackDataEnd = NULL;
29
30static void crUnpackExtend(PCrUnpackerState pState);
31static void crUnpackExtendDbg(PCrUnpackerState pState);
32
33#if 0 //def DEBUG_misha
34//# define CR_UNPACK_DEBUG_OPCODES
35# define CR_UNPACK_DEBUG_LAST_OPCODES
36# define CR_UNPACK_DEBUG_PREV_OPCODES
37#endif
38
39#ifdef CR_UNPACK_DEBUG_PREV_OPCODES
40static GLenum g_VBoxDbgCrPrevOpcode = 0;
41static GLenum g_VBoxDbgCrPrevExtendOpcode = 0;
42#endif
43""")
44
45nodebug_opcodes = [
46 "CR_MULTITEXCOORD2FARB_OPCODE",
47 "CR_VERTEX3F_OPCODE",
48 "CR_NORMAL3F_OPCODE",
49 "CR_COLOR4UB_OPCODE",
50 "CR_LOADIDENTITY_OPCODE",
51 "CR_MATRIXMODE_OPCODE",
52 "CR_LOADMATRIXF_OPCODE",
53 "CR_DISABLE_OPCODE",
54 "CR_COLOR4F_OPCODE",
55 "CR_ENABLE_OPCODE",
56 "CR_BEGIN_OPCODE",
57 "CR_END_OPCODE",
58 "CR_SECONDARYCOLOR3FEXT_OPCODE"
59]
60
61nodebug_extopcodes = [
62 "CR_ACTIVETEXTUREARB_EXTEND_OPCODE"
63]
64
65#
66# Useful functions
67#
68
69def ReadData( offset, arg_type ):
70 """Emit a READ_DOUBLE or READ_DATA call for pulling a GL function
71 argument out of the buffer's operand area."""
72 if arg_type == "GLdouble" or arg_type == "GLclampd":
73 retval = "READ_DOUBLE(pState, %d)" % offset
74 else:
75 retval = "READ_DATA(pState, %d, %s)" % (offset, arg_type)
76 return retval
77
78
79def FindReturnPointer( return_type, params ):
80 """For GL functions that return values (either as the return value or
81 through a pointer parameter) emit a SET_RETURN_PTR call."""
82 arg_len = apiutil.PacketLength( params )
83 if (return_type != 'void'):
84 print('\tSET_RETURN_PTR(pState, %d);' % (arg_len + 8)) # extended opcode plus packet length
85 else:
86 paramList = [ ('foo', 'void *', 0) ]
87 print('\tSET_RETURN_PTR(pState, %d);' % (arg_len + 8 - apiutil.PacketLength(paramList)))
88
89
90def getWritebackPointerOffset(return_type, params):
91 """Returns the offset of the writeback pointer"""
92 arg_len = apiutil.PacketLength( params )
93 if return_type != 'void':
94 paramList = [ ('foo', 'void *', 0) ]
95 arg_len += apiutil.PacketLength( paramList )
96
97 return arg_len + 8 # extended opcode plus packet length
98
99def FindWritebackPointer( return_type, params ):
100 """Emit a SET_WRITEBACK_PTR call."""
101 print('\tSET_WRITEBACK_PTR(pState, %d);' % getWritebackPointerOffset(return_type, params))
102
103
104def MakeNormalCall( return_type, func_name, params, counter_init = 0 ):
105 counter = counter_init
106 copy_of_params = params[:]
107
108 for i in range( 0, len(params) ):
109 (name, type, vecSize) = params[i]
110 if apiutil.IsPointer(copy_of_params[i][1]):
111 params[i] = ('NULL', type, vecSize)
112 copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
113 if not "get" in apiutil.Properties(func_name):
114 print('\tcrError( "%s needs to be special cased!" );' % func_name)
115 else:
116 print("\t%s %s = %s;" % ( copy_of_params[i][1], name, ReadData( counter, copy_of_params[i][1] ) ))
117 counter += apiutil.sizeof(copy_of_params[i][1])
118
119 if ("get" in apiutil.Properties(func_name)):
120 FindReturnPointer( return_type, params )
121 FindWritebackPointer( return_type, params )
122
123 if return_type != "void":
124 print("\t(void)", end=" ")
125 else:
126 print("\t", end="")
127 print("pState->pDispatchTbl->%s(%s);" % (func_name, apiutil.MakeCallStringForDispatcher(params)))
128
129
130def MakeVectorCall( return_type, func_name, arg_type ):
131 """Convert a call like glVertex3f to glVertex3fv."""
132 vec_func = apiutil.VectorFunction(func_name)
133 params = apiutil.Parameters(vec_func)
134 assert len(params) == 1
135 (arg_name, vecType, vecSize) = params[0]
136
137 if arg_type == "GLdouble" or arg_type == "GLclampd":
138 print("#ifdef CR_UNALIGNED_ACCESS_OKAY")
139 print("\tpState->pDispatchTbl->%s((%s) pState->pbUnpackData);" % (vec_func, vecType))
140 print("#else")
141 for index in range(0, vecSize):
142 print("\tGLdouble v" + repr(index) + " = READ_DOUBLE(pState, " + repr(index * 8) + ");")
143 if return_type != "void":
144 print("\t(void) pState->pDispatchTbl->%s(" % func_name, end="")
145 else:
146 print("\tpState->pDispatchTbl->%s(" % func_name, end="")
147 for index in range(0, vecSize):
148 print("v" + repr(index), end="")
149 if index != vecSize - 1:
150 print(",", end=" ")
151 print(");")
152 print("#endif")
153 else:
154 print("\tpState->pDispatchTbl->%s((%s) pState->pbUnpackData);" % (vec_func, vecType))
155
156
157
158keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
159
160
161#
162# Generate unpack functions for all the simple functions.
163#
164for func_name in keys:
165 if (not "pack" in apiutil.ChromiumProps(func_name) or
166 apiutil.FindSpecial( "unpacker", func_name )):
167 continue
168
169 params = apiutil.Parameters(func_name)
170 return_type = apiutil.ReturnType(func_name)
171
172 packet_length = apiutil.PacketLength( params )
173 print("static void crUnpack%s(PCrUnpackerState pState)" % func_name)
174 print("{")
175 if ("get" in apiutil.Properties(func_name)):
176 print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % getWritebackPointerOffset(return_type, params));
177 elif packet_length != 0:
178 print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % packet_length);
179
180 vector_func = apiutil.VectorFunction(func_name)
181 if (vector_func and len(apiutil.Parameters(vector_func)) == 1):
182 MakeVectorCall( return_type, func_name, params[0][1] )
183 else:
184 MakeNormalCall( return_type, func_name, params )
185 if packet_length == 0:
186 print("\tINCR_DATA_PTR_NO_ARGS(pState);")
187 else:
188 print("\tINCR_DATA_PTR(pState, %d);" % packet_length)
189 print("}\n")
190
191
192#
193# Emit some code
194#
195print("""
196CR_UNPACK_BUFFER_TYPE crUnpackGetBufferType(const void *opcodes, unsigned int num_opcodes)
197{
198 const uint8_t *pu8Codes = (const uint8_t *)opcodes;
199
200 uint8_t first;
201 uint8_t last;
202
203 if (!num_opcodes)
204 return CR_UNPACK_BUFFER_TYPE_GENERIC;
205
206 first = pu8Codes[0];
207 last = pu8Codes[1-(int)num_opcodes];
208
209 switch (last)
210 {
211 case CR_CMDBLOCKFLUSH_OPCODE:
212 return CR_UNPACK_BUFFER_TYPE_CMDBLOCK_FLUSH;
213 case CR_CMDBLOCKEND_OPCODE:
214 return (first == CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_END;
215 default:
216 return (first != CR_CMDBLOCKBEGIN_OPCODE) ? CR_UNPACK_BUFFER_TYPE_GENERIC : CR_UNPACK_BUFFER_TYPE_CMDBLOCK_BEGIN;
217 }
218}
219
220void crUnpack(PCrUnpackerState pState)
221{
222 unsigned int i;
223
224#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
225 crDebug("crUnpack: %d opcodes", pState->cOpcodes);
226#endif
227
228 for (i = 0; i < pState->cOpcodes && RT_SUCCESS(pState->rcUnpack); i++)
229 {
230
231 CRDBGPTR_CHECKZ(pState->pWritebackPtr);
232 CRDBGPTR_CHECKZ(pState->pReturnPtr);
233
234 /*crDebug(\"Unpacking opcode \%d\", *pState->pbOpcodes);*/
235#ifdef CR_UNPACK_DEBUG_PREV_OPCODES
236 g_VBoxDbgCrPrevOpcode = *pState->pbOpcodes;
237#endif
238 switch( *pState->pbOpcodes )
239 {""")
240
241#
242# Emit switch cases for all unextended opcodes
243#
244for func_name in keys:
245 if "pack" in apiutil.ChromiumProps(func_name):
246 print('\t\t\tcase %s:' % apiutil.OpcodeName( func_name ))
247 if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
248 print("""
249#ifdef CR_UNPACK_DEBUG_LAST_OPCODES
250 if (i==(num_opcodes-1))
251#endif
252#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
253 crDebug("Unpack: %s");
254#endif """ % apiutil.OpcodeName(func_name))
255 print('\t\t\t\tcrUnpack%s(pState); \n\t\t\t\tbreak;' % func_name)
256
257print("""
258 case CR_EXTEND_OPCODE:
259 #ifdef CR_UNPACK_DEBUG_OPCODES
260 crUnpackExtendDbg(pState);
261 #else
262 # ifdef CR_UNPACK_DEBUG_LAST_OPCODES
263 if (i==(num_opcodes-1)) crUnpackExtendDbg(pState);
264 else
265 # endif
266 crUnpackExtend(pState);
267 #endif
268 break;
269 case CR_CMDBLOCKBEGIN_OPCODE:
270 case CR_CMDBLOCKEND_OPCODE:
271 case CR_CMDBLOCKFLUSH_OPCODE:
272 case CR_NOP_OPCODE:
273 INCR_DATA_PTR_NO_ARGS(pState);
274 break;
275 default:
276 crError( "Unknown opcode: %d", *pState->pbOpcodes );
277 break;
278 }
279
280 CRDBGPTR_CHECKZ(pState->pWritebackPtr);
281 CRDBGPTR_CHECKZ(pState->pReturnPtr);
282 pState->pbOpcodes--;
283 }
284}""")
285
286
287#
288# Emit unpack functions for extended opcodes, non-special functions only.
289#
290for func_name in keys:
291 if ("extpack" in apiutil.ChromiumProps(func_name)
292 and not apiutil.FindSpecial("unpacker", func_name)):
293 return_type = apiutil.ReturnType(func_name)
294 params = apiutil.Parameters(func_name)
295 print('static void crUnpackExtend%s(PCrUnpackerState pState)' % func_name)
296 print('{')
297 if ("get" in apiutil.Properties(func_name)):
298 print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % (8 + getWritebackPointerOffset(return_type, params)));
299 else:
300 print("\tCHECK_BUFFER_SIZE_STATIC(pState, %s);" % (8 + apiutil.PacketLength( params )));
301 MakeNormalCall( return_type, func_name, params, 8 )
302 print('}\n')
303
304print('static void crUnpackExtend(PCrUnpackerState pState)')
305print('{')
306print('\tCHECK_BUFFER_SIZE_STATIC_LAST(pState, 4, GLenum);');
307print('\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' ))
308print('')
309print('#ifdef CR_UNPACK_DEBUG_PREV_OPCODES')
310print('\tg_VBoxDbgCrPrevExtendOpcode = extend_opcode;')
311print('#endif')
312print('')
313print('\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/')
314print('\tswitch( extend_opcode )')
315print('\t{')
316
317
318#
319# Emit switch statement for extended opcodes
320#
321for func_name in keys:
322 if "extpack" in apiutil.ChromiumProps(func_name):
323 print('\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name ))
324# print('\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )))
325 print('\t\t\tcrUnpackExtend%s(pState);' % func_name)
326 print('\t\t\tbreak;')
327
328print(""" default:
329 crError( "Unknown extended opcode: %d", (int) extend_opcode );
330 break;
331 }
332 INCR_VAR_PTR(pState);
333}""")
334
335print('static void crUnpackExtendDbg(PCrUnpackerState pState)')
336print('{')
337print('\tCHECK_BUFFER_SIZE_STATIC_LAST(pState, 4, GLenum);');
338print('\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' ))
339print('')
340print('#ifdef CR_UNPACK_DEBUG_PREV_OPCODES')
341print('\tg_VBoxDbgCrPrevExtendOpcode = extend_opcode;')
342print('#endif')
343print('')
344print('\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/')
345print('\tswitch( extend_opcode )')
346print('\t{')
347
348
349#
350# Emit switch statement for extended opcodes
351#
352for func_name in keys:
353 if "extpack" in apiutil.ChromiumProps(func_name):
354 print('\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name ))
355 if not apiutil.ExtendedOpcodeName(func_name) in nodebug_extopcodes:
356 print('\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name ))
357 print('\t\t\tcrUnpackExtend%s(pState);' % func_name)
358 print('\t\t\tbreak;')
359
360print(""" default:
361 crError( "Unknown extended opcode: %d", (int) extend_opcode );
362 break;
363 }
364 INCR_VAR_PTR(pState);
365}""")
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