mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Completed mutex and semaphore implementation
Enabled some global memory functions svn path=/trunk/; revision=1544
This commit is contained in:
parent
703924d130
commit
3676b49d28
8 changed files with 517 additions and 272 deletions
|
@ -31,6 +31,7 @@
|
|||
/* GLOBAL VARIABLES ***********************************************************/
|
||||
|
||||
extern WINBOOL bIsFileApiAnsi;
|
||||
extern HANDLE hProcessHeap;
|
||||
|
||||
|
||||
/* FUNCTION PROTOTYPES ********************************************************/
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $Id: makefile,v 1.41 2000/11/20 19:59:08 ekohl Exp $
|
||||
# $Id: makefile,v 1.42 2001/01/20 12:17:51 ekohl Exp $
|
||||
#
|
||||
# ReactOS Operating System
|
||||
#
|
||||
|
@ -14,7 +14,8 @@ DLLTARGET=$(TARGET).dll
|
|||
|
||||
all: $(DLLTARGET)
|
||||
|
||||
SYNCH_OBJECTS = synch/critical.o synch/event.o synch/wait.o synch/intrlck.o synch/timer.o
|
||||
SYNCH_OBJECTS = synch/critical.o synch/event.o synch/intrlck.o synch/mutex.o \
|
||||
synch/sem.o synch/timer.o synch/wait.o
|
||||
|
||||
MISC_OBJECTS = misc/error.o misc/atom.o misc/handle.o misc/env.o misc/dllmain.o \
|
||||
misc/console.o misc/time.o misc/stubs.o misc/rtl.o misc/ldr.o misc/res.o \
|
||||
|
@ -26,7 +27,8 @@ FILE_OBJECTS = file/file.o file/curdir.o file/lfile.o file/dir.o \
|
|||
file/move.o file/lock.o file/rw.o file/delete.o \
|
||||
file/npipe.o
|
||||
|
||||
MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o mem/section.o mem/isbad.o mem/procmem.o
|
||||
MEM_OBJECTS = mem/global.o mem/heap.o mem/utils.o mem/section.o mem/isbad.o \
|
||||
mem/procmem.o mem/virtual.o
|
||||
|
||||
NLS_OBJECTS = nls/codepage.o nls/cpmisc.o nls/cptable.o\
|
||||
nls/cp37.o nls/cp437.o nls/cp500.o nls/cp737.o nls/cp775.o nls/cp850.o nls/cp852.o nls/cp855.o nls/cp857.o\
|
||||
|
@ -49,7 +51,7 @@ NLS_OBJECTS = nls/codepage.o nls/cpmisc.o nls/cptable.o\
|
|||
nls/lcSLV.o nls/lcSQI.o nls/lcSRB.o nls/lcSRL.o nls/lcSVE.o nls/lcSVF.o nls/lcTRK.o nls/lcUKR.o\
|
||||
nls/locale.o nls/mbtowc.o nls/wctomb.o nls/ole2nls.o
|
||||
|
||||
THREAD_OBJECTS =\
|
||||
THREAD_OBJECTS = \
|
||||
thread/fiber.o \
|
||||
thread/thread.o \
|
||||
thread/tls.o
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: global.c,v 1.4 2000/07/01 17:07:00 ea Exp $
|
||||
/* $Id: global.c,v 1.5 2001/01/20 12:18:54 ekohl Exp $
|
||||
*
|
||||
* Win32 Global/Local heap functions (GlobalXXX, LocalXXX).
|
||||
* These functions included in Win32 for compatibility with 16 bit Windows
|
||||
|
@ -7,11 +7,18 @@
|
|||
* used.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NOTE: Only fixed memory is implemented!!
|
||||
*/
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include <ntdll/rtl.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <kernel32/kernel32.h>
|
||||
|
||||
|
||||
#define MAGIC_GLOBAL_USED 0x5342BEEF
|
||||
#define GLOBAL_LOCK_MAX 0xFF
|
||||
|
||||
|
@ -29,17 +36,18 @@ typedef struct __GLOBAL_LOCAL_HANDLE
|
|||
HGLOBAL WINAPI GlobalAlloc(UINT flags, DWORD size)
|
||||
{
|
||||
PGLOBAL_HANDLE phandle;
|
||||
LPVOID palloc;
|
||||
PVOID palloc;
|
||||
|
||||
DPRINT("GlobalAlloc( 0x%X, 0x%lX )\n", flags, size );
|
||||
|
||||
if((flags & GMEM_MOVEABLE)==0) /* POINTER */
|
||||
{
|
||||
palloc=HeapAlloc(__ProcessHeap, 0, size);
|
||||
palloc=RtlAllocateHeap(hProcessHeap, 0, size);
|
||||
return (HGLOBAL) palloc;
|
||||
}
|
||||
else /* HANDLE */
|
||||
{
|
||||
#if 0
|
||||
HeapLock(__ProcessHeap);
|
||||
|
||||
|
||||
|
@ -58,12 +66,15 @@ HGLOBAL WINAPI GlobalAlloc(UINT flags, DWORD size)
|
|||
HeapUnlock(__ProcessHeap);
|
||||
|
||||
return (HGLOBAL) &(phandle->Pointer);
|
||||
#endif
|
||||
return (HGLOBAL)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalLock -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
LPVOID WINAPI GlobalLock(HGLOBAL hmem)
|
||||
{
|
||||
PGLOBAL_HANDLE phandle;
|
||||
|
@ -90,10 +101,12 @@ LPVOID WINAPI GlobalLock(HGLOBAL hmem)
|
|||
HeapUnlock(__ProcessHeap);
|
||||
return palloc;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalUnlock -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
BOOL WINAPI GlobalUnlock(HGLOBAL hmem)
|
||||
{
|
||||
PGLOBAL_HANDLE phandle;
|
||||
|
@ -121,10 +134,12 @@ BOOL WINAPI GlobalUnlock(HGLOBAL hmem)
|
|||
HeapUnlock(__ProcessHeap);
|
||||
return locked;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalHandle -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
HGLOBAL WINAPI GlobalHandle(LPCVOID pmem)
|
||||
{
|
||||
DPRINT("GlobalHandle( 0x%lX )\n", (ULONG) pmem );
|
||||
|
@ -134,10 +149,12 @@ HGLOBAL WINAPI GlobalHandle(LPCVOID pmem)
|
|||
else /* MOVEABLE */
|
||||
return (HGLOBAL) *(LPVOID *)(pmem-sizeof(HANDLE));
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalReAlloc -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags)
|
||||
{
|
||||
LPVOID palloc;
|
||||
|
@ -218,22 +235,26 @@ HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags)
|
|||
HeapUnlock(__ProcessHeap);
|
||||
return hnew;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalFree -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
HGLOBAL WINAPI GlobalHeapFree(GetProcessHeap(),0,HGLOBAL hmem)
|
||||
HGLOBAL WINAPI GlobalFree(HGLOBAL hmem)
|
||||
{
|
||||
#if 0
|
||||
PGLOBAL_HANDLE phandle;
|
||||
#endif
|
||||
|
||||
DPRINT("GlobalHeapFree(GetProcessHeap(),0, 0x%lX )\n", (ULONG) hmem );
|
||||
DPRINT("GlobalFree( 0x%lX )\n", (ULONG) hmem );
|
||||
|
||||
if(((ULONG)hmem%4)==0) /* POINTER */
|
||||
{
|
||||
HeapHeapFree(GetProcessHeap(),0,__ProcessHeap, 0, (LPVOID) hmem);
|
||||
}
|
||||
else /* HANDLE */
|
||||
{
|
||||
if (((ULONG)hmem % 4) == 0) /* POINTER */
|
||||
{
|
||||
RtlFreeHeap(hProcessHeap, 0, (LPVOID)hmem);
|
||||
}
|
||||
else /* HANDLE */
|
||||
{
|
||||
#if 0
|
||||
HeapLock(__ProcessHeap);
|
||||
phandle=(PGLOBAL_HANDLE)(((LPVOID) hmem)-4);
|
||||
if(phandle->Magic==MAGIC_GLOBAL_USED)
|
||||
|
@ -246,7 +267,9 @@ HGLOBAL WINAPI GlobalHeapFree(GetProcessHeap(),0,HGLOBAL hmem)
|
|||
__HeapFreeFragment(__ProcessHeap, 0, phandle);
|
||||
}
|
||||
HeapUnlock(__ProcessHeap);
|
||||
}
|
||||
#endif
|
||||
hmem = NULL;
|
||||
}
|
||||
return hmem;
|
||||
}
|
||||
|
||||
|
@ -260,12 +283,13 @@ DWORD WINAPI GlobalSize(HGLOBAL hmem)
|
|||
|
||||
DPRINT("GlobalSize( 0x%lX )\n", (ULONG) hmem );
|
||||
|
||||
if(((ULONG)hmem%8)==0)
|
||||
if(((ULONG)hmem % 4) == 0)
|
||||
{
|
||||
retval=HeapSize(__ProcessHeap, 0, hmem);
|
||||
retval = RtlSizeHeap(hProcessHeap, 0, hmem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
HeapLock(__ProcessHeap);
|
||||
phandle=(PGLOBAL_HANDLE)(((LPVOID) hmem)-4);
|
||||
if(phandle->Magic==MAGIC_GLOBAL_USED)
|
||||
|
@ -278,6 +302,8 @@ DWORD WINAPI GlobalSize(HGLOBAL hmem)
|
|||
retval=0;
|
||||
}
|
||||
HeapUnlock(__ProcessHeap);
|
||||
#endif
|
||||
retval = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -285,41 +311,51 @@ DWORD WINAPI GlobalSize(HGLOBAL hmem)
|
|||
/*********************************************************************
|
||||
* GlobalWire -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
LPVOID WINAPI GlobalWire(HGLOBAL hmem)
|
||||
{
|
||||
return GlobalLock( hmem );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalUnWire -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
BOOL WINAPI GlobalUnWire(HGLOBAL hmem)
|
||||
{
|
||||
return GlobalUnlock( hmem);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalFix -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
VOID WINAPI GlobalFix(HGLOBAL hmem)
|
||||
{
|
||||
GlobalLock( hmem );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalUnfix -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
VOID WINAPI GlobalUnfix(HGLOBAL hmem)
|
||||
{
|
||||
GlobalUnlock( hmem);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* GlobalFlags -- KERNEL32 *
|
||||
*********************************************************************/
|
||||
#if 0
|
||||
UINT WINAPI GlobalFlags(HGLOBAL hmem)
|
||||
{
|
||||
return LocalFlags( (HLOCAL) hmem);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: dllmain.c,v 1.15 2000/09/05 13:52:04 ekohl Exp $
|
||||
/* $Id: dllmain.c,v 1.16 2001/01/20 12:19:57 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -23,6 +23,8 @@
|
|||
extern UNICODE_STRING SystemDirectory;
|
||||
extern UNICODE_STRING WindowsDirectory;
|
||||
|
||||
HANDLE hProcessHeap = NULL;
|
||||
|
||||
static WINBOOL DllInitialized = FALSE;
|
||||
|
||||
WINBOOL STDCALL DllMain (HANDLE hInst,
|
||||
|
@ -65,6 +67,8 @@ WINBOOL STDCALL DllMain(HANDLE hInst,
|
|||
// ZwTerminateProcess(NtCurrentProcess(), Status);
|
||||
}
|
||||
|
||||
hProcessHeap = RtlGetProcessHeap();
|
||||
|
||||
/*
|
||||
* Initialize WindowsDirectory and SystemDirectory
|
||||
*/
|
||||
|
@ -74,7 +78,7 @@ WINBOOL STDCALL DllMain(HANDLE hInst,
|
|||
SharedUserData->NtSystemRoot);
|
||||
SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
|
||||
SystemDirectory.Length = WindowsDirectory.Length + 18;
|
||||
SystemDirectory.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
|
||||
SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
|
||||
0,
|
||||
SystemDirectory.MaximumLength);
|
||||
wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: stubs.c,v 1.22 2000/09/05 13:52:04 ekohl Exp $
|
||||
/* $Id: stubs.c,v 1.23 2001/01/20 12:19:57 ekohl Exp $
|
||||
*
|
||||
* KERNEL32.DLL stubs (unimplemented functions)
|
||||
* Remove from this file, if you implement them.
|
||||
|
@ -2108,7 +2108,7 @@ GlobalAddAtomA (
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
HGLOBAL
|
||||
STDCALL
|
||||
GlobalAlloc (
|
||||
|
@ -2119,7 +2119,7 @@ GlobalAlloc (
|
|||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
UINT
|
||||
STDCALL
|
||||
|
@ -2186,6 +2186,7 @@ GlobalFlags (
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
HGLOBAL
|
||||
STDCALL
|
||||
GlobalFree (
|
||||
|
@ -2195,7 +2196,7 @@ GlobalFree (
|
|||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return hMem;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
UINT
|
||||
STDCALL
|
||||
|
@ -2267,7 +2268,7 @@ GlobalReAlloc (
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
DWORD
|
||||
STDCALL
|
||||
GlobalSize (
|
||||
|
@ -2277,7 +2278,7 @@ GlobalSize (
|
|||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
|
@ -2635,9 +2636,6 @@ LocalUnlock (
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
STDCALL
|
||||
MulDiv (
|
||||
|
@ -2829,32 +2827,6 @@ OpenConsoleW (
|
|||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
OpenMutexA (
|
||||
DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCSTR lpName
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
OpenMutexW (
|
||||
DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCWSTR lpName
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
STDCALL
|
||||
OpenProfileUserMapping (VOID)
|
||||
|
@ -2864,32 +2836,6 @@ OpenProfileUserMapping (VOID)
|
|||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
OpenSemaphoreA (
|
||||
DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCSTR lpName
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
OpenSemaphoreW (
|
||||
DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCWSTR lpName
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
PeekNamedPipe (
|
||||
|
@ -2980,9 +2926,6 @@ RaiseException (
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
RegisterConsoleVDM (
|
||||
|
@ -3026,32 +2969,6 @@ RegisterWowExec (
|
|||
}
|
||||
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
ReleaseMutex (
|
||||
HANDLE hMutex
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
ReleaseSemaphore (
|
||||
HANDLE hSemaphore,
|
||||
LONG lReleaseCount,
|
||||
LPLONG lpPreviousCount
|
||||
)
|
||||
{
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
WINBOOL
|
||||
STDCALL
|
||||
SetCommBreak (
|
||||
|
|
201
reactos/lib/kernel32/synch/mutex.c
Normal file
201
reactos/lib/kernel32/synch/mutex.c
Normal file
|
@ -0,0 +1,201 @@
|
|||
/* $Id: mutex.c,v 1.1 2001/01/20 12:20:43 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/kernel32/synch/mutex.c
|
||||
* PURPOSE: Mutex functions
|
||||
* PROGRAMMER: Eric Kohl (ekohl@rz-online.de)
|
||||
* UPDATE HISTORY:
|
||||
* Created 01/20/2001
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include <kernel32/error.h>
|
||||
#include <windows.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <kernel32/kernel32.h>
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
HANDLE STDCALL
|
||||
CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes,
|
||||
WINBOOL bInitialOwner,
|
||||
LPCSTR lpName)
|
||||
{
|
||||
UNICODE_STRING NameU;
|
||||
ANSI_STRING Name;
|
||||
HANDLE Handle;
|
||||
|
||||
RtlInitAnsiString(&Name,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString(&NameU,
|
||||
&Name,
|
||||
TRUE);
|
||||
|
||||
Handle = CreateMutexW(lpMutexAttributes,
|
||||
bInitialOwner,
|
||||
NameU.Buffer);
|
||||
|
||||
RtlFreeUnicodeString(&NameU);
|
||||
|
||||
return Handle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE STDCALL
|
||||
CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes,
|
||||
WINBOOL bInitialOwner,
|
||||
LPCWSTR lpName)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
NTSTATUS Status;
|
||||
UNICODE_STRING NameString;
|
||||
HANDLE MutantHandle;
|
||||
|
||||
RtlInitUnicodeString(&NameString,
|
||||
(LPWSTR)lpName);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &NameString;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
|
||||
if (lpMutexAttributes != NULL)
|
||||
{
|
||||
ObjectAttributes.SecurityDescriptor = lpMutexAttributes->lpSecurityDescriptor;
|
||||
if (lpMutexAttributes->bInheritHandle == TRUE)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
}
|
||||
|
||||
Status = NtCreateMutant(&MutantHandle,
|
||||
MUTEX_ALL_ACCESS,
|
||||
&ObjectAttributes,
|
||||
(BOOLEAN)bInitialOwner);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return MutantHandle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE STDCALL
|
||||
OpenMutexA(DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCSTR lpName)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING NameU;
|
||||
ANSI_STRING Name;
|
||||
HANDLE Handle;
|
||||
NTSTATUS Status;
|
||||
|
||||
if (lpName == NULL)
|
||||
{
|
||||
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RtlInitAnsiString(&Name,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString(&NameU,
|
||||
&Name,
|
||||
TRUE);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &NameU;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
if (bInheritHandle == TRUE)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
Status = NtOpenMutant(&Handle,
|
||||
(ACCESS_MASK)dwDesiredAccess,
|
||||
&ObjectAttributes);
|
||||
|
||||
RtlFreeUnicodeString(&NameU);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Handle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE STDCALL
|
||||
OpenMutexW(DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCWSTR lpName)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING Name;
|
||||
HANDLE Handle;
|
||||
NTSTATUS Status;
|
||||
|
||||
if (lpName == NULL)
|
||||
{
|
||||
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RtlInitUnicodeString(&Name,
|
||||
(LPWSTR)lpName);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &Name;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
if (bInheritHandle == TRUE)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
Status = NtOpenMutant(&Handle,
|
||||
(ACCESS_MASK)dwDesiredAccess,
|
||||
&ObjectAttributes);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Handle;
|
||||
}
|
||||
|
||||
|
||||
WINBOOL STDCALL
|
||||
ReleaseMutex(HANDLE hMutex)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
Status = NtReleaseMutant(hMutex,
|
||||
NULL);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* EOF */
|
214
reactos/lib/kernel32/synch/sem.c
Normal file
214
reactos/lib/kernel32/synch/sem.c
Normal file
|
@ -0,0 +1,214 @@
|
|||
/* $Id: sem.c,v 1.1 2001/01/20 12:20:43 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/kernel32/synch/sem.c
|
||||
* PURPOSE: Semaphore functions
|
||||
* PROGRAMMER: Eric Kohl (ekohl@rz-online.de)
|
||||
* UPDATE HISTORY:
|
||||
* Created 01/20/2001
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <kernel32/kernel32.h>
|
||||
#include <kernel32/error.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
HANDLE STDCALL
|
||||
CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
|
||||
LONG lInitialCount,
|
||||
LONG lMaximumCount,
|
||||
LPCSTR lpName)
|
||||
{
|
||||
UNICODE_STRING NameU;
|
||||
ANSI_STRING Name;
|
||||
HANDLE Handle;
|
||||
|
||||
RtlInitAnsiString(&Name,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString(&NameU,
|
||||
&Name,
|
||||
TRUE);
|
||||
|
||||
Handle = CreateSemaphoreW(lpSemaphoreAttributes,
|
||||
lInitialCount,
|
||||
lMaximumCount,
|
||||
NameU.Buffer);
|
||||
|
||||
RtlFreeUnicodeString (&NameU);
|
||||
|
||||
return Handle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE STDCALL
|
||||
CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
|
||||
LONG lInitialCount,
|
||||
LONG lMaximumCount,
|
||||
LPCWSTR lpName)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
NTSTATUS Status;
|
||||
UNICODE_STRING NameString;
|
||||
HANDLE SemaphoreHandle;
|
||||
|
||||
if (lpName)
|
||||
{
|
||||
NameString.Length = lstrlenW(lpName)*sizeof(WCHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
NameString.Length = 0;
|
||||
}
|
||||
|
||||
NameString.Buffer = (WCHAR *)lpName;
|
||||
NameString.MaximumLength = NameString.Length;
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &NameString;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
if (lpSemaphoreAttributes != NULL)
|
||||
{
|
||||
ObjectAttributes.SecurityDescriptor = lpSemaphoreAttributes->lpSecurityDescriptor;
|
||||
if (lpSemaphoreAttributes->bInheritHandle == TRUE)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
}
|
||||
|
||||
Status = NtCreateSemaphore(&SemaphoreHandle,
|
||||
SEMAPHORE_ALL_ACCESS,
|
||||
&ObjectAttributes,
|
||||
lInitialCount,
|
||||
lMaximumCount);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
return SemaphoreHandle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE STDCALL
|
||||
OpenSemaphoreA(DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCSTR lpName)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING NameU;
|
||||
ANSI_STRING Name;
|
||||
HANDLE Handle;
|
||||
NTSTATUS Status;
|
||||
|
||||
if (lpName == NULL)
|
||||
{
|
||||
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RtlInitAnsiString(&Name,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString(&NameU,
|
||||
&Name,
|
||||
TRUE);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &NameU;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
if (bInheritHandle == TRUE)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
Status = NtOpenSemaphore(&Handle,
|
||||
(ACCESS_MASK)dwDesiredAccess,
|
||||
&ObjectAttributes);
|
||||
|
||||
RtlFreeUnicodeString(&NameU);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Handle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE STDCALL
|
||||
OpenSemaphoreW(DWORD dwDesiredAccess,
|
||||
WINBOOL bInheritHandle,
|
||||
LPCWSTR lpName)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
UNICODE_STRING Name;
|
||||
HANDLE Handle;
|
||||
NTSTATUS Status;
|
||||
|
||||
if (lpName == NULL)
|
||||
{
|
||||
SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RtlInitUnicodeString(&Name,
|
||||
(LPWSTR)lpName);
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &Name;
|
||||
ObjectAttributes.Attributes = 0;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
if (bInheritHandle == TRUE)
|
||||
{
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
Status = NtOpenSemaphore(&Handle,
|
||||
(ACCESS_MASK)dwDesiredAccess,
|
||||
&ObjectAttributes);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Handle;
|
||||
}
|
||||
|
||||
|
||||
WINBOOL STDCALL
|
||||
ReleaseSemaphore(HANDLE hSemaphore,
|
||||
LONG lReleaseCount,
|
||||
LPLONG lpPreviousCount)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
Status = NtReleaseSemaphore(hSemaphore,
|
||||
lReleaseCount,
|
||||
lpPreviousCount);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
SetLastErrorByStatus(Status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* EOF */
|
|
@ -1,178 +1,36 @@
|
|||
/* $Id: wait.c,v 1.13 2000/12/08 22:08:02 chorns Exp $
|
||||
/* $Id: wait.c,v 1.14 2001/01/20 12:20:43 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/kernel32/synch/wait.c
|
||||
* PURPOSE: Wait functions
|
||||
* PURPOSE: Wait functions
|
||||
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
|
||||
* UPDATE HISTORY:
|
||||
* Created 01/11/98
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
||||
#include <ddk/ntddk.h>
|
||||
#include <kernel32/error.h>
|
||||
#include <windows.h>
|
||||
#include <wchar.h>
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
CreateSemaphoreA (
|
||||
LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
|
||||
LONG lInitialCount,
|
||||
LONG lMaximumCount,
|
||||
LPCSTR lpName
|
||||
)
|
||||
#include <kernel32/kernel32.h>
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
DWORD STDCALL
|
||||
WaitForSingleObject(HANDLE hHandle,
|
||||
DWORD dwMilliseconds)
|
||||
{
|
||||
UNICODE_STRING NameU;
|
||||
ANSI_STRING Name;
|
||||
HANDLE Handle;
|
||||
|
||||
RtlInitAnsiString (&Name,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString (&NameU,
|
||||
&Name,
|
||||
TRUE);
|
||||
|
||||
Handle = CreateSemaphoreW (lpSemaphoreAttributes,
|
||||
lInitialCount,
|
||||
lMaximumCount,
|
||||
NameU.Buffer);
|
||||
|
||||
RtlFreeUnicodeString (&NameU);
|
||||
|
||||
return Handle;
|
||||
return WaitForSingleObjectEx(hHandle,
|
||||
dwMilliseconds,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
CreateSemaphoreW(
|
||||
LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
|
||||
LONG lInitialCount,
|
||||
LONG lMaximumCount,
|
||||
LPCWSTR lpName
|
||||
)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
NTSTATUS errCode;
|
||||
UNICODE_STRING NameString;
|
||||
HANDLE SemaphoreHandle;
|
||||
if (lpName)
|
||||
NameString.Length = lstrlenW(lpName)*sizeof(WCHAR);
|
||||
else
|
||||
NameString.Length = 0;
|
||||
NameString.Buffer = (WCHAR *)lpName;
|
||||
NameString.MaximumLength = NameString.Length;
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &NameString;
|
||||
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
if ( lpSemaphoreAttributes != NULL ) {
|
||||
ObjectAttributes.SecurityDescriptor = lpSemaphoreAttributes->lpSecurityDescriptor;
|
||||
if ( lpSemaphoreAttributes->bInheritHandle == TRUE )
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
errCode = NtCreateSemaphore(
|
||||
&SemaphoreHandle,
|
||||
GENERIC_ALL,
|
||||
&ObjectAttributes,
|
||||
lInitialCount,
|
||||
lMaximumCount
|
||||
);
|
||||
if (!NT_SUCCESS(errCode))
|
||||
{
|
||||
SetLastErrorByStatus (errCode);
|
||||
return NULL;
|
||||
}
|
||||
return SemaphoreHandle;
|
||||
}
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
CreateMutexA (
|
||||
LPSECURITY_ATTRIBUTES lpMutexAttributes,
|
||||
WINBOOL bInitialOwner,
|
||||
LPCSTR lpName
|
||||
)
|
||||
{
|
||||
UNICODE_STRING NameU;
|
||||
ANSI_STRING Name;
|
||||
HANDLE Handle;
|
||||
|
||||
RtlInitAnsiString (&Name,
|
||||
(LPSTR)lpName);
|
||||
RtlAnsiStringToUnicodeString (&NameU,
|
||||
&Name,
|
||||
TRUE);
|
||||
|
||||
Handle = CreateMutexW (lpMutexAttributes,
|
||||
bInitialOwner,
|
||||
NameU.Buffer);
|
||||
|
||||
RtlFreeUnicodeString (&NameU);
|
||||
|
||||
return Handle;
|
||||
}
|
||||
|
||||
|
||||
HANDLE
|
||||
STDCALL
|
||||
CreateMutexW (
|
||||
LPSECURITY_ATTRIBUTES lpMutexAttributes,
|
||||
WINBOOL bInitialOwner,
|
||||
LPCWSTR lpName
|
||||
)
|
||||
{
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
NTSTATUS errCode;
|
||||
UNICODE_STRING NameString;
|
||||
HANDLE MutantHandle;
|
||||
|
||||
NameString.Length = lstrlenW(lpName)*sizeof(WCHAR);
|
||||
NameString.Buffer = (WCHAR *)lpName;
|
||||
NameString.MaximumLength = NameString.Length;
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = &NameString;
|
||||
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE;
|
||||
ObjectAttributes.SecurityDescriptor = NULL;
|
||||
ObjectAttributes.SecurityQualityOfService = NULL;
|
||||
|
||||
if ( lpMutexAttributes != NULL ) {
|
||||
ObjectAttributes.SecurityDescriptor = lpMutexAttributes->lpSecurityDescriptor;
|
||||
if ( lpMutexAttributes->bInheritHandle == TRUE )
|
||||
ObjectAttributes.Attributes |= OBJ_INHERIT;
|
||||
}
|
||||
|
||||
|
||||
errCode = NtCreateMutant(&MutantHandle,GENERIC_ALL, &ObjectAttributes,(BOOLEAN)bInitialOwner);
|
||||
if (!NT_SUCCESS(errCode))
|
||||
{
|
||||
SetLastErrorByStatus (errCode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return MutantHandle;
|
||||
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
STDCALL
|
||||
WaitForSingleObject (
|
||||
HANDLE hHandle,
|
||||
DWORD dwMilliseconds
|
||||
)
|
||||
{
|
||||
return WaitForSingleObjectEx(hHandle,dwMilliseconds,FALSE);
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
STDCALL
|
||||
DWORD STDCALL
|
||||
WaitForSingleObjectEx(HANDLE hHandle,
|
||||
DWORD dwMilliseconds,
|
||||
BOOL bAlertable)
|
||||
|
@ -209,19 +67,21 @@ WaitForSingleObjectEx(HANDLE hHandle,
|
|||
}
|
||||
|
||||
|
||||
DWORD
|
||||
STDCALL
|
||||
DWORD STDCALL
|
||||
WaitForMultipleObjects(DWORD nCount,
|
||||
CONST HANDLE *lpHandles,
|
||||
BOOL bWaitAll,
|
||||
DWORD dwMilliseconds)
|
||||
{
|
||||
return WaitForMultipleObjectsEx( nCount, lpHandles, bWaitAll ? WaitAll : WaitAny, dwMilliseconds, FALSE );
|
||||
return WaitForMultipleObjectsEx(nCount,
|
||||
lpHandles,
|
||||
bWaitAll ? WaitAll : WaitAny,
|
||||
dwMilliseconds,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
STDCALL
|
||||
DWORD STDCALL
|
||||
WaitForMultipleObjectsEx(DWORD nCount,
|
||||
CONST HANDLE *lpHandles,
|
||||
BOOL bWaitAll,
|
||||
|
@ -263,4 +123,14 @@ WaitForMultipleObjectsEx(DWORD nCount,
|
|||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
|
||||
BOOL STDCALL
|
||||
SignalObjectAndWait(HANDLE hObjectToSignal,
|
||||
HANDLE hObjectToWaitOn,
|
||||
DWORD dwMilliseconds,
|
||||
BOOL bAlertable)
|
||||
{
|
||||
UNIMPLEMENTED
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
Loading…
Reference in a new issue