Return new UC_ERR_OVERFLOW instead of UC_ERR_NOMEM when reg buffer is too small
This commit is contained in:
@@ -192,6 +192,7 @@ typedef enum uc_err {
|
|||||||
UC_ERR_HOOK_EXIST, // hook for this event already existed
|
UC_ERR_HOOK_EXIST, // hook for this event already existed
|
||||||
UC_ERR_RESOURCE, // Insufficient resource: uc_emu_start()
|
UC_ERR_RESOURCE, // Insufficient resource: uc_emu_start()
|
||||||
UC_ERR_EXCEPTION, // Unhandled CPU exception
|
UC_ERR_EXCEPTION, // Unhandled CPU exception
|
||||||
|
UC_ERR_OVERFLOW, // Provided buffer is not large enough: uc_reg_*2()
|
||||||
} uc_err;
|
} uc_err;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -807,7 +808,7 @@ uc_err uc_reg_read(uc_engine *uc, int regid, void *value);
|
|||||||
@size: size of value being written; on return, size of value written
|
@size: size of value being written; on return, size of value written
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
||||||
invalid; UC_ERR_NOMEM if value is not large enough.
|
invalid; UC_ERR_OVERFLOW if value is not large enough for the register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_reg_write2(uc_engine *uc, int regid, const void *value, size_t *size);
|
uc_err uc_reg_write2(uc_engine *uc, int regid, const void *value, size_t *size);
|
||||||
@@ -821,7 +822,7 @@ uc_err uc_reg_write2(uc_engine *uc, int regid, const void *value, size_t *size);
|
|||||||
@size: size of value buffer; on return, size of value read
|
@size: size of value buffer; on return, size of value read
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
||||||
invalid; UC_ERR_NOMEM if value is not large enough.
|
invalid; UC_ERR_OVERFLOW if value is not large enough to hold the register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_reg_read2(uc_engine *uc, int regid, void *value, size_t *size);
|
uc_err uc_reg_read2(uc_engine *uc, int regid, void *value, size_t *size);
|
||||||
@@ -865,7 +866,8 @@ uc_err uc_reg_read_batch(uc_engine *uc, int *regs, void **vals, int count);
|
|||||||
@count: length of *regs, *vals and *sizes
|
@count: length of *regs, *vals and *sizes
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
||||||
invalid; UC_ERR_NOMEM if some value is not large enough.
|
invalid; UC_ERR_OVERFLOW if some value is not large enough for the
|
||||||
|
corresponding register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_reg_write_batch2(uc_engine *uc, int *regs, const void *const *vals,
|
uc_err uc_reg_write_batch2(uc_engine *uc, int *regs, const void *const *vals,
|
||||||
@@ -882,7 +884,8 @@ uc_err uc_reg_write_batch2(uc_engine *uc, int *regs, const void *const *vals,
|
|||||||
@count: length of *regs, *vals and *sizes
|
@count: length of *regs, *vals and *sizes
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
||||||
invalid; UC_ERR_NOMEM if some value is not large enough.
|
invalid; UC_ERR_OVERFLOW if some value is not large enough to hold the
|
||||||
|
corresponding register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_reg_read_batch2(uc_engine *uc, int *regs, void *const *vals,
|
uc_err uc_reg_read_batch2(uc_engine *uc, int *regs, void *const *vals,
|
||||||
@@ -1218,7 +1221,7 @@ uc_err uc_context_reg_read(uc_context *ctx, int regid, void *value);
|
|||||||
@size: size of value being written; on return, size of value written
|
@size: size of value being written; on return, size of value written
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
||||||
invalid; UC_ERR_NOMEM if value is not large enough.
|
invalid; UC_ERR_OVERFLOW if value is not large enough for the register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_context_reg_write2(uc_context *ctx, int regid, const void *value,
|
uc_err uc_context_reg_write2(uc_context *ctx, int regid, const void *value,
|
||||||
@@ -1233,7 +1236,7 @@ uc_err uc_context_reg_write2(uc_context *ctx, int regid, const void *value,
|
|||||||
@size: size of value buffer; on return, size of value read
|
@size: size of value buffer; on return, size of value read
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if register number or value is
|
||||||
invalid; UC_ERR_NOMEM if value is not large enough.
|
invalid; UC_ERR_OVERFLOW if value is not large enough to hold the register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_context_reg_read2(uc_context *ctx, int regid, void *value,
|
uc_err uc_context_reg_read2(uc_context *ctx, int regid, void *value,
|
||||||
@@ -1279,7 +1282,8 @@ uc_err uc_context_reg_read_batch(uc_context *ctx, int *regs, void **vals,
|
|||||||
@count: length of *regs, *vals and *sizes
|
@count: length of *regs, *vals and *sizes
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
||||||
invalid; UC_ERR_NOMEM if some value is not large enough.
|
invalid; UC_ERR_OVERFLOW if some value is not large enough for the
|
||||||
|
corresponding register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_context_reg_write_batch2(uc_context *ctx, int *regs,
|
uc_err uc_context_reg_write_batch2(uc_context *ctx, int *regs,
|
||||||
@@ -1297,7 +1301,8 @@ uc_err uc_context_reg_write_batch2(uc_context *ctx, int *regs,
|
|||||||
@count: length of *regs, *vals and *sizes
|
@count: length of *regs, *vals and *sizes
|
||||||
|
|
||||||
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
@return UC_ERR_OK on success; UC_ERR_ARG if some register number or value is
|
||||||
invalid; UC_ERR_NOMEM if some value is not large enough.
|
invalid; UC_ERR_OVERFLOW if some value is not large enough to hold the
|
||||||
|
corresponding register.
|
||||||
*/
|
*/
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_context_reg_read_batch2(uc_context *ctx, int *regs, void *const *vals,
|
uc_err uc_context_reg_read_batch2(uc_context *ctx, int *regs, void *const *vals,
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ static inline void uc_common_init(struct uc_struct* uc)
|
|||||||
|
|
||||||
#define CHECK_REG_TYPE(type) do { \
|
#define CHECK_REG_TYPE(type) do { \
|
||||||
if (unlikely(*size < sizeof(type))) { \
|
if (unlikely(*size < sizeof(type))) { \
|
||||||
return UC_ERR_NOMEM; \
|
return UC_ERR_OVERFLOW; \
|
||||||
} \
|
} \
|
||||||
*size = sizeof(type); \
|
*size = sizeof(type); \
|
||||||
ret = UC_ERR_OK; \
|
ret = UC_ERR_OK; \
|
||||||
|
|||||||
2
uc.c
2
uc.c
@@ -148,6 +148,8 @@ const char *uc_strerror(uc_err code)
|
|||||||
return "Insufficient resource (UC_ERR_RESOURCE)";
|
return "Insufficient resource (UC_ERR_RESOURCE)";
|
||||||
case UC_ERR_EXCEPTION:
|
case UC_ERR_EXCEPTION:
|
||||||
return "Unhandled CPU exception (UC_ERR_EXCEPTION)";
|
return "Unhandled CPU exception (UC_ERR_EXCEPTION)";
|
||||||
|
case UC_ERR_OVERFLOW:
|
||||||
|
return "Provided buffer is too small (UC_ERR_OVERFLOW)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user