forked from KindDragon/vld
-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
#include <windows.h>
#include <thread>
#include <chrono>
#include <memory>
int main(int argc, wchar_t *argv[]) {
for (int i = 0; i < 0x40; ++i)
TlsAlloc();
HMODULE h_vld = LoadLibraryA("vld.dll");
typedef void(*vld_enable_t)(void);
auto vld_enable = (vld_enable_t)::GetProcAddress(h_vld, "VLDGlobalEnable");
vld_enable();
std::thread([]() {std::make_shared<int>(); }).join();
return 0;
}
When a memory allocation happens, VLD will store the information in its TLS slot to avoid contention and reduce performance impact. When VLD is assigned with a TLS slot >= 0x40 and a memory allocation happens in a thread that hasn't expand TLS, the access to TLS slot from VLD will trigger another TLS expansion.
However, the expansion will call RtlAllocateHeap to allocate memory and the record of this memory allocation will be saved into TLS slot by VLD, which will again trigger another TLS expansion… In this way, The program will enter infinite recursion.
Due to some restrictions, I can only use vld in dll in my program, which prevents me from initializing vld at the entry point at the beginning of the program. What should I do?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels