Exception handler abstraction class

This commit is contained in:
Dr. Chat
2015-09-11 17:07:12 -05:00
parent edef57065b
commit 8e716a3a7e
2 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_BASE_EXCEPTION_HANDLER_H_
#define XENIA_BASE_EXCEPTION_HANDLER_H_
#include <functional>
#include <vector>
namespace xe {
class ExceptionHandler {
public:
struct Info {
enum {
kInvalidException = 0,
kAccessViolation,
} code = kInvalidException;
uint64_t pc = 0; // Program counter address. RIP on x64.
uint64_t fault_address =
0; // In case of AV, address that was read from/written to.
void* thread_context = nullptr; // Platform-specific thread context info.
};
typedef std::function<bool(Info* ex_info)> Handler;
// Static initialization. Only call this once!
static bool Initialize();
// Install an exception handler. Returns an ID which you can save to remove
// this later. This will install the exception handler in the last place
// on Windows.
static uint32_t Install(Handler fn);
static bool Remove(uint32_t id);
static const std::vector<Handler>& handlers() { return handlers_; }
private:
static std::vector<Handler> handlers_;
};
}; // namespace xe
#endif // XENIA_BASE_EXCEPTION_HANDLER_H_