Section and general memory manager enhancements including COW

svn path=/trunk/; revision=1617
This commit is contained in:
David Welch 2001-02-10 22:51:11 +00:00
parent 29c4727f7a
commit 9359db14a0
41 changed files with 2057 additions and 1262 deletions

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.14 2001/01/16 09:55:02 dwelch Exp $
/* $Id: create.c,v 1.15 2001/02/10 22:51:11 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -446,6 +446,10 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
FileObject->FsContext = (PVOID)&Fcb->RFCB;
newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB));
memset (newCCB, 0, sizeof (VFATCCB));
FileObject->Flags = FileObject->Flags |
FO_FCB_IS_VALID | FO_DIRECT_CACHE_PAGING_READ;
FileObject->SectionObjectPointers =
&Fcb->SectionObjectPointers;
FileObject->FsContext2 = newCCB;
newCCB->pFcb = Fcb;
newCCB->PtrFileObject = FileObject;
@ -563,6 +567,9 @@ VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
FileObject->Flags = FileObject->Flags |
FO_FCB_IS_VALID | FO_DIRECT_CACHE_PAGING_READ;
FileObject->SectionObjectPointers = &ParentFcb->SectionObjectPointers;
memset(FileObject->SectionObjectPointers, 0,
sizeof(SECTION_OBJECT_POINTERS));
FileObject->FsContext = (PVOID)&ParentFcb->RFCB;
newCCB = ExAllocatePool (NonPagedPool, sizeof (VFATCCB));
memset (newCCB, 0, sizeof (VFATCCB));

View file

@ -1,4 +1,4 @@
/* $Id: vfat.h,v 1.24 2001/01/16 09:55:02 dwelch Exp $ */
/* $Id: vfat.h,v 1.25 2001/02/10 22:51:11 dwelch Exp $ */
#include <ddk/ntifs.h>
@ -95,6 +95,7 @@ typedef struct
typedef struct _VFATFCB
{
REACTOS_COMMON_FCB_HEADER RFCB;
SECTION_OBJECT_POINTERS SectionObjectPointers;
FATDirEntry entry;
/* point on filename (250 chars max) in PathName */
WCHAR *ObjectName;

View file

@ -1,7 +1,7 @@
#ifndef _NTOS_CCFUNCS_H
#define _NTOS_CCFUNCS_H
/* $Id: ccfuncs.h,v 1.5 2000/06/12 14:51:26 ekohl Exp $ */
/* $Id: ccfuncs.h,v 1.6 2001/02/10 22:51:07 dwelch Exp $ */
/* exported variables */
/*
@ -325,4 +325,4 @@ CcZeroData (
#endif
/* EOF */
/* EOF */

View file

@ -81,6 +81,6 @@ typedef struct _REACTOS_COMMON_FCB_HEADER
LARGE_INTEGER AllocationSize;
LARGE_INTEGER FileSize;
LARGE_INTEGER ValidDataLength;
} REACTOS_COMMON_FCB_HEADER;
} REACTOS_COMMON_FCB_HEADER, *PREACTOS_COMMON_FCB_HEADER;
#endif /* __INCLUDE_DDK_CCTYPES_H */

View file

@ -1,4 +1,4 @@
/* $Id: iotypes.h,v 1.22 2001/01/08 02:14:05 dwelch Exp $
/* $Id: iotypes.h,v 1.23 2001/02/10 22:51:07 dwelch Exp $
*
*/
@ -714,4 +714,4 @@ VOID
);
#endif // (_WIN32_WINNT >= 0x0400)
#endif __INCLUDE_DDK_IOTYPES_H
#endif /* __INCLUDE_DDK_IOTYPES_H */

View file

@ -1,4 +1,4 @@
/* $Id: rtl.h,v 1.46 2000/12/29 13:47:30 ekohl Exp $
/* $Id: rtl.h,v 1.47 2001/02/10 22:51:07 dwelch Exp $
*
*/
@ -875,13 +875,8 @@ RtlExtendedMagicDivide (
CCHAR ShiftCount
);
VOID
STDCALL
RtlFillMemory (
PVOID Destination,
ULONG Length,
UCHAR Fill
);
VOID STDCALL
RtlFillMemory (PVOID Destination, ULONG Length, UCHAR Fill);
VOID
STDCALL
@ -1299,13 +1294,8 @@ RtlLookupAtomInAtomTable (
OUT PRTL_ATOM Atom
);
VOID
STDCALL
RtlMoveMemory (
PVOID Destination,
CONST VOID * Source,
ULONG Length
);
VOID STDCALL
RtlMoveMemory (PVOID Destination, CONST VOID* Source, ULONG Length);
NTSTATUS
STDCALL
@ -1787,12 +1777,8 @@ RtlWriteRegistryValue (
ULONG ValueLength
);
VOID
STDCALL
RtlZeroMemory (
PVOID Destination,
ULONG Length
);
VOID STDCALL
RtlZeroMemory (PVOID Destination, ULONG Length);
ULONG
STDCALL

View file

@ -1257,4 +1257,34 @@ struct _LPC_PORT_BASIC_INFORMATION
} LPC_PORT_BASIC_INFORMATION, * PLPC_PORT_BASIC_INFORMATION;
typedef struct _SECTION_BASIC_INFORMATION
{
PVOID BaseAddress;
ULONG Attributes;
LARGE_INTEGER Size;
} SECTION_BASIC_INFORMATION, *PSECTION_BASIC_INFORMATION;
typedef struct _SECTION_IMAGE_INFORMATION
{
PVOID EntryPoint;
ULONG Unknown1;
ULONG StackReserve;
ULONG StackCommit;
ULONG Subsystem;
USHORT MinorSubsystemVersion;
USHORT MajorSubsystemVersion;
ULONG Unknown2;
ULONG Characteristics;
USHORT ImageNumber;
BOOLEAN Executable;
UCHAR Unknown3;
ULONG Unknown4[3];
} SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;
typedef enum _SECTION_INFORMATION_CLASS
{
SectionBasicInformation,
SectionImageInformation,
} SECTION_INFORMATION_CLASS;
#endif

View file

