Completed mutex and semaphore implementation

Enabled some global memory functions

svn path=/trunk/; revision=1544
This commit is contained in:
Eric Kohl 2001-01-20 12:20:43 +00:00
parent 703924d130
commit 3676b49d28
8 changed files with 517 additions and 272 deletions

View file

@ -31,6 +31,7 @@
/* GLOBAL VARIABLES ***********************************************************/ /* GLOBAL VARIABLES ***********************************************************/
extern WINBOOL bIsFileApiAnsi; extern WINBOOL bIsFileApiAnsi;
extern HANDLE hProcessHeap;
/* FUNCTION PROTOTYPES ********************************************************/ /* FUNCTION PROTOTYPES ********************************************************/

View file

@ -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 # ReactOS Operating System
# #
@ -14,7 +14,8 @@ DLLTARGET=$(TARGET).dll
all: $(DLLTARGET) 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_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 \ 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/move.o file/lock.o file/rw.o file/delete.o \
file/npipe.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_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\ 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/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 nls/locale.o nls/mbtowc.o nls/wctomb.o nls/ole2nls.o
THREAD_OBJECTS =\ THREAD_OBJECTS = \
thread/fiber.o \ thread/fiber.o \
thread/thread.o \ thread/thread.o \
thread/tls.o thread/tls.o

View file

