to clean up return val checking of some mdl calls

svn path=/trunk/; revision=9725
This commit is contained in:
Vizzini 2004-06-19 08:53:35 +00:00
parent 5d2036782e
commit 4444a6885d
6 changed files with 155 additions and 36 deletions

View file

@ -1,4 +1,4 @@
/* $Id: copy.c,v 1.24 2004/06/19 05:04:33 sedwards Exp $
/* $Id: copy.c,v 1.25 2004/06/19 08:53:35 vizzini Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -139,7 +139,12 @@ ReadCacheSegmentChain(PBCB Bcb, ULONG ReadOffset, ULONG Length,
/*
* Create an MDL which contains all their pages.
*/
MmInitializeMdl(Mdl, NULL, current_size);
Mdl = MmCreateMdl(NULL, NULL, current_size);
if(Mdl == NULL) {
DPRINT("MmCreateMdl: Out of memory!");
return(STATUS_NO_MEMORY);
}
Mdl->MdlFlags |= (MDL_PAGES_LOCKED | MDL_IO_PAGE_READ);
current2 = current;
offset = 0;
@ -222,8 +227,14 @@ ReadCacheSegment(PCACHE_SEGMENT CacheSeg)
{
Size = CacheSeg->Bcb->CacheSegmentSize;
}
Mdl = alloca(MmSizeOfMdl(CacheSeg->BaseAddress, Size));
MmInitializeMdl(Mdl, CacheSeg->BaseAddress, Size);
Mdl = MmCreateMdl(NULL, CacheSeg->BaseAddress, Size);
if(Mdl == NULL)
{
DPRINT("MmCreateMdl: Out of memory!");
return(STATUS_NO_MEMORY);
}
MmBuildMdlForNonPagedPool(Mdl);
Mdl->MdlFlags |= MDL_IO_PAGE_READ;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
@ -264,8 +275,14 @@ WriteCacheSegment(PCACHE_SEGMENT CacheSeg)
{
Size = CacheSeg->Bcb->CacheSegmentSize;
}
Mdl = alloca(MmSizeOfMdl(CacheSeg->BaseAddress, Size));
MmInitializeMdl(Mdl, CacheSeg->BaseAddress, Size);
Mdl = MmCreateMdl(NULL, CacheSeg->BaseAddress, Size);
if(Mdl == NULL)
{
DPRINT("MmCreateMdl: Out of memory!");
return(STATUS_NO_MEMORY);
}
MmBuildMdlForNonPagedPool(Mdl);
Mdl->MdlFlags |= MDL_IO_PAGE_READ;
KeInitializeEvent(&Event, NotificationEvent, FALSE);

View file