@ -1,4 +1,4 @@
/* $Id: rtl.h,v 1.21 2000/12/29 13:47:43 ekohl Exp $
/* $Id: rtl.h,v 1.22 2001/02/10 22:51:07 dwelch Exp $
*
*/
@ -6,6 +6,7 @@
#define __INCLUDE_NTDLL_RTL_H
#include <napi/teb.h>
#include <ddk/ntddk.h>
typedef struct _CRITICAL_SECTION_DEBUG {
WORD Type;
@ -27,27 +28,6 @@ typedef struct _CRITICAL_SECTION {
DWORD Reserved;
} CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
typedef struct _SECTION_IMAGE_INFORMATION
{
PVOID ProcessEntryPoint;
ULONG StackZero;
ULONG StackReserve;
ULONG StackCommit;
ULONG SubsystemType;
USHORT MinorImageVersion;
USHORT MajorImageVersion;
ULONG u4;
ULONG Characteristics;
USHORT Machine;
BOOLEAN Executable;
USHORT u6;
ULONG u7;
ULONG u8;
ULONG u9;
}SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;
typedef struct _RTL_PROCESS_INFO
{
ULONG Size;

View file

@ -1,4 +1,4 @@
/* $Id: rtl.c,v 1.3 2000/07/01 17:07:00 ea Exp $
/* $Id: rtl.c,v 1.4 2001/02/10 22:51:07 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -11,90 +11,80 @@
#include <windows.h>
typedef DWORD ( *RtlFillMemoryType) (DWORD Unknown0, DWORD Unknown1, DWORD Unknown2 );
typedef DWORD
(*RtlFillMemoryType) (PVOID Destination, ULONG Length, UCHAR Fill);
#undef FillMemory
DWORD
STDCALL
RtlFillMemory (
DWORD Unknown0,
DWORD Unknown1,
DWORD Unknown2
)
VOID STDCALL
RtlFillMemory (PVOID Destination, ULONG Length, UCHAR Fill)
{
HINSTANCE hModule;
RtlFillMemoryType FillMemory;
hModule = LoadLibraryA("ntdll.dll");
if ( hModule == NULL )
return -1;
FillMemory = (RtlFillMemoryType)GetProcAddress(hModule, "RtlFillMemory");
if ( FillMemory == NULL )
return -1;
return FillMemory(Unknown0, Unknown1, Unknown2);
HINSTANCE hModule;
RtlFillMemoryType FillMemory;
hModule = LoadLibraryA("ntdll.dll");
if (hModule == NULL)
return;
FillMemory = (RtlFillMemoryType)GetProcAddress(hModule, "RtlFillMemory");
if ( FillMemory == NULL )
return;
FillMemory(Destination, Length, Fill);
}
typedef DWORD ( *RtlMoveMemoryType) (DWORD Unknown0, DWORD Unknown1, DWORD Unknown2 );
typedef DWORD
(*RtlMoveMemoryType) (PVOID Destination, CONST VOID* Source, ULONG Length);
#undef MoveMemory
DWORD
STDCALL
RtlMoveMemory (
DWORD Unknown0,
DWORD Unknown1,
DWORD Unknown2
)
VOID STDCALL
RtlMoveMemory (PVOID Destination, CONST VOID* Source, ULONG Length)
{
HINSTANCE hModule;
RtlMoveMemoryType MoveMemory;
hModule = LoadLibraryA("ntdll.dll");
if ( hModule == NULL )
return -1;
MoveMemory = (RtlMoveMemoryType)GetProcAddress(hModule, "RtlMoveMemory");
if ( MoveMemory == NULL )
return -1;
return MoveMemory(Unknown0, Unknown1, Unknown2);
HINSTANCE hModule;
RtlMoveMemoryType MoveMemory;
hModule = LoadLibraryA("ntdll.dll");
if (hModule == NULL)
return;
MoveMemory = (RtlMoveMemoryType)GetProcAddress(hModule, "RtlMoveMemory");
if (MoveMemory == NULL)
return;
MoveMemory(Destination, Source, Length);
}
typedef DWORD ( *RtlZeroMemoryType) (DWORD Unknown0, DWORD Unknown1 );
typedef DWORD ( *RtlZeroMemoryType) (PVOID Destination, ULONG Length);
#undef ZeroMemory
DWORD
STDCALL
RtlZeroMemory (
DWORD Unknown0,
DWORD Unknown1
)
VOID STDCALL
RtlZeroMemory (PVOID Destination, ULONG Length)
{
HINSTANCE hModule;
RtlZeroMemoryType ZeroMemory;
hModule = LoadLibraryA("ntdll.dll");
if ( hModule == NULL )
return -1;
ZeroMemory = (RtlZeroMemoryType)GetProcAddress(hModule, "RtlZeroMemory");
if ( ZeroMemory == NULL )
return -1;
return ZeroMemory(Unknown0, Unknown1);
HINSTANCE hModule;
RtlZeroMemoryType ZeroMemory;
hModule = LoadLibraryA("ntdll.dll");
if (hModule == NULL)
return;
ZeroMemory = (RtlZeroMemoryType)GetProcAddress(hModule, "RtlZeroMemory");
if (ZeroMemory == NULL)
return;
ZeroMemory(Destination, Length);
}
typedef DWORD ( *RtlUnwindType) (DWORD Unknown0, DWORD Unknown1, DWORD Unknown2, DWORD Unknown3 );
#undef Unwind
DWORD
VOID
STDCALL
RtlUnwind (
DWORD Unknown0,
DWORD Unknown1,
DWORD Unknown2,
DWORD Unknown3
ULONG Unknown0,
ULONG Unknown1,
ULONG Unknown2,
ULONG Unknown3
)
{
HINSTANCE hModule;
RtlUnwindType Unwind;
hModule = LoadLibraryA("ntdll.dll");
if ( hModule == NULL )
return -1;
return;
Unwind = (RtlUnwindType)GetProcAddress(hModule, "RtlUnwind");
if ( Unwind == NULL )
return -1;
return Unwind(Unknown0, Unknown1, Unknown2, Unknown3);
return;
Unwind(Unknown0, Unknown1, Unknown2, Unknown3);
}

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.34 2001/02/10 22:30:21 ekohl Exp $
/* $Id: create.c,v 1.35 2001/02/10 22:51:08 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -383,6 +383,8 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
NTSTATUS Status;
LPTHREAD_START_ROUTINE lpStartAddress = NULL;
WCHAR TempCommandLine[256];
WCHAR ImagePathName[256];
UNICODE_STRING ImagePathName_U;
PROCESS_BASIC_INFORMATION ProcessBasicInfo;
ULONG retlen;
PRTL_USER_PROCESS_PARAMETERS Ppb;
@ -433,6 +435,8 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
256 * sizeof(WCHAR),
TempCommandLine,
NULL);
wcscpy(ImagePathName, TempCommandLine);
RtlInitUnicodeString(&ImagePathName_U, ImagePathName);
if (lpCommandLine != NULL)
{
@ -453,7 +457,7 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
DPRINT("CommandLine_U %S\n", CommandLine_U.Buffer);
RtlCreateProcessParameters(&Ppb,
&CommandLine_U,
&ImagePathName_U,
NULL,
(lpCurrentDirectory == NULL) ? NULL : &CurrentDirectoryW,
&CommandLine_U,

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.40 2001/02/10 22:23:30 ekohl Exp $
/* $Id: utils.c,v 1.41 2001/02/10 22:51:08 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -155,288 +155,269 @@ LdrLoadDll (IN PWSTR SearchPath OPTIONAL,
IN PUNICODE_STRING Name,
OUT PVOID *BaseAddress OPTIONAL)
{
WCHAR SearchPathBuffer[MAX_PATH];
WCHAR FullDosName[MAX_PATH];
UNICODE_STRING AdjustedName;
UNICODE_STRING FullNtFileName;
OBJECT_ATTRIBUTES FileObjectAttributes;
char BlockBuffer [1024];
PIMAGE_DOS_HEADER DosHeader;
NTSTATUS Status;
PIMAGE_NT_HEADERS NTHeaders;
ULONG ImageSize;
ULONG InitialViewSize;
PVOID ImageBase;
HANDLE FileHandle;
HANDLE SectionHandle;
PDLLMAIN_FUNC Entrypoint = NULL;
PLDR_MODULE Module;
WCHAR SearchPathBuffer[MAX_PATH];
WCHAR FullDosName[MAX_PATH];
UNICODE_STRING AdjustedName;
UNICODE_STRING FullNtFileName;
OBJECT_ATTRIBUTES FileObjectAttributes;
char BlockBuffer [1024];
PIMAGE_DOS_HEADER DosHeader;
NTSTATUS Status;
PIMAGE_NT_HEADERS NTHeaders;
ULONG ImageSize;
ULONG InitialViewSize;
PVOID ImageBase;
HANDLE FileHandle;
HANDLE SectionHandle;
PDLLMAIN_FUNC Entrypoint = NULL;
PLDR_MODULE Module;
if (Name == NULL)
{
*BaseAddress = NtCurrentPeb()->ImageBaseAddress;
return STATUS_SUCCESS;
}
*BaseAddress = NULL;
DPRINT("LdrLoadDll(Name \"%wZ\" BaseAddress %x)\n",
Name, BaseAddress);
/* adjust the full dll name */
LdrAdjustDllName (&AdjustedName,
Name,
FALSE);
DPRINT("AdjustedName: %wZ\n", &AdjustedName);
/*
* Test if dll is already loaded.
*/
if (LdrFindDll(&Module, &AdjustedName) == STATUS_SUCCESS)
{
DPRINT("DLL %wZ already loaded.\n", &AdjustedName);
if (Module->LoadCount != -1)
Module->LoadCount++;
*BaseAddress = Module->BaseAddress;
return STATUS_SUCCESS;
}
DPRINT("Loading \"%wZ\"\n", Name);
if (SearchPath == NULL)
{
PKUSER_SHARED_DATA SharedUserData =
(PKUSER_SHARED_DATA)USER_SHARED_DATA_BASE;
SearchPath = SearchPathBuffer;
wcscpy (SearchPathBuffer, SharedUserData->NtSystemRoot);
wcscat (SearchPathBuffer, L"\\system32;");
wcscat (SearchPathBuffer, SharedUserData->NtSystemRoot);
}
if ( Name == NULL )
{
*BaseAddress = NtCurrentPeb()->ImageBaseAddress;
return STATUS_SUCCESS;
}
*BaseAddress = NULL;
DPRINT("LdrLoadDll(Name \"%wZ\" BaseAddress %x)\n",
Name, BaseAddress);
/* adjust the full dll name */
LdrAdjustDllName (&AdjustedName,
Name,
FALSE);
DPRINT("AdjustedName: %wZ\n", &AdjustedName);
/*
* Test if dll is already loaded.
*/
if (LdrFindDll(&Module, &AdjustedName) == STATUS_SUCCESS)
{
DPRINT("DLL %wZ already loaded.\n", &AdjustedName);
if (Module->LoadCount != -1)
Module->LoadCount++;
*BaseAddress = Module->BaseAddress;
return STATUS_SUCCESS;
}
DPRINT("Loading \"%wZ\"\n", Name);
if (SearchPath == NULL)
{
PKUSER_SHARED_DATA SharedUserData =
(PKUSER_SHARED_DATA)USER_SHARED_DATA_BASE;
SearchPath = SearchPathBuffer;
wcscpy (SearchPathBuffer, SharedUserData->NtSystemRoot);
wcscat (SearchPathBuffer, L"\\system32;");
wcscat (SearchPathBuffer, SharedUserData->NtSystemRoot);
}
DPRINT("SearchPath %S\n", SearchPath);
if (RtlDosSearchPath_U (SearchPath,
AdjustedName.Buffer,
NULL,
MAX_PATH,
FullDosName,
NULL) == 0)
return STATUS_DLL_NOT_FOUND;
DPRINT("FullDosName %S\n", FullDosName);
RtlFreeUnicodeString (&AdjustedName);
if (!RtlDosPathNameToNtPathName_U (FullDosName,
&FullNtFileName,
NULL,
NULL))
return STATUS_DLL_NOT_FOUND;
DPRINT("FullNtFileName %wZ\n", &FullNtFileName);
InitializeObjectAttributes(
& FileObjectAttributes,
& FullNtFileName,
0,
NULL,
NULL
);
DPRINT("Opening dll \"%wZ\"\n", &FullNtFileName);
Status = ZwOpenFile(
& FileHandle,
FILE_ALL_ACCESS,
& FileObjectAttributes,
NULL,
0,
0
);
if (!NT_SUCCESS(Status))
{
DbgPrint("Dll open of %wZ failed: Status = 0x%08x\n",
&FullNtFileName, Status);
RtlFreeUnicodeString (&FullNtFileName);
return Status;
}
RtlFreeUnicodeString (&FullNtFileName);
Status = ZwReadFile(
FileHandle,
0,
0,
0,
0,
BlockBuffer,
sizeof BlockBuffer,
0,
0
);
if (!NT_SUCCESS(Status))
{
DPRINT("Dll header read failed: Status = 0x%08x\n", Status);
ZwClose(FileHandle);
return Status;
}
/*
* Overlay DOS and NT headers structures to the
* buffer with DLL's header raw data.
*/
DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
NTHeaders = (PIMAGE_NT_HEADERS) (BlockBuffer + DosHeader->e_lfanew);
/*
* Check it is a PE image file.
*/
if ((DosHeader->e_magic != IMAGE_DOS_MAGIC)
|| (DosHeader->e_lfanew == 0L)
|| (*(PULONG)(NTHeaders) != IMAGE_PE_MAGIC))
{
DPRINT("NTDLL format invalid\n");
ZwClose(FileHandle);
return STATUS_UNSUCCESSFUL;
}
ImageBase = (PVOID) NTHeaders->OptionalHeader.ImageBase;
ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
DPRINT("ImageBase 0x%08x\n", ImageBase);
DPRINT("SearchPath %S\n", SearchPath);
if (RtlDosSearchPath_U (SearchPath,
AdjustedName.Buffer,
NULL,
MAX_PATH,
FullDosName,
NULL) == 0)
return STATUS_DLL_NOT_FOUND;
DPRINT("FullDosName %S\n", FullDosName);
RtlFreeUnicodeString (&AdjustedName);
if (!RtlDosPathNameToNtPathName_U (FullDosName,
&FullNtFileName,
NULL,
NULL))
return STATUS_DLL_NOT_FOUND;
DPRINT("FullNtFileName %wZ\n", &FullNtFileName);
InitializeObjectAttributes(&FileObjectAttributes,
&FullNtFileName,
0,
NULL,
NULL);
DPRINT("Opening dll \"%wZ\"\n", &FullNtFileName);
Status = ZwOpenFile(&FileHandle,
FILE_ALL_ACCESS,
&FileObjectAttributes,
NULL,
0,
0);
if (!NT_SUCCESS(Status))
{
DbgPrint("Dll open of %wZ failed: Status = 0x%08x\n",
&FullNtFileName, Status);
RtlFreeUnicodeString (&FullNtFileName);
return Status;
}
RtlFreeUnicodeString (&FullNtFileName);
Status = ZwReadFile(FileHandle,
0,
0,
0,
0,
BlockBuffer,
sizeof(BlockBuffer),
0,
0);
if (!NT_SUCCESS(Status))
{
DPRINT("Dll header read failed: Status = 0x%08x\n", Status);
ZwClose(FileHandle);
return Status;
}
/*
* Overlay DOS and NT headers structures to the
* buffer with DLL's header raw data.
*/
DosHeader = (PIMAGE_DOS_HEADER) BlockBuffer;
NTHeaders = (PIMAGE_NT_HEADERS) (BlockBuffer + DosHeader->e_lfanew);
/*
* Check it is a PE image file.
*/
if ((DosHeader->e_magic != IMAGE_DOS_MAGIC)
|| (DosHeader->e_lfanew == 0L)
|| (*(PULONG)(NTHeaders) != IMAGE_PE_MAGIC))
{
DPRINT("NTDLL format invalid\n");
ZwClose(FileHandle);
return STATUS_UNSUCCESSFUL;
}
ImageBase = (PVOID) NTHeaders->OptionalHeader.ImageBase;
ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
DPRINT("ImageBase 0x%08x\n", ImageBase);
/*
* Create a section for dll.
*/
Status = ZwCreateSection(
& SectionHandle,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_READWRITE,
MEM_COMMIT,
FileHandle
);
if (!NT_SUCCESS(Status))
{
DPRINT("NTDLL create section failed: Status = 0x%08x\n", Status);
ZwClose(FileHandle);
return Status;
}
/*
* Map the dll into the process.
*/
InitialViewSize =
DosHeader->e_lfanew
+ sizeof (IMAGE_NT_HEADERS)
+ sizeof (IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections;
Status = ZwMapViewOfSection(
SectionHandle,
NtCurrentProcess(),
(PVOID*)&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE
);
if (!NT_SUCCESS(Status))
{
DbgPrint("NTDLL.LDR: map view of section failed (Status %x)\n",
Status);
ZwClose(FileHandle);
/*
* Create a section for dll.
*/
Status = ZwCreateSection(&SectionHandle,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_READWRITE,
SEC_COMMIT | SEC_IMAGE,
FileHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("NTDLL create section failed: Status = 0x%08x\n", Status);
ZwClose(FileHandle);
return Status;
}
/*
* Map the dll into the process.
*/
InitialViewSize = 0;
ImageBase = 0;
Status = ZwMapViewOfSection(SectionHandle,
NtCurrentProcess(),
&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("NTDLL.LDR: map view of section failed (Status %x)\n",
Status);
ZwClose(FileHandle);
return(Status);
}
ZwClose(FileHandle);
}
ZwClose(FileHandle);
/* relocate dll and fixup import table */
if ((NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL) ==
IMAGE_FILE_DLL)
/* relocate dll and fixup import table */
if ((NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL) ==
IMAGE_FILE_DLL)
{
Entrypoint =
(PDLLMAIN_FUNC) LdrPEStartup(ImageBase, SectionHandle);
}
/* build module entry */
Module = RtlAllocateHeap(RtlGetProcessHeap(),
0,
sizeof (LDR_MODULE));
Module->BaseAddress = (PVOID)ImageBase;
Module->EntryPoint = NTHeaders->OptionalHeader.AddressOfEntryPoint;
if (Module->EntryPoint != 0)
Module->EntryPoint += (ULONG)Module->BaseAddress;
Module->SizeOfImage = ImageSize;
if (NtCurrentPeb()->Ldr->Initialized == TRUE)
{
/* loading while app is running */
Module->LoadCount = 1;
}
else
{
/*
* loading while app is initializing
* dll must not be unloaded
*/
Module->LoadCount = -1;
}
Module->TlsIndex = 0;
Module->CheckSum = NTHeaders->OptionalHeader.CheckSum;
Module->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
RtlCreateUnicodeString (&Module->FullDllName,
FullDosName);
RtlCreateUnicodeString (&Module->BaseDllName,
wcsrchr(FullDosName, L'\\') + 1);
DPRINT ("BaseDllName %wZ\n", &Module->BaseDllName);
/* FIXME: aquire loader lock */
InsertTailList(&NtCurrentPeb()->Ldr->InLoadOrderModuleList,
&Module->InLoadOrderModuleList);
InsertTailList(&NtCurrentPeb()->Ldr->InInitializationOrderModuleList,
&Module->InInitializationOrderModuleList);
/* FIXME: release loader lock */
/* initialize dll */
if ((NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL) ==
IMAGE_FILE_DLL)
{
if (Module->EntryPoint != 0)
{
Entrypoint =
(PDLLMAIN_FUNC) LdrPEStartup(
ImageBase,
SectionHandle
);
Entrypoint = (PDLLMAIN_FUNC)Module->EntryPoint;
DPRINT("Calling entry point at 0x%08x\n", Entrypoint);
if (FALSE == Entrypoint(Module->BaseAddress,
DLL_PROCESS_ATTACH,
NULL))
{
DPRINT("NTDLL.LDR: DLL \"%wZ\" failed to initialize\n",
&Module->BaseDllName);
/* FIXME: should clean up and fail */
}
else
{
DPRINT("NTDLL.LDR: DLL \"%wZ\" initialized successfully\n",
&Module->BaseDllName);
}
}
/* build module entry */
Module = RtlAllocateHeap(
RtlGetProcessHeap(),
0,
sizeof (LDR_MODULE)
);
Module->BaseAddress = (PVOID)ImageBase;
Module->EntryPoint = NTHeaders->OptionalHeader.AddressOfEntryPoint;
if (Module->EntryPoint != 0)
Module->EntryPoint += (ULONG)Module->BaseAddress;
Module->SizeOfImage = ImageSize;
if (NtCurrentPeb()->Ldr->Initialized == TRUE)
else
{
/* loading while app is running */
Module->LoadCount = 1;
DPRINT("NTDLL.LDR: Entrypoint is NULL for \"%wZ\"\n",
&Module->BaseDllName);
}
else
{
/*
* loading while app is initializing
* dll must not be unloaded
*/
Module->LoadCount = -1;
}
Module->TlsIndex = 0;
Module->CheckSum = NTHeaders->OptionalHeader.CheckSum;
Module->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
RtlCreateUnicodeString (&Module->FullDllName,
FullDosName);
RtlCreateUnicodeString (&Module->BaseDllName,
wcsrchr(FullDosName, L'\\') + 1);
DPRINT ("BaseDllName %wZ\n", &Module->BaseDllName);
/* FIXME: aquire loader lock */
InsertTailList(&NtCurrentPeb()->Ldr->InLoadOrderModuleList,
&Module->InLoadOrderModuleList);
InsertTailList(&NtCurrentPeb()->Ldr->InInitializationOrderModuleList,
&Module->InInitializationOrderModuleList);
/* FIXME: release loader lock */
/* initialize dll */
if ((NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL) ==
IMAGE_FILE_DLL)
{
if (Module->EntryPoint != 0)
{
Entrypoint = (PDLLMAIN_FUNC)Module->EntryPoint;
DPRINT("Calling entry point at 0x%08x\n", Entrypoint);
if (FALSE == Entrypoint(
Module->BaseAddress,
DLL_PROCESS_ATTACH,
NULL
))
{
DPRINT("NTDLL.LDR: DLL \"%wZ\" failed to initialize\n",
&Module->BaseDllName);
/* FIXME: should clean up and fail */
}
else
{
DPRINT("NTDLL.LDR: DLL \"%wZ\" initialized successfully\n",
&Module->BaseDllName);
}
}
else
{
DPRINT("NTDLL.LDR: Entrypoint is NULL for \"%wZ\"\n",
&Module->BaseDllName);
}
}
*BaseAddress = Module->BaseAddress;
return STATUS_SUCCESS;
}
*BaseAddress = Module->BaseAddress;
return STATUS_SUCCESS;
}
@ -493,84 +474,6 @@ static NTSTATUS LdrFindDll(PLDR_MODULE *Dll, PUNICODE_STRING Name)
return STATUS_UNSUCCESSFUL;
}
/**********************************************************************
* NAME
* LdrMapSections
*
* DESCRIPTION
*
* ARGUMENTS
*
* RETURN VALUE
*
* REVISIONS
*
* NOTE
*
*/
NTSTATUS LdrMapSections(HANDLE ProcessHandle,
PVOID ImageBase,
HANDLE SectionHandle,
PIMAGE_NT_HEADERS NTHeaders)
{
ULONG i;
NTSTATUS Status;
for (i = 0; (i < NTHeaders->FileHeader.NumberOfSections); i++)
{
PIMAGE_SECTION_HEADER Sections;
LARGE_INTEGER Offset;
ULONG Base;
ULONG Size;
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(ImageBase);
Base = (ULONG) (Sections[i].VirtualAddress + ImageBase);
Offset.u.LowPart = Sections[i].PointerToRawData;
Offset.u.HighPart = 0;
Size = max(Sections[i].Misc.VirtualSize, Sections[i].SizeOfRawData);
DPRINT("Mapping section %d offset %x base %x size %x\n",
i, Offset.u.LowPart, Base, Sections[i].Misc.VirtualSize);
DPRINT("Size %x\n", Sections[i].SizeOfRawData);
if( Offset.u.LowPart )
{ // only map section if it is initialized
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&Base,
0,
Size,
&Offset,
(PULONG)&Size,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to map section");
return(Status);
}
}
else {
// allocate pure memory for uninitialized section
Status = NtAllocateVirtualMemory( NtCurrentProcess(),
(PVOID *)&Base,
0,
&Size,
MEM_COMMIT,
PAGE_READWRITE );
if( !NT_SUCCESS( Status ) )
{
DPRINT1( "Failed to allocate memory for uninitialized section\n" );
return Status;
}
}
}
return STATUS_SUCCESS;
}
/**********************************************************************
* NAME LOCAL
* LdrFixupForward
@ -1097,17 +1000,6 @@ PEPFUNC LdrPEStartup (PVOID ImageBase,
DosHeader = (PIMAGE_DOS_HEADER) ImageBase;
NTHeaders = (PIMAGE_NT_HEADERS) (ImageBase + DosHeader->e_lfanew);
/*
* Initialize image sections.
*/
if (SectionHandle != NULL)
{
LdrMapSections(NtCurrentProcess(),
ImageBase,
SectionHandle,
NTHeaders);
}
/*
* If the base address is different from the
* one the DLL is actually loaded, perform any

View file

@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: view.c,v 1.13 2001/01/01 04:42:11 dwelch Exp $
/* $Id: view.c,v 1.14 2001/02/10 22:51:08 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -186,6 +186,18 @@ CcRequestCacheSegment(PBCB Bcb,
return(STATUS_SUCCESS);
}
static
VOID CcFreeCachePage(PVOID Context, PVOID Address)
{
ULONG PhysAddr;
PhysAddr = MmGetPhysicalAddressForProcess(NULL, Address);
if (PhysAddr != 0)
{
MmDereferencePage((PVOID)PhysAddr);
}
}
NTSTATUS STDCALL
CcFreeCacheSegment(PBCB Bcb,
PCACHE_SEGMENT CacheSeg)
@ -196,7 +208,8 @@ CcFreeCacheSegment(PBCB Bcb,
MmFreeMemoryArea(NULL,
CacheSeg->BaseAddress,
Bcb->CacheSegmentSize,
TRUE);
CcFreeCachePage,
NULL);
ExFreePool(CacheSeg);
return(STATUS_SUCCESS);
}

View file

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.53 2001/01/28 21:37:37 ekohl Exp $
/* $Id: registry.c,v 1.54 2001/02/10 22:51:08 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -14,6 +14,7 @@
#include <ddk/ntddk.h>
#include <internal/ob.h>
#include <limits.h>
#include <string.h>
#define NDEBUG
#include <internal/debug.h>

View file

@ -7,11 +7,12 @@
struct _EPROCESS;
#if 0
/*
* Page access attributes (or these together)
*/
#define PA_READ (1<<0)
#define PA_WRITE ((1<<0)+(1<<1))
#define PA_WRITE ((1<<0)+(1<<1))
#define PA_EXECUTE PA_READ
#define PA_PCD (1<<4)
#define PA_PWT (1<<3)
@ -21,6 +22,7 @@ struct _EPROCESS;
*/
#define PA_USER (1<<2)
#define PA_SYSTEM (0)
#endif
#define PAGESIZE (4096)

