Fixed sequence of DLL_PROCESS_DETACH notification calls.
Moved PE_MODREF flags to WINE_MODREF level.
Better handling of LoadLibraryEx flags.
PE_InitTls() changed to work only on the current thread.

diff --git a/scheduler/thread.c b/scheduler/thread.c
index b9c6ee2..28c8a1f 100644
--- a/scheduler/thread.c
+++ b/scheduler/thread.c
@@ -261,7 +261,6 @@
     if (!THREAD_InitTHDB( thdb, stack_size, alloc_stack16, sa )) goto error;
     thdb->next = THREAD_First;
     THREAD_First = thdb;
-    PE_InitTls( thdb );
     return thdb;
 
 error:
@@ -282,6 +281,7 @@
 {
     THDB *thdb = THREAD_Current();
     LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)thdb->entry_point;
+    PE_InitTls();
     MODULE_InitializeDLLs( 0, DLL_THREAD_ATTACH, NULL );
     ExitThread( func( thdb->entry_arg ) );
 }
@@ -412,10 +412,17 @@
 
 
 /**********************************************************************
- *           THREAD_TlsAlloc
+ * TlsAlloc [KERNEL32.530]  Allocates a TLS index.
+ *
+ * Allocates a thread local storage index
+ *
+ * RETURNS
+ *    Success: TLS Index
+ *    Failure: 0xFFFFFFFF
  */
-DWORD THREAD_TlsAlloc(THDB *thread)
+DWORD WINAPI TlsAlloc( void )
 {
+    THDB *thread = THREAD_Current();
     DWORD i, mask, ret = 0;
     DWORD *bits = thread->process->tls_bits;
     EnterCriticalSection( &thread->process->crit_section );
@@ -438,21 +445,6 @@
 
 
 /**********************************************************************
- * TlsAlloc [KERNEL32.530]  Allocates a TLS index.
- *
- * Allocates a thread local storage index
- *
- * RETURNS
- *    Success: TLS Index
- *    Failure: 0xFFFFFFFF
- */
-DWORD WINAPI TlsAlloc(void)
-{
-    return THREAD_TlsAlloc(THREAD_Current());
-}
-
-
-/**********************************************************************
  * TlsFree [KERNEL32.531]  Releases a TLS index.
  *
  * Releases a thread local storage index, making it available for reuse