thunk.h 1.2 KB

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