View file

@ -1,4 +1,4 @@
/* $Id: kd.h,v 1.2 2000/12/28 03:38:07 dwelch Exp $
/* $Id: kd.h,v 1.3 2001/02/10 22:51:08 dwelch Exp $
*
* kernel debugger prototypes
*/
@ -9,4 +9,11 @@
ULONG
KdpPrintString (PANSI_STRING String);
VOID
DebugLogWrite(PCH String);
VOID
DebugLogInit(VOID);
VOID
DebugLogInit2(VOID);
#endif /* __INCLUDE_INTERNAL_KERNEL_DEBUGGER_H */

View file

@ -71,14 +71,25 @@ typedef struct
PSECTION_PAGE_TABLE PageTables[NR_SECTION_PAGE_TABLES];
} SECTION_PAGE_DIRECTORY, *PSECTION_PAGE_DIRECTORY;
typedef struct
#define MM_PAGEFILE_SECTION (0x1)
#define MM_IMAGE_SECTION (0x2)
#define MM_SECTION_SEGMENT_BSS (0x1)
typedef struct _MM_SECTION_SEGMENT
{
ULONG FileOffset;
ULONG Protection;
ULONG Attributes;
SECTION_PAGE_DIRECTORY PageDirectory;
ULONG Length;
ULONG RawLength;
KMUTEX Lock;
} MM_SECTION_SEGMENT;
ULONG ReferenceCount;
SECTION_PAGE_DIRECTORY PageDirectory;
ULONG Flags;
PVOID VirtualAddress;
ULONG Characteristics;
} MM_SECTION_SEGMENT, *PMM_SECTION_SEGMENT;
typedef struct
{
@ -91,8 +102,19 @@ typedef struct
LIST_ENTRY ViewListHead;
KSPIN_LOCK ViewListLock;
KMUTEX Lock;
SECTION_PAGE_DIRECTORY PageDirectory;
ULONG Flags;
ULONG NrSegments;
PMM_SECTION_SEGMENT Segments;
PVOID ImageBase;
PVOID EntryPoint;
ULONG StackReserve;
ULONG StackCommit;
ULONG Subsystem;
ULONG MinorSubsystemVersion;
ULONG MajorSubsystemVersion;
ULONG ImageCharacteristics;
USHORT Machine;
BOOLEAN Executable;
} SECTION_OBJECT, *PSECTION_OBJECT;
typedef struct
@ -111,6 +133,7 @@ typedef struct
SECTION_OBJECT* Section;
ULONG ViewOffset;
LIST_ENTRY ViewListEntry;
PMM_SECTION_SEGMENT Segment;
} SectionData;
struct
{
@ -135,7 +158,6 @@ typedef struct _MADDRESS_SPACE
ULONG PageTableRefCountTableSize;
} MADDRESS_SPACE, *PMADDRESS_SPACE;
/* FUNCTIONS */
VOID MmLockAddressSpace(PMADDRESS_SPACE AddressSpace);
@ -161,7 +183,8 @@ VOID ExInitNonPagedPool(ULONG BaseAddress);
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress,
ULONG Length,
BOOLEAN FreePages);
VOID (*FreePage)(PVOID Context, PVOID Address),
PVOID FreePageContext);
VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead);
NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea);
NTSTATUS MmUnlockMemoryArea(MEMORY_AREA* MemoryArea);
@ -199,8 +222,8 @@ PVOID MmGetMdlPageAddress(PMDL Mdl, PVOID Offset);
VOID MiShutdownMemoryManager(VOID);
ULONG MmGetPhysicalAddressForProcess(struct _EPROCESS* Process,
PVOID Address);
NTSTATUS STDCALL MmUnmapViewOfSection(struct _EPROCESS* Process,
PMEMORY_AREA MemoryArea);
NTSTATUS STDCALL
MmUnmapViewOfSection(struct _EPROCESS* Process, PVOID BaseAddress);
NTSTATUS MmSafeCopyFromUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
VOID MmInitPagingFile(VOID);
@ -263,12 +286,11 @@ ULONG MmTrimWorkingSet(struct _EPROCESS* Process,
ULONG ReduceHint);
VOID MmRemovePageFromWorkingSet(struct _EPROCESS* Process,
PVOID Address);
VOID
MmAddPageToWorkingSet(struct _EPROCESS* Process, PVOID Address);
VOID MmAddPageToWorkingSet(struct _EPROCESS* Process,
PVOID Address);
VOID MmInitPagingFile(VOID);
BOOLEAN
MmReserveSwapPages(ULONG Nr);
BOOLEAN MmReserveSwapPages(ULONG Nr);
VOID MmDereserveSwapPages(ULONG Nr);
SWAPENTRY MmAllocSwapPage(VOID);
VOID MmFreeSwapPage(SWAPENTRY Entry);
@ -331,4 +353,17 @@ MmGetContinuousPages(ULONG NumberOfBytes,
#define MM_PHYSICAL_PAGE_MPW_PENDING (0x8)
NTSTATUS
MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
MEMORY_AREA* MemoryArea,
PVOID Address);
ULONG
MmGetPageProtect(struct _EPROCESS* Process, PVOID Address);
PVOID
ExAllocatePageWithPhysPage(ULONG PhysPage);
ULONG
MmGetReferenceCountPage(PVOID PhysicalAddress);
BOOLEAN
MmIsUsablePage(PVOID PhysicalAddress);
#endif

