| 75 | |
| 76 | #ifndef __linux |
| 77 | int ExtendMemory() |
| 78 | { |
| 79 | // External stack cannot be extended, end execution with error |
| 80 | if(!stackManaged) |
| 81 | { |
| 82 | expAllocCode = 5; |
| 83 | return EXCEPTION_EXECUTE_HANDLER; |
| 84 | } |
| 85 | if(stackEndAddress && (char*)stackBaseAddress + commitedStack + stackGrowSize > (char*)stackEndAddress) |
| 86 | { |
| 87 | expAllocCode = 2; |
| 88 | return EXCEPTION_EXECUTE_HANDLER; |
| 89 | } |
| 90 | // Check that we haven't exceeded available memory |
| 91 | if(reservedStack > 512*1024*1024) |
| 92 | { |
| 93 | expAllocCode = 4; |
| 94 | return EXCEPTION_EXECUTE_HANDLER; |
| 95 | } |
| 96 | // Allow the use of last reserved memory page |
| 97 | if(!VirtualAlloc(reinterpret_cast<void*>(long long(paramDataBase+commitedStack)), stackGrowSize-stackGrowCommit, MEM_COMMIT, PAGE_READWRITE)) |
| 98 | { |
| 99 | expAllocCode = 1; // failed to commit all old memory |
| 100 | return EXCEPTION_EXECUTE_HANDLER; |
| 101 | } |
| 102 | // Reserve new memory right after the block |
| 103 | if(!VirtualAlloc(reinterpret_cast<void*>(long long(paramDataBase+reservedStack)), stackGrowSize, MEM_RESERVE, PAGE_NOACCESS)) |
| 104 | { |
| 105 | expAllocCode = 2; // failed to reserve new memory |
| 106 | return EXCEPTION_EXECUTE_HANDLER; |
| 107 | } |
| 108 | // Allow access to all new reserved memory, except for the last memory page |
| 109 | if(!VirtualAlloc(reinterpret_cast<void*>(long long(paramDataBase+reservedStack)), stackGrowCommit, MEM_COMMIT, PAGE_READWRITE)) |
| 110 | { |
| 111 | expAllocCode = 3; // failed to commit new memory |
| 112 | return EXCEPTION_EXECUTE_HANDLER; |
| 113 | } |
| 114 | // Update variables |
| 115 | commitedStack = reservedStack; |
| 116 | reservedStack += stackGrowSize; |
| 117 | commitedStack += stackGrowCommit; |
| 118 | stackReallocs++; |
| 119 | |
| 120 | SetUnmanagableRange(parameterHead, reservedStack); |
| 121 | |
| 122 | return (DWORD)EXCEPTION_CONTINUE_EXECUTION; |
| 123 | } |
| 124 | |
| 125 | DWORD CanWeHandleSEH(unsigned int expCode, _EXCEPTION_POINTERS* expInfo) |
| 126 | { |
no test coverage detected