2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2009-2010 The FreeBSD Foundation
7 * This software was developed by Pawel Jakub Dawidek under sponsorship from
8 * the FreeBSD Foundation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/endian.h>
38 #include <bitstring.h>
54 #define PJDLOG_ASSERT(...) assert(__VA_ARGS__)
57 #define PJDLOG_ABORT(...) abort()
60 #define NV_TYPE_NONE 0
62 #define NV_TYPE_INT8 1
63 #define NV_TYPE_UINT8 2
64 #define NV_TYPE_INT16 3
65 #define NV_TYPE_UINT16 4
66 #define NV_TYPE_INT32 5
67 #define NV_TYPE_UINT32 6
68 #define NV_TYPE_INT64 7
69 #define NV_TYPE_UINT64 8
70 #define NV_TYPE_INT8_ARRAY 9
71 #define NV_TYPE_UINT8_ARRAY 10
72 #define NV_TYPE_INT16_ARRAY 11
73 #define NV_TYPE_UINT16_ARRAY 12
74 #define NV_TYPE_INT32_ARRAY 13
75 #define NV_TYPE_UINT32_ARRAY 14
76 #define NV_TYPE_INT64_ARRAY 15
77 #define NV_TYPE_UINT64_ARRAY 16
78 #define NV_TYPE_STRING 17
80 #define NV_TYPE_MASK 0x7f
81 #define NV_TYPE_FIRST NV_TYPE_INT8
82 #define NV_TYPE_LAST NV_TYPE_STRING
84 #define NV_ORDER_NETWORK 0x00
85 #define NV_ORDER_HOST 0x80
87 #define NV_ORDER_MASK 0x80
89 #define NV_MAGIC 0xaea1e
102 #define NVH_DATA(nvh) ((unsigned char *)nvh + NVH_HSIZE(nvh))
103 #define NVH_HSIZE(nvh) \
104 (sizeof(struct nvhdr) + roundup2((nvh)->nvh_namesize, 8))
105 #define NVH_DSIZE(nvh) \
106 (((nvh)->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST ? \
108 le32toh((nvh)->nvh_dsize))
109 #define NVH_SIZE(nvh) (NVH_HSIZE(nvh) + roundup2(NVH_DSIZE(nvh), 8))
111 #define NV_CHECK(nv) do { \
112 PJDLOG_ASSERT((nv) != NULL); \
113 PJDLOG_ASSERT((nv)->nv_magic == NV_MAGIC); \
116 static void nv_add(struct nv *nv, const unsigned char *value, size_t vsize,
117 int type, const char *name);
118 static void nv_addv(struct nv *nv, const unsigned char *value, size_t vsize,
119 int type, const char *namefmt, va_list nameap);
120 static struct nvhdr *nv_find(struct nv *nv, int type, const char *namefmt,
122 static void nv_swap(struct nvhdr *nvh, bool tohost);
125 * Allocate and initialize new nv structure.
126 * Return NULL in case of malloc(3) failure.
133 nv = malloc(sizeof(*nv));
136 nv->nv_ebuf = ebuf_alloc(0);
137 if (nv->nv_ebuf == NULL) {
142 nv->nv_magic = NV_MAGIC;
147 * Free the given nv structure.
150 nv_free(struct nv *nv)
159 ebuf_free(nv->nv_ebuf);
164 * Return error for the given nv structure.
167 nv_error(const struct nv *nv)
175 return (nv->nv_error);
179 * Set error for the given nv structure and return previous error.
182 nv_set_error(struct nv *nv, int error)
191 preverr = nv->nv_error;
192 nv->nv_error = error;
197 * Validate correctness of the entire nv structure and all its elements.
198 * If extrap is not NULL, store number of extra bytes at the end of the buffer.
201 nv_validate(struct nv *nv, size_t *extrap)
204 unsigned char *data, *ptr;
205 size_t dsize, size, vsize;
214 PJDLOG_ASSERT(nv->nv_error == 0);
216 /* TODO: Check that names are unique? */
219 ptr = ebuf_data(nv->nv_ebuf, &size);
222 * Zeros at the end of the buffer are acceptable.
227 * Minimum size at this point is size of nvhdr structure, one
228 * character long name plus terminating '\0'.
230 if (size < sizeof(*nvh) + 2) {
234 nvh = (struct nvhdr *)ptr;
235 if (size < NVH_HSIZE(nvh)) {
239 if (nvh->nvh_name[nvh->nvh_namesize - 1] != '\0') {
243 if (strlen(nvh->nvh_name) !=
244 (size_t)(nvh->nvh_namesize - 1)) {
248 if ((nvh->nvh_type & NV_TYPE_MASK) < NV_TYPE_FIRST ||
249 (nvh->nvh_type & NV_TYPE_MASK) > NV_TYPE_LAST) {
253 dsize = NVH_DSIZE(nvh);
258 if (size < NVH_SIZE(nvh)) {
263 switch (nvh->nvh_type & NV_TYPE_MASK) {
283 if (dsize != vsize) {
288 case NV_TYPE_INT8_ARRAY:
289 case NV_TYPE_UINT8_ARRAY:
291 case NV_TYPE_INT16_ARRAY:
292 case NV_TYPE_UINT16_ARRAY:
296 case NV_TYPE_INT32_ARRAY:
297 case NV_TYPE_UINT32_ARRAY:
301 case NV_TYPE_INT64_ARRAY:
302 case NV_TYPE_UINT64_ARRAY:
305 if ((dsize % vsize) != 0) {
311 data = NVH_DATA(nvh);
312 if (data[dsize - 1] != '\0') {
316 if (strlen((char *)data) != dsize - 1) {
322 PJDLOG_ABORT("invalid condition");
326 ptr += NVH_SIZE(nvh);
327 size -= NVH_SIZE(nvh);
331 if (nv->nv_error == 0)
332 nv->nv_error = error;
341 * Convert the given nv structure to network byte order and return ebuf
345 nv_hton(struct nv *nv)
352 PJDLOG_ASSERT(nv->nv_error == 0);
354 ptr = ebuf_data(nv->nv_ebuf, &size);
357 * Minimum size at this point is size of nvhdr structure,
358 * one character long name plus terminating '\0'.
360 PJDLOG_ASSERT(size >= sizeof(*nvh) + 2);
361 nvh = (struct nvhdr *)ptr;
362 PJDLOG_ASSERT(NVH_SIZE(nvh) <= size);
364 ptr += NVH_SIZE(nvh);
365 size -= NVH_SIZE(nvh);
368 return (nv->nv_ebuf);
372 * Create nv structure based on ebuf received from the network.
375 nv_ntoh(struct ebuf *eb)
381 PJDLOG_ASSERT(eb != NULL);
383 nv = malloc(sizeof(*nv));
388 nv->nv_magic = NV_MAGIC;
390 if (nv_validate(nv, &extra) == -1) {
398 * Remove extra zeros at the end of the buffer.
400 ebuf_del_tail(eb, extra);
405 #define NV_DEFINE_ADD(type, TYPE) \
407 nv_add_##type(struct nv *nv, type##_t value, const char *namefmt, ...) \
411 va_start(nameap, namefmt); \
412 nv_addv(nv, (unsigned char *)&value, sizeof(value), \
413 NV_TYPE_##TYPE, namefmt, nameap); \
417 NV_DEFINE_ADD(int8, INT8)
418 NV_DEFINE_ADD(uint8, UINT8)
419 NV_DEFINE_ADD(int16, INT16)
420 NV_DEFINE_ADD(uint16, UINT16)
421 NV_DEFINE_ADD(int32, INT32)
422 NV_DEFINE_ADD(uint32, UINT32)
423 NV_DEFINE_ADD(int64, INT64)
424 NV_DEFINE_ADD(uint64, UINT64)
428 #define NV_DEFINE_ADD_ARRAY(type, TYPE) \
430 nv_add_##type##_array(struct nv *nv, const type##_t *value, \
431 size_t nsize, const char *namefmt, ...) \
435 va_start(nameap, namefmt); \
436 nv_addv(nv, (const unsigned char *)value, \
437 sizeof(value[0]) * nsize, NV_TYPE_##TYPE##_ARRAY, namefmt, \
442 NV_DEFINE_ADD_ARRAY(int8, INT8)
443 NV_DEFINE_ADD_ARRAY(uint8, UINT8)
444 NV_DEFINE_ADD_ARRAY(int16, INT16)
445 NV_DEFINE_ADD_ARRAY(uint16, UINT16)
446 NV_DEFINE_ADD_ARRAY(int32, INT32)
447 NV_DEFINE_ADD_ARRAY(uint32, UINT32)
448 NV_DEFINE_ADD_ARRAY(int64, INT64)
449 NV_DEFINE_ADD_ARRAY(uint64, UINT64)
451 #undef NV_DEFINE_ADD_ARRAY
454 nv_add_string(struct nv *nv, const char *value, const char *namefmt, ...)
459 size = strlen(value) + 1;
461 va_start(nameap, namefmt);
462 nv_addv(nv, (const unsigned char *)value, size, NV_TYPE_STRING,
468 nv_add_stringf(struct nv *nv, const char *name, const char *valuefmt, ...)
472 va_start(valueap, valuefmt);
473 nv_add_stringv(nv, name, valuefmt, valueap);
478 nv_add_stringv(struct nv *nv, const char *name, const char *valuefmt,
484 size = vasprintf(&value, valuefmt, valueap);
486 if (nv->nv_error == 0)
487 nv->nv_error = ENOMEM;
491 nv_add(nv, (const unsigned char *)value, size, NV_TYPE_STRING, name);
495 #define NV_DEFINE_GET(type, TYPE) \
497 nv_get_##type(struct nv *nv, const char *namefmt, ...) \
503 va_start(nameap, namefmt); \
504 nvh = nv_find(nv, NV_TYPE_##TYPE, namefmt, nameap); \
508 PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST);\
509 PJDLOG_ASSERT(sizeof(value) == nvh->nvh_dsize); \
510 bcopy(NVH_DATA(nvh), &value, sizeof(value)); \
515 NV_DEFINE_GET(int8, INT8)
516 NV_DEFINE_GET(uint8, UINT8)
517 NV_DEFINE_GET(int16, INT16)
518 NV_DEFINE_GET(uint16, UINT16)
519 NV_DEFINE_GET(int32, INT32)
520 NV_DEFINE_GET(uint32, UINT32)
521 NV_DEFINE_GET(int64, INT64)
522 NV_DEFINE_GET(uint64, UINT64)
526 #define NV_DEFINE_GET_ARRAY(type, TYPE) \
528 nv_get_##type##_array(struct nv *nv, size_t *sizep, \
529 const char *namefmt, ...) \
534 va_start(nameap, namefmt); \
535 nvh = nv_find(nv, NV_TYPE_##TYPE##_ARRAY, namefmt, nameap); \
539 PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST);\
540 PJDLOG_ASSERT((nvh->nvh_dsize % sizeof(type##_t)) == 0); \
542 *sizep = nvh->nvh_dsize / sizeof(type##_t); \
543 return ((type##_t *)(void *)NVH_DATA(nvh)); \
546 NV_DEFINE_GET_ARRAY(int8, INT8)
547 NV_DEFINE_GET_ARRAY(uint8, UINT8)
548 NV_DEFINE_GET_ARRAY(int16, INT16)
549 NV_DEFINE_GET_ARRAY(uint16, UINT16)
550 NV_DEFINE_GET_ARRAY(int32, INT32)
551 NV_DEFINE_GET_ARRAY(uint32, UINT32)
552 NV_DEFINE_GET_ARRAY(int64, INT64)
553 NV_DEFINE_GET_ARRAY(uint64, UINT64)
555 #undef NV_DEFINE_GET_ARRAY
558 nv_get_string(struct nv *nv, const char *namefmt, ...)
564 va_start(nameap, namefmt);
565 nvh = nv_find(nv, NV_TYPE_STRING, namefmt, nameap);
569 PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST);
570 PJDLOG_ASSERT(nvh->nvh_dsize >= 1);
571 str = (char *)NVH_DATA(nvh);
572 PJDLOG_ASSERT(str[nvh->nvh_dsize - 1] == '\0');
573 PJDLOG_ASSERT(strlen(str) == nvh->nvh_dsize - 1);
578 nv_vexists(struct nv *nv, const char *namefmt, va_list nameap)
581 int snverror, serrno;
587 snverror = nv->nv_error;
589 nvh = nv_find(nv, NV_TYPE_NONE, namefmt, nameap);
592 nv->nv_error = snverror;
594 return (nvh != NULL);
598 nv_exists(struct nv *nv, const char *namefmt, ...)
603 va_start(nameap, namefmt);
604 ret = nv_vexists(nv, namefmt, nameap);
611 nv_assert(struct nv *nv, const char *namefmt, ...)
615 va_start(nameap, namefmt);
616 PJDLOG_ASSERT(nv_vexists(nv, namefmt, nameap));
621 * Dump content of the nv structure.
624 nv_dump(struct nv *nv)
627 unsigned char *data, *ptr;
632 if (nv_validate(nv, NULL) == -1) {
633 printf("error: %d\n", errno);
638 PJDLOG_ASSERT(nv->nv_error == 0);
640 ptr = ebuf_data(nv->nv_ebuf, &size);
642 PJDLOG_ASSERT(size >= sizeof(*nvh) + 2);
643 nvh = (struct nvhdr *)ptr;
644 PJDLOG_ASSERT(size >= NVH_SIZE(nvh));
645 swap = ((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_NETWORK);
646 dsize = NVH_DSIZE(nvh);
647 data = NVH_DATA(nvh);
648 printf(" %s", nvh->nvh_name);
649 switch (nvh->nvh_type & NV_TYPE_MASK) {
651 printf("(int8): %jd", (intmax_t)(*(int8_t *)data));
654 printf("(uint8): %ju", (uintmax_t)(*(uint8_t *)data));
657 printf("(int16): %jd", swap ?
658 (intmax_t)le16toh(*(int16_t *)(void *)data) :
659 (intmax_t)*(int16_t *)(void *)data);
662 printf("(uint16): %ju", swap ?
663 (uintmax_t)le16toh(*(uint16_t *)(void *)data) :
664 (uintmax_t)*(uint16_t *)(void *)data);
667 printf("(int32): %jd", swap ?
668 (intmax_t)le32toh(*(int32_t *)(void *)data) :
669 (intmax_t)*(int32_t *)(void *)data);
672 printf("(uint32): %ju", swap ?
673 (uintmax_t)le32toh(*(uint32_t *)(void *)data) :
674 (uintmax_t)*(uint32_t *)(void *)data);
677 printf("(int64): %jd", swap ?
678 (intmax_t)le64toh(*(int64_t *)(void *)data) :
679 (intmax_t)*(int64_t *)(void *)data);
682 printf("(uint64): %ju", swap ?
683 (uintmax_t)le64toh(*(uint64_t *)(void *)data) :
684 (uintmax_t)*(uint64_t *)(void *)data);
686 case NV_TYPE_INT8_ARRAY:
687 printf("(int8 array):");
688 for (ii = 0; ii < dsize; ii++)
689 printf(" %jd", (intmax_t)((int8_t *)data)[ii]);
691 case NV_TYPE_UINT8_ARRAY:
692 printf("(uint8 array):");
693 for (ii = 0; ii < dsize; ii++)
694 printf(" %ju", (uintmax_t)((uint8_t *)data)[ii]);
696 case NV_TYPE_INT16_ARRAY:
697 printf("(int16 array):");
698 for (ii = 0; ii < dsize / 2; ii++) {
699 printf(" %jd", swap ?
700 (intmax_t)le16toh(((int16_t *)(void *)data)[ii]) :
701 (intmax_t)((int16_t *)(void *)data)[ii]);
704 case NV_TYPE_UINT16_ARRAY:
705 printf("(uint16 array):");
706 for (ii = 0; ii < dsize / 2; ii++) {
707 printf(" %ju", swap ?
708 (uintmax_t)le16toh(((uint16_t *)(void *)data)[ii]) :
709 (uintmax_t)((uint16_t *)(void *)data)[ii]);
712 case NV_TYPE_INT32_ARRAY:
713 printf("(int32 array):");
714 for (ii = 0; ii < dsize / 4; ii++) {
715 printf(" %jd", swap ?
716 (intmax_t)le32toh(((int32_t *)(void *)data)[ii]) :
717 (intmax_t)((int32_t *)(void *)data)[ii]);
720 case NV_TYPE_UINT32_ARRAY:
721 printf("(uint32 array):");
722 for (ii = 0; ii < dsize / 4; ii++) {
723 printf(" %ju", swap ?
724 (uintmax_t)le32toh(((uint32_t *)(void *)data)[ii]) :
725 (uintmax_t)((uint32_t *)(void *)data)[ii]);
728 case NV_TYPE_INT64_ARRAY:
729 printf("(int64 array):");
730 for (ii = 0; ii < dsize / 8; ii++) {
731 printf(" %ju", swap ?
732 (uintmax_t)le64toh(((uint64_t *)(void *)data)[ii]) :
733 (uintmax_t)((uint64_t *)(void *)data)[ii]);
736 case NV_TYPE_UINT64_ARRAY:
737 printf("(uint64 array):");
738 for (ii = 0; ii < dsize / 8; ii++) {
739 printf(" %ju", swap ?
740 (uintmax_t)le64toh(((uint64_t *)(void *)data)[ii]) :
741 (uintmax_t)((uint64_t *)(void *)data)[ii]);
745 printf("(string): %s", (char *)data);
748 PJDLOG_ABORT("invalid condition");
751 ptr += NVH_SIZE(nvh);
752 size -= NVH_SIZE(nvh);
757 * Local routines below.
761 nv_add(struct nv *nv, const unsigned char *value, size_t vsize, int type,
764 static unsigned char align[7];
775 namesize = strlen(name) + 1;
777 nvh = malloc(sizeof(*nvh) + roundup2(namesize, 8));
779 if (nv->nv_error == 0)
780 nv->nv_error = ENOMEM;
783 nvh->nvh_type = NV_ORDER_HOST | type;
784 nvh->nvh_namesize = (uint8_t)namesize;
785 nvh->nvh_dsize = (uint32_t)vsize;
786 bcopy(name, nvh->nvh_name, namesize);
788 /* Add header first. */
789 if (ebuf_add_tail(nv->nv_ebuf, nvh, NVH_HSIZE(nvh)) == -1) {
790 PJDLOG_ASSERT(errno != 0);
791 if (nv->nv_error == 0)
792 nv->nv_error = errno;
797 /* Add the actual data. */
798 if (ebuf_add_tail(nv->nv_ebuf, value, vsize) == -1) {
799 PJDLOG_ASSERT(errno != 0);
800 if (nv->nv_error == 0)
801 nv->nv_error = errno;
804 /* Align the data (if needed). */
805 vsize = roundup2(vsize, 8) - vsize;
808 PJDLOG_ASSERT(vsize > 0 && vsize <= sizeof(align));
809 if (ebuf_add_tail(nv->nv_ebuf, align, vsize) == -1) {
810 PJDLOG_ASSERT(errno != 0);
811 if (nv->nv_error == 0)
812 nv->nv_error = errno;
818 nv_addv(struct nv *nv, const unsigned char *value, size_t vsize, int type,
819 const char *namefmt, va_list nameap)
824 namesize = vsnprintf(name, sizeof(name), namefmt, nameap);
825 PJDLOG_ASSERT(namesize > 0 && namesize < sizeof(name));
827 nv_add(nv, value, vsize, type, name);
830 static struct nvhdr *
831 nv_find(struct nv *nv, int type, const char *namefmt, va_list nameap)
836 size_t size, namesize;
845 namesize = vsnprintf(name, sizeof(name), namefmt, nameap);
846 PJDLOG_ASSERT(namesize > 0 && namesize < sizeof(name));
849 ptr = ebuf_data(nv->nv_ebuf, &size);
851 PJDLOG_ASSERT(size >= sizeof(*nvh) + 2);
852 nvh = (struct nvhdr *)ptr;
853 PJDLOG_ASSERT(size >= NVH_SIZE(nvh));
855 if (strcmp(nvh->nvh_name, name) == 0) {
856 if (type != NV_TYPE_NONE &&
857 (nvh->nvh_type & NV_TYPE_MASK) != type) {
859 if (nv->nv_error == 0)
860 nv->nv_error = EINVAL;
865 ptr += NVH_SIZE(nvh);
866 size -= NVH_SIZE(nvh);
869 if (nv->nv_error == 0)
870 nv->nv_error = ENOENT;
875 nv_swap(struct nvhdr *nvh, bool tohost)
877 unsigned char *data, *end, *p;
880 data = NVH_DATA(nvh);
882 if ((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST)
884 nvh->nvh_dsize = le32toh(nvh->nvh_dsize);
885 end = data + nvh->nvh_dsize;
886 nvh->nvh_type &= ~NV_ORDER_MASK;
887 nvh->nvh_type |= NV_ORDER_HOST;
889 if ((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_NETWORK)
891 end = data + nvh->nvh_dsize;
892 nvh->nvh_dsize = htole32(nvh->nvh_dsize);
893 nvh->nvh_type &= ~NV_ORDER_MASK;
894 nvh->nvh_type |= NV_ORDER_NETWORK;
899 switch (nvh->nvh_type & NV_TYPE_MASK) {
902 case NV_TYPE_INT8_ARRAY:
903 case NV_TYPE_UINT8_ARRAY:
907 case NV_TYPE_INT16_ARRAY:
908 case NV_TYPE_UINT16_ARRAY:
914 case NV_TYPE_INT32_ARRAY:
915 case NV_TYPE_UINT32_ARRAY:
921 case NV_TYPE_INT64_ARRAY:
922 case NV_TYPE_UINT64_ARRAY:
925 for (p = data; p < end; p += vsize) {
929 *(uint16_t *)(void *)p =
930 le16toh(*(uint16_t *)(void *)p);
933 *(uint32_t *)(void *)p =
934 le32toh(*(uint32_t *)(void *)p);
937 *(uint64_t *)(void *)p =
938 le64toh(*(uint64_t *)(void *)p);
941 PJDLOG_ABORT("invalid condition");
946 *(uint16_t *)(void *)p =
947 htole16(*(uint16_t *)(void *)p);
950 *(uint32_t *)(void *)p =
951 htole32(*(uint32_t *)(void *)p);
954 *(uint64_t *)(void *)p =
955 htole64(*(uint64_t *)(void *)p);
958 PJDLOG_ABORT("invalid condition");
966 PJDLOG_ABORT("unrecognized type");