I hope Alexandre will not got mad about the introduced circular dep (kernel32 => (delay) winedos => kernel32). Since, we're now building the DLLs through the .spec files, I assumed, since it no longer impacts the make system, it would be ok.
A+ -- Eric Pouech
Name: dh ChangeLog: Cleaning of wine specific exports from kernel32: - removed no longer used export - got rid of _lclose16 & FILE_Dup2 export by moving all dos handles code to winedos (with delay import) - moved _lclose16 into dlls/kernel directory License: X11 GenDate: 2003/12/06 14:14:06 UTC ModifiedFiles: dlls/kernel/Makefile.in dlls/kernel/kernel32.spec dlls/kernel/kernel_private.h dlls/kernel/file.c dlls/kernel/file16.c dlls/winedos/winedos.spec dlls/winedos/int21.c files/file.c include/file.h =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/dlls/kernel/Makefile.in,v retrieving revision 1.102 diff -u -u -r1.102 Makefile.in --- dlls/kernel/Makefile.in 14 Nov 2003 21:08:39 -0000 1.102 +++ dlls/kernel/Makefile.in 6 Dec 2003 10:49:59 -0000 @@ -7,6 +7,7 @@ IMPORTS = ntdll ALTNAMES = krnl386.exe comm.drv stress.dll system.drv toolhelp.dll windebug.dll win87em.dll EXTRALIBS = $(LIBUNICODE) +DELAYIMPORTS = winedos SPEC_SRCS16 = \ comm.drv.spec \ Index: dlls/kernel/kernel32.spec =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/dlls/kernel/kernel32.spec,v retrieving revision 1.120 diff -u -u -r1.120 kernel32.spec --- dlls/kernel/kernel32.spec 25 Nov 2003 01:51:07 -0000 1.120 +++ dlls/kernel/kernel32.spec 6 Dec 2003 14:12:57 -0000 @@ -29,7 +29,7 @@ 19 stub ThunkTheTemplateHandle 20 stdcall DosFileHandleToWin32Handle(long) 21 stdcall Win32HandleToDosFileHandle(long) - 22 stdcall DisposeLZ32Handle(long) + 22 stdcall DisposeLZ32Handle(long) KERNEL_DisposeLZ32Handle 23 stub GDIReallyCares 24 stdcall GlobalAlloc16(long long) 25 stdcall GlobalLock16(long) @@ -1075,7 +1077,6 @@ ################################################################ # Wine extensions: Win16 functions that are needed by other dlls # -@ stdcall _lclose16(long) @ stdcall AllocCStoDSAlias16(long) @ stdcall AllocSelectorArray16(long) @ stdcall ConvertDialog32To16(ptr long ptr) @@ -1090,12 +1091,8 @@ @ stdcall GetDOSEnvironment16() @ stdcall GetExePtr(long) @ stdcall GetExpWinVer16(long) -@ stdcall GetModuleFileName16(long ptr long) @ stdcall GetModuleHandle16(str) -@ stdcall GetModuleName16(long ptr long) -@ stdcall GetSelectorBase(long) @ stdcall GetSelectorLimit16(long) -@ stdcall GetThreadQueue16(long) @ stdcall GetVersion16() @ stdcall GetWinFlags16() @ stdcall GlobalDOSAlloc16(long) @@ -1140,14 +1137,13 @@ ################################################################ # Wine dll separation hacks, these will go away, don't use them # @ cdecl DOSFS_GetDeviceByHandle(long) @ cdecl DOSMEM_AllocSelector(long) @ cdecl DOSMEM_Available() @ cdecl DOSMEM_FreeBlock(ptr) @ cdecl DOSMEM_GetBlock(long ptr) @ cdecl DOSMEM_Init(long) @ cdecl DOSMEM_ResizeBlock(ptr long long) -@ cdecl FILE_Dup2(long long) @ cdecl LOCAL_Alloc(long long long) @ cdecl LOCAL_Compact(long long long) @ cdecl LOCAL_CountFree(long) Index: dlls/kernel/kernel_private.h =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/dlls/kernel/kernel_private.h,v retrieving revision 1.8 diff -u -u -r1.8 kernel_private.h --- dlls/kernel/kernel_private.h 1 Dec 2003 22:47:28 -0000 1.8 +++ dlls/kernel/kernel_private.h 6 Dec 2003 13:58:10 -0000 @@ -44,10 +44,8 @@ return h != INVALID_HANDLE_VALUE ? (HANDLE)((DWORD)h ^ 3) : INVALID_HANDLE_VALUE; } -/* Size of per-process table of DOS handles */ -#define DOS_TABLE_SIZE 256 -extern HANDLE dos_handles[DOS_TABLE_SIZE]; void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing ); +extern BOOL WINAPI DisposeDosFileHandle(UINT16, HANDLE*); extern BOOL WOWTHUNK_Init(void); Index: dlls/kernel/file.c =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/dlls/kernel/file.c,v retrieving revision 1.4 diff -u -u -r1.4 file.c --- dlls/kernel/file.c 5 Sep 2003 23:08:37 -0000 1.4 +++ dlls/kernel/file.c 6 Dec 2003 13:54:25 -0000 @@ -222,7 +222,6 @@ return (HFILE)CreateFileA( path, access, sharing, NULL, OPEN_EXISTING, 0, 0 ); } - /*********************************************************************** * _lread (KERNEL32.@) */ @@ -251,6 +250,20 @@ return (UINT)_hwrite( hFile, buffer, (LONG)count ); } + +/****************************************************************** + * KERNEL_DisposeLZ32Handle + * + * sigh: this is needed because we delay import winedos, and since we don't use + * in kernel32 the DisposeLZ32Handle API, it's not seen by winebuild as a missing + * symbol, hence a linking error + * This will do for now (don't think it's necessary to add a specific flag to + * winebuild for this kind of behavior + */ +void WINAPI KERNEL_DisposeLZ32Handle( HANDLE hFile ) +{ + DisposeLZ32Handle(hFile); +} /*********************************************************************** * FlushFileBuffers (KERNEL32.@) Index: dlls/kernel/file16.c =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/dlls/kernel/file16.c,v retrieving revision 1.4 diff -u -u -r1.4 file16.c --- dlls/kernel/file16.c 15 Nov 2003 00:13:21 -0000 1.4 +++ dlls/kernel/file16.c 6 Dec 2003 13:55:23 -0000 @@ -72,6 +72,20 @@ } /*********************************************************************** + * _lclose (KERNEL.81) + */ +HFILE16 WINAPI _lclose16( HFILE16 hFile16 ) +{ + HANDLE hFile; + + if (!DisposeDosFileHandle(hFile16, &hFile)) + return HFILE_ERROR16; + TRACE("%d (handle32=%p)\n", hFile16, hFile ); + CloseHandle(hFile); + return 0; +} + +/*********************************************************************** * _llseek (KERNEL.84) * * FIXME: Index: dlls/winedos/winedos.spec =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/dlls/winedos/winedos.spec,v retrieving revision 1.17 diff -u -u -r1.17 winedos.spec --- dlls/winedos/winedos.spec 17 Sep 2003 22:45:46 -0000 1.17 +++ dlls/winedos/winedos.spec 6 Dec 2003 12:51:45 -0000 @@ -6,3 +6,9 @@ # I/O functions @ stdcall inport(long long) DOSVM_inport @ stdcall outport(long long long) DOSVM_outport + +# DOS handles manipulation +@ stdcall DosFileHandleToWin32Handle(long) +@ stdcall Win32HandleToDosFileHandle(long) +@ stdcall DisposeDosFileHandle(long ptr) +@ stdcall DisposeLZ32Handle(long) Index: dlls/winedos/int21.c =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/dlls/winedos/int21.c,v retrieving revision 1.51 diff -u -u -r1.51 int21.c --- dlls/winedos/int21.c 26 Nov 2003 22:29:30 -0000 1.51 +++ dlls/winedos/int21.c 6 Dec 2003 14:13:55 -0000 @@ -38,12 +55,11 @@ #include "winternl.h" #include "wine/winbase16.h" #include "dosexe.h" -#include "file.h" #include "winerror.h" #include "winuser.h" #include "wine/unicode.h" #include "wine/debug.h" #include "wine/exception.h" #include "wine/server.h" /* * Note: @@ -245,6 +262,164 @@ #define EL_Serial 0x04 #define EL_Memory 0x05 +#define DOS_TABLE_SIZE 256 +static HANDLE dos_handles[DOS_TABLE_SIZE]; + +/*********************************************************************** + * FILE_InitProcessDosHandles + * + * Allocates the default DOS handles for a process. Called either by + * Win32HandleToDosFileHandle below or by the DOSVM stuff. + */ +static void FILE_InitProcessDosHandles( void ) +{ + HANDLE cp = GetCurrentProcess(); + DuplicateHandle(cp, GetStdHandle(STD_INPUT_HANDLE), cp, &dos_handles[0], + 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, GetStdHandle(STD_OUTPUT_HANDLE), cp, &dos_handles[1], + 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[2], + 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[3], + 0, TRUE, DUPLICATE_SAME_ACCESS); + DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[4], + 0, TRUE, DUPLICATE_SAME_ACCESS); +} + +/*********************************************************************** + * Win32HandleToDosFileHandle (KERNEL32.21) + * + * Allocate a DOS handle for a Win32 handle. The Win32 handle is no + * longer valid after this function (even on failure). + * + * Note: this is not exactly right, since on Win95 the Win32 handles + * are on top of DOS handles and we do it the other way + * around. Should be good enough though. + */ +HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle ) +{ + int i; + + FIXME("I'm called\n"); + if (!handle || (handle == INVALID_HANDLE_VALUE)) + return HFILE_ERROR; + + for (i = 5; i < DOS_TABLE_SIZE; i++) + { + if (!dos_handles[i]) + { + dos_handles[i] = handle; + TRACE("Got %d for h32 %p\n", i, handle ); + return (HFILE)i; + } + } + CloseHandle( handle ); + SetLastError( ERROR_TOO_MANY_OPEN_FILES ); + return HFILE_ERROR; +} + +/*********************************************************************** + * DosFileHandleToWin32Handle (KERNEL32.20) + * + * Return the Win32 handle for a DOS handle. + * + * Note: this is not exactly right, since on Win95 the Win32 handles + * are on top of DOS handles and we do it the other way + * around. Should be good enough though. + */ +HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle ) +{ + HFILE16 hfile = (HFILE16)handle; + FIXME("I'm called\n"); + if (hfile < 5 && !dos_handles[hfile]) FILE_InitProcessDosHandles(); + if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile]) + { + SetLastError( ERROR_INVALID_HANDLE ); + return INVALID_HANDLE_VALUE; + } + return dos_handles[hfile]; +} + +/****************************************************************** + * DisposeDosFileHandle + * + */ +BOOL WINAPI DisposeDosFileHandle( HFILE16 hFile16, HANDLE* hFile ) +{ + FIXME("I'm called\n"); + if (hFile16 >= DOS_TABLE_SIZE || !dos_handles[hFile16]) + { + SetLastError( ERROR_INVALID_HANDLE ); + return FALSE; + } + if (hFile) *hFile = dos_handles[hFile16]; + dos_handles[hFile16] = NULL; + return TRUE; +} + +/*********************************************************************** + * DisposeLZ32Handle (KERNEL32.22) + * + * Note: this is not entirely correct, we should only close the + * 32-bit handle and not the 16-bit one, but we cannot do + * this because of the way our DOS handles are implemented. + * It shouldn't break anything though. + */ +void WINAPI DisposeLZ32Handle( HANDLE handle ) +{ + int i; + + FIXME("I'm called\n"); + if (!handle || (handle == INVALID_HANDLE_VALUE)) return; + + for (i = 5; i < DOS_TABLE_SIZE; i++) + { + if (dos_handles[i] == handle) + { + dos_handles[i] = 0; + CloseHandle( handle ); + break; + } + } +} + +/*********************************************************************** + * FILE_Dup2 + * + * dup2() function for DOS handles. + */ +static HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ) +{ + HANDLE new_handle; + + if (hFile1 < 5 && !dos_handles[hFile1]) FILE_InitProcessDosHandles(); + + if ((hFile1 >= DOS_TABLE_SIZE) || (hFile2 >= DOS_TABLE_SIZE) || !dos_handles[hFile1]) + { + SetLastError( ERROR_INVALID_HANDLE ); + return HFILE_ERROR16; + } + if (!DuplicateHandle( GetCurrentProcess(), dos_handles[hFile1], + GetCurrentProcess(), &new_handle, + 0, FALSE, DUPLICATE_SAME_ACCESS )) + return HFILE_ERROR16; + if (dos_handles[hFile2]) CloseHandle( dos_handles[hFile2] ); + dos_handles[hFile2] = new_handle; + return hFile2; +} + +/****************************************************************** + * FILE_Close + */ +static BOOL FILE_Close( HFILE16 hFile16 ) +{ + HANDLE hFile; + + if (!DisposeDosFileHandle(hFile16, &hFile)) return FALSE; + TRACE("%d (handle32=%p)\n", hFile16, hFile); + CloseHandle(hFile); + return TRUE; +} /* Many calls translate a drive argument like this: drive number (00h = default, 01h = A:, etc) @@ -1109,13 +1284,13 @@ AL_result = 0xff; /* failed */ } else if (hfile16 > 255) { TRACE("hfile16 (=%d) larger than 255 for \"%s\"\n", hfile16, file_path); - _lclose16(hfile16); + FILE_Close(hfile16); AL_result = 0xff; /* failed */ } else { if (!GetFileInformationByHandle(handle, &info)) { TRACE("GetFileInformationByHandle(%d, %p) for \"%s\" failed\n", hfile16, handle, file_path); - _lclose16(hfile16); + FILE_Close(hfile16); AL_result = 0xff; /* failed */ } else { fcb->drive_number = file_path[0] - 'A' + 1; @@ -1173,7 +1348,7 @@ fcb = (struct FCB *) xfcb->fcb; } /* if */ - if (_lclose16((HFILE16) fcb->file_number) != 0) { + if (!FILE_Close((HFILE16) fcb->file_number)) { TRACE("_lclose16(%d) failed\n", fcb->file_number); AL_result = 0xff; /* failed */ } else { @@ -3439,7 +3661,7 @@ * is something behind this ? */ while (*p == '*' || *p == ' ') p++; /* skip wildcards and spaces */ - return IS_END_OF_NAME(*p); + return !*p || *p == '/' || *p == '\\'; } static HANDLE INT21_FindHandle; @@ -4362,7 +4584,7 @@ case 0x3e: /* "CLOSE" - CLOSE FILE */ TRACE( "CLOSE handle %d\n", BX_reg(context) ); - if (_lclose16( BX_reg(context) ) == HFILE_ERROR16) + if (!FILE_Close( BX_reg(context) )) bSetDOSExtendedError = TRUE; else RESET_CFLAG(context); Index: files/file.c =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/files/file.c,v retrieving revision 1.195 diff -u -u -r1.195 file.c --- files/file.c 2 Dec 2003 04:48:16 -0000 1.195 +++ files/file.c 6 Dec 2003 13:53:30 -0000 @@ -84,7 +84,6 @@ #define IS_OPTION_TRUE(ch) ((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1') -HANDLE dos_handles[DOS_TABLE_SIZE]; mode_t FILE_umask; /*********************************************************************** @@ -1244,7 +1194,10 @@ hFileRet = Win32HandleToDosFileHandle( handle ); if (hFileRet == HFILE_ERROR16) goto error; if (mode & OF_EXIST) /* Return the handle, but close it first */ - _lclose16( hFileRet ); + { + CloseHandle(handle); + DisposeDosFileHandle(hFileRet, NULL); + } } return hFileRet; @@ -1280,146 +1233,6 @@ } -/*********************************************************************** - * FILE_InitProcessDosHandles - * - * Allocates the default DOS handles for a process. Called either by - * Win32HandleToDosFileHandle below or by the DOSVM stuff. - */ -static void FILE_InitProcessDosHandles( void ) -{ - HANDLE cp = GetCurrentProcess(); - DuplicateHandle(cp, GetStdHandle(STD_INPUT_HANDLE), cp, &dos_handles[0], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_OUTPUT_HANDLE), cp, &dos_handles[1], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[2], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[3], - 0, TRUE, DUPLICATE_SAME_ACCESS); - DuplicateHandle(cp, GetStdHandle(STD_ERROR_HANDLE), cp, &dos_handles[4], - 0, TRUE, DUPLICATE_SAME_ACCESS); -} - -/*********************************************************************** - * Win32HandleToDosFileHandle (KERNEL32.21) - * - * Allocate a DOS handle for a Win32 handle. The Win32 handle is no - * longer valid after this function (even on failure). - * - * Note: this is not exactly right, since on Win95 the Win32 handles - * are on top of DOS handles and we do it the other way - * around. Should be good enough though. - */ -HFILE WINAPI Win32HandleToDosFileHandle( HANDLE handle ) -{ - int i; - - if (!handle || (handle == INVALID_HANDLE_VALUE)) - return HFILE_ERROR; - - for (i = 5; i < DOS_TABLE_SIZE; i++) - if (!dos_handles[i]) - { - dos_handles[i] = handle; - TRACE("Got %d for h32 %p\n", i, handle ); - return (HFILE)i; - } - CloseHandle( handle ); - SetLastError( ERROR_TOO_MANY_OPEN_FILES ); - return HFILE_ERROR; -} - - -/*********************************************************************** - * DosFileHandleToWin32Handle (KERNEL32.20) - * - * Return the Win32 handle for a DOS handle. - * - * Note: this is not exactly right, since on Win95 the Win32 handles - * are on top of DOS handles and we do it the other way - * around. Should be good enough though. - */ -HANDLE WINAPI DosFileHandleToWin32Handle( HFILE handle ) -{ - HFILE16 hfile = (HFILE16)handle; - if (hfile < 5 && !dos_handles[hfile]) FILE_InitProcessDosHandles(); - if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile]) - { - SetLastError( ERROR_INVALID_HANDLE ); - return INVALID_HANDLE_VALUE; - } - return dos_handles[hfile]; -} - - -/*********************************************************************** - * DisposeLZ32Handle (KERNEL32.22) - * - * Note: this is not entirely correct, we should only close the - * 32-bit handle and not the 16-bit one, but we cannot do - * this because of the way our DOS handles are implemented. - * It shouldn't break anything though. - */ -void WINAPI DisposeLZ32Handle( HANDLE handle ) -{ - int i; - - if (!handle || (handle == INVALID_HANDLE_VALUE)) return; - - for (i = 5; i < DOS_TABLE_SIZE; i++) - if (dos_handles[i] == handle) - { - dos_handles[i] = 0; - CloseHandle( handle ); - break; - } -} - - -/*********************************************************************** - * FILE_Dup2 - * - * dup2() function for DOS handles. - */ -HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ) -{ - HANDLE new_handle; - - if (hFile1 < 5 && !dos_handles[hFile1]) FILE_InitProcessDosHandles(); - - if ((hFile1 >= DOS_TABLE_SIZE) || (hFile2 >= DOS_TABLE_SIZE) || !dos_handles[hFile1]) - { - SetLastError( ERROR_INVALID_HANDLE ); - return HFILE_ERROR16; - } - if (!DuplicateHandle( GetCurrentProcess(), dos_handles[hFile1], - GetCurrentProcess(), &new_handle, - 0, FALSE, DUPLICATE_SAME_ACCESS )) - return HFILE_ERROR16; - if (dos_handles[hFile2]) CloseHandle( dos_handles[hFile2] ); - dos_handles[hFile2] = new_handle; - return hFile2; -} - - -/*********************************************************************** - * _lclose (KERNEL.81) - */ -HFILE16 WINAPI _lclose16( HFILE16 hFile ) -{ - if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile]) - { - SetLastError( ERROR_INVALID_HANDLE ); - return HFILE_ERROR16; - } - TRACE("%d (handle32=%p)\n", hFile, dos_handles[hFile] ); - CloseHandle( dos_handles[hFile] ); - dos_handles[hFile] = 0; - return 0; -} - - /****************************************************************** * FILE_ReadWriteApc (internal) * Index: include/file.h =================================================================== RCS file: /home/cvs/cvsroot/wine/wine/include/file.h,v retrieving revision 1.62 diff -u -u -r1.62 file.h --- include/file.h 2 Dec 2003 04:19:56 -0000 1.62 +++ include/file.h 6 Dec 2003 11:50:42 -0000 @@ -71,12 +73,11 @@ extern int FILE_strncasecmp( const char *str1, const char *str2, int len ); extern void FILE_SetDosError(void); extern BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info, BOOL *is_symlink ); -extern HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ); extern HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, LPSECURITY_ATTRIBUTES sa, DWORD creation, DWORD attributes, HANDLE template, BOOL fail_read_only, UINT drive_type ); extern HANDLE FILE_CreateDevice( int client_id, DWORD access, LPSECURITY_ATTRIBUTES sa ); extern LONG WINAPI WIN16_hread(HFILE16,SEGPTR,LONG);