static int dis_i386_handle_attach(dis_handle_t *dhp) { dis_handle_i386_t *dhx; /* * Validate architecture flags */ if (dhp->dh_flags & ~(DIS_X86_SIZE16 | DIS_X86_SIZE32 | DIS_X86_SIZE64 | DIS_OCTAL | DIS_NOIMMSYM)) { (void) dis_seterrno(E_DIS_INVALFLAG); return (-1); } /* * Create and initialize the internal structure */ if ((dhx = dis_zalloc(sizeof (dis_handle_i386_t))) == NULL) { (void) dis_seterrno(E_DIS_NOMEM); return (-1); } dhp->dh_arch_private = dhx; /* * Initialize x86-specific architecture structure */ if (dhp->dh_flags & DIS_X86_SIZE16) dhx->dhx_mode = SIZE16; else if (dhp->dh_flags & DIS_X86_SIZE64) dhx->dhx_mode = SIZE64; else dhx->dhx_mode = SIZE32; if (dhp->dh_flags & DIS_OCTAL) dhx->dhx_dis.d86_flags = DIS_F_OCTAL; dhx->dhx_dis.d86_sprintf_func = dis_snprintf; dhx->dhx_dis.d86_get_byte = get_byte; dhx->dhx_dis.d86_sym_lookup = do_lookup; dhx->dhx_dis.d86_check_func = check_func; dhx->dhx_dis.d86_data = dhp; return (0); }
dis_handle_t * dis_handle_create(int flags, void *data, dis_lookup_f lookup_func, dis_read_f read_func) { dis_handle_t *dhp; dis_arch_t *arch = NULL; int i; /* Select an architecture based on flags */ for (i = 0; dis_archs[i] != NULL; i++) { if (dis_archs[i]->da_supports_flags(flags)) { arch = dis_archs[i]; break; } } if (arch == NULL) { (void) dis_seterrno(E_DIS_UNSUPARCH); return (NULL); } if ((dhp = dis_zalloc(sizeof (dis_handle_t))) == NULL) { (void) dis_seterrno(E_DIS_NOMEM); return (NULL); } dhp->dh_arch = arch; dhp->dh_lookup = lookup_func; dhp->dh_read = read_func; dhp->dh_flags = flags; dhp->dh_data = data; /* * Allow the architecture-specific code to allocate * its private data. */ if (arch->da_handle_attach(dhp) != 0) { dis_free(dhp, sizeof (dis_handle_t)); /* dis errno already set */ return (NULL); } return (dhp); }