simplify some exception classes

Signed-off-by: Double Sine <xiao_ai_yu@live.cn>
This commit is contained in:
Double Sine
2022-05-07 23:08:50 +08:00
parent 73ff67d4a5
commit b3046b43f0
9 changed files with 99 additions and 105 deletions

View File

@@ -18,23 +18,9 @@ namespace nkg {
using rva_t = uintptr_t;
using va_t = uintptr_t;
class parse_error : public ::nkg::exception {
public:
parse_error(std::string_view file, int line, std::string_view message) noexcept :
::nkg::exception(file, line, message) {}
};
class bad_fo_exception : public ::nkg::exception {
public:
bad_fo_exception(std::string_view file, int line, std::string_view message) noexcept :
::nkg::exception(file, line, message) {}
};
class bad_va_exception : public ::nkg::exception {
public:
bad_va_exception(std::string_view file, int line, std::string_view message) noexcept :
::nkg::exception(file, line, message) {}
};
class parse_error;
class bad_fo_exception;
class bad_va_exception;
private:
size_t m_elf_size;
@@ -236,4 +222,16 @@ namespace nkg {
const std::map<va_t, size_t>& relocation_distribute() const;
};
class elf64_interpreter::parse_error : public ::nkg::exception {
using ::nkg::exception::exception;
};
class elf64_interpreter::bad_fo_exception : public ::nkg::exception {
using ::nkg::exception::exception;
};
class elf64_interpreter::bad_va_exception : public ::nkg::exception {
using ::nkg::exception::exception;
};
}

View File

@@ -12,33 +12,7 @@ namespace nkg {
class keystone_assembler {
public:
class backend_error : public ::nkg::exception {
public:
using error_code_t = ks_err;
private:
error_code_t m_error_code;
std::string m_error_string;
public:
backend_error(std::string_view file, int line, error_code_t keystone_err, std::string_view message) noexcept :
::nkg::exception(file, line, message), m_error_code(keystone_err), m_error_string(ks_strerror(keystone_err)) {}
[[nodiscard]]
virtual bool error_code_exists() const noexcept override {
return true;
}
[[nodiscard]]
virtual intptr_t error_code() const noexcept override {
return m_error_code;
}
[[nodiscard]]
virtual const std::string& error_string() const noexcept override {
return m_error_string;
}
};
class backend_error;
private:
resource_wrapper<resource_traits::keystone::keystone_handle> m_keystone_engine;
@@ -52,4 +26,32 @@ namespace nkg {
std::vector<uint8_t> assemble(std::string_view asm_string, uint64_t asm_address = 0) const;
};
class keystone_assembler::backend_error : public ::nkg::exception {
public:
using error_code_t = ks_err;
private:
error_code_t m_error_code;
std::string m_error_string;
public:
backend_error(std::string_view file, int line, error_code_t keystone_err, std::string_view message) noexcept :
::nkg::exception(file, line, message), m_error_code(keystone_err), m_error_string(ks_strerror(keystone_err)) {}
[[nodiscard]]
virtual bool error_code_exists() const noexcept override {
return true;
}
[[nodiscard]]
virtual intptr_t error_code() const noexcept override {
return m_error_code;
}
[[nodiscard]]
virtual const std::string& error_string() const noexcept override {
return m_error_string;
}
};
}