diff options
Diffstat (limited to 'win/tclWin32Dll.c')
-rw-r--r-- | win/tclWin32Dll.c | 835 |
1 files changed, 387 insertions, 448 deletions
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 59746d2..8303af5 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWin32Dll.c,v 1.40 2004/11/01 16:58:37 kennykb Exp $ + * RCS: @(#) $Id: tclWin32Dll.c,v 1.41 2005/05/10 18:35:37 kennykb Exp $ */ #include "tclWinInt.h" @@ -57,26 +57,7 @@ _except_dllmain_detach_handler( struct _CONTEXT *ContextRecord, void *DispatcherContext); -static -__attribute__ ((cdecl)) -EXCEPTION_DISPOSITION -_except_checkstackspace_handler( - struct _EXCEPTION_RECORD *ExceptionRecord, - void *EstablisherFrame, - struct _CONTEXT *ContextRecord, - void *DispatcherContext); - -static -__attribute__((cdecl)) -EXCEPTION_DISPOSITION -_except_TclWinCPUID_detach_handler( - struct _EXCEPTION_RECORD *ExceptionRecord, - void *EstablisherFrame, - struct _CONTEXT *ContextRecord, - void *DispatcherContext); - -#endif /* HAVE_NO_SEH */ - +#endif /* * VC++ 5.x has no 'cpuid' assembler instruction, so we @@ -327,7 +308,7 @@ DllMain(hInst, reason, reserved) "pushl %%ebp" "\n\t" "pushl %0" "\n\t" "pushl %%fs:0" "\n\t" - "movl %%esp, %%fs:0" + "movl %%esp, %%fs:0" "\n\t" : : "r" (_except_dllmain_detach_handler) ); #else @@ -549,6 +530,7 @@ TclWinNoBackslash( int TclpCheckStackSpace() { + int retval = 0; /* @@ -559,123 +541,103 @@ TclpCheckStackSpace() */ #ifdef HAVE_NO_SEH -# ifdef TCL_MEM_DEBUG __asm__ __volatile__ ( - "movl %%esp, %0" "\n\t" - "movl %%ebp, %1" "\n\t" - "movl %%fs:0, %2" "\n\t" - : "=m"(INITIAL_ESP), - "=m"(INITIAL_EBP), - "=r"(INITIAL_HANDLER) ); -# endif /* TCL_MEM_DEBUG */ - __asm__ __volatile__ ( - "pushl %%ebp" "\n\t" - "pushl %0" "\n\t" - "pushl %%fs:0" "\n\t" - "movl %%esp, %%fs:0" - : - : "r" (_except_checkstackspace_handler) ); -#else + /* + * Build an EXCEPTION_REGISTRATION structure on the stack, and + * stack it on the list of EXCEPTION_REGISTRATIONs + * anchored at the thread information block. + * Put the saved EBP at 0x8 and the address of the status + * return at 0xc. + */ + + "leal %[stat], %%edx" "\n\t" + "pushl %%edx" "\n\t" + "pushl %%ebp" "\n\t" + "leal 1f, %%edx" "\n\t" + "pushl %%edx" "\n\t" + "pushl %%fs:0" "\n\t" + "movl %%esp, %%fs:0" "\n\t" + + /* + * Attempt a call to _alloca, to determine whether there's + * sufficient memory to be had. + */ + + "movl %[size], %%eax" "\n\t" + "pushl %%eax" "\n\t" + "call __alloca" "\n\t" + + /* + * If 'alloca' succeeds, pull back the address of the + * EXCEPTION_REGISTRATION and put a 1 in EAX for status. + */ + + "movl $1, %%eax" "\n\t" + "movl %%fs:0, %%esp" "\n\t" + "jmp 2f" "\n" + + /* + * Come here on an exception. Retrieve the EXCEPTION_REGISTRATION + * from the link in the runtime library's EXCEPTION_REGISTRATION, + * and put a 0 in EAX to indicate failure. + */ + + "1:" "\t" + "movl %%fs:0, %%edx" "\n\t" + "movl $0, %%eax" "\n\t" + "movl 0x8(%%edx), %%esp" "\n" + + /* + * Come here whether or not an exception occurred. The stack + * pointer points to the EXCEPTION_REGISTRATION, and EAX contains + * status. Unstack the EXCEPTION_REGISTRATION and clean up + * the stack. + */ + + "2:" "\t" + "pop %%fs:0" "\n\t" + "addl $4, %%esp" "\n\t" + "pop %%ebp" "\n\t" + "pop %%edx" "\n\t" + "movl %%eax, 0x0(%%edx)" "\n\t" + + : [stat]"=m"(retval) + : [size]"i"(TCL_WIN_STACK_THRESHOLD) + : "%eax","%ebx", "%ecx", "%edx", "%esi", "%edi", "memory" ); + +#else /* !HAVE_NO_SEH */ __try { -#endif /* HAVE_NO_SEH */ #ifdef HAVE_ALLOCA_GCC_INLINE - __asm__ __volatile__ ( + __asm__ __volatile__ ( "movl %0, %%eax" "\n\t" "call __alloca" "\n\t" : : "i"(TCL_WIN_STACK_THRESHOLD) : "%eax"); #else - alloca(TCL_WIN_STACK_THRESHOLD); + alloca(TCL_WIN_STACK_THRESHOLD); #endif /* HAVE_ALLOCA_GCC_INLINE */ - retval = 1; -#ifdef HAVE_NO_SEH - __asm__ __volatile__ ( - "movl %%fs:0, %%esp" "\n\t" - "jmp checkstackspace_pop" "\n" - "checkstackspace_reentry:" "\n\t" - "movl %%fs:0, %%eax" "\n\t" - "movl 0x8(%%eax), %%esp" "\n\t" - "movl 0x8(%%esp), %%ebp" "\n" - "checkstackspace_pop:" "\n\t" - "movl (%%esp), %%eax" "\n\t" - "movl %%eax, %%fs:0" "\n\t" - "add $12, %%esp" "\n\t" - : - : - : "%eax"); - -# ifdef TCL_MEM_DEBUG - __asm__ __volatile__ ( - "movl %%esp, %0" "\n\t" - "movl %%ebp, %1" "\n\t" - "movl %%fs:0, %2" "\n\t" - : "=m"(RESTORED_ESP), - "=m"(RESTORED_EBP), - "=r"(RESTORED_HANDLER) ); - - if (INITIAL_ESP != RESTORED_ESP) - Tcl_Panic("ESP restored incorrectly"); - if (INITIAL_EBP != RESTORED_EBP) - Tcl_Panic("EBP restored incorrectly"); - if (INITIAL_HANDLER != RESTORED_HANDLER) - Tcl_Panic("HANDLER restored incorrectly"); -# endif /* TCL_MEM_DEBUG */ -#else + retval = 1; } __except (EXCEPTION_EXECUTE_HANDLER) {} #endif /* HAVE_NO_SEH */ - - /* - * Avoid using control flow statements in the SEH guarded block! - */ + return retval; } /* *---------------------------------------------------------------------- * - * _except_checkstackspace_handler -- - * - * SEH exception handler for TclpCheckStackSpace. - * - * Results: - * See TclpCheckStackSpace. - * - * Side effects: - * See TclpCheckStackSpace. - * - *---------------------------------------------------------------------- - */ -#ifdef HAVE_NO_SEH -static -__attribute__ ((cdecl)) -EXCEPTION_DISPOSITION -_except_checkstackspace_handler( - struct _EXCEPTION_RECORD *ExceptionRecord, - void *EstablisherFrame, - struct _CONTEXT *ContextRecord, - void *DispatcherContext) -{ - __asm__ __volatile__ ( - "jmp checkstackspace_reentry"); - return 0; /* Function does not return */ -} -#endif /* HAVE_NO_SEH */ - -/* - *---------------------------------------------------------------------- - * * TclWinGetPlatform -- * - * This is a kludge that allows the test library to get access - * the internal tclPlatform variable. + * This is a kludge that allows the test library to get access + * the internal tclPlatform variable. * * Results: - * Returns a pointer to the tclPlatform variable. + * Returns a pointer to the tclPlatform variable. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ @@ -691,123 +653,123 @@ TclWinGetPlatform() * * TclWinSetInterfaces -- * - * A helper proc that allows the test library to change the - * tclWinProcs structure to dispatch to either the wide-character - * or multi-byte versions of the operating system calls, depending - * on whether Unicode is the system encoding. - * - * As well as this, we can also try to load in some additional - * procs which may/may not be present depending on the current - * Windows version (e.g. Win95 will not have the procs below). + * A helper proc that allows the test library to change the + * tclWinProcs structure to dispatch to either the wide-character + * or multi-byte versions of the operating system calls, depending + * on whether Unicode is the system encoding. + * + * As well as this, we can also try to load in some additional + * procs which may/may not be present depending on the current + * Windows version (e.g. Win95 will not have the procs below). * * Results: - * None. + * None. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ void TclWinSetInterfaces( - int wide) /* Non-zero to use wide interfaces, 0 - * otherwise. */ + int wide) /* Non-zero to use wide interfaces, 0 + * otherwise. */ { Tcl_FreeEncoding(tclWinTCharEncoding); if (wide) { - tclWinProcs = &unicodeProcs; - tclWinTCharEncoding = Tcl_GetEncoding(NULL, "unicode"); - if (tclWinProcs->getFileAttributesExProc == NULL) { - HINSTANCE hInstance = LoadLibraryA("kernel32"); - if (hInstance != NULL) { - tclWinProcs->getFileAttributesExProc = - (BOOL (WINAPI *)(CONST TCHAR *, GET_FILEEX_INFO_LEVELS, - LPVOID)) GetProcAddress(hInstance, "GetFileAttributesExW"); - tclWinProcs->createHardLinkProc = - (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR*, - LPSECURITY_ATTRIBUTES)) GetProcAddress(hInstance, - "CreateHardLinkW"); - tclWinProcs->findFirstFileExProc = - (HANDLE (WINAPI *)(CONST TCHAR*, UINT, - LPVOID, UINT, LPVOID, DWORD)) GetProcAddress(hInstance, - "FindFirstFileExW"); - tclWinProcs->getVolumeNameForVMPProc = - (BOOL (WINAPI *)(CONST TCHAR*, TCHAR*, - DWORD)) GetProcAddress(hInstance, - "GetVolumeNameForVolumeMountPointW"); - tclWinProcs->getLongPathNameProc = - (DWORD (WINAPI *)(CONST TCHAR*, TCHAR*, - DWORD)) GetProcAddress(hInstance, - "GetLongPathNameW"); - FreeLibrary(hInstance); - } - hInstance = LoadLibraryA("advapi32"); - if (hInstance != NULL) { - tclWinProcs->getFileSecurityProc = (BOOL (WINAPI *)( - LPCTSTR lpFileName, - SECURITY_INFORMATION RequestedInformation, - PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, - LPDWORD lpnLengthNeeded)) GetProcAddress(hInstance, - "GetFileSecurityW"); - tclWinProcs->impersonateSelfProc = (BOOL (WINAPI *) ( - SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)) - GetProcAddress(hInstance, "ImpersonateSelf"); - tclWinProcs->openThreadTokenProc = (BOOL (WINAPI *) ( - HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf, - PHANDLE TokenHandle)) GetProcAddress(hInstance, - "OpenThreadToken"); - tclWinProcs->revertToSelfProc = (BOOL (WINAPI *) (void)) - GetProcAddress(hInstance, "RevertToSelf"); - tclWinProcs->mapGenericMaskProc = (VOID (WINAPI *) ( - PDWORD AccessMask, PGENERIC_MAPPING GenericMapping)) - GetProcAddress(hInstance, "MapGenericMask"); - tclWinProcs->accessCheckProc = (BOOL (WINAPI *)( - PSECURITY_DESCRIPTOR pSecurityDescriptor, - HANDLE ClientToken, DWORD DesiredAccess, - PGENERIC_MAPPING GenericMapping, - PPRIVILEGE_SET PrivilegeSet, - LPDWORD PrivilegeSetLength, - LPDWORD GrantedAccess, - LPBOOL AccessStatus)) GetProcAddress(hInstance, - "AccessCheck"); - FreeLibrary(hInstance); - } - } + tclWinProcs = &unicodeProcs; + tclWinTCharEncoding = Tcl_GetEncoding(NULL, "unicode"); + if (tclWinProcs->getFileAttributesExProc == NULL) { + HINSTANCE hInstance = LoadLibraryA("kernel32"); + if (hInstance != NULL) { + tclWinProcs->getFileAttributesExProc = + (BOOL (WINAPI *)(CONST TCHAR *, GET_FILEEX_INFO_LEVELS, + LPVOID)) GetProcAddress(hInstance, "GetFileAttributesExW"); + tclWinProcs->createHardLinkProc = + (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR*, + LPSECURITY_ATTRIBUTES)) GetProcAddress(hInstance, + "CreateHardLinkW"); + tclWinProcs->findFirstFileExProc = + (HANDLE (WINAPI *)(CONST TCHAR*, UINT, + LPVOID, UINT, LPVOID, DWORD)) GetProcAddress(hInstance, + "FindFirstFileExW"); + tclWinProcs->getVolumeNameForVMPProc = + (BOOL (WINAPI *)(CONST TCHAR*, TCHAR*, + DWORD)) GetProcAddress(hInstance, + "GetVolumeNameForVolumeMountPointW"); + tclWinProcs->getLongPathNameProc = + (DWORD (WINAPI *)(CONST TCHAR*, TCHAR*, + DWORD)) GetProcAddress(hInstance, + "GetLongPathNameW"); + FreeLibrary(hInstance); + } + hInstance = LoadLibraryA("advapi32"); + if (hInstance != NULL) { + tclWinProcs->getFileSecurityProc = (BOOL (WINAPI *)( + LPCTSTR lpFileName, + SECURITY_INFORMATION RequestedInformation, + PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, + LPDWORD lpnLengthNeeded)) GetProcAddress(hInstance, + "GetFileSecurityW"); + tclWinProcs->impersonateSelfProc = (BOOL (WINAPI *) ( + SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)) + GetProcAddress(hInstance, "ImpersonateSelf"); + tclWinProcs->openThreadTokenProc = (BOOL (WINAPI *) ( + HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf, + PHANDLE TokenHandle)) GetProcAddress(hInstance, + "OpenThreadToken"); + tclWinProcs->revertToSelfProc = (BOOL (WINAPI *) (void)) + GetProcAddress(hInstance, "RevertToSelf"); + tclWinProcs->mapGenericMaskProc = (VOID (WINAPI *) ( + PDWORD AccessMask, PGENERIC_MAPPING GenericMapping)) + GetProcAddress(hInstance, "MapGenericMask"); + tclWinProcs->accessCheckProc = (BOOL (WINAPI *)( + PSECURITY_DESCRIPTOR pSecurityDescriptor, + HANDLE ClientToken, DWORD DesiredAccess, + PGENERIC_MAPPING GenericMapping, + PPRIVILEGE_SET PrivilegeSet, + LPDWORD PrivilegeSetLength, + LPDWORD GrantedAccess, + LPBOOL AccessStatus)) GetProcAddress(hInstance, + "AccessCheck"); + FreeLibrary(hInstance); + } + } } else { - tclWinProcs = &asciiProcs; - tclWinTCharEncoding = NULL; - if (tclWinProcs->getFileAttributesExProc == NULL) { - HINSTANCE hInstance = LoadLibraryA("kernel32"); - if (hInstance != NULL) { - tclWinProcs->getFileAttributesExProc = - (BOOL (WINAPI *)(CONST TCHAR *, GET_FILEEX_INFO_LEVELS, - LPVOID)) GetProcAddress(hInstance, "GetFileAttributesExA"); - tclWinProcs->createHardLinkProc = - (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR*, - LPSECURITY_ATTRIBUTES)) GetProcAddress(hInstance, - "CreateHardLinkA"); - tclWinProcs->findFirstFileExProc = NULL; - tclWinProcs->getLongPathNameProc = NULL; - /* - * The 'findFirstFileExProc' function exists on some - * of 95/98/ME, but it seems not to work as anticipated. - * Therefore we don't set this function pointer. The - * relevant code will fall back on a slower approach - * using the normal findFirstFileProc. - * - * (HANDLE (WINAPI *)(CONST TCHAR*, UINT, - * LPVOID, UINT, LPVOID, DWORD)) GetProcAddress(hInstance, - * "FindFirstFileExA"); - */ - tclWinProcs->getVolumeNameForVMPProc = - (BOOL (WINAPI *)(CONST TCHAR*, TCHAR*, - DWORD)) GetProcAddress(hInstance, - "GetVolumeNameForVolumeMountPointA"); - FreeLibrary(hInstance); - } - } + tclWinProcs = &asciiProcs; + tclWinTCharEncoding = NULL; + if (tclWinProcs->getFileAttributesExProc == NULL) { + HINSTANCE hInstance = LoadLibraryA("kernel32"); + if (hInstance != NULL) { + tclWinProcs->getFileAttributesExProc = + (BOOL (WINAPI *)(CONST TCHAR *, GET_FILEEX_INFO_LEVELS, + LPVOID)) GetProcAddress(hInstance, "GetFileAttributesExA"); + tclWinProcs->createHardLinkProc = + (BOOL (WINAPI *)(CONST TCHAR *, CONST TCHAR*, + LPSECURITY_ATTRIBUTES)) GetProcAddress(hInstance, + "CreateHardLinkA"); + tclWinProcs->findFirstFileExProc = NULL; + tclWinProcs->getLongPathNameProc = NULL; + /* + * The 'findFirstFileExProc' function exists on some + * of 95/98/ME, but it seems not to work as anticipated. + * Therefore we don't set this function pointer. The + * relevant code will fall back on a slower approach + * using the normal findFirstFileProc. + * + * (HANDLE (WINAPI *)(CONST TCHAR*, UINT, + * LPVOID, UINT, LPVOID, DWORD)) GetProcAddress(hInstance, + * "FindFirstFileExA"); + */ + tclWinProcs->getVolumeNameForVMPProc = + (BOOL (WINAPI *)(CONST TCHAR*, TCHAR*, + DWORD)) GetProcAddress(hInstance, + "GetVolumeNameForVolumeMountPointA"); + FreeLibrary(hInstance); + } + } } } @@ -816,9 +778,9 @@ TclWinSetInterfaces( * * TclWinResetInterfaceEncodings -- * - * Called during finalization to free up any encodings we use. - * The tclWinProcs-> look up table is still ok to use after - * this call, provided no encoding conversion is required. + * Called during finalization to free up any encodings we use. + * The tclWinProcs-> look up table is still ok to use after + * this call, provided no encoding conversion is required. * * We also clean up any memory allocated in our mount point * map which is used to follow certain kinds of symlinks. @@ -826,10 +788,10 @@ TclWinSetInterfaces( * down. * * Results: - * None. + * None. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ @@ -838,17 +800,17 @@ TclWinResetInterfaceEncodings() { MountPointMap *dlIter, *dlIter2; if (tclWinTCharEncoding != NULL) { - Tcl_FreeEncoding(tclWinTCharEncoding); - tclWinTCharEncoding = NULL; + Tcl_FreeEncoding(tclWinTCharEncoding); + tclWinTCharEncoding = NULL; } /* Clean up the mount point map */ Tcl_MutexLock(&mountPointMap); dlIter = driveLetterLookup; while (dlIter != NULL) { - dlIter2 = dlIter->nextPtr; - ckfree((char*)dlIter->volumeName); - ckfree((char*)dlIter); - dlIter = dlIter2; + dlIter2 = dlIter->nextPtr; + ckfree((char*)dlIter->volumeName); + ckfree((char*)dlIter); + dlIter = dlIter2; } Tcl_MutexUnlock(&mountPointMap); } @@ -858,15 +820,15 @@ TclWinResetInterfaceEncodings() * * TclWinResetInterfaces -- * - * Called during finalization to reset us to a safe state for reuse. - * After this call, it is best not to use the tclWinProcs-> look - * up table since it is likely to be different to what is expected. + * Called during finalization to reset us to a safe state for reuse. + * After this call, it is best not to use the tclWinProcs-> look + * up table since it is likely to be different to what is expected. * * Results: - * None. + * None. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ @@ -912,84 +874,84 @@ TclWinDriveLetterForVolMountPoint(CONST WCHAR *mountPoint) Tcl_MutexLock(&mountPointMap); dlIter = driveLetterLookup; while (dlIter != NULL) { - if (wcscmp(dlIter->volumeName, mountPoint) == 0) { - /* - * We need to check whether this information is - * still valid, since either the user or various - * programs could have adjusted the mount points on - * the fly. - */ - drive[0] = L'A' + (dlIter->driveLetter - 'A'); - /* Try to read the volume mount point and see where it points */ - if ((*tclWinProcs->getVolumeNameForVMPProc)((TCHAR*)drive, - (TCHAR*)Target, 55) != 0) { - if (wcscmp((WCHAR*)dlIter->volumeName, Target) == 0) { - /* Nothing has changed */ - Tcl_MutexUnlock(&mountPointMap); - return dlIter->driveLetter; - } - } - /* - * If we reach here, unfortunately, this mount point is - * no longer valid at all - */ - if (driveLetterLookup == dlIter) { - dlPtr2 = dlIter; - driveLetterLookup = dlIter->nextPtr; - } else { - for (dlPtr2 = driveLetterLookup; - dlPtr2 != NULL; dlPtr2 = dlPtr2->nextPtr) { - if (dlPtr2->nextPtr == dlIter) { - dlPtr2->nextPtr = dlIter->nextPtr; - dlPtr2 = dlIter; - break; - } - } - } - /* Now dlPtr2 points to the structure to free */ - ckfree((char*)dlPtr2->volumeName); - ckfree((char*)dlPtr2); - /* - * Restart the loop --- we could try to be clever - * and continue half way through, but the logic is a - * bit messy, so it's cleanest just to restart - */ - dlIter = driveLetterLookup; - continue; - } - dlIter = dlIter->nextPtr; + if (wcscmp(dlIter->volumeName, mountPoint) == 0) { + /* + * We need to check whether this information is + * still valid, since either the user or various + * programs could have adjusted the mount points on + * the fly. + */ + drive[0] = L'A' + (dlIter->driveLetter - 'A'); + /* Try to read the volume mount point and see where it points */ + if ((*tclWinProcs->getVolumeNameForVMPProc)((TCHAR*)drive, + (TCHAR*)Target, 55) != 0) { + if (wcscmp((WCHAR*)dlIter->volumeName, Target) == 0) { + /* Nothing has changed */ + Tcl_MutexUnlock(&mountPointMap); + return dlIter->driveLetter; + } + } + /* + * If we reach here, unfortunately, this mount point is + * no longer valid at all + */ + if (driveLetterLookup == dlIter) { + dlPtr2 = dlIter; + driveLetterLookup = dlIter->nextPtr; + } else { + for (dlPtr2 = driveLetterLookup; + dlPtr2 != NULL; dlPtr2 = dlPtr2->nextPtr) { + if (dlPtr2->nextPtr == dlIter) { + dlPtr2->nextPtr = dlIter->nextPtr; + dlPtr2 = dlIter; + break; + } + } + } + /* Now dlPtr2 points to the structure to free */ + ckfree((char*)dlPtr2->volumeName); + ckfree((char*)dlPtr2); + /* + * Restart the loop --- we could try to be clever + * and continue half way through, but the logic is a + * bit messy, so it's cleanest just to restart + */ + dlIter = driveLetterLookup; + continue; + } + dlIter = dlIter->nextPtr; } /* We couldn't find it, so we must iterate over the letters */ for (drive[0] = L'A'; drive[0] <= L'Z'; drive[0]++) { - /* Try to read the volume mount point and see where it points */ - if ((*tclWinProcs->getVolumeNameForVMPProc)((TCHAR*)drive, - (TCHAR*)Target, 55) != 0) { - int alreadyStored = 0; - for (dlIter = driveLetterLookup; dlIter != NULL; - dlIter = dlIter->nextPtr) { - if (wcscmp((WCHAR*)dlIter->volumeName, Target) == 0) { - alreadyStored = 1; - break; - } - } - if (!alreadyStored) { - dlPtr2 = (MountPointMap*) ckalloc(sizeof(MountPointMap)); - dlPtr2->volumeName = TclNativeDupInternalRep(Target); - dlPtr2->driveLetter = 'A' + (drive[0] - L'A'); - dlPtr2->nextPtr = driveLetterLookup; - driveLetterLookup = dlPtr2; - } - } + /* Try to read the volume mount point and see where it points */ + if ((*tclWinProcs->getVolumeNameForVMPProc)((TCHAR*)drive, + (TCHAR*)Target, 55) != 0) { + int alreadyStored = 0; + for (dlIter = driveLetterLookup; dlIter != NULL; + dlIter = dlIter->nextPtr) { + if (wcscmp((WCHAR*)dlIter->volumeName, Target) == 0) { + alreadyStored = 1; + break; + } + } + if (!alreadyStored) { + dlPtr2 = (MountPointMap*) ckalloc(sizeof(MountPointMap)); + dlPtr2->volumeName = TclNativeDupInternalRep(Target); + dlPtr2->driveLetter = 'A' + (drive[0] - L'A'); + dlPtr2->nextPtr = driveLetterLookup; + driveLetterLookup = dlPtr2; + } + } } /* Try again */ for (dlIter = driveLetterLookup; dlIter != NULL; - dlIter = dlIter->nextPtr) { - if (wcscmp(dlIter->volumeName, mountPoint) == 0) { - Tcl_MutexUnlock(&mountPointMap); - return dlIter->driveLetter; - } + dlIter = dlIter->nextPtr) { + if (wcscmp(dlIter->volumeName, mountPoint) == 0) { + Tcl_MutexUnlock(&mountPointMap); + return dlIter->driveLetter; + } } /* * The volume doesn't appear to correspond to a drive letter -- we @@ -1010,78 +972,78 @@ TclWinDriveLetterForVolMountPoint(CONST WCHAR *mountPoint) * * Tcl_WinUtfToTChar, Tcl_WinTCharToUtf -- * - * Convert between UTF-8 and Unicode when running Windows NT or - * the current ANSI code page when running Windows 95. - * - * On Mac, Unix, and Windows 95, all strings exchanged between Tcl - * and the OS are "char" oriented. We need only one Tcl_Encoding to - * convert between UTF-8 and the system's native encoding. We use - * NULL to represent that encoding. - * - * On NT, some strings exchanged between Tcl and the OS are "char" - * oriented, while others are in Unicode. We need two Tcl_Encoding - * APIs depending on whether we are targeting a "char" or Unicode - * interface. - * - * Calling Tcl_UtfToExternal() or Tcl_ExternalToUtf() with an - * encoding of NULL should always used to convert between UTF-8 - * and the system's "char" oriented encoding. The following two - * functions are used in Windows-specific code to convert between - * UTF-8 and Unicode strings (NT) or "char" strings(95). This saves - * you the trouble of writing the following type of fragment over and - * over: - * - * if (running NT) { - * encoding <- Tcl_GetEncoding("unicode"); - * nativeBuffer <- UtfToExternal(encoding, utfBuffer); - * Tcl_FreeEncoding(encoding); - * } else { - * nativeBuffer <- UtfToExternal(NULL, utfBuffer); - * } - * - * By convention, in Windows a TCHAR is a character in the ANSI code - * page on Windows 95, a Unicode character on Windows NT. If you - * plan on targeting a Unicode interfaces when running on NT and a - * "char" oriented interface while running on 95, these functions - * should be used. If you plan on targetting the same "char" - * oriented function on both 95 and NT, use Tcl_UtfToExternal() - * with an encoding of NULL. + * Convert between UTF-8 and Unicode when running Windows NT or + * the current ANSI code page when running Windows 95. + * + * On Mac, Unix, and Windows 95, all strings exchanged between Tcl + * and the OS are "char" oriented. We need only one Tcl_Encoding to + * convert between UTF-8 and the system's native encoding. We use + * NULL to represent that encoding. + * + * On NT, some strings exchanged between Tcl and the OS are "char" + * oriented, while others are in Unicode. We need two Tcl_Encoding + * APIs depending on whether we are targeting a "char" or Unicode + * interface. + * + * Calling Tcl_UtfToExternal() or Tcl_ExternalToUtf() with an + * encoding of NULL should always used to convert between UTF-8 + * and the system's "char" oriented encoding. The following two + * functions are used in Windows-specific code to convert between + * UTF-8 and Unicode strings (NT) or "char" strings(95). This saves + * you the trouble of writing the following type of fragment over and + * over: + * + * if (running NT) { + * encoding <- Tcl_GetEncoding("unicode"); + * nativeBuffer <- UtfToExternal(encoding, utfBuffer); + * Tcl_FreeEncoding(encoding); + * } else { + * nativeBuffer <- UtfToExternal(NULL, utfBuffer); + * } + * + * By convention, in Windows a TCHAR is a character in the ANSI code + * page on Windows 95, a Unicode character on Windows NT. If you + * plan on targeting a Unicode interfaces when running on NT and a + * "char" oriented interface while running on 95, these functions + * should be used. If you plan on targetting the same "char" + * oriented function on both 95 and NT, use Tcl_UtfToExternal() + * with an encoding of NULL. * * Results: - * The result is a pointer to the string in the desired target - * encoding. Storage for the result string is allocated in - * dsPtr; the caller must call Tcl_DStringFree() when the result - * is no longer needed. + * The result is a pointer to the string in the desired target + * encoding. Storage for the result string is allocated in + * dsPtr; the caller must call Tcl_DStringFree() when the result + * is no longer needed. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ TCHAR * Tcl_WinUtfToTChar(string, len, dsPtr) - CONST char *string; /* Source string in UTF-8. */ - int len; /* Source string length in bytes, or < 0 for - * strlen(). */ - Tcl_DString *dsPtr; /* Uninitialized or free DString in which - * the converted string is stored. */ + CONST char *string; /* Source string in UTF-8. */ + int len; /* Source string length in bytes, or < 0 for + * strlen(). */ + Tcl_DString *dsPtr; /* Uninitialized or free DString in which + * the converted string is stored. */ { return (TCHAR *) Tcl_UtfToExternalDString(tclWinTCharEncoding, - string, len, dsPtr); + string, len, dsPtr); } char * Tcl_WinTCharToUtf(string, len, dsPtr) - CONST TCHAR *string; /* Source string in Unicode when running - * NT, ANSI when running 95. */ - int len; /* Source string length in bytes, or < 0 for - * platform-specific string length. */ - Tcl_DString *dsPtr; /* Uninitialized or free DString in which - * the converted string is stored. */ + CONST TCHAR *string; /* Source string in Unicode when running + * NT, ANSI when running 95. */ + int len; /* Source string length in bytes, or < 0 for + * platform-specific string length. */ + Tcl_DString *dsPtr; /* Uninitialized or free DString in which + * the converted string is stored. */ { return Tcl_ExternalToUtfDString(tclWinTCharEncoding, - (CONST char *) string, len, dsPtr); + (CONST char *) string, len, dsPtr); } /* @@ -1089,14 +1051,14 @@ Tcl_WinTCharToUtf(string, len, dsPtr) * * TclWinCPUID -- * - * Get CPU ID information on an Intel box under Windows + * Get CPU ID information on an Intel box under Windows * * Results: - * Returns TCL_OK if successful, TCL_ERROR if CPUID is not - * supported or fails. + * Returns TCL_OK if successful, TCL_ERROR if CPUID is not + * supported or fails. * * Side effects: - * If successful, stores EAX, EBX, ECX and EDX registers after + * If successful, stores EAX, EBX, ECX and EDX registers after * the CPUID instruction in the four integers designated by 'regsPtr' * *---------------------------------------------------------------------- @@ -1104,70 +1066,79 @@ Tcl_WinTCharToUtf(string, len, dsPtr) int TclWinCPUID( unsigned int index, /* Which CPUID value to retrieve */ - register unsigned int * regsPtr ) /* Registers after the CPUID */ + unsigned int * regsPtr ) /* Registers after the CPUID */ { int status = TCL_ERROR; -#if defined(__GNUC__) - - /* Establish structured exception handling */ +#if defined(__GNUC__) && !defined(_WIN64) -# ifdef HAVE_NO_SEH + /* + * Execute the CPUID instruction with the given index, and + * store results off 'regPtr'. + */ + __asm__ __volatile__ ( - "pushl %%ebp" "\n\t" - "pushl %0" "\n\t" - "pushl %%fs:0" "\n\t" - "movl %%esp, %%fs:0" - : - : "r" (_except_TclWinCPUID_detach_handler) ); -# else - __try { -# endif - - /* - * Execute the CPUID instruction with the given index, and - * store results off 'regPtr'. - */ - - __asm__ __volatile__ ( - "movl %4, %%eax" "\n\t" - "cpuid" "\n\t" - "movl %%eax, %0" "\n\t" - "movl %%ebx, %1" "\n\t" - "movl %%ecx, %2" "\n\t" - "movl %%edx, %3" - : - "=m"(regsPtr[0]), - "=m"(regsPtr[1]), - "=m"(regsPtr[2]), - "=m"(regsPtr[3]) - : "m"(index) - : "%eax", "%ebx", "%ecx", "%edx" ); - status = TCL_OK; - /* End the structured exception handler */ - -# ifndef HAVE_NO_SEH - } __except( EXCEPTION_EXECUTE_HANDLER ) { - /* do nothing */ - } -# else - __asm __volatile__ ( - "jmp TclWinCPUID_detach_pop" "\n" - "TclWinCPUID_detach_reentry:" "\n\t" - "movl %%fs:0, %%eax" "\n\t" - "movl 0x8(%%eax), %%esp" "\n\t" - "movl 0x8(%%esp), %%ebp" "\n" - "TclWinCPUID_detach_pop:" "\n\t" - "movl (%%esp), %%eax" "\n\t" - "movl %%eax, %%fs:0" "\n\t" - "add $12, %%esp" "\n\t" - : - : - : "%eax"); -# endif + /* + * Build an EXCEPTION_REGISTRATION on the stack. Save + * EBP in the EXCEPTION_REGISTRATION's third longword. + * Put the address of the status word at 0x0c relative + * to the EXCEPTION_REGISTRATION. + */ + + "movl %[index], %%eax" "\n\t" + "leal %[stat], %%edx" "\n\t" + "movl %[rptr], %%edi" "\n\t" + "pushl %%edx" "\n\t" + "pushl %%ebp" "\n\t" + "leal 1f, %%edx" "\n\t" + "pushl %%edx" "\n\t" + "pushl %%fs:0" "\n\t" + "movl %%esp, %%fs:0" "\n\t" + + /* + * Do the CPUID instruction, and save the results in + * the 'regsPtr' area + */ + + "cpuid" "\n\t" + "movl %%eax, 0x0(%%edi)" "\n\t" + "movl %%ebx, 0x4(%%edi)" "\n\t" + "movl %%ecx, 0x8(%%edi)" "\n\t" + "movl %%edx, 0xc(%%edi)" "\n\t" + "movl %[ok], %%eax" "\n\t" + "jmp 2f" "\n" + + /* + * Come here on any exception. Retrieve the EXCEPTION_REGISTRATION + * and repair the stack. + */ + + "1:" "\t" + "movl %%fs:0, %%edx" "\n\t" + "movl 0x8(%%edx), %%esp" "\n\t" + "movl %[error], %%eax" "\n" + + /* + * Unstack the EXCEPTION_REGISTRATION, get back the address + * of the status word, and store status. + */ + + "2:" "\t" + "pop %%fs:0" "\n\t" + "addl $4, %%esp" "\n\t" + "pop %%ebp" "\n\t" + "pop %%edx" "\n\t" + "movl %%eax, 0x0(%%edx)" "\n\t" + + : [stat]"=m"(status) + : [index]"m"(index), + [rptr]"m"(regsPtr), + [ok]"i"(TCL_OK), + [error]"i"(TCL_ERROR) + : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory" ); #elif defined(_MSC_VER) && !defined(_WIN64) @@ -1216,36 +1187,4 @@ TclWinCPUID( unsigned int index, /* Which CPUID value to retrieve */ #endif return status; } - -/* - *---------------------------------------------------------------------- - * - * _except_TclWinCPUID_detach_handler -- - * - * SEH exception handler for TclWinCPUID. - * - * Results: - * See TclWinCPUID. - * - * Side effects: - * See TclWinCPUID. - * - *---------------------------------------------------------------------- - */ - -#if defined( HAVE_NO_SEH ) -static -__attribute__((cdecl)) -EXCEPTION_DISPOSITION -_except_TclWinCPUID_detach_handler( - struct _EXCEPTION_RECORD *ExceptionRecord, - void *EstablisherFrame, - struct _CONTEXT *ContextRecord, - void *DispatcherContext) -{ - __asm__ __volatile__ ( - "jmp TclWinCPUID_detach_reentry" ); - return 0; /* Function does not return */ -} -#endif |