zydis/include/Zydis/Status.h

181 lines
6.6 KiB
C
Raw Normal View History

2016-05-26 03:25:48 +08:00
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
2016-05-26 03:25:48 +08:00
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
2017-07-25 07:04:25 +08:00
/**
* @file
* @brief Status code definitions and check macros.
*/
2016-05-26 03:25:48 +08:00
#ifndef ZYDIS_STATUS_H
#define ZYDIS_STATUS_H
#include <Zydis/CommonTypes.h>
2016-05-26 03:25:48 +08:00
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* @brief Defines the @c ZydisStatus datatype.
*/
typedef uint32_t ZydisStatus;
/**
* @brief Values that represent a zydis status-codes.
*/
enum ZydisStatusCode
{
/* ------------------------------------------------------------------------------------------ */
/* General */
/* ------------------------------------------------------------------------------------------ */
2016-05-26 03:25:48 +08:00
/**
* @brief The operation completed successfully.
*/
2017-09-24 01:53:48 +08:00
ZYDIS_STATUS_SUCCESS = 0x00000000,
2016-05-26 03:25:48 +08:00
/**
* @brief An invalid parameter was passed to a function.
*/
ZYDIS_STATUS_INVALID_PARAMETER,
2016-05-26 03:25:48 +08:00
/**
* @brief An attempt was made to perform an invalid operation.
*/
ZYDIS_STATUS_INVALID_OPERATION,
2017-07-10 20:34:25 +08:00
/**
* @brief A buffer passed to a function was too small to complete the requested operation.
*/
ZYDIS_STATUS_INSUFFICIENT_BUFFER_SIZE,
/* ------------------------------------------------------------------------------------------ */
/* Decoder */
/* ------------------------------------------------------------------------------------------ */
2016-05-26 03:25:48 +08:00
/**
* @brief An attempt was made to read data from an input data-source that has no more data
* available.
*/
ZYDIS_STATUS_NO_MORE_DATA,
/**
* @brief An general error occured while decoding the current instruction. The instruction
* might be undefined.
*/
ZYDIS_STATUS_DECODING_ERROR,
/**
* @brief The instruction exceeded the maximum length of 15 bytes.
*/
ZYDIS_STATUS_INSTRUCTION_TOO_LONG,
/**
* @brief The instruction encoded an invalid register.
*/
2017-01-20 07:01:56 +08:00
ZYDIS_STATUS_BAD_REGISTER,
/**
* @brief A lock-prefix (F0) was found while decoding an instruction that does not support
* locking.
*/
ZYDIS_STATUS_ILLEGAL_LOCK,
2016-05-26 03:25:48 +08:00
/**
* @brief A legacy-prefix (F2, F3, 66) was found while decoding a XOP/VEX/EVEX/MVEX
* instruction.
2016-05-26 03:25:48 +08:00
*/
ZYDIS_STATUS_ILLEGAL_LEGACY_PFX,
/**
* @brief A rex-prefix was found while decoding a XOP/VEX/EVEX/MVEX instruction.
*/
ZYDIS_STATUS_ILLEGAL_REX,
/**
* @brief An invalid opcode-map value was found while decoding a XOP/VEX/EVEX/MVEX-prefix.
*/
ZYDIS_STATUS_INVALID_MAP,
/**
* @brief An error occured while decoding the EVEX-prefix.
*/
ZYDIS_STATUS_MALFORMED_EVEX,
/**
* @brief An error occured while decoding the MVEX-prefix.
*/
ZYDIS_STATUS_MALFORMED_MVEX, // TODO: Do we need this?
/**
* @brief An invalid write-mask was specified for an EVEX/MVEX instruction.
*/
ZYDIS_STATUS_INVALID_MASK,
/* ------------------------------------------------------------------------------------------ */
/* Encoder */
/* ------------------------------------------------------------------------------------------ */
ZYDIS_STATUS_IMPOSSIBLE_INSTRUCTION,
/* ------------------------------------------------------------------------------------------ */
/* Misc */
/* ------------------------------------------------------------------------------------------ */
2016-11-24 17:57:23 +08:00
/**
* @brief The base value for user-defined status codes.
*/
2017-09-24 01:53:48 +08:00
ZYDIS_STATUS_USER = 0x10000000
// Max value entry intentionally omitted since users might
// define custom error codes for formatter hooks.
2016-05-26 03:25:48 +08:00
};
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/**
* @brief Checks if a zydis operation was successfull.
2016-05-26 03:25:48 +08:00
*
* @param status The zydis status-code to check.
2016-05-26 03:25:48 +08:00
*/
#define ZYDIS_SUCCESS(status) (status == ZYDIS_STATUS_SUCCESS)
/**
* @brief Checks if a zydis operation was successfull and returns the status-code, if not.
*
* @param status The zydis status-code to check.
*/
#define ZYDIS_CHECK(status) \
2017-01-20 07:01:56 +08:00
do \
{ \
ZydisStatus s = status; \
if (!ZYDIS_SUCCESS(s)) \
{ \
return s; \
} \
} while (0)
2016-05-26 03:25:48 +08:00
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_STATUS_H */