View file

@ -206,6 +206,7 @@ VOID IoSecondStageCompletion(PIRP Irp, CCHAR PriorityBoost)
break;
default:
break;
}
if (Irp->Overlay.AsynchronousParameters.UserApcRoutine != NULL)

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.35 2001/01/08 02:14:05 dwelch Exp $
/* $Id: create.c,v 1.36 2001/02/10 22:51:09 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -108,9 +108,8 @@ IopCreateFile (PVOID ObjectBody,
}
else
{
if ( (DeviceObject->DeviceType != FILE_DEVICE_FILE_SYSTEM)
&& (DeviceObject->DeviceType != FILE_DEVICE_DISK)
)
if ((DeviceObject->DeviceType != FILE_DEVICE_FILE_SYSTEM)
&& (DeviceObject->DeviceType != FILE_DEVICE_DISK))
{
DPRINT ("Device was wrong type\n");
return (STATUS_UNSUCCESSFUL);
@ -322,8 +321,9 @@ IoCreateFile (
//FileObject->Flags |= FileObject->Flags | FO_SYNCHRONOUS_IO;
FileObject->Flags |= FO_SYNCHRONOUS_IO;
}
KeInitializeEvent (&FileObject->Lock, NotificationEvent, TRUE);
KeInitializeEvent (&Event, NotificationEvent, FALSE);
DPRINT("FileObject %x\n", FileObject);
DPRINT("FileObject->DeviceObject %x\n", FileObject->DeviceObject);
/*

View file

@ -1,4 +1,4 @@
/* $Id: xhaldisp.c,v 1.2 2000/08/21 00:14:04 ekohl Exp $
/* $Id: xhaldisp.c,v 1.3 2001/02/10 22:51:09 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -45,4 +45,5 @@ HAL_PRIVATE_DISPATCH EXPORTED HalPrivateDispatchTable =
// any more??
};
/* EOF */
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: kdebug.c,v 1.17 2001/01/06 21:40:13 rex Exp $
/* $Id: kdebug.c,v 1.18 2001/02/10 22:51:09 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -27,6 +27,7 @@
#define ScreenDebug (0x1)
#define SerialDebug (0x2)
#define BochsDebug (0x4)
#define FileLogDebug (0x8)
/* VARIABLES ***************************************************************/
@ -43,7 +44,6 @@ static BOOLEAN KdpBreakPending = FALSE;
static BOOLEAN KdpBreakRecieved = FALSE;
static ULONG KdpDebugType = ScreenDebug | BochsDebug;
/* PRIVATE FUNCTIONS ********************************************************/
static void
@ -116,7 +116,12 @@ KdInitSystem (
}
p1 = p2;
}
#ifdef DBGPRINT_FILE_LOG
KdpDebugType |= FileLogDebug;
DebugLogInit();
#endif /* DBGPRINT_FILE_LOG */
/* check for 'BAUDRATE' */
p1 = (PCHAR)LoaderBlock->CommandLine;
while (p1 && (p2 = strchr (p1, '/')))
@ -215,6 +220,10 @@ KdInitSystem (
PrintString ("\n Serial debugging enabled: COM%ld %ld Baud\n\n",
PortInfo.ComPort, PortInfo.BaudRate);
}
if (KdpDebugType & FileLogDebug)
{
PrintString("\n File log debugging enabled\n\n");
}
}
else
PrintString ("\n Debugging disabled\n\n");
@ -262,7 +271,12 @@ ULONG KdpPrintString (PANSI_STRING String)
pch++;
}
}
#ifdef DEBUGPRINT_LOG_WRITE
if (KdpDebugType & FileLogDebug)
{
DebugLogWrite(String->Buffer);
}
#endif /* DEBUGPRINT_LOG_WRITE */
return (ULONG)String->Length;
}

