2000-09-29 22:48:04 +02:00
|
|
|
/*
|
|
|
|
* Kernel synchronization objects
|
|
|
|
*
|
|
|
|
* Copyright 1998 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
|
2001-07-20 20:00:00 +02:00
|
|
|
#include "config.h"
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "wine/port.h"
|
2001-07-20 20:00:00 +02:00
|
|
|
|
2000-09-29 22:48:04 +02:00
|
|
|
#include <string.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2002-07-25 02:22:03 +02:00
|
|
|
#include <errno.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-05-20 06:32:53 +02:00
|
|
|
#include <stdio.h>
|
2001-07-20 20:00:00 +02:00
|
|
|
|
2005-04-18 16:57:04 +02:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2001-07-20 20:00:00 +02:00
|
|
|
#include "winbase.h"
|
2000-09-29 22:48:04 +02:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnls.h"
|
2004-03-18 02:36:09 +01:00
|
|
|
#include "winternl.h"
|
2005-08-18 12:59:26 +02:00
|
|
|
#include "winioctl.h"
|
2005-12-02 15:55:48 +01:00
|
|
|
#include "ddk/wdm.h"
|
2001-07-20 20:00:00 +02:00
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
2003-12-08 22:58:55 +01:00
|
|
|
#include "wine/winbase16.h"
|
2003-09-18 06:39:13 +02:00
|
|
|
#include "kernel_private.h"
|
2001-07-20 20:00:00 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2004-02-26 06:30:54 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(sync);
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2003-05-12 05:28:26 +02:00
|
|
|
/* check if current version is NT or Win95 */
|
2007-03-17 11:22:45 +01:00
|
|
|
static inline int is_version_nt(void)
|
2003-05-12 05:28:26 +02:00
|
|
|
{
|
|
|
|
return !(GetVersion() & 0x80000000);
|
|
|
|
}
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2005-12-02 15:55:48 +01:00
|
|
|
/* returns directory handle to \\BaseNamedObjects */
|
|
|
|
HANDLE get_BaseNamedObjects_handle(void)
|
|
|
|
{
|
|
|
|
static HANDLE handle = NULL;
|
|
|
|
static const WCHAR basenameW[] =
|
|
|
|
{'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',0};
|
|
|
|
UNICODE_STRING str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
HANDLE dir;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&str, basenameW);
|
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
NtOpenDirectoryObject(&dir, DIRECTORY_CREATE_OBJECT|DIRECTORY_TRAVERSE,
|
|
|
|
&attr);
|
|
|
|
if (InterlockedCompareExchangePointer( (PVOID)&handle, dir, 0 ) != 0)
|
|
|
|
{
|
|
|
|
/* someone beat us here... */
|
|
|
|
CloseHandle( dir );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2007-06-02 00:30:01 +02:00
|
|
|
/* helper for kernel32->ntdll timeout format conversion */
|
|
|
|
static inline PLARGE_INTEGER get_nt_timeout( PLARGE_INTEGER pTime, DWORD timeout )
|
|
|
|
{
|
|
|
|
if (timeout == INFINITE) return NULL;
|
|
|
|
pTime->QuadPart = (ULONGLONG)timeout * -10000;
|
|
|
|
return pTime;
|
|
|
|
}
|
|
|
|
|
2003-09-18 06:39:13 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Sleep (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
VOID WINAPI Sleep( DWORD timeout )
|
|
|
|
{
|
|
|
|
SleepEx( timeout, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SleepEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
2007-06-02 00:30:01 +02:00
|
|
|
LARGE_INTEGER time;
|
2003-09-18 06:39:13 +02:00
|
|
|
|
2007-06-02 00:30:01 +02:00
|
|
|
status = NtDelayExecution( alertable, get_nt_timeout( &time, timeout ) );
|
|
|
|
if (status == STATUS_USER_APC) return WAIT_IO_COMPLETION;
|
|
|
|
return 0;
|
2003-09-18 06:39:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-11 22:11:01 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SwitchToThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SwitchToThread(void)
|
|
|
|
{
|
|
|
|
return (NtYieldExecution() != STATUS_NO_YIELD_PERFORMED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-18 06:39:13 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForMultipleObjectsEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
|
|
|
|
BOOL wait_all, DWORD timeout,
|
|
|
|
BOOL alertable )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
|
2007-06-02 00:30:01 +02:00
|
|
|
LARGE_INTEGER time;
|
2004-08-11 01:43:21 +02:00
|
|
|
unsigned int i;
|
2003-09-18 06:39:13 +02:00
|
|
|
|
2006-03-21 22:45:40 +01:00
|
|
|
if (count > MAXIMUM_WAIT_OBJECTS)
|
2003-09-18 06:39:13 +02:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return WAIT_FAILED;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) ||
|
|
|
|
(handles[i] == (HANDLE)STD_OUTPUT_HANDLE) ||
|
|
|
|
(handles[i] == (HANDLE)STD_ERROR_HANDLE))
|
2007-05-23 09:36:53 +02:00
|
|
|
hloc[i] = GetStdHandle( HandleToULong(handles[i]) );
|
2003-09-18 06:39:13 +02:00
|
|
|
else
|
|
|
|
hloc[i] = handles[i];
|
|
|
|
|
|
|
|
/* yes, even screen buffer console handles are waitable, and are
|
|
|
|
* handled as a handle to the console itself !!
|
|
|
|
*/
|
|
|
|
if (is_console_handle(hloc[i]))
|
|
|
|
{
|
|
|
|
if (!VerifyConsoleIoHandle(hloc[i]))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
hloc[i] = GetConsoleInputWaitHandle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:30:01 +02:00
|
|
|
status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable,
|
|
|
|
get_nt_timeout( &time, timeout ) );
|
2003-09-18 06:39:13 +02:00
|
|
|
|
|
|
|
if (HIWORD(status)) /* is it an error code? */
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
status = WAIT_FAILED;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForSingleObject (KERNEL.460)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
|
|
|
|
{
|
|
|
|
DWORD retval, mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
|
|
|
retval = WaitForSingleObject( handle, timeout );
|
|
|
|
RestoreThunkLock( mutex_count );
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForMultipleObjects (KERNEL.461)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
|
|
|
|
BOOL wait_all, DWORD timeout )
|
|
|
|
{
|
|
|
|
DWORD retval, mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
|
|
|
retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
|
|
|
|
RestoreThunkLock( mutex_count );
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WaitForMultipleObjectsEx (KERNEL.495)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
|
|
|
|
BOOL wait_all, DWORD timeout, BOOL alertable )
|
|
|
|
{
|
|
|
|
DWORD retval, mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
|
|
|
retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
|
|
|
|
RestoreThunkLock( mutex_count );
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-10-09 21:46:43 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RegisterWaitForSingleObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject,
|
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Context,
|
|
|
|
ULONG dwMilliseconds, ULONG dwFlags)
|
|
|
|
{
|
2008-01-01 23:37:25 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("%p %p %p %p %d %d\n",
|
2003-10-09 21:46:43 +02:00
|
|
|
phNewWaitObject,hObject,Callback,Context,dwMilliseconds,dwFlags);
|
2008-01-01 23:37:25 +01:00
|
|
|
|
|
|
|
status = RtlRegisterWait( phNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2003-10-09 21:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RegisterWaitForSingleObjectEx (KERNEL32.@)
|
|
|
|
*/
|
2004-05-18 22:43:29 +02:00
|
|
|
HANDLE WINAPI RegisterWaitForSingleObjectEx( HANDLE hObject,
|
2003-10-09 21:46:43 +02:00
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Context,
|
|
|
|
ULONG dwMilliseconds, ULONG dwFlags )
|
|
|
|
{
|
2008-01-04 18:43:56 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE hNewWaitObject;
|
|
|
|
|
|
|
|
TRACE("%p %p %p %d %d\n",
|
2003-10-09 21:46:43 +02:00
|
|
|
hObject,Callback,Context,dwMilliseconds,dwFlags);
|
2008-01-04 18:43:56 +01:00
|
|
|
|
|
|
|
status = RtlRegisterWait( &hNewWaitObject, hObject, Callback, Context, dwMilliseconds, dwFlags );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return hNewWaitObject;
|
2003-10-09 21:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnregisterWait (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnregisterWait( HANDLE WaitHandle )
|
|
|
|
{
|
2008-01-01 23:37:25 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("%p\n",WaitHandle);
|
|
|
|
|
|
|
|
status = RtlDeregisterWait( WaitHandle );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2003-10-09 21:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UnregisterWaitEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI UnregisterWaitEx( HANDLE WaitHandle, HANDLE CompletionEvent )
|
|
|
|
{
|
|
|
|
FIXME("%p %p\n",WaitHandle, CompletionEvent);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-17 02:43:47 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SignalObjectAndWait (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Allows to atomically signal any of the synchro objects (semaphore,
|
|
|
|
* mutex, event) and wait on another.
|
|
|
|
*/
|
2005-04-24 19:36:34 +02:00
|
|
|
DWORD WINAPI SignalObjectAndWait( HANDLE hObjectToSignal, HANDLE hObjectToWaitOn,
|
|
|
|
DWORD dwMilliseconds, BOOL bAlertable )
|
2004-03-17 02:43:47 +01:00
|
|
|
{
|
2005-04-24 19:36:34 +02:00
|
|
|
NTSTATUS status;
|
2007-06-02 00:30:01 +02:00
|
|
|
LARGE_INTEGER timeout;
|
2005-04-24 19:36:34 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%p %p %d %d\n", hObjectToSignal,
|
2005-04-24 19:36:34 +02:00
|
|
|
hObjectToWaitOn, dwMilliseconds, bAlertable);
|
|
|
|
|
2007-06-02 00:30:01 +02:00
|
|
|
status = NtSignalAndWaitForSingleObject( hObjectToSignal, hObjectToWaitOn, bAlertable,
|
|
|
|
get_nt_timeout( &timeout, dwMilliseconds ) );
|
2005-04-24 19:36:34 +02:00
|
|
|
if (HIWORD(status))
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
status = WAIT_FAILED;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
2004-03-17 02:43:47 +01:00
|
|
|
|
2003-06-24 05:34:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* InitializeCriticalSection (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Initialise a critical section before use.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to initialise.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing. If the function fails an exception is raised.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
|
|
|
void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit )
|
|
|
|
{
|
|
|
|
NTSTATUS ret = RtlInitializeCriticalSection( crit );
|
|
|
|
if (ret) RtlRaiseStatus( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InitializeCriticalSectionAndSpinCount (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Initialise a critical section with a spin count.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to initialise.
|
|
|
|
* spincount [I] Number of times to spin upon contention.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: Nothing. If the function fails an exception is raised.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* spincount is ignored on uni-processor systems.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
|
|
|
|
{
|
|
|
|
NTSTATUS ret = RtlInitializeCriticalSectionAndSpinCount( crit, spincount );
|
|
|
|
if (ret) RtlRaiseStatus( ret );
|
|
|
|
return !ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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 );
|
2006-05-01 22:44:43 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, crit->DebugInfo );
|
|
|
|
crit->DebugInfo = NULL;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ReinitializeCriticalSection (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Initialise an already used critical section.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to initialise.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
|
|
|
void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit )
|
|
|
|
{
|
|
|
|
if ( !crit->LockSemaphore )
|
|
|
|
RtlInitializeCriticalSection( crit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* UninitializeCriticalSection (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* UnInitialise a critical section after use.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to uninitialise (destroy).
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
|
|
|
void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
|
|
|
|
{
|
|
|
|
RtlDeleteCriticalSection( crit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-29 22:48:04 +02:00
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateEventA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateEventW( sa, manual_reset, initial_state, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return CreateEventW( sa, manual_reset, initial_state, buffer );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateEventW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2000-12-29 04:18:08 +01:00
|
|
|
/* one buggy program needs this
|
|
|
|
* ("Van Dale Groot woordenboek der Nederlandse taal")
|
|
|
|
*/
|
|
|
|
if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES)))
|
|
|
|
{
|
|
|
|
ERR("Bad security attributes pointer %p\n",sa);
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-02 19:05:37 +01:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:42:54 +02:00
|
|
|
attr.Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 15:55:48 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
2004-12-02 19:05:37 +01:00
|
|
|
|
|
|
|
status = NtCreateEvent( &ret, EVENT_ALL_ACCESS, &attr, manual_reset, initial_state );
|
2005-11-21 17:26:34 +01:00
|
|
|
if (status == STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
SetLastError( ERROR_ALREADY_EXISTS );
|
|
|
|
else
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* CreateW32Event (KERNEL.457)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
|
|
|
|
{
|
2005-01-07 16:40:09 +01:00
|
|
|
return CreateEventW( NULL, manual_reset, initial_state, NULL );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenEventA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenEventW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return OpenEventW( access, inherit, buffer );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenEventW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = EVENT_ALL_ACCESS;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:42:54 +02:00
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 15:55:48 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
2003-05-12 05:28:26 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
status = NtOpenEvent( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* PulseEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PulseEvent( HANDLE handle )
|
|
|
|
{
|
2004-03-18 02:36:09 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = NtPulseEvent( handle, NULL )))
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* SetW32Event (KERNEL.458)
|
2001-06-13 22:13:18 +02:00
|
|
|
* SetEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetEvent( HANDLE handle )
|
|
|
|
{
|
2004-03-18 02:36:09 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = NtSetEvent( handle, NULL )))
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-11 20:56:41 +02:00
|
|
|
* ResetW32Event (KERNEL.459)
|
2001-06-13 22:13:18 +02:00
|
|
|
* ResetEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ResetEvent( HANDLE handle )
|
|
|
|
{
|
2004-03-18 02:36:09 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = NtResetEvent( handle, NULL )))
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* NOTE: The Win95 VWin32_Event routines given below are really low-level
|
|
|
|
* routines implemented directly by VWin32. The user-mode libraries
|
|
|
|
* implement Win32 synchronisation routines on top of these low-level
|
|
|
|
* primitives. We do it the other way around here :-)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* VWin32_EventCreate (KERNEL.442)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI VWin32_EventCreate(VOID)
|
|
|
|
{
|
2005-01-07 16:40:09 +01:00
|
|
|
HANDLE hEvent = CreateEventW( NULL, FALSE, 0, NULL );
|
2000-09-29 22:48:04 +02:00
|
|
|
return ConvertToGlobalHandle( hEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* VWin32_EventDestroy (KERNEL.443)
|
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventDestroy(HANDLE event)
|
|
|
|
{
|
|
|
|
CloseHandle( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2002-06-01 01:06:46 +02:00
|
|
|
* VWin32_EventWait (KERNEL.450)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventWait(HANDLE event)
|
|
|
|
{
|
2000-11-16 00:41:46 +01:00
|
|
|
DWORD mutex_count;
|
|
|
|
|
|
|
|
ReleaseThunkLock( &mutex_count );
|
2000-09-29 22:48:04 +02:00
|
|
|
WaitForSingleObject( event, INFINITE );
|
2000-11-16 00:41:46 +01:00
|
|
|
RestoreThunkLock( mutex_count );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* VWin32_EventSet (KERNEL.451)
|
2001-07-02 21:59:40 +02:00
|
|
|
* KERNEL_479 (KERNEL.479)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_EventSet(HANDLE event)
|
|
|
|
{
|
|
|
|
SetEvent( event );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateMutexA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateMutexW( sa, owner, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return CreateMutexW( sa, owner, buffer );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateMutexW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:41:45 +02:00
|
|
|
attr.Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 15:55:48 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
2004-12-02 19:05:37 +01:00
|
|
|
|
|
|
|
status = NtCreateMutant( &ret, MUTEX_ALL_ACCESS, &attr, owner );
|
2005-11-21 17:26:34 +01:00
|
|
|
if (status == STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
SetLastError( ERROR_ALREADY_EXISTS );
|
|
|
|
else
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenMutexA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenMutexW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return OpenMutexW( access, inherit, buffer );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenMutexW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:41:45 +02:00
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 15:55:48 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
2003-05-12 05:28:26 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
status = NtOpenMutant( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* ReleaseMutex (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ReleaseMutex( HANDLE handle )
|
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtReleaseMutant(handle, NULL);
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
2004-12-02 19:05:37 +01:00
|
|
|
return TRUE;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Semaphores
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateSemaphoreA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
if (!name) return CreateSemaphoreW( sa, initial, max, NULL );
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return CreateSemaphoreW( sa, initial, max, buffer );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateSemaphoreW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
|
2004-12-02 19:05:37 +01:00
|
|
|
LONG max, LPCWSTR name )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:43:43 +02:00
|
|
|
attr.Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 16:01:17 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
status = NtCreateSemaphore( &ret, SEMAPHORE_ALL_ACCESS, &attr, initial, max );
|
2005-11-21 17:26:34 +01:00
|
|
|
if (status == STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
SetLastError( ERROR_ALREADY_EXISTS );
|
|
|
|
else
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2000-09-29 22:48:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenSemaphoreA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenSemaphoreW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return OpenSemaphoreW( access, inherit, buffer );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenSemaphoreW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:43:43 +02:00
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 16:01:17 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
2003-05-12 05:28:26 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
status = NtOpenSemaphore( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* ReleaseSemaphore (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
|
|
|
|
{
|
2005-08-17 12:28:35 +02:00
|
|
|
NTSTATUS status = NtReleaseSemaphore( handle, count, (PULONG)previous );
|
2000-09-29 22:48:04 +02:00
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-20 06:14:45 +02:00
|
|
|
/*
|
|
|
|
* Timers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateWaitableTimerW( sa, manual, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return CreateWaitableTimerW( sa, manual, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
|
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
HANDLE handle;
|
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2003-05-20 06:14:45 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:44:36 +02:00
|
|
|
attr.Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
2003-05-20 06:14:45 +02:00
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 16:05:54 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2003-05-20 06:14:45 +02:00
|
|
|
}
|
2004-12-02 19:05:37 +01:00
|
|
|
|
|
|
|
status = NtCreateTimer(&handle, TIMER_ALL_ACCESS, &attr,
|
|
|
|
manual ? NotificationTimer : SynchronizationTimer);
|
2005-11-21 17:26:34 +01:00
|
|
|
if (status == STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
SetLastError( ERROR_ALREADY_EXISTS );
|
|
|
|
else
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2003-05-20 06:14:45 +02:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenWaitableTimerA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenWaitableTimerW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return OpenWaitableTimerW( access, inherit, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenWaitableTimerW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
2004-12-02 19:05:37 +01:00
|
|
|
HANDLE handle;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
2003-05-20 06:14:45 +02:00
|
|
|
|
2005-01-03 15:43:15 +01:00
|
|
|
if (!is_version_nt()) access = TIMER_ALL_ACCESS;
|
2004-12-02 19:05:37 +01:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
2008-05-21 20:44:36 +02:00
|
|
|
attr.Attributes = inherit ? OBJ_INHERIT : 0;
|
2004-12-02 19:05:37 +01:00
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
RtlInitUnicodeString( &nameW, name );
|
|
|
|
attr.ObjectName = &nameW;
|
2005-12-02 16:05:54 +01:00
|
|
|
attr.RootDirectory = get_BaseNamedObjects_handle();
|
2004-12-02 19:05:37 +01:00
|
|
|
}
|
2003-05-20 06:14:45 +02:00
|
|
|
|
2004-12-02 19:05:37 +01:00
|
|
|
status = NtOpenTimer(&handle, access, &attr);
|
2003-05-20 06:14:45 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWaitableTimer (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
|
|
|
|
PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
|
|
|
|
{
|
2005-06-10 21:33:47 +02:00
|
|
|
NTSTATUS status = NtSetTimer(handle, when, (PTIMER_APC_ROUTINE)callback,
|
|
|
|
arg, resume, period, NULL);
|
2003-05-20 06:14:45 +02:00
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
if (status != STATUS_TIMER_RESUME_IGNORED) return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CancelWaitableTimer (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CancelWaitableTimer( HANDLE handle )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
status = NtCancelTimer(handle, NULL);
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateTimerQueue (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateTimerQueue(void)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteTimerQueueEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateTimerQueueTimer (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Creates a timer-queue timer. This timer expires at the specified due
|
|
|
|
* time (in ms), then after every specified period (in ms). When the timer
|
|
|
|
* expires, the callback function is called.
|
|
|
|
*
|
|
|
|
* RETURNS
|
2008-03-17 21:51:39 +01:00
|
|
|
* nonzero on success or zero on failure
|
2003-05-20 06:14:45 +02:00
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
|
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Parameter,
|
|
|
|
DWORD DueTime, DWORD Period, ULONG Flags )
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteTimerQueueTimer (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Cancels a timer-queue timer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
2008-03-17 21:51:39 +01:00
|
|
|
* nonzero on success or zero on failure
|
2003-05-20 06:14:45 +02:00
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
|
|
|
|
HANDLE CompletionEvent )
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-29 22:48:04 +02:00
|
|
|
/*
|
|
|
|
* Pipes
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateNamedPipeA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
|
|
|
|
DWORD dwPipeMode, DWORD nMaxInstances,
|
|
|
|
DWORD nOutBufferSize, DWORD nInBufferSize,
|
|
|
|
DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2001-07-10 21:16:49 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
if (!name) return CreateNamedPipeW( NULL, dwOpenMode, dwPipeMode, nMaxInstances,
|
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
|
2001-07-10 21:16:49 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2001-07-10 21:16:49 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
2003-05-06 02:19:59 +02:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2001-07-10 21:16:49 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return CreateNamedPipeW( buffer, dwOpenMode, dwPipeMode, nMaxInstances,
|
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateNamedPipeW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode,
|
|
|
|
DWORD dwPipeMode, DWORD nMaxInstances,
|
|
|
|
DWORD nOutBufferSize, DWORD nInBufferSize,
|
2005-04-18 16:57:04 +02:00
|
|
|
DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES sa )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2005-04-18 16:57:04 +02:00
|
|
|
HANDLE handle;
|
2004-04-30 23:03:09 +02:00
|
|
|
UNICODE_STRING nt_name;
|
2005-04-18 16:57:04 +02:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
2007-04-16 14:32:18 +02:00
|
|
|
DWORD access, options;
|
2005-04-18 16:57:04 +02:00
|
|
|
BOOLEAN pipe_type, read_mode, non_block;
|
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
LARGE_INTEGER timeout;
|
2001-07-10 21:16:49 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%s, %#08x, %#08x, %d, %d, %d, %d, %p)\n",
|
2000-09-29 22:48:04 +02:00
|
|
|
debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances,
|
2005-04-18 16:57:04 +02:00
|
|
|
nOutBufferSize, nInBufferSize, nDefaultTimeOut, sa );
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2004-04-30 23:03:09 +02:00
|
|
|
if (!RtlDosPathNameToNtPathName_U( name, &nt_name, NULL, NULL ))
|
2003-02-19 23:06:36 +01:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2004-04-30 23:03:09 +02:00
|
|
|
if (nt_name.Length >= MAX_PATH * sizeof(WCHAR) )
|
2001-07-10 21:16:49 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
2004-04-30 23:03:09 +02:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2003-02-19 23:06:36 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2005-04-18 16:57:04 +02:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nt_name;
|
2005-09-21 13:42:30 +02:00
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE |
|
2005-09-30 12:33:43 +02:00
|
|
|
((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
|
2005-04-18 16:57:04 +02:00
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2007-04-16 14:32:18 +02:00
|
|
|
switch(dwOpenMode & 3)
|
|
|
|
{
|
|
|
|
case PIPE_ACCESS_INBOUND:
|
|
|
|
options = FILE_PIPE_INBOUND;
|
|
|
|
access = GENERIC_READ;
|
|
|
|
break;
|
|
|
|
case PIPE_ACCESS_OUTBOUND:
|
|
|
|
options = FILE_PIPE_OUTBOUND;
|
|
|
|
access = GENERIC_WRITE;
|
|
|
|
break;
|
|
|
|
case PIPE_ACCESS_DUPLEX:
|
|
|
|
options = FILE_PIPE_FULL_DUPLEX;
|
|
|
|
access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
access |= SYNCHRONIZE;
|
2005-04-18 16:57:04 +02:00
|
|
|
if (dwOpenMode & FILE_FLAG_WRITE_THROUGH) options |= FILE_WRITE_THROUGH;
|
|
|
|
if (!(dwOpenMode & FILE_FLAG_OVERLAPPED)) options |= FILE_SYNCHRONOUS_IO_ALERT;
|
|
|
|
pipe_type = (dwPipeMode & PIPE_TYPE_MESSAGE) ? TRUE : FALSE;
|
|
|
|
read_mode = (dwPipeMode & PIPE_READMODE_MESSAGE) ? TRUE : FALSE;
|
|
|
|
non_block = (dwPipeMode & PIPE_NOWAIT) ? TRUE : FALSE;
|
2007-05-23 09:36:53 +02:00
|
|
|
if (nMaxInstances >= PIPE_UNLIMITED_INSTANCES) nMaxInstances = ~0U;
|
2005-04-18 16:57:04 +02:00
|
|
|
|
|
|
|
timeout.QuadPart = (ULONGLONG)nDefaultTimeOut * -10000;
|
|
|
|
|
|
|
|
SetLastError(0);
|
2007-04-16 14:32:18 +02:00
|
|
|
|
|
|
|
status = NtCreateNamedPipeFile(&handle, access, &attr, &iosb, 0,
|
|
|
|
FILE_OVERWRITE_IF, options, pipe_type,
|
2005-09-26 13:02:45 +02:00
|
|
|
read_mode, non_block, nMaxInstances,
|
|
|
|
nInBufferSize, nOutBufferSize, &timeout);
|
2005-04-18 16:57:04 +02:00
|
|
|
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
if (status)
|
2001-07-10 21:16:49 +02:00
|
|
|
{
|
2005-04-18 16:57:04 +02:00
|
|
|
handle = INVALID_HANDLE_VALUE;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2001-07-10 21:16:49 +02:00
|
|
|
}
|
2005-04-18 16:57:04 +02:00
|
|
|
return handle;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* PeekNamedPipe (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
|
|
|
|
LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
|
|
|
|
{
|
2006-11-01 16:24:36 +01:00
|
|
|
FILE_PIPE_PEEK_BUFFER local_buffer;
|
|
|
|
FILE_PIPE_PEEK_BUFFER *buffer = &local_buffer;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
2005-03-22 19:23:44 +01:00
|
|
|
|
2006-11-01 16:24:36 +01:00
|
|
|
if (cbBuffer && !(buffer = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data[cbBuffer] ))))
|
2003-12-02 05:19:56 +01:00
|
|
|
{
|
2006-11-01 16:24:36 +01:00
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
2003-12-02 05:19:56 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-09-05 01:34:03 +02:00
|
|
|
|
2006-11-01 16:24:36 +01:00
|
|
|
status = NtFsControlFile( hPipe, 0, NULL, NULL, &io, FSCTL_PIPE_PEEK, NULL, 0,
|
|
|
|
buffer, FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data[cbBuffer] ) );
|
|
|
|
if (!status)
|
2002-09-05 01:34:03 +02:00
|
|
|
{
|
2006-11-01 16:24:36 +01:00
|
|
|
ULONG read_size = io.Information - FIELD_OFFSET( FILE_PIPE_PEEK_BUFFER, Data );
|
|
|
|
if (lpcbAvail) *lpcbAvail = buffer->ReadDataAvailable;
|
|
|
|
if (lpcbRead) *lpcbRead = read_size;
|
|
|
|
if (lpcbMessage) *lpcbMessage = 0; /* FIXME */
|
|
|
|
if (lpvBuffer) memcpy( lpvBuffer, buffer->Data, read_size );
|
2002-09-05 01:34:03 +02:00
|
|
|
}
|
2006-11-01 16:24:36 +01:00
|
|
|
else SetLastError( RtlNtStatusToDosError(status) );
|
2002-07-25 02:22:03 +02:00
|
|
|
|
2006-11-01 16:24:36 +01:00
|
|
|
if (buffer != &local_buffer) HeapFree( GetProcessHeap(), 0, buffer );
|
|
|
|
return !status;
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
2001-11-07 21:14:45 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* WaitNamedPipeA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WaitNamedPipeA (LPCSTR name, DWORD nTimeOut)
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2001-11-07 21:14:45 +01:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
if (!name) return WaitNamedPipeW( NULL, nTimeOut );
|
2001-08-24 01:29:20 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2001-11-07 21:14:45 +01:00
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
2001-11-07 21:14:45 +01:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return WaitNamedPipeW( buffer, nTimeOut );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* WaitNamedPipeW (KERNEL32.@)
|
2005-12-14 11:14:02 +01:00
|
|
|
*
|
|
|
|
* Waits for a named pipe instance to become available
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* name [I] Pointer to a named pipe name to wait for
|
|
|
|
* nTimeOut [I] How long to wait in ms
|
|
|
|
*
|
|
|
|
* RETURNS
|
2006-09-07 20:01:50 +02:00
|
|
|
* TRUE: Success, named pipe can be opened with CreateFile
|
2005-12-14 11:14:02 +01:00
|
|
|
* FALSE: Failure, GetLastError can be called for further details
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2001-11-30 19:46:42 +01:00
|
|
|
BOOL WINAPI WaitNamedPipeW (LPCWSTR name, DWORD nTimeOut)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2004-06-14 19:00:21 +02:00
|
|
|
static const WCHAR leadin[] = {'\\','?','?','\\','P','I','P','E','\\'};
|
2005-12-14 11:14:02 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
UNICODE_STRING nt_name, pipe_dev_name;
|
|
|
|
FILE_PIPE_WAIT_FOR_BUFFER *pipe_wait;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
ULONG sz_pipe_wait;
|
|
|
|
HANDLE pipe_dev;
|
2001-08-24 01:29:20 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%s 0x%08x\n",debugstr_w(name),nTimeOut);
|
2004-06-14 19:00:21 +02:00
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( name, &nt_name, NULL, NULL ))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-12-14 11:14:02 +01:00
|
|
|
if (nt_name.Length >= MAX_PATH * sizeof(WCHAR) ||
|
|
|
|
nt_name.Length < sizeof(leadin) ||
|
|
|
|
strncmpiW( nt_name.Buffer, leadin, sizeof(leadin)/sizeof(WCHAR) != 0))
|
2001-08-24 01:29:20 +02:00
|
|
|
{
|
2004-06-14 19:00:21 +02:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2005-12-14 11:14:02 +01:00
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
2004-06-14 19:00:21 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-12-14 11:14:02 +01:00
|
|
|
|
|
|
|
sz_pipe_wait = sizeof(*pipe_wait) + nt_name.Length - sizeof(leadin) - sizeof(WCHAR);
|
|
|
|
if (!(pipe_wait = HeapAlloc( GetProcessHeap(), 0, sz_pipe_wait)))
|
2004-06-14 19:00:21 +02:00
|
|
|
{
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
2005-12-14 11:14:02 +01:00
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
2001-08-24 01:29:20 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-07-10 21:16:49 +02:00
|
|
|
|
2005-12-14 11:14:02 +01:00
|
|
|
pipe_dev_name.Buffer = nt_name.Buffer;
|
|
|
|
pipe_dev_name.Length = sizeof(leadin);
|
|
|
|
pipe_dev_name.MaximumLength = sizeof(leadin);
|
|
|
|
InitializeObjectAttributes(&attr,&pipe_dev_name, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
status = NtOpenFile( &pipe_dev, FILE_READ_ATTRIBUTES, &attr,
|
|
|
|
&iosb, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
|
|
|
if (status != ERROR_SUCCESS)
|
2001-11-30 19:46:42 +01:00
|
|
|
{
|
2005-12-14 11:14:02 +01:00
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return FALSE;
|
2001-11-30 19:46:42 +01:00
|
|
|
}
|
|
|
|
|
2005-12-14 11:14:02 +01:00
|
|
|
pipe_wait->TimeoutSpecified = !(nTimeOut == NMPWAIT_USE_DEFAULT_WAIT);
|
2007-04-17 20:08:59 +02:00
|
|
|
if (nTimeOut == NMPWAIT_WAIT_FOREVER)
|
|
|
|
pipe_wait->Timeout.QuadPart = ((ULONGLONG)0x7fffffff << 32) | 0xffffffff;
|
|
|
|
else
|
|
|
|
pipe_wait->Timeout.QuadPart = (ULONGLONG)nTimeOut * -10000;
|
2005-12-14 11:14:02 +01:00
|
|
|
pipe_wait->NameLength = nt_name.Length - sizeof(leadin);
|
|
|
|
memcpy(pipe_wait->Name, nt_name.Buffer + sizeof(leadin)/sizeof(WCHAR),
|
|
|
|
pipe_wait->NameLength);
|
2004-06-14 19:00:21 +02:00
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
|
2005-12-14 11:14:02 +01:00
|
|
|
status = NtFsControlFile( pipe_dev, NULL, NULL, NULL, &iosb, FSCTL_PIPE_WAIT,
|
|
|
|
pipe_wait, sz_pipe_wait, NULL, 0 );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, pipe_wait );
|
|
|
|
NtClose( pipe_dev );
|
|
|
|
|
|
|
|
if(status != STATUS_SUCCESS)
|
2001-11-07 21:14:45 +01:00
|
|
|
{
|
2005-12-14 11:14:02 +01:00
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
2001-07-10 21:16:49 +02:00
|
|
|
}
|
2005-12-14 11:14:02 +01:00
|
|
|
else
|
|
|
|
return TRUE;
|
2001-11-07 21:14:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2005-04-18 16:57:04 +02:00
|
|
|
* ConnectNamedPipe (KERNEL32.@)
|
2005-09-06 16:09:42 +02:00
|
|
|
*
|
|
|
|
* Connects to a named pipe
|
|
|
|
*
|
|
|
|
* Parameters
|
|
|
|
* hPipe: A handle to a named pipe returned by CreateNamedPipe
|
|
|
|
* overlapped: Optional OVERLAPPED struct
|
|
|
|
*
|
|
|
|
* Return values
|
|
|
|
* TRUE: Success
|
|
|
|
* FALSE: Failure, GetLastError can be called for further details
|
2001-11-07 21:14:45 +01:00
|
|
|
*/
|
2005-04-18 16:57:04 +02:00
|
|
|
BOOL WINAPI ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
|
2001-11-07 21:14:45 +01:00
|
|
|
{
|
2005-09-06 16:09:42 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK status_block;
|
2007-09-27 22:04:07 +02:00
|
|
|
LPVOID cvalue = NULL;
|
2001-11-07 21:14:45 +01:00
|
|
|
|
2005-04-18 16:57:04 +02:00
|
|
|
TRACE("(%p,%p)\n", hPipe, overlapped);
|
2001-11-07 21:14:45 +01:00
|
|
|
|
2005-09-06 16:09:42 +02:00
|
|
|
if(overlapped)
|
2007-07-16 16:20:29 +02:00
|
|
|
{
|
2005-09-06 16:09:42 +02:00
|
|
|
overlapped->Internal = STATUS_PENDING;
|
2007-07-16 16:20:29 +02:00
|
|
|
overlapped->InternalHigh = 0;
|
2007-09-27 22:04:07 +02:00
|
|
|
if (((ULONG_PTR)overlapped->hEvent & 1) == 0) cvalue = overlapped;
|
2007-07-16 16:20:29 +02:00
|
|
|
}
|
2001-07-10 21:16:49 +02:00
|
|
|
|
2007-09-27 22:04:07 +02:00
|
|
|
status = NtFsControlFile(hPipe, overlapped ? overlapped->hEvent : NULL, NULL, cvalue,
|
2005-09-06 16:09:42 +02:00
|
|
|
overlapped ? (IO_STATUS_BLOCK *)overlapped : &status_block,
|
|
|
|
FSCTL_PIPE_LISTEN, NULL, 0, NULL, 0);
|
2001-11-07 21:14:45 +01:00
|
|
|
|
2005-09-06 16:09:42 +02:00
|
|
|
if (status == STATUS_SUCCESS) return TRUE;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2001-07-10 21:16:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DisconnectNamedPipe (KERNEL32.@)
|
2005-08-18 12:59:26 +02:00
|
|
|
*
|
|
|
|
* Disconnects from a named pipe
|
|
|
|
*
|
|
|
|
* Parameters
|
|
|
|
* hPipe: A handle to a named pipe returned by CreateNamedPipe
|
|
|
|
*
|
|
|
|
* Return values
|
|
|
|
* TRUE: Success
|
|
|
|
* FALSE: Failure, GetLastError can be called for further details
|
2001-07-10 21:16:49 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DisconnectNamedPipe(HANDLE hPipe)
|
|
|
|
{
|
2005-08-18 12:59:26 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK io_block;
|
2001-08-24 01:29:20 +02:00
|
|
|
|
2002-10-25 23:02:30 +02:00
|
|
|
TRACE("(%p)\n",hPipe);
|
2001-08-24 01:29:20 +02:00
|
|
|
|
2005-08-18 12:59:26 +02:00
|
|
|
status = NtFsControlFile(hPipe, 0, NULL, NULL, &io_block, FSCTL_PIPE_DISCONNECT,
|
|
|
|
NULL, 0, NULL, 0);
|
|
|
|
if (status == STATUS_SUCCESS) return TRUE;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2001-07-10 21:16:49 +02:00
|
|
|
}
|
|
|
|
|
2001-08-24 21:15:35 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* TransactNamedPipe (KERNEL32.@)
|
2005-01-19 18:00:48 +01:00
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* should be done as a single operation in the wineserver or kernel
|
2001-08-24 21:15:35 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI TransactNamedPipe(
|
2007-07-11 13:34:48 +02:00
|
|
|
HANDLE handle, LPVOID write_buf, DWORD write_size, LPVOID read_buf,
|
|
|
|
DWORD read_size, LPDWORD bytes_read, LPOVERLAPPED overlapped)
|
2001-08-24 21:15:35 +02:00
|
|
|
{
|
2005-01-19 18:00:48 +01:00
|
|
|
BOOL r;
|
|
|
|
DWORD count;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%p %p %d %p %d %p %p\n",
|
2007-07-11 13:34:48 +02:00
|
|
|
handle, write_buf, write_size, read_buf,
|
|
|
|
read_size, bytes_read, overlapped);
|
2005-01-19 18:00:48 +01:00
|
|
|
|
2007-07-11 13:34:48 +02:00
|
|
|
if (overlapped)
|
2005-01-19 18:00:48 +01:00
|
|
|
{
|
|
|
|
FIXME("Doesn't support overlapped operation as yet\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-07-11 13:34:48 +02:00
|
|
|
r = WriteFile(handle, write_buf, write_size, &count, NULL);
|
2005-01-19 18:00:48 +01:00
|
|
|
if (r)
|
2007-07-11 13:34:48 +02:00
|
|
|
r = ReadFile(handle, read_buf, read_size, bytes_read, NULL);
|
2005-01-19 18:00:48 +01:00
|
|
|
|
|
|
|
return r;
|
2001-08-24 21:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeInfo (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeInfo(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpFlags, LPDWORD lpOutputBufferSize,
|
|
|
|
LPDWORD lpInputBufferSize, LPDWORD lpMaxInstances)
|
|
|
|
{
|
2006-05-26 12:10:11 +02:00
|
|
|
FILE_PIPE_LOCAL_INFORMATION fpli;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
2001-08-27 21:03:42 +02:00
|
|
|
|
2006-05-26 12:10:11 +02:00
|
|
|
status = NtQueryInformationFile(hNamedPipe, &iosb, &fpli, sizeof(fpli),
|
|
|
|
FilePipeLocalInformation);
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-08-27 21:03:42 +02:00
|
|
|
|
2006-05-26 12:10:11 +02:00
|
|
|
if (lpFlags)
|
2001-08-27 21:03:42 +02:00
|
|
|
{
|
2006-05-26 12:10:11 +02:00
|
|
|
*lpFlags = (fpli.NamedPipeEnd & FILE_PIPE_SERVER_END) ?
|
|
|
|
PIPE_SERVER_END : PIPE_CLIENT_END;
|
|
|
|
*lpFlags |= (fpli.NamedPipeType & FILE_PIPE_TYPE_MESSAGE) ?
|
|
|
|
PIPE_TYPE_MESSAGE : PIPE_TYPE_BYTE;
|
2001-08-27 21:03:42 +02:00
|
|
|
}
|
|
|
|
|
2006-05-26 12:10:11 +02:00
|
|
|
if (lpOutputBufferSize) *lpOutputBufferSize = fpli.OutboundQuota;
|
|
|
|
if (lpInputBufferSize) *lpInputBufferSize = fpli.InboundQuota;
|
|
|
|
if (lpMaxInstances) *lpMaxInstances = fpli.MaximumInstances;
|
|
|
|
|
|
|
|
return TRUE;
|
2001-08-24 21:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeHandleStateA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeHandleStateA(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
|
|
|
|
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
|
|
|
|
LPSTR lpUsername, DWORD nUsernameMaxSize)
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME("%p %p %p %p %p %p %d\n",
|
2001-08-24 21:15:35 +02:00
|
|
|
hNamedPipe, lpState, lpCurInstances,
|
|
|
|
lpMaxCollectionCount, lpCollectDataTimeout,
|
|
|
|
lpUsername, nUsernameMaxSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-24 21:15:35 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeHandleStateW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeHandleStateW(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
|
|
|
|
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
|
|
|
|
LPWSTR lpUsername, DWORD nUsernameMaxSize)
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME("%p %p %p %p %p %p %d\n",
|
2001-08-24 21:15:35 +02:00
|
|
|
hNamedPipe, lpState, lpCurInstances,
|
|
|
|
lpMaxCollectionCount, lpCollectDataTimeout,
|
|
|
|
lpUsername, nUsernameMaxSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-08-24 21:15:35 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetNamedPipeHandleState (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetNamedPipeHandleState(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpMode, LPDWORD lpMaxCollectionCount,
|
|
|
|
LPDWORD lpCollectDataTimeout)
|
|
|
|
{
|
2005-06-05 20:03:38 +02:00
|
|
|
/* should be a fixme, but this function is called a lot by the RPC
|
|
|
|
* runtime, and it slows down InstallShield a fair bit. */
|
2006-10-12 22:56:29 +02:00
|
|
|
WARN("stub: %p %p/%d %p %p\n",
|
2005-06-05 20:03:38 +02:00
|
|
|
hNamedPipe, lpMode, lpMode ? *lpMode : 0, lpMaxCollectionCount, lpCollectDataTimeout);
|
2001-08-24 21:15:35 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CallNamedPipeA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CallNamedPipeA(
|
2004-10-19 23:08:58 +02:00
|
|
|
LPCSTR lpNamedPipeName, LPVOID lpInput, DWORD dwInputSize,
|
|
|
|
LPVOID lpOutput, DWORD dwOutputSize,
|
2001-08-24 21:15:35 +02:00
|
|
|
LPDWORD lpBytesRead, DWORD nTimeout)
|
|
|
|
{
|
2004-10-19 23:08:58 +02:00
|
|
|
DWORD len;
|
|
|
|
LPWSTR str = NULL;
|
|
|
|
BOOL ret;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%s %p %d %p %d %p %d\n",
|
2004-10-19 23:08:58 +02:00
|
|
|
debugstr_a(lpNamedPipeName), lpInput, dwInputSize,
|
|
|
|
lpOutput, dwOutputSize, lpBytesRead, nTimeout);
|
|
|
|
|
|
|
|
if( lpNamedPipeName )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, NULL, 0 );
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, str, len );
|
|
|
|
}
|
|
|
|
ret = CallNamedPipeW( str, lpInput, dwInputSize, lpOutput,
|
|
|
|
dwOutputSize, lpBytesRead, nTimeout );
|
|
|
|
if( lpNamedPipeName )
|
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
|
|
|
|
return ret;
|
2001-08-24 21:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CallNamedPipeW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CallNamedPipeW(
|
|
|
|
LPCWSTR lpNamedPipeName, LPVOID lpInput, DWORD lpInputSize,
|
|
|
|
LPVOID lpOutput, DWORD lpOutputSize,
|
|
|
|
LPDWORD lpBytesRead, DWORD nTimeout)
|
|
|
|
{
|
2007-03-05 13:06:02 +01:00
|
|
|
HANDLE pipe;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD mode;
|
|
|
|
|
|
|
|
TRACE("%s %p %d %p %d %p %d\n",
|
|
|
|
debugstr_w(lpNamedPipeName), lpInput, lpInputSize,
|
|
|
|
lpOutput, lpOutputSize, lpBytesRead, nTimeout);
|
|
|
|
|
|
|
|
pipe = CreateFileW(lpNamedPipeName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if (pipe == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ret = WaitNamedPipeW(lpNamedPipeName, nTimeout);
|
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
|
|
|
pipe = CreateFileW(lpNamedPipeName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if (pipe == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = PIPE_READMODE_MESSAGE;
|
|
|
|
ret = SetNamedPipeHandleState(pipe, &mode, NULL, NULL);
|
2007-07-11 13:39:03 +02:00
|
|
|
|
|
|
|
/* Currently SetNamedPipeHandleState() is a stub returning FALSE */
|
|
|
|
if (ret) FIXME("Now that SetNamedPipeHandleState() is more than a stub, please update CallNamedPipeW\n");
|
|
|
|
/*
|
2007-03-05 13:06:02 +01:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
CloseHandle(pipe);
|
|
|
|
return FALSE;
|
2007-07-11 13:39:03 +02:00
|
|
|
}*/
|
2007-03-05 13:06:02 +01:00
|
|
|
|
|
|
|
ret = TransactNamedPipe(pipe, lpInput, lpInputSize, lpOutput, lpOutputSize, lpBytesRead, NULL);
|
|
|
|
CloseHandle(pipe);
|
|
|
|
if (!ret)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2001-08-24 21:15:35 +02:00
|
|
|
}
|
2003-05-20 06:32:53 +02:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CreatePipe (KERNEL32.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
|
|
|
|
LPSECURITY_ATTRIBUTES sa, DWORD size )
|
|
|
|
{
|
2005-09-26 13:02:45 +02:00
|
|
|
static unsigned index /* = 0 */;
|
|
|
|
WCHAR name[64];
|
|
|
|
HANDLE hr, hw;
|
|
|
|
unsigned in_index = index;
|
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
LARGE_INTEGER timeout;
|
2003-05-20 06:32:53 +02:00
|
|
|
|
|
|
|
*hReadPipe = *hWritePipe = INVALID_HANDLE_VALUE;
|
2005-09-26 13:02:45 +02:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nt_name;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE |
|
2005-10-06 13:32:53 +02:00
|
|
|
((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
|
2005-09-26 13:02:45 +02:00
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
timeout.QuadPart = (ULONGLONG)NMPWAIT_USE_DEFAULT_WAIT * -10000;
|
2003-05-20 06:32:53 +02:00
|
|
|
/* generate a unique pipe name (system wide) */
|
|
|
|
do
|
|
|
|
{
|
2005-09-26 13:02:45 +02:00
|
|
|
static const WCHAR nameFmt[] = { '\\','?','?','\\','p','i','p','e',
|
2004-12-07 15:23:03 +01:00
|
|
|
'\\','W','i','n','3','2','.','P','i','p','e','s','.','%','0','8','l',
|
|
|
|
'u','.','%','0','8','u','\0' };
|
2005-09-26 13:02:45 +02:00
|
|
|
|
2004-12-07 15:23:03 +01:00
|
|
|
snprintfW(name, sizeof(name) / sizeof(name[0]), nameFmt,
|
|
|
|
GetCurrentProcessId(), ++index);
|
2005-09-26 13:02:45 +02:00
|
|
|
RtlInitUnicodeString(&nt_name, name);
|
|
|
|
status = NtCreateNamedPipeFile(&hr, GENERIC_READ | SYNCHRONIZE, &attr, &iosb,
|
|
|
|
0, FILE_OVERWRITE_IF,
|
|
|
|
FILE_SYNCHRONOUS_IO_ALERT | FILE_PIPE_INBOUND,
|
|
|
|
FALSE, FALSE, FALSE,
|
|
|
|
1, size, size, &timeout);
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
hr = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2003-05-20 06:32:53 +02:00
|
|
|
} while (hr == INVALID_HANDLE_VALUE && index != in_index);
|
|
|
|
/* from completion sakeness, I think system resources might be exhausted before this happens !! */
|
|
|
|
if (hr == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
|
2005-09-26 13:02:45 +02:00
|
|
|
status = NtOpenFile(&hw, GENERIC_WRITE | SYNCHRONIZE, &attr, &iosb, 0,
|
|
|
|
FILE_SYNCHRONOUS_IO_ALERT | FILE_NON_DIRECTORY_FILE);
|
|
|
|
|
|
|
|
if (status)
|
2003-05-20 06:32:53 +02:00
|
|
|
{
|
2005-09-26 13:02:45 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
NtClose(hr);
|
2003-05-20 06:32:53 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*hReadPipe = hr;
|
|
|
|
*hWritePipe = hw;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
|
2003-09-16 00:07:50 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateMailslotA [KERNEL32.@]
|
2005-11-08 12:01:03 +01:00
|
|
|
*
|
2007-12-18 14:15:23 +01:00
|
|
|
* See CreateMailslotW.
|
2003-09-16 00:07:50 +02:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
|
|
|
|
DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
HANDLE handle;
|
|
|
|
LPWSTR name = NULL;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%s %d %d %p\n", debugstr_a(lpName),
|
2003-09-16 00:07:50 +02:00
|
|
|
nMaxMessageSize, lReadTimeout, sa);
|
|
|
|
|
|
|
|
if( lpName )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpName, -1, NULL, 0 );
|
|
|
|
name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpName, -1, name, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
handle = CreateMailslotW( name, nMaxMessageSize, lReadTimeout, sa );
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, name );
|
2003-09-16 00:07:50 +02:00
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-17 22:05:03 +02:00
|
|
|
* CreateMailslotW [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Create a mailslot with specified name.
|
2003-09-16 00:07:50 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpName [I] Pointer to string for mailslot name
|
|
|
|
* nMaxMessageSize [I] Maximum message size
|
|
|
|
* lReadTimeout [I] Milliseconds before read time-out
|
|
|
|
* sa [I] Pointer to security structure
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Handle to mailslot
|
|
|
|
* Failure: INVALID_HANDLE_VALUE
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
|
|
|
|
DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
|
|
|
|
{
|
2005-03-28 12:03:56 +02:00
|
|
|
HANDLE handle = INVALID_HANDLE_VALUE;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
LARGE_INTEGER timeout;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%s %d %d %p\n", debugstr_w(lpName),
|
2003-09-16 00:07:50 +02:00
|
|
|
nMaxMessageSize, lReadTimeout, sa);
|
2005-03-28 12:03:56 +02:00
|
|
|
|
|
|
|
if (!RtlDosPathNameToNtPathName_U( lpName, &nameW, NULL, NULL ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_PATH_NOT_FOUND );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nameW.Length >= MAX_PATH * sizeof(WCHAR) )
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
RtlFreeUnicodeString( &nameW );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2005-11-21 16:23:49 +01:00
|
|
|
if (lReadTimeout != MAILSLOT_WAIT_FOREVER)
|
|
|
|
timeout.QuadPart = (ULONGLONG) lReadTimeout * -10000;
|
|
|
|
else
|
|
|
|
timeout.QuadPart = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
|
2005-03-28 12:03:56 +02:00
|
|
|
|
2007-04-10 22:24:40 +02:00
|
|
|
status = NtCreateMailslotFile( &handle, GENERIC_READ | SYNCHRONIZE, &attr,
|
2005-03-28 12:03:56 +02:00
|
|
|
&iosb, 0, 0, nMaxMessageSize, &timeout );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
handle = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlFreeUnicodeString( &nameW );
|
|
|
|
return handle;
|
2003-09-16 00:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-17 22:05:03 +02:00
|
|
|
* GetMailslotInfo [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Retrieve information about a mailslot.
|
2003-09-16 00:07:50 +02:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hMailslot [I] Mailslot handle
|
|
|
|
* lpMaxMessageSize [O] Address of maximum message size
|
|
|
|
* lpNextSize [O] Address of size of next message
|
|
|
|
* lpMessageCount [O] Address of number of messages
|
|
|
|
* lpReadTimeout [O] Address of read time-out
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
|
|
|
|
LPDWORD lpNextSize, LPDWORD lpMessageCount,
|
|
|
|
LPDWORD lpReadTimeout )
|
|
|
|
{
|
2005-04-11 16:20:49 +02:00
|
|
|
FILE_MAILSLOT_QUERY_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
2005-03-30 21:02:15 +02:00
|
|
|
|
2005-04-11 16:20:49 +02:00
|
|
|
TRACE("%p %p %p %p %p\n",hMailslot, lpMaxMessageSize,
|
|
|
|
lpNextSize, lpMessageCount, lpReadTimeout);
|
2005-03-30 21:02:15 +02:00
|
|
|
|
2005-04-11 16:20:49 +02:00
|
|
|
status = NtQueryInformationFile( hMailslot, &iosb, &info, sizeof info,
|
|
|
|
FileMailslotQueryInformation );
|
|
|
|
|
|
|
|
if( status != STATUS_SUCCESS )
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2005-04-11 16:20:49 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2005-04-11 16:20:49 +02:00
|
|
|
if( lpMaxMessageSize )
|
|
|
|
*lpMaxMessageSize = info.MaximumMessageSize;
|
|
|
|
if( lpNextSize )
|
|
|
|
*lpNextSize = info.NextMessageSize;
|
|
|
|
if( lpMessageCount )
|
|
|
|
*lpMessageCount = info.MessagesAvailable;
|
|
|
|
if( lpReadTimeout )
|
2007-04-17 20:08:59 +02:00
|
|
|
{
|
|
|
|
if (info.ReadTimeout.QuadPart == (((LONGLONG)0x7fffffff << 32) | 0xffffffff))
|
|
|
|
*lpReadTimeout = MAILSLOT_WAIT_FOREVER;
|
|
|
|
else
|
|
|
|
*lpReadTimeout = info.ReadTimeout.QuadPart / -10000;
|
|
|
|
}
|
2005-04-11 16:20:49 +02:00
|
|
|
return TRUE;
|
2003-09-16 00:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
2003-09-17 22:05:03 +02:00
|
|
|
* SetMailslotInfo [KERNEL32.@]
|
|
|
|
*
|
|
|
|
* Set the read timeout of a mailslot.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hMailslot [I] Mailslot handle
|
|
|
|
* dwReadTimeout [I] Timeout in milliseconds.
|
2003-09-16 00:07:50 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetMailslotInfo( HANDLE hMailslot, DWORD dwReadTimeout)
|
|
|
|
{
|
2005-04-11 16:20:49 +02:00
|
|
|
FILE_MAILSLOT_SET_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
2005-03-30 21:02:15 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%p %d\n", hMailslot, dwReadTimeout);
|
2005-03-30 21:02:15 +02:00
|
|
|
|
2007-04-17 20:08:59 +02:00
|
|
|
if (dwReadTimeout != MAILSLOT_WAIT_FOREVER)
|
|
|
|
info.ReadTimeout.QuadPart = (ULONGLONG)dwReadTimeout * -10000;
|
|
|
|
else
|
|
|
|
info.ReadTimeout.QuadPart = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
|
2005-04-11 16:20:49 +02:00
|
|
|
status = NtSetInformationFile( hMailslot, &iosb, &info, sizeof info,
|
|
|
|
FileMailslotSetInformation );
|
|
|
|
if( status != STATUS_SUCCESS )
|
2005-03-30 21:02:15 +02:00
|
|
|
{
|
2005-04-11 16:20:49 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
2005-03-30 21:02:15 +02:00
|
|
|
}
|
2005-04-11 16:20:49 +02:00
|
|
|
return TRUE;
|
2003-09-16 00:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 06:24:49 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateIoCompletionPort (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle, HANDLE hExistingCompletionPort,
|
2004-10-20 01:55:15 +02:00
|
|
|
ULONG_PTR CompletionKey, DWORD dwNumberOfConcurrentThreads)
|
2003-10-08 06:24:49 +02:00
|
|
|
{
|
2007-06-02 00:32:07 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE ret = 0;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %08lx, %08x)\n",
|
2004-10-20 01:55:15 +02:00
|
|
|
hFileHandle, hExistingCompletionPort, CompletionKey, dwNumberOfConcurrentThreads);
|
2003-10-08 06:24:49 +02:00
|
|
|
|
2007-06-02 00:32:07 +02:00
|
|
|
if (hExistingCompletionPort && hFileHandle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hExistingCompletionPort)
|
|
|
|
ret = hExistingCompletionPort;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = NtCreateIoCompletion( &ret, IO_COMPLETION_ALL_ACCESS, NULL, dwNumberOfConcurrentThreads );
|
|
|
|
if (status != STATUS_SUCCESS) goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hFileHandle != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
FILE_COMPLETION_INFORMATION info;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
|
|
|
|
info.CompletionPort = ret;
|
|
|
|
info.CompletionKey = CompletionKey;
|
|
|
|
status = NtSetInformationFile( hFileHandle, &iosb, &info, sizeof(info), FileCompletionInformation );
|
|
|
|
if (status != STATUS_SUCCESS) goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (ret && !hExistingCompletionPort)
|
|
|
|
CloseHandle( ret );
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-08 06:24:49 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GetQueuedCompletionStatus (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetQueuedCompletionStatus( HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
|
2004-10-20 01:55:15 +02:00
|
|
|
PULONG_PTR pCompletionKey, LPOVERLAPPED *lpOverlapped,
|
2003-10-08 06:24:49 +02:00
|
|
|
DWORD dwMilliseconds )
|
|
|
|
{
|
2007-06-02 00:32:07 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
LARGE_INTEGER wait_time;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p,%p,%d)\n",
|
2004-10-20 01:55:15 +02:00
|
|
|
CompletionPort,lpNumberOfBytesTransferred,pCompletionKey,lpOverlapped,dwMilliseconds);
|
2007-06-02 00:32:07 +02:00
|
|
|
|
|
|
|
*lpOverlapped = NULL;
|
|
|
|
|
|
|
|
status = NtRemoveIoCompletion( CompletionPort, pCompletionKey, (PULONG_PTR)lpOverlapped,
|
|
|
|
&iosb, get_nt_timeout( &wait_time, dwMilliseconds ) );
|
|
|
|
if (status == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
*lpNumberOfBytesTransferred = iosb.Information;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2003-10-08 06:24:49 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:32:07 +02:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* PostQueuedCompletionStatus (KERNEL32.@)
|
|
|
|
*/
|
2006-01-17 13:13:01 +01:00
|
|
|
BOOL WINAPI PostQueuedCompletionStatus( HANDLE CompletionPort, DWORD dwNumberOfBytes,
|
|
|
|
ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped)
|
|
|
|
{
|
2007-06-02 00:32:07 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("%p %d %08lx %p\n", CompletionPort, dwNumberOfBytes, dwCompletionKey, lpOverlapped );
|
|
|
|
|
|
|
|
status = NtSetIoCompletion( CompletionPort, dwCompletionKey, (ULONG_PTR)lpOverlapped,
|
|
|
|
STATUS_SUCCESS, dwNumberOfBytes );
|
|
|
|
|
|
|
|
if (status == STATUS_SUCCESS) return TRUE;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2006-01-17 13:13:01 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-30 22:29:18 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* BindIoCompletionCallback (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI BindIoCompletionCallback( HANDLE FileHandle, LPOVERLAPPED_COMPLETION_ROUTINE Function, ULONG Flags)
|
|
|
|
{
|
2007-12-19 22:27:44 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %d)\n", FileHandle, Function, Flags);
|
|
|
|
|
|
|
|
status = RtlSetIoCompletionCallback( FileHandle, (PRTL_OVERLAPPED_COMPLETION_ROUTINE)Function, Flags );
|
|
|
|
if (status == STATUS_SUCCESS) return TRUE;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
2007-04-30 22:29:18 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-03 23:12:15 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* CreateJobObjectW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES attr, LPCWSTR name )
|
|
|
|
{
|
|
|
|
FIXME("%p %s\n", attr, debugstr_w(name) );
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CreateJobObjectA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateJobObjectA( LPSECURITY_ATTRIBUTES attr, LPCSTR name )
|
|
|
|
{
|
|
|
|
LPWSTR str = NULL;
|
|
|
|
UINT len;
|
|
|
|
HANDLE r;
|
|
|
|
|
|
|
|
TRACE("%p %s\n", attr, debugstr_a(name) );
|
|
|
|
|
|
|
|
if( name )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
if( !str )
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, name, -1, str, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
r = CreateJobObjectW( attr, str );
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
2003-11-03 23:12:15 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* AssignProcessToJobObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI AssignProcessToJobObject( HANDLE hJob, HANDLE hProcess )
|
|
|
|
{
|
|
|
|
FIXME("%p %p\n", hJob, hProcess);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:34:15 +02:00
|
|
|
#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"
|
2004-06-14 19:00:21 +02:00
|
|
|
"ret $12")
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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"
|
2004-06-14 19:00:21 +02:00
|
|
|
"ret $8")
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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"
|
2004-06-14 19:00:21 +02:00
|
|
|
"ret $8")
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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"
|
2004-06-14 19:00:21 +02:00
|
|
|
"ret $4")
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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"
|
2004-06-14 19:00:21 +02:00
|
|
|
"ret $4")
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedCompareExchange (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Atomically swap one value with another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to replace
|
|
|
|
* xchq [I] The value to be swapped
|
|
|
|
* compare [I] The value to compare to dest
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* dest is updated only if it is equal to compare, otherwise no swap is done.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
2005-08-22 11:23:32 +02:00
|
|
|
LONG WINAPI InterlockedCompareExchange( LONG volatile *dest, LONG xchg, LONG compare )
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
return interlocked_cmpxchg( (int *)dest, xchg, compare );
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedExchange (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Atomically swap one value with another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to replace
|
|
|
|
* val [I] The value to be swapped
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
2005-08-22 11:23:32 +02:00
|
|
|
LONG WINAPI InterlockedExchange( LONG volatile *dest, LONG val )
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
return interlocked_xchg( (int *)dest, val );
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedExchangeAdd (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Atomically add one value to another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to add to
|
|
|
|
* incr [I] The value to be added
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
2005-08-22 11:23:32 +02:00
|
|
|
LONG WINAPI InterlockedExchangeAdd( LONG volatile *dest, LONG incr )
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
return interlocked_xchg_add( (int *)dest, incr );
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedIncrement (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Atomically increment a value.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to increment
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
2005-08-22 11:23:32 +02:00
|
|
|
LONG WINAPI InterlockedIncrement( LONG volatile *dest )
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
return interlocked_xchg_add( (int *)dest, 1 ) + 1;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedDecrement (KERNEL32.@)
|
2003-09-17 22:05:03 +02:00
|
|
|
*
|
|
|
|
* Atomically decrement a value.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dest [I/O] The value to decrement
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The resulting value of dest.
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
2005-08-22 11:23:32 +02:00
|
|
|
LONG WINAPI InterlockedDecrement( LONG volatile *dest )
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2005-09-26 15:51:58 +02:00
|
|
|
return interlocked_xchg_add( (int *)dest, -1 ) - 1;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|