Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working around fls limitations with too many statically linked CRTs?

When loading external DLLs (not under our control) via LoadLibrary, we're hitting a problem where the statically linked CRT in those DLLs are failing to allocate fiber-local storage. This is similar to mskb 193462, except that this is FLS and there's only 128 of them.

Are there any useful ways to work around the problem? The CRT is using GetProcAddress to find FlsAlloc anyway (since that apparently never existed in XP), so does it even really need it?

(This is on Vista, where FlsAlloc actually exists; the DLLs appear to be using MSVC8)

like image 223
Mook Avatar asked Sep 17 '09 08:09

Mook


1 Answers

There is frankly no solution here, short of loading less dlls.

You could hook the dll's import address table - but that will happen too late as you can only install an IAT hook when LoadLibrary returns, and the CRT initialization code probably executes in response to DllProcessAttach which will already have been processed.

You could I guess find the kernel32.dll module in memory, and patch the export address for GetProcAddress or perhaps FlsAlloc to point to your implementation. But that approach is getting seriously hackish.

like image 106
Chris Becke Avatar answered Dec 18 '22 12:12

Chris Becke