From dc4b0c76550f11026cb2fe60e3b1fe3af0ac4dda Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 24 Jun 2003 03:34:15 +0000 Subject: [PATCH] Moved tape.c to dlls/kernel. Moved critical section and resource update functions to dlls/kernel. Started moving some of the thread functions too. --- dlls/kernel/Makefile.in | 2 + dlls/kernel/resource.c | 78 +++++++++ dlls/kernel/sync.c | 162 ++++++++++++++++++ {files => dlls/kernel}/tape.c | 0 dlls/kernel/thread.c | 376 ++++++++++++++++++++++++++++++++++++++++++ dlls/ntdll/Makefile.in | 3 - scheduler/critsection.c | 195 ---------------------- scheduler/thread.c | 312 ----------------------------------- win32/kernel32.c | 110 ------------ 9 files changed, 618 insertions(+), 620 deletions(-) rename {files => dlls/kernel}/tape.c (100%) create mode 100644 dlls/kernel/thread.c delete mode 100644 scheduler/critsection.c delete mode 100644 win32/kernel32.c diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in index 8a26c2846c5..2636e276d4e 100644 --- a/dlls/kernel/Makefile.in +++ b/dlls/kernel/Makefile.in @@ -40,6 +40,8 @@ C_SRCS = \ stress.c \ string.c \ sync.c \ + tape.c \ + thread.c \ thunk.c \ time.c \ toolhelp.c \ diff --git a/dlls/kernel/resource.c b/dlls/kernel/resource.c index 29d5bd0b2fe..538958122aa 100644 --- a/dlls/kernel/resource.c +++ b/dlls/kernel/resource.c @@ -560,3 +560,81 @@ DWORD WINAPI SizeofResource( HINSTANCE hModule, HRSRC hRsrc ) if (!hRsrc) return 0; return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size; } + + +/*********************************************************************** + * BeginUpdateResourceA (KERNEL32.@) + */ +HANDLE WINAPI BeginUpdateResourceA( LPCSTR pFileName, BOOL bDeleteExistingResources ) +{ + FIXME("(%s,%d): stub\n",debugstr_a(pFileName),bDeleteExistingResources); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return 0; +} + + +/*********************************************************************** + * BeginUpdateResourceW (KERNEL32.@) + */ +HANDLE WINAPI BeginUpdateResourceW( LPCWSTR pFileName, BOOL bDeleteExistingResources ) +{ + FIXME("(%s,%d): stub\n",debugstr_w(pFileName),bDeleteExistingResources); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return 0; +} + + +/*********************************************************************** + * EndUpdateResourceA (KERNEL32.@) + */ +BOOL WINAPI EndUpdateResourceA( HANDLE hUpdate, BOOL fDiscard ) +{ + FIXME("(%p,%d): stub\n",hUpdate, fDiscard); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + + +/*********************************************************************** + * EndUpdateResourceW (KERNEL32.@) + */ +BOOL WINAPI EndUpdateResourceW( HANDLE hUpdate, BOOL fDiscard ) +{ + FIXME("(%p,%d): stub\n",hUpdate, fDiscard); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + + +/*********************************************************************** + * UpdateResourceA (KERNEL32.@) + */ +BOOL WINAPI UpdateResourceA( + HANDLE hUpdate, + LPCSTR lpType, + LPCSTR lpName, + WORD wLanguage, + LPVOID lpData, + DWORD cbData) +{ + FIXME(": stub\n"); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + + +/*********************************************************************** + * UpdateResourceW (KERNEL32.@) + */ +BOOL WINAPI UpdateResourceW( + HANDLE hUpdate, + LPCWSTR lpType, + LPCWSTR lpName, + WORD wLanguage, + LPVOID lpData, + DWORD cbData) +{ + FIXME(": stub\n"); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} diff --git a/dlls/kernel/sync.c b/dlls/kernel/sync.c index 3a6ac7a872f..2c5a3011d38 100644 --- a/dlls/kernel/sync.c +++ b/dlls/kernel/sync.c @@ -54,6 +54,69 @@ inline static int is_version_nt(void) /*********************************************************************** + * InitializeCriticalSection (KERNEL32.@) + */ +void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit ) +{ + NTSTATUS ret = RtlInitializeCriticalSection( crit ); + if (ret) RtlRaiseStatus( ret ); +} + +/*********************************************************************** + * InitializeCriticalSectionAndSpinCount (KERNEL32.@) + */ +BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount ) +{ + NTSTATUS ret = RtlInitializeCriticalSectionAndSpinCount( crit, spincount ); + if (ret) RtlRaiseStatus( ret ); + return !ret; +} + +/*********************************************************************** + * SetCriticalSectionSpinCount (KERNEL32.@) + * This function is available on NT4SP3 or later, but not Win98 + * It is SMP related + */ +DWORD WINAPI SetCriticalSectionSpinCount( CRITICAL_SECTION *crit, DWORD spincount ) +{ + ULONG_PTR oldspincount = crit->SpinCount; + if(spincount) FIXME("critsection=%p: spincount=%ld not supported\n", crit, spincount); + crit->SpinCount = spincount; + return oldspincount; +} + +/*********************************************************************** + * MakeCriticalSectionGlobal (KERNEL32.@) + */ +void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit ) +{ + /* let's assume that only one thread at a time will try to do this */ + HANDLE sem = crit->LockSemaphore; + if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 ); + crit->LockSemaphore = ConvertToGlobalHandle( sem ); +} + + +/*********************************************************************** + * ReinitializeCriticalSection (KERNEL32.@) + */ +void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit ) +{ + if ( !crit->LockSemaphore ) + RtlInitializeCriticalSection( crit ); +} + + +/*********************************************************************** + * UninitializeCriticalSection (KERNEL32.@) + */ +void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit ) +{ + RtlDeleteCriticalSection( crit ); +} + + +/*********************************************************************** * CreateEventA (KERNEL32.@) */ HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset, @@ -1105,3 +1168,102 @@ BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe, *hWritePipe = hw; return TRUE; } + + +#ifdef __i386__ + +/*********************************************************************** + * InterlockedCompareExchange (KERNEL32.@) + */ +/* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */ +__ASM_GLOBAL_FUNC(InterlockedCompareExchange, + "movl 12(%esp),%eax\n\t" + "movl 8(%esp),%ecx\n\t" + "movl 4(%esp),%edx\n\t" + "lock; cmpxchgl %ecx,(%edx)\n\t" + "ret $12"); + +/*********************************************************************** + * InterlockedExchange (KERNEL32.@) + */ +/* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */ +__ASM_GLOBAL_FUNC(InterlockedExchange, + "movl 8(%esp),%eax\n\t" + "movl 4(%esp),%edx\n\t" + "lock; xchgl %eax,(%edx)\n\t" + "ret $8"); + +/*********************************************************************** + * InterlockedExchangeAdd (KERNEL32.@) + */ +/* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */ +__ASM_GLOBAL_FUNC(InterlockedExchangeAdd, + "movl 8(%esp),%eax\n\t" + "movl 4(%esp),%edx\n\t" + "lock; xaddl %eax,(%edx)\n\t" + "ret $8"); + +/*********************************************************************** + * InterlockedIncrement (KERNEL32.@) + */ +/* LONG WINAPI InterlockedIncrement( PLONG dest ); */ +__ASM_GLOBAL_FUNC(InterlockedIncrement, + "movl 4(%esp),%edx\n\t" + "movl $1,%eax\n\t" + "lock; xaddl %eax,(%edx)\n\t" + "incl %eax\n\t" + "ret $4"); + +/*********************************************************************** + * InterlockedDecrement (KERNEL32.@) + */ +__ASM_GLOBAL_FUNC(InterlockedDecrement, + "movl 4(%esp),%edx\n\t" + "movl $-1,%eax\n\t" + "lock; xaddl %eax,(%edx)\n\t" + "decl %eax\n\t" + "ret $4"); + +#else /* __i386__ */ + +/*********************************************************************** + * InterlockedCompareExchange (KERNEL32.@) + */ +LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ) +{ + return interlocked_cmpxchg( dest, xchg, compare ); +} + +/*********************************************************************** + * InterlockedExchange (KERNEL32.@) + */ +LONG WINAPI InterlockedExchange( PLONG dest, LONG val ) +{ + return interlocked_xchg( dest, val ); +} + +/*********************************************************************** + * InterlockedExchangeAdd (KERNEL32.@) + */ +LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ) +{ + return interlocked_xchg_add( dest, incr ); +} + +/*********************************************************************** + * InterlockedIncrement (KERNEL32.@) + */ +LONG WINAPI InterlockedIncrement( PLONG dest ) +{ + return interlocked_xchg_add( dest, 1 ) + 1; +} + +/*********************************************************************** + * InterlockedDecrement (KERNEL32.@) + */ +LONG WINAPI InterlockedDecrement( PLONG dest ) +{ + return interlocked_xchg_add( dest, -1 ) - 1; +} + +#endif /* __i386__ */ diff --git a/files/tape.c b/dlls/kernel/tape.c similarity index 100% rename from files/tape.c rename to dlls/kernel/tape.c diff --git a/dlls/kernel/thread.c b/dlls/kernel/thread.c new file mode 100644 index 00000000000..bd1eb934cd8 --- /dev/null +++ b/dlls/kernel/thread.c @@ -0,0 +1,376 @@ +/* + * Win32 threads + * + * Copyright 1996 Alexandre Julliard + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" +#include "wine/port.h" + +#include +#include +#include +#ifdef HAVE_SYS_TIMES_H +#include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + +#include "winbase.h" +#include "winerror.h" +#include "winnls.h" +#include "thread.h" +#include "wine/server.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(thread); + + +/*********************************************************************** + * SetThreadContext [KERNEL32.@] Sets context of thread. + * + * RETURNS + * Success: TRUE + * Failure: FALSE + */ +BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ + const CONTEXT *context ) /* [in] Address of context structure */ +{ + NTSTATUS status = NtSetContextThread( handle, context ); + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; +} + + +/*********************************************************************** + * GetThreadContext [KERNEL32.@] Retrieves context of thread. + * + * RETURNS + * Success: TRUE + * Failure: FALSE + */ +BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ + CONTEXT *context ) /* [out] Address of context structure */ +{ + NTSTATUS status = NtGetContextThread( handle, context ); + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; +} + + +/********************************************************************** + * SuspendThread [KERNEL32.@] Suspends a thread. + * + * RETURNS + * Success: Previous suspend count + * Failure: 0xFFFFFFFF + */ +DWORD WINAPI SuspendThread( HANDLE hthread ) /* [in] Handle to the thread */ +{ + DWORD ret; + NTSTATUS status = NtSuspendThread( hthread, &ret ); + + if (status) + { + ret = ~0U; + SetLastError( RtlNtStatusToDosError(status) ); + } + return ret; +} + + +/********************************************************************** + * ResumeThread [KERNEL32.@] Resumes a thread. + * + * Decrements a thread's suspend count. When count is zero, the + * execution of the thread is resumed. + * + * RETURNS + * Success: Previous suspend count + * Failure: 0xFFFFFFFF + * Already running: 0 + */ +DWORD WINAPI ResumeThread( HANDLE hthread ) /* [in] Identifies thread to restart */ +{ + DWORD ret; + NTSTATUS status = NtResumeThread( hthread, &ret ); + + if (status) + { + ret = ~0U; + SetLastError( RtlNtStatusToDosError(status) ); + } + return ret; +} + + +/********************************************************************** + * GetThreadPriority [KERNEL32.@] Returns priority for thread. + * + * RETURNS + * Success: Thread's priority level. + * Failure: THREAD_PRIORITY_ERROR_RETURN + */ +INT WINAPI GetThreadPriority( + HANDLE hthread) /* [in] Handle to thread */ +{ + INT ret = THREAD_PRIORITY_ERROR_RETURN; + SERVER_START_REQ( get_thread_info ) + { + req->handle = hthread; + req->tid_in = 0; + if (!wine_server_call_err( req )) ret = reply->priority; + } + SERVER_END_REQ; + return ret; +} + + +/********************************************************************** + * SetThreadPriority [KERNEL32.@] Sets priority for thread. + * + * RETURNS + * Success: TRUE + * Failure: FALSE + */ +BOOL WINAPI SetThreadPriority( + HANDLE hthread, /* [in] Handle to thread */ + INT priority) /* [in] Thread priority level */ +{ + BOOL ret; + SERVER_START_REQ( set_thread_info ) + { + req->handle = hthread; + req->priority = priority; + req->mask = SET_THREAD_INFO_PRIORITY; + ret = !wine_server_call_err( req ); + } + SERVER_END_REQ; + return ret; +} + + +/********************************************************************** + * GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread. + * + * Always reports that priority boost is disabled. + * + * RETURNS + * Success: TRUE. + * Failure: FALSE + */ +BOOL WINAPI GetThreadPriorityBoost( + HANDLE hthread, /* [in] Handle to thread */ + PBOOL pstate) /* [out] pointer to var that receives the boost state */ +{ + if (pstate) *pstate = FALSE; + return NO_ERROR; +} + + +/********************************************************************** + * SetThreadPriorityBoost [KERNEL32.@] Sets priority boost for thread. + * + * Priority boost is not implemented. Thsi function always returns + * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED + * + * RETURNS + * Always returns FALSE to indicate a failure + */ +BOOL WINAPI SetThreadPriorityBoost( + HANDLE hthread, /* [in] Handle to thread */ + BOOL disable) /* [in] TRUE to disable priority boost */ +{ + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return FALSE; +} + + +/********************************************************************** + * SetThreadAffinityMask (KERNEL32.@) + */ +DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) +{ + DWORD ret; + SERVER_START_REQ( set_thread_info ) + { + req->handle = hThread; + req->affinity = dwThreadAffinityMask; + req->mask = SET_THREAD_INFO_AFFINITY; + ret = !wine_server_call_err( req ); + /* FIXME: should return previous value */ + } + SERVER_END_REQ; + return ret; +} + + +/********************************************************************** + * SetThreadIdealProcessor [KERNEL32.@] Obtains timing information. + * + * RETURNS + * Success: Value of last call to SetThreadIdealProcessor + * Failure: -1 + */ +DWORD WINAPI SetThreadIdealProcessor( + HANDLE hThread, /* [in] Specifies the thread of interest */ + DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */ +{ + FIXME("(%p): stub\n",hThread); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return -1L; +} + + +/*********************************************************************** + * SetThreadExecutionState (KERNEL32.@) + * + * Informs the system that activity is taking place for + * power management purposes. + */ +EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags) +{ + static EXECUTION_STATE current = + ES_SYSTEM_REQUIRED|ES_DISPLAY_REQUIRED|ES_USER_PRESENT; + EXECUTION_STATE old = current; + + if (!(current & ES_CONTINUOUS) || (flags & ES_CONTINUOUS)) + current = flags; + FIXME("(0x%lx): stub, harmless (power management).\n", flags); + return old; +} + + +/* callback for QueueUserAPC */ +static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) +{ + PAPCFUNC func = (PAPCFUNC)arg1; + func( arg2 ); +} + +/*********************************************************************** + * QueueUserAPC (KERNEL32.@) + */ +DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data ) +{ + NTSTATUS status = NtQueueApcThread( hthread, call_user_apc, (ULONG_PTR)func, data, 0 ); + + if (status) SetLastError( RtlNtStatusToDosError(status) ); + return !status; +} + + +/********************************************************************** + * GetThreadTimes [KERNEL32.@] Obtains timing information. + * + * RETURNS + * Success: TRUE + * Failure: FALSE + */ +BOOL WINAPI GetThreadTimes( + HANDLE thread, /* [in] Specifies the thread of interest */ + LPFILETIME creationtime, /* [out] When the thread was created */ + LPFILETIME exittime, /* [out] When the thread was destroyed */ + LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */ + LPFILETIME usertime) /* [out] Time thread spent in user mode */ +{ + BOOL ret = TRUE; + + if (creationtime || exittime) + { + /* We need to do a server call to get the creation time or exit time */ + /* This works on any thread */ + + SERVER_START_REQ( get_thread_info ) + { + req->handle = thread; + req->tid_in = 0; + if ((ret = !wine_server_call_err( req ))) + { + if (creationtime) + RtlSecondsSince1970ToTime( reply->creation_time, (LARGE_INTEGER*)creationtime ); + if (exittime) + RtlSecondsSince1970ToTime( reply->exit_time, (LARGE_INTEGER*)exittime ); + } + } + SERVER_END_REQ; + } + if (ret && (kerneltime || usertime)) + { + /* We call times(2) for kernel time or user time */ + /* We can only (portably) do this for the current thread */ + if (thread == GetCurrentThread()) + { + ULONGLONG time; + struct tms time_buf; + long clocks_per_sec = sysconf(_SC_CLK_TCK); + + times(&time_buf); + if (kerneltime) + { + time = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec; + kerneltime->dwHighDateTime = time >> 32; + kerneltime->dwLowDateTime = (DWORD)time; + } + if (usertime) + { + time = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec; + usertime->dwHighDateTime = time >> 32; + usertime->dwLowDateTime = (DWORD)time; + } + } + else + { + if (kerneltime) kerneltime->dwHighDateTime = kerneltime->dwLowDateTime = 0; + if (usertime) usertime->dwHighDateTime = usertime->dwLowDateTime = 0; + FIXME("Cannot get kerneltime or usertime of other threads\n"); + } + } + return ret; +} + + +/********************************************************************** + * VWin32_BoostThreadGroup [KERNEL.535] + */ +VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost ) +{ + FIXME("(0x%08lx,%d): stub\n", threadId, boost); +} + + +/********************************************************************** + * VWin32_BoostThreadStatic [KERNEL.536] + */ +VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost ) +{ + FIXME("(0x%08lx,%d): stub\n", threadId, boost); +} + + +/*********************************************************************** + * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread + * + * RETURNS + * Pseudohandle for the current thread + */ +#undef GetCurrentThread +HANDLE WINAPI GetCurrentThread(void) +{ + return (HANDLE)0xfffffffe; +} diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index 5992d8eefab..b0b1d13894d 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -13,7 +13,6 @@ C_SRCS = \ $(TOPOBJDIR)/files/file.c \ $(TOPOBJDIR)/files/profile.c \ $(TOPOBJDIR)/files/smb.c \ - $(TOPOBJDIR)/files/tape.c \ $(TOPOBJDIR)/if1632/builtin.c \ $(TOPOBJDIR)/if1632/relay.c \ $(TOPOBJDIR)/if1632/snoop.c \ @@ -45,7 +44,6 @@ C_SRCS = \ $(TOPOBJDIR)/relay32/relay386.c \ $(TOPOBJDIR)/relay32/snoop.c \ $(TOPOBJDIR)/scheduler/client.c \ - $(TOPOBJDIR)/scheduler/critsection.c \ $(TOPOBJDIR)/scheduler/fiber.c \ $(TOPOBJDIR)/scheduler/handle.c \ $(TOPOBJDIR)/scheduler/process.c \ @@ -56,7 +54,6 @@ C_SRCS = \ $(TOPOBJDIR)/scheduler/thread.c \ $(TOPOBJDIR)/win32/device.c \ $(TOPOBJDIR)/win32/except.c \ - $(TOPOBJDIR)/win32/kernel32.c \ $(TOPOBJDIR)/win32/newfns.c \ cdrom.c \ critsection.c \ diff --git a/scheduler/critsection.c b/scheduler/critsection.c deleted file mode 100644 index 8fca8d4148e..00000000000 --- a/scheduler/critsection.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Win32 critical sections - * - * Copyright 1998 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#include - -#include "winerror.h" -#include "winbase.h" -#include "winternl.h" -#include "wine/debug.h" -#include "thread.h" - -WINE_DEFAULT_DEBUG_CHANNEL(win32); -WINE_DECLARE_DEBUG_CHANNEL(relay); - -/*********************************************************************** - * InitializeCriticalSection (KERNEL32.@) - */ -void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit ) -{ - NTSTATUS ret = RtlInitializeCriticalSection( crit ); - if (ret) RtlRaiseStatus( ret ); -} - -/*********************************************************************** - * InitializeCriticalSectionAndSpinCount (KERNEL32.@) - */ -BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount ) -{ - NTSTATUS ret = RtlInitializeCriticalSectionAndSpinCount( crit, spincount ); - if (ret) RtlRaiseStatus( ret ); - return !ret; -} - -/*********************************************************************** - * SetCriticalSectionSpinCount (KERNEL32.@) - * This function is available on NT4SP3 or later, but not Win98 - * It is SMP related - */ -DWORD WINAPI SetCriticalSectionSpinCount( CRITICAL_SECTION *crit, DWORD spincount ) -{ - ULONG_PTR oldspincount = crit->SpinCount; - if(spincount) FIXME("critsection=%p: spincount=%ld not supported\n", crit, spincount); - crit->SpinCount = spincount; - return oldspincount; -} - -/*********************************************************************** - * MakeCriticalSectionGlobal (KERNEL32.@) - */ -void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit ) -{ - /* let's assume that only one thread at a time will try to do this */ - HANDLE sem = crit->LockSemaphore; - if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 ); - crit->LockSemaphore = ConvertToGlobalHandle( sem ); -} - - -/*********************************************************************** - * ReinitializeCriticalSection (KERNEL32.@) - */ -void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit ) -{ - if ( !crit->LockSemaphore ) - RtlInitializeCriticalSection( crit ); -} - - -/*********************************************************************** - * UninitializeCriticalSection (KERNEL32.@) - */ -void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit ) -{ - RtlDeleteCriticalSection( crit ); -} - -#ifdef __i386__ - -/*********************************************************************** - * InterlockedCompareExchange (KERNEL32.@) - */ -/* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */ -__ASM_GLOBAL_FUNC(InterlockedCompareExchange, - "movl 12(%esp),%eax\n\t" - "movl 8(%esp),%ecx\n\t" - "movl 4(%esp),%edx\n\t" - "lock; cmpxchgl %ecx,(%edx)\n\t" - "ret $12"); - -/*********************************************************************** - * InterlockedExchange (KERNEL32.@) - */ -/* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */ -__ASM_GLOBAL_FUNC(InterlockedExchange, - "movl 8(%esp),%eax\n\t" - "movl 4(%esp),%edx\n\t" - "lock; xchgl %eax,(%edx)\n\t" - "ret $8"); - -/*********************************************************************** - * InterlockedExchangeAdd (KERNEL32.@) - */ -/* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */ -__ASM_GLOBAL_FUNC(InterlockedExchangeAdd, - "movl 8(%esp),%eax\n\t" - "movl 4(%esp),%edx\n\t" - "lock; xaddl %eax,(%edx)\n\t" - "ret $8"); - -/*********************************************************************** - * InterlockedIncrement (KERNEL32.@) - */ -/* LONG WINAPI InterlockedIncrement( PLONG dest ); */ -__ASM_GLOBAL_FUNC(InterlockedIncrement, - "movl 4(%esp),%edx\n\t" - "movl $1,%eax\n\t" - "lock; xaddl %eax,(%edx)\n\t" - "incl %eax\n\t" - "ret $4"); - -/*********************************************************************** - * InterlockedDecrement (KERNEL32.@) - */ -__ASM_GLOBAL_FUNC(InterlockedDecrement, - "movl 4(%esp),%edx\n\t" - "movl $-1,%eax\n\t" - "lock; xaddl %eax,(%edx)\n\t" - "decl %eax\n\t" - "ret $4"); - -#else /* __i386__ */ - -/*********************************************************************** - * InterlockedCompareExchange (KERNEL32.@) - */ -LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ) -{ - return interlocked_cmpxchg( dest, xchg, compare ); -} - -/*********************************************************************** - * InterlockedExchange (KERNEL32.@) - */ -LONG WINAPI InterlockedExchange( PLONG dest, LONG val ) -{ - return interlocked_xchg( dest, val ); -} - -/*********************************************************************** - * InterlockedExchangeAdd (KERNEL32.@) - */ -LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ) -{ - return interlocked_xchg_add( dest, incr ); -} - -/*********************************************************************** - * InterlockedIncrement (KERNEL32.@) - */ -LONG WINAPI InterlockedIncrement( PLONG dest ) -{ - return interlocked_xchg_add( dest, 1 ) + 1; -} - -/*********************************************************************** - * InterlockedDecrement (KERNEL32.@) - */ -LONG WINAPI InterlockedDecrement( PLONG dest ) -{ - return interlocked_xchg_add( dest, -1 ) - 1; -} - -#endif /* __i386__ */ diff --git a/scheduler/thread.c b/scheduler/thread.c index 24792f94237..e2854651d4c 100644 --- a/scheduler/thread.c +++ b/scheduler/thread.c @@ -348,154 +348,6 @@ HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwTh return ret; } -/*********************************************************************** - * SetThreadContext [KERNEL32.@] Sets context of thread. - * - * RETURNS - * Success: TRUE - * Failure: FALSE - */ -BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ - const CONTEXT *context ) /* [in] Address of context structure */ -{ - NTSTATUS status = NtSetContextThread( handle, context ); - if (status) SetLastError( RtlNtStatusToDosError(status) ); - return !status; -} - - -/*********************************************************************** - * GetThreadContext [KERNEL32.@] Retrieves context of thread. - * - * RETURNS - * Success: TRUE - * Failure: FALSE - */ -BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */ - CONTEXT *context ) /* [out] Address of context structure */ -{ - NTSTATUS status = NtGetContextThread( handle, context ); - if (status) SetLastError( RtlNtStatusToDosError(status) ); - return !status; -} - - -/********************************************************************** - * GetThreadPriority [KERNEL32.@] Returns priority for thread. - * - * RETURNS - * Success: Thread's priority level. - * Failure: THREAD_PRIORITY_ERROR_RETURN - */ -INT WINAPI GetThreadPriority( - HANDLE hthread) /* [in] Handle to thread */ -{ - INT ret = THREAD_PRIORITY_ERROR_RETURN; - SERVER_START_REQ( get_thread_info ) - { - req->handle = hthread; - req->tid_in = 0; - if (!wine_server_call_err( req )) ret = reply->priority; - } - SERVER_END_REQ; - return ret; -} - - -/********************************************************************** - * SetThreadPriority [KERNEL32.@] Sets priority for thread. - * - * RETURNS - * Success: TRUE - * Failure: FALSE - */ -BOOL WINAPI SetThreadPriority( - HANDLE hthread, /* [in] Handle to thread */ - INT priority) /* [in] Thread priority level */ -{ - BOOL ret; - SERVER_START_REQ( set_thread_info ) - { - req->handle = hthread; - req->priority = priority; - req->mask = SET_THREAD_INFO_PRIORITY; - ret = !wine_server_call_err( req ); - } - SERVER_END_REQ; - return ret; -} - - -/********************************************************************** - * GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread. - * - * Always reports that priority boost is disabled. - * - * RETURNS - * Success: TRUE. - * Failure: FALSE - */ -BOOL WINAPI GetThreadPriorityBoost( - HANDLE hthread, /* [in] Handle to thread */ - PBOOL pstate) /* [out] pointer to var that receives the boost state */ -{ - if (pstate) *pstate = FALSE; - return NO_ERROR; -} - - -/********************************************************************** - * SetThreadPriorityBoost [KERNEL32.@] Sets priority boost for thread. - * - * Priority boost is not implemented. Thsi function always returns - * FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED - * - * RETURNS - * Always returns FALSE to indicate a failure - */ -BOOL WINAPI SetThreadPriorityBoost( - HANDLE hthread, /* [in] Handle to thread */ - BOOL disable) /* [in] TRUE to disable priority boost */ -{ - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - - -/********************************************************************** - * SetThreadAffinityMask (KERNEL32.@) - */ -DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask ) -{ - DWORD ret; - SERVER_START_REQ( set_thread_info ) - { - req->handle = hThread; - req->affinity = dwThreadAffinityMask; - req->mask = SET_THREAD_INFO_AFFINITY; - ret = !wine_server_call_err( req ); - /* FIXME: should return previous value */ - } - SERVER_END_REQ; - return ret; -} - -/********************************************************************** - * SetThreadIdealProcessor [KERNEL32.@] Obtains timing information. - * - * RETURNS - * Success: Value of last call to SetThreadIdealProcessor - * Failure: -1 - */ -DWORD WINAPI SetThreadIdealProcessor( - HANDLE hThread, /* [in] Specifies the thread of interest */ - DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */ -{ - FIXME("(%p): stub\n",hThread); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return -1L; -} - /********************************************************************** * TerminateThread [KERNEL32.@] Terminates a thread * @@ -538,52 +390,6 @@ BOOL WINAPI GetExitCodeThread( } -/********************************************************************** - * ResumeThread [KERNEL32.@] Resumes a thread. - * - * Decrements a thread's suspend count. When count is zero, the - * execution of the thread is resumed. - * - * RETURNS - * Success: Previous suspend count - * Failure: 0xFFFFFFFF - * Already running: 0 - */ -DWORD WINAPI ResumeThread( HANDLE hthread ) /* [in] Identifies thread to restart */ -{ - DWORD ret; - NTSTATUS status = NtResumeThread( hthread, &ret ); - - if (status) - { - ret = ~0U; - SetLastError( RtlNtStatusToDosError(status) ); - } - return ret; -} - - -/********************************************************************** - * SuspendThread [KERNEL32.@] Suspends a thread. - * - * RETURNS - * Success: Previous suspend count - * Failure: 0xFFFFFFFF - */ -DWORD WINAPI SuspendThread( HANDLE hthread ) /* [in] Handle to the thread */ -{ - DWORD ret; - NTSTATUS status = NtSuspendThread( hthread, &ret ); - - if (status) - { - ret = ~0U; - SetLastError( RtlNtStatusToDosError(status) ); - } - return ret; -} - - /* callback for QueueUserAPC */ static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 ) { @@ -603,106 +409,6 @@ DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data ) } -/********************************************************************** - * GetThreadTimes [KERNEL32.@] Obtains timing information. - * - * RETURNS - * Success: TRUE - * Failure: FALSE - */ -BOOL WINAPI GetThreadTimes( - HANDLE thread, /* [in] Specifies the thread of interest */ - LPFILETIME creationtime, /* [out] When the thread was created */ - LPFILETIME exittime, /* [out] When the thread was destroyed */ - LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */ - LPFILETIME usertime) /* [out] Time thread spent in user mode */ -{ - BOOL ret = TRUE; - - if (creationtime || exittime) - { - /* We need to do a server call to get the creation time or exit time */ - /* This works on any thread */ - - SERVER_START_REQ( get_thread_info ) - { - req->handle = thread; - req->tid_in = 0; - if ((ret = !wine_server_call_err( req ))) - { - if (creationtime) - RtlSecondsSince1970ToTime( reply->creation_time, (LARGE_INTEGER*)creationtime ); - if (exittime) - RtlSecondsSince1970ToTime( reply->exit_time, (LARGE_INTEGER*)exittime ); - } - } - SERVER_END_REQ; - } - if (ret && (kerneltime || usertime)) - { - /* We call times(2) for kernel time or user time */ - /* We can only (portably) do this for the current thread */ - if (thread == GetCurrentThread()) - { - ULONGLONG time; - struct tms time_buf; - long clocks_per_sec = sysconf(_SC_CLK_TCK); - - times(&time_buf); - if (kerneltime) - { - time = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec; - kerneltime->dwHighDateTime = time >> 32; - kerneltime->dwLowDateTime = (DWORD)time; - } - if (usertime) - { - time = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec; - usertime->dwHighDateTime = time >> 32; - usertime->dwLowDateTime = (DWORD)time; - } - } - else - { - if (kerneltime) kerneltime->dwHighDateTime = kerneltime->dwLowDateTime = 0; - if (usertime) usertime->dwHighDateTime = usertime->dwLowDateTime = 0; - FIXME("Cannot get kerneltime or usertime of other threads\n"); - } - } - return ret; -} - - -/********************************************************************** - * VWin32_BoostThreadGroup [KERNEL.535] - */ -VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost ) -{ - FIXME("(0x%08lx,%d): stub\n", threadId, boost); -} - -/********************************************************************** - * VWin32_BoostThreadStatic [KERNEL.536] - */ -VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost ) -{ - FIXME("(0x%08lx,%d): stub\n", threadId, boost); -} - - -/*********************************************************************** - * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread - * - * RETURNS - * Pseudohandle for the current thread - */ -#undef GetCurrentThread -HANDLE WINAPI GetCurrentThread(void) -{ - return (HANDLE)0xfffffffe; -} - - /*********************************************************************** * ProcessIdToSessionId (KERNEL32.@) * This function is available on Terminal Server 4SP4 and Windows 2000 @@ -716,24 +422,6 @@ BOOL WINAPI ProcessIdToSessionId( DWORD procid, DWORD *sessionid_ptr ) return TRUE; } -/*********************************************************************** - * SetThreadExecutionState (KERNEL32.@) - * - * Informs the system that activity is taking place for - * power management purposes. - */ -EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags) -{ - static EXECUTION_STATE current = - ES_SYSTEM_REQUIRED|ES_DISPLAY_REQUIRED|ES_USER_PRESENT; - EXECUTION_STATE old = current; - - if (!(current & ES_CONTINUOUS) || (flags & ES_CONTINUOUS)) - current = flags; - FIXME("(0x%lx): stub, harmless (power management).\n", flags); - return old; -} - #ifdef __i386__ diff --git a/win32/kernel32.c b/win32/kernel32.c deleted file mode 100644 index 64788194942..00000000000 --- a/win32/kernel32.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * KERNEL32 thunks and other undocumented stuff - * - * Copyright 1997-1998 Marcus Meissner - * Copyright 1998 Ulrich Weigand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "windef.h" -#include "winbase.h" -#include "wine/winbase16.h" -#include "winerror.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(win32); - -/*********************************************************************** - * BeginUpdateResourceA (KERNEL32.@) - */ -HANDLE WINAPI BeginUpdateResourceA( LPCSTR pFileName, BOOL bDeleteExistingResources ) -{ - FIXME("(%s,%d): stub\n",debugstr_a(pFileName),bDeleteExistingResources); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} - -/*********************************************************************** - * BeginUpdateResourceW (KERNEL32.@) - */ -HANDLE WINAPI BeginUpdateResourceW( LPCWSTR pFileName, BOOL bDeleteExistingResources ) -{ - - FIXME("(%s,%d): stub\n",debugstr_w(pFileName),bDeleteExistingResources); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} - -/*********************************************************************** - * EndUpdateResourceA (KERNEL32.@) - */ -BOOL WINAPI EndUpdateResourceA( HANDLE hUpdate, BOOL fDiscard ) -{ - - FIXME("(%p,%d): stub\n",hUpdate, fDiscard); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - -/*********************************************************************** - * EndUpdateResourceW (KERNEL32.@) - */ -BOOL WINAPI EndUpdateResourceW( HANDLE hUpdate, BOOL fDiscard ) -{ - FIXME("(%p,%d): stub\n",hUpdate, fDiscard); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - -/*********************************************************************** - * UpdateResourceA (KERNEL32.@) - */ -BOOL WINAPI UpdateResourceA( - HANDLE hUpdate, - LPCSTR lpType, - LPCSTR lpName, - WORD wLanguage, - LPVOID lpData, - DWORD cbData) { - - FIXME(": stub\n"); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} - -/*********************************************************************** - * UpdateResourceW (KERNEL32.@) - */ -BOOL WINAPI UpdateResourceW( - HANDLE hUpdate, - LPCWSTR lpType, - LPCWSTR lpName, - WORD wLanguage, - LPVOID lpData, - DWORD cbData) { - - FIXME(": stub\n"); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; -} -- 2.11.4.GIT