2014-12-17 06:38:14 +01:00
|
|
|
// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
2013-09-05 02:17:46 +02:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-08-17 19:45:50 +02:00
|
|
|
#pragma once
|
2013-09-05 02:17:46 +02:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2015-05-06 09:06:12 +02:00
|
|
|
#include "common/common_types.h"
|
2013-09-05 02:17:46 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
2014-04-02 00:20:08 +02:00
|
|
|
std::map<void *, const u8 *> thunks;
|
2013-09-05 02:17:46 +02:00
|
|
|
|
2014-04-02 00:20:08 +02:00
|
|
|
const u8 *save_regs;
|
|
|
|
const u8 *load_regs;
|
2013-09-05 02:17:46 +02:00
|
|
|
|
|
|
|
public:
|
2014-04-02 00:20:08 +02:00
|
|
|
ThunkManager() {
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
~ThunkManager() {
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
void *ProtectFunction(void *function, int num_params);
|
2013-09-05 02:17:46 +02:00
|
|
|
private:
|
2014-04-02 00:20:08 +02:00
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
|
|
|
void Reset();
|
2013-09-05 02:17:46 +02:00
|
|
|
};
|