View file

@ -130,7 +130,8 @@ exception_handler(struct trap_frame* tf)
if (PsGetCurrentThread() != NULL &&
tf->esp < (ULONG)PsGetCurrentThread()->Tcb.StackLimit)
{
DbgPrint("Stack underflow\n");
DbgPrint("Stack underflow (tf->esp %x Limit %x)\n",
tf->esp, (ULONG)PsGetCurrentThread()->Tcb.StackLimit);
tf->type = 12;
}

View file

@ -30,6 +30,7 @@
#include <internal/trap.h>
#include <internal/mm.h>
#include <internal/i386/segment.h>
#include <string.h>
//#define NDEBUG
#include <internal/debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.77 2001/02/06 00:11:18 dwelch Exp $
/* $Id: main.c,v 1.78 2001/02/10 22:51:09 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -26,6 +26,7 @@
#include <internal/i386/segment.h>
#include <napi/shared_data.h>
#include <internal/v86m.h>
#include <internal/kd.h>
#define NDEBUG
#include <internal/debug.h>
@ -574,6 +575,12 @@ _main (ULONG MultiBootMagic, PLOADER_PARAMETER_BLOCK _LoaderBlock)
}
}
#ifdef DEBUGPRINT_FILE_LOG
/* On the assumption that we can now access disks start up the debug
logger thread */
DebugLogInit2();
#endif /* DEBUGPRINT_FILE_LOG */
/* Create the SystemRoot symbolic link */
DbgPrint("CommandLine: %s\n", (PUCHAR)KeLoaderBlock.CommandLine);
CreateSystemRootLink ((PUCHAR)KeLoaderBlock.CommandLine);

View file