@ -1,4 +1,4 @@
/* $Id: buildirp.c,v 1.39 2004/03/04 00:07:00 navaraf Exp $
/* $Id: buildirp.c,v 1.40 2004/06/19 08:53:35 vizzini Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -56,6 +56,10 @@ NTSTATUS IoPrepareIrpBuffer(PIRP Irp,
DPRINT("Doing direct i/o\n");
Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
if(Irp->MdlAddress == NULL) {
DPRINT("MmCreateMdl: Out of memory!");
return(STATUS_NO_MEMORY);
}
if (MajorFunction == IRP_MJ_READ)
{
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
@ -298,6 +302,10 @@ IoBuildDeviceIoControlRequest(ULONG IoControlCode,
FALSE,
FALSE,
Irp);
if(Irp->MdlAddress == NULL) {
IoFreeIrp(Irp);
return(NULL);
}
MmProbeAndLockPages (Irp->MdlAddress,UserMode,IoReadAccess);
}
break;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: pagefile.c,v 1.47 2004/06/06 09:13:21 hbirr Exp $
/* $Id: pagefile.c,v 1.48 2004/06/19 08:53:35 vizzini Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/pagefile.c
@ -376,18 +376,13 @@ MiAllocPageFromPagingFile(PPAGINGFILE PagingFile)
{
if (!(PagingFile->AllocMap[i] & (1 << j)))
{
break;
PagingFile->AllocMap[i] |= (1 << j);
PagingFile->UsedPages++;
PagingFile->FreePages--;
KeReleaseSpinLock(&PagingFile->AllocMapLock, oldIrql);
return((i * 32) + j);
}
}
if (j == 32)
{
continue;
}
PagingFile->AllocMap[i] |= (1 << j);
PagingFile->UsedPages++;
PagingFile->FreePages--;
KeReleaseSpinLock(&PagingFile->AllocMapLock, oldIrql);
return((i * 32) + j);
}
KeReleaseSpinLock(&PagingFile->AllocMapLock, oldIrql);
@ -403,6 +398,12 @@ MmFreeSwapPage(SWAPENTRY Entry)
i = FILE_FROM_ENTRY(Entry);
off = OFFSET_FROM_ENTRY(Entry);
if (i >= MAX_PAGING_FILES)
{
DPRINT1("Bad swap entry 0x%.8X\n", Entry);
KEBUGCHECK(0);
}
KeAcquireSpinLock(&PagingFileListLock, &oldIrql);
if (PagingFileList[i] == NULL)
@ -410,9 +411,9 @@ MmFreeSwapPage(SWAPENTRY Entry)
KEBUGCHECK(0);
}
KeAcquireSpinLockAtDpcLevel(&PagingFileList[i]->AllocMapLock);
PagingFileList[i]->AllocMap[off / 32] &= (~(1 << (off % 32)));
PagingFileList[i]->AllocMap[off >> 5] &= (~(1 << (off % 32)));
PagingFileList[i]->FreePages++;
PagingFileList[i]->UsedPages--;
@ -685,6 +686,12 @@ MmInitializeCrashDump(HANDLE PageFileHandle, ULONG PageFileNum)
FALSE,
&Event,
&Iosb);
if(Irp == NULL)
{
ObDereferenceObject(PageFile);
return(STATUS_NO_MEMORY);// tMk - is this correct return code ???
}
StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->FileObject = PageFile;
StackPtr->DeviceObject = PageFileDevice;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: virtual.c,v 1.75 2004/06/13 10:35:52 navaraf Exp $
/* $Id: virtual.c,v 1.76 2004/06/19 08:53:35 vizzini Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/virtual.c
@ -59,6 +59,12 @@ NtFlushVirtualMemory(IN HANDLE ProcessHandle,
return(STATUS_NOT_IMPLEMENTED);
}
/* (tMk 2004.II.4)
* FUNCTION: Locks range of process virtual memory.
* Called from VirtualLock (lib\kernel32\mem\virtual.c)
*
* NOTE: This function will be correct if MmProbeAndLockPages() would be fully IMPLEMENTED.
*/
NTSTATUS STDCALL
NtLockVirtualMemory(HANDLE ProcessHandle,
PVOID BaseAddress,
@ -82,7 +88,7 @@ NtLockVirtualMemory(HANDLE ProcessHandle,
UserMode,
(PVOID*)(&Process),
NULL);
if (Status != STATUS_SUCCESS)
if (!NT_SUCCESS(Status))
{
return(Status);
}
@ -90,6 +96,11 @@ NtLockVirtualMemory(HANDLE ProcessHandle,
Mdl = MmCreateMdl(NULL,
BaseAddress,
NumberOfBytesToLock);
if(Mdl == NULL)
{
ObDereferenceObject(Process);
return(STATUS_NO_MEMORY);
}
MmProbeAndLockPages(Mdl,
UserMode,
IoWriteAccess);
@ -102,7 +113,13 @@ NtLockVirtualMemory(HANDLE ProcessHandle,
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL
/* (tMk 2004.II.4)
* FUNCTION:
* Called from VirtualQueryEx (lib\kernel32\mem\virtual.c)
*
*/
NTSTATUS STDCALL
NtQueryVirtualMemory (IN HANDLE ProcessHandle,
IN PVOID Address,
IN CINT VirtualMemoryInformationClass,
@ -204,6 +221,12 @@ NtQueryVirtualMemory (IN HANDLE ProcessHandle,
return(Status);
}
/* (tMk 2004.II.5)
* FUNCTION:
* Called from VirtualProtectEx (lib\kernel32\mem\virtual.c)
*
*/
NTSTATUS STDCALL
NtProtectVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID *UnsafeBaseAddress,
@ -226,6 +249,13 @@ NtProtectVirtualMemory(IN HANDLE ProcessHandle,
if (!NT_SUCCESS(Status))
return Status;
// (tMk 2004.II.5) in Microsoft SDK I read:
// 'if this parameter is NULL or does not point to a valid variable, the function fails'
if(UnsafeOldAccessProtection == NULL)
{
return(STATUS_INVALID_PARAMETER);
}
NumberOfBytesToProtect =
PAGE_ROUND_UP(BaseAddress + NumberOfBytesToProtect) -
PAGE_ROUND_DOWN(BaseAddress);
@ -279,6 +309,13 @@ NtProtectVirtualMemory(IN HANDLE ProcessHandle,
return(Status);
}
/* (tMk 2004.II.05)
* FUNCTION:
* Called from ReadProcessMemory (lib\kernel32\mem\procmem.c) and KlInitPeb(lib\kernel32\process\create.c)
*
* NOTE: This function will be correct if MmProbeAndLockPages() would be fully IMPLEMENTED.
*/
NTSTATUS STDCALL
NtReadVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
@ -301,7 +338,7 @@ NtReadVirtualMemory(IN HANDLE ProcessHandle,
UserMode,
(PVOID*)(&Process),
NULL);
if (Status != STATUS_SUCCESS)
if (!NT_SUCCESS(Status))
{
return(Status);
}
@ -309,6 +346,11 @@ NtReadVirtualMemory(IN HANDLE ProcessHandle,
Mdl = MmCreateMdl(NULL,
Buffer,
NumberOfBytesToRead);
if(Mdl == NULL)
{
ObDereferenceObject(Process);
return(STATUS_NO_MEMORY);
}
MmProbeAndLockPages(Mdl,
UserMode,
IoWriteAccess);
@ -331,10 +373,13 @@ NtReadVirtualMemory(IN HANDLE ProcessHandle,
if (NumberOfBytesRead)
*NumberOfBytesRead = NumberOfBytesToRead;
return(STATUS_SUCCESS);
}
/* (tMk 2004.II.05)
* FUNCTION: THIS function doesn't make a sense...
* Called from VirtualUnlock (lib\kernel32\mem\virtual.c)
*/
NTSTATUS STDCALL
NtUnlockVirtualMemory(HANDLE ProcessHandle,
PVOID BaseAddress,
@ -358,7 +403,7 @@ NtUnlockVirtualMemory(HANDLE ProcessHandle,
UserMode,
(PVOID*)(&Process),
NULL);
if (Status != STATUS_SUCCESS)
if (!NT_SUCCESS(Status))
{
return(Status);
}
@ -366,6 +411,11 @@ NtUnlockVirtualMemory(HANDLE ProcessHandle,
Mdl = MmCreateMdl(NULL,
BaseAddress,
NumberOfBytesToUnlock);
if(Mdl == NULL)
{
ObDereferenceObject(Process);
return(STATUS_NO_MEMORY);
}
ObDereferenceObject(Process);
@ -382,6 +432,12 @@ NtUnlockVirtualMemory(HANDLE ProcessHandle,
}
/* (tMk 2004.II.05)
* FUNCTION:
* Called from WriteProcessMemory (lib\kernel32\mem\procmem.c) and KlInitPeb(lib\kernel32\process\create.c)
*
* NOTE: This function will be correct if MmProbeAndLockPages() would be fully IMPLEMENTED.
*/
NTSTATUS STDCALL
NtWriteVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
@ -404,7 +460,7 @@ NtWriteVirtualMemory(IN HANDLE ProcessHandle,
UserMode,
(PVOID*)(&Process),
NULL);
if (Status != STATUS_SUCCESS)
if (!NT_SUCCESS(Status))
{
return(Status);
}
@ -415,7 +471,11 @@ NtWriteVirtualMemory(IN HANDLE ProcessHandle,
MmProbeAndLockPages(Mdl,
UserMode,
IoReadAccess);
if(Mdl == NULL)
{
ObDereferenceObject(Process);
return(STATUS_NO_MEMORY);
}
KeAttachProcess(Process);
SystemAddress = MmGetSystemAddressForMdl(Mdl);
@ -437,7 +497,8 @@ NtWriteVirtualMemory(IN HANDLE ProcessHandle,
return(STATUS_SUCCESS);
}
/*
/* FUNCTION:
* Called from EngSecureMem (subsys\win32k\eng\mem.c)
* @unimplemented
*/
PVOID STDCALL
@ -457,7 +518,8 @@ MmSecureVirtualMemory (PVOID Address,
}
/*
/* FUNCTION:
* Called from EngUnsecureMem (subsys\win32k\eng\mem.c)
* @unimplemented
*/
VOID STDCALL

View file

@ -482,6 +482,10 @@ NtCreateProfile(OUT PHANDLE UnsafeProfileHandle,
Profile->Size = ImageSize;
Profile->BucketShift = Granularity;
Profile->BufferMdl = MmCreateMdl(NULL, Buffer, BufferSize);
if(Profile->BufferMdl == NULL) {
DPRINT("MmCreateMdl: Out of memory!");
return(STATUS_NO_MEMORY);
}
MmProbeAndLockPages(Profile->BufferMdl, UserMode, IoWriteAccess);
Profile->Buffer = MmGetSystemAddressForMdl(Profile->BufferMdl);
Profile->BufferSize = BufferSize;

View file

@ -26,6 +26,9 @@ extern CHAR KiTimerSystemAuditing;
/* FUNCTIONS *****************************************************************/
/** System idle thread procedure
*
*/
VOID STDCALL
PsIdleThreadMain(PVOID Context)
{
@ -50,28 +53,46 @@ PsIdleThreadMain(PVOID Context)
}
}
/** Initialization of system idle thread
*
*/
VOID INIT_FUNCTION
PsInitIdleThread(VOID)
{
KPRIORITY Priority;
ULONG Affinity;
PsCreateSystemThread(&PsIdleThreadHandle,
NTSTATUS Status;
Status = PsCreateSystemThread(&PsIdleThreadHandle,
THREAD_ALL_ACCESS,
NULL,
NULL,
NULL,
PsIdleThreadMain,
NULL);
if(!NT_SUCCESS(Status)) {
DPRINT("Couldn't create Idle System Thread!");
KEBUGCHECK(0);
return;
}
Priority = LOW_PRIORITY;
NtSetInformationThread(PsIdleThreadHandle,
Status = NtSetInformationThread(PsIdleThreadHandle,
ThreadPriority,
&Priority,
sizeof(Priority));
if(!NT_SUCCESS(Status)) {
DPRINT("Couldn't set Priority to Idle System Thread!");
return;
}
Affinity = 1 << 0;
NtSetInformationThread(PsIdleThreadHandle,
Status = NtSetInformationThread(PsIdleThreadHandle,
ThreadAffinityMask,
&Affinity,
sizeof(Affinity));
if(!NT_SUCCESS(Status)) {
DPRINT("Couldn't set Affinity Mask to Idle System Thread!");
}
}