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
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2015-03-12 10:39:31 +01:00
|
|
|
#define NONAMELESSUNION
|
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
|
|
|
|
2018-03-07 16:59:39 +01:00
|
|
|
#include "wine/library.h"
|
2001-07-20 20:00:00 +02:00
|
|
|
#include "wine/unicode.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 */
|
2013-10-24 00:40:22 +02:00
|
|
|
static inline BOOL 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 */
|
2018-03-02 10:51:31 +01:00
|
|
|
static HANDLE get_BaseNamedObjects_handle(void)
|
2005-12-02 15:55:48 +01:00
|
|
|
{
|
|
|
|
static HANDLE handle = NULL;
|
2016-07-18 08:38:30 +02:00
|
|
|
static const WCHAR basenameW[] = {'\\','S','e','s','s','i','o','n','s','\\','%','u',
|
|
|
|
'\\','B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s',0};
|
|
|
|
WCHAR buffer[64];
|
2005-12-02 15:55:48 +01:00
|
|
|
UNICODE_STRING str;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
|
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
HANDLE dir;
|
|
|
|
|
2016-07-18 08:38:30 +02:00
|
|
|
sprintfW( buffer, basenameW, NtCurrentTeb()->Peb->SessionId );
|
|
|
|
RtlInitUnicodeString( &str, buffer );
|
2005-12-02 15:55:48 +01:00
|
|
|
InitializeObjectAttributes(&attr, &str, 0, 0, NULL);
|
|
|
|
NtOpenDirectoryObject(&dir, DIRECTORY_CREATE_OBJECT|DIRECTORY_TRAVERSE,
|
|
|
|
&attr);
|
2009-03-11 09:39:16 +01:00
|
|
|
if (InterlockedCompareExchangePointer( &handle, dir, 0 ) != 0)
|
2005-12-02 15:55:48 +01:00
|
|
|
{
|
|
|
|
/* someone beat us here... */
|
|
|
|
CloseHandle( dir );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2018-03-02 10:41:12 +01:00
|
|
|
static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
|
|
|
|
SECURITY_ATTRIBUTES *sa, const WCHAR *name )
|
|
|
|
{
|
|
|
|
attr->Length = sizeof(*attr);
|
|
|
|
attr->RootDirectory = 0;
|
|
|
|
attr->ObjectName = NULL;
|
|
|
|
attr->Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
|
|
|
|
attr->SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
|
|
|
|
attr->SecurityQualityOfService = NULL;
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
RtlInitUnicodeString( nameW, name );
|
|
|
|
attr->ObjectName = nameW;
|
|
|
|
attr->RootDirectory = get_BaseNamedObjects_handle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 10:40:41 +01:00
|
|
|
static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
|
|
|
|
BOOL inherit, const WCHAR *name )
|
|
|
|
{
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RtlInitUnicodeString( nameW, name );
|
|
|
|
InitializeObjectAttributes( attr, nameW, inherit ? OBJ_INHERIT : 0,
|
|
|
|
get_BaseNamedObjects_handle(), NULL );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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.@)
|
|
|
|
*/
|
2012-03-08 15:00:29 +01:00
|
|
|
VOID WINAPI DECLSPEC_HOTPATCH Sleep( DWORD timeout )
|
2003-09-18 06:39:13 +02:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2016-08-16 20:35:27 +02:00
|
|
|
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) );
|
|
|
|
|
|
|
|
/* yes, even screen buffer console handles are waitable, and are
|
|
|
|
* handled as a handle to the console itself !!
|
|
|
|
*/
|
|
|
|
if (is_console_handle(handle))
|
|
|
|
{
|
|
|
|
if (VerifyConsoleIoHandle(handle))
|
|
|
|
handle = GetConsoleInputWaitHandle();
|
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
2003-09-18 06:39:13 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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++)
|
2016-08-16 20:35:27 +02:00
|
|
|
hloc[i] = normalize_handle_if_console(handles[i]);
|
2003-09-18 06:39:13 +02:00
|
|
|
|
2014-09-01 08:40:42 +02:00
|
|
|
status = NtWaitForMultipleObjects( count, hloc, !wait_all, alertable,
|
2007-06-02 00:30:01 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-16 20:35:27 +02:00
|
|
|
hObject = normalize_handle_if_console(hObject);
|
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
|
|
|
|
2016-08-16 20:35:27 +02:00
|
|
|
hObject = normalize_handle_if_console(hObject);
|
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 )
|
|
|
|
{
|
2008-09-11 11:49:40 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE("%p %p\n",WaitHandle, CompletionEvent);
|
|
|
|
|
|
|
|
status = RtlDeregisterWaitEx( WaitHandle, CompletionEvent );
|
|
|
|
if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2003-10-09 21:46:43 +02:00
|
|
|
}
|
|
|
|
|
2004-03-17 02:43:47 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SignalObjectAndWait (KERNEL32.@)
|
|
|
|
*
|
2012-05-15 10:15:32 +02:00
|
|
|
* Makes it possible to atomically signal any of the synchronization
|
|
|
|
* objects (semaphore, mutex, event) and wait on another.
|
2004-03-17 02:43:47 +01:00
|
|
|
*/
|
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 )
|
|
|
|
{
|
2008-06-20 09:19:09 +02:00
|
|
|
InitializeCriticalSectionEx( crit, 0, 0 );
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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 )
|
|
|
|
{
|
2008-06-20 09:19:09 +02:00
|
|
|
return InitializeCriticalSectionEx( crit, spincount, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InitializeCriticalSectionEx (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Initialise a critical section with a spin count and flags.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* crit [O] Critical section to initialise.
|
|
|
|
* spincount [I] Number of times to spin upon contention.
|
|
|
|
* flags [I] CRITICAL_SECTION_ flags from winbase.h.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: Nothing. If the function fails an exception is raised.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* spincount is ignored on uni-processor systems.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI InitializeCriticalSectionEx( CRITICAL_SECTION *crit, DWORD spincount, DWORD flags )
|
|
|
|
{
|
|
|
|
NTSTATUS ret = RtlInitializeCriticalSectionEx( crit, spincount, flags );
|
2003-06-24 05:34:15 +02:00
|
|
|
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 );
|
2019-04-30 12:19:22 +02:00
|
|
|
if (crit->DebugInfo != (void *)(ULONG_PTR)-1)
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, crit->DebugInfo );
|
2006-05-01 22:44:43 +02:00
|
|
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCSTR name )
|
2008-11-11 12:17:05 +01:00
|
|
|
{
|
|
|
|
DWORD flags = 0;
|
|
|
|
|
|
|
|
if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
|
|
|
|
if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
|
|
|
|
return CreateEventExA( sa, name, flags, EVENT_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateEventW (KERNEL32.@)
|
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
|
|
|
|
BOOL initial_state, LPCWSTR name )
|
2008-11-11 12:17:05 +01:00
|
|
|
{
|
|
|
|
DWORD flags = 0;
|
|
|
|
|
|
|
|
if (manual_reset) flags |= CREATE_EVENT_MANUAL_RESET;
|
|
|
|
if (initial_state) flags |= CREATE_EVENT_INITIAL_SET;
|
|
|
|
return CreateEventExW( sa, name, flags, EVENT_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateEventExA (KERNEL32.@)
|
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExA( SECURITY_ATTRIBUTES *sa, LPCSTR name, DWORD flags, DWORD access )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
2008-11-11 12:17:05 +01:00
|
|
|
if (!name) return CreateEventExW( sa, NULL, flags, access );
|
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;
|
|
|
|
}
|
2008-11-11 12:17:05 +01:00
|
|
|
return CreateEventExW( sa, buffer, flags, access );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-11-11 12:17:05 +01:00
|
|
|
* CreateEventExW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWORD flags, DWORD access )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2014-07-09 02:05:51 +02:00
|
|
|
HANDLE ret = 0;
|
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
|
|
|
|
2018-03-02 10:41:12 +01:00
|
|
|
get_create_object_attributes( &attr, &nameW, sa, name );
|
2004-12-02 19:05:37 +01:00
|
|
|
|
2010-01-18 20:34:54 +01:00
|
|
|
status = NtCreateEvent( &ret, access, &attr,
|
|
|
|
(flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent,
|
2008-11-11 12:17:05 +01:00
|
|
|
(flags & CREATE_EVENT_INITIAL_SET) != 0 );
|
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
|
|
|
* OpenEventA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW( DWORD access, BOOL inherit, 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;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = EVENT_ALL_ACCESS;
|
|
|
|
|
2018-03-02 10:40:41 +01:00
|
|
|
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH PulseEvent( HANDLE handle )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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-06-13 22:13:18 +02:00
|
|
|
* SetEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent( HANDLE handle )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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-06-13 22:13:18 +02:00
|
|
|
* ResetEvent (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent( HANDLE handle )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateMutexA (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
|
2008-11-11 12:17:05 +01:00
|
|
|
{
|
|
|
|
return CreateMutexExA( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateMutexW (KERNEL32.@)
|
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
|
2008-11-11 12:17:05 +01:00
|
|
|
{
|
|
|
|
return CreateMutexExW( sa, name, owner ? CREATE_MUTEX_INITIAL_OWNER : 0, MUTEX_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateMutexExA (KERNEL32.@)
|
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExA( SECURITY_ATTRIBUTES *sa, LPCSTR name, DWORD flags, DWORD access )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2010-02-23 16:41:27 +01:00
|
|
|
ANSI_STRING nameA;
|
|
|
|
NTSTATUS status;
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2008-11-11 12:17:05 +01:00
|
|
|
if (!name) return CreateMutexExW( sa, NULL, flags, access );
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2010-02-23 16:41:27 +01:00
|
|
|
RtlInitAnsiString( &nameA, name );
|
|
|
|
status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString, &nameA, FALSE );
|
|
|
|
if (status != STATUS_SUCCESS)
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2010-02-23 16:41:27 +01:00
|
|
|
return CreateMutexExW( sa, NtCurrentTeb()->StaticUnicodeString.Buffer, flags, access );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-11-11 12:17:05 +01:00
|
|
|
* CreateMutexExW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWORD flags, DWORD access )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2014-07-09 02:05:51 +02:00
|
|
|
HANDLE ret = 0;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2018-03-02 10:41:12 +01:00
|
|
|
get_create_object_attributes( &attr, &nameW, sa, name );
|
2004-12-02 19:05:37 +01:00
|
|
|
|
2008-11-11 12:17:05 +01:00
|
|
|
status = NtCreateMutant( &ret, access, &attr, (flags & CREATE_MUTEX_INITIAL_OWNER) != 0 );
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexW( DWORD access, BOOL inherit, 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;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
|
|
|
|
|
2018-03-02 10:40:41 +01:00
|
|
|
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex( HANDLE handle )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
|
2008-11-11 12:17:05 +01:00
|
|
|
{
|
|
|
|
return CreateSemaphoreExA( sa, initial, max, name, 0, SEMAPHORE_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateSemaphoreW (KERNEL32.@)
|
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCWSTR name )
|
2008-11-11 12:17:05 +01:00
|
|
|
{
|
|
|
|
return CreateSemaphoreExW( sa, initial, max, name, 0, SEMAPHORE_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateSemaphoreExA (KERNEL32.@)
|
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreExA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max,
|
|
|
|
LPCSTR name, DWORD flags, DWORD access )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2008-11-11 12:17:05 +01:00
|
|
|
if (!name) return CreateSemaphoreExW( sa, initial, max, NULL, flags, access );
|
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;
|
|
|
|
}
|
2008-11-11 12:17:05 +01:00
|
|
|
return CreateSemaphoreExW( sa, initial, max, buffer, flags, access );
|
2000-09-29 22:48:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-11-11 12:17:05 +01:00
|
|
|
* CreateSemaphoreExW (KERNEL32.@)
|
2000-09-29 22:48:04 +02:00
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreExW( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max,
|
|
|
|
LPCWSTR name, DWORD flags, DWORD access )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
2014-07-08 05:08:39 +02:00
|
|
|
HANDLE ret = 0;
|
2004-12-02 19:05:37 +01:00
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2018-03-02 10:41:12 +01:00
|
|
|
get_create_object_attributes( &attr, &nameW, sa, name );
|
2000-09-29 22:48:04 +02:00
|
|
|
|
2008-11-11 12:17:05 +01:00
|
|
|
status = NtCreateSemaphore( &ret, 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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreW( DWORD access, BOOL inherit, 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;
|
|
|
|
|
|
|
|
if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
|
|
|
|
|
2018-03-02 10:40:41 +01:00
|
|
|
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
|
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
|
|
|
*/
|
2013-04-10 23:54:08 +02:00
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
|
2000-09-29 22:48:04 +02:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-04 22:51:02 +02:00
|
|
|
/*
|
|
|
|
* Jobs
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CreateJobObjectW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES sa, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret = 0;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2018-03-02 10:41:12 +01:00
|
|
|
get_create_object_attributes( &attr, &nameW, sa, name );
|
2008-09-04 22:51:02 +02:00
|
|
|
|
|
|
|
status = NtCreateJobObject( &ret, JOB_OBJECT_ALL_ACCESS, &attr );
|
|
|
|
if (status == STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
SetLastError( ERROR_ALREADY_EXISTS );
|
|
|
|
else
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* CreateJobObjectA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateJobObjectA( LPSECURITY_ATTRIBUTES attr, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateJobObjectW( attr, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return CreateJobObjectW( attr, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* OpenJobObjectW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenJobObjectW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2018-03-02 10:40:41 +01:00
|
|
|
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
|
2008-09-04 22:51:02 +02:00
|
|
|
|
|
|
|
status = NtOpenJobObject( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* OpenJobObjectA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenJobObjectA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenJobObjectW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return OpenJobObjectW( access, inherit, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TerminateJobObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI TerminateJobObject( HANDLE job, UINT exit_code )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtTerminateJobObject( job, exit_code );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* QueryInformationJobObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueryInformationJobObject( HANDLE job, JOBOBJECTINFOCLASS class, LPVOID info,
|
|
|
|
DWORD len, DWORD *ret_len )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtQueryInformationJobObject( job, class, info, len, ret_len );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* SetInformationJobObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetInformationJobObject( HANDLE job, JOBOBJECTINFOCLASS class, LPVOID info, DWORD len )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtSetInformationJobObject( job, class, info, len );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* AssignProcessToJobObject (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI AssignProcessToJobObject( HANDLE job, HANDLE process )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtAssignProcessToJobObject( job, process );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* IsProcessInJob (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsProcessInJob( HANDLE process, HANDLE job, PBOOL result )
|
|
|
|
{
|
2013-09-06 08:13:12 +02:00
|
|
|
NTSTATUS status = NtIsProcessInJob( process, job );
|
2008-09-04 22:51:02 +02:00
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case STATUS_PROCESS_IN_JOB:
|
|
|
|
*result = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
case STATUS_PROCESS_NOT_IN_JOB:
|
|
|
|
*result = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-20 06:14:45 +02:00
|
|
|
/*
|
|
|
|
* Timers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
|
2008-11-11 12:17:05 +01:00
|
|
|
{
|
|
|
|
return CreateWaitableTimerExA( sa, name, manual ? CREATE_WAITABLE_TIMER_MANUAL_RESET : 0,
|
|
|
|
TIMER_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
|
|
|
|
{
|
|
|
|
return CreateWaitableTimerExW( sa, name, manual ? CREATE_WAITABLE_TIMER_MANUAL_RESET : 0,
|
|
|
|
TIMER_ALL_ACCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerExA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerExA( SECURITY_ATTRIBUTES *sa, LPCSTR name, DWORD flags, DWORD access )
|
2003-05-20 06:14:45 +02:00
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
2008-11-11 12:17:05 +01:00
|
|
|
if (!name) return CreateWaitableTimerExW( sa, NULL, flags, access );
|
2003-05-20 06:14:45 +02:00
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-11 12:17:05 +01:00
|
|
|
return CreateWaitableTimerExW( sa, buffer, flags, access );
|
2003-05-20 06:14:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-11-11 12:17:05 +01:00
|
|
|
* CreateWaitableTimerExW (KERNEL32.@)
|
2003-05-20 06:14:45 +02:00
|
|
|
*/
|
2008-11-11 12:17:05 +01:00
|
|
|
HANDLE WINAPI CreateWaitableTimerExW( SECURITY_ATTRIBUTES *sa, LPCWSTR name, DWORD flags, DWORD access )
|
2003-05-20 06:14:45 +02:00
|
|
|
{
|
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
|
|
|
|
2018-03-02 10:41:12 +01:00
|
|
|
get_create_object_attributes( &attr, &nameW, sa, name );
|
2004-12-02 19:05:37 +01:00
|
|
|
|
2008-11-11 12:17:05 +01:00
|
|
|
status = NtCreateTimer( &handle, access, &attr,
|
|
|
|
(flags & CREATE_WAITABLE_TIMER_MANUAL_RESET) ? 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
|
|
|
|
2018-03-02 10:40:41 +01:00
|
|
|
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-22 08:09:18 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetWaitableTimerEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetWaitableTimerEx( HANDLE handle, const LARGE_INTEGER *when, LONG period,
|
|
|
|
PTIMERAPCROUTINE callback, LPVOID arg, REASON_CONTEXT *context, ULONG tolerabledelay )
|
|
|
|
{
|
2014-04-03 05:25:38 +02:00
|
|
|
static int once;
|
|
|
|
if (!once++)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %d, %p, %p, %p, %d) semi-stub\n",
|
|
|
|
handle, when, period, callback, arg, context, tolerabledelay);
|
|
|
|
}
|
2014-03-22 08:09:18 +01:00
|
|
|
return SetWaitableTimer(handle, when, period, callback, arg, FALSE);
|
|
|
|
}
|
2003-05-20 06:14:45 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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)
|
|
|
|
{
|
2008-07-22 02:46:30 +02:00
|
|
|
HANDLE q;
|
|
|
|
NTSTATUS status = RtlCreateTimerQueue(&q);
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return q;
|
2003-05-20 06:14:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteTimerQueueEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
|
|
|
|
{
|
2008-07-22 02:46:30 +02:00
|
|
|
NTSTATUS status = RtlDeleteTimerQueueEx(TimerQueue, CompletionEvent);
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2003-05-20 06:14:45 +02:00
|
|
|
}
|
|
|
|
|
2009-01-22 18:55:35 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DeleteTimerQueue (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueue(HANDLE TimerQueue)
|
|
|
|
{
|
|
|
|
return DeleteTimerQueueEx(TimerQueue, NULL);
|
|
|
|
}
|
|
|
|
|
2003-05-20 06:14:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
|
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Parameter,
|
|
|
|
DWORD DueTime, DWORD Period, ULONG Flags )
|
|
|
|
{
|
2008-07-23 03:10:08 +02:00
|
|
|
NTSTATUS status = RtlCreateTimer(phNewTimer, TimerQueue, Callback,
|
|
|
|
Parameter, DueTime, Period, Flags);
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-05-20 06:14:45 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-07-22 02:42:03 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ChangeTimerQueueTimer (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Changes the times at which the timer expires.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* nonzero on success or zero on failure
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ChangeTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
|
|
|
|
ULONG DueTime, ULONG Period )
|
|
|
|
{
|
2008-07-25 01:27:03 +02:00
|
|
|
NTSTATUS status = RtlUpdateTimer(TimerQueue, Timer, DueTime, Period);
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2008-07-22 02:42:03 +02:00
|
|
|
}
|
|
|
|
|
2014-10-25 08:03:01 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* CancelTimerQueueTimer (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CancelTimerQueueTimer(HANDLE queue, HANDLE timer)
|
|
|
|
{
|
|
|
|
FIXME("stub: %p %p\n", queue, timer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-05-20 06:14:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
|
|
|
|
HANDLE CompletionEvent )
|
|
|
|
{
|
2008-07-25 01:27:54 +02:00
|
|
|
NTSTATUS status = RtlDeleteTimer(TimerQueue, Timer, CompletionEvent);
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-20 06:14:45 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-02 10:51:31 +01:00
|
|
|
/*
|
|
|
|
* Mappings
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateFileMappingA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateFileMappingA( HANDLE file, SECURITY_ATTRIBUTES *sa, DWORD protect,
|
|
|
|
DWORD size_high, DWORD size_low, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateFileMappingW( file, sa, protect, size_high, size_low, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return CreateFileMappingW( file, sa, protect, size_high, size_low, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateFileMappingW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateFileMappingW( HANDLE file, LPSECURITY_ATTRIBUTES sa, DWORD protect,
|
|
|
|
DWORD size_high, DWORD size_low, LPCWSTR name )
|
|
|
|
{
|
|
|
|
static const int sec_flags = (SEC_FILE | SEC_IMAGE | SEC_RESERVE | SEC_COMMIT |
|
|
|
|
SEC_NOCACHE | SEC_WRITECOMBINE | SEC_LARGE_PAGES);
|
|
|
|
HANDLE ret;
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD access, sec_type;
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
|
|
|
|
sec_type = protect & sec_flags;
|
|
|
|
protect &= ~sec_flags;
|
|
|
|
if (!sec_type) sec_type = SEC_COMMIT;
|
|
|
|
|
|
|
|
/* Win9x compatibility */
|
|
|
|
if (!protect && !is_version_nt()) protect = PAGE_READONLY;
|
|
|
|
|
|
|
|
switch(protect)
|
|
|
|
{
|
|
|
|
case PAGE_READONLY:
|
|
|
|
case PAGE_WRITECOPY:
|
|
|
|
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ;
|
|
|
|
break;
|
|
|
|
case PAGE_READWRITE:
|
|
|
|
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE;
|
|
|
|
break;
|
|
|
|
case PAGE_EXECUTE_READ:
|
|
|
|
case PAGE_EXECUTE_WRITECOPY:
|
|
|
|
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE;
|
|
|
|
break;
|
|
|
|
case PAGE_EXECUTE_READWRITE:
|
|
|
|
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size.u.LowPart = size_low;
|
|
|
|
size.u.HighPart = size_high;
|
|
|
|
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
file = 0;
|
|
|
|
if (!size.QuadPart)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get_create_object_attributes( &attr, &nameW, sa, name );
|
|
|
|
|
|
|
|
status = NtCreateSection( &ret, access, &attr, &size, protect, sec_type, file );
|
|
|
|
if (status == STATUS_OBJECT_NAME_EXISTS)
|
|
|
|
SetLastError( ERROR_ALREADY_EXISTS );
|
|
|
|
else
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenFileMappingA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenFileMappingA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenFileMappingW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return OpenFileMappingW( access, inherit, buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenFileMappingW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
HANDLE ret;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
|
|
|
|
|
|
|
|
if (access == FILE_MAP_COPY) access = SECTION_MAP_READ;
|
|
|
|
|
|
|
|
if (!is_version_nt())
|
|
|
|
{
|
|
|
|
/* win9x doesn't do access checks, so try with full access first */
|
|
|
|
if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = NtOpenSection( &ret, access, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2011-09-26 13:57:15 +02:00
|
|
|
DWORD access, options, sharing;
|
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:
|
2011-09-26 13:57:15 +02:00
|
|
|
sharing = FILE_SHARE_WRITE;
|
2007-04-16 14:32:18 +02:00
|
|
|
access = GENERIC_READ;
|
|
|
|
break;
|
|
|
|
case PIPE_ACCESS_OUTBOUND:
|
2011-09-26 13:57:15 +02:00
|
|
|
sharing = FILE_SHARE_READ;
|
2007-04-16 14:32:18 +02:00
|
|
|
access = GENERIC_WRITE;
|
|
|
|
break;
|
|
|
|
case PIPE_ACCESS_DUPLEX:
|
2011-09-26 13:57:15 +02:00
|
|
|
sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
2007-04-16 14:32:18 +02:00
|
|
|
access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
access |= SYNCHRONIZE;
|
2011-09-26 13:57:15 +02:00
|
|
|
options = 0;
|
2014-02-05 16:35:30 +01:00
|
|
|
if (dwOpenMode & WRITE_DAC) access |= WRITE_DAC;
|
|
|
|
if (dwOpenMode & WRITE_OWNER) access |= WRITE_OWNER;
|
|
|
|
if (dwOpenMode & ACCESS_SYSTEM_SECURITY) access |= ACCESS_SYSTEM_SECURITY;
|
2005-04-18 16:57:04 +02:00
|
|
|
if (dwOpenMode & FILE_FLAG_WRITE_THROUGH) options |= FILE_WRITE_THROUGH;
|
2011-08-22 11:02:51 +02:00
|
|
|
if (!(dwOpenMode & FILE_FLAG_OVERLAPPED)) options |= FILE_SYNCHRONOUS_IO_NONALERT;
|
2013-03-12 10:28:04 +01:00
|
|
|
pipe_type = (dwPipeMode & PIPE_TYPE_MESSAGE) != 0;
|
|
|
|
read_mode = (dwPipeMode & PIPE_READMODE_MESSAGE) != 0;
|
|
|
|
non_block = (dwPipeMode & PIPE_NOWAIT) != 0;
|
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
|
|
|
|
2011-09-26 13:57:15 +02:00
|
|
|
status = NtCreateNamedPipeFile(&handle, access, &attr, &iosb, sharing,
|
2007-04-16 14:32:18 +02:00
|
|
|
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] ) );
|
2018-10-20 19:18:06 +02:00
|
|
|
if (status == STATUS_BUFFER_OVERFLOW) status = STATUS_SUCCESS;
|
2006-11-01 16:24:36 +01:00
|
|
|
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;
|
2017-05-21 15:53:51 +02:00
|
|
|
if (lpcbMessage) *lpcbMessage = buffer->MessageLength - read_size;
|
2006-11-01 16:24:36 +01:00
|
|
|
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 );
|
2013-10-24 00:40:22 +02:00
|
|
|
return FALSE;
|
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) ||
|
2018-07-30 21:18:09 +02:00
|
|
|
strncmpiW( nt_name.Buffer, leadin, ARRAY_SIZE( leadin )) != 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);
|
2015-10-30 12:54:18 +01:00
|
|
|
status = NtOpenFile( &pipe_dev, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr,
|
2005-12-14 11:14:02 +01:00
|
|
|
&iosb, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
2016-09-14 07:45:30 +02:00
|
|
|
if (status != STATUS_SUCCESS)
|
2001-11-30 19:46:42 +01:00
|
|
|
{
|
2011-12-06 21:51:45 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, pipe_wait);
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
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);
|
2018-07-30 21:18:09 +02:00
|
|
|
memcpy( pipe_wait->Name, nt_name.Buffer + ARRAY_SIZE( leadin ), 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);
|
2018-10-30 16:08:22 +01:00
|
|
|
if (status == STATUS_PENDING && !overlapped)
|
|
|
|
{
|
|
|
|
WaitForSingleObject(hPipe, INFINITE);
|
|
|
|
status = status_block.u.Status;
|
|
|
|
}
|
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.@)
|
|
|
|
*/
|
|
|
|
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
|
|
|
{
|
2018-03-28 22:46:51 +02:00
|
|
|
IO_STATUS_BLOCK default_iosb, *iosb = &default_iosb;
|
|
|
|
HANDLE event = NULL;
|
|
|
|
void *cvalue = NULL;
|
|
|
|
NTSTATUS status;
|
2005-01-19 18:00:48 +01:00
|
|
|
|
2018-03-28 22:46:51 +02:00
|
|
|
TRACE("%p %p %u %p %u %p %p\n", handle, write_buf, write_size, read_buf,
|
2007-07-11 13:34:48 +02:00
|
|
|
read_size, bytes_read, overlapped);
|
2005-01-19 18:00:48 +01:00
|
|
|
|
2007-07-11 13:34:48 +02:00
|
|
|
if (overlapped)
|
2018-03-28 22:46:51 +02:00
|
|
|
{
|
|
|
|
event = overlapped->hEvent;
|
|
|
|
iosb = (IO_STATUS_BLOCK *)overlapped;
|
|
|
|
if (((ULONG_PTR)event & 1) == 0) cvalue = overlapped;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iosb->Information = 0;
|
|
|
|
}
|
2005-01-19 18:00:48 +01:00
|
|
|
|
2018-03-28 22:46:51 +02:00
|
|
|
status = NtFsControlFile(handle, event, NULL, cvalue, iosb, FSCTL_PIPE_TRANSCEIVE,
|
|
|
|
write_buf, write_size, read_buf, read_size);
|
2018-10-30 16:08:27 +01:00
|
|
|
if (status == STATUS_PENDING && !overlapped)
|
|
|
|
{
|
|
|
|
WaitForSingleObject(handle, INFINITE);
|
|
|
|
status = iosb->u.Status;
|
|
|
|
}
|
2005-01-19 18:00:48 +01:00
|
|
|
|
2018-03-28 22:46:51 +02:00
|
|
|
if (bytes_read) *bytes_read = overlapped && status ? 0 : iosb->Information;
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError(RtlNtStatusToDosError(status));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
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
|
|
|
}
|
|
|
|
|
2018-04-11 14:32:56 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeClientProcessId (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeClientProcessId( HANDLE pipe, ULONG *id )
|
|
|
|
{
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "%p %p\n", pipe, id );
|
|
|
|
|
|
|
|
status = NtFsControlFile( pipe, NULL, NULL, NULL, &iosb, FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE,
|
|
|
|
(void *)"ClientProcessId", sizeof("ClientProcessId"), id, sizeof(*id) );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeServerProcessId (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeServerProcessId( HANDLE pipe, ULONG *id )
|
|
|
|
{
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "%p, %p\n", pipe, id );
|
|
|
|
|
|
|
|
status = NtFsControlFile( pipe, NULL, NULL, NULL, &iosb, FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE,
|
|
|
|
(void *)"ServerProcessId", sizeof("ServerProcessId"), id, sizeof(*id) );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-04-11 14:32:57 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeClientSessionId (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeClientSessionId( HANDLE pipe, ULONG *id )
|
|
|
|
{
|
|
|
|
FIXME( "%p, %p\n", pipe, id );
|
|
|
|
|
|
|
|
if (!id) return FALSE;
|
|
|
|
*id = NtCurrentTeb()->Peb->SessionId;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeServerSessionId (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeServerSessionId( HANDLE pipe, ULONG *id )
|
|
|
|
{
|
|
|
|
FIXME( "%p, %p\n", pipe, id );
|
|
|
|
|
|
|
|
if (!id) return FALSE;
|
|
|
|
*id = NtCurrentTeb()->Peb->SessionId;
|
|
|
|
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)
|
|
|
|
{
|
2018-03-07 16:59:39 +01:00
|
|
|
WCHAR *username = NULL;
|
|
|
|
BOOL ret;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2018-03-07 16:59:39 +01:00
|
|
|
WARN("%p %p %p %p %p %p %d: semi-stub\n", hNamedPipe, lpState, lpCurInstances,
|
|
|
|
lpMaxCollectionCount, lpCollectDataTimeout, lpUsername, nUsernameMaxSize);
|
|
|
|
|
|
|
|
if (lpUsername && nUsernameMaxSize &&
|
|
|
|
!(username = HeapAlloc(GetProcessHeap(), 0, nUsernameMaxSize * sizeof(WCHAR)))) return FALSE;
|
|
|
|
|
|
|
|
ret = GetNamedPipeHandleStateW(hNamedPipe, lpState, lpCurInstances, lpMaxCollectionCount,
|
|
|
|
lpCollectDataTimeout, username, nUsernameMaxSize);
|
|
|
|
if (ret && username)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, username, -1, lpUsername, nUsernameMaxSize, NULL, NULL);
|
2014-08-11 17:26:18 +02:00
|
|
|
|
2018-03-07 16:59:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, username);
|
|
|
|
return ret;
|
2001-08-24 21:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNamedPipeHandleStateW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNamedPipeHandleStateW(
|
|
|
|
HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
|
|
|
|
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
|
|
|
|
LPWSTR lpUsername, DWORD nUsernameMaxSize)
|
|
|
|
{
|
2014-08-11 17:26:18 +02:00
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2018-03-07 16:59:39 +01:00
|
|
|
FIXME("%p %p %p %p %p %p %d: semi-stub\n", hNamedPipe, lpState, lpCurInstances,
|
|
|
|
lpMaxCollectionCount, lpCollectDataTimeout, lpUsername, nUsernameMaxSize);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2014-08-11 17:26:18 +02:00
|
|
|
if (lpMaxCollectionCount)
|
|
|
|
*lpMaxCollectionCount = 0;
|
|
|
|
|
|
|
|
if (lpCollectDataTimeout)
|
|
|
|
*lpCollectDataTimeout = 0;
|
|
|
|
|
|
|
|
if (lpUsername && nUsernameMaxSize)
|
2018-03-07 16:59:39 +01:00
|
|
|
{
|
|
|
|
const char *username = wine_get_user_name();
|
|
|
|
int len = MultiByteToWideChar(CP_UNIXCP, 0, username, -1, lpUsername, nUsernameMaxSize);
|
|
|
|
if (!len) *lpUsername = 0;
|
|
|
|
}
|
2014-08-11 17:26:18 +02:00
|
|
|
|
|
|
|
if (lpState)
|
|
|
|
{
|
|
|
|
FILE_PIPE_INFORMATION fpi;
|
|
|
|
status = NtQueryInformationFile(hNamedPipe, &iosb, &fpi, sizeof(fpi),
|
|
|
|
FilePipeInformation);
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lpState = (fpi.ReadMode ? PIPE_READMODE_MESSAGE : PIPE_READMODE_BYTE) |
|
|
|
|
(fpi.CompletionMode ? PIPE_NOWAIT : PIPE_WAIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpCurInstances)
|
|
|
|
{
|
|
|
|
FILE_PIPE_LOCAL_INFORMATION fpli;
|
|
|
|
status = NtQueryInformationFile(hNamedPipe, &iosb, &fpli, sizeof(fpli),
|
|
|
|
FilePipeLocalInformation);
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*lpCurInstances = fpli.CurrentInstances;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-08-24 21:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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. */
|
2014-08-21 05:41:15 +02:00
|
|
|
WARN("semi-stub: %p %p/%d %p %p\n",
|
2005-06-05 20:03:38 +02:00
|
|
|
hNamedPipe, lpMode, lpMode ? *lpMode : 0, lpMaxCollectionCount, lpCollectDataTimeout);
|
2014-08-21 05:41:15 +02:00
|
|
|
|
|
|
|
if (lpMode)
|
|
|
|
{
|
|
|
|
FILE_PIPE_INFORMATION fpi;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (*lpMode & ~(PIPE_READMODE_MESSAGE | PIPE_NOWAIT))
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fpi.CompletionMode = (*lpMode & PIPE_NOWAIT) ?
|
|
|
|
FILE_PIPE_COMPLETE_OPERATION : FILE_PIPE_QUEUE_OPERATION;
|
|
|
|
fpi.ReadMode = (*lpMode & PIPE_READMODE_MESSAGE) ?
|
|
|
|
FILE_PIPE_MESSAGE_MODE : FILE_PIPE_BYTE_STREAM_MODE;
|
|
|
|
status = NtSetInformationFile(hNamedPipe, &iosb, &fpi, sizeof(fpi), FilePipeInformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2001-08-24 21:15:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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);
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
CloseHandle(pipe);
|
|
|
|
return FALSE;
|
2014-08-21 05:41:15 +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;
|
|
|
|
|
2017-03-30 14:02:49 +02:00
|
|
|
if (!size) size = 4096;
|
|
|
|
|
2005-09-26 13:02:45 +02:00
|
|
|
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
|
|
|
|
2018-07-30 21:18:09 +02:00
|
|
|
snprintfW(name, ARRAY_SIZE(name), nameFmt, GetCurrentProcessId(), ++index);
|
2005-09-26 13:02:45 +02:00
|
|
|
RtlInitUnicodeString(&nt_name, name);
|
2018-08-20 19:29:30 +02:00
|
|
|
status = NtCreateNamedPipeFile(&hr, GENERIC_READ | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
|
|
|
|
&attr, &iosb, FILE_SHARE_WRITE, FILE_OVERWRITE_IF,
|
2011-09-26 13:57:15 +02:00
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT,
|
2005-09-26 13:02:45 +02:00
|
|
|
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;
|
|
|
|
|
2018-08-20 19:29:30 +02:00
|
|
|
status = NtOpenFile(&hw, GENERIC_WRITE | FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb, 0,
|
2011-08-22 11:02:51 +02:00
|
|
|
FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
|
2005-09-26 13:02:45 +02:00
|
|
|
|
|
|
|
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;
|
2009-10-27 16:52:35 +01:00
|
|
|
if (iosb.u.Status >= 0) return TRUE;
|
|
|
|
SetLastError( RtlNtStatusToDosError(iosb.u.Status) );
|
|
|
|
return FALSE;
|
2007-06-02 00:32:07 +02:00
|
|
|
}
|
|
|
|
|
2009-03-02 20:35:23 +01:00
|
|
|
if (status == STATUS_TIMEOUT) SetLastError( WAIT_TIMEOUT );
|
|
|
|
else SetLastError( RtlNtStatusToDosError(status) );
|
2003-10-08 06:24:49 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-09-30 23:59:49 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* GetQueuedCompletionStatusEx (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetQueuedCompletionStatusEx( HANDLE port, OVERLAPPED_ENTRY *entries, ULONG count,
|
|
|
|
ULONG *written, DWORD timeout, BOOL alertable )
|
|
|
|
{
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
NTSTATUS ret;
|
|
|
|
|
|
|
|
TRACE("%p %p %u %p %u %u\n", port, entries, count, written, timeout, alertable);
|
|
|
|
|
|
|
|
ret = NtRemoveIoCompletionEx( port, (FILE_IO_COMPLETION_INFORMATION *)entries, count,
|
|
|
|
written, get_nt_timeout( &time, timeout ), alertable );
|
|
|
|
if (ret == STATUS_SUCCESS) return TRUE;
|
|
|
|
else if (ret == STATUS_TIMEOUT) SetLastError( WAIT_TIMEOUT );
|
|
|
|
else if (ret == STATUS_USER_APC) SetLastError( WAIT_IO_COMPLETION );
|
|
|
|
else SetLastError( RtlNtStatusToDosError(ret) );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-14 09:58:47 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateMemoryResourceNotification (KERNEL32.@)
|
|
|
|
*/
|
2012-03-12 10:33:32 +01:00
|
|
|
HANDLE WINAPI CreateMemoryResourceNotification(MEMORY_RESOURCE_NOTIFICATION_TYPE type)
|
|
|
|
{
|
|
|
|
static const WCHAR lowmemW[] =
|
|
|
|
{'\\','K','e','r','n','e','l','O','b','j','e','c','t','s',
|
|
|
|
'\\','L','o','w','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n',0};
|
|
|
|
static const WCHAR highmemW[] =
|
|
|
|
{'\\','K','e','r','n','e','l','O','b','j','e','c','t','s',
|
|
|
|
'\\','H','i','g','h','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n',0};
|
|
|
|
HANDLE ret;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case LowMemoryResourceNotification:
|
|
|
|
RtlInitUnicodeString( &nameW, lowmemW );
|
|
|
|
break;
|
|
|
|
case HighMemoryResourceNotification:
|
|
|
|
RtlInitUnicodeString( &nameW, highmemW );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
status = NtOpenEvent( &ret, EVENT_ALL_ACCESS, &attr );
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ret;
|
2009-11-14 09:58:47 +01:00
|
|
|
}
|
|
|
|
|
2010-06-28 22:28:59 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* QueryMemoryResourceNotification (KERNEL32.@)
|
|
|
|
*/
|
2012-03-12 10:33:32 +01:00
|
|
|
BOOL WINAPI QueryMemoryResourceNotification(HANDLE handle, PBOOL state)
|
2010-06-28 22:28:59 +02:00
|
|
|
{
|
2012-03-12 10:33:32 +01:00
|
|
|
switch (WaitForSingleObject( handle, 0 ))
|
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
*state = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
*state = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
2010-06-28 22:28:59 +02:00
|
|
|
}
|
2009-11-14 09:58:47 +01:00
|
|
|
|
2013-08-28 21:11:00 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* InitOnceBeginInitialize (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI InitOnceBeginInitialize( INIT_ONCE *once, DWORD flags, BOOL *pending, void **context )
|
|
|
|
{
|
|
|
|
NTSTATUS status = RtlRunOnceBeginInitialize( once, flags, context );
|
|
|
|
if (status >= 0) *pending = (status == STATUS_PENDING);
|
|
|
|
else SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return status >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InitOnceComplete (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI InitOnceComplete( INIT_ONCE *once, DWORD flags, void *context )
|
|
|
|
{
|
|
|
|
NTSTATUS status = RtlRunOnceComplete( once, flags, context );
|
|
|
|
if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InitOnceExecuteOnce (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI InitOnceExecuteOnce( INIT_ONCE *once, PINIT_ONCE_FN func, void *param, void **context )
|
|
|
|
{
|
|
|
|
return !RtlRunOnceExecuteOnce( once, (PRTL_RUN_ONCE_INIT_FN)func, param, context );
|
|
|
|
}
|
|
|
|
|
2003-06-24 05:34:15 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* InterlockedCompareExchange (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC(InterlockedCompareExchange, 12,
|
2003-06-24 05:34:15 +02:00
|
|
|
"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 ); */
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC(InterlockedExchange, 8,
|
2003-06-24 05:34:15 +02:00
|
|
|
"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 ); */
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC(InterlockedExchangeAdd, 8,
|
2003-06-24 05:34:15 +02:00
|
|
|
"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 ); */
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC(InterlockedIncrement, 4,
|
2003-06-24 05:34:15 +02:00
|
|
|
"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.@)
|
|
|
|
*/
|
2009-06-14 15:34:09 +02:00
|
|
|
__ASM_STDCALL_FUNC(InterlockedDecrement, 4,
|
2003-06-24 05:34:15 +02:00
|
|
|
"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
|
|
|
|
|
|
|
#endif /* __i386__ */
|
2014-01-05 03:53:12 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SleepConditionVariableCS (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SleepConditionVariableCS( CONDITION_VARIABLE *variable, CRITICAL_SECTION *crit, DWORD timeout )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
status = RtlSleepConditionVariableCS( variable, crit, get_nt_timeout( &time, timeout ) );
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-01-22 01:09:49 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SleepConditionVariableSRW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SleepConditionVariableSRW( RTL_CONDITION_VARIABLE *variable, RTL_SRWLOCK *lock, DWORD timeout, ULONG flags )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
LARGE_INTEGER time;
|
|
|
|
|
|
|
|
status = RtlSleepConditionVariableSRW( variable, lock, get_nt_timeout( &time, timeout ), flags );
|
|
|
|
|
|
|
|
if (status != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|