@ -91,7 +91,7 @@ NTSTATUS LdrLoadInitialProcess (VOID)
NULL,
NULL,
PAGE_READWRITE,
MEM_COMMIT,
SEC_COMMIT | SEC_IMAGE,
FileHandle);
if (!NT_SUCCESS(Status))
{

View file

@ -1,4 +1,4 @@
/* $Id: rtl.c,v 1.11 2000/10/22 16:36:51 ekohl Exp $
/* $Id: rtl.c,v 1.12 2001/02/10 22:51:09 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -23,19 +23,14 @@
/* FUNCTIONS ****************************************************************/
PIMAGE_NT_HEADERS STDCALL RtlImageNtHeader (IN PVOID BaseAddress)
PIMAGE_NT_HEADERS STDCALL
RtlImageNtHeader (IN PVOID BaseAddress)
{
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders;
DPRINT("BaseAddress %x\n", BaseAddress);
DosHeader = (PIMAGE_DOS_HEADER)BaseAddress;
DPRINT("DosHeader %x\n", DosHeader);
NTHeaders = (PIMAGE_NT_HEADERS)(BaseAddress + DosHeader->e_lfanew);
DPRINT("NTHeaders %x\n", NTHeaders);
DPRINT("DosHeader->e_magic %x DosHeader->e_lfanew %x\n",
DosHeader->e_magic, DosHeader->e_lfanew);
DPRINT("*NTHeaders %x\n", *(PULONG)NTHeaders);
if ((DosHeader->e_magic != IMAGE_DOS_MAGIC)
|| (DosHeader->e_lfanew == 0L)
|| (*(PULONG) NTHeaders != IMAGE_PE_MAGIC))
@ -47,12 +42,10 @@ PIMAGE_NT_HEADERS STDCALL RtlImageNtHeader (IN PVOID BaseAddress)
PVOID STDCALL
RtlImageDirectoryEntryToData (
IN PVOID BaseAddress,
IN BOOLEAN ImageLoaded,
IN ULONG Directory,
OUT PULONG Size
)
RtlImageDirectoryEntryToData (IN PVOID BaseAddress,
IN BOOLEAN ImageLoaded,
IN ULONG Directory,
OUT PULONG Size)
{
PIMAGE_NT_HEADERS NtHeader;
PIMAGE_SECTION_HEADER SectionHeader;
@ -149,6 +142,7 @@ RtlImageRvaToVa (
Section->VirtualAddress);
}
#define RVA(m, b) ((ULONG)b + m)
NTSTATUS STDCALL
LdrGetProcedureAddress (IN PVOID BaseAddress,
@ -164,24 +158,57 @@ LdrGetProcedureAddress (IN PVOID BaseAddress,
/* get the pointer to the export directory */
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
RtlImageDirectoryEntryToData (BaseAddress, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &i);
RtlImageDirectoryEntryToData (BaseAddress, TRUE,
IMAGE_DIRECTORY_ENTRY_EXPORT, &i);
if (!ExportDir || !i || !ProcedureAddress)
{
return STATUS_INVALID_PARAMETER;
return(STATUS_INVALID_PARAMETER);
}
AddressPtr = (PULONG)((ULONG)BaseAddress + (ULONG)ExportDir->AddressOfFunctions);
AddressPtr = (PULONG)RVA(BaseAddress, ExportDir->AddressOfFunctions);
if (Name && Name->Length)
{
ULONG minn, maxn;
/* by name */
OrdinalPtr = (PUSHORT)((ULONG)BaseAddress + (ULONG)ExportDir->AddressOfNameOrdinals);
NamePtr = (PULONG)((ULONG)BaseAddress + (ULONG)ExportDir->AddressOfNames);
OrdinalPtr =
(PUSHORT)RVA(BaseAddress, ExportDir->AddressOfNameOrdinals);
NamePtr = (PULONG)RVA(BaseAddress, ExportDir->AddressOfNames);
minn = 0; maxn = ExportDir->NumberOfNames;
while (minn <= maxn)
{
ULONG mid;
LONG res;
mid = (minn + maxn) / 2;
res = _strnicmp(Name->Buffer, (PCH)RVA(BaseAddress, NamePtr[mid]),
Name->Length);
if (res == 0)
{
*ProcedureAddress =
(PVOID)RVA(BaseAddress, AddressPtr[OrdinalPtr[mid]]);
return(STATUS_SUCCESS);
}
else if (res > 0)
{
maxn = mid - 1;
}
else
{
minn = mid + 1;
}
}
for (i = 0; i < ExportDir->NumberOfNames; i++, NamePtr++, OrdinalPtr++)
{
if (!_strnicmp(Name->Buffer, (char*)(BaseAddress + *NamePtr), Name->Length))
if (!_strnicmp(Name->Buffer,
(char*)(BaseAddress + *NamePtr), Name->Length))
{
*ProcedureAddress = (PVOID)((ULONG)BaseAddress + (ULONG)AddressPtr[*OrdinalPtr]);
*ProcedureAddress =
(PVOID)((ULONG)BaseAddress +
(ULONG)AddressPtr[*OrdinalPtr]);
return STATUS_SUCCESS;
}
}
@ -193,10 +220,13 @@ LdrGetProcedureAddress (IN PVOID BaseAddress,
Ordinal &= 0x0000FFFF;
if (Ordinal - ExportDir->Base < ExportDir->NumberOfFunctions)
{
*ProcedureAddress = (PVOID)((ULONG)BaseAddress + (ULONG)AddressPtr[Ordinal - ExportDir->Base]);
*ProcedureAddress =
(PVOID)((ULONG)BaseAddress +
(ULONG)AddressPtr[Ordinal - ExportDir->Base]);
return STATUS_SUCCESS;
}
DbgPrint("LdrGetProcedureAddress: Can't resolve symbol @%d\n", Ordinal);
DbgPrint("LdrGetProcedureAddress: Can't resolve symbol @%d\n",
Ordinal);
}
return STATUS_PROCEDURE_NOT_FOUND;

View file

@ -76,10 +76,9 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
UNICODE_STRING DllPathname;
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders;
ULONG InitialViewSize;
ULONG i;
PEPROCESS Process;
ANSI_STRING ProcedureName;
ULONG ViewSize;
/*
* Locate and open NTDLL to determine ImageBase
@ -146,7 +145,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
NULL,
NULL,
PAGE_READWRITE,
MEM_COMMIT,
SEC_IMAGE | SEC_COMMIT,
FileHandle);
if (!NT_SUCCESS(Status))
{
@ -159,17 +158,15 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
/*
* Map the NTDLL into the process
*/
InitialViewSize = DosHeader->e_lfanew +
sizeof (IMAGE_NT_HEADERS) +
(sizeof (IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections);
DPRINT("Mapping view of section\n");
ViewSize = 0;
ImageBase = 0;
Status = ZwMapViewOfSection(NTDllSectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
InitialViewSize,
ViewSize,
NULL,
&InitialViewSize,
&ViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
@ -180,40 +177,6 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
return(Status);
}
for (i = 0; i < NTHeaders->FileHeader.NumberOfSections; i++)
{
PIMAGE_SECTION_HEADER Sections;
LARGE_INTEGER Offset;
ULONG Base;
DPRINT("Mapping view of section %d\n", i);
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(BlockBuffer);
DPRINT("Sections %x\n", Sections);
Base = Sections[i].VirtualAddress + ImageBase;
DPRINT("Base %x\n", Base);
Offset.u.LowPart = Sections[i].PointerToRawData;
Offset.u.HighPart = 0;
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(NTDllSectionHandle,
ProcessHandle,
(PVOID*)&Base,
0,
Sections[i].Misc.VirtualSize,
&Offset,
(PULONG)&Sections[i].Misc.VirtualSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("NTDLL map view of secion failed (Status %x)\n", Status);
ZwClose(NTDllSectionHandle);
return(Status);
}
}
DPRINT("Finished mapping\n");
DPRINT("Referencing process\n");
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_ALL_ACCESS,
@ -233,74 +196,86 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
/*
* retrieve ntdll's startup address
*/
RtlInitAnsiString (&ProcedureName,
"LdrInitializeThunk");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllEntryPoint);
if (!NT_SUCCESS(Status))
if (SystemDllEntryPoint == NULL)
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
RtlInitAnsiString (&ProcedureName,
"LdrInitializeThunk");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllEntryPoint);
if (!NT_SUCCESS(Status))
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
}
*LdrStartupAddr = SystemDllEntryPoint;
}
*LdrStartupAddr = SystemDllEntryPoint;
/*
* Retrieve the offset of the APC dispatcher from NTDLL
*/
RtlInitAnsiString (&ProcedureName,
"KiUserApcDispatcher");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllApcDispatcher);
if (!NT_SUCCESS(Status))
if (SystemDllApcDispatcher == NULL)
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
RtlInitAnsiString (&ProcedureName,
"KiUserApcDispatcher");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllApcDispatcher);
if (!NT_SUCCESS(Status))
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
}
}
/*
* Retrieve the offset of the exception dispatcher from NTDLL
*/
RtlInitAnsiString (&ProcedureName,
"KiUserExceptionDispatcher");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllExceptionDispatcher);
if (!NT_SUCCESS(Status))
if (SystemDllExceptionDispatcher == NULL)
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
RtlInitAnsiString (&ProcedureName,
"KiUserExceptionDispatcher");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllExceptionDispatcher);
if (!NT_SUCCESS(Status))
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
}
}
/*
* Retrieve the offset of the callback dispatcher from NTDLL
*/
RtlInitAnsiString (&ProcedureName,
"KiUserCallbackDispatcher");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllCallbackDispatcher);
if (!NT_SUCCESS(Status))
if (SystemDllCallbackDispatcher == NULL)
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
RtlInitAnsiString (&ProcedureName,
"KiUserCallbackDispatcher");
Status = LdrGetProcedureAddress ((PVOID)ImageBase,
&ProcedureName,
0,
&SystemDllCallbackDispatcher);
if (!NT_SUCCESS(Status))
{
DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
KeDetachProcess();
ObDereferenceObject(Process);
ZwClose(NTDllSectionHandle);
return (Status);
}
}
KeDetachProcess();

View file

@ -40,188 +40,29 @@ NTSTATUS LdrpMapImage(HANDLE ProcessHandle,
* RETURNS: Status
*/
{
PVOID ImageBase;
NTSTATUS Status;
PIMAGE_NT_HEADERS NTHeaders;
ULONG InitialViewSize;
ULONG i;
PEPROCESS Process;
PVOID FinalBase;
ULONG NumberOfSections;
DPRINT("Referencing process\n");
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_ALL_ACCESS,
PsProcessType,
KernelMode,
(PVOID*)&Process,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("ObReferenceObjectByProcess() failed (Status %x)\n", Status);
return(Status);
}
/*
* map the dos header into the process
*/
DPRINT("Mapping view of section\n");
InitialViewSize = sizeof(IMAGE_DOS_HEADER);
ImageBase = NULL;
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of section failed (Status %x)", Status);
return(Status);
}
/*
* Map the pe headers into the process
*/
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
InitialViewSize = ((PIMAGE_DOS_HEADER)ImageBase)->e_lfanew +
sizeof(IMAGE_NT_HEADERS);
DPRINT("InitialViewSize %d\n", InitialViewSize);
KeDetachProcess();
DPRINT("Unmapping view of section\n");
Status = ZwUnmapViewOfSection(ProcessHandle,
ImageBase);
if (!NT_SUCCESS(Status))
{
DbgPrint("ZwUnmapViewOfSection failed (Status %x)\n", Status);
return(Status);
}
DPRINT("Mapping view of section\n");
ImageBase = NULL;
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of section failed (Status %x)", Status);
return(Status);
}
DPRINT("ImageBase %x\n", ImageBase);
/*
* TBD
*/
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
NTHeaders = RtlImageNtHeader(ImageBase);
DPRINT("NTHeaders %x\n", NTHeaders);
InitialViewSize = ((PIMAGE_DOS_HEADER)ImageBase)->e_lfanew +
sizeof(IMAGE_NT_HEADERS) +
(sizeof (IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections);
DPRINT("InitialViewSize %x\n", InitialViewSize);
FinalBase = (PVOID)NTHeaders->OptionalHeader.ImageBase;
DPRINT("FinalBase %x\n", FinalBase);
NumberOfSections = NTHeaders->FileHeader.NumberOfSections;
DPRINT("NrSections %d\n", NumberOfSections);
KeDetachProcess();
DPRINT("Unmapping view of section\n");
Status = ZwUnmapViewOfSection(ProcessHandle,
ImageBase);
if (!NT_SUCCESS(Status))
{
DbgPrint("ZwUnmapViewOfSection failed (Status %x)\n", Status);
return(Status);
}
ImageBase = FinalBase;
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of section failed (Status %x)", Status);
return(Status);
}
DPRINT("Mapping view of all sections\n");
for (i = 0; i < NumberOfSections; i++)
{
PIMAGE_SECTION_HEADER Sections;
LARGE_INTEGER Offset;
ULONG Base;
ULONG Size;
KeAttachProcess(Process);
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(ImageBase);
DPRINT("Sections %x\n", Sections);
Base = (ULONG)(Sections[i].VirtualAddress + ImageBase);
Offset.u.LowPart = Sections[i].PointerToRawData;
Offset.u.HighPart = 0;
Size = Sections[i].Misc.VirtualSize;
KeDetachProcess();
if( Offset.u.LowPart )
{ // map the section if it is initialized
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID *)&Base,
0,
Size,
&Offset,
(PULONG)&Size,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of secion failed (Status %x)\n", Status);
return(Status);
}
}
else {
// allocate the section if it is uninitialized
Status = NtAllocateVirtualMemory( ProcessHandle,
(PVOID *)&Base,
0,
&Size,
MEM_COMMIT,
PAGE_READWRITE );
if( !NT_SUCCESS( Status ) )
{
DPRINT1( "Failed to allocate memory for uninitialized section\n" );
return Status;
}
}
}
DPRINT("Returning\n");
ULONG ViewSize;
PVOID ImageBase;
NTSTATUS Status;
ViewSize = 0;
ImageBase = 0;
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
ViewSize,
NULL,
&ViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of section failed (Status %x)", Status);
return(Status);
}
*ReturnedImageBase = ImageBase;
return(STATUS_SUCCESS);

View file

