Workaround for VS2013-update2

cl.exe of VS2013 update2 overwrites memory.
It looks tls size is less than cl.exe expected.

We need to allocate more tls when load_dll is used
as well as load_native_dll.

Change-Id: I12b4fcd2270c01eb25e5681c11dc968b6745fa4e
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 01aae4f..7ea79c1 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -674,6 +674,28 @@
     }
 
 done:
+
+    {
+      // (shinyak) We need to increase tls_total_size when loading dll?
+      // It's the same as load_native_dll.
+      // This is workaround for VS2013-update2.
+      // With current wine, cl.exe of VS2013-update2 has buffer overflow, so it's
+      // crashed on initializing phase or termination phase. (I saw the both
+      // case). Since memset overwrites memory tail somewhere, let's allocate
+      // memory more so that it doesn't overwrite.
+      // The allocated memory looks tls, so we'd like to allocate more memory.
+      IMAGE_NT_HEADERS *nt = RtlImageNtHeader(module);
+      int i;
+      IMAGE_SECTION_HEADER* sect = IMAGE_FIRST_SECTION(nt);
+      for (i = 0; i < nt->FileHeader.NumberOfSections; ++i, ++sect) {
+        if (strcasecmp(sect->Name, ".tls") == 0) {
+          TRACE("(shinyak) add .tls size 0x%x by %s\n", sect->SizeOfRawData, debugstr_w(wmImp->ldr.FullDllName.Buffer));
+          tls_total_size += TLS_ALIGN(sect->SizeOfRawData);
+          break;
+        }
+      }
+    }
+
     /* restore old protection of the import address table */
     NtProtectVirtualMemory( NtCurrentProcess(), &protect_base, &protect_size, protect_old, NULL );
     return wmImp;
@@ -926,7 +948,7 @@
     if (!tls_module_count) return STATUS_SUCCESS;
 
     size = TLS_ALIGN( tls_module_count * sizeof(*pointers) );
-    TRACE( "size %u count %u tls_total_size\n", size, tls_module_count, tls_total_size);
+    TRACE( "size %u count %u tls_total_size %u\n", size, tls_module_count, tls_total_size);
     if (!(pointers = RtlAllocateHeap( GetProcessHeap(), 0, size + tls_total_size + 0x6f0 + 0x11b08)))
         return STATUS_NO_MEMORY;
     data = (char *)pointers + size;