From 186b419e02fa0e0a1055e984317a200efa8a0749 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 16 Apr 2004 00:10:03 +0000 Subject: [PATCH] Added hack to fetch the current directory from the subsystem tid so that it is handled correctly in ntdll also for 16-bit tasks. --- dlls/kernel/kernel_private.h | 17 ----------------- dlls/kernel/task.c | 18 ++++++++++++++++++ dlls/ntdll/path.c | 35 ++++++++++++++--------------------- include/thread.h | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/dlls/kernel/kernel_private.h b/dlls/kernel/kernel_private.h index d7ca56069f1..5054cd70234 100644 --- a/dlls/kernel/kernel_private.h +++ b/dlls/kernel/kernel_private.h @@ -21,23 +21,6 @@ #ifndef __WINE_KERNEL_PRIVATE_H #define __WINE_KERNEL_PRIVATE_H -#include -#include "windef.h" -#include "winbase.h" -#include "winreg.h" -#include "winternl.h" - -/* The thread information for 16-bit threads */ -/* NtCurrentTeb()->SubSystemTib points to this */ -typedef struct -{ - void *unknown; /* 00 unknown */ - UNICODE_STRING *exe_name; /* 04 exe module name */ - - /* the following fields do not exist under Windows */ - UNICODE_STRING exe_str; /* exe name string pointed to by exe_name */ -} WIN16_SUBSYSTEM_TIB; - HANDLE WINAPI OpenConsoleW(LPCWSTR, DWORD, BOOL, DWORD); BOOL WINAPI VerifyConsoleIoHandle(HANDLE); HANDLE WINAPI DuplicateConsoleHandle(HANDLE, DWORD, BOOL, DWORD); diff --git a/dlls/kernel/task.c b/dlls/kernel/task.c index 22c3377849d..94844f67afb 100644 --- a/dlls/kernel/task.c +++ b/dlls/kernel/task.c @@ -432,6 +432,7 @@ static WIN16_SUBSYSTEM_TIB *allocate_win16_tib( TDB *pTask ) { WCHAR path[MAX_PATH]; WIN16_SUBSYSTEM_TIB *tib; + UNICODE_STRING *curdir; NE_MODULE *pModule = NE_GetPtr( pTask->hModule ); if (!(tib = HeapAlloc( GetProcessHeap(), 0, sizeof(*tib) ))) return NULL; @@ -439,6 +440,15 @@ static WIN16_SUBSYSTEM_TIB *allocate_win16_tib( TDB *pTask ) GetLongPathNameW( path, path, MAX_PATH ); if (RtlCreateUnicodeString( &tib->exe_str, path )) tib->exe_name = &tib->exe_str; else tib->exe_name = NULL; + + RtlAcquirePebLock(); + curdir = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectoryName; + tib->curdir.MaximumLength = sizeof(tib->curdir_buffer); + tib->curdir.Length = min( curdir->Length, tib->curdir.MaximumLength-sizeof(WCHAR) ); + tib->curdir.Buffer = tib->curdir_buffer; + memcpy( tib->curdir_buffer, curdir->Buffer, tib->curdir.Length ); + tib->curdir_buffer[tib->curdir.Length/sizeof(WCHAR)] = 0; + RtlReleasePebLock(); return tib; } @@ -518,6 +528,7 @@ static void TASK_CallTaskSignalProc( UINT16 uCode, HANDLE16 hTaskOrModule ) */ void TASK_ExitTask(void) { + WIN16_SUBSYSTEM_TIB *tib; TDB *pTask; DWORD lockCount; @@ -553,6 +564,13 @@ void TASK_ExitTask(void) TASK_DeleteTask( pTask->hSelf ); + if ((tib = NtCurrentTeb()->Tib.SubSystemTib)) + { + if (tib->exe_name) RtlFreeUnicodeString( tib->exe_name ); + HeapFree( GetProcessHeap(), 0, tib ); + NtCurrentTeb()->Tib.SubSystemTib = NULL; + } + /* ... and completely release the Win16Lock, just in case. */ ReleaseThunkLock( &lockCount ); } diff --git a/dlls/ntdll/path.c b/dlls/ntdll/path.c index d06b733e91a..85392842d2c 100644 --- a/dlls/ntdll/path.c +++ b/dlls/ntdll/path.c @@ -541,7 +541,10 @@ static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size) RtlAcquirePebLock(); - cd = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectoryName; + if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */ + cd = &((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir; + else + cd = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectoryName; switch (type = RtlDetermineDosPathNameType_U(name)) { @@ -851,7 +854,11 @@ NTSTATUS WINAPI RtlGetCurrentDirectory_U(ULONG buflen, LPWSTR buf) RtlAcquirePebLock(); - us = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectoryName; + if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */ + us = &((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir; + else + us = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectoryName; + len = us->Length / sizeof(WCHAR); if (us->Buffer[len - 1] == '\\' && us->Buffer[len - 2] != ':') len--; @@ -886,7 +893,11 @@ NTSTATUS WINAPI RtlSetCurrentDirectory_U(const UNICODE_STRING* dir) RtlAcquirePebLock(); - curdir = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectoryName; + if (NtCurrentTeb()->Tib.SubSystemTib) /* FIXME: hack */ + curdir = &((WIN16_SUBSYSTEM_TIB *)NtCurrentTeb()->Tib.SubSystemTib)->curdir; + else + curdir = &NtCurrentTeb()->Peb->ProcessParameters->CurrentDirectoryName; + size = curdir->MaximumLength; buf = RtlAllocateHeap(GetProcessHeap(), 0, size); @@ -929,24 +940,6 @@ NTSTATUS WINAPI RtlSetCurrentDirectory_U(const UNICODE_STRING* dir) memmove(curdir->Buffer, buf, size + sizeof(WCHAR)); curdir->Length = size; -#if 0 - if (curdir->Buffer[1] == ':') - { - UNICODE_STRING env; - WCHAR var[4]; - - var[0] = '='; - var[1] = curdir->Buffer[0]; - var[2] = ':'; - var[3] = 0; - env.Length = 3 * sizeof(WCHAR); - env.MaximumLength = 4 * sizeof(WCHAR); - env.Buffer = var; - - RtlSetEnvironmentVariable(NULL, &env, curdir); - } -#endif - out: if (buf) RtlFreeHeap(GetProcessHeap(), 0, buf); diff --git a/include/thread.h b/include/thread.h index 8a0cf48cc86..9c2ae9fa3ee 100644 --- a/include/thread.h +++ b/include/thread.h @@ -133,6 +133,20 @@ typedef struct _TEB } TEB; #endif /* WINE_TEB_DEFINED */ + +/* The thread information for 16-bit threads */ +/* NtCurrentTeb()->SubSystemTib points to this */ +typedef struct +{ + void *unknown; /* 00 unknown */ + UNICODE_STRING *exe_name; /* 04 exe module name */ + + /* the following fields do not exist under Windows */ + UNICODE_STRING exe_str; /* exe name string pointed to by exe_name */ + UNICODE_STRING curdir; /* current directory */ + WCHAR curdir_buffer[MAX_PATH]; +} WIN16_SUBSYSTEM_TIB; + /* scheduler/thread.c */ extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size );