@ -1,4 +1,4 @@
/* $Id: cont.c,v 1.6 2001/01/08 02:14:05 dwelch Exp $
/* $Id: cont.c,v 1.7 2001/02/10 22:51:10 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -18,6 +18,17 @@
/* FUNCTIONS *****************************************************************/
VOID static
MmFreeContinuousPage(PVOID Context, PVOID Address)
{
ULONG PhysAddr;
PhysAddr = MmGetPhysicalAddressForProcess(NULL, Address);
if (PhysAddr != 0)
{
MmDereferencePage((PVOID)PhysAddr);
}
}
/**********************************************************************
* NAME EXPORTED
@ -74,7 +85,8 @@ MmAllocateContiguousMemory (IN ULONG NumberOfBytes,
MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress,
0,
TRUE);
NULL,
NULL);
return(NULL);
}
for (i = 0; i < (PAGE_ROUND_UP(NumberOfBytes) / 4096); i++)
@ -116,7 +128,8 @@ MmFreeContiguousMemory(IN PVOID BaseAddress)
MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress,
0,
TRUE);
MmFreeContinuousPage,
NULL);
}

View file

@ -358,6 +358,56 @@ VOID MmReferencePage(PVOID PhysicalAddress)
KeReleaseSpinLock(&PageListLock, oldIrql);
}
ULONG
MmGetReferenceCountPage(PVOID PhysicalAddress)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
KIRQL oldIrql;
ULONG RCount;
DPRINT("MmGetReferenceCountPage(PhysicalAddress %x)\n", PhysicalAddress);
if (((ULONG)PhysicalAddress) == 0)
{
KeBugCheck(0);
}
KeAcquireSpinLock(&PageListLock, &oldIrql);
if (MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Getting reference count for free page\n");
KeBugCheck(0);
}
RCount = MmPageArray[Start].ReferenceCount;
KeReleaseSpinLock(&PageListLock, oldIrql);
return(RCount);
}
BOOLEAN
MmIsUsablePage(PVOID PhysicalAddress)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
DPRINT("MmGetReferenceCountPage(PhysicalAddress %x)\n", PhysicalAddress);
if (((ULONG)PhysicalAddress) == 0)
{
KeBugCheck(0);
}
if (MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_USED &&
MM_PTYPE(MmPageArray[Start].Flags) != MM_PHYSICAL_PAGE_BIOS)
{
return(FALSE);
}
return(TRUE);
}
VOID MmDereferencePage(PVOID PhysicalAddress)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
@ -377,27 +427,27 @@ VOID MmDereferencePage(PVOID PhysicalAddress)
DbgPrint("Dereferencing free page\n");
KeBugCheck(0);
}
MmStats.NrFreePages++;
MmStats.NrSystemPages--;
MmPageArray[Start].ReferenceCount--;
if (MmPageArray[Start].ReferenceCount == 0)
{
RemoveEntryList(&MmPageArray[Start].ListEntry);
if (MmPageArray[Start].LockCount > 0)
{
DbgPrint("Freeing locked page\n");
KeBugCheck(0);
}
if (MmPageArray[Start].Flags != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Freeing page with flags %x\n",
MmPageArray[Start].Flags);
KeBugCheck(0);
}
MmPageArray[Start].Flags = MM_PHYSICAL_PAGE_FREE;
InsertTailList(&FreePageListHead, &MmPageArray[Start].ListEntry);
MmStats.NrFreePages++;
MmStats.NrSystemPages--;
RemoveEntryList(&MmPageArray[Start].ListEntry);
if (MmPageArray[Start].LockCount > 0)
{
DbgPrint("Freeing locked page\n");
KeBugCheck(0);
}
if (MmPageArray[Start].Flags != MM_PHYSICAL_PAGE_USED)
{
DbgPrint("Freeing page with flags %x\n",
MmPageArray[Start].Flags);
KeBugCheck(0);
}
MmPageArray[Start].Flags = MM_PHYSICAL_PAGE_FREE;
InsertTailList(&FreePageListHead, &MmPageArray[Start].ListEntry);
}
KeReleaseSpinLock(&PageListLock, oldIrql);
}

View file

@ -1,4 +1,4 @@
/* $Id: page.c,v 1.18 2001/02/06 00:11:19 dwelch Exp $
/* $Id: page.c,v 1.19 2001/02/10 22:51:11 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -30,10 +30,14 @@
#define PA_BIT_ACCESSED (5)
#define PA_BIT_DIRTY (6)
#define PA_PRESENT (1 << PA_BIT_PRESENT)
#define PA_DIRTY (1 << PA_BIT_DIRTY)
#define PA_WT (1 << PA_BIT_WT)
#define PA_CD (1 << PA_BIT_CD)
#define PA_PRESENT (1 << PA_BIT_PRESENT)
#define PA_READWRITE (1 << PA_BIT_READWRITE)
#define PA_USER (1 << PA_BIT_USER)
#define PA_DIRTY (1 << PA_BIT_DIRTY)
#define PA_WT (1 << PA_BIT_WT)
#define PA_CD (1 << PA_BIT_CD)
#define PA_ACCESSED (1 << PA_BIT_ACCESSED)
#define PA_DIRTY (1 << PA_BIT_DIRTY)
#define PAGETABLE_MAP (0xf0000000)
#define PAGEDIRECTORY_MAP (0xf0000000 + (PAGETABLE_MAP / (1024)))
@ -60,22 +64,22 @@ ProtectToPTE(ULONG flProtect)
}
if (flProtect & PAGE_READWRITE || flProtect & PAGE_EXECUTE_READWRITE)
{
Attributes = PA_WRITE;
Attributes = PA_PRESENT | PA_READWRITE;
}
if (flProtect & PAGE_READONLY || flProtect & PAGE_EXECUTE ||
flProtect & PAGE_EXECUTE_READ)
{
Attributes = PA_READ;
Attributes = PA_PRESENT;
}
if (!(flProtect & PAGE_SYSTEM))
{
Attributes = Attributes | PA_USER;
}
if (!(flProtect & PAGE_NOCACHE))
if (flProtect & PAGE_NOCACHE)
{
Attributes = Attributes | PA_CD;
}
if (!(flProtect & PAGE_WRITETHROUGH))
if (flProtect & PAGE_WRITETHROUGH)
{
Attributes = Attributes | PA_WT;
}
@ -289,7 +293,8 @@ VOID MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage)
PULONG Pte;
PULONG Pde;
PEPROCESS CurrentProcess = PsGetCurrentProcess();
BOOLEAN WasValid;
if (Process != NULL && Process != CurrentProcess)
{
KeAttachProcess(Process);
@ -304,12 +309,13 @@ VOID MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage)
return;
}
Pte = ADDR_TO_PTE(Address);
if (FreePage && PAGE_MASK(*Pte) != 0)
WasValid = (PAGE_MASK(*Pte) != 0);
if (FreePage && WasValid)
{
MmDereferencePage((PVOID)PAGE_MASK(*Pte));
}
*Pte = 0;
if (Process != NULL &&
if (Process != NULL && WasValid &&
Process->AddressSpace.PageTableRefCountTable != NULL &&
ADDR_TO_PAGE_TABLE(Address) < 768)
{
@ -318,10 +324,12 @@ VOID MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage)
Ptrc = Process->AddressSpace.PageTableRefCountTable;
Ptrc[ADDR_TO_PAGE_TABLE(Address)]--;
#if 0
if (Ptrc[ADDR_TO_PAGE_TABLE(Address)] == 0)
{
MmFreePageTable(Process, Address);
}
#endif
}
if (Process != NULL && Process != CurrentProcess)
{
@ -431,6 +439,11 @@ NTSTATUS MmCreateVirtualMapping(PEPROCESS Process,
PULONG Pte;
NTSTATUS Status;
if (!MmIsUsablePage((PVOID)PhysicalAddress))
{
KeBugCheck(0);
}
Attributes = ProtectToPTE(flProtect);
if (Process != NULL && Process != CurrentProcess)
@ -467,6 +480,29 @@ NTSTATUS MmCreateVirtualMapping(PEPROCESS Process,
return(STATUS_SUCCESS);
}
ULONG
MmGetPageProtect(PEPROCESS Process, PVOID Address)
{
ULONG Entry;
ULONG Protect;
Entry = MmGetPageEntryForProcess1(Process, Address);
if (!(Entry & PA_PRESENT))
{
Protect = PAGE_NOACCESS;
}
else if (Entry & PA_READWRITE)
{
Protect = PAGE_READWRITE;
}
else
{
Protect = PAGE_EXECUTE_READ;
}
return(Protect);
}
VOID
MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
{

View file

@ -1,4 +1,4 @@
/* $Id: iospace.c,v 1.7 2001/01/08 02:14:05 dwelch Exp $
/* $Id: iospace.c,v 1.8 2001/02/10 22:51:10 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -121,7 +121,8 @@ VOID STDCALL MmUnmapIoSpace (IN PVOID BaseAddress,
(VOID)MmFreeMemoryArea(&PsGetCurrentProcess()->AddressSpace,
BaseAddress,
NumberOfBytes,
FALSE);
NULL,
NULL);
}

View file

@ -1,4 +1,4 @@
/* $Id: kmap.c,v 1.5 2001/01/08 02:14:06 dwelch Exp $
/* $Id: kmap.c,v 1.6 2001/02/10 22:51:10 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -51,20 +51,27 @@ ExUnmapPage(PVOID Addr)
PVOID
ExAllocatePage(VOID)
{
ULONG PhysPage;
PhysPage = (ULONG)MmAllocPage(0);
DPRINT("Allocated page %x\n",PhysPage);
if (PhysPage == 0)
{
return(NULL);
}
return(ExAllocatePageWithPhysPage(PhysPage));
}
PVOID
ExAllocatePageWithPhysPage(ULONG PhysPage)
{
KIRQL oldlvl;
ULONG addr;
ULONG i;
ULONG PhysPage;
NTSTATUS Status;
PhysPage = (ULONG)MmAllocPage(0);
DPRINT("Allocated page %x\n",PhysPage);
if (PhysPage == 0)
{
return(NULL);
}
KeAcquireSpinLock(&AllocMapLock, &oldlvl);
for (i=1; i<ALLOC_MAP_SIZE;i++)
{

View file

@ -269,14 +269,15 @@ NTSTATUS MmInitMemoryAreas(VOID)
return(STATUS_SUCCESS);
}
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress,
ULONG Length,
BOOLEAN FreePages)
NTSTATUS
MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress,
ULONG Length,
VOID (*FreePage)(PVOID Context, PVOID Address),
PVOID FreePageContext)
{
MEMORY_AREA* MemoryArea;
ULONG i;
LARGE_INTEGER PhysicalAddr;
DPRINT("MmFreeMemoryArea(AddressSpace %x, BaseAddress %x, Length %x,"
"FreePages %d)\n",AddressSpace,BaseAddress,Length,FreePages);
@ -288,16 +289,12 @@ NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
KeBugCheck(0);
return(STATUS_UNSUCCESSFUL);
}
if (FreePages)
if (FreePage != NULL)
{
for (i=0;i<=(MemoryArea->Length/PAGESIZE);i++)
{
PhysicalAddr = MmGetPhysicalAddress(MemoryArea->BaseAddress +
(i*PAGESIZE));
if (PhysicalAddr.u.LowPart != 0)
{
MmDereferencePage((PVOID)(ULONG)(PhysicalAddr.u.LowPart));
}
FreePage(FreePageContext,
MemoryArea->BaseAddress + (i * PAGESIZE));
}
}
for (i=0; i<=(MemoryArea->Length/PAGESIZE); i++)

View file

@ -1,4 +1,4 @@
/* $Id: mdl.c,v 1.27 2001/01/08 02:14:06 dwelch Exp $
/* $Id: mdl.c,v 1.28 2001/02/10 22:51:10 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -60,15 +60,12 @@ VOID STDCALL MmUnlockPages(PMDL Mdl)
return;
}
MmLockAddressSpace(&Mdl->Process->AddressSpace);
MdlPages = (PULONG)(Mdl + 1);
for (i=0; i<(PAGE_ROUND_UP(Mdl->ByteCount+Mdl->ByteOffset)/PAGESIZE); i++)
{
MmUnlockPage((PVOID)MdlPages[i]);
MmDereferencePage((PVOID)MdlPages[i]);
}
MmUnlockAddressSpace(&Mdl->Process->AddressSpace);
Mdl->MdlFlags = Mdl->MdlFlags & (~MDL_PAGES_LOCKED);
}
@ -141,7 +138,8 @@ VOID STDCALL MmUnmapLockedPages(PVOID BaseAddress, PMDL Mdl)
(VOID)MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress - Mdl->ByteOffset,
Mdl->ByteCount,
FALSE);
NULL,
NULL);
Mdl->MdlFlags = Mdl->MdlFlags & ~MDL_MAPPED_TO_SYSTEM_VA;
Mdl->MappedSystemVa = NULL;
MmUnlockAddressSpace(MmGetKernelAddressSpace());

View file

@ -1,4 +1,4 @@
/* $Id: mm.c,v 1.40 2001/01/08 02:14:06 dwelch Exp $
/* $Id: mm.c,v 1.41 2001/02/10 22:51:10 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -41,20 +41,30 @@ NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
DPRINT("Releasing %x between %x %x\n",
Marea, Marea->BaseAddress, Marea->BaseAddress + Marea->Length);
if (Marea->Type == MEMORY_AREA_SECTION_VIEW_COMMIT ||
Marea->Type == MEMORY_AREA_SECTION_VIEW_RESERVE)
switch (Marea->Type)
{
MmUnmapViewOfSection(Process, Marea);
case MEMORY_AREA_SECTION_VIEW_COMMIT:
case MEMORY_AREA_SECTION_VIEW_RESERVE:
MmUnmapViewOfSection(Process, Marea->BaseAddress);
return(STATUS_SUCCESS);
case MEMORY_AREA_VIRTUAL_MEMORY:
for (i = Marea->BaseAddress;
i < (Marea->BaseAddress + Marea->Length);
i = i + PAGESIZE)
{
MmDeleteVirtualMapping(Process, i, TRUE);
}
ExFreePool(Marea);
break;
case MEMORY_AREA_SHARED_DATA:
break;
default:
KeBugCheck(0);
}
for (i = Marea->BaseAddress;
i < (Marea->BaseAddress + Marea->Length);
i = i+PAGESIZE)
{
MmDeleteVirtualMapping(Process, i, TRUE);
}
ExFreePool(Marea);
return(STATUS_SUCCESS);
}
@ -69,8 +79,7 @@ NTSTATUS MmReleaseMmInfo(PEPROCESS Process)
while (!IsListEmpty(&Process->AddressSpace.MAreaListHead))
{
CurrentEntry = RemoveHeadList(
&Process->AddressSpace.MAreaListHead);
CurrentEntry = RemoveHeadList(&Process->AddressSpace.MAreaListHead);
Current = CONTAINING_RECORD(CurrentEntry, MEMORY_AREA, Entry);
MmReleaseMemoryArea(Process, Current);
@ -122,7 +131,79 @@ BOOLEAN STDCALL MmIsAddressValid(PVOID VirtualAddress)
NTSTATUS MmAccessFault(KPROCESSOR_MODE Mode,
ULONG Address)
{
return(STATUS_UNSUCCESSFUL);
PMADDRESS_SPACE AddressSpace;
MEMORY_AREA* MemoryArea;
NTSTATUS Status;
DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address);
if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
{
DbgPrint("Page fault at high IRQL was %d\n", KeGetCurrentIrql());
return(STATUS_UNSUCCESSFUL);
}
if (PsGetCurrentProcess() == NULL)
{
DbgPrint("No current process\n");
return(STATUS_UNSUCCESSFUL);
}
/*
* Find the memory area for the faulting address
*/
if (Address >= KERNEL_BASE)
{
/*
* Check permissions
*/
if (Mode != KernelMode)
{
DbgPrint("%s:%d\n",__FILE__,__LINE__);
return(STATUS_UNSUCCESSFUL);
}
AddressSpace = MmGetKernelAddressSpace();
}
else
{
AddressSpace = &PsGetCurrentProcess()->AddressSpace;
}
MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace, (PVOID)Address);
if (MemoryArea == NULL)
{
DbgPrint("%s:%d\n",__FILE__,__LINE__);
MmUnlockAddressSpace(AddressSpace);
return(STATUS_UNSUCCESSFUL);
}
switch (MemoryArea->Type)
{
case MEMORY_AREA_SYSTEM:
Status = STATUS_UNSUCCESSFUL;
break;
case MEMORY_AREA_SECTION_VIEW_COMMIT:
Status = MmAccessFaultSectionView(AddressSpace,
MemoryArea,
(PVOID)Address);
break;
case MEMORY_AREA_VIRTUAL_MEMORY:
Status = STATUS_UNSUCCESSFUL;
break;
case MEMORY_AREA_SHARED_DATA:
Status = STATUS_UNSUCCESSFUL;
break;
default:
Status = STATUS_UNSUCCESSFUL;
break;
}
DPRINT("Completed page fault handling\n");
MmUnlockAddressSpace(AddressSpace);
return(Status);
}
NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode,

