Commit 4cb21206 authored by Alexandre Julliard's avatar Alexandre Julliard

Moved some of the process functions to dlls/kernel.

Removed kernel dependencies from sysdeps.c and moved it to dlls/ntdll.
parent b3793342
...@@ -35,6 +35,7 @@ C_SRCS = \ ...@@ -35,6 +35,7 @@ C_SRCS = \
lcformat.c \ lcformat.c \
local16.c \ local16.c \
locale.c \ locale.c \
process.c \
resource.c \ resource.c \
resource16.c \ resource16.c \
stress.c \ stress.c \
......
...@@ -49,7 +49,6 @@ C_SRCS = \ ...@@ -49,7 +49,6 @@ C_SRCS = \
$(TOPOBJDIR)/scheduler/process.c \ $(TOPOBJDIR)/scheduler/process.c \
$(TOPOBJDIR)/scheduler/pthread.c \ $(TOPOBJDIR)/scheduler/pthread.c \
$(TOPOBJDIR)/scheduler/synchro.c \ $(TOPOBJDIR)/scheduler/synchro.c \
$(TOPOBJDIR)/scheduler/sysdeps.c \
$(TOPOBJDIR)/scheduler/syslevel.c \ $(TOPOBJDIR)/scheduler/syslevel.c \
$(TOPOBJDIR)/scheduler/thread.c \ $(TOPOBJDIR)/scheduler/thread.c \
$(TOPOBJDIR)/win32/device.c \ $(TOPOBJDIR)/win32/device.c \
...@@ -80,6 +79,7 @@ C_SRCS = \ ...@@ -80,6 +79,7 @@ C_SRCS = \
signal_sparc.c \ signal_sparc.c \
string.c \ string.c \
sync.c \ sync.c \
sysdeps.c \
thread.c \ thread.c \
time.c \ time.c \
virtual.c \ virtual.c \
......
...@@ -55,8 +55,6 @@ ...@@ -55,8 +55,6 @@
#include "thread.h" #include "thread.h"
#include "wine/server.h" #include "wine/server.h"
#include "winbase.h" #include "winbase.h"
#include "wine/winbase16.h"
#include "wine/exception.h"
#include "wine/library.h" #include "wine/library.h"
#include "wine/debug.h" #include "wine/debug.h"
...@@ -101,27 +99,6 @@ void SYSDEPS_SetCurThread( TEB *teb ) ...@@ -101,27 +99,6 @@ void SYSDEPS_SetCurThread( TEB *teb )
/*********************************************************************** /***********************************************************************
* call_on_thread_stack
*
* Call a function once we switched to the thread stack.
*/
static void call_on_thread_stack( void *func )
{
__TRY
{
void (*funcptr)(void) = func;
funcptr();
}
__EXCEPT(UnhandledExceptionFilter)
{
TerminateThread( GetCurrentThread(), GetExceptionCode() );
}
__ENDTRY
SYSDEPS_ExitThread(0); /* should never get here */
}
/***********************************************************************
* get_temp_stack * get_temp_stack
* *
* Get a temporary stack address to run the thread exit code on. * Get a temporary stack address to run the thread exit code on.
...@@ -161,15 +138,7 @@ static void SYSDEPS_StartThread( TEB *teb ) ...@@ -161,15 +138,7 @@ static void SYSDEPS_StartThread( TEB *teb )
SYSDEPS_SetCurThread( teb ); SYSDEPS_SetCurThread( teb );
SIGNAL_Init(); SIGNAL_Init();
CLIENT_InitThread(); CLIENT_InitThread();
__TRY teb->startup();
{
teb->startup();
}
__EXCEPT(UnhandledExceptionFilter)
{
TerminateThread( GetCurrentThread(), GetExceptionCode() );
}
__ENDTRY
SYSDEPS_ExitThread(0); /* should never get here */ SYSDEPS_ExitThread(0); /* should never get here */
} }
...@@ -230,12 +199,15 @@ int SYSDEPS_SpawnThread( TEB *teb ) ...@@ -230,12 +199,15 @@ int SYSDEPS_SpawnThread( TEB *teb )
/*********************************************************************** /***********************************************************************
* SYSDEPS_CallOnStack * SYSDEPS_SwitchToThreadStack
*
* Switch to the stack specified in the current thread TEB
* and call the specified function.
*/ */
void DECLSPEC_NORETURN SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ); void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void *), void *arg );
#ifdef __i386__ #ifdef __i386__
# ifdef __GNUC__ # ifdef __GNUC__
__ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack, __ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
"movl 4(%esp),%ecx\n\t" /* func */ "movl 4(%esp),%ecx\n\t" /* func */
"movl 8(%esp),%edx\n\t" /* arg */ "movl 8(%esp),%edx\n\t" /* arg */
".byte 0x64\n\tmovl 0x04,%esp\n\t" /* teb->stack_top */ ".byte 0x64\n\tmovl 0x04,%esp\n\t" /* teb->stack_top */
...@@ -244,7 +216,7 @@ __ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack, ...@@ -244,7 +216,7 @@ __ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack,
"call *%ecx\n\t" "call *%ecx\n\t"
"int $3" /* we never return here */ ); "int $3" /* we never return here */ );
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
__declspec(naked) void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ) __declspec(naked) void SYSDEPS_SwitchToThreadStack( void (*func)(void *), void *arg )
{ {
__asm mov ecx, 4[esp]; __asm mov ecx, 4[esp];
__asm mov edx, 8[esp]; __asm mov edx, 8[esp];
...@@ -256,7 +228,7 @@ __declspec(naked) void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ) ...@@ -256,7 +228,7 @@ __declspec(naked) void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg )
} }
# endif /* defined(__GNUC__) || defined(_MSC_VER) */ # endif /* defined(__GNUC__) || defined(_MSC_VER) */
#elif defined(__sparc__) && defined(__GNUC__) #elif defined(__sparc__) && defined(__GNUC__)
__ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack, __ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
"mov %o0, %l0\n\t" /* store first argument */ "mov %o0, %l0\n\t" /* store first argument */
"call " __ASM_NAME("NtCurrentTeb") ", 0\n\t" "call " __ASM_NAME("NtCurrentTeb") ", 0\n\t"
"mov %o1, %l1\n\t" /* delay slot: store second argument */ "mov %o1, %l1\n\t" /* delay slot: store second argument */
...@@ -265,7 +237,7 @@ __ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack, ...@@ -265,7 +237,7 @@ __ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack,
"mov %l1, %o0\n\t" /* delay slot: arg for func */ "mov %l1, %o0\n\t" /* delay slot: arg for func */
"ta 0x01\n\t"); /* breakpoint - we never get here */ "ta 0x01\n\t"); /* breakpoint - we never get here */
#else /* !sparc, !i386 */ #else /* !sparc, !i386 */
void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ) void SYSDEPS_SwitchToThreadStack( void (*func)(void *), void *arg )
{ {
func( arg ); func( arg );
while(1); /* avoid warning */ while(1); /* avoid warning */
...@@ -274,15 +246,6 @@ void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ) ...@@ -274,15 +246,6 @@ void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg )
/*********************************************************************** /***********************************************************************
* SYSDEPS_SwitchToThreadStack
*/
void SYSDEPS_SwitchToThreadStack( void (*func)(void) )
{
SYSDEPS_CallOnStack( call_on_thread_stack, func );
}
/***********************************************************************
* SYSDEPS_ExitThread * SYSDEPS_ExitThread
* *
* Exit a running thread; must not return. * Exit a running thread; must not return.
...@@ -292,8 +255,10 @@ void SYSDEPS_ExitThread( int status ) ...@@ -292,8 +255,10 @@ void SYSDEPS_ExitThread( int status )
TEB *teb = NtCurrentTeb(); TEB *teb = NtCurrentTeb();
struct thread_cleanup_info info; struct thread_cleanup_info info;
MEMORY_BASIC_INFORMATION meminfo; MEMORY_BASIC_INFORMATION meminfo;
DWORD size = 0;
VirtualQuery( teb->stack_top, &meminfo, sizeof(meminfo) ); NtQueryVirtualMemory( GetCurrentProcess(), teb->stack_top, MemoryBasicInformation,
&meminfo, sizeof(meminfo), NULL );
info.stack_base = meminfo.AllocationBase; info.stack_base = meminfo.AllocationBase;
info.stack_size = meminfo.RegionSize + ((char *)teb->stack_top - (char *)meminfo.AllocationBase); info.stack_size = meminfo.RegionSize + ((char *)teb->stack_top - (char *)meminfo.AllocationBase);
info.status = status; info.status = status;
...@@ -304,14 +269,15 @@ void SYSDEPS_ExitThread( int status ) ...@@ -304,14 +269,15 @@ void SYSDEPS_ExitThread( int status )
SYSDEPS_AbortThread( status ); SYSDEPS_AbortThread( status );
#else #else
SIGNAL_Reset(); SIGNAL_Reset();
VirtualFree( teb->stack_base, 0, MEM_RELEASE | MEM_SYSTEM ); size = 0;
NtFreeVirtualMemory( GetCurrentProcess(), &teb->stack_base, &size, MEM_RELEASE | MEM_SYSTEM );
close( teb->wait_fd[0] ); close( teb->wait_fd[0] );
close( teb->wait_fd[1] ); close( teb->wait_fd[1] );
close( teb->reply_fd ); close( teb->reply_fd );
close( teb->request_fd ); close( teb->request_fd );
teb->stack_low = get_temp_stack(); teb->stack_low = get_temp_stack();
teb->stack_top = (char *) teb->stack_low + TEMP_STACK_SIZE; teb->stack_top = (char *) teb->stack_low + TEMP_STACK_SIZE;
SYSDEPS_CallOnStack( cleanup_thread, &info ); SYSDEPS_SwitchToThreadStack( cleanup_thread, &info );
#endif #endif
} }
......
...@@ -150,7 +150,7 @@ extern int SYSDEPS_GetUnixTid(void); ...@@ -150,7 +150,7 @@ extern int SYSDEPS_GetUnixTid(void);
extern void SYSDEPS_InitErrno(void); extern void SYSDEPS_InitErrno(void);
extern void DECLSPEC_NORETURN SYSDEPS_ExitThread( int status ); extern void DECLSPEC_NORETURN SYSDEPS_ExitThread( int status );
extern void DECLSPEC_NORETURN SYSDEPS_AbortThread( int status ); extern void DECLSPEC_NORETURN SYSDEPS_AbortThread( int status );
extern void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void) ); extern void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void *), void *arg );
/* signal handling */ /* signal handling */
extern BOOL SIGNAL_Init(void); extern BOOL SIGNAL_Init(void);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "winbase.h" #include "winbase.h"
#include "winerror.h" #include "winerror.h"
#include "wine/exception.h"
#include "thread.h" #include "thread.h"
struct fiber_data struct fiber_data
...@@ -41,14 +42,22 @@ struct fiber_data ...@@ -41,14 +42,22 @@ struct fiber_data
/* call the fiber initial function once we have switched stack */ /* call the fiber initial function once we have switched stack */
static void start_fiber(void) static void start_fiber( void *arg )
{ {
struct fiber_data *fiber = NtCurrentTeb()->fiber; struct fiber_data *fiber = arg;
LPFIBER_START_ROUTINE start = fiber->start; LPFIBER_START_ROUTINE start = fiber->start;
fiber->start = NULL; __TRY
start( fiber->param ); {
ExitThread( 1 ); fiber->start = NULL;
start( fiber->param );
ExitThread( 1 );
}
__EXCEPT(UnhandledExceptionFilter)
{
TerminateThread( GetCurrentThread(), GetExceptionCode() );
}
__ENDTRY
} }
...@@ -180,7 +189,7 @@ void WINAPI SwitchToFiber( LPVOID fiber ) ...@@ -180,7 +189,7 @@ void WINAPI SwitchToFiber( LPVOID fiber )
NtCurrentTeb()->stack_low = new_fiber->stack_low; NtCurrentTeb()->stack_low = new_fiber->stack_low;
NtCurrentTeb()->stack_base = new_fiber->stack_base; NtCurrentTeb()->stack_base = new_fiber->stack_base;
if (new_fiber->start) /* first time */ if (new_fiber->start) /* first time */
SYSDEPS_SwitchToThreadStack( start_fiber ); SYSDEPS_SwitchToThreadStack( start_fiber, new_fiber );
else else
longjmp( new_fiber->jmpbuf, 1 ); longjmp( new_fiber->jmpbuf, 1 );
} }
......
...@@ -232,8 +232,16 @@ static void THREAD_Start(void) ...@@ -232,8 +232,16 @@ static void THREAD_Start(void)
if (TRACE_ON(relay)) if (TRACE_ON(relay))
DPRINTF("%04lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func ); DPRINTF("%04lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func );
MODULE_DllThreadAttach( NULL ); __TRY
ExitThread( func( NtCurrentTeb()->entry_arg ) ); {
MODULE_DllThreadAttach( NULL );
ExitThread( func( NtCurrentTeb()->entry_arg ) );
}
__EXCEPT(UnhandledExceptionFilter)
{
TerminateThread( GetCurrentThread(), GetExceptionCode() );
}
__ENDTRY
} }
......
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