clean-up uc_support() API

- rename to more obviously-named uc_arch_supported()
- remove UC_ARCH_ALL and associated test -- There's no point in having this
  API, and it was improperly implemented anyway.
- remove now unneeded archs_enable() and all_arch
- add UNICORN_HAS_PPC test -- This seems to be only partially implemented
This commit is contained in:
Jonathon Reinhart 2015-08-23 21:10:47 -04:00
parent ee9e2d6a12
commit 11cc9ec9ba
2 changed files with 29 additions and 54 deletions

View file

@ -78,7 +78,6 @@ typedef enum uc_arch {
UC_ARCH_SPARC, // Sparc architecture UC_ARCH_SPARC, // Sparc architecture
UC_ARCH_M68K, // M68K architecture UC_ARCH_M68K, // M68K architecture
UC_ARCH_MAX, UC_ARCH_MAX,
UC_ARCH_ALL = 0xFFFF, // All architectures - for uc_support()
} uc_arch; } uc_arch;
// Mode type // Mode type
@ -203,16 +202,14 @@ unsigned int uc_version(unsigned int *major, unsigned int *minor);
/* /*
This API can be used to either ask for archs supported by this library. Determine if the given architecture is supported by this library.
To check if a particular arch is supported by this library, set @query to @arch: architecture type (UC_ARCH_*)
arch mode (UC_ARCH_* value).
To verify if this library supports all the archs, use UC_ARCH_ALL.
@return True if this library supports the given arch. @return True if this library supports the given arch.
*/ */
UNICORN_EXPORT UNICORN_EXPORT
bool uc_support(int query); bool uc_arch_supported(uc_arch arch);
/* /*

74
uc.c
View file

@ -36,43 +36,9 @@ static uint64_t map_begin[32], map_end[32];
static int map_count = 0; static int map_count = 0;
static unsigned int all_arch = 0;
static void archs_enable(void)
{
static bool initialized = false;
if (initialized)
return;
#ifdef UNICORN_HAS_ARM
all_arch = all_arch + (1 << UC_ARCH_ARM);
#endif
#ifdef UNICORN_HAS_ARM64
all_arch = all_arch + (1 << UC_ARCH_ARM64);
#endif
#ifdef UNICORN_HAS_MIPS
all_arch = all_arch + (1 << UC_ARCH_MIPS);
#endif
#ifdef UNICORN_HAS_SPARC
all_arch = all_arch + (1 << UC_ARCH_SPARC);
#endif
#ifdef UNICORN_HAS_M68K
all_arch = all_arch + (1 << UC_ARCH_M68K);
#endif
#ifdef UNICORN_HAS_X86
all_arch = all_arch + (1 << UC_ARCH_X86);
#endif
initialized = true;
}
UNICORN_EXPORT UNICORN_EXPORT
unsigned int uc_version(unsigned int *major, unsigned int *minor) unsigned int uc_version(unsigned int *major, unsigned int *minor)
{ {
archs_enable();
if (major != NULL && minor != NULL) { if (major != NULL && minor != NULL) {
*major = UC_API_MAJOR; *major = UC_API_MAJOR;
*minor = UC_API_MINOR; *minor = UC_API_MINOR;
@ -131,20 +97,34 @@ const char *uc_strerror(uc_err code)
UNICORN_EXPORT UNICORN_EXPORT
bool uc_support(int query) bool uc_arch_supported(uc_arch arch)
{ {
archs_enable(); switch (arch) {
#ifdef UNICORN_HAS_ARM
case UC_ARCH_ARM: return true;
#endif
#ifdef UNICORN_HAS_ARM64
case UC_ARCH_ARM64: return true;
#endif
#ifdef UNICORN_HAS_M68K
case UC_ARCH_M68K: return true;
#endif
#ifdef UNICORN_HAS_MIPS
case UC_ARCH_MIPS: return true;
#endif
#ifdef UNICORN_HAS_PPC
case UC_ARCH_PPC: return true;
#endif
#ifdef UNICORN_HAS_SPARC
case UC_ARCH_SPARC: return true;
#endif
#ifdef UNICORN_HAS_X86
case UC_ARCH_X86: return true;
#endif
if (query == UC_ARCH_ALL) /* Invalid or disabled arch */
return all_arch == ((1 << UC_ARCH_ARM) | (1 << UC_ARCH_ARM64) | default: return false;
(1 << UC_ARCH_MIPS) | (1 << UC_ARCH_X86) | }
(1 << UC_ARCH_M68K) | (1 << UC_ARCH_SPARC));
if ((unsigned int)query < UC_ARCH_MAX)
return ((all_arch & (1 << query)) != 0);
// unsupported query
return false;
} }
@ -153,8 +133,6 @@ uc_err uc_open(uc_arch arch, uc_mode mode, uch *handle)
{ {
struct uc_struct *uc; struct uc_struct *uc;
archs_enable();
if (arch < UC_ARCH_MAX) { if (arch < UC_ARCH_MAX) {
uc = calloc(1, sizeof(*uc)); uc = calloc(1, sizeof(*uc));
if (!uc) { if (!uc) {