@ -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). * Win32 Global/Local heap functions (GlobalXXX, LocalXXX).
* These functions included in Win32 for compatibility with 16 bit Windows * These functions included in Win32 for compatibility with 16 bit Windows
@ -7,11 +7,18 @@
* used. * used.
*/ */
/*
* NOTE: Only fixed memory is implemented!!
*/
#include <ddk/ntddk.h>
#include <ntdll/rtl.h>
#include <windows.h> #include <windows.h>
#define NDEBUG #define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
#define MAGIC_GLOBAL_USED 0x5342BEEF #define MAGIC_GLOBAL_USED 0x5342BEEF
#define GLOBAL_LOCK_MAX 0xFF #define GLOBAL_LOCK_MAX 0xFF
@ -29,17 +36,18 @@ typedef struct __GLOBAL_LOCAL_HANDLE
HGLOBAL WINAPI GlobalAlloc(UINT flags, DWORD size) HGLOBAL WINAPI GlobalAlloc(UINT flags, DWORD size)
{ {
PGLOBAL_HANDLE phandle; PGLOBAL_HANDLE phandle;
LPVOID palloc; PVOID palloc;
DPRINT("GlobalAlloc( 0x%X, 0x%lX )\n", flags, size ); DPRINT("GlobalAlloc( 0x%X, 0x%lX )\n", flags, size );
if((flags & GMEM_MOVEABLE)==0) /* POINTER */ if((flags & GMEM_MOVEABLE)==0) /* POINTER */
{ {
palloc=HeapAlloc(__ProcessHeap, 0, size); palloc=RtlAllocateHeap(hProcessHeap, 0, size);
return (HGLOBAL) palloc; return (HGLOBAL) palloc;
} }
else /* HANDLE */ else /* HANDLE */
{ {
#if 0
HeapLock(__ProcessHeap); HeapLock(__ProcessHeap);
@ -58,12 +66,15 @@ HGLOBAL WINAPI GlobalAlloc(UINT flags, DWORD size)
HeapUnlock(__ProcessHeap); HeapUnlock(__ProcessHeap);
return (HGLOBAL) &(phandle->Pointer); return (HGLOBAL) &(phandle->Pointer);
#endif
return (HGLOBAL)NULL;
} }
} }
/********************************************************************* /*********************************************************************
* GlobalLock -- KERNEL32 * * GlobalLock -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
LPVOID WINAPI GlobalLock(HGLOBAL hmem) LPVOID WINAPI GlobalLock(HGLOBAL hmem)
{ {
PGLOBAL_HANDLE phandle; PGLOBAL_HANDLE phandle;
@ -90,10 +101,12 @@ LPVOID WINAPI GlobalLock(HGLOBAL hmem)
HeapUnlock(__ProcessHeap); HeapUnlock(__ProcessHeap);
return palloc; return palloc;
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalUnlock -- KERNEL32 * * GlobalUnlock -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
BOOL WINAPI GlobalUnlock(HGLOBAL hmem) BOOL WINAPI GlobalUnlock(HGLOBAL hmem)
{ {
PGLOBAL_HANDLE phandle; PGLOBAL_HANDLE phandle;
@ -121,10 +134,12 @@ BOOL WINAPI GlobalUnlock(HGLOBAL hmem)
HeapUnlock(__ProcessHeap); HeapUnlock(__ProcessHeap);
return locked; return locked;
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalHandle -- KERNEL32 * * GlobalHandle -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
HGLOBAL WINAPI GlobalHandle(LPCVOID pmem) HGLOBAL WINAPI GlobalHandle(LPCVOID pmem)
{ {
DPRINT("GlobalHandle( 0x%lX )\n", (ULONG) pmem ); DPRINT("GlobalHandle( 0x%lX )\n", (ULONG) pmem );
@ -134,10 +149,12 @@ HGLOBAL WINAPI GlobalHandle(LPCVOID pmem)
else /* MOVEABLE */ else /* MOVEABLE */
return (HGLOBAL) *(LPVOID *)(pmem-sizeof(HANDLE)); return (HGLOBAL) *(LPVOID *)(pmem-sizeof(HANDLE));
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalReAlloc -- KERNEL32 * * GlobalReAlloc -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags) HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags)
{ {
LPVOID palloc; LPVOID palloc;
@ -218,22 +235,26 @@ HGLOBAL WINAPI GlobalReAlloc(HGLOBAL hmem, DWORD size, UINT flags)
HeapUnlock(__ProcessHeap); HeapUnlock(__ProcessHeap);
return hnew; return hnew;
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalFree -- KERNEL32 * * GlobalFree -- KERNEL32 *
*********************************************************************/ *********************************************************************/
HGLOBAL WINAPI GlobalHeapFree(GetProcessHeap(),0,HGLOBAL hmem) HGLOBAL WINAPI GlobalFree(HGLOBAL hmem)
{ {
#if 0
PGLOBAL_HANDLE phandle; 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 */ if (((ULONG)hmem % 4) == 0) /* POINTER */
{ {
HeapHeapFree(GetProcessHeap(),0,__ProcessHeap, 0, (LPVOID) hmem); RtlFreeHeap(hProcessHeap, 0, (LPVOID)hmem);
} }
else /* HANDLE */ else /* HANDLE */
{ {
#if 0
HeapLock(__ProcessHeap); HeapLock(__ProcessHeap);
phandle=(PGLOBAL_HANDLE)(((LPVOID) hmem)-4); phandle=(PGLOBAL_HANDLE)(((LPVOID) hmem)-4);
if(phandle->Magic==MAGIC_GLOBAL_USED) if(phandle->Magic==MAGIC_GLOBAL_USED)
@ -246,6 +267,8 @@ HGLOBAL WINAPI GlobalHeapFree(GetProcessHeap(),0,HGLOBAL hmem)
__HeapFreeFragment(__ProcessHeap, 0, phandle); __HeapFreeFragment(__ProcessHeap, 0, phandle);
} }
HeapUnlock(__ProcessHeap); HeapUnlock(__ProcessHeap);
#endif
hmem = NULL;
} }
return hmem; return hmem;
} }
@ -260,12 +283,13 @@ DWORD WINAPI GlobalSize(HGLOBAL hmem)
DPRINT("GlobalSize( 0x%lX )\n", (ULONG) 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 else
{ {
#if 0
HeapLock(__ProcessHeap); HeapLock(__ProcessHeap);
phandle=(PGLOBAL_HANDLE)(((LPVOID) hmem)-4); phandle=(PGLOBAL_HANDLE)(((LPVOID) hmem)-4);
if(phandle->Magic==MAGIC_GLOBAL_USED) if(phandle->Magic==MAGIC_GLOBAL_USED)
@ -278,6 +302,8 @@ DWORD WINAPI GlobalSize(HGLOBAL hmem)
retval=0; retval=0;
} }
HeapUnlock(__ProcessHeap); HeapUnlock(__ProcessHeap);
#endif
retval = 0;
} }
return retval; return retval;
} }
@ -285,41 +311,51 @@ DWORD WINAPI GlobalSize(HGLOBAL hmem)
/********************************************************************* /*********************************************************************
* GlobalWire -- KERNEL32 * * GlobalWire -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
LPVOID WINAPI GlobalWire(HGLOBAL hmem) LPVOID WINAPI GlobalWire(HGLOBAL hmem)
{ {
return GlobalLock( hmem ); return GlobalLock( hmem );
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalUnWire -- KERNEL32 * * GlobalUnWire -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
BOOL WINAPI GlobalUnWire(HGLOBAL hmem) BOOL WINAPI GlobalUnWire(HGLOBAL hmem)
{ {
return GlobalUnlock( hmem); return GlobalUnlock( hmem);
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalFix -- KERNEL32 * * GlobalFix -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
VOID WINAPI GlobalFix(HGLOBAL hmem) VOID WINAPI GlobalFix(HGLOBAL hmem)
{ {
GlobalLock( hmem ); GlobalLock( hmem );
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalUnfix -- KERNEL32 * * GlobalUnfix -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
VOID WINAPI GlobalUnfix(HGLOBAL hmem) VOID WINAPI GlobalUnfix(HGLOBAL hmem)
{ {
GlobalUnlock( hmem); GlobalUnlock( hmem);
} }
#endif
/********************************************************************* /*********************************************************************
* GlobalFlags -- KERNEL32 * * GlobalFlags -- KERNEL32 *
*********************************************************************/ *********************************************************************/
#if 0
UINT WINAPI GlobalFlags(HGLOBAL hmem) UINT WINAPI GlobalFlags(HGLOBAL hmem)
{ {
return LocalFlags( (HLOCAL) hmem); return LocalFlags( (HLOCAL) hmem);
} }
#endif
/* EOF */ /* EOF */

