xref: /xnu-11417.140.69/libkern/c++/OSSerialize.cpp (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions  * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
3*43a90889SApple OSS Distributions  *
4*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*43a90889SApple OSS Distributions  *
6*43a90889SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*43a90889SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*43a90889SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*43a90889SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*43a90889SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*43a90889SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*43a90889SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*43a90889SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*43a90889SApple OSS Distributions  *
15*43a90889SApple OSS Distributions  * Please obtain a copy of the License at
16*43a90889SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*43a90889SApple OSS Distributions  *
18*43a90889SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*43a90889SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*43a90889SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*43a90889SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*43a90889SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*43a90889SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*43a90889SApple OSS Distributions  * limitations under the License.
25*43a90889SApple OSS Distributions  *
26*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*43a90889SApple OSS Distributions  */
28*43a90889SApple OSS Distributions /* OSSerialize.cpp created by rsulack on Wen 25-Nov-1998 */
29*43a90889SApple OSS Distributions 
30*43a90889SApple OSS Distributions #define IOKIT_ENABLE_SHARED_PTR
31*43a90889SApple OSS Distributions 
32*43a90889SApple OSS Distributions #include <sys/cdefs.h>
33*43a90889SApple OSS Distributions #include <vm/vm_kern_xnu.h>
34*43a90889SApple OSS Distributions #include <os/hash.h>
35*43a90889SApple OSS Distributions 
36*43a90889SApple OSS Distributions #include <libkern/c++/OSContainers.h>
37*43a90889SApple OSS Distributions #include <libkern/c++/OSLib.h>
38*43a90889SApple OSS Distributions #include <libkern/c++/OSDictionary.h>
39*43a90889SApple OSS Distributions #include <libkern/c++/OSSharedPtr.h>
40*43a90889SApple OSS Distributions #include <libkern/OSSerializeBinary.h>
41*43a90889SApple OSS Distributions #include <libkern/Block.h>
42*43a90889SApple OSS Distributions #include <IOKit/IOLib.h>
43*43a90889SApple OSS Distributions 
44*43a90889SApple OSS Distributions #define super OSObject
45*43a90889SApple OSS Distributions 
46*43a90889SApple OSS Distributions OSDefineMetaClassAndStructors(OSSerialize, OSObject)
47*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 0);
48*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 1);
49*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 2);
50*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 3);
51*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 4);
52*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 5);
53*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 6);
54*43a90889SApple OSS Distributions OSMetaClassDefineReservedUnused(OSSerialize, 7);
55*43a90889SApple OSS Distributions 
56*43a90889SApple OSS Distributions static inline kmem_guard_t
OSSerialize_guard()57*43a90889SApple OSS Distributions OSSerialize_guard()
58*43a90889SApple OSS Distributions {
59*43a90889SApple OSS Distributions 	kmem_guard_t guard = {
60*43a90889SApple OSS Distributions 		.kmg_tag     = IOMemoryTag(kernel_map),
61*43a90889SApple OSS Distributions 	};
62*43a90889SApple OSS Distributions 
63*43a90889SApple OSS Distributions 	return guard;
64*43a90889SApple OSS Distributions }
65*43a90889SApple OSS Distributions 
66*43a90889SApple OSS Distributions 
67*43a90889SApple OSS Distributions char *
text() const68*43a90889SApple OSS Distributions OSSerialize::text() const
69*43a90889SApple OSS Distributions {
70*43a90889SApple OSS Distributions 	return data;
71*43a90889SApple OSS Distributions }
72*43a90889SApple OSS Distributions 
73*43a90889SApple OSS Distributions void
clearText()74*43a90889SApple OSS Distributions OSSerialize::clearText()
75*43a90889SApple OSS Distributions {
76*43a90889SApple OSS Distributions 	if (binary) {
77*43a90889SApple OSS Distributions 		length = sizeof(kOSSerializeBinarySignature);
78*43a90889SApple OSS Distributions 		bzero(&data[length], capacity - length);
79*43a90889SApple OSS Distributions 		endCollection = true;
80*43a90889SApple OSS Distributions 	} else {
81*43a90889SApple OSS Distributions 		bzero((void *)data, capacity);
82*43a90889SApple OSS Distributions 		length = 1;
83*43a90889SApple OSS Distributions 	}
84*43a90889SApple OSS Distributions 	tags->flushCollection();
85*43a90889SApple OSS Distributions }
86*43a90889SApple OSS Distributions 
87*43a90889SApple OSS Distributions bool
previouslySerialized(const OSMetaClassBase * o)88*43a90889SApple OSS Distributions OSSerialize::previouslySerialized(const OSMetaClassBase *o)
89*43a90889SApple OSS Distributions {
90*43a90889SApple OSS Distributions 	char temp[16];
91*43a90889SApple OSS Distributions 	unsigned int tagIdx;
92*43a90889SApple OSS Distributions 
93*43a90889SApple OSS Distributions 	if (binary) {
94*43a90889SApple OSS Distributions 		return binarySerialize(o);
95*43a90889SApple OSS Distributions 	}
96*43a90889SApple OSS Distributions 
97*43a90889SApple OSS Distributions 	// look it up
98*43a90889SApple OSS Distributions 	tagIdx = tags->getNextIndexOfObject(o, 0);
99*43a90889SApple OSS Distributions 
100*43a90889SApple OSS Distributions // xx-review: no error checking here for addString calls!
101*43a90889SApple OSS Distributions 	// does it exist?
102*43a90889SApple OSS Distributions 	if (tagIdx != -1U) {
103*43a90889SApple OSS Distributions 		addString("<reference IDREF=\"");
104*43a90889SApple OSS Distributions 		snprintf(temp, sizeof(temp), "%u", tagIdx);
105*43a90889SApple OSS Distributions 		addString(temp);
106*43a90889SApple OSS Distributions 		addString("\"/>");
107*43a90889SApple OSS Distributions 		return true;
108*43a90889SApple OSS Distributions 	}
109*43a90889SApple OSS Distributions 
110*43a90889SApple OSS Distributions 	// add to tag array
111*43a90889SApple OSS Distributions 	tags->setObject(o);// XXX check return
112*43a90889SApple OSS Distributions 
113*43a90889SApple OSS Distributions 	return false;
114*43a90889SApple OSS Distributions }
115*43a90889SApple OSS Distributions 
116*43a90889SApple OSS Distributions bool
addXMLStartTag(const OSMetaClassBase * o,const char * tagString)117*43a90889SApple OSS Distributions OSSerialize::addXMLStartTag(const OSMetaClassBase *o, const char *tagString)
118*43a90889SApple OSS Distributions {
119*43a90889SApple OSS Distributions 	char temp[16];
120*43a90889SApple OSS Distributions 	unsigned int tagIdx;
121*43a90889SApple OSS Distributions 
122*43a90889SApple OSS Distributions 	if (binary) {
123*43a90889SApple OSS Distributions 		printf("class %s: xml serialize\n", o->getMetaClass()->getClassName());
124*43a90889SApple OSS Distributions 		return false;
125*43a90889SApple OSS Distributions 	}
126*43a90889SApple OSS Distributions 
127*43a90889SApple OSS Distributions 	if (!addChar('<')) {
128*43a90889SApple OSS Distributions 		return false;
129*43a90889SApple OSS Distributions 	}
130*43a90889SApple OSS Distributions 	if (!addString(tagString)) {
131*43a90889SApple OSS Distributions 		return false;
132*43a90889SApple OSS Distributions 	}
133*43a90889SApple OSS Distributions 	if (!addString(" ID=\"")) {
134*43a90889SApple OSS Distributions 		return false;
135*43a90889SApple OSS Distributions 	}
136*43a90889SApple OSS Distributions 	tagIdx = tags->getNextIndexOfObject(o, 0);
137*43a90889SApple OSS Distributions 	assert(tagIdx != -1U);
138*43a90889SApple OSS Distributions 	snprintf(temp, sizeof(temp), "%u", tagIdx);
139*43a90889SApple OSS Distributions 	if (!addString(temp)) {
140*43a90889SApple OSS Distributions 		return false;
141*43a90889SApple OSS Distributions 	}
142*43a90889SApple OSS Distributions 	if (!addChar('\"')) {
143*43a90889SApple OSS Distributions 		return false;
144*43a90889SApple OSS Distributions 	}
145*43a90889SApple OSS Distributions 	if (!addChar('>')) {
146*43a90889SApple OSS Distributions 		return false;
147*43a90889SApple OSS Distributions 	}
148*43a90889SApple OSS Distributions 	return true;
149*43a90889SApple OSS Distributions }
150*43a90889SApple OSS Distributions 
151*43a90889SApple OSS Distributions bool
addXMLEndTag(const char * tagString)152*43a90889SApple OSS Distributions OSSerialize::addXMLEndTag(const char *tagString)
153*43a90889SApple OSS Distributions {
154*43a90889SApple OSS Distributions 	if (!addChar('<')) {
155*43a90889SApple OSS Distributions 		return false;
156*43a90889SApple OSS Distributions 	}
157*43a90889SApple OSS Distributions 	if (!addChar('/')) {
158*43a90889SApple OSS Distributions 		return false;
159*43a90889SApple OSS Distributions 	}
160*43a90889SApple OSS Distributions 	if (!addString(tagString)) {
161*43a90889SApple OSS Distributions 		return false;
162*43a90889SApple OSS Distributions 	}
163*43a90889SApple OSS Distributions 	if (!addChar('>')) {
164*43a90889SApple OSS Distributions 		return false;
165*43a90889SApple OSS Distributions 	}
166*43a90889SApple OSS Distributions 	return true;
167*43a90889SApple OSS Distributions }
168*43a90889SApple OSS Distributions 
169*43a90889SApple OSS Distributions bool
addChar(const char c)170*43a90889SApple OSS Distributions OSSerialize::addChar(const char c)
171*43a90889SApple OSS Distributions {
172*43a90889SApple OSS Distributions 	if (binary) {
173*43a90889SApple OSS Distributions 		printf("xml serialize\n");
174*43a90889SApple OSS Distributions 		return false;
175*43a90889SApple OSS Distributions 	}
176*43a90889SApple OSS Distributions 
177*43a90889SApple OSS Distributions 	// add char, possibly extending our capacity
178*43a90889SApple OSS Distributions 	if (length >= capacity && length >= ensureCapacity(capacity + capacityIncrement)) {
179*43a90889SApple OSS Distributions 		return false;
180*43a90889SApple OSS Distributions 	}
181*43a90889SApple OSS Distributions 
182*43a90889SApple OSS Distributions 	data[length - 1] = c;
183*43a90889SApple OSS Distributions 	length++;
184*43a90889SApple OSS Distributions 
185*43a90889SApple OSS Distributions 	return true;
186*43a90889SApple OSS Distributions }
187*43a90889SApple OSS Distributions 
188*43a90889SApple OSS Distributions bool
addString(const char * s)189*43a90889SApple OSS Distributions OSSerialize::addString(const char *s)
190*43a90889SApple OSS Distributions {
191*43a90889SApple OSS Distributions 	bool rc = false;
192*43a90889SApple OSS Distributions 
193*43a90889SApple OSS Distributions 	while (*s && (rc = addChar(*s++))) {
194*43a90889SApple OSS Distributions 		;
195*43a90889SApple OSS Distributions 	}
196*43a90889SApple OSS Distributions 
197*43a90889SApple OSS Distributions 	return rc;
198*43a90889SApple OSS Distributions }
199*43a90889SApple OSS Distributions 
200*43a90889SApple OSS Distributions bool
initWithCapacity(unsigned int inCapacity)201*43a90889SApple OSS Distributions OSSerialize::initWithCapacity(unsigned int inCapacity)
202*43a90889SApple OSS Distributions {
203*43a90889SApple OSS Distributions 	kmem_return_t kmr;
204*43a90889SApple OSS Distributions 
205*43a90889SApple OSS Distributions 	if (!super::init()) {
206*43a90889SApple OSS Distributions 		return false;
207*43a90889SApple OSS Distributions 	}
208*43a90889SApple OSS Distributions 
209*43a90889SApple OSS Distributions 	tags = OSArray::withCapacity(256);
210*43a90889SApple OSS Distributions 	if (!tags) {
211*43a90889SApple OSS Distributions 		return false;
212*43a90889SApple OSS Distributions 	}
213*43a90889SApple OSS Distributions 
214*43a90889SApple OSS Distributions 	length = 1;
215*43a90889SApple OSS Distributions 
216*43a90889SApple OSS Distributions 	if (!inCapacity) {
217*43a90889SApple OSS Distributions 		inCapacity = 1;
218*43a90889SApple OSS Distributions 	}
219*43a90889SApple OSS Distributions 	if (round_page_overflow(inCapacity, &inCapacity)) {
220*43a90889SApple OSS Distributions 		tags.reset();
221*43a90889SApple OSS Distributions 		return false;
222*43a90889SApple OSS Distributions 	}
223*43a90889SApple OSS Distributions 
224*43a90889SApple OSS Distributions 	capacityIncrement = inCapacity;
225*43a90889SApple OSS Distributions 
226*43a90889SApple OSS Distributions 	// allocate from the kernel map so that we can safely map this data
227*43a90889SApple OSS Distributions 	// into user space (the primary use of the OSSerialize object)
228*43a90889SApple OSS Distributions 
229*43a90889SApple OSS Distributions 	kmr = kmem_alloc_guard(kernel_map, inCapacity, /* mask */ 0,
230*43a90889SApple OSS Distributions 	    (kma_flags_t)(KMA_ZERO | KMA_DATA), OSSerialize_guard());
231*43a90889SApple OSS Distributions 
232*43a90889SApple OSS Distributions 	if (kmr.kmr_return == KERN_SUCCESS) {
233*43a90889SApple OSS Distributions 		data = (char *)kmr.kmr_ptr;
234*43a90889SApple OSS Distributions 		capacity = inCapacity;
235*43a90889SApple OSS Distributions 		OSCONTAINER_ACCUMSIZE(capacity);
236*43a90889SApple OSS Distributions 		return true;
237*43a90889SApple OSS Distributions 	}
238*43a90889SApple OSS Distributions 
239*43a90889SApple OSS Distributions 	capacity = 0;
240*43a90889SApple OSS Distributions 	return false;
241*43a90889SApple OSS Distributions }
242*43a90889SApple OSS Distributions 
243*43a90889SApple OSS Distributions OSSharedPtr<OSSerialize>
withCapacity(unsigned int inCapacity)244*43a90889SApple OSS Distributions OSSerialize::withCapacity(unsigned int inCapacity)
245*43a90889SApple OSS Distributions {
246*43a90889SApple OSS Distributions 	OSSharedPtr<OSSerialize> me = OSMakeShared<OSSerialize>();
247*43a90889SApple OSS Distributions 
248*43a90889SApple OSS Distributions 	if (me && !me->initWithCapacity(inCapacity)) {
249*43a90889SApple OSS Distributions 		return nullptr;
250*43a90889SApple OSS Distributions 	}
251*43a90889SApple OSS Distributions 
252*43a90889SApple OSS Distributions 	return me;
253*43a90889SApple OSS Distributions }
254*43a90889SApple OSS Distributions 
255*43a90889SApple OSS Distributions unsigned int
getLength() const256*43a90889SApple OSS Distributions OSSerialize::getLength() const
257*43a90889SApple OSS Distributions {
258*43a90889SApple OSS Distributions 	return length;
259*43a90889SApple OSS Distributions }
260*43a90889SApple OSS Distributions unsigned int
getCapacity() const261*43a90889SApple OSS Distributions OSSerialize::getCapacity() const
262*43a90889SApple OSS Distributions {
263*43a90889SApple OSS Distributions 	return capacity;
264*43a90889SApple OSS Distributions }
265*43a90889SApple OSS Distributions unsigned int
getCapacityIncrement() const266*43a90889SApple OSS Distributions OSSerialize::getCapacityIncrement() const
267*43a90889SApple OSS Distributions {
268*43a90889SApple OSS Distributions 	return capacityIncrement;
269*43a90889SApple OSS Distributions }
270*43a90889SApple OSS Distributions unsigned int
setCapacityIncrement(unsigned int increment)271*43a90889SApple OSS Distributions OSSerialize::setCapacityIncrement(unsigned int increment)
272*43a90889SApple OSS Distributions {
273*43a90889SApple OSS Distributions 	capacityIncrement = (increment)? increment : 256;
274*43a90889SApple OSS Distributions 	return capacityIncrement;
275*43a90889SApple OSS Distributions }
276*43a90889SApple OSS Distributions 
277*43a90889SApple OSS Distributions unsigned int
ensureCapacity(unsigned int newCapacity)278*43a90889SApple OSS Distributions OSSerialize::ensureCapacity(unsigned int newCapacity)
279*43a90889SApple OSS Distributions {
280*43a90889SApple OSS Distributions 	kmem_return_t kmr;
281*43a90889SApple OSS Distributions 
282*43a90889SApple OSS Distributions 	if (newCapacity <= capacity) {
283*43a90889SApple OSS Distributions 		return capacity;
284*43a90889SApple OSS Distributions 	}
285*43a90889SApple OSS Distributions 
286*43a90889SApple OSS Distributions 	if (round_page_overflow(newCapacity, &newCapacity)) {
287*43a90889SApple OSS Distributions 		return capacity;
288*43a90889SApple OSS Distributions 	}
289*43a90889SApple OSS Distributions 
290*43a90889SApple OSS Distributions 	kmr = kmem_realloc_guard(kernel_map, (vm_offset_t)data, capacity,
291*43a90889SApple OSS Distributions 	    newCapacity, (kmr_flags_t)(KMR_ZERO | KMR_DATA | KMR_FREEOLD),
292*43a90889SApple OSS Distributions 	    OSSerialize_guard());
293*43a90889SApple OSS Distributions 
294*43a90889SApple OSS Distributions 	if (kmr.kmr_return == KERN_SUCCESS) {
295*43a90889SApple OSS Distributions 		size_t delta = 0;
296*43a90889SApple OSS Distributions 
297*43a90889SApple OSS Distributions 		data     = (char *)kmr.kmr_ptr;
298*43a90889SApple OSS Distributions 		delta   -= capacity;
299*43a90889SApple OSS Distributions 		capacity = newCapacity;
300*43a90889SApple OSS Distributions 		delta   += capacity;
301*43a90889SApple OSS Distributions 		OSCONTAINER_ACCUMSIZE(delta);
302*43a90889SApple OSS Distributions 	}
303*43a90889SApple OSS Distributions 
304*43a90889SApple OSS Distributions 	return capacity;
305*43a90889SApple OSS Distributions }
306*43a90889SApple OSS Distributions 
307*43a90889SApple OSS Distributions void
free()308*43a90889SApple OSS Distributions OSSerialize::free()
309*43a90889SApple OSS Distributions {
310*43a90889SApple OSS Distributions 	if (capacity) {
311*43a90889SApple OSS Distributions 		kmem_free_guard(kernel_map, (vm_offset_t)data, capacity,
312*43a90889SApple OSS Distributions 		    KMF_NONE, OSSerialize_guard());
313*43a90889SApple OSS Distributions 		OSCONTAINER_ACCUMSIZE( -((size_t)capacity));
314*43a90889SApple OSS Distributions 		data = nullptr;
315*43a90889SApple OSS Distributions 		capacity = 0;
316*43a90889SApple OSS Distributions 	}
317*43a90889SApple OSS Distributions 	super::free();
318*43a90889SApple OSS Distributions }
319*43a90889SApple OSS Distributions 
320*43a90889SApple OSS Distributions 
OSDefineMetaClassAndStructors(OSSerializer,OSObject)321*43a90889SApple OSS Distributions OSDefineMetaClassAndStructors(OSSerializer, OSObject)
322*43a90889SApple OSS Distributions 
323*43a90889SApple OSS Distributions OSSharedPtr<OSSerializer>
324*43a90889SApple OSS Distributions OSSerializer::forTarget( void * target,
325*43a90889SApple OSS Distributions     OSSerializerCallback callback, void * ref )
326*43a90889SApple OSS Distributions {
327*43a90889SApple OSS Distributions 	OSSharedPtr<OSSerializer> thing = OSMakeShared<OSSerializer>();
328*43a90889SApple OSS Distributions 
329*43a90889SApple OSS Distributions 	if (thing && !thing->init()) {
330*43a90889SApple OSS Distributions 		thing.reset();
331*43a90889SApple OSS Distributions 	}
332*43a90889SApple OSS Distributions 
333*43a90889SApple OSS Distributions 	if (thing) {
334*43a90889SApple OSS Distributions 		thing->target   = target;
335*43a90889SApple OSS Distributions 		thing->ref      = ref;
336*43a90889SApple OSS Distributions 		thing->callback = callback;
337*43a90889SApple OSS Distributions 	}
338*43a90889SApple OSS Distributions 	return thing;
339*43a90889SApple OSS Distributions }
340*43a90889SApple OSS Distributions 
341*43a90889SApple OSS Distributions bool
callbackToBlock(void * target __unused,void * ref,OSSerialize * serializer)342*43a90889SApple OSS Distributions OSSerializer::callbackToBlock(void * target __unused, void * ref,
343*43a90889SApple OSS Distributions     OSSerialize * serializer)
344*43a90889SApple OSS Distributions {
345*43a90889SApple OSS Distributions 	return ((OSSerializerBlock)ref)(serializer);
346*43a90889SApple OSS Distributions }
347*43a90889SApple OSS Distributions 
348*43a90889SApple OSS Distributions OSSharedPtr<OSSerializer>
withBlock(OSSerializerBlock callback)349*43a90889SApple OSS Distributions OSSerializer::withBlock(
350*43a90889SApple OSS Distributions 	OSSerializerBlock callback)
351*43a90889SApple OSS Distributions {
352*43a90889SApple OSS Distributions 	OSSharedPtr<OSSerializer> serializer;
353*43a90889SApple OSS Distributions 	OSSerializerBlock block;
354*43a90889SApple OSS Distributions 
355*43a90889SApple OSS Distributions 	block = Block_copy(callback);
356*43a90889SApple OSS Distributions 	if (!block) {
357*43a90889SApple OSS Distributions 		return NULL;
358*43a90889SApple OSS Distributions 	}
359*43a90889SApple OSS Distributions 
360*43a90889SApple OSS Distributions 	serializer = (OSSerializer::forTarget(NULL, &OSSerializer::callbackToBlock, block));
361*43a90889SApple OSS Distributions 
362*43a90889SApple OSS Distributions 	if (!serializer) {
363*43a90889SApple OSS Distributions 		Block_release(block);
364*43a90889SApple OSS Distributions 	}
365*43a90889SApple OSS Distributions 
366*43a90889SApple OSS Distributions 	return serializer;
367*43a90889SApple OSS Distributions }
368*43a90889SApple OSS Distributions 
369*43a90889SApple OSS Distributions void
free(void)370*43a90889SApple OSS Distributions OSSerializer::free(void)
371*43a90889SApple OSS Distributions {
372*43a90889SApple OSS Distributions 	if (callback == &callbackToBlock) {
373*43a90889SApple OSS Distributions 		Block_release(ref);
374*43a90889SApple OSS Distributions 	}
375*43a90889SApple OSS Distributions 
376*43a90889SApple OSS Distributions 	super::free();
377*43a90889SApple OSS Distributions }
378*43a90889SApple OSS Distributions 
379*43a90889SApple OSS Distributions bool
serialize(OSSerialize * s) const380*43a90889SApple OSS Distributions OSSerializer::serialize( OSSerialize * s ) const
381*43a90889SApple OSS Distributions {
382*43a90889SApple OSS Distributions 	return (*callback)(target, ref, s);
383*43a90889SApple OSS Distributions }
384