View file

@ -1,4 +1,4 @@
/* $Id: ncache.c,v 1.7 2001/01/08 02:14:06 dwelch Exp $
/* $Id: ncache.c,v 1.8 2001/02/10 22:51:10 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -80,7 +80,17 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
return ((PVOID)Result);
}
VOID static
MmFreeNonCachedPage(PVOID Context, PVOID Address)
{
ULONG PhysAddr;
PhysAddr = MmGetPhysicalAddressForProcess(NULL, Address);
if (PhysAddr != 0)
{
MmDereferencePage((PVOID)PhysAddr);
}
}
/**********************************************************************
* NAME EXPORTED
@ -113,7 +123,8 @@ VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
MmFreeMemoryArea (MmGetKernelAddressSpace(),
BaseAddress,
NumberOfBytes,
TRUE);
MmFreeNonCachedPage,
NULL);
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* $Id: virtual.c,v 1.37 2001/01/21 14:54:29 dwelch Exp $
/* $Id: virtual.c,v 1.38 2001/02/10 22:51:10 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -1013,7 +1013,8 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
MmFreeMemoryArea(&Process->AddressSpace,
BaseAddress,
0,
FALSE);
NULL,
NULL);
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_SUCCESS);

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.68 2001/01/28 17:38:40 ekohl Exp $
/* $Id: thread.c,v 1.69 2001/02/10 22:51:11 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -114,8 +114,8 @@ VOID PsDumpThreads(VOID)
DbgPrint("current %x current->Tcb.State %d eip %x/%x ",
current, current->Tcb.State,
0, current->Tcb.LastEip);
// KeDumpStackFrames((PVOID)current->Tcb.Context.esp0,
// 16);
KeDumpStackFrames((PVOID)current->Tcb.KernelStack,
16);
DbgPrint("PID %d ", current->ThreadsProcess->UniqueProcessId);
DbgPrint("\n");

View file

@ -1,4 +1,4 @@
/* $Id: regio.c,v 1.2 2000/05/09 21:30:27 ekohl Exp $
/* $Id: regio.c,v 1.3 2001/02/10 22:51:11 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -155,4 +155,4 @@ WRITE_REGISTER_BUFFER_ULONG (
}
}
/* EOF */
/* EOF */

View file

@ -18,6 +18,7 @@ endif
ifeq ($(HOST),mingw32-linux)
NASM_FORMAT = win32
PREFIX = i586-mingw32-
#PREFIX = /usr/mingw32-cvs-000207/bin/mingw32-cvs-000207-
EXE_POSTFIX =
EXE_PREFIX = ./
#CP = cp