| 42 | } |
| 43 | |
| 44 | KMemoryData::KMemoryData(KMemory* memory) : memory(memory) { |
| 45 | ::memset(mmu, 0, sizeof(mmu)); |
| 46 | #ifdef BOXEDWINE_MEM_CACHE |
| 47 | ::memset(readCache, 0, sizeof(readCache)); |
| 48 | ::memset(writeCache, 0, sizeof(writeCache)); |
| 49 | #endif |
| 50 | if(!callbackRam.value) { |
| 51 | callbackRam = ramPageAlloc(); |
| 52 | addCallback(onExitSignal); |
| 53 | } |
| 54 | this->allocPages(nullptr, CALL_BACK_ADDRESS >> K_PAGE_SHIFT, 1, K_PROT_READ | K_PROT_EXEC, -1, 0, nullptr, &callbackRam); |
| 55 | // in case another thread is using it right when we free it |
| 56 | codeMemory.delayedFree = 1000; // 10s |
| 57 | #ifdef BOXEDWINE_HOST_EXCEPTIONS |
| 58 | codeMemory.delayedFreeCallback = [this](void* p, U32 len) { |
| 59 | auto startIt = this->jitAddressToEip.upper_bound((U8*)p); |
| 60 | auto endIt = this->jitAddressToEip.lower_bound((U8*)p + len); |
| 61 | auto it = startIt; |
| 62 | |
| 63 | while (it != endIt) { |
| 64 | it = this->jitAddressToEip.erase(it); |
| 65 | } |
| 66 | }; |
| 67 | #endif |
| 68 | codeMemory.isCodeMemory = true; |
| 69 | } |
| 70 | |
| 71 | KMemoryData::~KMemoryData() { |
| 72 | codeMemory.freeAll(); |
nothing calls this directly
no test coverage detected