1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25/*
26 * Copyright (c) 2011 by Delphix. All rights reserved.
27 */
28/*
29 * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
30 */
31
32/*
33 * DTrace print() action
34 *
35 * This file contains the post-processing logic for the print() action.  The
36 * print action behaves identically to trace() in that it generates a
37 * DTRACEACT_DIFEXPR action, but the action argument field refers to a CTF type
38 * string stored in the DOF string table (similar to printf formats).  We
39 * take the result of the trace action and post-process it in the fashion of
40 * MDB's ::print dcmd.
41 *
42 * This implementation differs from MDB's in the following ways:
43 *
44 * 	- We do not expose any options or flags.  The behavior of print() is
45 *	  equivalent to "::print -tn".
46 *
47 * 	- MDB will display "holes" in structures (unused padding between
48 *	  members).
49 *
50 * 	- When printing arrays of structures, MDB will leave a trailing ','
51 *	  after the last element.
52 *
53 *	- MDB will print time_t types as date and time.
54 *
55 *	- MDB will detect when an enum is actually the OR of several flags,
56 *	  and print it out with the constituent flags separated.
57 *
58 *	- For large arrays, MDB will print the first few members and then
59 *	  print a "..." continuation line.
60 *
61 *	- MDB will break and wrap arrays at 80 columns.
62 *
63 *	- MDB prints out floats and doubles by hand, as it must run in kmdb
64 *	  context.  We're able to leverage the printf() format strings,
65 *	  but the result is a slightly different format.
66 */
67
68#include <sys/sysmacros.h>
69#include <strings.h>
70#include <stdlib.h>
71#include <alloca.h>
72#include <assert.h>
73#include <ctype.h>
74#include <errno.h>
75#include <limits.h>
76#include <sys/socket.h>
77#include <netdb.h>
78#include <netinet/in.h>
79#include <arpa/inet.h>
80
81#include <dt_module.h>
82#include <dt_printf.h>
83#include <dt_string.h>
84#include <dt_impl.h>
85
86/* determines whether the given integer CTF encoding is a character */
87#define	CTF_IS_CHAR(e) \
88	(((e).cte_format & (CTF_INT_CHAR | CTF_INT_SIGNED)) == \
89	(CTF_INT_CHAR | CTF_INT_SIGNED) && (e).cte_bits == NBBY)
90/* determines whether the given CTF kind is a struct or union */
91#define	CTF_IS_STRUCTLIKE(k) \
92	((k) == CTF_K_STRUCT || (k) == CTF_K_UNION)
93
94/*
95 * Print structure passed down recursively through printing algorithm.
96 */
97typedef struct dt_printarg {
98	dtrace_hdl_t	*pa_dtp;	/* libdtrace handle */
99	caddr_t		pa_addr;	/* base address of trace data */
100	ctf_file_t	*pa_ctfp;	/* CTF container */
101	int		pa_depth;	/* member depth */
102	int		pa_nest;	/* nested array depth */
103	FILE		*pa_file;	/* output file */
104} dt_printarg_t;
105
106static int dt_print_member(const char *, ctf_id_t, ulong_t, int, void *);
107
108/*
109 * Safe version of ctf_type_name() that will fall back to just "<ctfid>" if it
110 * can't resolve the type.
111 */
112static void
113dt_print_type_name(ctf_file_t *ctfp, ctf_id_t id, char *buf, size_t buflen)
114{
115	if (ctf_type_name(ctfp, id, buf, buflen) == NULL)
116		(void) snprintf(buf, buflen, "<%ld>", id);
117}
118
119/*
120 * Print any necessary trailing braces for structures or unions.  We don't get
121 * invoked when a struct or union ends, so we infer the need to print braces
122 * based on the depth the last time we printed something and the new depth.
123 */
124static void
125dt_print_trailing_braces(dt_printarg_t *pap, int depth)
126{
127	int d;
128
129	for (d = pap->pa_depth; d > depth; d--) {
130		(void) fprintf(pap->pa_file, "%*s}%s",
131		    (d + pap->pa_nest - 1) * 4, "",
132		    d == depth + 1 ? "" : "\n");
133	}
134}
135
136/*
137 * Print the appropriate amount of indentation given the current depth and
138 * array nesting.
139 */
140static void
141dt_print_indent(dt_printarg_t *pap)
142{
143	(void) fprintf(pap->pa_file, "%*s",
144	    (pap->pa_depth + pap->pa_nest) * 4, "");
145}
146
147/*
148 * Print a bitfield.  It's worth noting that the D compiler support for
149 * bitfields is currently broken; printing "D`user_desc_t" (pulled in by the
150 * various D provider files) will produce incorrect results compared to
151 * "genunix`user_desc_t".
152 */
153static void
154print_bitfield(dt_printarg_t *pap, ulong_t off, ctf_encoding_t *ep)
155{
156	FILE *fp = pap->pa_file;
157	caddr_t addr = pap->pa_addr + off / NBBY;
158	uint64_t mask = (1ULL << ep->cte_bits) - 1;
159	uint64_t value = 0;
160	size_t size = (ep->cte_bits + (NBBY - 1)) / NBBY;
161	uint8_t *buf = (uint8_t *)&value;
162	uint8_t shift;
163
164	/*
165	 * On big-endian machines, we need to adjust the buf pointer to refer
166	 * to the lowest 'size' bytes in 'value', and we need to shift based on
167	 * the offset from the end of the data, not the offset of the start.
168	 */
169#if BYTE_ORDER == _BIG_ENDIAN
170	buf += sizeof (value) - size;
171	off += ep->cte_bits;
172#endif
173	bcopy(addr, buf, size);
174	shift = off % NBBY;
175
176	/*
177	 * Offsets are counted from opposite ends on little- and
178	 * big-endian machines.
179	 */
180#if BYTE_ORDER == _BIG_ENDIAN
181	shift = NBBY - shift;
182#endif
183
184	/*
185	 * If the bits we want do not begin on a byte boundary, shift the data
186	 * right so that the value is in the lowest 'cte_bits' of 'value'.
187	 */
188	if (off % NBBY != 0)
189		value >>= shift;
190	value &= mask;
191
192	(void) fprintf(fp, "%#llx", (u_longlong_t)value);
193}
194
195/*
196 * Dump the contents of memory as a fixed-size integer in hex.
197 */
198static void
199dt_print_hex(FILE *fp, caddr_t addr, size_t size)
200{
201	switch (size) {
202	case sizeof (uint8_t):
203		(void) fprintf(fp, "%#x", *(uint8_t *)addr);
204		break;
205	case sizeof (uint16_t):
206		/* LINTED - alignment */
207		(void) fprintf(fp, "%#x", *(uint16_t *)addr);
208		break;
209	case sizeof (uint32_t):
210		/* LINTED - alignment */
211		(void) fprintf(fp, "%#x", *(uint32_t *)addr);
212		break;
213	case sizeof (uint64_t):
214		(void) fprintf(fp, "%#llx",
215		    /* LINTED - alignment */
216		    (unsigned long long)*(uint64_t *)addr);
217		break;
218	default:
219		(void) fprintf(fp, "<invalid size %u>", (uint_t)size);
220	}
221}
222
223/*
224 * Print an integer type.  Before dumping the contents via dt_print_hex(), we
225 * first check the encoding to see if it's part of a bitfield or a character.
226 */
227static void
228dt_print_int(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
229{
230	FILE *fp = pap->pa_file;
231	ctf_file_t *ctfp = pap->pa_ctfp;
232	ctf_encoding_t e;
233	size_t size;
234	caddr_t addr = pap->pa_addr + off / NBBY;
235
236	if (ctf_type_encoding(ctfp, base, &e) == CTF_ERR) {
237		(void) fprintf(fp, "<unknown encoding>");
238		return;
239	}
240
241	/*
242	 * This comes from MDB - it's not clear under what circumstances this
243	 * would be found.
244	 */
245	if (e.cte_format & CTF_INT_VARARGS) {
246		(void) fprintf(fp, "...");
247		return;
248	}
249
250	/*
251	 * We print this as a bitfield if the bit encoding indicates it's not
252	 * an even power of two byte size, or is larger than 8 bytes.
253	 */
254	size = e.cte_bits / NBBY;
255	if (size > 8 || (e.cte_bits % NBBY) != 0 || (size & (size - 1)) != 0) {
256		print_bitfield(pap, off, &e);
257		return;
258	}
259
260	/*
261	 * If this is a character, print it out as such.
262	 */
263	if (CTF_IS_CHAR(e)) {
264		char c = *(char *)addr;
265		if (isprint(c))
266			(void) fprintf(fp, "'%c'", c);
267		else if (c == 0)
268			(void) fprintf(fp, "'\\0'");
269		else
270			(void) fprintf(fp, "'\\%03o'", c);
271		return;
272	}
273
274	dt_print_hex(fp, addr, size);
275}
276
277/*
278 * Print a floating point (float, double, long double) value.
279 */
280/* ARGSUSED */
281static void
282dt_print_float(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
283{
284	FILE *fp = pap->pa_file;
285	ctf_file_t *ctfp = pap->pa_ctfp;
286	ctf_encoding_t e;
287	caddr_t addr = pap->pa_addr + off / NBBY;
288
289	if (ctf_type_encoding(ctfp, base, &e) == 0) {
290		if (e.cte_format == CTF_FP_SINGLE &&
291		    e.cte_bits == sizeof (float) * NBBY) {
292			/* LINTED - alignment */
293			(void) fprintf(fp, "%+.7e", *((float *)addr));
294		} else if (e.cte_format == CTF_FP_DOUBLE &&
295		    e.cte_bits == sizeof (double) * NBBY) {
296			/* LINTED - alignment */
297			(void) fprintf(fp, "%+.7e", *((double *)addr));
298		} else if (e.cte_format == CTF_FP_LDOUBLE &&
299		    e.cte_bits == sizeof (long double) * NBBY) {
300			/* LINTED - alignment */
301			(void) fprintf(fp, "%+.16LE", *((long double *)addr));
302		} else {
303			(void) fprintf(fp, "<unknown encoding>");
304		}
305	}
306}
307
308/*
309 * A pointer is generally printed as a fixed-size integer.  If we have a
310 * function pointer, we try to look up its name.
311 */
312static void
313dt_print_ptr(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
314{
315	FILE *fp = pap->pa_file;
316	ctf_file_t *ctfp = pap->pa_ctfp;
317	caddr_t addr = pap->pa_addr + off / NBBY;
318	size_t size = ctf_type_size(ctfp, base);
319	ctf_id_t bid = ctf_type_reference(ctfp, base);
320	uint64_t pc;
321	dtrace_syminfo_t dts;
322	GElf_Sym sym;
323
324	if (bid == CTF_ERR || ctf_type_kind(ctfp, bid) != CTF_K_FUNCTION) {
325		dt_print_hex(fp, addr, size);
326	} else {
327		/* LINTED - alignment */
328		pc = *((uint64_t *)addr);
329		if (dtrace_lookup_by_addr(pap->pa_dtp, pc, &sym, &dts) != 0) {
330			dt_print_hex(fp, addr, size);
331		} else {
332			(void) fprintf(fp, "%s`%s", dts.dts_object,
333			    dts.dts_name);
334		}
335	}
336}
337
338/*
339 * Print out an array.  This is somewhat complex, as we must manually visit
340 * each member, and recursively invoke ctf_type_visit() for each member.  If
341 * the members are non-structs, then we print them out directly:
342 *
343 * 	[ 0x14, 0x2e, 0 ]
344 *
345 * If they are structs, then we print out the necessary leading and trailing
346 * braces, to end up with:
347 *
348 *	[
349 *	    type {
350 *	    ...
351 *	    },
352 *	    type {
353 *	    ...
354 *	    }
355 *	]
356 *
357 * We also use a heuristic to detect whether the array looks like a character
358 * array.  If the encoding indicates it's a character, and we have all
359 * printable characters followed by a null byte, then we display it as a
360 * string:
361 *
362 *	[ "string" ]
363 */
364static void
365dt_print_array(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
366{
367	FILE *fp = pap->pa_file;
368	ctf_file_t *ctfp = pap->pa_ctfp;
369	caddr_t addr = pap->pa_addr + off / NBBY;
370	ctf_arinfo_t car;
371	ssize_t eltsize;
372	ctf_encoding_t e;
373	int i;
374	boolean_t isstring;
375	int kind;
376	ctf_id_t rtype;
377
378	if (ctf_array_info(ctfp, base, &car) == CTF_ERR) {
379		(void) fprintf(fp, "%p", (void *)addr);
380		return;
381	}
382
383	if ((eltsize = ctf_type_size(ctfp, car.ctr_contents)) < 0 ||
384	    (rtype = ctf_type_resolve(ctfp, car.ctr_contents)) == CTF_ERR ||
385	    (kind = ctf_type_kind(ctfp, rtype)) == CTF_ERR) {
386		(void) fprintf(fp, "<invalid type %lu>", car.ctr_contents);
387		return;
388	}
389
390	/* see if this looks like a string */
391	isstring = B_FALSE;
392	if (kind == CTF_K_INTEGER &&
393	    ctf_type_encoding(ctfp, rtype, &e) != CTF_ERR && CTF_IS_CHAR(e)) {
394		char c;
395		for (i = 0; i < car.ctr_nelems; i++) {
396			c = *((char *)addr + eltsize * i);
397			if (!isprint(c) || c == '\0')
398				break;
399		}
400
401		if (i != car.ctr_nelems && c == '\0')
402			isstring = B_TRUE;
403	}
404
405	/*
406	 * As a slight aesthetic optimization, if we are a top-level type, then
407	 * don't bother printing out the brackets.  This lets print("foo") look
408	 * like:
409	 *
410	 * 	string "foo"
411	 *
412	 * As D will internally represent this as a char[256] array.
413	 */
414	if (!isstring || pap->pa_depth != 0)
415		(void) fprintf(fp, "[ ");
416
417	if (isstring)
418		(void) fprintf(fp, "\"");
419
420	for (i = 0; i < car.ctr_nelems; i++) {
421		if (isstring) {
422			char c = *((char *)addr + eltsize * i);
423			if (c == '\0')
424				break;
425			(void) fprintf(fp, "%c", c);
426		} else {
427			/*
428			 * Recursively invoke ctf_type_visit() on each member.
429			 * We setup a new printarg struct with 'pa_nest' set to
430			 * indicate that we are within a nested array.
431			 */
432			dt_printarg_t pa = *pap;
433			pa.pa_nest += pap->pa_depth + 1;
434			pa.pa_depth = 0;
435			pa.pa_addr = addr + eltsize * i;
436			(void) ctf_type_visit(ctfp, car.ctr_contents,
437			    dt_print_member, &pa);
438
439			dt_print_trailing_braces(&pa, 0);
440			if (i != car.ctr_nelems - 1)
441				(void) fprintf(fp, ", ");
442			else if (CTF_IS_STRUCTLIKE(kind))
443				(void) fprintf(fp, "\n");
444		}
445	}
446
447	if (isstring)
448		(void) fprintf(fp, "\"");
449
450	if (!isstring || pap->pa_depth != 0) {
451		if (CTF_IS_STRUCTLIKE(kind))
452			dt_print_indent(pap);
453		else
454			(void) fprintf(fp, " ");
455		(void) fprintf(fp, "]");
456	}
457}
458
459/*
460 * This isued by both structs and unions to print the leading brace.
461 */
462/* ARGSUSED */
463static void
464dt_print_structlike(ctf_id_t id, ulong_t off, dt_printarg_t *pap)
465{
466	(void) fprintf(pap->pa_file, "{");
467}
468
469/*
470 * For enums, we try to print the enum name, and fall back to the value if it
471 * can't be determined.  We do not do any fancy flag processing like mdb.
472 */
473/* ARGSUSED */
474static void
475dt_print_enum(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
476{
477	FILE *fp = pap->pa_file;
478	ctf_file_t *ctfp = pap->pa_ctfp;
479	const char *ename;
480	ssize_t size;
481	caddr_t addr = pap->pa_addr + off / NBBY;
482	int value = 0;
483
484	/*
485	 * The C standard says that an enum will be at most the sizeof (int).
486	 * But if all the values are less than that, the compiler can use a
487	 * smaller size. Thanks standards.
488	 */
489	size = ctf_type_size(ctfp, base);
490	switch (size) {
491	case sizeof (uint8_t):
492		value = *(uint8_t *)addr;
493		break;
494	case sizeof (uint16_t):
495		value = *(uint16_t *)addr;
496		break;
497	case sizeof (int32_t):
498		value = *(int32_t *)addr;
499		break;
500	default:
501		(void) fprintf(fp, "<invalid enum size %u>", (uint_t)size);
502		return;
503	}
504
505	if ((ename = ctf_enum_name(ctfp, base, value)) != NULL)
506		(void) fprintf(fp, "%s", ename);
507	else
508		(void) fprintf(fp, "%d", value);
509}
510
511/*
512 * Forward declaration.  There's not much to do here without the complete
513 * type information, so just print out this fact and drive on.
514 */
515/* ARGSUSED */
516static void
517dt_print_tag(ctf_id_t base, ulong_t off, dt_printarg_t *pap)
518{
519	(void) fprintf(pap->pa_file, "<forward decl>");
520}
521
522typedef void dt_printarg_f(ctf_id_t, ulong_t, dt_printarg_t *);
523
524static dt_printarg_f *const dt_printfuncs[] = {
525	dt_print_int,		/* CTF_K_INTEGER */
526	dt_print_float,		/* CTF_K_FLOAT */
527	dt_print_ptr,		/* CTF_K_POINTER */
528	dt_print_array,		/* CTF_K_ARRAY */
529	dt_print_ptr,		/* CTF_K_FUNCTION */
530	dt_print_structlike,	/* CTF_K_STRUCT */
531	dt_print_structlike,	/* CTF_K_UNION */
532	dt_print_enum,		/* CTF_K_ENUM */
533	dt_print_tag		/* CTF_K_FORWARD */
534};
535
536/*
537 * Print one member of a structure.  This callback is invoked from
538 * ctf_type_visit() recursively.
539 */
540static int
541dt_print_member(const char *name, ctf_id_t id, ulong_t off, int depth,
542    void *data)
543{
544	char type[DT_TYPE_NAMELEN];
545	int kind;
546	dt_printarg_t *pap = data;
547	FILE *fp = pap->pa_file;
548	ctf_file_t *ctfp = pap->pa_ctfp;
549	boolean_t arraymember;
550	boolean_t brief;
551	ctf_encoding_t e;
552	ctf_id_t rtype;
553
554	dt_print_trailing_braces(pap, depth);
555	/*
556	 * dt_print_trailing_braces() doesn't include the trailing newline; add
557	 * it here if necessary.
558	 */
559	if (depth < pap->pa_depth)
560		(void) fprintf(fp, "\n");
561	pap->pa_depth = depth;
562
563	if ((rtype = ctf_type_resolve(ctfp, id)) == CTF_ERR ||
564	    (kind = ctf_type_kind(ctfp, rtype)) == CTF_ERR ||
565	    kind < CTF_K_INTEGER || kind > CTF_K_FORWARD) {
566		dt_print_indent(pap);
567		(void) fprintf(fp, "%s = <invalid type %lu>", name, id);
568		return (0);
569	}
570
571	dt_print_type_name(ctfp, id, type, sizeof (type));
572
573	arraymember = (pap->pa_nest != 0 && depth == 0);
574	brief = (arraymember && !CTF_IS_STRUCTLIKE(kind));
575
576	if (!brief) {
577		/*
578		 * If this is a direct array member and a struct (otherwise
579		 * brief would be true), then print a trailing newline, as the
580		 * array printing code doesn't include it because it might be a
581		 * simple type.
582		 */
583		if (arraymember)
584			(void) fprintf(fp, "\n");
585		dt_print_indent(pap);
586
587		/* always print the type */
588		(void) fprintf(fp, "%s", type);
589		if (name[0] != '\0') {
590			/*
591			 * For aesthetics, we don't include a space between the
592			 * type name and member name if the type is a pointer.
593			 * This will give us "void *foo =" instead of "void *
594			 * foo =".  Unions also have the odd behavior that the
595			 * type name is returned as "union ", with a trailing
596			 * space, so we also avoid printing a space if the type
597			 * name already ends with a space.
598			 */
599			if (type[strlen(type) - 1] != '*' &&
600			    type[strlen(type) -1] != ' ') {
601				(void) fprintf(fp, " ");
602			}
603			(void) fprintf(fp, "%s", name);
604
605			/*
606			 * If this looks like a bitfield, or is an integer not
607			 * aligned on a byte boundary, print the number of
608			 * bits after the name.
609			 */
610			if (kind == CTF_K_INTEGER &&
611			    ctf_type_encoding(ctfp, id, &e) == 0) {
612				ulong_t bits = e.cte_bits;
613				ulong_t size = bits / NBBY;
614
615				if (bits % NBBY != 0 ||
616				    off % NBBY != 0 ||
617				    size > 8 ||
618				    size != ctf_type_size(ctfp, id)) {
619					(void) fprintf(fp, " :%lu", bits);
620				}
621			}
622
623			(void) fprintf(fp, " =");
624		}
625		(void) fprintf(fp, " ");
626	}
627
628	dt_printfuncs[kind - 1](rtype, off, pap);
629
630	/* direct simple array members are not separated by newlines */
631	if (!brief)
632		(void) fprintf(fp, "\n");
633
634	return (0);
635}
636
637/*
638 * Main print function invoked by dt_consume_cpu().
639 */
640int
641dtrace_print(dtrace_hdl_t *dtp, FILE *fp, const char *typename,
642    caddr_t addr, size_t len)
643{
644	const char *s;
645	char *object;
646	dt_printarg_t pa;
647	ctf_id_t id;
648	dt_module_t *dmp;
649	ctf_file_t *ctfp;
650	int libid;
651
652	/*
653	 * Split the fully-qualified type ID (module`id).  This should
654	 * always be the format, but if for some reason we don't find the
655	 * expected value, return 0 to fall back to the generic trace()
656	 * behavior. In the case of userland CTF modules this will actually be
657	 * of the format (module`lib`id). This is due to the fact that those
658	 * modules have multiple CTF containers which `lib` identifies.
659	 */
660	for (s = typename; *s != '\0' && *s != '`'; s++)
661		;
662
663	if (*s != '`')
664		return (0);
665
666	object = alloca(s - typename + 1);
667	bcopy(typename, object, s - typename);
668	object[s - typename] = '\0';
669	dmp = dt_module_lookup_by_name(dtp, object);
670	if (dmp == NULL)
671		return (0);
672
673	if (dmp->dm_pid != 0) {
674		libid = atoi(s + 1);
675		s = strchr(s + 1, '`');
676		if (s == NULL || libid > dmp->dm_nctflibs)
677			return (0);
678		ctfp = dmp->dm_libctfp[libid];
679	} else {
680		ctfp = dt_module_getctf(dtp, dmp);
681	}
682
683	id = atoi(s + 1);
684
685	/*
686	 * Try to get the CTF kind for this id.  If something has gone horribly
687	 * wrong and we can't resolve the ID, bail out and let trace() do the
688	 * work.
689	 */
690	if (ctfp == NULL || ctf_type_kind(ctfp, id) == CTF_ERR)
691		return (0);
692
693	/* setup the print structure and kick off the main print routine */
694	pa.pa_dtp = dtp;
695	pa.pa_addr = addr;
696	pa.pa_ctfp = ctfp;
697	pa.pa_nest = 0;
698	pa.pa_depth = 0;
699	pa.pa_file = fp;
700	(void) ctf_type_visit(pa.pa_ctfp, id, dt_print_member, &pa);
701
702	dt_print_trailing_braces(&pa, 0);
703
704	return (len);
705}
706