Fix remaning ROS bugs. A minor hack has been added to ObCreateObject because it seems that gcc doesn't dword-align the stacks?!! Thanks to w3seek for some of the ex patches.

svn path=/trunk/; revision=13206
This commit is contained in:
Alex Ionescu 2005-01-22 03:54:23 +00:00
parent c6bd59c308
commit 07ea0d9fa0
10 changed files with 673 additions and 324 deletions

View file

@ -88,9 +88,9 @@ TARGET_BASE_LIB_VERSION =0x77a90000
TARGET_BASE_LIB_ADVAPI32 =0x77dc0000
TARGET_BASE_LIB_USER32 =0x77e60000
TARGET_BASE_LIB_GDI32 =0x77ed0000
TARGET_BASE_LIB_DNSAPI =0x78000000
TARGET_BASE_LIB_DNSAPI =0x77f00000
TARGET_BASE_LIB_MSVCRT =0x78000000
TARGET_BASE_LIB_MSVCRT20 =0x78000000
TARGET_BASE_LIB_MSVCRT20 =0x78500000
TARGET_BASE_LIB_EXPAT =0x79000000
TARGET_BASE_LIB_KERNEL32 =0x7C800000
TARGET_BASE_LIB_NTDLL =0x7C900000

View file

@ -64,7 +64,7 @@ domaininit()
register struct domain *dp, **dpp;
register struct protosw *pr;
printf("domaininit starting\n");
//printf("domaininit starting\n");
/*
* NB - local domain is always present.
@ -73,7 +73,7 @@ domaininit()
ADDDOMAIN(inet);
for (dpp = (struct domain **)domain_set.ls_items; *dpp; dpp++) {
printf("(1) Domain %s counting\n", (**dpp).dom_name);
//printf("(1) Domain %s counting\n", (**dpp).dom_name);
(**dpp).dom_next = domains;
domains = *dpp;
}
@ -84,11 +84,11 @@ domaininit()
#endif
*/
for (dp = domains; dp; dp = dp->dom_next) {
printf("(1) Domain %s initializing\n", dp->dom_name);
//printf("(1) Domain %s initializing\n", dp->dom_name);
if (dp->dom_init)
(*dp->dom_init)();
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
printf("Registering protocols for %s\n", dp->dom_name);
//printf("Registering protocols for %s\n", dp->dom_name);
if (pr->pr_init)
(*pr->pr_init)();
}
@ -103,7 +103,7 @@ domaininit()
timeout(pffasttimo, (void *)0, 1);
timeout(pfslowtimo, (void *)0, 1);
printf("Domaininit done\n");
//printf("Domaininit done\n");
}
struct protosw *

View file

@ -79,11 +79,11 @@ mbinit()
#else
#define NCL_INIT 1
#endif
printf("Here1\n");
//printf("Here1\n");
s = splimp();
if (m_clalloc(NCL_INIT, M_DONTWAIT) == 0)
goto bad;
printf("Here2\n");
//printf("Here2\n");
splx(s);
return;
bad:
@ -116,12 +116,12 @@ m_clalloc(ncl, nowait)
npg = ncl * CLSIZE;
printf("kmem_malloc(%d)\n", npg);
//printf("kmem_malloc(%d)\n", npg);
p = (caddr_t)kmem_malloc(mb_map, ctob(npg),
nowait ? M_NOWAIT : M_WAITOK);
printf("kmem_malloc done\n");
//printf("kmem_malloc done\n");
/*
* Either the map is now full, or this is nowait and there
@ -133,13 +133,13 @@ m_clalloc(ncl, nowait)
ncl = ncl * CLBYTES / MCLBYTES;
for (i = 0; i < ncl; i++) {
((union mcluster *)p)->mcl_next = mclfree;
printf( "Freeing %x onto the free list\n", p);
//printf( "Freeing %x onto the free list\n", p);
mclfree = (union mcluster *)p;
p += MCLBYTES;
mbstat.m_clfree++;
}
mbstat.m_clusters += ncl;
printf( "done with m_clalloc\n");
//printf( "done with m_clalloc\n");
return (1);
}
#endif /* !OSKIT */

View file

