diff options
author | bunnei <ericbunnie@gmail.com> | 2014-04-08 19:25:03 -0400 |
---|---|---|
committer | bunnei <ericbunnie@gmail.com> | 2014-04-08 19:25:03 -0400 |
commit | 63e46abdb8764bc97e91bae862c8d461e61b1965 (patch) | |
tree | e73f4aa25d7b4015a265e7bbfb6004dab7561027 /src/common/thunk.h | |
parent | 03c245345e1f319da5007c15019ed54432029fb8 (diff) |
got rid of 'src' folders in each sub-project
Diffstat (limited to 'src/common/thunk.h')
-rw-r--r-- | src/common/thunk.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/common/thunk.h b/src/common/thunk.h new file mode 100644 index 00000000..c9e6fd39 --- /dev/null +++ b/src/common/thunk.h @@ -0,0 +1,46 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#ifndef _THUNK_H_ +#define _THUNK_H_ + +#include <map> + +#include "common.h" +#include "x64Emitter.h" + +// This simple class creates a wrapper around a C/C++ function that saves all fp state +// before entering it, and restores it upon exit. This is required to be able to selectively +// call functions from generated code, without inflicting the performance hit and increase +// of complexity that it means to protect the generated code from this problem. + +// This process is called thunking. + +// There will only ever be one level of thunking on the stack, plus, +// we don't want to pollute the stack, so we store away regs somewhere global. +// NOT THREAD SAFE. This may only be used from the CPU thread. +// Any other thread using this stuff will be FATAL. + +class ThunkManager : public Gen::XCodeBlock +{ + std::map<void *, const u8 *> thunks; + + const u8 *save_regs; + const u8 *load_regs; + +public: + ThunkManager() { + Init(); + } + ~ThunkManager() { + Shutdown(); + } + void *ProtectFunction(void *function, int num_params); +private: + void Init(); + void Shutdown(); + void Reset(); +}; + +#endif // _THUNK_H_ |