View file

@ -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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -23,6 +23,8 @@
extern UNICODE_STRING SystemDirectory; extern UNICODE_STRING SystemDirectory;
extern UNICODE_STRING WindowsDirectory; extern UNICODE_STRING WindowsDirectory;
HANDLE hProcessHeap = NULL;
static WINBOOL DllInitialized = FALSE; static WINBOOL DllInitialized = FALSE;
WINBOOL STDCALL DllMain (HANDLE hInst, WINBOOL STDCALL DllMain (HANDLE hInst,
@ -65,6 +67,8 @@ WINBOOL STDCALL DllMain(HANDLE hInst,
// ZwTerminateProcess(NtCurrentProcess(), Status); // ZwTerminateProcess(NtCurrentProcess(), Status);
} }
hProcessHeap = RtlGetProcessHeap();
/* /*
* Initialize WindowsDirectory and SystemDirectory * Initialize WindowsDirectory and SystemDirectory
*/ */
@ -74,7 +78,7 @@ WINBOOL STDCALL DllMain(HANDLE hInst,
SharedUserData->NtSystemRoot); SharedUserData->NtSystemRoot);
SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18; SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
SystemDirectory.Length = WindowsDirectory.Length + 18; SystemDirectory.Length = WindowsDirectory.Length + 18;
SystemDirectory.Buffer = RtlAllocateHeap (RtlGetProcessHeap (), SystemDirectory.Buffer = RtlAllocateHeap (hProcessHeap,
0, 0,
SystemDirectory.MaximumLength); SystemDirectory.MaximumLength);
wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer); wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);

View file

