diff --git a/files/file.c b/files/file.c index 6b61a6047be..3d5b46969ce 100644 --- a/files/file.c +++ b/files/file.c @@ -975,6 +975,27 @@ HFILE32 WINAPI OpenFile32( LPCSTR name, OFSTRUCT *ofs, UINT32 mode ) } +/*********************************************************************** + * FILE_InitProcessDosHandles + * + * Allocates the default DOS handles for a process. Called either by + * AllocDosHandle below or by the DOSVM stuff. + */ +BOOL32 FILE_InitProcessDosHandles( void ) { + HANDLE32 *ptr; + + if (!(ptr = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, + sizeof(*ptr) * DOS_TABLE_SIZE ))) + return FALSE; + PROCESS_Current()->dos_handles = ptr; + 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; +} + /*********************************************************************** * FILE_AllocDosHandle * @@ -989,17 +1010,10 @@ HFILE16 FILE_AllocDosHandle( HANDLE32 handle ) if (!handle || (handle == INVALID_HANDLE_VALUE32)) return INVALID_HANDLE_VALUE16; - if (!ptr) - { - if (!(ptr = HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, - sizeof(*ptr) * DOS_TABLE_SIZE ))) - goto error; - PROCESS_Current()->dos_handles = ptr; - 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); + if (!ptr) { + if (!FILE_InitProcessDosHandles()) + goto error; + ptr = PROCESS_Current()->dos_handles; } for (i = 0; i < DOS_TABLE_SIZE; i++, ptr++) diff --git a/include/file.h b/include/file.h index 6af604ac4f3..f1882913a86 100644 --- a/include/file.h +++ b/include/file.h @@ -47,6 +47,7 @@ extern LPVOID FILE_dommap( int unix_handle, LPVOID start, int prot, int flags ); extern int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low ); extern HFILE16 FILE_AllocDosHandle( HANDLE32 handle ); +extern BOOL32 FILE_InitProcessDosHandles( void ); extern HANDLE32 FILE_GetHandle32( HFILE16 hfile ); extern HFILE16 _lcreat16_uniq( LPCSTR path, INT32 attr ); diff --git a/loader/dos/dosvm.c b/loader/dos/dosvm.c index c4933637ced..bebc815cf6f 100644 --- a/loader/dos/dosvm.c +++ b/loader/dos/dosvm.c @@ -210,6 +210,9 @@ int DOSVM_Enter( PCONTEXT context ) it will be killed automatically when the current task terminates */ } else lpDosTask=pModule->lpDosTask; + /* allocate standard DOS handles */ + FILE_InitProcessDosHandles(); + if (context) { #define CP(x,y) VM86.regs.x = y##_reg(context) CV;