VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/packer/pack_buffer.c@ 78190

Last change on this file since 78190 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: 13.9 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 "packer.h"
10#include "cr_error.h"
11#include "cr_protocol.h"
12#ifndef IN_RING0
13#include "cr_unpack.h"
14#endif
15
16#ifndef IN_RING0
17void crWriteUnalignedDouble( void *buffer, double d )
18{
19 unsigned int *ui = (unsigned int *) buffer;
20 ui[0] = ((unsigned int *) &d)[0];
21 ui[1] = ((unsigned int *) &d)[1];
22}
23
24double crReadUnalignedDouble( const void *buffer )
25{
26 const unsigned int *ui = (unsigned int *) buffer;
27 double d;
28 ((unsigned int *) &d)[0] = ui[0];
29 ((unsigned int *) &d)[1] = ui[1];
30 return d;
31}
32#endif
33/*
34 * We need the packer to run as efficiently as possible. To avoid one
35 * pointer dereference from the CRPackContext to the current CRPackBuffer,
36 * we keep a _copy_ of the current CRPackBuffer in the CRPackContext and
37 * operate on the fields in CRPackContext, rather than the CRPackBuffer.
38 *
39 * To keep things in sync, when we change a context's
40 * buffer, we have to use the crPackSet/GetBuffer() functions.
41 */
42
43void crPackSetBuffer( CRPackContext *pc, CRPackBuffer *buffer )
44{
45 CRASSERT( pc );
46 CRASSERT( buffer );
47
48 if (pc->currentBuffer == buffer)
49 return; /* re-bind is no-op */
50
51 if (pc->currentBuffer) {
52 /* Another buffer currently bound to this packer (shouldn't normally occur)
53 * Release it. Fixes Ensight issue.
54 */
55 crPackReleaseBuffer(pc);
56 }
57
58 CRASSERT( pc->currentBuffer == NULL); /* release if NULL? */
59 CRASSERT( buffer->context == NULL );
60
61 /* bind context to buffer */
62 pc->currentBuffer = buffer;
63 buffer->context = pc;
64
65 /* update the context's packing fields with those from the buffer */
66 pc->buffer = *buffer; /* struct copy */
67}
68
69#ifndef IN_RING0
70/* This is useful for debugging packer problems */
71void crPackSetBufferDEBUG( const char *file, int line, CRPackContext *pc, CRPackBuffer *buffer)
72
73{
74 crPackSetBuffer( pc, buffer );
75 /* record debugging info */
76 pc->file = crStrdup(file);
77 pc->line = line;
78}
79#endif
80
81/*
82 * Release the buffer currently attached to the context.
83 * Update/resync data structures.
84 */
85void crPackReleaseBuffer( CRPackContext *pc )
86{
87 CRPackBuffer *buf;
88 CRASSERT( pc );
89
90 if (!pc->currentBuffer) {
91 crWarning("crPackReleaseBuffer called with no current buffer");
92 return; /* nothing to do */
93 }
94
95 CRASSERT( pc->currentBuffer->context == pc );
96
97 /* buffer to release */
98 buf = pc->currentBuffer;
99
100 /* copy context's fields back into the buffer to update it */
101 *buf = pc->buffer; /* struct copy */
102
103 /* unbind buffer from context */
104 buf->context = NULL;
105 pc->currentBuffer = NULL;
106
107 /* zero-out context's packing fields just to be safe */
108 crMemZero(&(pc->buffer), sizeof(pc->buffer));
109
110 /* update the debugging fields */
111 if (pc->file)
112 crFree(pc->file);
113 pc->file = NULL;
114 pc->line = -1;
115}
116
117void crPackFlushFunc( CRPackContext *pc, CRPackFlushFunc ff )
118{
119 pc->Flush = ff;
120}
121
122void crPackFlushArg( CRPackContext *pc, void *flush_arg )
123{
124 pc->flush_arg = flush_arg;
125}
126
127void crPackSendHugeFunc( CRPackContext *pc, CRPackSendHugeFunc shf )
128{
129 pc->SendHuge = shf;
130}
131
132/*
133 * This basically resets the buffer attached to <pc> to the default, empty
134 * state.
135 */
136void crPackResetPointers( CRPackContext *pc )
137{
138 const GLboolean geom_only = pc->buffer.geometry_only; /* save this flag */
139 const GLboolean holds_BeginEnd = pc->buffer.holds_BeginEnd;
140 const GLboolean in_BeginEnd = pc->buffer.in_BeginEnd;
141 const GLboolean canBarf = pc->buffer.canBarf;
142 CRPackBuffer *buf = pc->currentBuffer;
143 CRASSERT(buf);
144 crPackInitBuffer( buf, buf->pack, buf->size, buf->mtu
145#ifdef IN_RING0
146 , 0
147#endif
148 );
149 pc->buffer.geometry_only = geom_only; /* restore the flag */
150 pc->buffer.holds_BeginEnd = holds_BeginEnd;
151 pc->buffer.in_BeginEnd = in_BeginEnd;
152 pc->buffer.canBarf = canBarf;
153}
154
155
156/**
157 * Return max number of opcodes that'll fit in the given buffer size.
158 * Each opcode has at least a 1-word payload, so opcodes can occupy at most
159 * 20% of the space.
160 */
161int
162crPackMaxOpcodes( int buffer_size )
163{
164 int n = ( buffer_size - sizeof(CRMessageOpcodes) ) / 5;
165 /* Don't forget to add one here in case the buffer size is not
166 * divisible by 4. Thanks to Ken Moreland for finding this.
167 */
168 n++;
169 /* round up to multiple of 4 */
170 n = (n + 0x3) & (~0x3);
171 return n;
172}
173
174
175/**
176 * Return max number of data bytes that'll fit in the given buffer size.
177 */
178int
179crPackMaxData( int buffer_size )
180{
181 int n = buffer_size - sizeof(CRMessageOpcodes);
182 n -= crPackMaxOpcodes(buffer_size);
183 return n;
184}
185
186
187/**
188 * Initialize the given CRPackBuffer object.
189 * The buffer may or may not be currently bound to a CRPackContext.
190 *
191 * Opcodes and operands are packed into a buffer in a special way.
192 * Opcodes start at opcode_start and go downward in memory while operands
193 * start at data_start and go upward in memory. The buffer is full when we
194 * either run out of opcode space or operand space.
195 *
196 * Diagram (memory addresses increase upward):
197 *
198 * data_end -> | | <- buf->pack + buf->size
199 * +---------+
200 * | |
201 * | |
202 * | operands|
203 * | |
204 * | |
205 * data_start -> +---------+
206 * opcode_start -> | |
207 * | |
208 * | opcodes |
209 * | |
210 * | |
211 * opcode_end -> +---------+ <- buf->pack
212 *
213 * \param buf the CRPackBuffer to initialize
214 * \param pack the address of the buffer for packing opcodes/operands.
215 * \param size size of the buffer, in bytes
216 * \param mtu max transmission unit size, in bytes. When the buffer
217 * has 'mtu' bytes in it, we have to send it. The MTU might
218 * be somewhat smaller than the buffer size.
219 */
220void crPackInitBuffer( CRPackBuffer *buf, void *pack, int size, int mtu
221#ifdef IN_RING0
222 , unsigned int num_opcodes
223#endif
224 )
225{
226#ifndef IN_RING0
227 unsigned int num_opcodes;
228#endif
229
230 CRASSERT(mtu <= size);
231
232 buf->size = size;
233 buf->mtu = mtu;
234 buf->pack = pack;
235
236#ifdef IN_RING0
237 if(num_opcodes)
238 {
239 num_opcodes = (num_opcodes + 0x3) & (~0x3);
240 }
241 else
242#endif
243 {
244 num_opcodes = crPackMaxOpcodes( buf->size );
245 }
246
247 buf->data_start =
248 (unsigned char *) buf->pack + num_opcodes + sizeof(CRMessageOpcodes);
249 buf->data_current = buf->data_start;
250 buf->data_end = (unsigned char *) buf->pack + buf->size;
251
252 buf->opcode_start = buf->data_start - 1;
253 buf->opcode_current = buf->opcode_start;
254 buf->opcode_end = buf->opcode_start - num_opcodes;
255
256 buf->geometry_only = GL_FALSE;
257 buf->holds_BeginEnd = GL_FALSE;
258 buf->in_BeginEnd = GL_FALSE;
259 buf->canBarf = GL_FALSE;
260
261 if (buf->context) {
262 /* Also reset context's packing fields */
263 CRPackContext *pc = buf->context;
264 CRASSERT(pc->currentBuffer == buf);
265 /*crMemcpy( &(pc->buffer), buf, sizeof(*buf) );*/
266 pc->buffer = *buf;
267 }
268}
269
270
271int crPackCanHoldBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src )
272{
273 const int num_data = crPackNumData(src);
274 const int num_opcode = crPackNumOpcodes(src);
275 int res;
276 CR_GET_PACKER_CONTEXT(pc);
277 CR_LOCK_PACKER_CONTEXT(pc);
278 res = crPackCanHoldOpcode( pc, num_opcode, num_data );
279 CR_UNLOCK_PACKER_CONTEXT(pc);
280 return res;
281}
282
283
284int crPackCanHoldBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src )
285{
286 const int len_aligned = (src->data_current - src->opcode_current - 1 + 3) & ~3;
287 CR_GET_PACKER_CONTEXT(pc);
288 /* 24 is the size of the bounds-info packet... */
289 return crPackCanHoldOpcode( pc, 1, len_aligned + 24 );
290}
291
292void crPackAppendBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src )
293{
294 CR_GET_PACKER_CONTEXT(pc);
295 const int num_data = crPackNumData(src);
296 const int num_opcode = crPackNumOpcodes(src);
297
298 CRASSERT(num_data >= 0);
299 CRASSERT(num_opcode >= 0);
300
301 CR_LOCK_PACKER_CONTEXT(pc);
302
303 /* don't append onto ourself! */
304 CRASSERT(pc->currentBuffer);
305 CRASSERT(pc->currentBuffer != src);
306
307 if (!crPackCanHoldBuffer(CR_PACKER_CONTEXT_ARG src))
308 {
309 if (src->holds_BeginEnd)
310 {
311 crWarning( "crPackAppendBuffer: overflowed the destination!" );
312 CR_UNLOCK_PACKER_CONTEXT(pc);
313 return;
314 }
315 else
316 {
317 crError( "crPackAppendBuffer: overflowed the destination!" );
318 CR_UNLOCK_PACKER_CONTEXT(pc);
319 }
320 }
321
322 /* Copy the buffer data/operands which are at the head of the buffer */
323 crMemcpy( pc->buffer.data_current, src->data_start, num_data );
324 pc->buffer.data_current += num_data;
325
326 /* Copy the buffer opcodes which are at the tail of the buffer */
327 CRASSERT( pc->buffer.opcode_current - num_opcode >= pc->buffer.opcode_end );
328 crMemcpy( pc->buffer.opcode_current + 1 - num_opcode, src->opcode_current + 1,
329 num_opcode );
330 pc->buffer.opcode_current -= num_opcode;
331 pc->buffer.holds_BeginEnd |= src->holds_BeginEnd;
332 pc->buffer.in_BeginEnd = src->in_BeginEnd;
333 pc->buffer.holds_List |= src->holds_List;
334 CR_UNLOCK_PACKER_CONTEXT(pc);
335}
336
337
338void
339crPackAppendBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *src, const CRrecti *bounds )
340{
341 CR_GET_PACKER_CONTEXT(pc);
342 const GLbyte *payload = (const GLbyte *) src->opcode_current + 1;
343 const int num_opcodes = crPackNumOpcodes(src);
344 const int length = src->data_current - src->opcode_current - 1;
345
346 CRASSERT(pc);
347 CR_LOCK_PACKER_CONTEXT(pc);
348 CRASSERT(pc->currentBuffer);
349 CRASSERT(pc->currentBuffer != src);
350
351 /*
352 * payload points to the block of opcodes immediately followed by operands.
353 */
354
355 if ( !crPackCanHoldBoundedBuffer( CR_PACKER_CONTEXT_ARG src ) )
356 {
357 if (src->holds_BeginEnd)
358 {
359 crWarning( "crPackAppendBoundedBuffer: overflowed the destination!" );
360 CR_UNLOCK_PACKER_CONTEXT(pc);
361 return;
362 }
363 else
364 {
365 crError( "crPackAppendBoundedBuffer: overflowed the destination!" );
366 CR_UNLOCK_PACKER_CONTEXT(pc);
367 }
368 }
369
370 crPackBoundsInfoCR( CR_PACKER_CONTEXT_ARG bounds, payload, length, num_opcodes );
371 pc->buffer.holds_BeginEnd |= src->holds_BeginEnd;
372 pc->buffer.in_BeginEnd = src->in_BeginEnd;
373 pc->buffer.holds_List |= src->holds_List;
374 CR_UNLOCK_PACKER_CONTEXT(pc);
375}
376
377
378#ifndef CHROMIUM_THREADSAFE
379static unsigned char *sanityCheckPointer = NULL;
380#endif
381
382
383/*
384 * Allocate space for a command that might be very large, such as
385 * glTexImage2D or glBufferDataARB call.
386 * The command buffer _MUST_ then be transmitted by calling crHugePacket.
387 */
388void *crPackAlloc( CR_PACKER_CONTEXT_ARGDECL unsigned int size )
389{
390 CR_GET_PACKER_CONTEXT(pc);
391 unsigned char *data_ptr;
392
393 /* include space for the length and make the payload word-aligned */
394 size = ( size + sizeof(unsigned int) + 0x3 ) & ~0x3;
395
396 CR_LOCK_PACKER_CONTEXT(pc);
397
398 if ( crPackCanHoldOpcode( pc, 1, size ) )
399 {
400 /* we can just put it in the current buffer */
401 CR_GET_BUFFERED_POINTER_NOLOCK(pc, size ); /* NOTE: this sets data_ptr */
402 }
403 else
404 {
405 /* Okay, it didn't fit. Maybe it will after we flush. */
406 CR_UNLOCK_PACKER_CONTEXT(pc);
407 pc->Flush( pc->flush_arg );
408 CR_LOCK_PACKER_CONTEXT(pc);
409 if ( crPackCanHoldOpcode( pc, 1, size ) )
410 {
411 CR_GET_BUFFERED_POINTER_NOLOCK(pc, size ); /* NOTE: this sets data_ptr */
412 }
413 else
414 {
415 /* It's really way too big, so allocate a temporary packet
416 * with space for the single opcode plus the payload &
417 * header.
418 */
419 data_ptr = (unsigned char *)
420 crAlloc( sizeof(CRMessageOpcodes) + 4 + size );
421
422 /* skip the header & opcode space */
423 data_ptr += sizeof(CRMessageOpcodes) + 4;
424 }
425 }
426
427 /* At the top of the function, we added four to the request size and
428 * rounded it up to the next multiple of four.
429 *
430 * At this point, we have:
431 *
432 * HIGH MEM | byte size - 1 | \
433 * ... |
434 * ... | - original 'size' bytes for data
435 * | operand data | |
436 * return value -> | operand data | /
437 * | byte 3 | \
438 * | byte 2 | |- These bytes will store 'size'
439 * | byte 1 | |
440 * data_ptr -> | byte 0 | /
441 * | CR opcode | <- Set in packspuHuge()
442 * | unused |
443 * | unused |
444 * | unused |
445 * | CRMessageOpcodes |
446 * | CRMessageOpcodes |
447 * ...
448 * | CRMessageOpcodes |
449 * | CRMessageOpcodes |
450 * LOW MEM +------------------+
451 */
452
453 *((unsigned int *) data_ptr) = size;
454#ifndef CHROMIUM_THREADSAFE
455 sanityCheckPointer = data_ptr + 4;
456#endif
457 return data_ptr + 4;
458}
459
460#define IS_BUFFERED( packet ) \
461 ((unsigned char *) (packet) >= pc->buffer.data_start && \
462 (unsigned char *) (packet) < pc->buffer.data_end)
463
464
465/*
466 * Transmit a packet which was allocated with crPackAlloc.
467 */
468void crHugePacket( CR_PACKER_CONTEXT_ARGDECL CROpcode opcode, void *packet )
469{
470 CR_GET_PACKER_CONTEXT(pc);
471#ifndef CHROMIUM_THREADSAFE
472 CRASSERT(sanityCheckPointer == packet);
473 sanityCheckPointer = NULL;
474#endif
475
476 if ( IS_BUFFERED( packet ) )
477 WRITE_OPCODE( pc, opcode );
478 else
479 pc->SendHuge( opcode, packet );
480}
481
482void crPackFree( CR_PACKER_CONTEXT_ARGDECL void *packet )
483{
484 CR_GET_PACKER_CONTEXT(pc);
485
486 if ( IS_BUFFERED( packet ) )
487 {
488 CR_UNLOCK_PACKER_CONTEXT(pc);
489 return;
490 }
491
492 CR_UNLOCK_PACKER_CONTEXT(pc);
493
494 /* the pointer passed in doesn't include the space for the single
495 * opcode (4 bytes because of the alignment requirement) or the
496 * length field or the header */
497 crFree( (unsigned char *) packet - 8 - sizeof(CRMessageOpcodes) );
498}
499
500void crNetworkPointerWrite( CRNetworkPointer *dst, void *src )
501{
502 /* init CRNetworkPointer with invalid values */
503 dst->ptrAlign[0] = 0xDeadBeef;
504 dst->ptrAlign[1] = 0xCafeBabe;
505 /* copy the pointer's value into the CRNetworkPointer */
506 crMemcpy( dst, &src, sizeof(src) );
507
508 /* if either assertion fails, it probably means that a packer function
509 * (which returns a value) was called without setting up the writeback
510 * pointer, or something like that.
511 */
512 CRASSERT(dst->ptrAlign[0] != 0xffffffff);
513 CRASSERT(dst->ptrAlign[0] != 0xDeadBeef);
514}
Note: See TracBrowser for help on using the repository browser.

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