/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <libdisasm.h>
#include <stdlib.h>
#include <stdio.h>
#include "dis_tables.h"
#include "libdisasm_impl.h"
struct dis_handle {
void *dh_data;
int dh_flags;
int dh_mode;
};
/*
* Returns true if we are near the end of a function. This is a cheap hack at
* detecting NULL padding between functions. If we're within a few bytes of the
* next function, or past the start, then return true.
*/
static int
{
!= 0)
return (0);
return (1);
}
static int
{
sizeof (byte))
return (-1);
return ((int)byte);
}
static int
{
}
{
/*
* Validate architecture flags
*/
DIS_OCTAL | DIS_NOIMMSYM)) {
(void) dis_seterrno(E_DIS_INVALFLAG);
return (NULL);
}
/*
* Create and initialize the internal structure
*/
(void) dis_seterrno(E_DIS_NOMEM);
return (NULL);
}
/*
* Initialize x86-specific architecture structure
*/
if (flags & DIS_X86_SIZE16)
else if (flags & DIS_X86_SIZE64)
else
return (dhp);
}
int
{
/* DIS_NOIMMSYM might not be set until now, so update */
else
return (-1);
buflen);
return (0);
}
void
{
}
void
{
}
void
{
}
void
{
}
/* ARGSUSED */
int
{
return (15);
}
#define MIN(a, b) ((a) < (b) ? (a) : (b))
/*
* Return the previous instruction. On x86, we have no choice except to
* disassemble everything from the start of the symbol, and stop when we have
* reached our instruction address. If we're not in the middle of a known
* symbol, then we return the same address to indicate failure.
*/
{
if (n <= 0)
return (pc);
return (res);
nseen++;
/* if we cannot make forward progress, give up */
goto done;
}
/*
* We scanned past %pc, but didn't find an instruction that
* started at %pc. This means that either the caller specified
* an invalid address, or we ran into something other than code
* during our scan. Virtually any combination of bytes can be
* construed as a valid Intel instruction, so any non-code bytes
* we encounter will have thrown off the scan.
*/
goto done;
}
done:
return (res);
}