diff options
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 000000000..c9e6fd39f --- /dev/null +++ b/src/common/thunk.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #ifndef _THUNK_H_ | ||
| 6 | #define _THUNK_H_ | ||
| 7 | |||
| 8 | #include <map> | ||
| 9 | |||
| 10 | #include "common.h" | ||
| 11 | #include "x64Emitter.h" | ||
| 12 | |||
| 13 | // This simple class creates a wrapper around a C/C++ function that saves all fp state | ||
| 14 | // before entering it, and restores it upon exit. This is required to be able to selectively | ||
| 15 | // call functions from generated code, without inflicting the performance hit and increase | ||
| 16 | // of complexity that it means to protect the generated code from this problem. | ||
| 17 | |||
| 18 | // This process is called thunking. | ||
| 19 | |||
| 20 | // There will only ever be one level of thunking on the stack, plus, | ||
| 21 | // we don't want to pollute the stack, so we store away regs somewhere global. | ||
| 22 | // NOT THREAD SAFE. This may only be used from the CPU thread. | ||
| 23 | // Any other thread using this stuff will be FATAL. | ||
| 24 | |||
| 25 | class ThunkManager : public Gen::XCodeBlock | ||
| 26 | { | ||
| 27 | std::map<void *, const u8 *> thunks; | ||
| 28 | |||
| 29 | const u8 *save_regs; | ||
| 30 | const u8 *load_regs; | ||
| 31 | |||
| 32 | public: | ||
| 33 | ThunkManager() { | ||
| 34 | Init(); | ||
| 35 | } | ||
| 36 | ~ThunkManager() { | ||
| 37 | Shutdown(); | ||
| 38 | } | ||
| 39 | void *ProtectFunction(void *function, int num_params); | ||
| 40 | private: | ||
| 41 | void Init(); | ||
| 42 | void Shutdown(); | ||
| 43 | void Reset(); | ||
| 44 | }; | ||
| 45 | |||
| 46 | #endif // _THUNK_H_ | ||