Commit 5fbb446c authored by Alexandre Julliard's avatar Alexandre Julliard

Moved most of the 16-bit task support and NE module loader to

dlls/kernel.
parent df167d17
......@@ -34,6 +34,8 @@ C_SRCS = \
lcformat.c \
local16.c \
locale.c \
ne_module.c \
ne_segment.c \
powermgnt.c \
process.c \
resource.c \
......@@ -42,6 +44,7 @@ C_SRCS = \
string.c \
sync.c \
tape.c \
task.c \
thread.c \
thunk.c \
time.c \
......
......@@ -97,6 +97,7 @@ static void thread_detach(void)
/* free the 16-bit stack */
K32WOWGlobalFree16( NtCurrentTeb()->stack_sel );
NtCurrentTeb()->cur_stack = 0;
if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask();
}
......
......@@ -34,6 +34,7 @@
#include <string.h>
#include "wine/winbase16.h"
#include "wownt32.h"
#include "wine/library.h"
#include "global.h"
#include "task.h"
......@@ -82,10 +83,6 @@ struct relocation_entry_s
static void NE_FixupSegmentPrologs(NE_MODULE *pModule, WORD segnum);
/* ### start build ### */
extern WORD CALLBACK NE_CallTo16_word_ww(FARPROC16,WORD,WORD);
extern WORD CALLBACK NE_CallTo16_word_www(FARPROC16,WORD,WORD,WORD);
/* ### stop build ### */
/***********************************************************************
* NE_GetRelocAddrName
......@@ -158,6 +155,8 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum )
DWORD oldstack;
HANDLE hFile32;
HFILE16 hFile16;
WORD args[3];
DWORD ret;
selfloadheader = MapSL( MAKESEGPTR(SEL(pSegTable->hSeg),0) );
oldstack = NtCurrentTeb()->cur_stack;
......@@ -169,8 +168,11 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum )
DuplicateHandle( GetCurrentProcess(), hf, GetCurrentProcess(), &hFile32,
0, FALSE, DUPLICATE_SAME_ACCESS );
hFile16 = Win32HandleToDosFileHandle( hFile32 );
pSeg->hSeg = NE_CallTo16_word_www( selfloadheader->LoadAppSeg,
pModule->self, hFile16, segnum );
args[2] = pModule->self;
args[1] = hFile16;
args[0] = segnum;
WOWCallback16Ex( (DWORD)selfloadheader->LoadAppSeg, WCB16_PASCAL, sizeof(args), args, &ret );
pSeg->hSeg = LOWORD(ret);
TRACE_(dll)("Ret CallLoadAppSegProc: hSeg = 0x%04x\n", pSeg->hSeg);
_lclose16( hFile16 );
NtCurrentTeb()->cur_stack = oldstack;
......@@ -450,6 +452,7 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule )
SELFLOADHEADER *selfloadheader;
HMODULE16 mod = GetModuleHandle16("KERNEL");
DWORD oldstack;
WORD args[2];
TRACE_(module)("%.*s is a self-loading module!\n",
*((BYTE*)pModule + pModule->name_table),
......@@ -470,7 +473,9 @@ BOOL NE_LoadAllSegments( NE_MODULE *pModule )
hFile16 = Win32HandleToDosFileHandle( hf );
TRACE_(dll)("CallBootAppProc(hModule=0x%04x,hf=0x%04x)\n",
pModule->self,hFile16);
NE_CallTo16_word_ww(selfloadheader->BootApp, pModule->self,hFile16);
args[1] = pModule->self;
args[0] = hFile16;
WOWCallback16Ex( (DWORD)selfloadheader->BootApp, WCB16_PASCAL, sizeof(args), args, NULL );
TRACE_(dll)("Return from CallBootAppProc\n");
_lclose16(hFile16);
NtCurrentTeb()->cur_stack = oldstack;
......
......@@ -1589,7 +1589,7 @@ FARPROC THUNK_AllocLSThunklet( SEGPTR target, DWORD relay,
THUNKLET_TYPE_LS );
if (!thunk)
{
TDB *pTask = TASK_GetPtr( owner );
TDB *pTask = GlobalLock16( owner );
if (!ThunkletHeap) THUNK_Init();
if ( !(thunk = HeapAlloc( ThunkletHeap, 0, sizeof(THUNKLET) )) )
......@@ -1623,7 +1623,7 @@ SEGPTR THUNK_AllocSLThunklet( FARPROC target, DWORD relay,
THUNKLET_TYPE_SL );
if (!thunk)
{
TDB *pTask = TASK_GetPtr( owner );
TDB *pTask = GlobalLock16( owner );
if (!ThunkletHeap) THUNK_Init();
if ( !(thunk = HeapAlloc( ThunkletHeap, 0, sizeof(THUNKLET) )) )
......
......@@ -235,7 +235,7 @@ HANDLE WINAPI K32WOWHandle32( WORD handle, WOW_HANDLE_TYPE type )
return (HANDLE)(ULONG_PTR)handle;
case WOW_TYPE_HTASK:
return (HANDLE)TASK_GetPtr(handle)->teb->tid;
return (HANDLE)((TDB *)GlobalLock16(handle))->teb->tid;
case WOW_TYPE_FULLHWND:
FIXME( "conversion of full window handles not supported yet\n" );
......@@ -276,7 +276,7 @@ WORD WINAPI K32WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type )
return LOWORD(handle);
case WOW_TYPE_HTASK:
return THREAD_IdToTEB((DWORD)handle)->htask16;
return TASK_GetTaskFromThread( (DWORD)handle );
default:
ERR( "handle %p of unknown type %d\n", handle, type );
......
......@@ -21,7 +21,6 @@ C_SRCS = \
$(TOPOBJDIR)/loader/pe_image.c \
$(TOPOBJDIR)/loader/task.c \
$(TOPOBJDIR)/loader/ne/module.c \
$(TOPOBJDIR)/loader/ne/segment.c \
$(TOPOBJDIR)/memory/codepage.c \
$(TOPOBJDIR)/memory/environ.c \
$(TOPOBJDIR)/memory/global.c \
......@@ -89,7 +88,7 @@ ASM_SRCS = \
relay16.s \
relay32.s
EXTRA_OBJS = $(ASM_SRCS:.s=.o) $(MODULE).glue.o
EXTRA_OBJS = $(ASM_SRCS:.s=.o)
SUBDIRS = tests
......
......@@ -428,7 +428,7 @@ int DRIVE_IsValid( int drive )
*/
int DRIVE_GetCurrentDrive(void)
{
TDB *pTask = TASK_GetCurrent();
TDB *pTask = GlobalLock16(GetCurrentTask());
if (pTask && (pTask->curdrive & 0x80)) return pTask->curdrive & ~0x80;
return DRIVE_CurDrive;
}
......@@ -439,7 +439,7 @@ int DRIVE_GetCurrentDrive(void)
*/
int DRIVE_SetCurrentDrive( int drive )
{
TDB *pTask = TASK_GetCurrent();
TDB *pTask = GlobalLock16(GetCurrentTask());
if (!DRIVE_IsValid( drive ))
{
SetLastError( ERROR_INVALID_DRIVE );
......@@ -619,7 +619,7 @@ const char * DRIVE_GetRoot( int drive )
*/
LPCWSTR DRIVE_GetDosCwd( int drive )
{
TDB *pTask = TASK_GetCurrent();
TDB *pTask = GlobalLock16(GetCurrentTask());
if (!DRIVE_IsValid( drive )) return NULL;
/* Check if we need to change the directory to the new task. */
......@@ -643,7 +643,7 @@ LPCWSTR DRIVE_GetDosCwd( int drive )
*/
const char * DRIVE_GetUnixCwd( int drive )
{
TDB *pTask = TASK_GetCurrent();
TDB *pTask = GlobalLock16(GetCurrentTask());
if (!DRIVE_IsValid( drive )) return NULL;
/* Check if we need to change the directory to the new task. */
......@@ -1234,7 +1234,7 @@ int DRIVE_Chdir( int drive, LPCWSTR path )
WCHAR buffer[MAX_PATHNAME_LEN];
LPSTR unix_cwd;
BY_HANDLE_FILE_INFORMATION info;
TDB *pTask = TASK_GetCurrent();
TDB *pTask = GlobalLock16(GetCurrentTask());
buffer[0] = 'A' + drive;
buffer[1] = ':';
......
......@@ -163,10 +163,8 @@ extern void TASK_CreateMainTask(void);
extern HTASK16 TASK_SpawnTask( struct _NE_MODULE *pModule, WORD cmdShow,
LPCSTR cmdline, BYTE len, HANDLE *hThread );
extern void TASK_ExitTask(void);
extern HTASK16 TASK_GetNextTask( HTASK16 hTask );
extern TDB *TASK_GetPtr( HTASK16 hTask );
extern HTASK16 TASK_GetTaskFromThread( DWORD thread );
extern TDB *TASK_GetCurrent(void);
extern void TASK_InstallTHHook( THHOOK *pNewThook );
extern void TASK_CallTaskSignalProc( UINT16 uCode, HANDLE16 hTaskOrModule );
#endif /* __WINE_TASK_H */
......@@ -149,7 +149,6 @@ typedef struct _TEB
/* scheduler/thread.c */
extern void THREAD_Init(void);
extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size );
extern TEB *THREAD_IdToTEB( DWORD id );
/* scheduler/sysdeps.c */
extern int SYSDEPS_SpawnThread( void (*func)(TEB *), TEB *teb );
......
......@@ -782,27 +782,6 @@ VOID WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
}
/***********************************************************************
* PrivateLoadLibrary (KERNEL32.@)
*
* FIXME: rough guesswork, don't know what "Private" means
*/
HINSTANCE16 WINAPI PrivateLoadLibrary(LPCSTR libname)
{
return LoadLibrary16(libname);
}
/***********************************************************************
* PrivateFreeLibrary (KERNEL32.@)
*
* FIXME: rough guesswork, don't know what "Private" means
*/
void WINAPI PrivateFreeLibrary(HINSTANCE16 handle)
{
FreeLibrary16(handle);
}
/***********************************************************************
* GetProcAddress (KERNEL32.@)
*/
FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
......
......@@ -148,7 +148,7 @@ static BOOL INT21_CreateHeap(void)
static BYTE *GetCurrentDTA( CONTEXT86 *context )
{
TDB *pTask = TASK_GetCurrent();
TDB *pTask = GlobalLock16(GetCurrentTask());
/* FIXME: This assumes DTA was set correctly! */
return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
......
......@@ -35,7 +35,6 @@
#endif
#include "wine/winbase16.h"
#include "thread.h"
#include "task.h"
#include "module.h"
#include "winerror.h"
#include "selectors.h"
......@@ -54,39 +53,6 @@ static TEB initial_teb;
extern struct _PDB current_process;
/***********************************************************************
* THREAD_IdToTEB
*
* Convert a thread id to a TEB, making sure it is valid.
*/
TEB *THREAD_IdToTEB( DWORD id )
{
TEB *ret = NULL;
if (!id || id == GetCurrentThreadId()) return NtCurrentTeb();
SERVER_START_REQ( get_thread_info )
{
req->handle = 0;
req->tid_in = id;
if (!wine_server_call( req )) ret = reply->teb;
}
SERVER_END_REQ;
if (!ret)
{
/* Allow task handles to be used; convert to main thread */
if ( IsTask16( id ) )
{
TDB *pTask = TASK_GetPtr( id );
if (pTask) return pTask->teb;
}
SetLastError( ERROR_INVALID_PARAMETER );
}
return ret;
}
/***********************************************************************
* THREAD_InitTEB
*
* Initialization of a newly created TEB.
......@@ -341,7 +307,6 @@ void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
else
{
LdrShutdownThread();
if (!(NtCurrentTeb()->tibflags & TEBF_WIN32)) TASK_ExitTask();
SYSDEPS_ExitThread( code );
}
}
......
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