Commit aa58676a authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Move wait functions to kernelbase.

parent bc28ed4c
......@@ -1251,7 +1251,7 @@
@ stub RegisterSysMsgHandler
@ stub RegisterWaitForInputIdle
@ stdcall RegisterWaitForSingleObject(ptr long ptr ptr long long)
@ stdcall RegisterWaitForSingleObjectEx(long ptr ptr long long)
@ stdcall -import RegisterWaitForSingleObjectEx(long ptr ptr long long)
@ stub RegisterWowBaseHandlers
@ stub RegisterWowExec
@ stdcall ReinitializeCriticalSection(ptr)
......@@ -1479,12 +1479,12 @@
# @ stub SetXStateFeaturesMask
@ stdcall SetupComm(long long long)
@ stub ShowConsoleCursor
@ stdcall SignalObjectAndWait(long long long long)
@ stdcall -import SignalObjectAndWait(long long long long)
@ stdcall SizeofResource(long long)
@ stdcall Sleep(long)
@ stdcall -import Sleep(long)
@ stdcall -import SleepConditionVariableCS(ptr ptr long)
@ stdcall -import SleepConditionVariableSRW(ptr ptr long long)
@ stdcall SleepEx(long long)
@ stdcall -import SleepEx(long long)
# @ stub SortCloseHandle
# @ stub SortGetHandle
# @ stub StartThreadpoolIo
......@@ -1541,7 +1541,7 @@
@ stdcall UnregisterApplicationRestart()
# @ stub UnregisterConsoleIME
@ stdcall UnregisterWait(long)
@ stdcall UnregisterWaitEx(long long)
@ stdcall -import UnregisterWaitEx(long long)
# @ stub UpdateCalendarDayOfWeek
@ stdcall UpdateProcThreadAttribute(ptr long long ptr long ptr ptr)
@ stdcall UpdateResourceA(long str str long ptr long)
......@@ -1572,10 +1572,10 @@
@ stdcall WTSGetActiveConsoleSessionId()
@ stdcall WaitCommEvent(long ptr ptr)
@ stdcall WaitForDebugEvent(ptr long)
@ stdcall WaitForMultipleObjects(long ptr long long)
@ stdcall WaitForMultipleObjectsEx(long ptr long long long)
@ stdcall WaitForSingleObject(long long)
@ stdcall WaitForSingleObjectEx(long long long)
@ stdcall -import WaitForMultipleObjects(long ptr long long)
@ stdcall -import WaitForMultipleObjectsEx(long ptr long long long)
@ stdcall -import WaitForSingleObject(long long)
@ stdcall -import WaitForSingleObjectEx(long long long)
# @ stub WaitForThreadpoolIoCallbacks
@ stdcall WaitForThreadpoolTimerCallbacks(ptr long) ntdll.TpWaitForTimer
@ stdcall WaitForThreadpoolWaitCallbacks(ptr long) ntdll.TpWaitForWait
......
......@@ -24,11 +24,6 @@
#include "wine/server.h"
NTSTATUS WINAPI BaseGetNamedObjectDirectory( HANDLE *dir );
HANDLE WINAPI OpenConsoleW(LPCWSTR, DWORD, BOOL, DWORD);
BOOL WINAPI VerifyConsoleIoHandle(HANDLE);
HANDLE WINAPI DuplicateConsoleHandle(HANDLE, DWORD, BOOL, DWORD);
BOOL WINAPI CloseConsoleHandle(HANDLE handle);
HANDLE WINAPI GetConsoleInputWaitHandle(void);
BOOL CONSOLE_Init(RTL_USER_PROCESS_PARAMETERS *params) DECLSPEC_HIDDEN;
BOOL CONSOLE_Exit(void) DECLSPEC_HIDDEN;
......
......@@ -55,6 +55,8 @@
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "winternl.h"
#include "winbase.h"
#include "wincon.h"
#include "kernel_private.h"
#include "psapi.h"
#include "wine/exception.h"
......
......@@ -34,6 +34,7 @@
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "wincon.h"
#include "winerror.h"
#include "winnls.h"
#include "winternl.h"
......@@ -97,28 +98,6 @@ static inline PLARGE_INTEGER get_nt_timeout( PLARGE_INTEGER pTime, DWORD timeout
}
/***********************************************************************
* Sleep (KERNEL32.@)
*/
VOID WINAPI DECLSPEC_HOTPATCH Sleep( DWORD timeout )
{
SleepEx( timeout, FALSE );
}
/******************************************************************************
* SleepEx (KERNEL32.@)
*/
DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
{
NTSTATUS status;
LARGE_INTEGER time;
status = NtDelayExecution( alertable, get_nt_timeout( &time, timeout ) );
if (status == STATUS_USER_APC) return WAIT_IO_COMPLETION;
return 0;
}
/***********************************************************************
* SwitchToThread (KERNEL32.@)
*/
BOOL WINAPI SwitchToThread(void)
......@@ -127,34 +106,6 @@ BOOL WINAPI SwitchToThread(void)
}
/***********************************************************************
* WaitForSingleObject (KERNEL32.@)
*/
DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
{
return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
}
/***********************************************************************
* WaitForSingleObjectEx (KERNEL32.@)
*/
DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
BOOL alertable )
{
return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
}
/***********************************************************************
* WaitForMultipleObjects (KERNEL32.@)
*/
DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
BOOL wait_all, DWORD timeout )
{
return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
}
static HANDLE normalize_handle_if_console(HANDLE handle)
{
if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
......@@ -174,38 +125,6 @@ static HANDLE normalize_handle_if_console(HANDLE handle)
}
/***********************************************************************
* WaitForMultipleObjectsEx (KERNEL32.@)
*/
DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
BOOL wait_all, DWORD timeout,
BOOL alertable )
{
NTSTATUS status;
HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
LARGE_INTEGER time;
unsigned int i;
if (count > MAXIMUM_WAIT_OBJECTS)
{
SetLastError(ERROR_INVALID_PARAMETER);
return WAIT_FAILED;
}
for (i = 0; i < count; i++)
hloc[i] = normalize_handle_if_console(handles[i]);
status = NtWaitForMultipleObjects( count, hloc, !wait_all, alertable,
get_nt_timeout( &time, timeout ) );
if (HIWORD(status)) /* is it an error code? */
{
SetLastError( RtlNtStatusToDosError(status) );
status = WAIT_FAILED;
}
return status;
}
/***********************************************************************
* RegisterWaitForSingleObject (KERNEL32.@)
*/
BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject,
......@@ -228,29 +147,6 @@ BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject,
}
/***********************************************************************
* RegisterWaitForSingleObjectEx (KERNEL32.@)
*/
HANDLE WINAPI RegisterWaitForSingleObjectEx( HANDLE hObject,
WAITORTIMERCALLBACK Callback, PVOID Context,
ULONG dwMilliseconds, ULONG dwFlags )
{
NTSTATUS status;
HANDLE hNewWaitObject;
TRACE("%p %p %p %d %d\n",
hObject,Callback,Context,dwMilliseconds,dwFlags);
hObject = normalize_handle_if_console(hObject);
status = RtlRegisterWait( &hNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return NULL;
}
return hNewWaitObject;
}
/***********************************************************************
* UnregisterWait (KERNEL32.@)
*/
BOOL WINAPI UnregisterWait( HANDLE WaitHandle )
......@@ -269,45 +165,6 @@ BOOL WINAPI UnregisterWait( HANDLE WaitHandle )
}
/***********************************************************************
* UnregisterWaitEx (KERNEL32.@)
*/
BOOL WINAPI UnregisterWaitEx( HANDLE WaitHandle, HANDLE CompletionEvent )
{
NTSTATUS status;
TRACE("%p %p\n",WaitHandle, CompletionEvent);
status = RtlDeregisterWaitEx( WaitHandle, CompletionEvent );
if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* SignalObjectAndWait (KERNEL32.@)
*
* Makes it possible to atomically signal any of the synchronization
* objects (semaphore, mutex, event) and wait on another.
*/
DWORD WINAPI SignalObjectAndWait( HANDLE hObjectToSignal, HANDLE hObjectToWaitOn,
DWORD dwMilliseconds, BOOL bAlertable )
{
NTSTATUS status;
LARGE_INTEGER timeout;
TRACE("%p %p %d %d\n", hObjectToSignal,
hObjectToWaitOn, dwMilliseconds, bAlertable);
status = NtSignalAndWaitForSingleObject( hObjectToSignal, hObjectToWaitOn, bAlertable,
get_nt_timeout( &timeout, dwMilliseconds ) );
if (HIWORD(status))
{
SetLastError( RtlNtStatusToDosError(status) );
status = WAIT_FAILED;
}
return status;
}
/***********************************************************************
* MakeCriticalSectionGlobal (KERNEL32.@)
*/
void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit )
......
......@@ -24,6 +24,11 @@
#include "windef.h"
#include "winbase.h"
static inline BOOL is_console_handle(HANDLE h)
{
return h != INVALID_HANDLE_VALUE && ((UINT_PTR)h & 3) == 3;
}
static inline BOOL set_ntstatus( NTSTATUS status )
{
if (status) SetLastError( RtlNtStatusToDosError( status ));
......
......@@ -1322,7 +1322,7 @@
# @ stub RegisterStateChangeNotification
# @ stub RegisterStateLock
@ stdcall RegisterTraceGuidsW(ptr ptr ptr long ptr wstr wstr ptr) ntdll.EtwRegisterTraceGuidsW
@ stdcall RegisterWaitForSingleObjectEx(long ptr ptr long long) kernel32.RegisterWaitForSingleObjectEx
@ stdcall RegisterWaitForSingleObjectEx(long ptr ptr long long)
@ stdcall ReleaseActCtx(ptr) kernel32.ReleaseActCtx
@ stdcall ReleaseMutex(long)
@ stdcall ReleaseMutexWhenCallbackReturns(ptr long) kernel32.ReleaseMutexWhenCallbackReturns
......@@ -1509,12 +1509,12 @@
# @ stub SetXStateFeaturesMask
@ stdcall SetupComm(long long long) kernel32.SetupComm
# @ stub SharedLocalIsEnabled
@ stdcall SignalObjectAndWait(long long long long) kernel32.SignalObjectAndWait
@ stdcall SignalObjectAndWait(long long long long)
@ stdcall SizeofResource(long long) kernel32.SizeofResource
@ stdcall Sleep(long) kernel32.Sleep
@ stdcall Sleep(long)
@ stdcall SleepConditionVariableCS(ptr ptr long)
@ stdcall SleepConditionVariableSRW(ptr ptr long long)
@ stdcall SleepEx(long long) kernel32.SleepEx
@ stdcall SleepEx(long long)
@ stub SpecialMBToWC
@ stub StartThreadpoolIo
# @ stub StmAlignSize
......@@ -1622,7 +1622,7 @@
# @ stub UnregisterStateChangeNotification
# @ stub UnregisterStateLock
@ stdcall UnregisterTraceGuids(int64) ntdll.EtwUnregisterTraceGuids
@ stdcall UnregisterWaitEx(long long) kernel32.UnregisterWaitEx
@ stdcall UnregisterWaitEx(long long)
# @ stub UnsubscribeEdpEnabledStateChange
# @ stub UnsubscribeStateChangeNotification
# @ stub UpdatePackageStatus
......@@ -1687,10 +1687,10 @@
@ stdcall WaitForDebugEvent(ptr long) kernel32.WaitForDebugEvent
# @ stub WaitForDebugEventEx
# @ stub WaitForMachinePolicyForegroundProcessingInternal
@ stdcall WaitForMultipleObjects(long ptr long long) kernel32.WaitForMultipleObjects
@ stdcall WaitForMultipleObjectsEx(long ptr long long long) kernel32.WaitForMultipleObjectsEx
@ stdcall WaitForSingleObject(long long) kernel32.WaitForSingleObject
@ stdcall WaitForSingleObjectEx(long long long) kernel32.WaitForSingleObjectEx
@ stdcall WaitForMultipleObjects(long ptr long long)
@ stdcall WaitForMultipleObjectsEx(long ptr long long long)
@ stdcall WaitForSingleObject(long long)
@ stdcall WaitForSingleObjectEx(long long long)
@ stub WaitForThreadpoolIoCallbacks
@ stdcall WaitForThreadpoolTimerCallbacks(ptr long) kernel32.WaitForThreadpoolTimerCallbacks
@ stdcall WaitForThreadpoolWaitCallbacks(ptr long) kernel32.WaitForThreadpoolWaitCallbacks
......
......@@ -27,6 +27,7 @@
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "wincon.h"
#include "winerror.h"
#include "winnls.h"
#include "winternl.h"
......@@ -120,6 +121,162 @@ static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING
/***********************************************************************
* Waits
***********************************************************************/
static HANDLE normalize_handle_if_console( HANDLE handle )
{
if ((handle == (HANDLE)STD_INPUT_HANDLE) ||
(handle == (HANDLE)STD_OUTPUT_HANDLE) ||
(handle == (HANDLE)STD_ERROR_HANDLE))
handle = GetStdHandle( HandleToULong(handle) );
/* even screen buffer console handles are waitable, and are
* handled as a handle to the console itself
*/
if (is_console_handle( handle ) && VerifyConsoleIoHandle( handle ))
handle = GetConsoleInputWaitHandle();
return handle;
}
/***********************************************************************
* RegisterWaitForSingleObjectEx (kernelbase.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH RegisterWaitForSingleObjectEx( HANDLE handle, WAITORTIMERCALLBACK callback,
PVOID context, ULONG timeout, ULONG flags )
{
NTSTATUS status;
HANDLE ret;
TRACE( "%p %p %p %d %d\n", handle, callback, context, timeout, flags );
handle = normalize_handle_if_console( handle );
status = RtlRegisterWait( &ret, handle, callback, context, timeout, flags );
if (status != STATUS_SUCCESS)
{
SetLastError( RtlNtStatusToDosError(status) );
return NULL;
}
return ret;
}
/***********************************************************************
* SignalObjectAndWait (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH SignalObjectAndWait( HANDLE signal, HANDLE wait,
DWORD timeout, BOOL alertable )
{
NTSTATUS status;
LARGE_INTEGER time;
TRACE( "%p %p %d %d\n", signal, wait, timeout, alertable );
status = NtSignalAndWaitForSingleObject( signal, wait, alertable, get_nt_timeout( &time, timeout ) );
if (HIWORD(status))
{
SetLastError( RtlNtStatusToDosError(status) );
status = WAIT_FAILED;
}
return status;
}
/***********************************************************************
* Sleep (kernelbase.@)
*/
void WINAPI DECLSPEC_HOTPATCH Sleep( DWORD timeout )
{
LARGE_INTEGER time;
NtDelayExecution( FALSE, get_nt_timeout( &time, timeout ) );
}
/******************************************************************************
* SleepEx (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH SleepEx( DWORD timeout, BOOL alertable )
{
NTSTATUS status;
LARGE_INTEGER time;
status = NtDelayExecution( alertable, get_nt_timeout( &time, timeout ) );
if (status == STATUS_USER_APC) return WAIT_IO_COMPLETION;
return 0;
}
/***********************************************************************
* UnregisterWaitEx (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH UnregisterWaitEx( HANDLE handle, HANDLE event )
{
return set_ntstatus( RtlDeregisterWaitEx( handle, event ));
}
/***********************************************************************
* WaitForSingleObject (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH WaitForSingleObject( HANDLE handle, DWORD timeout )
{
return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
}
/***********************************************************************
* WaitForSingleObjectEx (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH WaitForSingleObjectEx( HANDLE handle, DWORD timeout, BOOL alertable )
{
return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
}
/***********************************************************************
* WaitForMultipleObjects (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH WaitForMultipleObjects( DWORD count, const HANDLE *handles,
BOOL wait_all, DWORD timeout )
{
return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
}
/***********************************************************************
* WaitForMultipleObjectsEx (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
BOOL wait_all, DWORD timeout, BOOL alertable )
{
NTSTATUS status;
HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
LARGE_INTEGER time;
unsigned int i;
if (count > MAXIMUM_WAIT_OBJECTS)
{
SetLastError(ERROR_INVALID_PARAMETER);
return WAIT_FAILED;
}
for (i = 0; i < count; i++) hloc[i] = normalize_handle_if_console( handles[i] );
status = NtWaitForMultipleObjects( count, hloc, !wait_all, alertable,
get_nt_timeout( &time, timeout ) );
if (HIWORD(status)) /* is it an error code? */
{
SetLastError( RtlNtStatusToDosError(status) );
status = WAIT_FAILED;
}
return status;
}
/***********************************************************************
* Events
***********************************************************************/
......
......@@ -307,7 +307,9 @@ WINBASEAPI BOOL WINAPI AddConsoleAliasW(LPWSTR,LPWSTR,LPWSTR);
#define AddConsoleAlias WINELIB_NAME_AW(AddConsoleAlias)
WINBASEAPI BOOL WINAPI AllocConsole(VOID);
WINBASEAPI BOOL WINAPI AttachConsole(DWORD);
WINBASEAPI HANDLE WINAPI CreateConsoleScreenBuffer( DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,LPVOID);
WINBASEAPI BOOL WINAPI CloseConsoleHandle(HANDLE);
WINBASEAPI HANDLE WINAPI CreateConsoleScreenBuffer(DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,LPVOID);
WINBASEAPI HANDLE WINAPI DuplicateConsoleHandle(HANDLE,DWORD,BOOL,DWORD);
WINBASEAPI BOOL WINAPI FillConsoleOutputAttribute( HANDLE,WORD,DWORD,COORD,LPDWORD);
WINBASEAPI BOOL WINAPI FillConsoleOutputCharacterA(HANDLE,CHAR,DWORD,COORD,LPDWORD);
WINBASEAPI BOOL WINAPI FillConsoleOutputCharacterW(HANDLE,WCHAR,DWORD,COORD,LPDWORD);
......@@ -337,6 +339,7 @@ WINBASEAPI BOOL WINAPI GetConsoleHistoryInfo(LPCONSOLE_HISTORY_INFO);
WINBASEAPI BOOL WINAPI GetConsoleInputExeNameA(DWORD,LPSTR);
WINBASEAPI BOOL WINAPI GetConsoleInputExeNameW(DWORD,LPWSTR);
#define GetConsoleInputExeName WINELIB_NAME_AW(GetConsoleInputExeName)
WINBASEAPI HANDLE WINAPI GetConsoleInputWaitHandle(void);
WINBASEAPI BOOL WINAPI GetConsoleMode( HANDLE,LPDWORD);
WINBASEAPI DWORD WINAPI GetConsoleOriginalTitleA(LPSTR,DWORD);
WINBASEAPI DWORD WINAPI GetConsoleOriginalTitleW(LPWSTR,DWORD);
......@@ -352,6 +355,9 @@ WINBASEAPI HWND WINAPI GetConsoleWindow(void);
WINBASEAPI BOOL WINAPI GetCurrentConsoleFont(HANDLE,BOOL,LPCONSOLE_FONT_INFO);
WINBASEAPI BOOL WINAPI GetNumberOfConsoleInputEvents( HANDLE,LPDWORD);
WINBASEAPI BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD);
WINBASEAPI HANDLE WINAPI OpenConsoleA(LPCSTR,DWORD,BOOL,DWORD);
WINBASEAPI HANDLE WINAPI OpenConsoleW(LPCWSTR,DWORD,BOOL,DWORD);
#define OpenConsole WINELIB_NAME_AW(OpenConsole)
WINBASEAPI BOOL WINAPI PeekConsoleInputA( HANDLE,PINPUT_RECORD,DWORD,LPDWORD);
WINBASEAPI BOOL WINAPI PeekConsoleInputW( HANDLE,PINPUT_RECORD,DWORD,LPDWORD);
#define PeekConsoleInput WINELIB_NAME_AW(PeekConsoleInput)
......@@ -387,6 +393,7 @@ WINBASEAPI BOOL WINAPI SetConsoleTitleA(LPCSTR);
WINBASEAPI BOOL WINAPI SetConsoleTitleW(LPCWSTR);
#define SetConsoleTitle WINELIB_NAME_AW(SetConsoleTitle)
WINBASEAPI BOOL WINAPI SetConsoleWindowInfo( HANDLE,BOOL,LPSMALL_RECT);
WINBASEAPI BOOL WINAPI VerifyConsoleIoHandle(HANDLE);
WINBASEAPI BOOL WINAPI WriteConsoleA(HANDLE,const void *,DWORD,LPDWORD,void *);
WINBASEAPI BOOL WINAPI WriteConsoleW(HANDLE,const void *,DWORD,LPDWORD,void *);
#define WriteConsole WINELIB_NAME_AW(WriteConsole)
......
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