@ -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) * KERNEL32.DLL stubs (unimplemented functions)
* Remove from this file, if you implement them. * Remove from this file, if you implement them.
@ -2108,7 +2108,7 @@ GlobalAddAtomA (
return 0; return 0;
} }
/*
HGLOBAL HGLOBAL
STDCALL STDCALL
GlobalAlloc ( GlobalAlloc (
@ -2119,7 +2119,7 @@ GlobalAlloc (
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0; return 0;
} }
*/
UINT UINT
STDCALL STDCALL
@ -2186,6 +2186,7 @@ GlobalFlags (
} }
/*
HGLOBAL HGLOBAL
STDCALL STDCALL
GlobalFree ( GlobalFree (
@ -2195,7 +2196,7 @@ GlobalFree (
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return hMem; return hMem;
} }
*/
UINT UINT
STDCALL STDCALL
@ -2267,7 +2268,7 @@ GlobalReAlloc (
return 0; return 0;
} }
/*
DWORD DWORD
STDCALL STDCALL
GlobalSize ( GlobalSize (
@ -2277,7 +2278,7 @@ GlobalSize (
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0; return 0;
} }
*/
WINBOOL WINBOOL
STDCALL STDCALL
@ -2635,9 +2636,6 @@ LocalUnlock (
} }
int int
STDCALL STDCALL
MulDiv ( 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 DWORD
STDCALL STDCALL
OpenProfileUserMapping (VOID) 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 WINBOOL
STDCALL STDCALL
PeekNamedPipe ( PeekNamedPipe (
@ -2980,9 +2926,6 @@ RaiseException (
} }
WINBOOL WINBOOL
STDCALL STDCALL
RegisterConsoleVDM ( 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 WINBOOL
STDCALL STDCALL
SetCommBreak ( SetCommBreak (

View 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 */

View 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 */

View file

@ -1,4 +1,4 @@
/* $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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -9,170 +9,28 @@
* Created 01/11/98 * Created 01/11/98
*/ */
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <kernel32/error.h> #include <kernel32/error.h>
#include <windows.h> #include <windows.h>
#include <wchar.h> #include <wchar.h>
HANDLE #include <kernel32/kernel32.h>
STDCALL
CreateSemaphoreA ( /* FUNCTIONS ****************************************************************/
LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
LONG lInitialCount, DWORD STDCALL
LONG lMaximumCount, WaitForSingleObject(HANDLE hHandle,
LPCSTR lpName DWORD dwMilliseconds)
)
{ {
UNICODE_STRING NameU; return WaitForSingleObjectEx(hHandle,
ANSI_STRING Name; dwMilliseconds,
HANDLE Handle; FALSE);
RtlInitAnsiString (&Name,
(LPSTR)lpName);
RtlAnsiStringToUnicodeString (&NameU,
&Name,
TRUE);
Handle = CreateSemaphoreW (lpSemaphoreAttributes,
lInitialCount,
lMaximumCount,
NameU.Buffer);
RtlFreeUnicodeString (&NameU);
return Handle;
} }
HANDLE DWORD STDCALL
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
WaitForSingleObjectEx(HANDLE hHandle, WaitForSingleObjectEx(HANDLE hHandle,
DWORD dwMilliseconds, DWORD dwMilliseconds,
BOOL bAlertable) BOOL bAlertable)
@ -209,19 +67,21 @@ WaitForSingleObjectEx(HANDLE hHandle,
} }
DWORD DWORD STDCALL
STDCALL
WaitForMultipleObjects(DWORD nCount, WaitForMultipleObjects(DWORD nCount,
CONST HANDLE *lpHandles, CONST HANDLE *lpHandles,
BOOL bWaitAll, BOOL bWaitAll,
DWORD dwMilliseconds) DWORD dwMilliseconds)
{ {
return WaitForMultipleObjectsEx( nCount, lpHandles, bWaitAll ? WaitAll : WaitAny, dwMilliseconds, FALSE ); return WaitForMultipleObjectsEx(nCount,
lpHandles,
bWaitAll ? WaitAll : WaitAny,
dwMilliseconds,
FALSE);
} }
DWORD DWORD STDCALL
STDCALL
WaitForMultipleObjectsEx(DWORD nCount, WaitForMultipleObjectsEx(DWORD nCount,
CONST HANDLE *lpHandles, CONST HANDLE *lpHandles,
BOOL bWaitAll, BOOL bWaitAll,
@ -263,4 +123,14 @@ WaitForMultipleObjectsEx(DWORD nCount,
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
BOOL STDCALL
SignalObjectAndWait(HANDLE hObjectToSignal,
HANDLE hObjectToWaitOn,
DWORD dwMilliseconds,
BOOL bAlertable)
{
UNIMPLEMENTED
}
/* EOF */ /* EOF */