Commit 231674d8 authored by Alexandre Julliard's avatar Alexandre Julliard

Removed the DOS handles table from the PDB and made it a static

variable.
parent 4fef2f19
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "heap.h" #include "heap.h"
#include "msdos.h" #include "msdos.h"
#include "ldt.h" #include "ldt.h"
#include "process.h"
#include "task.h" #include "task.h"
#include "wincon.h" #include "wincon.h"
#include "debugtools.h" #include "debugtools.h"
...@@ -58,6 +57,8 @@ DEFAULT_DEBUG_CHANNEL(file); ...@@ -58,6 +57,8 @@ DEFAULT_DEBUG_CHANNEL(file);
/* Size of per-process table of DOS handles */ /* Size of per-process table of DOS handles */
#define DOS_TABLE_SIZE 256 #define DOS_TABLE_SIZE 256
static HANDLE dos_handles[DOS_TABLE_SIZE];
/*********************************************************************** /***********************************************************************
* FILE_ConvertOFMode * FILE_ConvertOFMode
...@@ -990,19 +991,13 @@ HFILE WINAPI OpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode ) ...@@ -990,19 +991,13 @@ HFILE WINAPI OpenFile( LPCSTR name, OFSTRUCT *ofs, UINT mode )
* Allocates the default DOS handles for a process. Called either by * Allocates the default DOS handles for a process. Called either by
* AllocDosHandle below or by the DOSVM stuff. * AllocDosHandle below or by the DOSVM stuff.
*/ */
BOOL FILE_InitProcessDosHandles( void ) { static void FILE_InitProcessDosHandles( void )
HANDLE *ptr; {
dos_handles[0] = GetStdHandle(STD_INPUT_HANDLE);
if (!(ptr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dos_handles[1] = GetStdHandle(STD_OUTPUT_HANDLE);
sizeof(*ptr) * DOS_TABLE_SIZE ))) dos_handles[2] = GetStdHandle(STD_ERROR_HANDLE);
return FALSE; dos_handles[3] = GetStdHandle(STD_ERROR_HANDLE);
PROCESS_Current()->dos_handles = ptr; dos_handles[4] = GetStdHandle(STD_ERROR_HANDLE);
ptr[0] = GetStdHandle(STD_INPUT_HANDLE);
ptr[1] = GetStdHandle(STD_OUTPUT_HANDLE);
ptr[2] = GetStdHandle(STD_ERROR_HANDLE);
ptr[3] = GetStdHandle(STD_ERROR_HANDLE);
ptr[4] = GetStdHandle(STD_ERROR_HANDLE);
return TRUE;
} }
/*********************************************************************** /***********************************************************************
...@@ -1014,25 +1009,17 @@ BOOL FILE_InitProcessDosHandles( void ) { ...@@ -1014,25 +1009,17 @@ BOOL FILE_InitProcessDosHandles( void ) {
HFILE16 FILE_AllocDosHandle( HANDLE handle ) HFILE16 FILE_AllocDosHandle( HANDLE handle )
{ {
int i; int i;
HANDLE *ptr = PROCESS_Current()->dos_handles;
if (!handle || (handle == INVALID_HANDLE_VALUE)) if (!handle || (handle == INVALID_HANDLE_VALUE))
return INVALID_HANDLE_VALUE16; return INVALID_HANDLE_VALUE16;
if (!ptr) { for (i = 5; i < DOS_TABLE_SIZE; i++)
if (!FILE_InitProcessDosHandles()) if (!dos_handles[i])
goto error;
ptr = PROCESS_Current()->dos_handles;
}
for (i = 0; i < DOS_TABLE_SIZE; i++, ptr++)
if (!*ptr)
{ {
*ptr = handle; dos_handles[i] = handle;
TRACE("Got %d for h32 %d\n", i, handle ); TRACE("Got %d for h32 %d\n", i, handle );
return i; return i;
} }
error:
CloseHandle( handle ); CloseHandle( handle );
SetLastError( ERROR_TOO_MANY_OPEN_FILES ); SetLastError( ERROR_TOO_MANY_OPEN_FILES );
return INVALID_HANDLE_VALUE16; return INVALID_HANDLE_VALUE16;
...@@ -1046,13 +1033,13 @@ error: ...@@ -1046,13 +1033,13 @@ error:
*/ */
HANDLE FILE_GetHandle( HFILE16 hfile ) HANDLE FILE_GetHandle( HFILE16 hfile )
{ {
HANDLE *table = PROCESS_Current()->dos_handles; if (hfile < 5 && !dos_handles[hfile]) FILE_InitProcessDosHandles();
if ((hfile >= DOS_TABLE_SIZE) || !table || !table[hfile]) if ((hfile >= DOS_TABLE_SIZE) || !dos_handles[hfile])
{ {
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
return table[hfile]; return dos_handles[hfile];
} }
...@@ -1063,11 +1050,11 @@ HANDLE FILE_GetHandle( HFILE16 hfile ) ...@@ -1063,11 +1050,11 @@ HANDLE FILE_GetHandle( HFILE16 hfile )
*/ */
HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ) HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 )
{ {
HANDLE *table = PROCESS_Current()->dos_handles;
HANDLE new_handle; HANDLE new_handle;
if ((hFile1 >= DOS_TABLE_SIZE) || (hFile2 >= DOS_TABLE_SIZE) || if (hFile1 < 5 && !dos_handles[hFile1]) FILE_InitProcessDosHandles();
!table || !table[hFile1])
if ((hFile1 >= DOS_TABLE_SIZE) || (hFile2 >= DOS_TABLE_SIZE) || !dos_handles[hFile1])
{ {
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
return HFILE_ERROR16; return HFILE_ERROR16;
...@@ -1078,12 +1065,12 @@ HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ) ...@@ -1078,12 +1065,12 @@ HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 )
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
return HFILE_ERROR16; return HFILE_ERROR16;
} }
if (!DuplicateHandle( GetCurrentProcess(), table[hFile1], if (!DuplicateHandle( GetCurrentProcess(), dos_handles[hFile1],
GetCurrentProcess(), &new_handle, GetCurrentProcess(), &new_handle,
0, FALSE, DUPLICATE_SAME_ACCESS )) 0, FALSE, DUPLICATE_SAME_ACCESS ))
return HFILE_ERROR16; return HFILE_ERROR16;
if (table[hFile2]) CloseHandle( table[hFile2] ); if (dos_handles[hFile2]) CloseHandle( dos_handles[hFile2] );
table[hFile2] = new_handle; dos_handles[hFile2] = new_handle;
return hFile2; return hFile2;
} }
...@@ -1093,22 +1080,20 @@ HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ) ...@@ -1093,22 +1080,20 @@ HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 )
*/ */
HFILE16 WINAPI _lclose16( HFILE16 hFile ) HFILE16 WINAPI _lclose16( HFILE16 hFile )
{ {
HANDLE *table = PROCESS_Current()->dos_handles;
if (hFile < 5) if (hFile < 5)
{ {
FIXME("stdio handle closed, need proper conversion\n" ); FIXME("stdio handle closed, need proper conversion\n" );
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
return HFILE_ERROR16; return HFILE_ERROR16;
} }
if ((hFile >= DOS_TABLE_SIZE) || !table || !table[hFile]) if ((hFile >= DOS_TABLE_SIZE) || !dos_handles[hFile])
{ {
SetLastError( ERROR_INVALID_HANDLE ); SetLastError( ERROR_INVALID_HANDLE );
return HFILE_ERROR16; return HFILE_ERROR16;
} }
TRACE("%d (handle32=%d)\n", hFile, table[hFile] ); TRACE("%d (handle32=%d)\n", hFile, dos_handles[hFile] );
CloseHandle( table[hFile] ); CloseHandle( dos_handles[hFile] );
table[hFile] = 0; dos_handles[hFile] = 0;
return 0; return 0;
} }
......
...@@ -46,7 +46,6 @@ extern LPVOID FILE_dommap( int unix_handle, LPVOID start, ...@@ -46,7 +46,6 @@ extern LPVOID FILE_dommap( int unix_handle, LPVOID start,
int prot, int flags ); int prot, int flags );
extern int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low ); extern int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low );
extern HFILE16 FILE_AllocDosHandle( HANDLE handle ); extern HFILE16 FILE_AllocDosHandle( HANDLE handle );
extern BOOL FILE_InitProcessDosHandles( void );
extern HANDLE FILE_GetHandle( HFILE16 hfile ); extern HANDLE FILE_GetHandle( HFILE16 hfile );
/* files/directory.c */ /* files/directory.c */
......
...@@ -464,8 +464,6 @@ int DOSVM_Enter( CONTEXT86 *context ) ...@@ -464,8 +464,6 @@ int DOSVM_Enter( CONTEXT86 *context )
VM86.regs.eflags |= VIF_MASK; VM86.regs.eflags |= VIF_MASK;
} else { } else {
/* initial setup */ /* initial setup */
/* allocate standard DOS handles */
FILE_InitProcessDosHandles();
/* registers */ /* registers */
memset(&VM86,0,sizeof(VM86)); memset(&VM86,0,sizeof(VM86));
VM86.regs.cs=lpDosTask->init_cs; VM86.regs.cs=lpDosTask->init_cs;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment