17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc. 247c478bd9Sstevel@tonic-gate * All rights reserved. 25*e492095eSRichard PALO * Copyright 2015 PALO, Richard. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate #include <assert.h> 287c478bd9Sstevel@tonic-gate #include <stdio.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <ctype.h> 317c478bd9Sstevel@tonic-gate #include <libintl.h> 327c478bd9Sstevel@tonic-gate #include <strings.h> 337c478bd9Sstevel@tonic-gate #include "iconv_tm.h" 347c478bd9Sstevel@tonic-gate #include "itmcomp.h" 357c478bd9Sstevel@tonic-gate #include "itm_util.h" 367c478bd9Sstevel@tonic-gate #include "hash.h" 377c478bd9Sstevel@tonic-gate #include "maptype.h" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate static size_t map_table_resultlen(itmc_map_t *); 417c478bd9Sstevel@tonic-gate static int data_pair_compare(itmc_data_pair_t **, itmc_data_pair_t **); 427c478bd9Sstevel@tonic-gate static long data_to_long(itm_data_t *); 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t *map_table_indexed_fixed(itmc_data_pair_t **, 457c478bd9Sstevel@tonic-gate itm_size_t, itm_data_t *, long, itm_num_t); 467c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t *map_table_dense_encoding(itmc_data_pair_t **, 477c478bd9Sstevel@tonic-gate itm_size_t, itm_data_t *, unsigned long, 487c478bd9Sstevel@tonic-gate unsigned char *, unsigned char *, long, 497c478bd9Sstevel@tonic-gate itm_num_t); 507c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t *map_table_lookup_fixed(itmc_data_pair_t **, 517c478bd9Sstevel@tonic-gate itm_size_t, itm_data_t *, long, itm_size_t); 527c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t *map_table_hash(itmc_data_pair_t **, itm_size_t, 537c478bd9Sstevel@tonic-gate itm_data_t *, long, long, itm_size_t, 547c478bd9Sstevel@tonic-gate itm_num_t); 557c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t *map_table_lookup_var(); 567c478bd9Sstevel@tonic-gate static void put_dense_encoding_default(char *, unsigned char *, 577c478bd9Sstevel@tonic-gate unsigned char *, unsigned char *, long, long, long); 587c478bd9Sstevel@tonic-gate static size_t map_table_resultlen(itmc_map_t *); 597c478bd9Sstevel@tonic-gate static void map_range_adjust_byte_seq(unsigned char *, 607c478bd9Sstevel@tonic-gate unsigned char *, long, itmc_data_pair_t *); 617c478bd9Sstevel@tonic-gate static void map_range_make_result(char *, itm_size_t, itm_size_t, 627c478bd9Sstevel@tonic-gate char *, itm_size_t); 637c478bd9Sstevel@tonic-gate static size_t map_table_num_range(itmc_data_pair_t *); 647c478bd9Sstevel@tonic-gate static itmc_map_type_t check_map_type(itmc_map_attr_t *); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate static itmc_name_t *name_lookup(itm_data_t *, itm_type_t); 687c478bd9Sstevel@tonic-gate static itmc_name_t *name_refer(itm_data_t *, itm_type_t, itmc_ref_t *); 697c478bd9Sstevel@tonic-gate static itmc_name_t *name_register(itm_data_t *, itm_type_t, itmc_ref_t *); 707c478bd9Sstevel@tonic-gate static void op_hirarchy(itm_tbl_hdr_t *, itmc_obj_t *); 717c478bd9Sstevel@tonic-gate static obj_array_t obj_list_to_array(itm_size_t, itmc_obj_t *, itm_size_t); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate void 757c478bd9Sstevel@tonic-gate itm_def_process(itm_data_t *itm_name) 767c478bd9Sstevel@tonic-gate { 777c478bd9Sstevel@tonic-gate itm_hdr_t *itm_hdr; 787c478bd9Sstevel@tonic-gate long len; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate TRACE_MESSAGE('y', ("itm_def_process\n")); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate itm_hdr = malloc_vital(sizeof (itm_hdr_t)); 847c478bd9Sstevel@tonic-gate (void) memset(itm_hdr, 0, sizeof (itm_hdr_t)); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate if ((NULL != cmd_opt.interpreter) && 877c478bd9Sstevel@tonic-gate (0 < (len = strlen(cmd_opt.interpreter)))) { 887c478bd9Sstevel@tonic-gate itm_hdr->interpreter = *(str_to_data(len, cmd_opt.interpreter)); 897c478bd9Sstevel@tonic-gate } 907c478bd9Sstevel@tonic-gate if ((sizeof (itm_place_t)) < itm_hdr->interpreter.size) { 917c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_STRING, NULL, 927c478bd9Sstevel@tonic-gate (void *)itm_hdr->interpreter.place.itm_ptr, 937c478bd9Sstevel@tonic-gate itm_hdr->interpreter.size, 947c478bd9Sstevel@tonic-gate &(itm_hdr->interpreter.place), 957c478bd9Sstevel@tonic-gate OBJ_REG_HEAD); 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate itm_hdr->type_id = *itm_name; 997c478bd9Sstevel@tonic-gate if ((sizeof (itm_place_t)) < itm_hdr->type_id.size) { 1007c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_STRING, NULL, 1017c478bd9Sstevel@tonic-gate (void *)itm_hdr->type_id.place.itm_ptr, 1027c478bd9Sstevel@tonic-gate itm_hdr->type_id.size, 1037c478bd9Sstevel@tonic-gate &(itm_hdr->type_id.place), 1047c478bd9Sstevel@tonic-gate OBJ_REG_HEAD); 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate (void) assemble(itm_hdr); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate itmc_obj_t * 1137c478bd9Sstevel@tonic-gate direction_unit( 1147c478bd9Sstevel@tonic-gate itmc_ref_t *cond, 1157c478bd9Sstevel@tonic-gate itm_data_t *cond_name, 1167c478bd9Sstevel@tonic-gate itmc_action_t *act, 1177c478bd9Sstevel@tonic-gate itm_data_t *act_name) 1187c478bd9Sstevel@tonic-gate { 1197c478bd9Sstevel@tonic-gate itmc_obj_t *du; 1207c478bd9Sstevel@tonic-gate itm_direc_t *direc; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate du = malloc_vital(sizeof (itmc_obj_t)); 1237c478bd9Sstevel@tonic-gate du->type = ITMC_OBJ_DIREC; 1247c478bd9Sstevel@tonic-gate du->name = NULL; 1257c478bd9Sstevel@tonic-gate du->obj = direc = malloc_vital(sizeof (itm_direc_t)); 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate if (NULL != cond) { 128*e492095eSRichard PALO direc->condition.itm_ptr = (uintptr_t)NULL; 1297c478bd9Sstevel@tonic-gate cond->referencer = &(direc->condition); 1307c478bd9Sstevel@tonic-gate du->ref[0] = cond; 1317c478bd9Sstevel@tonic-gate } else if (NULL != cond_name) { 1327c478bd9Sstevel@tonic-gate direc->condition.itm_ptr = (itm_place2_t)(cond_name); 1337c478bd9Sstevel@tonic-gate du->ref[0] = obj_register(ITMC_OBJ_COND, cond_name, NULL, 0, 1347c478bd9Sstevel@tonic-gate &(direc->condition), OBJ_REG_TAIL); 1357c478bd9Sstevel@tonic-gate } else { 1367c478bd9Sstevel@tonic-gate direc->condition.itm_ptr = 0; 1377c478bd9Sstevel@tonic-gate du->ref[0] = NULL; 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate if (NULL != act_name) { 1427c478bd9Sstevel@tonic-gate direc->action.itm_ptr = (itm_place2_t)(act_name); 1437c478bd9Sstevel@tonic-gate du->ref[1] = obj_register(ITMC_OBJ_ACTION, act_name, NULL, 0, 1447c478bd9Sstevel@tonic-gate &(direc->action), OBJ_REG_TAIL); 1457c478bd9Sstevel@tonic-gate } else if (NULL != act && act->tbl_hdr != NULL) { 1467c478bd9Sstevel@tonic-gate direc->action.itm_ptr = (itm_place2_t)(act->tbl_hdr); 1477c478bd9Sstevel@tonic-gate du->ref[1] = obj_register(act->type, 1487c478bd9Sstevel@tonic-gate (itm_data_t *)(act->tbl_hdr->name.itm_ptr), 1497c478bd9Sstevel@tonic-gate act->tbl_hdr, act->tbl_hdr->size, 1507c478bd9Sstevel@tonic-gate &(direc->action), OBJ_REG_TAIL); 1517c478bd9Sstevel@tonic-gate } else { 1527c478bd9Sstevel@tonic-gate return (NULL); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate du->ref[2] = NULL; 1567c478bd9Sstevel@tonic-gate return (du); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate itm_tbl_hdr_t * 1627c478bd9Sstevel@tonic-gate obj_table(itm_type_t tbl_type, 1637c478bd9Sstevel@tonic-gate itm_data_t *name, 1647c478bd9Sstevel@tonic-gate itmc_obj_t *obj_list, 1657c478bd9Sstevel@tonic-gate itm_size_t obj_size) 1667c478bd9Sstevel@tonic-gate { 1677c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *tbl; 1687c478bd9Sstevel@tonic-gate obj_array_t obj_array; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate obj_array = obj_list_to_array(sizeof (itm_tbl_hdr_t), 1717c478bd9Sstevel@tonic-gate obj_list, obj_size); 1727c478bd9Sstevel@tonic-gate tbl = obj_array.obj; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate tbl->type = tbl_type; 1757c478bd9Sstevel@tonic-gate if (name) { 1767c478bd9Sstevel@tonic-gate #if !defined(_LP64) 1777c478bd9Sstevel@tonic-gate tbl->name.itm_pad = 0; 1787c478bd9Sstevel@tonic-gate #endif 1797c478bd9Sstevel@tonic-gate tbl->name.itm_ptr = (itm_place2_t)name; 1807c478bd9Sstevel@tonic-gate } else { 1817c478bd9Sstevel@tonic-gate #if !defined(_LP64) 1827c478bd9Sstevel@tonic-gate tbl->name.itm_pad = 0; 1837c478bd9Sstevel@tonic-gate #endif 184*e492095eSRichard PALO tbl->name.itm_ptr = (uintptr_t)NULL; 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate tbl->size = (sizeof (itm_tbl_hdr_t)) + (obj_array.num *obj_size); 1877c478bd9Sstevel@tonic-gate tbl->number = obj_array.num; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate if ((ITM_TBL_MASK&tbl->type) == ITM_TBL_OP) { 1907c478bd9Sstevel@tonic-gate op_hirarchy(tbl, obj_list); 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate return (tbl); 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* 1967c478bd9Sstevel@tonic-gate * 1977c478bd9Sstevel@tonic-gate */ 1987c478bd9Sstevel@tonic-gate static obj_array_t 1997c478bd9Sstevel@tonic-gate obj_list_to_array(itm_size_t hdr_size, itmc_obj_t *obj_list, 2007c478bd9Sstevel@tonic-gate itm_size_t size) 2017c478bd9Sstevel@tonic-gate { 2027c478bd9Sstevel@tonic-gate obj_array_t obj_array; 2037c478bd9Sstevel@tonic-gate itm_size_t offset; 2047c478bd9Sstevel@tonic-gate itmc_obj_t *ol; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate for (obj_array.num = 0, ol = obj_list; 2077c478bd9Sstevel@tonic-gate ol; obj_array.num += 1, ol = ol->next) { 2087c478bd9Sstevel@tonic-gate /* NOP */; 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate obj_array.obj = malloc_vital(hdr_size + (size * obj_array.num)); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate if (obj_array.num == 0) 2147c478bd9Sstevel@tonic-gate return (obj_array); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate for (offset = hdr_size, ol = obj_list; 2177c478bd9Sstevel@tonic-gate ol; offset += size, ol = ol->next) { 2187c478bd9Sstevel@tonic-gate (void) memcpy((char *)(obj_array.obj) + offset, ol->obj, size); 2197c478bd9Sstevel@tonic-gate if (ol->ref[0]) { 2207c478bd9Sstevel@tonic-gate ol->ref[0]->referencer = 2217c478bd9Sstevel@tonic-gate (void *)((char *)(ol->ref[0]->referencer) + 2227c478bd9Sstevel@tonic-gate ((char *)(obj_array.obj) - 2237c478bd9Sstevel@tonic-gate (char *)(ol->obj) + offset)); 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate if (ol->ref[1]) { 2267c478bd9Sstevel@tonic-gate ol->ref[1]->referencer = 2277c478bd9Sstevel@tonic-gate (void *)((char *)(ol->ref[1]->referencer) + 2287c478bd9Sstevel@tonic-gate ((char *)(obj_array.obj) - 2297c478bd9Sstevel@tonic-gate (char *)(ol->obj) + offset)); 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate if (ol->ref[2]) { 2327c478bd9Sstevel@tonic-gate ol->ref[2]->referencer = 2337c478bd9Sstevel@tonic-gate (void *)((char *)(ol->ref[2]->referencer) + 2347c478bd9Sstevel@tonic-gate ((char *)(obj_array.obj) - 2357c478bd9Sstevel@tonic-gate (char *)(ol->obj) + offset)); 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate } 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate return (obj_array); 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate static void 2437c478bd9Sstevel@tonic-gate op_hirarchy(itm_tbl_hdr_t *optbl, 2447c478bd9Sstevel@tonic-gate itmc_obj_t *obj_list) 2457c478bd9Sstevel@tonic-gate { 2467c478bd9Sstevel@tonic-gate itm_op_outer_t *o; 2477c478bd9Sstevel@tonic-gate itm_op_inner_t *in; 2487c478bd9Sstevel@tonic-gate itmc_obj_t *ol; 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate TRACE_MESSAGE('l', ("op_hirarchy (optbl=%x)\n", optbl)); 2517c478bd9Sstevel@tonic-gate o = malloc_vital(sizeof (itm_op_outer_t)); 2527c478bd9Sstevel@tonic-gate o->link = itm_op_outer; 2537c478bd9Sstevel@tonic-gate itm_op_outer = o; 2547c478bd9Sstevel@tonic-gate o->in = NULL; 2557c478bd9Sstevel@tonic-gate o->optbl = optbl; 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate for (ol = obj_list; ol != NULL; ol = ol->next) { 2587c478bd9Sstevel@tonic-gate if ((ol->type == ITMC_OBJ_OP) && 2597c478bd9Sstevel@tonic-gate (((itm_op_t *)ol->obj)->type == ITM_OP_OPERATION)) { 2607c478bd9Sstevel@tonic-gate in = malloc_vital(sizeof (itm_op_inner_t)); 2617c478bd9Sstevel@tonic-gate in->in = o->in; 2627c478bd9Sstevel@tonic-gate o->in = in; 2637c478bd9Sstevel@tonic-gate TRACE_MESSAGE('L', ("o->in(%x) in->in(%x)\n", 2647c478bd9Sstevel@tonic-gate o->in, in->in)); 2657c478bd9Sstevel@tonic-gate in->ref = ol->ref[0]; 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate #ifdef ENABLE_TRACE 2707c478bd9Sstevel@tonic-gate for (in = o->in; in != NULL; in = in->in) { 2717c478bd9Sstevel@tonic-gate TRACE_MESSAGE('L', ("o=%x in=%x in->in=%x\n", 2727c478bd9Sstevel@tonic-gate o, in, in->in)); 2737c478bd9Sstevel@tonic-gate TRACE_MESSAGE('L', ("o(table)%x->in(ref)=%x\n", 2747c478bd9Sstevel@tonic-gate o->optbl, in->ref)); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate #endif 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate itmc_obj_t * 2817c478bd9Sstevel@tonic-gate obj_list_append(itmc_obj_t *obj_list, itmc_obj_t *obj) 2827c478bd9Sstevel@tonic-gate { 2837c478bd9Sstevel@tonic-gate if (0 == obj) { 2847c478bd9Sstevel@tonic-gate return (obj_list); 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate obj->next = NULL; 2887c478bd9Sstevel@tonic-gate obj->last = obj; 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate if (obj_list) { 2917c478bd9Sstevel@tonic-gate obj_list->last->next = obj; 2927c478bd9Sstevel@tonic-gate obj_list->last = obj; 2937c478bd9Sstevel@tonic-gate return (obj_list); 2947c478bd9Sstevel@tonic-gate } else { 2957c478bd9Sstevel@tonic-gate return (obj); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate itmc_ref_t * 3017c478bd9Sstevel@tonic-gate obj_register(itm_type_t type, itm_data_t *name, 3027c478bd9Sstevel@tonic-gate void *obj, size_t size, itm_place_t *ref, 3037c478bd9Sstevel@tonic-gate itm_type_t reg_place) 3047c478bd9Sstevel@tonic-gate { 3057c478bd9Sstevel@tonic-gate itmc_ref_t *refp; 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate TRACE_MESSAGE('O', ("obj_register: %6ld %08p %08p %08ld %08p %ld\n", 3087c478bd9Sstevel@tonic-gate type, name, obj, size, ref, reg_place)); 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate refp = malloc_vital(sizeof (itmc_ref_t)); 3117c478bd9Sstevel@tonic-gate refp->name = NULL; 3127c478bd9Sstevel@tonic-gate refp->referencee = obj; 3137c478bd9Sstevel@tonic-gate #if !defined(_LP64) 3147c478bd9Sstevel@tonic-gate refp->reloc.itm_pad = 0; 3157c478bd9Sstevel@tonic-gate #endif 3167c478bd9Sstevel@tonic-gate refp->reloc.itm_ptr = 0; 3177c478bd9Sstevel@tonic-gate refp->size = size; 3187c478bd9Sstevel@tonic-gate refp->referencer = ref; 3197c478bd9Sstevel@tonic-gate refp->next = NULL; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate if (NULL == obj) { /* reference to named object */ 3227c478bd9Sstevel@tonic-gate if (NULL == name) { 3237c478bd9Sstevel@tonic-gate if (0 == error_deferred) { 3247c478bd9Sstevel@tonic-gate /* should never happen */ 3257c478bd9Sstevel@tonic-gate itm_error( 3267c478bd9Sstevel@tonic-gate gettext("internal error: " 3277c478bd9Sstevel@tonic-gate "obj_register: (NULL == obj) " 3287c478bd9Sstevel@tonic-gate "&& (NULL == name)\n")); 3297c478bd9Sstevel@tonic-gate exit(ITMC_STATUS_SYS2); 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate return (NULL); 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate refp->name = name_refer(name, type, refp); 3347c478bd9Sstevel@tonic-gate return (refp); 3357c478bd9Sstevel@tonic-gate } else if ((NULL != name) && (0 < name->size)) { 3367c478bd9Sstevel@tonic-gate /* definition of named object */ 3377c478bd9Sstevel@tonic-gate refp->name = name_register(name, type, refp); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate if ((ITMC_OBJ_FIRST <= type) && (type <= ITMC_OBJ_LAST)) { 3417c478bd9Sstevel@tonic-gate switch (reg_place) { 3427c478bd9Sstevel@tonic-gate case OBJ_REG_HEAD: 3437c478bd9Sstevel@tonic-gate refp->next = ref_first[type]; 3447c478bd9Sstevel@tonic-gate ref_first[type] = refp; 3457c478bd9Sstevel@tonic-gate if (NULL == ref_last[type]) { 3467c478bd9Sstevel@tonic-gate ref_last[type] = refp; 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate break; 3497c478bd9Sstevel@tonic-gate case OBJ_REG_TAIL: 3507c478bd9Sstevel@tonic-gate if (ref_first[type]) { 3517c478bd9Sstevel@tonic-gate ref_last[type]->next = refp; 3527c478bd9Sstevel@tonic-gate } else { 3537c478bd9Sstevel@tonic-gate ref_first[type] = refp; 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate ref_last[type] = refp; 3567c478bd9Sstevel@tonic-gate break; 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate } else { 3597c478bd9Sstevel@tonic-gate itm_error(gettext("obj_register: illegal object type\n")); 3607c478bd9Sstevel@tonic-gate exit(ITMC_STATUS_SYS2); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate return (refp); 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate itm_tbl_hdr_t * 3687c478bd9Sstevel@tonic-gate range_table(itm_data_t *name, itmc_obj_t *obj_list) 3697c478bd9Sstevel@tonic-gate { 3707c478bd9Sstevel@tonic-gate itm_num_t num; 3717c478bd9Sstevel@tonic-gate itmc_obj_t *ol; 3727c478bd9Sstevel@tonic-gate itmc_data_pair_t *rp; 3737c478bd9Sstevel@tonic-gate itm_range_hdr_t *rh; 3747c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *table; 3757c478bd9Sstevel@tonic-gate itm_size_t length = 0; 3767c478bd9Sstevel@tonic-gate itm_num_t i; 3777c478bd9Sstevel@tonic-gate char *p; 3787c478bd9Sstevel@tonic-gate itm_size_t table_size; 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* count range, determine length */ 3817c478bd9Sstevel@tonic-gate for (num = 0, ol = obj_list; ol; ol = ol->next, num++) { 3827c478bd9Sstevel@tonic-gate rp = (itmc_data_pair_t *)(ol->obj); 3837c478bd9Sstevel@tonic-gate if (length == 0) { 3847c478bd9Sstevel@tonic-gate if (rp->data0.size == 0) { 3857c478bd9Sstevel@tonic-gate itm_error(gettext("between has null range\n")); 3867c478bd9Sstevel@tonic-gate error_deferred += 1; 3877c478bd9Sstevel@tonic-gate return (NULL); 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate length = rp->data0.size; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate if ((rp->data0.size != length) || 3927c478bd9Sstevel@tonic-gate (rp->data1.size != length)) { 3937c478bd9Sstevel@tonic-gate itm_error(gettext( 3947c478bd9Sstevel@tonic-gate "length of source sequences must be the same\n")); 3957c478bd9Sstevel@tonic-gate error_deferred += 1; 3967c478bd9Sstevel@tonic-gate return (NULL); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate if (num == 0) { 4007c478bd9Sstevel@tonic-gate itm_error(gettext("between has no ranges\n")); 4017c478bd9Sstevel@tonic-gate error_deferred += 1; 4027c478bd9Sstevel@tonic-gate return (NULL); 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate table_size = ((sizeof (itm_tbl_hdr_t)) + 4057c478bd9Sstevel@tonic-gate (sizeof (itm_range_hdr_t)) + (length * num) * 2); 4067c478bd9Sstevel@tonic-gate table_size = ITMROUNDUP(table_size); 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate table = malloc_vital(table_size); 4097c478bd9Sstevel@tonic-gate table->type = ITM_TBL_RANGE; 4107c478bd9Sstevel@tonic-gate if (NULL != name) 4117c478bd9Sstevel@tonic-gate table->name.itm_ptr = (itm_place2_t)name; 4127c478bd9Sstevel@tonic-gate table->size = table_size; 4137c478bd9Sstevel@tonic-gate table->number = num; 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate rh = (itm_range_hdr_t *)(table + 1); 4167c478bd9Sstevel@tonic-gate rh->len = length; 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate p = (char *)(rh + 1); 4197c478bd9Sstevel@tonic-gate for (ol = obj_list, i = 0; ol; ol = ol->next, i++) { 4207c478bd9Sstevel@tonic-gate rp = (itmc_data_pair_t *)(ol->obj); 4217c478bd9Sstevel@tonic-gate (void) memcpy(p, (NSPTR(&(rp->data0))), length); 4227c478bd9Sstevel@tonic-gate p += length; 4237c478bd9Sstevel@tonic-gate (void) memcpy(p, (NSPTR(&(rp->data1))), length); 4247c478bd9Sstevel@tonic-gate p += length; 4257c478bd9Sstevel@tonic-gate } 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate return (table); 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate /* 4317c478bd9Sstevel@tonic-gate * escape sequence table for stateful code set sequence 4327c478bd9Sstevel@tonic-gate */ 4337c478bd9Sstevel@tonic-gate itm_tbl_hdr_t * 4347c478bd9Sstevel@tonic-gate escseq_table(itm_data_t *name, itmc_obj_t *obj_list) 4357c478bd9Sstevel@tonic-gate { 4367c478bd9Sstevel@tonic-gate itm_num_t num; 4377c478bd9Sstevel@tonic-gate itmc_obj_t *ol; 4387c478bd9Sstevel@tonic-gate itm_data_t *ep; 4397c478bd9Sstevel@tonic-gate itm_escapeseq_hdr_t *eh; 4407c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *table; 4417c478bd9Sstevel@tonic-gate itm_size_t len_max = 0; 4427c478bd9Sstevel@tonic-gate itm_size_t len_min; 4437c478bd9Sstevel@tonic-gate itm_num_t i; 4447c478bd9Sstevel@tonic-gate itm_size_t table_size; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate ol = obj_list; 4477c478bd9Sstevel@tonic-gate len_min = ((itm_data_t *)(ol->obj))->size; 4487c478bd9Sstevel@tonic-gate for (num = 0; NULL != ol; ol = ol->next, num++) { 4497c478bd9Sstevel@tonic-gate ep = (itm_data_t *)(ol->obj); 4507c478bd9Sstevel@tonic-gate if (ep->size < len_min) len_min = ep->size; 4517c478bd9Sstevel@tonic-gate if (ep->size > len_max) len_max = ep->size; 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate if (num == 0) { 4547c478bd9Sstevel@tonic-gate itm_error(gettext 4557c478bd9Sstevel@tonic-gate ("escape sequence is defined without sequence\n")); 4567c478bd9Sstevel@tonic-gate error_deferred += 1; 4577c478bd9Sstevel@tonic-gate return (NULL); 4587c478bd9Sstevel@tonic-gate } else if (0 == len_min) { 4597c478bd9Sstevel@tonic-gate itm_error(gettext("null sequence\n")); 4607c478bd9Sstevel@tonic-gate error_deferred += 1; 4617c478bd9Sstevel@tonic-gate return (NULL); 4627c478bd9Sstevel@tonic-gate } 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate table_size = ((sizeof (itm_tbl_hdr_t)) + 4657c478bd9Sstevel@tonic-gate (sizeof (itm_escapeseq_hdr_t)) + 4667c478bd9Sstevel@tonic-gate (sizeof (itm_data_t) * num)); 4677c478bd9Sstevel@tonic-gate table_size = ITMROUNDUP(table_size); 4687c478bd9Sstevel@tonic-gate table = malloc_vital(table_size); 4697c478bd9Sstevel@tonic-gate table->type = ITM_TBL_ESCAPESEQ; 4707c478bd9Sstevel@tonic-gate if (NULL != name) 4717c478bd9Sstevel@tonic-gate table->name.itm_ptr = (itm_place2_t)name; 4727c478bd9Sstevel@tonic-gate table->size = table_size; 4737c478bd9Sstevel@tonic-gate table->number = num; 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate eh = (itm_escapeseq_hdr_t *)(table + 1); 4767c478bd9Sstevel@tonic-gate eh->len_max = len_max; 4777c478bd9Sstevel@tonic-gate eh->len_min = len_min; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate for (ol = obj_list, ep = (itm_data_t *)(eh + 1); 4807c478bd9Sstevel@tonic-gate ol != NULL; 4817c478bd9Sstevel@tonic-gate ol = ol->next, ep++) { 4827c478bd9Sstevel@tonic-gate *ep = *((itm_data_t *)(ol->obj)); 4837c478bd9Sstevel@tonic-gate if ((sizeof (itm_place_t)) < ep->size) { 4847c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_DATA, NULL, 4857c478bd9Sstevel@tonic-gate (void *)(ep->place.itm_ptr), ep->size, 4867c478bd9Sstevel@tonic-gate &(ep->place), OBJ_REG_TAIL); 4877c478bd9Sstevel@tonic-gate } 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate (void) qsort((itm_data_t *)(eh + 1), num, sizeof (itm_data_t), 4907c478bd9Sstevel@tonic-gate (int (*)(const void *, const void *))data_compare); 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate for (i = 0, ep = (itm_data_t *)(eh + 1); 4937c478bd9Sstevel@tonic-gate i < num - 1; 4947c478bd9Sstevel@tonic-gate i++, ep++) { 4957c478bd9Sstevel@tonic-gate if (0 <= data_compare(ep, (ep + 1))) { 4967c478bd9Sstevel@tonic-gate itm_error( 4977c478bd9Sstevel@tonic-gate gettext( 498*e492095eSRichard PALO "same escape sequences are defined: " 499*e492095eSRichard PALO "0x%1$s 0x%2$s\n"), 5007c478bd9Sstevel@tonic-gate data_to_hexadecimal(ep), 5017c478bd9Sstevel@tonic-gate data_to_hexadecimal(ep + 1)); 5027c478bd9Sstevel@tonic-gate error_deferred += 1; 5037c478bd9Sstevel@tonic-gate return (NULL); 5047c478bd9Sstevel@tonic-gate } 5057c478bd9Sstevel@tonic-gate } 5067c478bd9Sstevel@tonic-gate return (table); 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate itm_tbl_hdr_t * 5137c478bd9Sstevel@tonic-gate map_table(itm_data_t *name, itmc_map_t *map_list, 5147c478bd9Sstevel@tonic-gate itmc_map_attr_t *attr) 5157c478bd9Sstevel@tonic-gate { 5167c478bd9Sstevel@tonic-gate itm_size_t num; 5177c478bd9Sstevel@tonic-gate itm_size_t num2; 5187c478bd9Sstevel@tonic-gate itmc_map_t *ml; 5197c478bd9Sstevel@tonic-gate itmc_data_pair_t **tpp; 5207c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *table; 5217c478bd9Sstevel@tonic-gate long source_len = 0; 5227c478bd9Sstevel@tonic-gate long result_len = 0; 5237c478bd9Sstevel@tonic-gate long source_fixed_len = 1; 5247c478bd9Sstevel@tonic-gate long pass_through = 0; 5257c478bd9Sstevel@tonic-gate long default_count = 0; 5267c478bd9Sstevel@tonic-gate itm_data_t *default_data = NULL; 5277c478bd9Sstevel@tonic-gate long error_deferred_local = 0; 5287c478bd9Sstevel@tonic-gate unsigned long dense_encoded_map_ent; 5297c478bd9Sstevel@tonic-gate unsigned long simple_indexed_map_ent; 5307c478bd9Sstevel@tonic-gate itm_size_t source_start; 5317c478bd9Sstevel@tonic-gate itm_size_t source_end; 5327c478bd9Sstevel@tonic-gate unsigned long u; 5337c478bd9Sstevel@tonic-gate unsigned char *byte_seq_min; 5347c478bd9Sstevel@tonic-gate unsigned char *byte_seq_max; 5357c478bd9Sstevel@tonic-gate unsigned char *p; 5367c478bd9Sstevel@tonic-gate long i; 537*e492095eSRichard PALO itmc_map_type_t map_type = ITMC_MAP_UNKNOWN; 5387c478bd9Sstevel@tonic-gate itmc_map_name_type_t *map_name_type; 5397c478bd9Sstevel@tonic-gate long hash_factor; 5407c478bd9Sstevel@tonic-gate long result_len_specfied = 0; 5417c478bd9Sstevel@tonic-gate size_t j; 5427c478bd9Sstevel@tonic-gate long n; 5437c478bd9Sstevel@tonic-gate itmc_data_pair_t **dp1; 5447c478bd9Sstevel@tonic-gate itm_num_t error_count = 0; 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate if (attr != NULL) { 5477c478bd9Sstevel@tonic-gate map_type = check_map_type(attr); 5487c478bd9Sstevel@tonic-gate } 549*e492095eSRichard PALO if (ITMC_MAP_UNKNOWN == map_type) { 5507c478bd9Sstevel@tonic-gate map_type = ITMC_MAP_AUTOMATIC; 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate hash_factor = ((NULL != attr) && (attr->hash_factor != 0)) ? 5537c478bd9Sstevel@tonic-gate attr->hash_factor : 5547c478bd9Sstevel@tonic-gate 200; 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate map_name_type = cmd_opt.map_name_type; 5577c478bd9Sstevel@tonic-gate for (; map_name_type; map_name_type = map_name_type->next) { 5587c478bd9Sstevel@tonic-gate if ('\0' == *(map_name_type->name)) { 5597c478bd9Sstevel@tonic-gate map_type = map_name_type->type; 5607c478bd9Sstevel@tonic-gate hash_factor = map_name_type->hash_factor; 5617c478bd9Sstevel@tonic-gate break; 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate map_name_type = cmd_opt.map_name_type; 5657c478bd9Sstevel@tonic-gate if ((NULL != name) && (NULL != cmd_opt.map_name_type)) { 5667c478bd9Sstevel@tonic-gate p = NSPTR(name); 5677c478bd9Sstevel@tonic-gate for (; map_name_type; map_name_type = map_name_type->next) { 5687c478bd9Sstevel@tonic-gate if (0 == strcmp(map_name_type->name, (char *)p)) { 5697c478bd9Sstevel@tonic-gate map_type = map_name_type->type; 5707c478bd9Sstevel@tonic-gate hash_factor = map_name_type->hash_factor; 5717c478bd9Sstevel@tonic-gate break; 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate } 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate if (NULL != attr) { 5777c478bd9Sstevel@tonic-gate if (MAXSEQUENCE < attr->resultlen) { 5787c478bd9Sstevel@tonic-gate itm_error( 5797c478bd9Sstevel@tonic-gate gettext("output_byte_length must be less than %1$d\n"), 5807c478bd9Sstevel@tonic-gate MAXSEQUENCE); 5817c478bd9Sstevel@tonic-gate error_deferred += 1; 5827c478bd9Sstevel@tonic-gate return (NULL); 5837c478bd9Sstevel@tonic-gate } 5847c478bd9Sstevel@tonic-gate result_len_specfied = attr->resultlen; 5857c478bd9Sstevel@tonic-gate } else { 5867c478bd9Sstevel@tonic-gate result_len_specfied = 0; 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate for (num = 0, ml = map_list; ml; ml = ml->next, num++) { 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate /* default */ 5927c478bd9Sstevel@tonic-gate if (0 == ml->data_pair.data0.size) { 5937c478bd9Sstevel@tonic-gate if (0 == ml->data_pair.data1.size) { 5947c478bd9Sstevel@tonic-gate pass_through += 1; 5957c478bd9Sstevel@tonic-gate default_data = (itm_data_t *)(-1); 5967c478bd9Sstevel@tonic-gate } else { 5977c478bd9Sstevel@tonic-gate default_count += 1; 5987c478bd9Sstevel@tonic-gate default_data = &(ml->data_pair.data1); 5997c478bd9Sstevel@tonic-gate } 6007c478bd9Sstevel@tonic-gate --num; 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate } else if (0 == ml->data_pair.data1.size) { 6047c478bd9Sstevel@tonic-gate /* error source sequence */ 6057c478bd9Sstevel@tonic-gate continue; 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate /* fixed length */ 6097c478bd9Sstevel@tonic-gate if ((0 < source_len) && 6107c478bd9Sstevel@tonic-gate (0 < ml->data_pair.data0.size) && 6117c478bd9Sstevel@tonic-gate (source_len != ml->data_pair.data0.size)) { 6127c478bd9Sstevel@tonic-gate source_fixed_len = 0; 6137c478bd9Sstevel@tonic-gate } 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate /* maximum length */ 6167c478bd9Sstevel@tonic-gate if (source_len < ml->data_pair.data0.size) { 6177c478bd9Sstevel@tonic-gate source_len = ml->data_pair.data0.size; 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate if (result_len < ml->data_pair.data1.size) { 6207c478bd9Sstevel@tonic-gate result_len = ml->data_pair.data1.size; 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate 6237c478bd9Sstevel@tonic-gate /* map source has range */ 6247c478bd9Sstevel@tonic-gate if (0 < ml->data_pair.range.size) { 6257c478bd9Sstevel@tonic-gate if (ml->data_pair.range.size != 6267c478bd9Sstevel@tonic-gate ml->data_pair.data0.size) { 6277c478bd9Sstevel@tonic-gate itm_error( 6287c478bd9Sstevel@tonic-gate gettext("length of source range must be " 6297c478bd9Sstevel@tonic-gate "the same: 0x%1$s 0x%2$s\n"), 6307c478bd9Sstevel@tonic-gate data_to_hexadecimal(&(ml->data_pair.data0)), 631*e492095eSRichard PALO data_to_hexadecimal( 632*e492095eSRichard PALO &(ml->data_pair.range))); 6337c478bd9Sstevel@tonic-gate error_deferred += 1; 6347c478bd9Sstevel@tonic-gate return (NULL); 6357c478bd9Sstevel@tonic-gate } 6367c478bd9Sstevel@tonic-gate if (0 <= data_compare(&(ml->data_pair.data0), 6377c478bd9Sstevel@tonic-gate &((ml->data_pair.range)))) { 6387c478bd9Sstevel@tonic-gate itm_error( 6397c478bd9Sstevel@tonic-gate gettext("source range error: 0x%1$s 0x%2$s\n"), 640*e492095eSRichard PALO data_to_hexadecimal( 641*e492095eSRichard PALO &(ml->data_pair.data0)), 642*e492095eSRichard PALO data_to_hexadecimal( 643*e492095eSRichard PALO &(ml->data_pair.range))); 6447c478bd9Sstevel@tonic-gate error_deferred += 1; 6457c478bd9Sstevel@tonic-gate return (NULL); 6467c478bd9Sstevel@tonic-gate } 6477c478bd9Sstevel@tonic-gate j = map_table_resultlen(ml); 6487c478bd9Sstevel@tonic-gate if (result_len < j) { 6497c478bd9Sstevel@tonic-gate result_len = j; 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate } 6537c478bd9Sstevel@tonic-gate if (num == 0) { 6547c478bd9Sstevel@tonic-gate itm_error( 6557c478bd9Sstevel@tonic-gate gettext("no mapping pair\n")); 6567c478bd9Sstevel@tonic-gate error_deferred += 1; 6577c478bd9Sstevel@tonic-gate return (NULL); 6587c478bd9Sstevel@tonic-gate } 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate if (0 != result_len_specfied) { 6617c478bd9Sstevel@tonic-gate if (result_len > result_len_specfied) { 6627c478bd9Sstevel@tonic-gate itm_error( 6637c478bd9Sstevel@tonic-gate gettext("result value length is " 6647c478bd9Sstevel@tonic-gate "over specifed output_byte_length(%1$ld)\n"), 6657c478bd9Sstevel@tonic-gate result_len_specfied); 6667c478bd9Sstevel@tonic-gate error_deferred += 1; 6677c478bd9Sstevel@tonic-gate return (NULL); 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate result_len = result_len_specfied; 6707c478bd9Sstevel@tonic-gate } 6717c478bd9Sstevel@tonic-gate byte_seq_min = malloc_vital((sizeof (unsigned char)) * source_len); 6727c478bd9Sstevel@tonic-gate byte_seq_max = malloc_vital((sizeof (unsigned char)) * source_len); 6737c478bd9Sstevel@tonic-gate for (num = 0, ml = map_list; ml; ml = ml->next, num++) { 6747c478bd9Sstevel@tonic-gate if (0 == ml->data_pair.data0.size) { 6757c478bd9Sstevel@tonic-gate continue; 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate p = (unsigned char *)(NSPTR(&((ml->data_pair).data0))); 6797c478bd9Sstevel@tonic-gate for (i = 0; i < source_len; i++) { 6807c478bd9Sstevel@tonic-gate *(byte_seq_min + i) = *(p + i); 6817c478bd9Sstevel@tonic-gate *(byte_seq_max + i) = *(p + i); 6827c478bd9Sstevel@tonic-gate } 6837c478bd9Sstevel@tonic-gate break; 6847c478bd9Sstevel@tonic-gate } 6857c478bd9Sstevel@tonic-gate for (num = 0, ml = map_list; ml; ml = ml->next, num++) { 6867c478bd9Sstevel@tonic-gate if (0 == ml->data_pair.data0.size) { 6877c478bd9Sstevel@tonic-gate num--; 6887c478bd9Sstevel@tonic-gate continue; 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate if (ml->data_pair.range.size > 0) { 6917c478bd9Sstevel@tonic-gate map_range_adjust_byte_seq(byte_seq_min, byte_seq_max, 6927c478bd9Sstevel@tonic-gate source_len, &(ml->data_pair)); 6937c478bd9Sstevel@tonic-gate } else { 6947c478bd9Sstevel@tonic-gate p = (unsigned char *)(NSPTR(&((ml->data_pair).data0))); 6957c478bd9Sstevel@tonic-gate for (i = 0; i < source_len; i++) { 6967c478bd9Sstevel@tonic-gate if (*(p + i) < *(byte_seq_min + i)) { 6977c478bd9Sstevel@tonic-gate *(byte_seq_min + i) = *(p + i); 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate if (*(byte_seq_max + i) < *(p + i)) { 7007c478bd9Sstevel@tonic-gate *(byte_seq_max + i) = *(p + i); 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate } 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate for (dense_encoded_map_ent = 1, i = 0; i < source_len; i++) { 7067c478bd9Sstevel@tonic-gate u = dense_encoded_map_ent; 7077c478bd9Sstevel@tonic-gate dense_encoded_map_ent *= 7087c478bd9Sstevel@tonic-gate (*(byte_seq_max + i) - *(byte_seq_min + i) + 1); 7097c478bd9Sstevel@tonic-gate if (dense_encoded_map_ent < u) { 7107c478bd9Sstevel@tonic-gate dense_encoded_map_ent = (ulong_t)(~0); 7117c478bd9Sstevel@tonic-gate break; 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate #if defined(DEBUG) 7157c478bd9Sstevel@tonic-gate if (TRACE('m')) { 7167c478bd9Sstevel@tonic-gate int i; 7177c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("map_table: ent=%lu num=%lu ", 7187c478bd9Sstevel@tonic-gate dense_encoded_map_ent, num)); 7197c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("byte_seq_min=0x")); 7207c478bd9Sstevel@tonic-gate for (i = 0; i < source_len; i++) { 7217c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("%02x", *(byte_seq_min + i))); 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', (" byte_seq_max=0x")); 7247c478bd9Sstevel@tonic-gate for (i = 0; i < source_len; i++) { 7257c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("%02x", *(byte_seq_max + i))); 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("\n")); 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate tpp = malloc_vital((sizeof (itmc_data_pair_t *)) * num); 7327c478bd9Sstevel@tonic-gate for (num = 0, num2 = 0, ml = map_list; ml; ml = ml->next) { 7337c478bd9Sstevel@tonic-gate if (0 < ml->data_pair.data0.size) { 7347c478bd9Sstevel@tonic-gate itm_num_t range_num; 7357c478bd9Sstevel@tonic-gate *(tpp + num) = &(ml->data_pair); 7367c478bd9Sstevel@tonic-gate num++; 7377c478bd9Sstevel@tonic-gate range_num = 1; 7387c478bd9Sstevel@tonic-gate if (ml->data_pair.range.size > 0) { 7397c478bd9Sstevel@tonic-gate range_num += 7407c478bd9Sstevel@tonic-gate map_table_num_range(&(ml->data_pair)); 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate num2 += range_num; 7437c478bd9Sstevel@tonic-gate if (0 == ml->data_pair.data1.size) { 7447c478bd9Sstevel@tonic-gate /* specified error sequence */ 7457c478bd9Sstevel@tonic-gate error_count += range_num; 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate (void) qsort(tpp, num, sizeof (itmc_data_pair_t *), 7507c478bd9Sstevel@tonic-gate (int (*)(const void *, const void *))data_pair_compare); 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate /* check if map_pair range and next map_pair are overrapped */ 7537c478bd9Sstevel@tonic-gate for (n = 0, dp1 = tpp; n < (num-1); n++, dp1++) { 7547c478bd9Sstevel@tonic-gate if (((*(dp1+0))->range.size != 0) && 7557c478bd9Sstevel@tonic-gate (0 <= data_compare(&((*(dp1+0))->range), 7567c478bd9Sstevel@tonic-gate &((*(dp1+1))->data0)))) { 7577c478bd9Sstevel@tonic-gate itm_error( 7587c478bd9Sstevel@tonic-gate gettext("ranges of source sequences " 7597c478bd9Sstevel@tonic-gate "overrapped: %1$s %2$s\n"), 7607c478bd9Sstevel@tonic-gate data_to_hexadecimal(&((*(dp1+0))->range)), 7617c478bd9Sstevel@tonic-gate data_to_hexadecimal(&((*(dp1+1))->data0))); 7627c478bd9Sstevel@tonic-gate error_deferred += 1; 7637c478bd9Sstevel@tonic-gate return (NULL); 7647c478bd9Sstevel@tonic-gate } 7657c478bd9Sstevel@tonic-gate } 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate if (1 < default_count) { 7687c478bd9Sstevel@tonic-gate itm_error( 7697c478bd9Sstevel@tonic-gate gettext("default is specified %1$d times in a map\n"), 7707c478bd9Sstevel@tonic-gate default_count); 7717c478bd9Sstevel@tonic-gate error_deferred_local += 1; 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate if ((1 == default_count) && (!source_fixed_len)) { 7747c478bd9Sstevel@tonic-gate itm_error( 7757c478bd9Sstevel@tonic-gate gettext("default is specified," 7767c478bd9Sstevel@tonic-gate " but length of source data is not fixed\n")); 7777c478bd9Sstevel@tonic-gate error_deferred_local += 1; 7787c478bd9Sstevel@tonic-gate } 7797c478bd9Sstevel@tonic-gate if ((1 <= pass_through) && (source_len != result_len)) { 7807c478bd9Sstevel@tonic-gate itm_error( 7817c478bd9Sstevel@tonic-gate gettext("\"default no_change_copy\" is " 7827c478bd9Sstevel@tonic-gate "specified, but size does not match\n")); 7837c478bd9Sstevel@tonic-gate error_deferred_local += 1; 7847c478bd9Sstevel@tonic-gate } 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate if (error_deferred_local) { 7877c478bd9Sstevel@tonic-gate error_deferred += error_deferred_local; 7887c478bd9Sstevel@tonic-gate return (NULL); 7897c478bd9Sstevel@tonic-gate } 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate if (source_fixed_len) { 7927c478bd9Sstevel@tonic-gate source_start = data_to_long(&((*(tpp + 0))->data0)); 7937c478bd9Sstevel@tonic-gate source_end = data_to_long(&((*(tpp + num - 1))->data0)); 7947c478bd9Sstevel@tonic-gate if (0 < (*(tpp + num - 1))->range.size) { 7957c478bd9Sstevel@tonic-gate source_end = data_to_long(&((*(tpp + num - 1))->range)); 7967c478bd9Sstevel@tonic-gate } 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate simple_indexed_map_ent = source_end - source_start + 1; 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("map_table: simple_indexed_map_ent=%lu\n", 8017c478bd9Sstevel@tonic-gate simple_indexed_map_ent)); 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate switch (map_type) { 8047c478bd9Sstevel@tonic-gate case ITMC_MAP_AUTOMATIC: 8057c478bd9Sstevel@tonic-gate if ((source_len <= 2) && 8067c478bd9Sstevel@tonic-gate (((ulong_t)(~0) == dense_encoded_map_ent) || 8077c478bd9Sstevel@tonic-gate (simple_indexed_map_ent < 8087c478bd9Sstevel@tonic-gate (dense_encoded_map_ent * 2)))) { 8097c478bd9Sstevel@tonic-gate /* 8107c478bd9Sstevel@tonic-gate * for small source sequence, 8117c478bd9Sstevel@tonic-gate * if dense table is not so large 8127c478bd9Sstevel@tonic-gate * compared with simple table, 8137c478bd9Sstevel@tonic-gate * use simple. 8147c478bd9Sstevel@tonic-gate */ 8157c478bd9Sstevel@tonic-gate map_type = ITMC_MAP_SIMPLE_INDEX; 8167c478bd9Sstevel@tonic-gate } else if (cmd_opt.large_table) { 8177c478bd9Sstevel@tonic-gate if ((sizeof (long)) < source_len) { 8187c478bd9Sstevel@tonic-gate itm_error( 8197c478bd9Sstevel@tonic-gate gettext("length of source is too long " 8207c478bd9Sstevel@tonic-gate "for large table: %ld\n"), 8217c478bd9Sstevel@tonic-gate source_len); 8227c478bd9Sstevel@tonic-gate error_deferred += 1; 8237c478bd9Sstevel@tonic-gate return (NULL); 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate map_type = ITMC_MAP_SIMPLE_INDEX; 8267c478bd9Sstevel@tonic-gate } else if (((ulong_t)(~0) == dense_encoded_map_ent) || 8277c478bd9Sstevel@tonic-gate ((0xffff < dense_encoded_map_ent) && 8287c478bd9Sstevel@tonic-gate ((num2 * 8) < dense_encoded_map_ent))) { 8297c478bd9Sstevel@tonic-gate /* 8307c478bd9Sstevel@tonic-gate * if dense can be used and not too large 8317c478bd9Sstevel@tonic-gate * ( less than (hash table entry * 8), 8327c478bd9Sstevel@tonic-gate * use dense. 8337c478bd9Sstevel@tonic-gate */ 8347c478bd9Sstevel@tonic-gate map_type = ITMC_MAP_SIMPLE_HASH; 8357c478bd9Sstevel@tonic-gate } else { 8367c478bd9Sstevel@tonic-gate map_type = ITMC_MAP_DENSE_ENCODING; 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate break; 8397c478bd9Sstevel@tonic-gate case ITMC_MAP_SIMPLE_INDEX: 8407c478bd9Sstevel@tonic-gate if ((sizeof (long)) < source_len) { 8417c478bd9Sstevel@tonic-gate itm_error( 8427c478bd9Sstevel@tonic-gate gettext("length of source is too long " 8437c478bd9Sstevel@tonic-gate "for index lookup: %ld\n"), 8447c478bd9Sstevel@tonic-gate source_len); 8457c478bd9Sstevel@tonic-gate error_deferred += 1; 8467c478bd9Sstevel@tonic-gate return (NULL); 8477c478bd9Sstevel@tonic-gate } 8487c478bd9Sstevel@tonic-gate break; 8497c478bd9Sstevel@tonic-gate case ITMC_MAP_SIMPLE_HASH: 8507c478bd9Sstevel@tonic-gate for (i = 2, u = 256; i < (sizeof (long)); i++) { 8517c478bd9Sstevel@tonic-gate u *= 256; 8527c478bd9Sstevel@tonic-gate } 8537c478bd9Sstevel@tonic-gate if (u < num2) { 8547c478bd9Sstevel@tonic-gate itm_error( 8557c478bd9Sstevel@tonic-gate gettext("map is too large for hashing: %lu\n"), 8567c478bd9Sstevel@tonic-gate num2); 8577c478bd9Sstevel@tonic-gate error_deferred += 1; 8587c478bd9Sstevel@tonic-gate return (NULL); 8597c478bd9Sstevel@tonic-gate } 8607c478bd9Sstevel@tonic-gate break; 8617c478bd9Sstevel@tonic-gate case ITMC_MAP_DENSE_ENCODING: 8627c478bd9Sstevel@tonic-gate for (i = 2, u = 256; i < (sizeof (long)); i++) { 8637c478bd9Sstevel@tonic-gate u *= 256; 8647c478bd9Sstevel@tonic-gate } 8657c478bd9Sstevel@tonic-gate if (u < dense_encoded_map_ent) { 8667c478bd9Sstevel@tonic-gate itm_error( 8677c478bd9Sstevel@tonic-gate gettext( 868*e492095eSRichard PALO "map is too large for dense encoding: " 869*e492095eSRichard PALO "%lu\n"), 8707c478bd9Sstevel@tonic-gate dense_encoded_map_ent); 8717c478bd9Sstevel@tonic-gate error_deferred += 1; 8727c478bd9Sstevel@tonic-gate return (NULL); 8737c478bd9Sstevel@tonic-gate } 8747c478bd9Sstevel@tonic-gate break; 8757c478bd9Sstevel@tonic-gate case ITMC_MAP_BINARY_SEARCH: 8767c478bd9Sstevel@tonic-gate for (i = 2, u = 256; i < (sizeof (long)); i++) { 8777c478bd9Sstevel@tonic-gate u *= 256; 8787c478bd9Sstevel@tonic-gate } 8797c478bd9Sstevel@tonic-gate if (u < num2) { 8807c478bd9Sstevel@tonic-gate itm_error( 8817c478bd9Sstevel@tonic-gate gettext("length of source is too long for " 8827c478bd9Sstevel@tonic-gate "binary search: %ld\n"), 8837c478bd9Sstevel@tonic-gate source_len); 8847c478bd9Sstevel@tonic-gate error_deferred += 1; 8857c478bd9Sstevel@tonic-gate return (NULL); 8867c478bd9Sstevel@tonic-gate } 8877c478bd9Sstevel@tonic-gate break; 8887c478bd9Sstevel@tonic-gate default: 8897c478bd9Sstevel@tonic-gate break; 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate switch (map_type) { 8927c478bd9Sstevel@tonic-gate case ITMC_MAP_SIMPLE_INDEX: 8937c478bd9Sstevel@tonic-gate table = map_table_indexed_fixed( 8947c478bd9Sstevel@tonic-gate tpp, num, default_data, 8957c478bd9Sstevel@tonic-gate result_len, error_count); 8967c478bd9Sstevel@tonic-gate break; 8977c478bd9Sstevel@tonic-gate case ITMC_MAP_SIMPLE_HASH: 8987c478bd9Sstevel@tonic-gate table = map_table_hash(tpp, num, default_data, 8997c478bd9Sstevel@tonic-gate hash_factor, result_len, num2, 9007c478bd9Sstevel@tonic-gate error_count); 9017c478bd9Sstevel@tonic-gate break; 9027c478bd9Sstevel@tonic-gate case ITMC_MAP_DENSE_ENCODING: 9037c478bd9Sstevel@tonic-gate table = map_table_dense_encoding(tpp, num, 9047c478bd9Sstevel@tonic-gate default_data, 9057c478bd9Sstevel@tonic-gate dense_encoded_map_ent, 9067c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max, 9077c478bd9Sstevel@tonic-gate result_len, error_count); 9087c478bd9Sstevel@tonic-gate break; 9097c478bd9Sstevel@tonic-gate case ITMC_MAP_BINARY_SEARCH: 9107c478bd9Sstevel@tonic-gate table = map_table_lookup_fixed(tpp, num, 9117c478bd9Sstevel@tonic-gate default_data, 9127c478bd9Sstevel@tonic-gate result_len, num2); 9137c478bd9Sstevel@tonic-gate break; 9147c478bd9Sstevel@tonic-gate } 9157c478bd9Sstevel@tonic-gate } else { 9167c478bd9Sstevel@tonic-gate table = map_table_lookup_var(); 9177c478bd9Sstevel@tonic-gate } 9187c478bd9Sstevel@tonic-gate 9197c478bd9Sstevel@tonic-gate if ((NULL != name) && (NULL != table)) { 9207c478bd9Sstevel@tonic-gate table->name.itm_ptr = (itm_place2_t)name; 9217c478bd9Sstevel@tonic-gate } 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate return (table); 9247c478bd9Sstevel@tonic-gate } 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate static itmc_map_type_t 9287c478bd9Sstevel@tonic-gate check_map_type(itmc_map_attr_t *attr) 9297c478bd9Sstevel@tonic-gate { 9307c478bd9Sstevel@tonic-gate int i; 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate if (NULL == attr->type) { 9337c478bd9Sstevel@tonic-gate return (0); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate for (i = 0; NULL != map_type_name[i].name; i++) { 9367c478bd9Sstevel@tonic-gate if (0 == strncmp(((char *)&(attr->type->place)), 9377c478bd9Sstevel@tonic-gate map_type_name[i].name, attr->type->size)) { 9387c478bd9Sstevel@tonic-gate return (map_type_name[i].type); 9397c478bd9Sstevel@tonic-gate } 9407c478bd9Sstevel@tonic-gate } 9417c478bd9Sstevel@tonic-gate return (0); 9427c478bd9Sstevel@tonic-gate } 9437c478bd9Sstevel@tonic-gate 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t * 9467c478bd9Sstevel@tonic-gate map_table_indexed_fixed( 9477c478bd9Sstevel@tonic-gate itmc_data_pair_t **tpp, 9487c478bd9Sstevel@tonic-gate itm_size_t num, 9497c478bd9Sstevel@tonic-gate itm_data_t *default_data, 9507c478bd9Sstevel@tonic-gate long resultlen, 9517c478bd9Sstevel@tonic-gate itm_num_t error_count) 9527c478bd9Sstevel@tonic-gate { 9537c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *header; 9547c478bd9Sstevel@tonic-gate itm_map_idx_fix_hdr_t *sub_hdr; 9557c478bd9Sstevel@tonic-gate char *table; 9567c478bd9Sstevel@tonic-gate char *error_table; 9577c478bd9Sstevel@tonic-gate itm_size_t source_start; 9587c478bd9Sstevel@tonic-gate itm_size_t source_end; 9597c478bd9Sstevel@tonic-gate itm_size_t entry_num; 9607c478bd9Sstevel@tonic-gate itm_size_t table_size; 9617c478bd9Sstevel@tonic-gate itm_size_t j; 9627c478bd9Sstevel@tonic-gate itm_size_t i; 9637c478bd9Sstevel@tonic-gate itm_size_t k; 9647c478bd9Sstevel@tonic-gate char *p; 9657c478bd9Sstevel@tonic-gate itm_data_t *source; 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("map_table_range : %ld\n", num)); 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate source = &((*(tpp + 0))->data0); 9707c478bd9Sstevel@tonic-gate assert((sizeof (itm_place_t)) >= source->size); 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate if ((1 == source->size) && 9737c478bd9Sstevel@tonic-gate (1 == resultlen)) { 9747c478bd9Sstevel@tonic-gate source_start = 0; 9757c478bd9Sstevel@tonic-gate source_end = 255; 9767c478bd9Sstevel@tonic-gate } else { 9777c478bd9Sstevel@tonic-gate source_start = data_to_long(&((*(tpp + 0))->data0)); 9787c478bd9Sstevel@tonic-gate source_end = data_to_long(&((*(tpp + num - 1))->data0)); 9797c478bd9Sstevel@tonic-gate if (0 < (*(tpp + num - 1))->range.size) 9807c478bd9Sstevel@tonic-gate source_end = data_to_long(&((*(tpp + num - 1))->range)); 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate entry_num = source_end - source_start + 1; 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate table_size = ((sizeof (itm_tbl_hdr_t)) + 9867c478bd9Sstevel@tonic-gate (sizeof (itm_map_idx_fix_hdr_t)) + 9877c478bd9Sstevel@tonic-gate (resultlen * entry_num)); 9887c478bd9Sstevel@tonic-gate if (0 < error_count) { 9897c478bd9Sstevel@tonic-gate table_size += entry_num; 9907c478bd9Sstevel@tonic-gate } 9917c478bd9Sstevel@tonic-gate if (NULL == default_data) { 9927c478bd9Sstevel@tonic-gate if ((num < entry_num) || 9937c478bd9Sstevel@tonic-gate (error_count <= 0)) { 9947c478bd9Sstevel@tonic-gate table_size += entry_num; 9957c478bd9Sstevel@tonic-gate } 9967c478bd9Sstevel@tonic-gate } else if ((itm_data_t *)(-1) != default_data) { 9977c478bd9Sstevel@tonic-gate table_size += resultlen; 9987c478bd9Sstevel@tonic-gate } 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate table_size = ITMROUNDUP(table_size); 10017c478bd9Sstevel@tonic-gate header = malloc_vital(table_size); 10027c478bd9Sstevel@tonic-gate sub_hdr = (itm_map_idx_fix_hdr_t *)(header + 1); 10037c478bd9Sstevel@tonic-gate table = (char *)(sub_hdr + 1); 10047c478bd9Sstevel@tonic-gate 10057c478bd9Sstevel@tonic-gate if ((1 == (*tpp)->data0.size) && 10067c478bd9Sstevel@tonic-gate (1 == (*tpp)->data1.size)) { 10077c478bd9Sstevel@tonic-gate header->type = ITM_TBL_MAP_INDEX_FIXED_1_1; 10087c478bd9Sstevel@tonic-gate } else { 10097c478bd9Sstevel@tonic-gate header->type = ITM_TBL_MAP_INDEX_FIXED; 10107c478bd9Sstevel@tonic-gate } 10117c478bd9Sstevel@tonic-gate header->name.itm_ptr = 0; 10127c478bd9Sstevel@tonic-gate header->size = table_size; 10137c478bd9Sstevel@tonic-gate header->number = entry_num; 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate sub_hdr->source_len = (*tpp)->data0.size; 10167c478bd9Sstevel@tonic-gate sub_hdr->result_len = resultlen; 10177c478bd9Sstevel@tonic-gate sub_hdr->start.itm_ptr = source_start; 10187c478bd9Sstevel@tonic-gate sub_hdr->end.itm_ptr = source_end; 10197c478bd9Sstevel@tonic-gate sub_hdr->error_num = error_count; /* > 0; so pad4 = 0 */ 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate if (NULL != default_data) { 10227c478bd9Sstevel@tonic-gate if ((itm_data_t *)(-1) == default_data) { 10237c478bd9Sstevel@tonic-gate sub_hdr->default_error = -1; 10247c478bd9Sstevel@tonic-gate #if !defined(_LP64) 10257c478bd9Sstevel@tonic-gate sub_hdr->pad3_num = (pad_t)(~0); 10267c478bd9Sstevel@tonic-gate #endif 10277c478bd9Sstevel@tonic-gate } else { 10287c478bd9Sstevel@tonic-gate sub_hdr->default_error = 0; 10297c478bd9Sstevel@tonic-gate } 10307c478bd9Sstevel@tonic-gate } else { 10317c478bd9Sstevel@tonic-gate if (num < entry_num) { 10327c478bd9Sstevel@tonic-gate sub_hdr->default_error = 1; 10337c478bd9Sstevel@tonic-gate } else { 10347c478bd9Sstevel@tonic-gate sub_hdr->default_error = 2; 10357c478bd9Sstevel@tonic-gate } 10367c478bd9Sstevel@tonic-gate } 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate error_table = (table + (resultlen * entry_num)); 10397c478bd9Sstevel@tonic-gate if (-1 == sub_hdr->default_error) { 10407c478bd9Sstevel@tonic-gate if (source->size != resultlen) { 10417c478bd9Sstevel@tonic-gate itm_error( 10427c478bd9Sstevel@tonic-gate gettext("\"default no_change_copy\" is " 10437c478bd9Sstevel@tonic-gate "specified, but size does not match\n")); 10447c478bd9Sstevel@tonic-gate exit(ITMC_STATUS_BT); 10457c478bd9Sstevel@tonic-gate } 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate for (i = 0, j = 0; 10487c478bd9Sstevel@tonic-gate i < (entry_num); 10497c478bd9Sstevel@tonic-gate i++, j += resultlen) { 10507c478bd9Sstevel@tonic-gate for (k = 0; k < resultlen; k++) { 10517c478bd9Sstevel@tonic-gate *(table + j + k) = 10527c478bd9Sstevel@tonic-gate (((source_start + i) >> 10537c478bd9Sstevel@tonic-gate ((resultlen - k - 1) * 8)) & 10547c478bd9Sstevel@tonic-gate 0x00ff); 10557c478bd9Sstevel@tonic-gate } 10567c478bd9Sstevel@tonic-gate } 10577c478bd9Sstevel@tonic-gate } else if (0 == sub_hdr->default_error) { 10587c478bd9Sstevel@tonic-gate error_table += resultlen; 10597c478bd9Sstevel@tonic-gate if (default_data->size <= (sizeof (itm_place_t))) { 10607c478bd9Sstevel@tonic-gate for (i = 0, j = 0; 10617c478bd9Sstevel@tonic-gate i < (entry_num + 1); /* last one is for default */ 10627c478bd9Sstevel@tonic-gate i++, j += resultlen) { 10637c478bd9Sstevel@tonic-gate (void) memcpy(table + j + 10647c478bd9Sstevel@tonic-gate (resultlen - default_data->size), 10657c478bd9Sstevel@tonic-gate (void *)(&(default_data->place.itm_64d)), 10667c478bd9Sstevel@tonic-gate default_data->size); 10677c478bd9Sstevel@tonic-gate } 10687c478bd9Sstevel@tonic-gate } else { 10697c478bd9Sstevel@tonic-gate for (i = 0, j = 0; 10707c478bd9Sstevel@tonic-gate i < (entry_num + 1); /* last one is for default */ 10717c478bd9Sstevel@tonic-gate i++, j += resultlen) { 10727c478bd9Sstevel@tonic-gate (void) memcpy(table + j + 10737c478bd9Sstevel@tonic-gate (resultlen - default_data->size), 10747c478bd9Sstevel@tonic-gate (void *)(default_data->place.itm_ptr), 10757c478bd9Sstevel@tonic-gate default_data->size); 10767c478bd9Sstevel@tonic-gate } 10777c478bd9Sstevel@tonic-gate } 10787c478bd9Sstevel@tonic-gate } 10797c478bd9Sstevel@tonic-gate if (1 == sub_hdr->default_error) { 10807c478bd9Sstevel@tonic-gate (void) memset(error_table, 1, entry_num); 10817c478bd9Sstevel@tonic-gate for (i = 0; i < num; i++) { 10827c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 10837c478bd9Sstevel@tonic-gate continue; /* error sequence */ 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate j = data_to_long(&((*(tpp + i))->data0)) - 10867c478bd9Sstevel@tonic-gate source_start; 10877c478bd9Sstevel@tonic-gate k = ((*(tpp + i))->range.size) == 0 ? j : 10887c478bd9Sstevel@tonic-gate data_to_long(&((*(tpp + i))->range)) - 10897c478bd9Sstevel@tonic-gate source_start; 10907c478bd9Sstevel@tonic-gate for (; j <= k; j++) { 10917c478bd9Sstevel@tonic-gate *(error_table + j) = 0; 10927c478bd9Sstevel@tonic-gate } 10937c478bd9Sstevel@tonic-gate } 10947c478bd9Sstevel@tonic-gate } else if (0 < error_count) { 10957c478bd9Sstevel@tonic-gate (void) memset(error_table, 0, entry_num); 10967c478bd9Sstevel@tonic-gate for (i = 0; i < num; i++) { 10977c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 10987c478bd9Sstevel@tonic-gate /* error sequence */ 10997c478bd9Sstevel@tonic-gate j = data_to_long(&((*(tpp + i))->data0)) - 11007c478bd9Sstevel@tonic-gate source_start; 11017c478bd9Sstevel@tonic-gate k = ((*(tpp + i))->range.size) == 0 ? j : 11027c478bd9Sstevel@tonic-gate data_to_long(&((*(tpp + i))->range)) - 11037c478bd9Sstevel@tonic-gate source_start; 11047c478bd9Sstevel@tonic-gate for (; j <= k; j++) { 11057c478bd9Sstevel@tonic-gate *(error_table + j) = 1; 11067c478bd9Sstevel@tonic-gate } 11077c478bd9Sstevel@tonic-gate } 11087c478bd9Sstevel@tonic-gate } 11097c478bd9Sstevel@tonic-gate } 11107c478bd9Sstevel@tonic-gate 11117c478bd9Sstevel@tonic-gate p = malloc_vital(sizeof (uchar_t *) * resultlen); 11127c478bd9Sstevel@tonic-gate for (i = 0; i < num; i++) { 11137c478bd9Sstevel@tonic-gate j = data_to_long(&((*(tpp + i))->data0)) - source_start; 11147c478bd9Sstevel@tonic-gate if (0 != (*(tpp + i))->range.size) 11157c478bd9Sstevel@tonic-gate k = data_to_long(&((*(tpp + i))->range)) - 11167c478bd9Sstevel@tonic-gate source_start; 11177c478bd9Sstevel@tonic-gate else 11187c478bd9Sstevel@tonic-gate k = j; 11197c478bd9Sstevel@tonic-gate (void) memset(p, 0, sizeof (uchar_t *) * resultlen); 11207c478bd9Sstevel@tonic-gate (void) memcpy(p + (resultlen - (*(tpp + i))->data1.size), 11217c478bd9Sstevel@tonic-gate ((caddr_t)NSPTR(&((*(tpp + i))->data1))), 11227c478bd9Sstevel@tonic-gate (*(tpp + i))->data1.size); 11237c478bd9Sstevel@tonic-gate map_range_make_result(table, j, k, p, resultlen); 11247c478bd9Sstevel@tonic-gate } 11257c478bd9Sstevel@tonic-gate free(p); 11267c478bd9Sstevel@tonic-gate 11277c478bd9Sstevel@tonic-gate return (header); 11287c478bd9Sstevel@tonic-gate } 11297c478bd9Sstevel@tonic-gate 11307c478bd9Sstevel@tonic-gate 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate 11337c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t * 11347c478bd9Sstevel@tonic-gate map_table_lookup_fixed( 11357c478bd9Sstevel@tonic-gate itmc_data_pair_t **tpp, 11367c478bd9Sstevel@tonic-gate itm_size_t num, 11377c478bd9Sstevel@tonic-gate itm_data_t *default_data, 11387c478bd9Sstevel@tonic-gate long resultlen, 11397c478bd9Sstevel@tonic-gate itm_size_t num2) 11407c478bd9Sstevel@tonic-gate { 11417c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *header; 11427c478bd9Sstevel@tonic-gate itm_map_lookup_hdr_t *sub_hdr; 11437c478bd9Sstevel@tonic-gate char *table; 11447c478bd9Sstevel@tonic-gate itm_size_t table_size; 11457c478bd9Sstevel@tonic-gate itm_size_t j; 11467c478bd9Sstevel@tonic-gate itm_size_t i; 11477c478bd9Sstevel@tonic-gate itm_size_t k; 11487c478bd9Sstevel@tonic-gate itm_size_t h; 11497c478bd9Sstevel@tonic-gate itm_data_t *source; 11507c478bd9Sstevel@tonic-gate uchar_t *source_data; 11517c478bd9Sstevel@tonic-gate uchar_t *result_data; 11527c478bd9Sstevel@tonic-gate 11537c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("map_table_lookup_fixed : %ld(%ld) 0x%lx\n", 11547c478bd9Sstevel@tonic-gate num, num2, default_data)); 11557c478bd9Sstevel@tonic-gate 11567c478bd9Sstevel@tonic-gate source = &((*(tpp + 0))->data0); 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate table_size = ((sizeof (itm_tbl_hdr_t)) + 11597c478bd9Sstevel@tonic-gate (sizeof (itm_map_idx_fix_hdr_t)) + 11607c478bd9Sstevel@tonic-gate ((source->size + 1 + resultlen) * num2)); 11617c478bd9Sstevel@tonic-gate if ((NULL != default_data) && 11627c478bd9Sstevel@tonic-gate (((itm_data_t *)(-1)) != default_data)) { 11637c478bd9Sstevel@tonic-gate table_size += (source->size + 1 + resultlen); 11647c478bd9Sstevel@tonic-gate } 11657c478bd9Sstevel@tonic-gate table_size = ITMROUNDUP(table_size); 11667c478bd9Sstevel@tonic-gate header = malloc_vital(table_size); 11677c478bd9Sstevel@tonic-gate sub_hdr = (itm_map_lookup_hdr_t *)(header + 1); 11687c478bd9Sstevel@tonic-gate table = (char *)(sub_hdr + 1); 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate header->type = ITM_TBL_MAP_LOOKUP; 11717c478bd9Sstevel@tonic-gate header->name.itm_ptr = 0; 11727c478bd9Sstevel@tonic-gate header->size = table_size; 11737c478bd9Sstevel@tonic-gate header->number = num2; 11747c478bd9Sstevel@tonic-gate if (NULL != default_data) { 11757c478bd9Sstevel@tonic-gate if ((itm_data_t *)(-1) == default_data) { 11767c478bd9Sstevel@tonic-gate #if !defined(_LP64) 11777c478bd9Sstevel@tonic-gate sub_hdr->pad3_num = (pad_t)(~0); 11787c478bd9Sstevel@tonic-gate #endif 11797c478bd9Sstevel@tonic-gate sub_hdr->default_error = -1; 11807c478bd9Sstevel@tonic-gate } else { 11817c478bd9Sstevel@tonic-gate sub_hdr->default_error = 0; 11827c478bd9Sstevel@tonic-gate } 11837c478bd9Sstevel@tonic-gate } else { 11847c478bd9Sstevel@tonic-gate sub_hdr->default_error = 2; 11857c478bd9Sstevel@tonic-gate } 11867c478bd9Sstevel@tonic-gate 11877c478bd9Sstevel@tonic-gate sub_hdr->source_len = source->size; 11887c478bd9Sstevel@tonic-gate sub_hdr->result_len = resultlen; 11897c478bd9Sstevel@tonic-gate 11907c478bd9Sstevel@tonic-gate /* specified map */ 11917c478bd9Sstevel@tonic-gate source_data = malloc_vital(source->size); 11927c478bd9Sstevel@tonic-gate result_data = malloc_vital(resultlen); 11937c478bd9Sstevel@tonic-gate for (i = 0, j = 0; i < num; i++) { 11947c478bd9Sstevel@tonic-gate (void) memcpy(table + j, 11957c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data0)), source->size); 11967c478bd9Sstevel@tonic-gate j += source->size; 11977c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 11987c478bd9Sstevel@tonic-gate *(table + j) = 1; /* specified error */ 11997c478bd9Sstevel@tonic-gate j += 1; 12007c478bd9Sstevel@tonic-gate } else { 12017c478bd9Sstevel@tonic-gate /* *(table + j) = 0; ** valid */ 12027c478bd9Sstevel@tonic-gate j += 1; 12037c478bd9Sstevel@tonic-gate (void) memcpy(table + j + 12047c478bd9Sstevel@tonic-gate (resultlen - (*(tpp + i))->data1.size), 12057c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data1)), 12067c478bd9Sstevel@tonic-gate (*(tpp + i))->data1.size); 12077c478bd9Sstevel@tonic-gate } 12087c478bd9Sstevel@tonic-gate j += resultlen; 12097c478bd9Sstevel@tonic-gate 12107c478bd9Sstevel@tonic-gate if ((*(tpp + i))->range.size != 0) { 12117c478bd9Sstevel@tonic-gate (void) memcpy(source_data, 12127c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data0)), 12137c478bd9Sstevel@tonic-gate source->size); 12147c478bd9Sstevel@tonic-gate (void) memset(result_data, 0, resultlen); 12157c478bd9Sstevel@tonic-gate (void) memcpy(result_data + 12167c478bd9Sstevel@tonic-gate (resultlen - (*(tpp + i))->data1.size), 12177c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data1)), 12187c478bd9Sstevel@tonic-gate (*(tpp + i))->data1.size); 12197c478bd9Sstevel@tonic-gate h = map_table_num_range((*(tpp + i))); 12207c478bd9Sstevel@tonic-gate for (k = 0; k < h; k++) { 12217c478bd9Sstevel@tonic-gate uchar_t *dp; 12227c478bd9Sstevel@tonic-gate itm_size_t m; 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate for (m = 0, 12257c478bd9Sstevel@tonic-gate dp = (uchar_t *) 12267c478bd9Sstevel@tonic-gate (source_data + source->size - 1); 12277c478bd9Sstevel@tonic-gate m < source->size; 12287c478bd9Sstevel@tonic-gate m++, dp--) { 12297c478bd9Sstevel@tonic-gate if (0xff != *dp) { 12307c478bd9Sstevel@tonic-gate (*dp) += (char)1; 12317c478bd9Sstevel@tonic-gate for (++dp; m > 0; m--, dp++) { 12327c478bd9Sstevel@tonic-gate (*dp) = 0x00; 12337c478bd9Sstevel@tonic-gate } 12347c478bd9Sstevel@tonic-gate break; 12357c478bd9Sstevel@tonic-gate } 12367c478bd9Sstevel@tonic-gate } 12377c478bd9Sstevel@tonic-gate (void) memcpy(table + j, 12387c478bd9Sstevel@tonic-gate source_data, source->size); 12397c478bd9Sstevel@tonic-gate j += source->size; 12407c478bd9Sstevel@tonic-gate 12417c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 12427c478bd9Sstevel@tonic-gate *(table + j) = 1; /* specified error */ 12437c478bd9Sstevel@tonic-gate j += 1; 12447c478bd9Sstevel@tonic-gate } else { 12457c478bd9Sstevel@tonic-gate /* *(table + j) = 0; ** valid */ 12467c478bd9Sstevel@tonic-gate j += 1; 12477c478bd9Sstevel@tonic-gate for (m = 0, dp = (uchar_t *) 12487c478bd9Sstevel@tonic-gate (result_data + resultlen - 1); 12497c478bd9Sstevel@tonic-gate m < resultlen; 12507c478bd9Sstevel@tonic-gate m++, dp--) { 12517c478bd9Sstevel@tonic-gate if (0xff != *dp) { 12527c478bd9Sstevel@tonic-gate (*dp) += 1; 12537c478bd9Sstevel@tonic-gate for (++dp; 12547c478bd9Sstevel@tonic-gate m > 0; 12557c478bd9Sstevel@tonic-gate m--, dp++) { 12567c478bd9Sstevel@tonic-gate (*dp) = 0x00; 12577c478bd9Sstevel@tonic-gate } 12587c478bd9Sstevel@tonic-gate break; 12597c478bd9Sstevel@tonic-gate } 12607c478bd9Sstevel@tonic-gate } 12617c478bd9Sstevel@tonic-gate (void) memcpy(table + j, result_data, 12627c478bd9Sstevel@tonic-gate resultlen); 12637c478bd9Sstevel@tonic-gate } 12647c478bd9Sstevel@tonic-gate j += resultlen; 12657c478bd9Sstevel@tonic-gate } 12667c478bd9Sstevel@tonic-gate } 12677c478bd9Sstevel@tonic-gate } 12687c478bd9Sstevel@tonic-gate free(source_data); 12697c478bd9Sstevel@tonic-gate free(result_data); 12707c478bd9Sstevel@tonic-gate 12717c478bd9Sstevel@tonic-gate /* default */ 12727c478bd9Sstevel@tonic-gate if ((NULL != default_data) && 12737c478bd9Sstevel@tonic-gate (((itm_data_t *)(-1)) != default_data)) { 12747c478bd9Sstevel@tonic-gate (void) memset(table + j, 0, source->size + 1 + resultlen); 12757c478bd9Sstevel@tonic-gate (void) memcpy(table + j + source->size + 1 + 12767c478bd9Sstevel@tonic-gate (resultlen - default_data->size), 12777c478bd9Sstevel@tonic-gate NSPTR(default_data), default_data->size); 12787c478bd9Sstevel@tonic-gate } 12797c478bd9Sstevel@tonic-gate return (header); 12807c478bd9Sstevel@tonic-gate } 12817c478bd9Sstevel@tonic-gate 12827c478bd9Sstevel@tonic-gate 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t * 12867c478bd9Sstevel@tonic-gate map_table_hash( 12877c478bd9Sstevel@tonic-gate itmc_data_pair_t **tpp, 12887c478bd9Sstevel@tonic-gate itm_size_t num, 12897c478bd9Sstevel@tonic-gate itm_data_t *default_data, 12907c478bd9Sstevel@tonic-gate long hash_factor, 12917c478bd9Sstevel@tonic-gate long resultlen, 12927c478bd9Sstevel@tonic-gate itm_size_t num2, 12937c478bd9Sstevel@tonic-gate itm_num_t error_count) 12947c478bd9Sstevel@tonic-gate { 12957c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *header; 12967c478bd9Sstevel@tonic-gate itm_map_hash_hdr_t *sub_hdr; 12977c478bd9Sstevel@tonic-gate itm_size_t table_size; 12987c478bd9Sstevel@tonic-gate char *error_table; 12997c478bd9Sstevel@tonic-gate char *hash_table; 13007c478bd9Sstevel@tonic-gate itm_size_t hash_table_num; 13017c478bd9Sstevel@tonic-gate char *of_table; 13027c478bd9Sstevel@tonic-gate itm_size_t of_table_num; 13037c478bd9Sstevel@tonic-gate itm_size_t pair_size; 13047c478bd9Sstevel@tonic-gate itm_size_t i; 13057c478bd9Sstevel@tonic-gate itm_size_t j; 13067c478bd9Sstevel@tonic-gate itm_size_t k; 13077c478bd9Sstevel@tonic-gate char *p; 13087c478bd9Sstevel@tonic-gate itm_data_t *source; 13097c478bd9Sstevel@tonic-gate long hash_value; 13107c478bd9Sstevel@tonic-gate #if defined(DEBUG) 13117c478bd9Sstevel@tonic-gate long hash_none; 13127c478bd9Sstevel@tonic-gate long hash_one; 13137c478bd9Sstevel@tonic-gate long hash_conflict; 13147c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 13157c478bd9Sstevel@tonic-gate uchar_t *source_data; 13167c478bd9Sstevel@tonic-gate uchar_t *result_data; 13177c478bd9Sstevel@tonic-gate uchar_t *dp; 13187c478bd9Sstevel@tonic-gate itm_size_t m; 13197c478bd9Sstevel@tonic-gate itm_size_t n; 13207c478bd9Sstevel@tonic-gate itm_size_t h; 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("map_table_hash : %ld(%ld) 0x%lx\n", 13237c478bd9Sstevel@tonic-gate num, num2, default_data)); 13247c478bd9Sstevel@tonic-gate source = &((*(tpp + 0))->data0); 13257c478bd9Sstevel@tonic-gate pair_size = (source->size + 1 + resultlen); 13267c478bd9Sstevel@tonic-gate 13277c478bd9Sstevel@tonic-gate if (100 <= hash_factor) { 13287c478bd9Sstevel@tonic-gate hash_table_num = (num2 * (hash_factor / 100.0)); 13297c478bd9Sstevel@tonic-gate } else { 13307c478bd9Sstevel@tonic-gate hash_table_num = (num2 * 2); 13317c478bd9Sstevel@tonic-gate } 13327c478bd9Sstevel@tonic-gate if (hash_table_num < 256) { 13337c478bd9Sstevel@tonic-gate hash_table_num = 256; 13347c478bd9Sstevel@tonic-gate } 13357c478bd9Sstevel@tonic-gate source_data = malloc_vital(source->size); 13367c478bd9Sstevel@tonic-gate result_data = malloc_vital(resultlen); 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate hash_table = malloc_vital(hash_table_num); 13397c478bd9Sstevel@tonic-gate for (i = 0, of_table_num = 0; i < num; i++) { 1340*e492095eSRichard PALO hash_value = hash(NSPTR(&((*(tpp + i))->data0)), 13417c478bd9Sstevel@tonic-gate (*(tpp + i))->data0.size, 13427c478bd9Sstevel@tonic-gate hash_table_num); 13437c478bd9Sstevel@tonic-gate if (0 == *(hash_table + hash_value)) { 13447c478bd9Sstevel@tonic-gate *(hash_table + hash_value) = 1; 13457c478bd9Sstevel@tonic-gate } else { 13467c478bd9Sstevel@tonic-gate *(hash_table + hash_value) = 2; 13477c478bd9Sstevel@tonic-gate of_table_num += 1; 13487c478bd9Sstevel@tonic-gate } 13497c478bd9Sstevel@tonic-gate 13507c478bd9Sstevel@tonic-gate if ((*(tpp + i))->range.size != 0) { 13517c478bd9Sstevel@tonic-gate (void) memcpy(source_data, 13527c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data0)), 13537c478bd9Sstevel@tonic-gate source->size); 13547c478bd9Sstevel@tonic-gate h = map_table_num_range((*(tpp + i))); 13557c478bd9Sstevel@tonic-gate for (n = 0; n < h; n++) { 13567c478bd9Sstevel@tonic-gate for (m = 0, 13577c478bd9Sstevel@tonic-gate dp = (uchar_t *) 13587c478bd9Sstevel@tonic-gate (source_data + source->size - 1); 13597c478bd9Sstevel@tonic-gate m < source->size; 13607c478bd9Sstevel@tonic-gate m++, dp--) { 13617c478bd9Sstevel@tonic-gate if (0xff != *dp) { 13627c478bd9Sstevel@tonic-gate (*dp) += 1; 13637c478bd9Sstevel@tonic-gate for (++dp; m > 0; m--, dp++) { 13647c478bd9Sstevel@tonic-gate (*dp) = 0x00; 13657c478bd9Sstevel@tonic-gate } 13667c478bd9Sstevel@tonic-gate break; 13677c478bd9Sstevel@tonic-gate } 13687c478bd9Sstevel@tonic-gate } 1369*e492095eSRichard PALO hash_value = hash((char *)source_data, 1370*e492095eSRichard PALO source->size, 13717c478bd9Sstevel@tonic-gate hash_table_num); 13727c478bd9Sstevel@tonic-gate 13737c478bd9Sstevel@tonic-gate if (0 == *(hash_table + hash_value)) { 13747c478bd9Sstevel@tonic-gate *(hash_table + hash_value) = 1; 13757c478bd9Sstevel@tonic-gate } else { 13767c478bd9Sstevel@tonic-gate *(hash_table + hash_value) = 2; 13777c478bd9Sstevel@tonic-gate of_table_num += 1; 13787c478bd9Sstevel@tonic-gate } 13797c478bd9Sstevel@tonic-gate } 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate } 13827c478bd9Sstevel@tonic-gate 13837c478bd9Sstevel@tonic-gate #if defined(DEBUG) 13847c478bd9Sstevel@tonic-gate if (TRACE('s')) { 13857c478bd9Sstevel@tonic-gate hash_none = 0; 13867c478bd9Sstevel@tonic-gate hash_one = 0; 13877c478bd9Sstevel@tonic-gate hash_conflict = 0; 13887c478bd9Sstevel@tonic-gate j = 0; 13897c478bd9Sstevel@tonic-gate for (i = 0; i < hash_table_num; i++) { 13907c478bd9Sstevel@tonic-gate if (2 == *(hash_table + i)) { 13917c478bd9Sstevel@tonic-gate (void) putchar('2'); 13927c478bd9Sstevel@tonic-gate hash_conflict += 1; 13937c478bd9Sstevel@tonic-gate } else if (1 == *(hash_table + i)) { 13947c478bd9Sstevel@tonic-gate (void) putchar('1'); 13957c478bd9Sstevel@tonic-gate hash_one += 1; 13967c478bd9Sstevel@tonic-gate } else if (0 == *(hash_table + i)) { 13977c478bd9Sstevel@tonic-gate (void) putchar('-'); 13987c478bd9Sstevel@tonic-gate hash_none += 1; 13997c478bd9Sstevel@tonic-gate } else { 14007c478bd9Sstevel@tonic-gate (void) putchar('*'); 14017c478bd9Sstevel@tonic-gate } 14027c478bd9Sstevel@tonic-gate if (63 <= j) { 14037c478bd9Sstevel@tonic-gate j = 0; 14047c478bd9Sstevel@tonic-gate (void) putchar('\n'); 14057c478bd9Sstevel@tonic-gate } else { 14067c478bd9Sstevel@tonic-gate j += 1; 14077c478bd9Sstevel@tonic-gate } 14087c478bd9Sstevel@tonic-gate } 14097c478bd9Sstevel@tonic-gate (void) putchar('\n'); 14107c478bd9Sstevel@tonic-gate (void) printf("null=%ld one=%ld conflict=%ld\n", 14117c478bd9Sstevel@tonic-gate hash_none, hash_one, hash_conflict); 14127c478bd9Sstevel@tonic-gate } 14137c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 14147c478bd9Sstevel@tonic-gate 14157c478bd9Sstevel@tonic-gate free(hash_table); 14167c478bd9Sstevel@tonic-gate table_size = ((sizeof (itm_tbl_hdr_t)) + 14177c478bd9Sstevel@tonic-gate (sizeof (itm_map_hash_hdr_t)) + 14187c478bd9Sstevel@tonic-gate (hash_table_num) + 14197c478bd9Sstevel@tonic-gate (pair_size * hash_table_num) + 14207c478bd9Sstevel@tonic-gate (pair_size * of_table_num)); 14217c478bd9Sstevel@tonic-gate if ((NULL != default_data) && 14227c478bd9Sstevel@tonic-gate (((itm_data_t *)(-1)) != default_data)) { 14237c478bd9Sstevel@tonic-gate table_size += pair_size; 14247c478bd9Sstevel@tonic-gate } 14257c478bd9Sstevel@tonic-gate table_size = ITMROUNDUP(table_size); 14267c478bd9Sstevel@tonic-gate header = malloc_vital(table_size); 14277c478bd9Sstevel@tonic-gate sub_hdr = (itm_map_hash_hdr_t *)(header + 1); 14287c478bd9Sstevel@tonic-gate error_table = (char *)(sub_hdr + 1); 14297c478bd9Sstevel@tonic-gate hash_table = error_table + hash_table_num; 14307c478bd9Sstevel@tonic-gate of_table = hash_table + (pair_size * hash_table_num); 14317c478bd9Sstevel@tonic-gate 14327c478bd9Sstevel@tonic-gate header->type = ITM_TBL_MAP_HASH; 14337c478bd9Sstevel@tonic-gate header->name.itm_ptr = 0; 14347c478bd9Sstevel@tonic-gate header->size = table_size; 14357c478bd9Sstevel@tonic-gate header->number = num2; 14367c478bd9Sstevel@tonic-gate if (NULL != default_data) { 14377c478bd9Sstevel@tonic-gate if ((itm_data_t *)(-1) == default_data) { 14387c478bd9Sstevel@tonic-gate sub_hdr->default_error = -1; 14397c478bd9Sstevel@tonic-gate #if !defined(_LP64) 14407c478bd9Sstevel@tonic-gate sub_hdr->pad7_num = (pad_t)(~0); 14417c478bd9Sstevel@tonic-gate #endif 14427c478bd9Sstevel@tonic-gate } else { 14437c478bd9Sstevel@tonic-gate sub_hdr->default_error = 0; 14447c478bd9Sstevel@tonic-gate } 14457c478bd9Sstevel@tonic-gate } else { 14467c478bd9Sstevel@tonic-gate sub_hdr->default_error = 2; 14477c478bd9Sstevel@tonic-gate } 14487c478bd9Sstevel@tonic-gate 14497c478bd9Sstevel@tonic-gate sub_hdr->source_len = source->size; 14507c478bd9Sstevel@tonic-gate sub_hdr->result_len = resultlen; 14517c478bd9Sstevel@tonic-gate sub_hdr->hash_tbl_size = (pair_size * hash_table_num); 14527c478bd9Sstevel@tonic-gate sub_hdr->hash_tbl_num = hash_table_num; 14537c478bd9Sstevel@tonic-gate sub_hdr->hash_of_size = 14547c478bd9Sstevel@tonic-gate (pair_size * of_table_num); 14557c478bd9Sstevel@tonic-gate sub_hdr->hash_of_num = of_table_num; 14567c478bd9Sstevel@tonic-gate sub_hdr->error_num = error_count; /* > 0; so pad4 = 0 */ 14577c478bd9Sstevel@tonic-gate 14587c478bd9Sstevel@tonic-gate /* specified map */ 14597c478bd9Sstevel@tonic-gate for (i = 0, j = 0, k = 0; i < num; i++) { 1460*e492095eSRichard PALO hash_value = hash(NSPTR(&((*(tpp + i))->data0)), 14617c478bd9Sstevel@tonic-gate (*(tpp + i))->data0.size, 14627c478bd9Sstevel@tonic-gate hash_table_num); 14637c478bd9Sstevel@tonic-gate p = error_table + hash_value; 14647c478bd9Sstevel@tonic-gate if (*p) { /* conflict */ 14657c478bd9Sstevel@tonic-gate if (*p < 63) { 14667c478bd9Sstevel@tonic-gate *p += 1; 14677c478bd9Sstevel@tonic-gate } 14687c478bd9Sstevel@tonic-gate p = of_table + k; 14697c478bd9Sstevel@tonic-gate k += pair_size; 14707c478bd9Sstevel@tonic-gate } else { 14717c478bd9Sstevel@tonic-gate *p = 1; 14727c478bd9Sstevel@tonic-gate p = hash_table + (pair_size * hash_value); 14737c478bd9Sstevel@tonic-gate } 14747c478bd9Sstevel@tonic-gate 14757c478bd9Sstevel@tonic-gate (void) memcpy(p, NSPTR(&((*(tpp + i))->data0)), source->size); 14767c478bd9Sstevel@tonic-gate p += source->size; 14777c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 14787c478bd9Sstevel@tonic-gate (*p) = 1; /* specified error */ 14797c478bd9Sstevel@tonic-gate p++; 14807c478bd9Sstevel@tonic-gate } else { 14817c478bd9Sstevel@tonic-gate /* (*p) = 0; ** valid */ 14827c478bd9Sstevel@tonic-gate p++; 14837c478bd9Sstevel@tonic-gate (void) memset(p, 0, 14847c478bd9Sstevel@tonic-gate (resultlen - (*(tpp + i))->data1.size)); 14857c478bd9Sstevel@tonic-gate (void) memcpy(p + 14867c478bd9Sstevel@tonic-gate (resultlen - (*(tpp + i))->data1.size), 14877c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data1)), 14887c478bd9Sstevel@tonic-gate (*(tpp + i))->data1.size); 14897c478bd9Sstevel@tonic-gate } 14907c478bd9Sstevel@tonic-gate 14917c478bd9Sstevel@tonic-gate if ((*(tpp + i))->range.size != 0) { 14927c478bd9Sstevel@tonic-gate (void) memcpy(source_data, 14937c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data0)), 14947c478bd9Sstevel@tonic-gate source->size); 14957c478bd9Sstevel@tonic-gate (void) memset(result_data, 0, 14967c478bd9Sstevel@tonic-gate (resultlen - (*(tpp + i))->data1.size)); 14977c478bd9Sstevel@tonic-gate (void) memcpy(result_data + 14987c478bd9Sstevel@tonic-gate (resultlen - (*(tpp + i))->data1.size), 14997c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data1)), 15007c478bd9Sstevel@tonic-gate (*(tpp + i))->data1.size); 15017c478bd9Sstevel@tonic-gate h = map_table_num_range((*(tpp + i))); 15027c478bd9Sstevel@tonic-gate for (n = 0; n < h; n++) { 15037c478bd9Sstevel@tonic-gate for (m = 0, 15047c478bd9Sstevel@tonic-gate dp = (uchar_t *) 15057c478bd9Sstevel@tonic-gate (source_data + source->size - 1); 15067c478bd9Sstevel@tonic-gate m < source->size; 15077c478bd9Sstevel@tonic-gate m++, dp--) { 15087c478bd9Sstevel@tonic-gate if (0xff != *dp) { 15097c478bd9Sstevel@tonic-gate (*dp) += 1; 15107c478bd9Sstevel@tonic-gate for (++dp; m > 0; m--, dp++) { 15117c478bd9Sstevel@tonic-gate (*dp) = 0x00; 15127c478bd9Sstevel@tonic-gate } 15137c478bd9Sstevel@tonic-gate break; 15147c478bd9Sstevel@tonic-gate } 15157c478bd9Sstevel@tonic-gate } 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate hash_value = hash((char *)source_data, 15187c478bd9Sstevel@tonic-gate source->size, 15197c478bd9Sstevel@tonic-gate hash_table_num); 15207c478bd9Sstevel@tonic-gate p = error_table + hash_value; 15217c478bd9Sstevel@tonic-gate if (*p) { /* conflict */ 15227c478bd9Sstevel@tonic-gate if (*p < 63) { 15237c478bd9Sstevel@tonic-gate *p += 1; 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate p = of_table + k; 15267c478bd9Sstevel@tonic-gate k += pair_size; 15277c478bd9Sstevel@tonic-gate } else { 15287c478bd9Sstevel@tonic-gate *p = 1; 15297c478bd9Sstevel@tonic-gate p = hash_table + 15307c478bd9Sstevel@tonic-gate (pair_size * hash_value); 15317c478bd9Sstevel@tonic-gate } 15327c478bd9Sstevel@tonic-gate (void) memcpy(p, source_data, source->size); 15337c478bd9Sstevel@tonic-gate p += source->size; 15347c478bd9Sstevel@tonic-gate 15357c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 15367c478bd9Sstevel@tonic-gate (*p) = 1; /* specified error */ 15377c478bd9Sstevel@tonic-gate p += 1; 15387c478bd9Sstevel@tonic-gate } else { 15397c478bd9Sstevel@tonic-gate /* (*p) = 0; ** valid */ 15407c478bd9Sstevel@tonic-gate p += 1; 15417c478bd9Sstevel@tonic-gate for (m = 0, dp = (uchar_t *) 15427c478bd9Sstevel@tonic-gate (result_data + resultlen - 1); 15437c478bd9Sstevel@tonic-gate m < resultlen; 15447c478bd9Sstevel@tonic-gate m++, dp--) { 15457c478bd9Sstevel@tonic-gate if (0xff != *dp) { 15467c478bd9Sstevel@tonic-gate (*dp) += 1; 15477c478bd9Sstevel@tonic-gate for (++dp; m > 0; 15487c478bd9Sstevel@tonic-gate m--, dp++) { 15497c478bd9Sstevel@tonic-gate (*dp) = 0x00; 15507c478bd9Sstevel@tonic-gate } 15517c478bd9Sstevel@tonic-gate break; 15527c478bd9Sstevel@tonic-gate } 15537c478bd9Sstevel@tonic-gate } 15547c478bd9Sstevel@tonic-gate (void) memcpy(p, 15557c478bd9Sstevel@tonic-gate result_data, resultlen); 15567c478bd9Sstevel@tonic-gate } 15577c478bd9Sstevel@tonic-gate } 15587c478bd9Sstevel@tonic-gate } 15597c478bd9Sstevel@tonic-gate } 15607c478bd9Sstevel@tonic-gate free(source_data); 15617c478bd9Sstevel@tonic-gate free(result_data); 15627c478bd9Sstevel@tonic-gate 15637c478bd9Sstevel@tonic-gate /* default */ 15647c478bd9Sstevel@tonic-gate if ((NULL != default_data) && 15657c478bd9Sstevel@tonic-gate (((itm_data_t *)(-1)) != default_data)) { 15667c478bd9Sstevel@tonic-gate j = ((pair_size * hash_table_num) + 15677c478bd9Sstevel@tonic-gate (pair_size * of_table_num)); 15687c478bd9Sstevel@tonic-gate (void) memcpy(hash_table + j + (resultlen - default_data->size), 15697c478bd9Sstevel@tonic-gate NSPTR(default_data), default_data->size); 15707c478bd9Sstevel@tonic-gate } 15717c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE) 15727c478bd9Sstevel@tonic-gate for (i = 0, p = of_table; i < of_table_num; i++, p += 5) { 15737c478bd9Sstevel@tonic-gate (void) printf("0x%02x%02x%02x%02x 0x%02x\n", 15747c478bd9Sstevel@tonic-gate ((unsigned char)(*(p + 0))), 15757c478bd9Sstevel@tonic-gate ((unsigned char)(*(p + 1))), 15767c478bd9Sstevel@tonic-gate ((unsigned char)(*(p + 2))), 15777c478bd9Sstevel@tonic-gate ((unsigned char)(*(p + 3))), 15787c478bd9Sstevel@tonic-gate ((unsigned char)(*(p + 4)))); 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate #endif 15817c478bd9Sstevel@tonic-gate return (header); 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate 15857c478bd9Sstevel@tonic-gate 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate static itm_tbl_hdr_t * 15887c478bd9Sstevel@tonic-gate map_table_dense_encoding( 15897c478bd9Sstevel@tonic-gate itmc_data_pair_t **tpp, 15907c478bd9Sstevel@tonic-gate itm_size_t num, 15917c478bd9Sstevel@tonic-gate itm_data_t *default_data, 15927c478bd9Sstevel@tonic-gate unsigned long entry_num, 15937c478bd9Sstevel@tonic-gate unsigned char *byte_seq_min, 15947c478bd9Sstevel@tonic-gate unsigned char *byte_seq_max, 15957c478bd9Sstevel@tonic-gate long resultlen, 15967c478bd9Sstevel@tonic-gate itm_num_t error_count) 15977c478bd9Sstevel@tonic-gate { 15987c478bd9Sstevel@tonic-gate 15997c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *header; 16007c478bd9Sstevel@tonic-gate itm_map_dense_enc_hdr_t *sub_hdr; 16017c478bd9Sstevel@tonic-gate char *table; 16027c478bd9Sstevel@tonic-gate char *error_table; 16037c478bd9Sstevel@tonic-gate itm_size_t table_size; 16047c478bd9Sstevel@tonic-gate itm_size_t j; 16057c478bd9Sstevel@tonic-gate itm_size_t i; 16067c478bd9Sstevel@tonic-gate itm_size_t k; 16077c478bd9Sstevel@tonic-gate char *p; 16087c478bd9Sstevel@tonic-gate itm_data_t *source; 16097c478bd9Sstevel@tonic-gate unsigned char *byte_seq_def; 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate TRACE_MESSAGE('m', ("map_table_dense_encoding : %ld\n", num)); 16127c478bd9Sstevel@tonic-gate 16137c478bd9Sstevel@tonic-gate source = &((*(tpp + 0))->data0); 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate 16167c478bd9Sstevel@tonic-gate table_size = ((sizeof (itm_tbl_hdr_t)) + 16177c478bd9Sstevel@tonic-gate (sizeof (itm_map_dense_enc_hdr_t)) + 16187c478bd9Sstevel@tonic-gate (source->size + source->size) + 16197c478bd9Sstevel@tonic-gate (resultlen * entry_num)); 16207c478bd9Sstevel@tonic-gate if (0 < error_count) { 16217c478bd9Sstevel@tonic-gate table_size += entry_num; 16227c478bd9Sstevel@tonic-gate } 16237c478bd9Sstevel@tonic-gate if (NULL == default_data) { 16247c478bd9Sstevel@tonic-gate if ((num < entry_num) || 16257c478bd9Sstevel@tonic-gate (error_count <= 0)) { 16267c478bd9Sstevel@tonic-gate table_size += entry_num; 16277c478bd9Sstevel@tonic-gate } 16287c478bd9Sstevel@tonic-gate } else if ((itm_data_t *)(-1) != default_data) { 16297c478bd9Sstevel@tonic-gate table_size += resultlen; 16307c478bd9Sstevel@tonic-gate } 16317c478bd9Sstevel@tonic-gate 16327c478bd9Sstevel@tonic-gate table_size = ITMROUNDUP(table_size); 16337c478bd9Sstevel@tonic-gate header = malloc_vital(table_size); 16347c478bd9Sstevel@tonic-gate sub_hdr = (itm_map_dense_enc_hdr_t *)(header + 1); 16357c478bd9Sstevel@tonic-gate table = (char *)(sub_hdr + 1) + source->size + source->size; 16367c478bd9Sstevel@tonic-gate 16377c478bd9Sstevel@tonic-gate header->type = ITM_TBL_MAP_DENSE_ENC; 16387c478bd9Sstevel@tonic-gate header->name.itm_ptr = 0; 16397c478bd9Sstevel@tonic-gate header->size = table_size; 16407c478bd9Sstevel@tonic-gate header->number = entry_num; 16417c478bd9Sstevel@tonic-gate 16427c478bd9Sstevel@tonic-gate sub_hdr->source_len = (*tpp)->data0.size; 16437c478bd9Sstevel@tonic-gate sub_hdr->result_len = resultlen; 16447c478bd9Sstevel@tonic-gate sub_hdr->error_num = error_count; /* > 0; so pad4 = 0 */ 16457c478bd9Sstevel@tonic-gate 16467c478bd9Sstevel@tonic-gate if (NULL != default_data) { 16477c478bd9Sstevel@tonic-gate if ((itm_data_t *)(-1) == default_data) { 16487c478bd9Sstevel@tonic-gate sub_hdr->default_error = -1; 16497c478bd9Sstevel@tonic-gate #if !defined(_LP64) 16507c478bd9Sstevel@tonic-gate sub_hdr->pad3_num = (pad_t)(~0); 16517c478bd9Sstevel@tonic-gate #endif 16527c478bd9Sstevel@tonic-gate 16537c478bd9Sstevel@tonic-gate } else { 16547c478bd9Sstevel@tonic-gate sub_hdr->default_error = 0; 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate } else { 16577c478bd9Sstevel@tonic-gate if (num < entry_num) { 16587c478bd9Sstevel@tonic-gate sub_hdr->default_error = 1; 16597c478bd9Sstevel@tonic-gate } else { 16607c478bd9Sstevel@tonic-gate sub_hdr->default_error = 2; 16617c478bd9Sstevel@tonic-gate } 16627c478bd9Sstevel@tonic-gate } 16637c478bd9Sstevel@tonic-gate 16647c478bd9Sstevel@tonic-gate (void) memcpy((char *)(sub_hdr + 1), byte_seq_min, source->size); 16657c478bd9Sstevel@tonic-gate (void) memcpy((char *)(sub_hdr + 1) + source->size, 16667c478bd9Sstevel@tonic-gate byte_seq_max, source->size); 16677c478bd9Sstevel@tonic-gate 16687c478bd9Sstevel@tonic-gate if (-1 == sub_hdr->default_error) { 16697c478bd9Sstevel@tonic-gate byte_seq_def = malloc_vital((sizeof (unsigned char *)) * 16707c478bd9Sstevel@tonic-gate resultlen); 16717c478bd9Sstevel@tonic-gate if (source->size != resultlen) { 16727c478bd9Sstevel@tonic-gate itm_error( 16737c478bd9Sstevel@tonic-gate gettext("\"default no_change_copy\" is " 16747c478bd9Sstevel@tonic-gate "specified, but size does not match\n")); 16757c478bd9Sstevel@tonic-gate exit(ITMC_STATUS_BT); 16767c478bd9Sstevel@tonic-gate } 16777c478bd9Sstevel@tonic-gate put_dense_encoding_default( 16787c478bd9Sstevel@tonic-gate table, byte_seq_min, byte_seq_max, byte_seq_def, 16797c478bd9Sstevel@tonic-gate resultlen - 1, 0, 0); 16807c478bd9Sstevel@tonic-gate free(byte_seq_def); 16817c478bd9Sstevel@tonic-gate } else if (0 == sub_hdr->default_error) { 16827c478bd9Sstevel@tonic-gate if (default_data->size <= (sizeof (itm_place_t))) { 16837c478bd9Sstevel@tonic-gate for (i = 0, j = 0; 16847c478bd9Sstevel@tonic-gate i < (entry_num + 1); /* 1:default data */ 16857c478bd9Sstevel@tonic-gate i++, j += resultlen) { 16867c478bd9Sstevel@tonic-gate (void) memcpy(table + j + 16877c478bd9Sstevel@tonic-gate (resultlen - default_data->size), 16887c478bd9Sstevel@tonic-gate (void *)(&(default_data->place.itm_64d)), 16897c478bd9Sstevel@tonic-gate default_data->size); 16907c478bd9Sstevel@tonic-gate } 16917c478bd9Sstevel@tonic-gate } else { 16927c478bd9Sstevel@tonic-gate for (i = 0, j = 0; 16937c478bd9Sstevel@tonic-gate i < (entry_num + 1); /* 1:default data */ 16947c478bd9Sstevel@tonic-gate i++, j += resultlen) { 16957c478bd9Sstevel@tonic-gate (void) memcpy(table + j + 16967c478bd9Sstevel@tonic-gate (resultlen - default_data->size), 16977c478bd9Sstevel@tonic-gate (void *)(default_data->place.itm_ptr), 16987c478bd9Sstevel@tonic-gate default_data->size); 16997c478bd9Sstevel@tonic-gate } 17007c478bd9Sstevel@tonic-gate } 17017c478bd9Sstevel@tonic-gate } 17027c478bd9Sstevel@tonic-gate if (1 == sub_hdr->default_error) { 17037c478bd9Sstevel@tonic-gate (void) memset(table + (resultlen * entry_num), 1, entry_num); 17047c478bd9Sstevel@tonic-gate error_table = (table + (resultlen * entry_num)); 17057c478bd9Sstevel@tonic-gate for (i = 0; i < num; i++) { 17067c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 17077c478bd9Sstevel@tonic-gate continue; /* error sequence */ 17087c478bd9Sstevel@tonic-gate } 17097c478bd9Sstevel@tonic-gate j = hash_dense_encoding(NSPTR(&((*(tpp + i))->data0)), 17107c478bd9Sstevel@tonic-gate (*(tpp + i))->data0.size, 17117c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max); 17127c478bd9Sstevel@tonic-gate k = ((*(tpp + i))->range.size) == 0 ? j : 17137c478bd9Sstevel@tonic-gate hash_dense_encoding(NSPTR(&((*(tpp + i))->range)), 17147c478bd9Sstevel@tonic-gate (*(tpp + i))->data0.size, 17157c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max); 17167c478bd9Sstevel@tonic-gate for (; j <= k; j++) { 17177c478bd9Sstevel@tonic-gate *(error_table + j) = 0; 17187c478bd9Sstevel@tonic-gate } 17197c478bd9Sstevel@tonic-gate } 17207c478bd9Sstevel@tonic-gate } else if (0 < error_count) { 17217c478bd9Sstevel@tonic-gate error_table = (table + (resultlen * entry_num)); 17227c478bd9Sstevel@tonic-gate if (0 == sub_hdr->default_error) { 17237c478bd9Sstevel@tonic-gate error_table += resultlen; 17247c478bd9Sstevel@tonic-gate } 17257c478bd9Sstevel@tonic-gate (void) memset(error_table, 0, entry_num); 17267c478bd9Sstevel@tonic-gate for (i = 0; i < num; i++) { 17277c478bd9Sstevel@tonic-gate if (0 == (*(tpp + i))->data1.size) { 17287c478bd9Sstevel@tonic-gate j = hash_dense_encoding( 17297c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->data0)), 17307c478bd9Sstevel@tonic-gate (*(tpp + i))->data0.size, 17317c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max); 17327c478bd9Sstevel@tonic-gate k = ((*(tpp + i))->range.size) == 0 ? j : 17337c478bd9Sstevel@tonic-gate hash_dense_encoding( 17347c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->range)), 17357c478bd9Sstevel@tonic-gate (*(tpp + i))->data0.size, 17367c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max); 17377c478bd9Sstevel@tonic-gate for (; j <= k; j++) { 17387c478bd9Sstevel@tonic-gate *(error_table + j) = 1; /* specified */ 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate } 17437c478bd9Sstevel@tonic-gate 17447c478bd9Sstevel@tonic-gate 17457c478bd9Sstevel@tonic-gate p = malloc_vital(resultlen); 17467c478bd9Sstevel@tonic-gate for (i = 0; i < num; i++) { 17477c478bd9Sstevel@tonic-gate j = hash_dense_encoding(NSPTR(&((*(tpp + i))->data0)), 17487c478bd9Sstevel@tonic-gate (*(tpp + i))->data0.size, 17497c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max); 17507c478bd9Sstevel@tonic-gate 17517c478bd9Sstevel@tonic-gate if (0 != (*(tpp + i))->range.size) 17527c478bd9Sstevel@tonic-gate k = hash_dense_encoding( 17537c478bd9Sstevel@tonic-gate NSPTR(&((*(tpp + i))->range)), 17547c478bd9Sstevel@tonic-gate (*(tpp + i))->range.size, 17557c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max); 17567c478bd9Sstevel@tonic-gate else 17577c478bd9Sstevel@tonic-gate k = j; 17587c478bd9Sstevel@tonic-gate (void) memset(p, 0, (resultlen - (*(tpp + i))->data1.size)); 17597c478bd9Sstevel@tonic-gate (void) memcpy(p + (resultlen - (*(tpp + i))->data1.size), 17607c478bd9Sstevel@tonic-gate ((caddr_t)NSPTR(&((*(tpp + i))->data1))), 17617c478bd9Sstevel@tonic-gate (*(tpp + i))->data1.size); 17627c478bd9Sstevel@tonic-gate map_range_make_result(table, j, k, p, resultlen); 17637c478bd9Sstevel@tonic-gate } 17647c478bd9Sstevel@tonic-gate free(p); 17657c478bd9Sstevel@tonic-gate 17667c478bd9Sstevel@tonic-gate return (header); 17677c478bd9Sstevel@tonic-gate } 17687c478bd9Sstevel@tonic-gate 17697c478bd9Sstevel@tonic-gate 17707c478bd9Sstevel@tonic-gate static void 17717c478bd9Sstevel@tonic-gate put_dense_encoding_default( 17727c478bd9Sstevel@tonic-gate char *table, 17737c478bd9Sstevel@tonic-gate unsigned char *byte_seq_min, 17747c478bd9Sstevel@tonic-gate unsigned char *byte_seq_max, 17757c478bd9Sstevel@tonic-gate unsigned char *byte_seq_def, 17767c478bd9Sstevel@tonic-gate long pos_max, 17777c478bd9Sstevel@tonic-gate long position, 17787c478bd9Sstevel@tonic-gate long dense_encoded_value) 17797c478bd9Sstevel@tonic-gate { 17807c478bd9Sstevel@tonic-gate uchar_t i; 17817c478bd9Sstevel@tonic-gate 17827c478bd9Sstevel@tonic-gate if (position < pos_max) { 17837c478bd9Sstevel@tonic-gate for (i = *(byte_seq_min + position); 17847c478bd9Sstevel@tonic-gate i <= *(byte_seq_max + position); i++) { 17857c478bd9Sstevel@tonic-gate *(byte_seq_def + position) = i; 17867c478bd9Sstevel@tonic-gate put_dense_encoding_default( 17877c478bd9Sstevel@tonic-gate table, 17887c478bd9Sstevel@tonic-gate byte_seq_min, byte_seq_max, 17897c478bd9Sstevel@tonic-gate byte_seq_def, 17907c478bd9Sstevel@tonic-gate pos_max, position + 1, 17917c478bd9Sstevel@tonic-gate ((dense_encoded_value + i) * 17927c478bd9Sstevel@tonic-gate (*(byte_seq_max + position) - 17937c478bd9Sstevel@tonic-gate *(byte_seq_min + position) + 1))); 17947c478bd9Sstevel@tonic-gate } 17957c478bd9Sstevel@tonic-gate return; 17967c478bd9Sstevel@tonic-gate } 17977c478bd9Sstevel@tonic-gate 17987c478bd9Sstevel@tonic-gate for (i = *(byte_seq_min + position); 17997c478bd9Sstevel@tonic-gate i <= *(byte_seq_max + position); i++) { 18007c478bd9Sstevel@tonic-gate *(byte_seq_def + position) = i; 18017c478bd9Sstevel@tonic-gate (void) memcpy(table + 18027c478bd9Sstevel@tonic-gate ((pos_max + 1) * (dense_encoded_value + i - 1)), 18037c478bd9Sstevel@tonic-gate byte_seq_def, pos_max + 1); 18047c478bd9Sstevel@tonic-gate } 18057c478bd9Sstevel@tonic-gate } 18067c478bd9Sstevel@tonic-gate 18077c478bd9Sstevel@tonic-gate 18087c478bd9Sstevel@tonic-gate char * 18097c478bd9Sstevel@tonic-gate dense_enc_index_to_byte_seq( 18107c478bd9Sstevel@tonic-gate long value, 18117c478bd9Sstevel@tonic-gate long length, 18127c478bd9Sstevel@tonic-gate unsigned char *byte_seq_min, 18137c478bd9Sstevel@tonic-gate unsigned char *byte_seq_max) 18147c478bd9Sstevel@tonic-gate { 18157c478bd9Sstevel@tonic-gate static char *buf; 18167c478bd9Sstevel@tonic-gate static long buf_len; 18177c478bd9Sstevel@tonic-gate char *p; 18187c478bd9Sstevel@tonic-gate int i; 18197c478bd9Sstevel@tonic-gate int l; 18207c478bd9Sstevel@tonic-gate int residue; 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate if (buf_len < (2 + (length * 2) + 1)) { 18237c478bd9Sstevel@tonic-gate free(buf); 18247c478bd9Sstevel@tonic-gate buf_len = (2 + (length * 2) + 1) + 16; 18257c478bd9Sstevel@tonic-gate buf = malloc_vital(buf_len); 18267c478bd9Sstevel@tonic-gate } 18277c478bd9Sstevel@tonic-gate 18287c478bd9Sstevel@tonic-gate *(buf + (length * 2)) = '\0'; 18297c478bd9Sstevel@tonic-gate *(buf + 0) = '0'; 18307c478bd9Sstevel@tonic-gate *(buf + 1) = 'x'; 18317c478bd9Sstevel@tonic-gate p = buf + 2; 18327c478bd9Sstevel@tonic-gate for (i = length - 1; 0 <= i; --i) { 18337c478bd9Sstevel@tonic-gate residue = value % (*(byte_seq_max + i) - 18347c478bd9Sstevel@tonic-gate *(byte_seq_min + i) + 1); 18357c478bd9Sstevel@tonic-gate value /= (*(byte_seq_max + i) - 18367c478bd9Sstevel@tonic-gate *(byte_seq_min + i) + 1); 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate residue += *(byte_seq_min + i); 18397c478bd9Sstevel@tonic-gate l = ((0xf0 & residue) >> 4); 18407c478bd9Sstevel@tonic-gate if (l < 10) { 18417c478bd9Sstevel@tonic-gate *(p + (i * 2)) = ('0' + l); 18427c478bd9Sstevel@tonic-gate } else { 18437c478bd9Sstevel@tonic-gate *(p + (i * 2)) = ('a' + l - 10); 18447c478bd9Sstevel@tonic-gate } 18457c478bd9Sstevel@tonic-gate l = (0x0f & residue); 18467c478bd9Sstevel@tonic-gate if (l < 10) { 18477c478bd9Sstevel@tonic-gate *(p + (i * 2) + 1) = ('0' + l); 18487c478bd9Sstevel@tonic-gate } else { 18497c478bd9Sstevel@tonic-gate *(p + (i * 2) + 1) = ('a' + l - 10); 18507c478bd9Sstevel@tonic-gate } 18517c478bd9Sstevel@tonic-gate } 18527c478bd9Sstevel@tonic-gate return (buf); 18537c478bd9Sstevel@tonic-gate } 18547c478bd9Sstevel@tonic-gate 18557c478bd9Sstevel@tonic-gate 18567c478bd9Sstevel@tonic-gate itm_tbl_hdr_t * 18577c478bd9Sstevel@tonic-gate map_table_lookup_var() 18587c478bd9Sstevel@tonic-gate { 18597c478bd9Sstevel@tonic-gate itm_error(gettext( 1860*e492095eSRichard PALO "length of all source sequences must be the same\n")); 18617c478bd9Sstevel@tonic-gate error_deferred += 1; 18627c478bd9Sstevel@tonic-gate return (NULL); 18637c478bd9Sstevel@tonic-gate } 18647c478bd9Sstevel@tonic-gate 18657c478bd9Sstevel@tonic-gate 18667c478bd9Sstevel@tonic-gate 18677c478bd9Sstevel@tonic-gate static void 18687c478bd9Sstevel@tonic-gate map_range_adjust_byte_seq( 18697c478bd9Sstevel@tonic-gate unsigned char *byte_seq_min, 18707c478bd9Sstevel@tonic-gate unsigned char *byte_seq_max, 18717c478bd9Sstevel@tonic-gate long source_len, 18727c478bd9Sstevel@tonic-gate itmc_data_pair_t *pair) 18737c478bd9Sstevel@tonic-gate { 18747c478bd9Sstevel@tonic-gate unsigned char *p, *p2; 18757c478bd9Sstevel@tonic-gate int i; 18767c478bd9Sstevel@tonic-gate int flag; 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate p = (unsigned char *)(NSPTR(&((pair)->data0))); 18797c478bd9Sstevel@tonic-gate p2 = (unsigned char *)(NSPTR(&((pair)->range))); 18807c478bd9Sstevel@tonic-gate flag = 0; 18817c478bd9Sstevel@tonic-gate for (i = 0; i < source_len; i++) { 18827c478bd9Sstevel@tonic-gate if (flag != 0) { 18837c478bd9Sstevel@tonic-gate break; 18847c478bd9Sstevel@tonic-gate } 18857c478bd9Sstevel@tonic-gate if (*(p + i) != *(p2 + i)) 18867c478bd9Sstevel@tonic-gate flag = 1; 18877c478bd9Sstevel@tonic-gate if (*(p + i) < *(byte_seq_min + i)) { 18887c478bd9Sstevel@tonic-gate *(byte_seq_min + i) = *(p + i); 18897c478bd9Sstevel@tonic-gate } 18907c478bd9Sstevel@tonic-gate if (*(byte_seq_max + i) < *(p2 + i)) { 18917c478bd9Sstevel@tonic-gate *(byte_seq_max + i) = *(p2 + i); 18927c478bd9Sstevel@tonic-gate } 18937c478bd9Sstevel@tonic-gate } 18947c478bd9Sstevel@tonic-gate for (; i < source_len; i++) { 18957c478bd9Sstevel@tonic-gate *(byte_seq_min + i) = 0x00; 18967c478bd9Sstevel@tonic-gate *(byte_seq_max + i) = 0xff; 18977c478bd9Sstevel@tonic-gate } 18987c478bd9Sstevel@tonic-gate } 18997c478bd9Sstevel@tonic-gate 19007c478bd9Sstevel@tonic-gate /* 19017c478bd9Sstevel@tonic-gate * result value + (source range value - source base value) 19027c478bd9Sstevel@tonic-gate * and just caluculate its length 19037c478bd9Sstevel@tonic-gate */ 19047c478bd9Sstevel@tonic-gate static size_t 19057c478bd9Sstevel@tonic-gate map_table_resultlen(itmc_map_t *ml) 19067c478bd9Sstevel@tonic-gate { 19077c478bd9Sstevel@tonic-gate size_t j; 19087c478bd9Sstevel@tonic-gate size_t len; 19097c478bd9Sstevel@tonic-gate int m; 19107c478bd9Sstevel@tonic-gate uchar_t *c1; 19117c478bd9Sstevel@tonic-gate uchar_t *c2; 19127c478bd9Sstevel@tonic-gate uchar_t *c3; 19137c478bd9Sstevel@tonic-gate 19147c478bd9Sstevel@tonic-gate j = ml->data_pair.data0.size; 19157c478bd9Sstevel@tonic-gate if (j < ml->data_pair.data1.size) j = ml->data_pair.data1.size; 19167c478bd9Sstevel@tonic-gate if (j < ml->data_pair.range.size) j = ml->data_pair.range.size; 19177c478bd9Sstevel@tonic-gate c1 = (uchar_t *)(NSPTR(&((ml->data_pair).data0))) + 19187c478bd9Sstevel@tonic-gate ml->data_pair.data0.size - 1; 19197c478bd9Sstevel@tonic-gate c2 = (uchar_t *)(NSPTR(&((ml->data_pair).data1))) + 19207c478bd9Sstevel@tonic-gate ml->data_pair.data1.size - 1; 19217c478bd9Sstevel@tonic-gate c3 = (uchar_t *)(NSPTR(&((ml->data_pair.range)))) + 19227c478bd9Sstevel@tonic-gate ml->data_pair.range.size - 1; 19237c478bd9Sstevel@tonic-gate m = 0; 19247c478bd9Sstevel@tonic-gate for (len = 0; len < j; len++, c1--, c2--, c3--) { 19257c478bd9Sstevel@tonic-gate if (len < ml->data_pair.data0.size) m -= *c1; 19267c478bd9Sstevel@tonic-gate if (len < ml->data_pair.data1.size) m += *c2; 19277c478bd9Sstevel@tonic-gate if (len < ml->data_pair.range.size) m += *c3; 19287c478bd9Sstevel@tonic-gate m >>= 8; 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate if (m > 0) { 19317c478bd9Sstevel@tonic-gate len += 1; 19327c478bd9Sstevel@tonic-gate } 19337c478bd9Sstevel@tonic-gate TRACE_MESSAGE('g', ("map_table_resutlen: source(0x%s..0x%s), " 19347c478bd9Sstevel@tonic-gate "result(0x%s.... len= %ld)\n", 19357c478bd9Sstevel@tonic-gate data_to_hexadecimal(&(ml->data_pair.data0)), 19367c478bd9Sstevel@tonic-gate data_to_hexadecimal(&(ml->data_pair.range)), 19377c478bd9Sstevel@tonic-gate data_to_hexadecimal(&(ml->data_pair.data1)), 19387c478bd9Sstevel@tonic-gate len)); 19397c478bd9Sstevel@tonic-gate return (len); 19407c478bd9Sstevel@tonic-gate } 19417c478bd9Sstevel@tonic-gate 19427c478bd9Sstevel@tonic-gate /* 19437c478bd9Sstevel@tonic-gate * 19447c478bd9Sstevel@tonic-gate */ 19457c478bd9Sstevel@tonic-gate static void 19467c478bd9Sstevel@tonic-gate map_range_make_result( 19477c478bd9Sstevel@tonic-gate char *table, 19487c478bd9Sstevel@tonic-gate itm_size_t range_start, 19497c478bd9Sstevel@tonic-gate itm_size_t range_end, 19507c478bd9Sstevel@tonic-gate char *result_data, 19517c478bd9Sstevel@tonic-gate itm_size_t result_size) 19527c478bd9Sstevel@tonic-gate { 19537c478bd9Sstevel@tonic-gate itm_size_t i; 19547c478bd9Sstevel@tonic-gate itm_size_t j; 19557c478bd9Sstevel@tonic-gate itm_size_t p; 19567c478bd9Sstevel@tonic-gate uchar_t *dp; /* unsigned for ++ operation */ 19577c478bd9Sstevel@tonic-gate 19587c478bd9Sstevel@tonic-gate for (i = range_start, p = i * result_size; 19597c478bd9Sstevel@tonic-gate i <= range_end; i++, p += result_size) { 19607c478bd9Sstevel@tonic-gate (void) memcpy(table + p, result_data, result_size); 19617c478bd9Sstevel@tonic-gate for (j = 0, dp = (uchar_t *)(result_data + result_size - 1); 19627c478bd9Sstevel@tonic-gate j < result_size; 19637c478bd9Sstevel@tonic-gate j++, dp--) { 19647c478bd9Sstevel@tonic-gate if (0xff != *dp) { 19657c478bd9Sstevel@tonic-gate (*dp) += 1; 19667c478bd9Sstevel@tonic-gate for (++dp; j > 0; j--, dp++) { 19677c478bd9Sstevel@tonic-gate (*dp) = 0x00; 19687c478bd9Sstevel@tonic-gate } 19697c478bd9Sstevel@tonic-gate break; 19707c478bd9Sstevel@tonic-gate } 19717c478bd9Sstevel@tonic-gate } 19727c478bd9Sstevel@tonic-gate } 19737c478bd9Sstevel@tonic-gate } 19747c478bd9Sstevel@tonic-gate 19757c478bd9Sstevel@tonic-gate /* 19767c478bd9Sstevel@tonic-gate * 19777c478bd9Sstevel@tonic-gate */ 19787c478bd9Sstevel@tonic-gate static size_t 19797c478bd9Sstevel@tonic-gate map_table_num_range(itmc_data_pair_t *pair) 19807c478bd9Sstevel@tonic-gate { 19817c478bd9Sstevel@tonic-gate size_t i, j; 19827c478bd9Sstevel@tonic-gate itm_num_t num; 19837c478bd9Sstevel@tonic-gate itm_num_t num2; 19847c478bd9Sstevel@tonic-gate uchar_t *c1; 19857c478bd9Sstevel@tonic-gate uchar_t *c2; 19867c478bd9Sstevel@tonic-gate 19877c478bd9Sstevel@tonic-gate assert(0 < pair->range.size); 19887c478bd9Sstevel@tonic-gate j = pair->data0.size; 19897c478bd9Sstevel@tonic-gate if (j < pair->range.size) 19907c478bd9Sstevel@tonic-gate j = pair->range.size; 19917c478bd9Sstevel@tonic-gate c1 = ((uchar_t *)(NSPTR(&(pair->data0)))) + pair->data0.size - 1; 19927c478bd9Sstevel@tonic-gate c2 = ((uchar_t *)(NSPTR(&(pair->range)))) + pair->range.size - 1; 19937c478bd9Sstevel@tonic-gate num = 0; 19947c478bd9Sstevel@tonic-gate for (i = 0; i < j; i++, c1--, c2--) { 19957c478bd9Sstevel@tonic-gate if (i < pair->range.size) num2 = *c2; 19967c478bd9Sstevel@tonic-gate if (i < pair->data0.size) num2 -= *c1; 19977c478bd9Sstevel@tonic-gate TRACE_MESSAGE('G', (" num += %d(=%d-%d)\n ", 19987c478bd9Sstevel@tonic-gate *c2 - *c1, *c2, *c1)); 19997c478bd9Sstevel@tonic-gate num2 <<= (i*8); 20007c478bd9Sstevel@tonic-gate num += num2; 20017c478bd9Sstevel@tonic-gate } 20027c478bd9Sstevel@tonic-gate TRACE_MESSAGE('g', ("map_table_num_range: source(0x%s..0x%s), " 20037c478bd9Sstevel@tonic-gate "num= %ld\n", 20047c478bd9Sstevel@tonic-gate data_to_hexadecimal(&(pair->data0)), 20057c478bd9Sstevel@tonic-gate data_to_hexadecimal(&(pair->range)), 20067c478bd9Sstevel@tonic-gate num)); 20077c478bd9Sstevel@tonic-gate return (num); 20087c478bd9Sstevel@tonic-gate } 20097c478bd9Sstevel@tonic-gate 20107c478bd9Sstevel@tonic-gate /* 20117c478bd9Sstevel@tonic-gate * 20127c478bd9Sstevel@tonic-gate */ 20137c478bd9Sstevel@tonic-gate itmc_map_t * 20147c478bd9Sstevel@tonic-gate map_list_append(itmc_map_t *map_list, itmc_map_t *map_pair) 20157c478bd9Sstevel@tonic-gate { 20167c478bd9Sstevel@tonic-gate if (0 == map_pair) { 20177c478bd9Sstevel@tonic-gate return (map_list); 20187c478bd9Sstevel@tonic-gate } 20197c478bd9Sstevel@tonic-gate 20207c478bd9Sstevel@tonic-gate map_pair->next = NULL; 20217c478bd9Sstevel@tonic-gate map_pair->last = map_pair; 20227c478bd9Sstevel@tonic-gate 20237c478bd9Sstevel@tonic-gate if (map_list) { 20247c478bd9Sstevel@tonic-gate map_list->last->next = map_pair; 20257c478bd9Sstevel@tonic-gate map_list->last = map_pair; 20267c478bd9Sstevel@tonic-gate return (map_list); 20277c478bd9Sstevel@tonic-gate } else { 20287c478bd9Sstevel@tonic-gate return (map_pair); 20297c478bd9Sstevel@tonic-gate } 20307c478bd9Sstevel@tonic-gate } 20317c478bd9Sstevel@tonic-gate 20327c478bd9Sstevel@tonic-gate 20337c478bd9Sstevel@tonic-gate 20347c478bd9Sstevel@tonic-gate itmc_obj_t * 20357c478bd9Sstevel@tonic-gate op_self(itm_op_type_t type) 20367c478bd9Sstevel@tonic-gate { 20377c478bd9Sstevel@tonic-gate return (op_unit(type, NULL, 0, NULL, 0, NULL, 0)); 20387c478bd9Sstevel@tonic-gate } 20397c478bd9Sstevel@tonic-gate 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate itmc_obj_t * 20427c478bd9Sstevel@tonic-gate op_unary(itm_op_type_t type, void *data, size_t data_size) 20437c478bd9Sstevel@tonic-gate { 20447c478bd9Sstevel@tonic-gate return (op_unit(type, data, data_size, NULL, 0, NULL, 0)); 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate 20477c478bd9Sstevel@tonic-gate itmc_obj_t * 20487c478bd9Sstevel@tonic-gate op_unit(itm_op_type_t type, 20497c478bd9Sstevel@tonic-gate void *data0, size_t data0_size, 20507c478bd9Sstevel@tonic-gate void *data1, size_t data1_size, 20517c478bd9Sstevel@tonic-gate void *data2, size_t data2_size) 20527c478bd9Sstevel@tonic-gate { 20537c478bd9Sstevel@tonic-gate itm_op_t *op; 20547c478bd9Sstevel@tonic-gate itmc_obj_t *obj; 20557c478bd9Sstevel@tonic-gate 20567c478bd9Sstevel@tonic-gate op = malloc_vital(sizeof (itm_op_t)); 20577c478bd9Sstevel@tonic-gate op->type = type; 20587c478bd9Sstevel@tonic-gate op->data.operand[0].itm_ptr = (itm_place2_t)(data0); 20597c478bd9Sstevel@tonic-gate op->data.operand[1].itm_ptr = (itm_place2_t)(data1); 20607c478bd9Sstevel@tonic-gate op->data.operand[2].itm_ptr = (itm_place2_t)(data2); 20617c478bd9Sstevel@tonic-gate 20627c478bd9Sstevel@tonic-gate obj = malloc_vital(sizeof (itmc_obj_t)); 20637c478bd9Sstevel@tonic-gate obj->type = ITMC_OBJ_OP; 20647c478bd9Sstevel@tonic-gate obj->name = NULL; 20657c478bd9Sstevel@tonic-gate obj->obj = op; 20667c478bd9Sstevel@tonic-gate obj->ref[0] = obj->ref[1] = obj->ref[2] = NULL; 20677c478bd9Sstevel@tonic-gate if (NULL != data0) { 20687c478bd9Sstevel@tonic-gate obj->ref[0] = obj_register(ITMC_OBJ_EXPR, NULL, 20697c478bd9Sstevel@tonic-gate data0, data0_size, 20707c478bd9Sstevel@tonic-gate &(op->data.operand[0]), 20717c478bd9Sstevel@tonic-gate OBJ_REG_TAIL); 20727c478bd9Sstevel@tonic-gate } 20737c478bd9Sstevel@tonic-gate if (NULL != data1) { 20747c478bd9Sstevel@tonic-gate obj->ref[1] = obj_register(ITMC_OBJ_EXPR, NULL, 20757c478bd9Sstevel@tonic-gate data1, data1_size, 20767c478bd9Sstevel@tonic-gate &(op->data.operand[1]), 20777c478bd9Sstevel@tonic-gate OBJ_REG_TAIL); 20787c478bd9Sstevel@tonic-gate } 20797c478bd9Sstevel@tonic-gate if (NULL != data2) { 20807c478bd9Sstevel@tonic-gate obj->ref[2] = obj_register(ITMC_OBJ_EXPR, NULL, 20817c478bd9Sstevel@tonic-gate data2, data2_size, 20827c478bd9Sstevel@tonic-gate &(op->data.operand[2]), 20837c478bd9Sstevel@tonic-gate OBJ_REG_TAIL); 20847c478bd9Sstevel@tonic-gate } 20857c478bd9Sstevel@tonic-gate obj->next = NULL; 20867c478bd9Sstevel@tonic-gate obj->last = NULL; 20877c478bd9Sstevel@tonic-gate 20887c478bd9Sstevel@tonic-gate return (obj); 20897c478bd9Sstevel@tonic-gate } 20907c478bd9Sstevel@tonic-gate 20917c478bd9Sstevel@tonic-gate 20927c478bd9Sstevel@tonic-gate itmc_obj_t * 20937c478bd9Sstevel@tonic-gate op_self_num(itm_op_type_t type, itm_num_t data) 20947c478bd9Sstevel@tonic-gate { 20957c478bd9Sstevel@tonic-gate itm_op_t *op; 20967c478bd9Sstevel@tonic-gate itmc_obj_t *obj; 20977c478bd9Sstevel@tonic-gate 20987c478bd9Sstevel@tonic-gate op = malloc_vital(sizeof (itm_op_t)); 20997c478bd9Sstevel@tonic-gate op->type = type; 21007c478bd9Sstevel@tonic-gate op->data.itm_opnum = data; 21017c478bd9Sstevel@tonic-gate #if !defined(_LP64) 21027c478bd9Sstevel@tonic-gate op->data.itm_oppad = (data < 0) ? (pad_t)(~0) : 0; 21037c478bd9Sstevel@tonic-gate #endif 21047c478bd9Sstevel@tonic-gate obj = malloc_vital(sizeof (itmc_obj_t)); 21057c478bd9Sstevel@tonic-gate obj->type = ITMC_OBJ_OP; 21067c478bd9Sstevel@tonic-gate obj->name = NULL; 21077c478bd9Sstevel@tonic-gate obj->obj = op; 21087c478bd9Sstevel@tonic-gate obj->ref[0] = obj->ref[1] = obj->ref[2] = NULL; 21097c478bd9Sstevel@tonic-gate 21107c478bd9Sstevel@tonic-gate return (obj); 21117c478bd9Sstevel@tonic-gate } 21127c478bd9Sstevel@tonic-gate 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate itm_expr_t * 21157c478bd9Sstevel@tonic-gate expr_self_num(itm_expr_type_t type, itm_num_t data) 21167c478bd9Sstevel@tonic-gate { 21177c478bd9Sstevel@tonic-gate itm_expr_t *expr; 21187c478bd9Sstevel@tonic-gate 21197c478bd9Sstevel@tonic-gate expr = malloc_vital(sizeof (itm_expr_t)); 21207c478bd9Sstevel@tonic-gate expr->type = type; 21217c478bd9Sstevel@tonic-gate expr->data.itm_exnum = data; 21227c478bd9Sstevel@tonic-gate #if !defined(_LP64) 21237c478bd9Sstevel@tonic-gate expr->data.itm_expad = (data < 0) ? (pad_t)(~0) : 0; 21247c478bd9Sstevel@tonic-gate #endif 21257c478bd9Sstevel@tonic-gate return (expr); 21267c478bd9Sstevel@tonic-gate } 21277c478bd9Sstevel@tonic-gate 21287c478bd9Sstevel@tonic-gate 21297c478bd9Sstevel@tonic-gate itm_expr_t * 21307c478bd9Sstevel@tonic-gate expr_self(itm_expr_type_t type, itm_data_t *data) 21317c478bd9Sstevel@tonic-gate { 21327c478bd9Sstevel@tonic-gate itm_expr_t *expr; 21337c478bd9Sstevel@tonic-gate itmc_name_t *name; 21347c478bd9Sstevel@tonic-gate 21357c478bd9Sstevel@tonic-gate expr = malloc_vital(sizeof (itm_expr_t)); 21367c478bd9Sstevel@tonic-gate expr->type = type; 21377c478bd9Sstevel@tonic-gate if (NULL == data) { 21387c478bd9Sstevel@tonic-gate expr->data.value.size = 0; 21397c478bd9Sstevel@tonic-gate expr->data.value.place.itm_ptr = 0; 21407c478bd9Sstevel@tonic-gate } else { 21417c478bd9Sstevel@tonic-gate expr->data.value = *(data); 21427c478bd9Sstevel@tonic-gate } 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate switch (type) { 21457c478bd9Sstevel@tonic-gate case ITM_EXPR_NAME: /* register */ 21467c478bd9Sstevel@tonic-gate name = name_lookup(data, ITMC_OBJ_REGISTER); 21477c478bd9Sstevel@tonic-gate if (&name_lookup_error == name) { 21487c478bd9Sstevel@tonic-gate return (NULL); 21497c478bd9Sstevel@tonic-gate } else if (NULL == name) { 21507c478bd9Sstevel@tonic-gate if (reg_id >= MAXREGID) { 21517c478bd9Sstevel@tonic-gate itm_error( 2152*e492095eSRichard PALO gettext( 2153*e492095eSRichard PALO "more than %d variables are used\n"), 21547c478bd9Sstevel@tonic-gate MAXREGID); 21557c478bd9Sstevel@tonic-gate exit(ITMC_STATUS_BT2); 21567c478bd9Sstevel@tonic-gate } 21577c478bd9Sstevel@tonic-gate name = name_register(data, ITMC_OBJ_REGISTER, NULL); 21587c478bd9Sstevel@tonic-gate name->reg_id = (reg_id++); 21597c478bd9Sstevel@tonic-gate } 21607c478bd9Sstevel@tonic-gate expr->type = ITM_EXPR_REG; 21617c478bd9Sstevel@tonic-gate expr->data.itm_exnum = name->reg_id; 21627c478bd9Sstevel@tonic-gate #if !defined(_LP64) 21637c478bd9Sstevel@tonic-gate expr->data.itm_expad = 21647c478bd9Sstevel@tonic-gate (expr->data.itm_exnum < 0) ? (pad_t)(~0) : 0; 21657c478bd9Sstevel@tonic-gate #endif 21667c478bd9Sstevel@tonic-gate break; 21677c478bd9Sstevel@tonic-gate case ITM_EXPR_SEQ: 21687c478bd9Sstevel@tonic-gate if ((sizeof (itm_place_t)) < data->size) { 21697c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_DATA, NULL, 21707c478bd9Sstevel@tonic-gate (void *)(data->place.itm_ptr), data->size, 21717c478bd9Sstevel@tonic-gate &(expr->data.value.place), OBJ_REG_TAIL); 21727c478bd9Sstevel@tonic-gate } 21737c478bd9Sstevel@tonic-gate break; 21747c478bd9Sstevel@tonic-gate } 21757c478bd9Sstevel@tonic-gate return (expr); 21767c478bd9Sstevel@tonic-gate } 21777c478bd9Sstevel@tonic-gate 21787c478bd9Sstevel@tonic-gate 21797c478bd9Sstevel@tonic-gate itm_expr_t * 21807c478bd9Sstevel@tonic-gate expr_unary(itm_expr_type_t type, itm_expr_t *data0) 21817c478bd9Sstevel@tonic-gate { 21827c478bd9Sstevel@tonic-gate itm_expr_t *expr; 21837c478bd9Sstevel@tonic-gate 21847c478bd9Sstevel@tonic-gate expr = malloc_vital(sizeof (itm_expr_t)); 21857c478bd9Sstevel@tonic-gate expr->type = type; 21867c478bd9Sstevel@tonic-gate expr->data.operand[0].itm_ptr = (itm_place2_t)(data0); 21877c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 21887c478bd9Sstevel@tonic-gate data0, sizeof (itm_expr_t), 21897c478bd9Sstevel@tonic-gate &(expr->data.operand[0]), OBJ_REG_TAIL); 21907c478bd9Sstevel@tonic-gate 21917c478bd9Sstevel@tonic-gate return (expr); 21927c478bd9Sstevel@tonic-gate } 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate 21957c478bd9Sstevel@tonic-gate itm_expr_t * 21967c478bd9Sstevel@tonic-gate expr_binary(itm_expr_type_t type, 21977c478bd9Sstevel@tonic-gate itm_expr_t *data0, itm_expr_t *data1) 21987c478bd9Sstevel@tonic-gate { 21997c478bd9Sstevel@tonic-gate itm_expr_t *expr; 22007c478bd9Sstevel@tonic-gate itm_num_t num; 22017c478bd9Sstevel@tonic-gate unsigned char *p; 22027c478bd9Sstevel@tonic-gate int i; 22037c478bd9Sstevel@tonic-gate 22047c478bd9Sstevel@tonic-gate expr = malloc_vital(sizeof (itm_expr_t)); 22057c478bd9Sstevel@tonic-gate expr->type = type; 22067c478bd9Sstevel@tonic-gate 22077c478bd9Sstevel@tonic-gate if (ITM_EXPR_SEQ == data0->type) { 22087c478bd9Sstevel@tonic-gate p = (unsigned char *)NSPTR(&(data0->data.value)); 22097c478bd9Sstevel@tonic-gate for (i = 0, num = 0; i < data0->data.value.size; i++, p++) { 22107c478bd9Sstevel@tonic-gate num = ((num << 8) | *p); 22117c478bd9Sstevel@tonic-gate } 22127c478bd9Sstevel@tonic-gate data0 = expr_self_num(ITM_EXPR_INT, num); 22137c478bd9Sstevel@tonic-gate } 22147c478bd9Sstevel@tonic-gate if (ITM_EXPR_SEQ == data1->type) { 22157c478bd9Sstevel@tonic-gate p = (unsigned char *)NSPTR(&(data1->data.value)); 22167c478bd9Sstevel@tonic-gate for (i = 0, num = 0; i < data1->data.value.size; i++, p++) { 22177c478bd9Sstevel@tonic-gate num = ((num << 8) | *p); 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate data1 = expr_self_num(ITM_EXPR_INT, num); 22207c478bd9Sstevel@tonic-gate } 22217c478bd9Sstevel@tonic-gate 22227c478bd9Sstevel@tonic-gate expr->data.operand[0].itm_ptr = (itm_place2_t)(data0); 22237c478bd9Sstevel@tonic-gate expr->data.operand[1].itm_ptr = (itm_place2_t)(data1); 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 22267c478bd9Sstevel@tonic-gate data0, sizeof (itm_expr_t), 22277c478bd9Sstevel@tonic-gate &(expr->data.operand[0]), OBJ_REG_TAIL); 22287c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 22297c478bd9Sstevel@tonic-gate data1, sizeof (itm_expr_t), 22307c478bd9Sstevel@tonic-gate &(expr->data.operand[1]), OBJ_REG_TAIL); 22317c478bd9Sstevel@tonic-gate 22327c478bd9Sstevel@tonic-gate return (expr); 22337c478bd9Sstevel@tonic-gate } 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate 22367c478bd9Sstevel@tonic-gate itm_expr_t * 22377c478bd9Sstevel@tonic-gate expr_binary2(itm_expr_type_t type, 22387c478bd9Sstevel@tonic-gate itm_expr_t *data0, itm_expr_t *data1) 22397c478bd9Sstevel@tonic-gate { 22407c478bd9Sstevel@tonic-gate itm_expr_t *expr; 22417c478bd9Sstevel@tonic-gate itm_num_t num; 22427c478bd9Sstevel@tonic-gate unsigned char *p; 22437c478bd9Sstevel@tonic-gate int i; 22447c478bd9Sstevel@tonic-gate 22457c478bd9Sstevel@tonic-gate if ((NULL == data0) || (NULL == data1)) { 22467c478bd9Sstevel@tonic-gate return (NULL); 22477c478bd9Sstevel@tonic-gate } 22487c478bd9Sstevel@tonic-gate expr = malloc_vital(sizeof (itm_expr_t)); 22497c478bd9Sstevel@tonic-gate expr->type = type; 22507c478bd9Sstevel@tonic-gate 22517c478bd9Sstevel@tonic-gate switch (data0->type) { 22527c478bd9Sstevel@tonic-gate case ITM_EXPR_SEQ: 22537c478bd9Sstevel@tonic-gate p = (unsigned char *)NSPTR(&(data0->data.value)); 22547c478bd9Sstevel@tonic-gate for (i = 0, num = 0; i < data0->data.value.size; i++, p++) { 22557c478bd9Sstevel@tonic-gate num = ((num << 8) | *p); 22567c478bd9Sstevel@tonic-gate } 22577c478bd9Sstevel@tonic-gate data0 = expr_self_num(ITM_EXPR_INT, num); 22587c478bd9Sstevel@tonic-gate expr->data.operand[0].itm_ptr = (itm_place2_t)(data0); 22597c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 22607c478bd9Sstevel@tonic-gate data0, sizeof (itm_expr_t), 22617c478bd9Sstevel@tonic-gate &(expr->data.operand[0]), OBJ_REG_TAIL); 22627c478bd9Sstevel@tonic-gate break; 22637c478bd9Sstevel@tonic-gate case ITM_EXPR_INT: 22647c478bd9Sstevel@tonic-gate case ITM_EXPR_REG: 22657c478bd9Sstevel@tonic-gate case ITM_EXPR_IN_VECTOR_D: 22667c478bd9Sstevel@tonic-gate expr->data.operand[0] = data0->data.operand[0]; 22677c478bd9Sstevel@tonic-gate break; 22687c478bd9Sstevel@tonic-gate default: 22697c478bd9Sstevel@tonic-gate expr->data.operand[0].itm_ptr = (itm_place2_t)(data0); 22707c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 22717c478bd9Sstevel@tonic-gate data0, sizeof (itm_expr_t), 22727c478bd9Sstevel@tonic-gate &(expr->data.operand[0]), OBJ_REG_TAIL); 22737c478bd9Sstevel@tonic-gate break; 22747c478bd9Sstevel@tonic-gate } 22757c478bd9Sstevel@tonic-gate 22767c478bd9Sstevel@tonic-gate switch (data1->type) { 22777c478bd9Sstevel@tonic-gate case ITM_EXPR_SEQ: 22787c478bd9Sstevel@tonic-gate p = (unsigned char *)NSPTR(&(data1->data.value)); 22797c478bd9Sstevel@tonic-gate for (i = 0, num = 0; i < data1->data.value.size; i++, p++) { 22807c478bd9Sstevel@tonic-gate num = ((num << 8) | *p); 22817c478bd9Sstevel@tonic-gate } 22827c478bd9Sstevel@tonic-gate data1 = expr_self_num(ITM_EXPR_INT, num); 22837c478bd9Sstevel@tonic-gate expr->data.operand[1].itm_ptr = (itm_place2_t)(data1); 22847c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 22857c478bd9Sstevel@tonic-gate data1, sizeof (itm_expr_t), 22867c478bd9Sstevel@tonic-gate &(expr->data.operand[1]), OBJ_REG_TAIL); 22877c478bd9Sstevel@tonic-gate break; 22887c478bd9Sstevel@tonic-gate case ITM_EXPR_INT: 22897c478bd9Sstevel@tonic-gate case ITM_EXPR_REG: 22907c478bd9Sstevel@tonic-gate case ITM_EXPR_IN_VECTOR_D: 22917c478bd9Sstevel@tonic-gate expr->data.operand[1] = data1->data.operand[0]; 22927c478bd9Sstevel@tonic-gate break; 22937c478bd9Sstevel@tonic-gate default: 22947c478bd9Sstevel@tonic-gate expr->data.operand[1].itm_ptr = (itm_place2_t)(data1); 22957c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 22967c478bd9Sstevel@tonic-gate data1, sizeof (itm_expr_t), 22977c478bd9Sstevel@tonic-gate &(expr->data.operand[1]), OBJ_REG_TAIL); 22987c478bd9Sstevel@tonic-gate break; 22997c478bd9Sstevel@tonic-gate } 23007c478bd9Sstevel@tonic-gate return (expr); 23017c478bd9Sstevel@tonic-gate } 23027c478bd9Sstevel@tonic-gate 23037c478bd9Sstevel@tonic-gate 23047c478bd9Sstevel@tonic-gate itm_expr_t * 23057c478bd9Sstevel@tonic-gate expr_assign(itm_expr_type_t type, 23067c478bd9Sstevel@tonic-gate itm_data_t *data0, itm_expr_t *data1) 23077c478bd9Sstevel@tonic-gate { 23087c478bd9Sstevel@tonic-gate itm_expr_t *expr; 23097c478bd9Sstevel@tonic-gate itmc_name_t *name; 23107c478bd9Sstevel@tonic-gate 23117c478bd9Sstevel@tonic-gate expr = malloc_vital(sizeof (itm_expr_t)); 23127c478bd9Sstevel@tonic-gate expr->type = type; 23137c478bd9Sstevel@tonic-gate expr->data.operand[1].itm_ptr = (itm_place2_t)(data1); 23147c478bd9Sstevel@tonic-gate 23157c478bd9Sstevel@tonic-gate name = name_lookup(data0, ITMC_OBJ_REGISTER); 23167c478bd9Sstevel@tonic-gate if (&name_lookup_error == name) { 23177c478bd9Sstevel@tonic-gate free(expr); 23187c478bd9Sstevel@tonic-gate exit(ITMC_STATUS_BT); 23197c478bd9Sstevel@tonic-gate } else if (NULL == name) { 23207c478bd9Sstevel@tonic-gate name = name_register(data0, ITMC_OBJ_REGISTER, NULL); 23217c478bd9Sstevel@tonic-gate name->reg_id = (reg_id++); 23227c478bd9Sstevel@tonic-gate } 23237c478bd9Sstevel@tonic-gate expr->data.operand[0].itm_ptr = name->reg_id; 23247c478bd9Sstevel@tonic-gate 23257c478bd9Sstevel@tonic-gate (void) obj_register(ITMC_OBJ_EXPR, NULL, 23267c478bd9Sstevel@tonic-gate data1, sizeof (itm_expr_t), 23277c478bd9Sstevel@tonic-gate &(expr->data.operand[1]), OBJ_REG_TAIL); 23287c478bd9Sstevel@tonic-gate return (expr); 23297c478bd9Sstevel@tonic-gate } 23307c478bd9Sstevel@tonic-gate 23317c478bd9Sstevel@tonic-gate 23327c478bd9Sstevel@tonic-gate itm_expr_t * 23337c478bd9Sstevel@tonic-gate expr_seq_to_int(itm_expr_t *expr) 23347c478bd9Sstevel@tonic-gate { 23357c478bd9Sstevel@tonic-gate itm_num_t num; 23367c478bd9Sstevel@tonic-gate unsigned char *p; 23377c478bd9Sstevel@tonic-gate int i; 23387c478bd9Sstevel@tonic-gate 23397c478bd9Sstevel@tonic-gate if (ITM_EXPR_SEQ == expr->type) { 23407c478bd9Sstevel@tonic-gate if ((sizeof (itm_place_t)) < expr->data.value.size) { 23417c478bd9Sstevel@tonic-gate p = (unsigned char *)(expr->data.value.place.itm_ptr); 23427c478bd9Sstevel@tonic-gate } else { 23437c478bd9Sstevel@tonic-gate p = (unsigned char *)&(expr->data.value.place.itm_64d); 23447c478bd9Sstevel@tonic-gate } 23457c478bd9Sstevel@tonic-gate for (i = 0, num = 0; 23467c478bd9Sstevel@tonic-gate i < expr->data.value.size; 23477c478bd9Sstevel@tonic-gate i++, p++) { 23487c478bd9Sstevel@tonic-gate num = ((num << 8) | *p); 23497c478bd9Sstevel@tonic-gate } 23507c478bd9Sstevel@tonic-gate free(expr); 23517c478bd9Sstevel@tonic-gate expr = expr_self_num(ITM_EXPR_INT, num); 23527c478bd9Sstevel@tonic-gate } 23537c478bd9Sstevel@tonic-gate return (expr); 23547c478bd9Sstevel@tonic-gate } 23557c478bd9Sstevel@tonic-gate 23567c478bd9Sstevel@tonic-gate 23577c478bd9Sstevel@tonic-gate itmc_name_t * 23587c478bd9Sstevel@tonic-gate name_lookup(itm_data_t *name, itm_type_t type) 23597c478bd9Sstevel@tonic-gate { 23607c478bd9Sstevel@tonic-gate itmc_name_t *p; 23617c478bd9Sstevel@tonic-gate 23627c478bd9Sstevel@tonic-gate TRACE_MESSAGE('N', ("name_lookup\t: \"%-16s\" %2ld %2ld %2ld\n", 23637c478bd9Sstevel@tonic-gate name_to_str(name), name->size, type, name_id)); 23647c478bd9Sstevel@tonic-gate 23657c478bd9Sstevel@tonic-gate if (0 == name->size) 23667c478bd9Sstevel@tonic-gate return (NULL); 23677c478bd9Sstevel@tonic-gate for (p = name_first; p; p = p->next) { 23687c478bd9Sstevel@tonic-gate if ((name->size != p->name.size) || 23697c478bd9Sstevel@tonic-gate (memcmp(NSPTR(name), NSPTR(&(p->name)), name->size))) { 23707c478bd9Sstevel@tonic-gate continue; 23717c478bd9Sstevel@tonic-gate } 23727c478bd9Sstevel@tonic-gate if ((type != p->type) && 23737c478bd9Sstevel@tonic-gate (((ITMC_OBJ_ACTION != type) && 23747c478bd9Sstevel@tonic-gate (ITMC_OBJ_ACTION != p->type)) || 23757c478bd9Sstevel@tonic-gate ((ITMC_OBJ_ACTION == type) && 23767c478bd9Sstevel@tonic-gate (ITMC_OBJ_DIREC != p->type) && 23777c478bd9Sstevel@tonic-gate (ITMC_OBJ_OP != p->type) && 23787c478bd9Sstevel@tonic-gate (ITMC_OBJ_MAP != p->type)) || 23797c478bd9Sstevel@tonic-gate ((ITMC_OBJ_ACTION == p->type) && 23807c478bd9Sstevel@tonic-gate (ITMC_OBJ_DIREC != type) && 23817c478bd9Sstevel@tonic-gate (ITMC_OBJ_OP != type) && 23827c478bd9Sstevel@tonic-gate (ITMC_OBJ_MAP != type)))) { 23837c478bd9Sstevel@tonic-gate itm_error( 23847c478bd9Sstevel@tonic-gate gettext("name type conflict: \"%1$s\" " 23857c478bd9Sstevel@tonic-gate "%2$s %3$s\n"), 23867c478bd9Sstevel@tonic-gate name_to_str(name), 23877c478bd9Sstevel@tonic-gate itm_name_type_name[type], 23887c478bd9Sstevel@tonic-gate itm_name_type_name[p->type]); 23897c478bd9Sstevel@tonic-gate error_deferred += 1; 23907c478bd9Sstevel@tonic-gate return (&name_lookup_error); 23917c478bd9Sstevel@tonic-gate } else { 23927c478bd9Sstevel@tonic-gate return (p); 23937c478bd9Sstevel@tonic-gate } 23947c478bd9Sstevel@tonic-gate } 23957c478bd9Sstevel@tonic-gate return (NULL); 23967c478bd9Sstevel@tonic-gate } 23977c478bd9Sstevel@tonic-gate 23987c478bd9Sstevel@tonic-gate 23997c478bd9Sstevel@tonic-gate itmc_name_t * 24007c478bd9Sstevel@tonic-gate name_refer(itm_data_t *name, itm_type_t type, itmc_ref_t *refp) 24017c478bd9Sstevel@tonic-gate { 24027c478bd9Sstevel@tonic-gate itmc_name_t *p; 24037c478bd9Sstevel@tonic-gate itmc_ref_link_t *rl; 24047c478bd9Sstevel@tonic-gate 24057c478bd9Sstevel@tonic-gate p = name_lookup(name, type); 24067c478bd9Sstevel@tonic-gate 24077c478bd9Sstevel@tonic-gate TRACE_MESSAGE('N', ("name_refer\t: \"%-16s\" %2ld %2ld %08p %2d %08p\n", 24087c478bd9Sstevel@tonic-gate name_to_str(name), name->size, type, refp, name_id, p)); 24097c478bd9Sstevel@tonic-gate 24107c478bd9Sstevel@tonic-gate if (&name_lookup_error == p) { 24117c478bd9Sstevel@tonic-gate return (NULL); 24127c478bd9Sstevel@tonic-gate } 24137c478bd9Sstevel@tonic-gate 24147c478bd9Sstevel@tonic-gate rl = malloc_vital(sizeof (itmc_ref_link_t)); 24157c478bd9Sstevel@tonic-gate 24167c478bd9Sstevel@tonic-gate rl->ref = refp; 24177c478bd9Sstevel@tonic-gate rl->next = NULL; 24187c478bd9Sstevel@tonic-gate 24197c478bd9Sstevel@tonic-gate if (NULL != p) { 24207c478bd9Sstevel@tonic-gate if (p->ref_last) { 24217c478bd9Sstevel@tonic-gate p->ref_last->next = rl; 24227c478bd9Sstevel@tonic-gate } else { 24237c478bd9Sstevel@tonic-gate p->ref_first = rl; 24247c478bd9Sstevel@tonic-gate } 24257c478bd9Sstevel@tonic-gate p->ref_last = rl; 24267c478bd9Sstevel@tonic-gate } else { 24277c478bd9Sstevel@tonic-gate p = malloc_vital(sizeof (itmc_name_t)); 24287c478bd9Sstevel@tonic-gate p->id = (name_id++); 24297c478bd9Sstevel@tonic-gate p->reg_id = 0; 24307c478bd9Sstevel@tonic-gate p->name = *name; 24317c478bd9Sstevel@tonic-gate p->type = type; 24327c478bd9Sstevel@tonic-gate #if !defined(_LP64) 24337c478bd9Sstevel@tonic-gate p->reloc.itm_pad = 0; 24347c478bd9Sstevel@tonic-gate #endif 24357c478bd9Sstevel@tonic-gate p->reloc.itm_ptr = 0; 24367c478bd9Sstevel@tonic-gate p->ref_first = rl; 24377c478bd9Sstevel@tonic-gate p->ref_last = rl; 24387c478bd9Sstevel@tonic-gate p->next = NULL; 24397c478bd9Sstevel@tonic-gate 24407c478bd9Sstevel@tonic-gate if (name_last) { 24417c478bd9Sstevel@tonic-gate name_last->next = p; 24427c478bd9Sstevel@tonic-gate } else { 24437c478bd9Sstevel@tonic-gate name_first = p; 24447c478bd9Sstevel@tonic-gate } 24457c478bd9Sstevel@tonic-gate name_last = p; 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate return (p); 24487c478bd9Sstevel@tonic-gate } 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate 24517c478bd9Sstevel@tonic-gate itmc_name_t * 24527c478bd9Sstevel@tonic-gate name_register(itm_data_t *name, itm_type_t type, itmc_ref_t *refp) 24537c478bd9Sstevel@tonic-gate { 24547c478bd9Sstevel@tonic-gate itmc_name_t *p; 24557c478bd9Sstevel@tonic-gate 24567c478bd9Sstevel@tonic-gate TRACE_MESSAGE('N', ("name_register\t: \"%-16s\" %2ld %2ld %08p %2ld\n", 24577c478bd9Sstevel@tonic-gate name_to_str(name), name->size, type, refp, name_id)); 24587c478bd9Sstevel@tonic-gate 24597c478bd9Sstevel@tonic-gate 24607c478bd9Sstevel@tonic-gate p = name_lookup(name, type); 24617c478bd9Sstevel@tonic-gate if (&name_lookup_error == p) { 24627c478bd9Sstevel@tonic-gate return (NULL); 24637c478bd9Sstevel@tonic-gate } 24647c478bd9Sstevel@tonic-gate if (NULL != p) { 24657c478bd9Sstevel@tonic-gate if (NULL != p->object) { 24667c478bd9Sstevel@tonic-gate itm_error(gettext( 24677c478bd9Sstevel@tonic-gate "same names are specified: %1$s\n"), 24687c478bd9Sstevel@tonic-gate name_to_str(name)); 24697c478bd9Sstevel@tonic-gate error_deferred += 1; 24707c478bd9Sstevel@tonic-gate return (NULL); 24717c478bd9Sstevel@tonic-gate } 24727c478bd9Sstevel@tonic-gate p->object = refp; 24737c478bd9Sstevel@tonic-gate } else { 24747c478bd9Sstevel@tonic-gate p = malloc_vital(sizeof (itmc_name_t)); 24757c478bd9Sstevel@tonic-gate p->id = (name_id++); 24767c478bd9Sstevel@tonic-gate p->reg_id = 0; 24777c478bd9Sstevel@tonic-gate p->name = *name; 24787c478bd9Sstevel@tonic-gate p->type = type; 24797c478bd9Sstevel@tonic-gate p->object = refp; 24807c478bd9Sstevel@tonic-gate p->reloc.itm_ptr = 0; 24817c478bd9Sstevel@tonic-gate #if !defined(_LP64) 24827c478bd9Sstevel@tonic-gate p->reloc.itm_pad = 0; 24837c478bd9Sstevel@tonic-gate #endif 24847c478bd9Sstevel@tonic-gate p->ref_first = NULL; 24857c478bd9Sstevel@tonic-gate p->ref_last = NULL; 24867c478bd9Sstevel@tonic-gate p->next = NULL; 24877c478bd9Sstevel@tonic-gate 24887c478bd9Sstevel@tonic-gate if (name_last) { 24897c478bd9Sstevel@tonic-gate name_last->next = p; 24907c478bd9Sstevel@tonic-gate } else { 24917c478bd9Sstevel@tonic-gate name_first = p; 24927c478bd9Sstevel@tonic-gate } 24937c478bd9Sstevel@tonic-gate name_last = p; 24947c478bd9Sstevel@tonic-gate } 24957c478bd9Sstevel@tonic-gate 24967c478bd9Sstevel@tonic-gate return (p); 24977c478bd9Sstevel@tonic-gate } 24987c478bd9Sstevel@tonic-gate 24997c478bd9Sstevel@tonic-gate 25007c478bd9Sstevel@tonic-gate int 25017c478bd9Sstevel@tonic-gate data_compare(const itm_data_t *d0, const itm_data_t *d1) 25027c478bd9Sstevel@tonic-gate { 25037c478bd9Sstevel@tonic-gate if (d0->size < d1->size) { 25047c478bd9Sstevel@tonic-gate if (memcmp(NSPTR(d0), NSPTR(d1), d0->size) < 0) { 25057c478bd9Sstevel@tonic-gate return (-1); 25067c478bd9Sstevel@tonic-gate } else { 25077c478bd9Sstevel@tonic-gate return (1); 25087c478bd9Sstevel@tonic-gate } 25097c478bd9Sstevel@tonic-gate } else if (d0->size == d1->size) { 25107c478bd9Sstevel@tonic-gate return (memcmp(NSPTR(d0), NSPTR(d1), d0->size)); 25117c478bd9Sstevel@tonic-gate } else /* (d0->size > d1->size) */ { 25127c478bd9Sstevel@tonic-gate if (memcmp(NSPTR(d0), NSPTR(d1), d1->size) <= 0) { 25137c478bd9Sstevel@tonic-gate return (-1); 25147c478bd9Sstevel@tonic-gate } else { 25157c478bd9Sstevel@tonic-gate return (1); 25167c478bd9Sstevel@tonic-gate } 25177c478bd9Sstevel@tonic-gate } 25187c478bd9Sstevel@tonic-gate } 25197c478bd9Sstevel@tonic-gate 25207c478bd9Sstevel@tonic-gate int 25217c478bd9Sstevel@tonic-gate data_pair_compare(itmc_data_pair_t **p0, itmc_data_pair_t **p1) 25227c478bd9Sstevel@tonic-gate { 25237c478bd9Sstevel@tonic-gate int r; 25247c478bd9Sstevel@tonic-gate itm_data_t *d0; 25257c478bd9Sstevel@tonic-gate itm_data_t *d1; 25267c478bd9Sstevel@tonic-gate uchar_t *c0; 25277c478bd9Sstevel@tonic-gate uchar_t *c1; 25287c478bd9Sstevel@tonic-gate size_t s; 25297c478bd9Sstevel@tonic-gate int i; 25307c478bd9Sstevel@tonic-gate 25317c478bd9Sstevel@tonic-gate d0 = &((*p0)->data0); 25327c478bd9Sstevel@tonic-gate d1 = &((*p1)->data0); 25337c478bd9Sstevel@tonic-gate c0 = NSPTR(d0); 25347c478bd9Sstevel@tonic-gate c1 = NSPTR(d1); 25357c478bd9Sstevel@tonic-gate if (d0->size == d1->size) { 25367c478bd9Sstevel@tonic-gate s = d0->size; 25377c478bd9Sstevel@tonic-gate } else if (d0->size < d1->size) { 25387c478bd9Sstevel@tonic-gate s = d1->size - d0->size; 25397c478bd9Sstevel@tonic-gate for (i = 0; i < s; i++, c1++) { 25407c478bd9Sstevel@tonic-gate if (0x00 != *c1) { 25417c478bd9Sstevel@tonic-gate return (-1); 25427c478bd9Sstevel@tonic-gate } 25437c478bd9Sstevel@tonic-gate } 25447c478bd9Sstevel@tonic-gate s = d0->size; 25457c478bd9Sstevel@tonic-gate } else { 25467c478bd9Sstevel@tonic-gate assert(d0->size > d1->size); 25477c478bd9Sstevel@tonic-gate s = d0->size - d1->size; 25487c478bd9Sstevel@tonic-gate for (i = 0; i < s; i++, c0++) { 25497c478bd9Sstevel@tonic-gate if (0x00 != *c0) { 25507c478bd9Sstevel@tonic-gate return (1); 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate } 25537c478bd9Sstevel@tonic-gate s = d1->size; 25547c478bd9Sstevel@tonic-gate } 25557c478bd9Sstevel@tonic-gate r = memcmp(c0, c1, s); 25567c478bd9Sstevel@tonic-gate if (0 == r) { 25577c478bd9Sstevel@tonic-gate itm_data_t *d; 25587c478bd9Sstevel@tonic-gate if (c0 == NSPTR(d0)) { 25597c478bd9Sstevel@tonic-gate d = d0; 25607c478bd9Sstevel@tonic-gate } else { 25617c478bd9Sstevel@tonic-gate assert(c1 == NSPTR(d0)); 25627c478bd9Sstevel@tonic-gate d = d1; 25637c478bd9Sstevel@tonic-gate } 25647c478bd9Sstevel@tonic-gate itm_error(gettext( 25657c478bd9Sstevel@tonic-gate "distinct source values are specified: 0x%1$s\n"), 25667c478bd9Sstevel@tonic-gate data_to_hexadecimal(d)); 25677c478bd9Sstevel@tonic-gate error_deferred += 1; 25687c478bd9Sstevel@tonic-gate } 25697c478bd9Sstevel@tonic-gate return (r); 25707c478bd9Sstevel@tonic-gate } 25717c478bd9Sstevel@tonic-gate 25727c478bd9Sstevel@tonic-gate 25737c478bd9Sstevel@tonic-gate static long 25747c478bd9Sstevel@tonic-gate data_to_long(itm_data_t *data) 25757c478bd9Sstevel@tonic-gate { 25767c478bd9Sstevel@tonic-gate long l; 25777c478bd9Sstevel@tonic-gate int i; 25787c478bd9Sstevel@tonic-gate unsigned char *p; 25797c478bd9Sstevel@tonic-gate 25807c478bd9Sstevel@tonic-gate if ((sizeof (itm_place_t)) < data->size) { 25817c478bd9Sstevel@tonic-gate return (0); 25827c478bd9Sstevel@tonic-gate } 25837c478bd9Sstevel@tonic-gate for (l = 0, i = 0, p = (unsigned char *)&(data->place); 25847c478bd9Sstevel@tonic-gate i < data->size; 25857c478bd9Sstevel@tonic-gate i++, p++) { 25867c478bd9Sstevel@tonic-gate l <<= 8; 25877c478bd9Sstevel@tonic-gate l |= *p; 25887c478bd9Sstevel@tonic-gate } 25897c478bd9Sstevel@tonic-gate return (l); 25907c478bd9Sstevel@tonic-gate } 2591