@ -694,7 +694,7 @@ GetFileAttributesExW(LPCWSTR lpFileName,
NTSTATUS Status;
WIN32_FILE_ATTRIBUTE_DATA* FileAttributeData;
DPRINT ("GetFileAttributesExW(%S) called\n", lpFileName);
DPRINT("GetFileAttributesExW(%S) called\n", lpFileName);
if (fInfoLevelId != GetFileExInfoStandard || lpFileInformation == NULL)
@ -709,7 +709,7 @@ GetFileAttributesExW(LPCWSTR lpFileName,
NULL,
NULL))
{
DPRINT ("Invalid path\n");
DPRINT1 ("Invalid path\n");
SetLastError (ERROR_BAD_PATHNAME);
return FALSE;
}
@ -731,7 +731,7 @@ GetFileAttributesExW(LPCWSTR lpFileName,
RtlFreeUnicodeString (&FileName);
if (!NT_SUCCESS (Status))
{
DPRINT ("NtOpenFile() failed (Status %lx)\n", Status);
DPRINT1 ("NtOpenFile() failed %x (Status %lx)\n", &ObjectAttributes, Status);
SetLastErrorByStatus (Status);
return FALSE;
}
@ -746,7 +746,7 @@ GetFileAttributesExW(LPCWSTR lpFileName,
if (!NT_SUCCESS (Status))
{
DPRINT ("NtQueryInformationFile() failed (Status %lx)\n", Status);
DPRINT1 ("NtQueryInformationFile() failed (Status %lx)\n", Status);
SetLastErrorByStatus (Status);
return FALSE;
}

View file

@ -41,6 +41,10 @@ static GENERIC_MAPPING ExpEventMapping = {
STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE | EVENT_QUERY_STATE,
EVENT_ALL_ACCESS};
static const INFORMATION_CLASS_INFO ExEventInfoClass[] =
{
ICI_SQ_SAME( sizeof(EVENT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY ), /* EventBasicInformation */
};
/* FUNCTIONS *****************************************************************/
@ -92,6 +96,9 @@ ExpInitializeEventImplementation(VOID)
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtClearEvent(IN HANDLE EventHandle)
{
@ -101,16 +108,16 @@ NtClearEvent(IN HANDLE EventHandle)
Status = ObReferenceObjectByHandle(EventHandle,
EVENT_MODIFY_STATE,
ExEventObjectType,
UserMode,
ExGetPreviousMode(),
(PVOID*)&Event,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
KeClearEvent(Event);
ObDereferenceObject(Event);
return(STATUS_SUCCESS);
if(NT_SUCCESS(Status))
{
KeClearEvent(Event);
ObDereferenceObject(Event);
}
return Status;
}
@ -188,68 +195,119 @@ NtCreateEvent(OUT PHANDLE EventHandle,
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtOpenEvent(OUT PHANDLE EventHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes)
{
NTSTATUS Status;
HANDLE hEvent;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("NtOpenEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, DesiredAccess, ObjectAttributes);
DPRINT("ObjectName '%wZ'\n", ObjectAttributes->ObjectName);
PreviousMode = ExGetPreviousMode();
if(PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(EventHandle,
sizeof(HANDLE),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
if(!NT_SUCCESS(Status))
{
return Status;
}
}
Status = ObOpenObjectByName(ObjectAttributes,
ExEventObjectType,
NULL,
UserMode,
PreviousMode,
DesiredAccess,
NULL,
&hEvent);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = MmCopyToCaller(EventHandle, &hEvent, sizeof(HANDLE));
if (!NT_SUCCESS(Status))
if(NT_SUCCESS(Status))
{
_SEH_TRY
{
ZwClose(EventHandle);
return(Status);
*EventHandle = hEvent;
}
return(Status);
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
return Status;
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtPulseEvent(IN HANDLE EventHandle,
OUT PLONG PreviousState OPTIONAL)
{
PKEVENT Event;
NTSTATUS Status;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("NtPulseEvent(EventHandle %x PreviousState %x)\n",
DPRINT("NtPulseEvent(EventHandle 0%x PreviousState 0%x)\n",
EventHandle, PreviousState);
PreviousMode = ExGetPreviousMode();
if(PreviousState != NULL && PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(PreviousState,
sizeof(LONG),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
Status = ObReferenceObjectByHandle(EventHandle,
EVENT_MODIFY_STATE,
ExEventObjectType,
UserMode,
PreviousMode,
(PVOID*)&Event,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
if(NT_SUCCESS(Status))
{
KePulseEvent(Event, EVENT_INCREMENT, FALSE);
ObDereferenceObject(Event);
/* FIXME - Return the previous state! */
}
KePulseEvent(Event, EVENT_INCREMENT, FALSE);
ObDereferenceObject(Event);
return(STATUS_SUCCESS);
return Status;
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtQueryEvent(IN HANDLE EventHandle,
IN EVENT_INFORMATION_CLASS EventInformationClass,
@ -257,78 +315,129 @@ NtQueryEvent(IN HANDLE EventHandle,
IN ULONG EventInformationLength,
OUT PULONG ReturnLength OPTIONAL)
{
EVENT_BASIC_INFORMATION Info;
PKEVENT Event;
NTSTATUS Status;
ULONG RetLen;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
if (EventInformationClass > EventBasicInformation)
return STATUS_INVALID_INFO_CLASS;
if (EventInformationLength < sizeof(EVENT_BASIC_INFORMATION))
return STATUS_INFO_LENGTH_MISMATCH;
PreviousMode = ExGetPreviousMode();
DefaultQueryInfoBufferCheck(EventInformationClass,
ExEventInfoClass,
EventInformation,
EventInformationLength,
ReturnLength,
PreviousMode,
&Status);
if(!NT_SUCCESS(Status))
{
DPRINT1("NtQueryEvent() failed, Status: 0x%x\n", Status);
return Status;
}
Status = ObReferenceObjectByHandle(EventHandle,
EVENT_QUERY_STATE,
ExEventObjectType,
UserMode,
PreviousMode,
(PVOID*)&Event,
NULL);
if (!NT_SUCCESS(Status))
return Status;
if (Event->Header.Type == InternalNotificationEvent)
Info.EventType = NotificationEvent;
else
Info.EventType = SynchronizationEvent;
Info.EventState = KeReadStateEvent(Event);
Status = MmCopyToCaller(EventInformation, &Event,
sizeof(EVENT_BASIC_INFORMATION));
if (!NT_SUCCESS(Status))
if(NT_SUCCESS(Status))
{
switch(EventInformationClass)
{
ObDereferenceObject(Event);
return(Status);
}
if (ReturnLength != NULL)
{
RetLen = sizeof(EVENT_BASIC_INFORMATION);
Status = MmCopyToCaller(ReturnLength, &RetLen, sizeof(ULONG));
if (!NT_SUCCESS(Status))
case EventBasicInformation:
{
PEVENT_BASIC_INFORMATION BasicInfo = (PEVENT_BASIC_INFORMATION)EventInformation;
_SEH_TRY
{
ObDereferenceObject(Event);
return(Status);
if (Event->Header.Type == InternalNotificationEvent)
BasicInfo->EventType = NotificationEvent;
else
BasicInfo->EventType = SynchronizationEvent;
BasicInfo->EventState = KeReadStateEvent(Event);
if(ReturnLength != NULL)
{
*ReturnLength = sizeof(EVENT_BASIC_INFORMATION);
}
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
break;
}
default:
Status = STATUS_NOT_IMPLEMENTED;
break;
}
ObDereferenceObject(Event);
return(STATUS_SUCCESS);
ObDereferenceObject(Event);
}
return Status;
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtResetEvent(IN HANDLE EventHandle,
OUT PLONG PreviousState OPTIONAL)
{
PKEVENT Event;
NTSTATUS Status;
DPRINT("NtResetEvent(EventHandle %x)\n", EventHandle);
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("NtResetEvent(EventHandle 0%x PreviousState 0%x)\n",
EventHandle, PreviousState);
PreviousMode = ExGetPreviousMode();
if(PreviousState != NULL && PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(PreviousState,
sizeof(LONG),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
Status = ObReferenceObjectByHandle(EventHandle,
EVENT_MODIFY_STATE,
ExEventObjectType,
UserMode,
PreviousMode,
(PVOID*)&Event,
NULL);
if (!NT_SUCCESS(Status))
if(NT_SUCCESS(Status))
{
LONG Prev = KeResetEvent(Event);
ObDereferenceObject(Event);
if(PreviousState != NULL)
{
return(Status);
_SEH_TRY
{
*PreviousState = Prev;
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
KeResetEvent(Event);
ObDereferenceObject(Event);
return(STATUS_SUCCESS);
}
return Status;
}
@ -340,25 +449,58 @@ NtSetEvent(IN HANDLE EventHandle,
OUT PLONG PreviousState OPTIONAL)
{
PKEVENT Event;
NTSTATUS Status;
DPRINT("NtSetEvent(EventHandle %x)\n", EventHandle);
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("NtSetEvent(EventHandle 0%x PreviousState 0%x)\n",
EventHandle, PreviousState);
PreviousMode = ExGetPreviousMode();
if(PreviousState != NULL && PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(PreviousState,
sizeof(LONG),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
Status = ObReferenceObjectByHandle(EventHandle,
EVENT_MODIFY_STATE,
ExEventObjectType,
UserMode,
PreviousMode,
(PVOID*)&Event,
NULL);
if (!NT_SUCCESS(Status))
if(NT_SUCCESS(Status))
{
LONG Prev = KeSetEvent(Event, EVENT_INCREMENT, FALSE);
ObDereferenceObject(Event);
if(PreviousState != NULL)
{
return(Status);
_SEH_TRY
{
*PreviousState = Prev;
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
KeSetEvent(Event,EVENT_INCREMENT,FALSE);
ObDereferenceObject(Event);
return(STATUS_SUCCESS);
}
return Status;
}
/*
* @unimplemented
*/

View file

@ -95,39 +95,66 @@ NtCreateEventPair(OUT PHANDLE EventPairHandle,
IN POBJECT_ATTRIBUTES ObjectAttributes)
{
PKEVENT_PAIR EventPair;
NTSTATUS Status;
HANDLE hEventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
PreviousMode = ExGetPreviousMode();
if(PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(EventPairHandle,
sizeof(HANDLE),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
DPRINT("NtCreateEventPair()\n");
Status = ObCreateObject(ExGetPreviousMode(),
ExEventPairObjectType,
ObjectAttributes,
ExGetPreviousMode(),
PreviousMode,
NULL,
sizeof(KEVENT_PAIR),
0,
0,
(PVOID*)&EventPair);
if (!NT_SUCCESS(Status))
if(NT_SUCCESS(Status))
{
KeInitializeEvent(&EventPair->LowEvent,
SynchronizationEvent,
FALSE);
KeInitializeEvent(&EventPair->HighEvent,
SynchronizationEvent,
FALSE);
Status = ObInsertObject ((PVOID)EventPair,
NULL,
DesiredAccess,
0,
NULL,
&hEventPair);
ObDereferenceObject(EventPair);
if(NT_SUCCESS(Status))
{
return(Status);
_SEH_TRY
{
*EventPairHandle = hEventPair;
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
KeInitializeEvent(&EventPair->LowEvent,
SynchronizationEvent,
FALSE);
KeInitializeEvent(&EventPair->HighEvent,
SynchronizationEvent,
FALSE);
Status = ObInsertObject ((PVOID)EventPair,
NULL,
DesiredAccess,
0,
NULL,
EventPairHandle);
ObDereferenceObject(EventPair);
}
return Status;
}
@ -137,18 +164,47 @@ NtOpenEventPair(OUT PHANDLE EventPairHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes)
{
NTSTATUS Status;
HANDLE hEventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("NtOpenEventPair()\n");
PreviousMode = ExGetPreviousMode();
if(PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(EventPairHandle,
sizeof(HANDLE),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
Status = ObOpenObjectByName(ObjectAttributes,
ExEventPairObjectType,
NULL,
UserMode,
PreviousMode,
DesiredAccess,
NULL,
EventPairHandle);
&hEventPair);
if(NT_SUCCESS(Status))
{
_SEH_TRY
{
*EventPairHandle = hEventPair;
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
return Status;
}
@ -157,26 +213,30 @@ NTSTATUS STDCALL
NtSetHighEventPair(IN HANDLE EventPairHandle)
{
PKEVENT_PAIR EventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status;
DPRINT("NtSetHighEventPair(EventPairHandle %x)\n",
EventPairHandle);
PreviousMode = ExGetPreviousMode();
Status = ObReferenceObjectByHandle(EventPairHandle,
EVENT_PAIR_ALL_ACCESS,
SYNCHRONIZE,
ExEventPairObjectType,
UserMode,
PreviousMode,
(PVOID*)&EventPair,
NULL);
if (!NT_SUCCESS(Status))
return(Status);
if(NT_SUCCESS(Status))
{
KeSetEvent(&EventPair->HighEvent,
EVENT_INCREMENT,
FALSE);
KeSetEvent(&EventPair->HighEvent,
EVENT_INCREMENT,
FALSE);
ObDereferenceObject(EventPair);
return(STATUS_SUCCESS);
ObDereferenceObject(EventPair);
}
return Status;
}
@ -184,32 +244,36 @@ NTSTATUS STDCALL
NtSetHighWaitLowEventPair(IN HANDLE EventPairHandle)
{
PKEVENT_PAIR EventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status;
DPRINT("NtSetHighWaitLowEventPair(EventPairHandle %x)\n",
EventPairHandle);
PreviousMode = ExGetPreviousMode();
Status = ObReferenceObjectByHandle(EventPairHandle,
EVENT_PAIR_ALL_ACCESS,
SYNCHRONIZE,
ExEventPairObjectType,
UserMode,
PreviousMode,
(PVOID*)&EventPair,
NULL);
if (!NT_SUCCESS(Status))
return(Status);
if(NT_SUCCESS(Status))
{
KeSetEvent(&EventPair->HighEvent,
EVENT_INCREMENT,
TRUE);
KeSetEvent(&EventPair->HighEvent,
EVENT_INCREMENT,
TRUE);
KeWaitForSingleObject(&EventPair->LowEvent,
WrEventPair,
PreviousMode,
FALSE,
NULL);
KeWaitForSingleObject(&EventPair->LowEvent,
WrEventPair,
UserMode,
FALSE,
NULL);
ObDereferenceObject(EventPair);
return(STATUS_SUCCESS);
ObDereferenceObject(EventPair);
}
return Status;
}
@ -217,26 +281,30 @@ NTSTATUS STDCALL
NtSetLowEventPair(IN HANDLE EventPairHandle)
{
PKEVENT_PAIR EventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status;
DPRINT("NtSetLowEventPair(EventPairHandle %x)\n",
EventPairHandle);
PreviousMode = ExGetPreviousMode();
Status = ObReferenceObjectByHandle(EventPairHandle,
EVENT_PAIR_ALL_ACCESS,
SYNCHRONIZE,
ExEventPairObjectType,
UserMode,
PreviousMode,
(PVOID*)&EventPair,
NULL);
if (!NT_SUCCESS(Status))
return(Status);
if(NT_SUCCESS(Status))
{
KeSetEvent(&EventPair->LowEvent,
EVENT_INCREMENT,
FALSE);
KeSetEvent(&EventPair->LowEvent,
EVENT_INCREMENT,
FALSE);
ObDereferenceObject(EventPair);
return(STATUS_SUCCESS);
ObDereferenceObject(EventPair);
}
return Status;
}
@ -244,32 +312,36 @@ NTSTATUS STDCALL
NtSetLowWaitHighEventPair(IN HANDLE EventPairHandle)
{
PKEVENT_PAIR EventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status;
DPRINT("NtSetLowWaitHighEventPair(EventPairHandle %x)\n",
EventPairHandle);
PreviousMode = ExGetPreviousMode();
Status = ObReferenceObjectByHandle(EventPairHandle,
EVENT_PAIR_ALL_ACCESS,
SYNCHRONIZE,
ExEventPairObjectType,
UserMode,
PreviousMode,
(PVOID*)&EventPair,
NULL);
if (!NT_SUCCESS(Status))
return(Status);
if(NT_SUCCESS(Status))
{
KeSetEvent(&EventPair->LowEvent,
EVENT_INCREMENT,
TRUE);
KeSetEvent(&EventPair->LowEvent,
EVENT_INCREMENT,
TRUE);
KeWaitForSingleObject(&EventPair->HighEvent,
WrEventPair,
PreviousMode,
FALSE,
NULL);
KeWaitForSingleObject(&EventPair->HighEvent,
WrEventPair,
UserMode,
FALSE,
NULL);
ObDereferenceObject(EventPair);
return(STATUS_SUCCESS);
ObDereferenceObject(EventPair);
}
return Status;
}
@ -277,28 +349,32 @@ NTSTATUS STDCALL
NtWaitLowEventPair(IN HANDLE EventPairHandle)
{
PKEVENT_PAIR EventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status;
DPRINT("NtWaitLowEventPair(EventPairHandle %x)\n",
EventPairHandle);
PreviousMode = ExGetPreviousMode();
Status = ObReferenceObjectByHandle(EventPairHandle,
EVENT_PAIR_ALL_ACCESS,
SYNCHRONIZE,
ExEventPairObjectType,
UserMode,
PreviousMode,
(PVOID*)&EventPair,
NULL);
if (!NT_SUCCESS(Status))
return(Status);
if(NT_SUCCESS(Status))
{
KeWaitForSingleObject(&EventPair->LowEvent,
WrEventPair,
PreviousMode,
FALSE,
NULL);
KeWaitForSingleObject(&EventPair->LowEvent,
WrEventPair,
UserMode,
FALSE,
NULL);
ObDereferenceObject(EventPair);
return(STATUS_SUCCESS);
ObDereferenceObject(EventPair);
}
return Status;
}
@ -306,28 +382,32 @@ NTSTATUS STDCALL
NtWaitHighEventPair(IN HANDLE EventPairHandle)
{
PKEVENT_PAIR EventPair;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status;
DPRINT("NtWaitHighEventPair(EventPairHandle %x)\n",
EventPairHandle);
PreviousMode = ExGetPreviousMode();
Status = ObReferenceObjectByHandle(EventPairHandle,
EVENT_PAIR_ALL_ACCESS,
SYNCHRONIZE,
ExEventPairObjectType,
UserMode,
PreviousMode,
(PVOID*)&EventPair,
NULL);
if (!NT_SUCCESS(Status))
return(Status);
if(NT_SUCCESS(Status))
{
KeWaitForSingleObject(&EventPair->HighEvent,
WrEventPair,
PreviousMode,
FALSE,
NULL);
KeWaitForSingleObject(&EventPair->HighEvent,
WrEventPair,
UserMode,
FALSE,
NULL);
ObDereferenceObject(EventPair);
}
ObDereferenceObject(EventPair);
return(STATUS_SUCCESS);
return Status;
}
#ifdef _ENABLE_THRDEVTPAIR
@ -349,8 +429,8 @@ NtSetLowWaitHighThread(
PKEVENT_PAIR EventPair;
NTSTATUS Status;
KIRQL Irql;
Thread = PsGetCurrentThread();
PreviousMode = ExGetPreviousMode();
if(!Thread->EventPair)
return STATUS_NO_EVENT_PAIR;

View file

@ -40,6 +40,11 @@ static GENERIC_MAPPING ExpMutantMapping = {
STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE | MUTANT_QUERY_STATE,
MUTANT_ALL_ACCESS};
static const INFORMATION_CLASS_INFO ExMutantInfoClass[] =
{
ICI_SQ_SAME( sizeof(MUTANT_BASIC_INFORMATION), sizeof(ULONG), ICIF_QUERY ), /* MutantBasicInformation */
};
/* FUNCTIONS *****************************************************************/
@ -103,105 +108,70 @@ ExpInitializeMutantImplementation(VOID)
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtCreateMutant(OUT PHANDLE MutantHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
IN BOOLEAN InitialOwner)
{
KPROCESSOR_MODE PreviousMode;
HANDLE hMutant;
PKMUTEX Mutant;
NTSTATUS Status;
NTSTATUS Status = STATUS_SUCCESS;
PreviousMode = ExGetPreviousMode();
Status = ObCreateObject(ExGetPreviousMode(),
if(PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(MutantHandle,
sizeof(HANDLE),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
Status = ObCreateObject(PreviousMode,
ExMutantObjectType,
ObjectAttributes,
ExGetPreviousMode(),
PreviousMode,
NULL,
sizeof(KMUTANT),
0,
0,
(PVOID*)&Mutant);
if (!NT_SUCCESS(Status))
{
return(Status);
}
KeInitializeMutant(Mutant,
InitialOwner);
Status = ObInsertObject ((PVOID)Mutant,
NULL,
DesiredAccess,
0,
NULL,
MutantHandle);
ObDereferenceObject(Mutant);
return Status;
}
NTSTATUS STDCALL
NtOpenMutant(OUT PHANDLE MutantHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes)
{
return(ObOpenObjectByName(ObjectAttributes,
ExMutantObjectType,
NULL,
ExGetPreviousMode(),
DesiredAccess,
NULL,
MutantHandle));
}
NTSTATUS STDCALL
NtQueryMutant(IN HANDLE MutantHandle,
IN MUTANT_INFORMATION_CLASS MutantInformationClass,
OUT PVOID MutantInformation,
IN ULONG MutantInformationLength,
OUT PULONG ResultLength OPTIONAL)
{
MUTANT_BASIC_INFORMATION SafeMutantInformation;
PKMUTANT Mutant;
NTSTATUS Status;
if (MutantInformationClass > MutantBasicInformation)
return(STATUS_INVALID_INFO_CLASS);
if (MutantInformationLength < sizeof(MUTANT_BASIC_INFORMATION))
return(STATUS_INFO_LENGTH_MISMATCH);
Status = ObReferenceObjectByHandle(MutantHandle,
MUTANT_QUERY_STATE,
ExMutantObjectType,
ExGetPreviousMode(),
(PVOID*)&Mutant,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
SafeMutantInformation.Count = KeReadStateMutant(Mutant);
SafeMutantInformation.Owned = (Mutant->OwnerThread != NULL);
SafeMutantInformation.Abandoned = Mutant->Abandoned;
ObDereferenceObject(Mutant);
Status = MmCopyToCaller(MutantInformation, &SafeMutantInformation, sizeof(MUTANT_BASIC_INFORMATION));
if(NT_SUCCESS(Status))
{
if(ResultLength != NULL)
KeInitializeMutant(Mutant,
InitialOwner);
Status = ObInsertObject((PVOID)Mutant,
NULL,
DesiredAccess,
0,
NULL,
&hMutant);
ObDereferenceObject(Mutant);
if(NT_SUCCESS(Status))
{
ULONG RetLen = sizeof(MUTANT_BASIC_INFORMATION);
Status = MmCopyToCaller(ResultLength, &RetLen, sizeof(ULONG));
}
else
{
Status = STATUS_SUCCESS;
_SEH_TRY
{
*MutantHandle = hMutant;
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
}
@ -209,41 +179,198 @@ NtQueryMutant(IN HANDLE MutantHandle,
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtReleaseMutant(IN HANDLE MutantHandle,
IN PLONG PreviousCount OPTIONAL)
NtOpenMutant(OUT PHANDLE MutantHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes)
{
PKMUTANT Mutant;
NTSTATUS Status;
LONG Count;
HANDLE hMutant;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
Status = ObReferenceObjectByHandle(MutantHandle,
MUTANT_ALL_ACCESS,
ExMutantObjectType,
ExGetPreviousMode(),
(PVOID*)&Mutant,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
DPRINT1("NtOpenMutant(0x%x, 0x%x, 0x%x)\n", MutantHandle, DesiredAccess, ObjectAttributes);
Count = KeReleaseMutant(Mutant,
MUTANT_INCREMENT,
0,
FALSE);
ObDereferenceObject(Mutant);
PreviousMode = ExGetPreviousMode();
if (PreviousCount != NULL)
if(PreviousMode == UserMode)
{
_SEH_TRY
{
Status = MmCopyToCaller(PreviousCount, &Count, sizeof(LONG));
ProbeForWrite(MutantHandle,
sizeof(HANDLE),
sizeof(ULONG));
}
else
_SEH_HANDLE
{
Status = STATUS_SUCCESS;
Status = _SEH_GetExceptionCode();
}
_SEH_END;
if(!NT_SUCCESS(Status))
{
return Status;
}
}
Status = ObOpenObjectByName(ObjectAttributes,
ExMutantObjectType,
NULL,
PreviousMode,
DesiredAccess,
NULL,
&hMutant);
if(NT_SUCCESS(Status))
{
_SEH_TRY
{
*MutantHandle = hMutant;
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
return Status;
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtQueryMutant(IN HANDLE MutantHandle,
IN MUTANT_INFORMATION_CLASS MutantInformationClass,
OUT PVOID MutantInformation,
IN ULONG MutantInformationLength,
OUT PULONG ResultLength OPTIONAL)
{
PKMUTANT Mutant;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
PreviousMode = ExGetPreviousMode();
DefaultQueryInfoBufferCheck(MutantInformationClass,
ExMutantInfoClass,
MutantInformation,
MutantInformationLength,
ResultLength,
PreviousMode,
&Status);
if(!NT_SUCCESS(Status))
{
DPRINT1("NtQueryMutant() failed, Status: 0x%x\n", Status);
return Status;
}
Status = ObReferenceObjectByHandle(MutantHandle,
MUTANT_QUERY_STATE,
ExMutantObjectType,
PreviousMode,
(PVOID*)&Mutant,
NULL);
if(NT_SUCCESS(Status))
{
switch(MutantInformationClass)
{
case MutantBasicInformation:
{
PMUTANT_BASIC_INFORMATION BasicInfo = (PMUTANT_BASIC_INFORMATION)MutantInformation;
_SEH_TRY
{
BasicInfo->Count = KeReadStateMutant(Mutant);
BasicInfo->Owned = (Mutant->OwnerThread != NULL);
BasicInfo->Abandoned = Mutant->Abandoned;
if(ResultLength != NULL)
{
*ResultLength = sizeof(MUTANT_BASIC_INFORMATION);
}
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
break;
}
default:
Status = STATUS_NOT_IMPLEMENTED;
break;
}
ObDereferenceObject(Mutant);
}
return Status;
}
/*
* @implemented
*/
NTSTATUS STDCALL
NtReleaseMutant(IN HANDLE MutantHandle,
IN PLONG PreviousCount OPTIONAL)
{
PKMUTANT Mutant;
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("NtReleaseMutant(MutantHandle 0%x PreviousCount 0%x)\n",
MutantHandle, PreviousCount);
PreviousMode = ExGetPreviousMode();
if(PreviousCount != NULL && PreviousMode == UserMode)
{
_SEH_TRY
{
ProbeForWrite(PreviousCount,
sizeof(LONG),
sizeof(ULONG));
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
Status = ObReferenceObjectByHandle(MutantHandle,
MUTANT_QUERY_STATE,
ExMutantObjectType,
PreviousMode,
(PVOID*)&Mutant,
NULL);
if(NT_SUCCESS(Status))
{
LONG Prev = KeReleaseMutant(Mutant, MUTANT_INCREMENT, 0, FALSE);
ObDereferenceObject(Mutant);
if(PreviousCount != NULL)
{
_SEH_TRY
{
*PreviousCount = Prev;
}
_SEH_HANDLE
{
Status = _SEH_GetExceptionCode();
}
_SEH_END;
}
}
return Status;
}
/* EOF */

View file

@ -538,7 +538,7 @@ NtQueryAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes,
NTSTATUS Status;
/* Open the file */
Status = NtOpenFile (&FileHandle,
Status = ZwOpenFile (&FileHandle,
SYNCHRONIZE | FILE_READ_ATTRIBUTES,
ObjectAttributes,
&IoStatusBlock,
@ -546,20 +546,20 @@ NtQueryAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes,
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS (Status))
{
DPRINT ("NtOpenFile() failed (Status %lx)\n", Status);
DPRINT ("ZwOpenFile() failed (Status %lx)\n", Status);
return Status;
}
/* Get file attributes */
Status = NtQueryInformationFile (FileHandle,
Status = ZwQueryInformationFile (FileHandle,
&IoStatusBlock,
FileInformation,
sizeof(FILE_BASIC_INFORMATION),
FileBasicInformation);
NtClose (FileHandle);
ZwClose (FileHandle);
if (!NT_SUCCESS (Status))
{
DPRINT ("NtQueryInformationFile() failed (Status %lx)\n", Status);
DPRINT ("ZwQueryInformationFile() failed (Status %lx)\n", Status);
}
return Status;
@ -575,7 +575,7 @@ NtQueryFullAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes,
NTSTATUS Status;
/* Open the file */
Status = NtOpenFile (&FileHandle,
Status = ZwOpenFile (&FileHandle,
SYNCHRONIZE | FILE_READ_ATTRIBUTES,
ObjectAttributes,
&IoStatusBlock,
@ -583,20 +583,20 @@ NtQueryFullAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes,
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS (Status))
{
DPRINT ("NtOpenFile() failed (Status %lx)\n", Status);
DPRINT ("ZwOpenFile() failed (Status %lx)\n", Status);
return Status;
}
/* Get file attributes */
Status = NtQueryInformationFile (FileHandle,
Status = ZwQueryInformationFile (FileHandle,
&IoStatusBlock,
FileInformation,
sizeof(FILE_NETWORK_OPEN_INFORMATION),
FileNetworkOpenInformation);
NtClose (FileHandle);
ZwClose (FileHandle);
if (!NT_SUCCESS (Status))
{
DPRINT ("NtQueryInformationFile() failed (Status %lx)\n", Status);
DPRINT ("ZwQueryInformationFile() failed (Status %lx)\n", Status);
}
return Status;

View file

@ -608,7 +608,7 @@ ObCreateObject (IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL,
{
ProbeForRead(ObjectAttributes,
sizeof(OBJECT_ATTRIBUTES),
sizeof(ULONG));
sizeof(USHORT)); /*FIXME: HACK! kernel32/file/file.c:~734 is having a weird stack */
}
_SEH_HANDLE
{

View file

@ -52,10 +52,10 @@
VOID CALLBACK
ServiceMain(DWORD argc, LPTSTR *argv)
{
DPRINT1("ServiceMain() called\n");
DPRINT("ServiceMain() called\n");
DPRINT1("ServiceMain() done\n");
DPRINT("ServiceMain() done\n");
}