struct _VPB* Vpb;
struct _DEVICE_OBJECT* DeviceObject;
} Mount;
+ struct {
+ ULONG Length;
+ FILE_INFORMATION_CLASS FileInformationClass;
+ } QueryFile;
+ struct {
+ ULONG Length;
+ FS_INFORMATION_CLASS FileInformationClass;
+ } QueryVolume;
+ struct {
+ ULONG Length;
+ FS_INFORMATION_CLASS FileInformationClass;
+ } SetVolume;
+ struct {
+ ULONG Length;
+ FILE_INFORMATION_CLASS FileInformationClass;
+ struct FILE_OBJECT* FileObject;
+ union {
+ struct {
+ BOOLEAN ReplaceIfExists;
+ BOOLEAN AdvanceOnly;
+ } d;
+ ULONG ClusterCount;
+ HANDLE DeleteHandle;
+ } u;
+ } SetFile;
+
+ /*
+ * This is a guess
+ */
+ struct
+ {
+ FILE_INFORMATION_CLASS FileInformationClass;
+ BOOLEAN ReturnSingleEntry;
+ PUNICODE_STRING FileName;
+ BOOLEAN RestartScan;
+ } QueryDirectory;
} Parameters;
PIO_COMPLETION_ROUTINE CompletionRoutine;
PVOID Address
);
+NTSTATUS RtlUnicodeStringToAnsiString(IN OUT PANSI_STRING DestinationString,
+ IN PUNICODE_STRING SourceString,
+ IN BOOLEAN AllocateDestinationString);
+NTSTATUS RtlUnicodeStringToInteger(IN PUNICODE_STRING String, IN ULONG Base,
+ OUT PULONG Value);
+NTSTATUS RtlUpcaseUnicodeString(IN OUT PUNICODE_STRING DestinationString,
+ IN PUNICODE_STRING SourceString,
+ IN BOOLEAN AllocateDestinationString);
+VOID RtlUpperString(PSTRING DestinationString, PSTRING SourceString);
+BOOLEAN RtlValidSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor);
+NTSTATUS RtlWriteRegistryValue(ULONG RelativeTo,
+ PWSTR Path,
+ PWSTR ValueName,
+ ULONG ValueType,
+ PVOID ValueData,
+ ULONG ValueLength);
+
+
+
+
+
+VOID RtlStoreUlong(PULONG Address,
+ ULONG Value);
+
+
#endif /* __DDK_RTL_H */
#define DPRINT1(x)
#endif
-#define UNIMPLEMENTED do {DbgPrint("%s at %s:%d is umimplemented, have a nice day\n",__FUNCTION__,__FILE__,__LINE__); for(;;); } while(0);
+#define UNIMPLEMENTED do {DbgPrint("%s at %s:%d is unimplemented, have a nice day\n",__FUNCTION__,__FILE__,__LINE__); for(;;); } while(0);
#ifndef NDEBUG
-#define DPRINT(fmt,args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(fmt,args); ExAllocatePool(NonPagedPool, 0); } while(0);
+#define OLD_DPRINT(fmt,args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(fmt,args); } while(0);
+#define DPRINT(args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(args); ExAllocatePool(NonPagedPool,0); } while(0);
//#define assert(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); (*((unsigned int *)0))=1; for (;;); }
#define assert(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); for (;;); }
-#define CHECKPOINT do {DbgPrint("%s:%d\n",__FILE__,__LINE__); ExAllocatePool(NonPagedPool, 0); } while(0);
+#define CHECKPOINT do { DbgPrint("%s:%d\n",__FILE__,__LINE__); ExAllocatePool(NonPagedPool,0); } while(0);
#else
-#define DPRINT(fmt,args...)
+#define DPRINT(args...)
+#define OLD_DPRINT(args...)
#define assert(x)
#define CHECKPOINT
#endif /* NDEBUG */
dw 0x00eb,0x00eb ; jmp $+2, jmp $+2
out 0A0h,al ; and to 8259A-2
dw 0x00eb,0x00eb
- mov al,020h ; start of hardware int's (0x20)
+ mov al,040h ; start of hardware int's (0x20)
out 021h,al
dw 0x00eb,0x00eb
- mov al,028h ; start of hardware int's 2 (0x28)
+ mov al,048h ; start of hardware int's 2 (0x28)
out 0A1h,al
dw 0x00eb,0x00eb
mov al,04h ; 8259-1 is master
mov ss,ax
mov es,ax
mov fs,ax
+ mov gs,ax
;
; Initalize eflags
#
# Required to run the system
#
-COMPONENTS = kernel lib
+COMPONENTS = iface_native ntoskrnl kernel32 ntdll crtdll mingw32
#
# Select the server(s) you want to build
#
# Select the device drivers and filesystems you want
#
-KERNEL_SERVICES = parallel keyboard null mouse serial sound ide test minix
+KERNEL_SERVICES = parallel keyboard null mouse serial sound ide test sdisk \
+ minix vfat
-all: $(COMPONENTS) $(LOADERS) $(KERNEL_SERVICES)
+APPS = hello shell
+
+all: $(COMPONENTS) $(LOADERS) $(KERNEL_SERVICES) $(APPS)
+
+clean: dummy
+ make -C iface/native clean
+
+#
+# Applications
+#
+hello: dummy
+ make -C apps/hello
+
+cmd: dummy
+ make -C apps/cmd
+
+shell: dummy
+ make -C apps/shell
+
+#
+# Interfaces
+#
+iface_native: dummy
+ make -C iface/native
#
# Device driver rules
#
+vfat: dummy
+ make -C services/fs/vfat
+
sdisk: dummy
- make -C services/sdisk
+ make -C services/dd/sdisk
minix: dummy
make -C services/fs/minix
+
+template: dummy
+ make -C services/fs/template
ide-test: dummy
- make -C services/ide-test
+ make -C services/dd/ide-test
ide: dummy
- make -C services/ide
+ make -C services/dd/ide
test: dummy
- make -C services/test
+ make -C services/dd/test
test1: dummy
- make -C services/test1
+ make -C services/dd/test1
null: dummy
- make -C services/null
+ make -C services/dd/null
parallel: dummy
- make -C services/parallel
+ make -C services/dd/parallel
keyboard: dummy
- make -C services/keyboard
+ make -C services/dd/keyboard
mouse: dummy
- make -C services/mouse
+ make -C services/dd/mouse
serial: dummy
- make -C services/serial
+ make -C services/dd/serial
sound: dummy
- make -C services/sound
-
-ide: dummy
- make -C services/ide
-
-ide-test: dummy
- make -C services/ide-test
+ make -C services/dd/sound
#
# Kernel loaders
# Required system components
#
-kernel: dummy
+ntoskrnl: dummy
make -C ntoskrnl
-lib: dummy
- make -C lib
+kernel32: dummy
+ make -C lib/kernel32
+
+ntdll: dummy
+ make -C lib/ntdll
+
+crtdll: dummy
+ make -C lib/crtdll
+
+mingw32: dummy
+ make -C lib/mingw32
dummy:
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
- * FILE: mkernel/hal/irql.c
+ * FILE: ntoskrnl/hal/x86/irql.c
* PURPOSE: Implements IRQLs
* PROGRAMMER: David Welch (welch@mcmail.com)
*/
/*
* sanity check
*/
- DPRINT("CurrentIrql %x NewIrql %x OldIrql %x\n",CurrentIrql,NewIrql,
- OldIrql);
+ DPRINT("CurrentIrql %x NewIrql %x OldIrql %x\n",CurrentIrql,NewIrql,
+ OldIrql);
if (NewIrql < CurrentIrql)
{
- DbgPrint("%s:%d CurrentIrql %x NewIrql %x OldIrql %x\n",__FILE__,__LINE__,
- CurrentIrql,NewIrql,OldIrql);
+ DbgPrint("%s:%d CurrentIrql %x NewIrql %x OldIrql %x\n",
+ __FILE__,__LINE__,CurrentIrql,NewIrql,OldIrql);
for(;;);
}
/* FUNCTIONS *****************************************************************/
+NTSTATUS IoPrepareIrpBuffer(PIRP Irp,
+ PDEVICE_OBJECT DeviceObject,
+ PVOID Buffer,
+ PVOID Length)
+{
+}
+
PIRP IoBuildFilesystemControlRequest(ULONG MinorFunction,
PDEVICE_OBJECT DeviceObject,
PKEVENT UserEvent,
* ARGUMENTS:
* MinorFunction = Type of filesystem control
* DeviceObject = Device object to send the request to
+ * UserEvent = Event used to notify the caller of completion
+ * IoStatusBlock (OUT) = Used to return the status of the operation
+ * DeviceToMount = Device to mount (for the IRP_MN_MOUNT_DEVICE
+ * request)
*/
{
PIRP Irp;
StackPtr->Control = 0;
StackPtr->DeviceObject = DeviceObject;
StackPtr->FileObject = NULL;
- StackPtr->Parameters.Mount.Vpb = DeviceObject->Vpb;
- StackPtr->Parameters.Mount.DeviceObject = DeviceToMount;
+ switch(MinorFunction)
+ {
+ case IRP_MN_USER_FS_REQUEST:
+ break;
+
+ case IRP_MN_MOUNT_VOLUME:
+ StackPtr->Parameters.Mount.Vpb = DeviceObject->Vpb;
+ StackPtr->Parameters.Mount.DeviceObject = DeviceToMount;
+ break;
+
+ case IRP_MN_VERIFY_VOLUME:
+ break;
+
+ case IRP_MN_LOAD_FILE_SYSTEM:
+ break;
+ }
return(Irp);
}
* NULL on failure
*/
{
- PIRP Irp;
+ PIRP Irp;
PIO_STACK_LOCATION StackPtr;
+ DPRINT("IoBuildAsynchronousFsdRequest(MajorFunction %x, DeviceObject %x, "
+ "Buffer %x, Length %x, StartingOffset %x, "
+ "IoStatusBlock %x\n",MajorFunction,DeviceObject,Buffer,Length,
+ StartingOffset,IoStatusBlock);
Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE);
if (Irp==NULL)
{
return(NULL);
}
-
- Irp->UserBuffer = (LPVOID)Buffer;
- if (DeviceObject->Flags&DO_BUFFERED_IO)
- {
- DPRINT("Doing buffer i/o\n",0);
- Irp->AssociatedIrp.SystemBuffer = (PVOID)
- ExAllocatePool(NonPagedPool,Length);
- if (Irp->AssociatedIrp.SystemBuffer==NULL)
- {
- return(NULL);
- }
- Irp->UserBuffer = NULL;
- }
- if (DeviceObject->Flags&DO_DIRECT_IO)
- {
- DPRINT("Doing direct i/o\n",0);
-
- Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
- MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
- Irp->UserBuffer = NULL;
- Irp->AssociatedIrp.SystemBuffer = NULL;
- }
- Irp->UserIosb = IoStatusBlock;
-
StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->MajorFunction = MajorFunction;
StackPtr->MinorFunction = 0;
StackPtr->DeviceObject = DeviceObject;
StackPtr->FileObject = NULL;
StackPtr->Parameters.Write.Length = Length;
- if (StartingOffset!=NULL)
- {
- StackPtr->Parameters.Write.ByteOffset.LowPart =
- StartingOffset->LowPart;
- StackPtr->Parameters.Write.ByteOffset.HighPart =
- StartingOffset->HighPart;
- }
- else
- {
- StackPtr->Parameters.Write.ByteOffset.LowPart = 0;
- StackPtr->Parameters.Write.ByteOffset.HighPart = 0;
- }
+ if (MajorFunction == IRP_MJ_READ || MajorFunction == IRP_MJ_WRITE)
+ {
+ Irp->UserBuffer = (LPVOID)Buffer;
+ if (DeviceObject->Flags&DO_BUFFERED_IO)
+ {
+ DPRINT("Doing buffer i/o\n",0);
+ Irp->AssociatedIrp.SystemBuffer = (PVOID)
+ ExAllocatePool(NonPagedPool,Length);
+ if (Irp->AssociatedIrp.SystemBuffer==NULL)
+ {
+ return(NULL);
+ }
+ }
+ if (DeviceObject->Flags&DO_DIRECT_IO)
+ {
+ DPRINT("Doing direct i/o\n",0);
+
+ Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
+ MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
+ Irp->UserBuffer = NULL;
+ Irp->AssociatedIrp.SystemBuffer = NULL;
+ }
+ if (StartingOffset!=NULL)
+ {
+ StackPtr->Parameters.Write.ByteOffset.LowPart =
+ StartingOffset->LowPart;
+ StackPtr->Parameters.Write.ByteOffset.HighPart =
+ StartingOffset->HighPart;
+ }
+ else
+ {
+ StackPtr->Parameters.Write.ByteOffset.LowPart = 0;
+ StackPtr->Parameters.Write.ByteOffset.HighPart = 0;
+ }
+ }
+
+ Irp->UserIosb = IoStatusBlock;
+
return(Irp);
}
Irp->AssociatedIrp.SystemBuffer = NULL;
}
- Irp->UserIosb = IoStatusBlock;
- Irp->UserEvent = Event;
-
StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->MajorFunction = MajorFunction;
StackPtr->MinorFunction = 0;
/* INCLUDES ****************************************************************/
#include <internal/string.h>
+#include <internal/io.h>
#include <ddk/ntddk.h>
//#define NDEBUG
* Irp = Irp to mark
*/
{
+ DPRINT("IoGetCurrentIrpStackLocation(Irp) %x\n",
+ IoGetCurrentIrpStackLocation(Irp));
IoGetCurrentIrpStackLocation(Irp)->Control |= SL_PENDING_RETURNED;
+ DPRINT("IoGetCurrentIrpStackLocation(Irp)->Control %x\n",
+ IoGetCurrentIrpStackLocation(Irp)->Control);
+ DPRINT("SL_PENDING_RETURNED %x\n",SL_PENDING_RETURNED);
}
USHORT IoSizeOfIrp(CCHAR StackSize)
DPRINT("Io stack address %x\n",param);
DPRINT("Function %d Routine %x\n",param->MajorFunction,
drv->MajorFunction[param->MajorFunction]);
- DPRINT("IRP_MJ_CREATE %d\n",IRP_MJ_CREATE);
return(drv->MajorFunction[param->MajorFunction](DevObject,irp));
}
param->CompletionContext=Context;
if (InvokeOnSuccess)
{
- param->Control = SL_INVOKE_ON_SUCCESS;
+ param->Control = param->Control | SL_INVOKE_ON_SUCCESS;
}
if (InvokeOnError)
{
}
}
+VOID IopCompleteRequest(struct _KAPC* Apc,
+ PKNORMAL_ROUTINE* NormalRoutine,
+ PVOID* NormalContext,
+ PVOID* SystemArgument1,
+ PVOID* SystemArgument2)
+{
+ IoSecondStageCompletion((PIRP)(*NormalContext),
+ IO_NO_INCREMENT);
+}
+
VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
/*
* FUNCTION: Indicates the caller has finished all processing for a given
*/
{
unsigned int i;
+ NTSTATUS Status;
DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d)\n",
- Irp,PriorityBoost);
+ Irp,PriorityBoost);
+
for (i=0;i<Irp->StackCount;i++)
{
+ DPRINT("&Irp->Stack[i] %x\n",&Irp->Stack[i]);
if (Irp->Stack[i].CompletionRoutine!=NULL)
{
- Irp->Stack[i].CompletionRoutine(Irp->Stack[i].DeviceObject,Irp,
+ Status = Irp->Stack[i].CompletionRoutine(
+ Irp->Stack[i].DeviceObject,
+ Irp,
Irp->Stack[i].CompletionContext);
+ if (Status == STATUS_MORE_PROCESSING_REQUIRED)
+ {
+ return;
+ }
+ }
+ DPRINT("Irp->Stack[i].Control %x\n",Irp->Stack[i].Control);
+ if (Irp->Stack[i].Control & SL_PENDING_RETURNED)
+ {
+ DPRINT("Setting PendingReturned flag\n");
+ Irp->PendingReturned = TRUE;
}
}
-
- if (Irp->UserEvent!=NULL)
+
+ if (Irp->PendingReturned)
+ {
+ KeInitializeApc(&Irp->Tail.Apc,
+ &Irp->Tail.Overlay.Thread->Tcb,
+ 0,
+ IopCompleteRequest,
+ NULL,
+ NULL,
+ 0,
+ Irp);
+ KeInsertQueueApc(&Irp->Tail.Apc,NULL,NULL,0);
+ }
+ else
{
- KeSetEvent(Irp->UserEvent,PriorityBoost,FALSE);
+ IoSecondStageCompletion(Irp,PriorityBoost);
}
}
else
{
DeviceObject->CurrentIrp = NULL;
- }
+ }
}
VOID IoStartPacket(PDEVICE_OBJECT DeviceObject,
/* FUNCTIONS ***************************************************************/
-static VOID IoSecondStageCompletion(PIRP Irp,
- BOOLEAN FromDevice,
- PDEVICE_OBJECT DeviceObject,
- ULONG Length,
- PVOID Buffer)
-/*
- * FUNCTION: Performs the second stage of irp completion for read/write irps
- * ARGUMENTS:
- * Irp = Irp to completion
- * FromDevice = True if the operation transfered data from the device
- */
+NTSTATUS NtReadFile(HANDLE FileHandle,
+ HANDLE EventHandle,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID Buffer,
+ ULONG Length,
+ PLARGE_INTEGER ByteOffset,
+ PULONG Key)
{
- if (Irp->UserIosb!=NULL)
- {
- *Irp->UserIosb=Irp->IoStatus;
- }
-
- if (DeviceObject->Flags & DO_BUFFERED_IO && FromDevice)
- {
- memcpy(Buffer,Irp->AssociatedIrp.SystemBuffer,Length);
- }
- if (DeviceObject->Flags & DO_DIRECT_IO)
- {
- if (Irp->MdlAddress->MappedSystemVa!=NULL)
- {
- MmUnmapLockedPages(Irp->MdlAddress->MappedSystemVa,
- Irp->MdlAddress);
- }
- MmUnlockPages(Irp->MdlAddress);
- ExFreePool(Irp->MdlAddress);
- }
-
- IoFreeIrp(Irp);
+ return(ZwReadFile(FileHandle,
+ EventHandle,
+ ApcRoutine,
+ ApcContext,
+ IoStatusBlock,
+ Buffer,
+ Length,
+ ByteOffset,
+ Key));
}
NTSTATUS ZwReadFile(HANDLE FileHandle,
"IoStatusBlock %x)\n",
FileHandle,Buffer,Length,ByteOffset,IoStatusBlock);
- if (hdr==NULL)
+ Status = ObReferenceObjectByHandle(FileHandle,
+ FILE_READ_DATA,
+ NULL,
+ UserMode,
+ &FileObject,
+ NULL);
+ if (Status != STATUS_SUCCESS)
{
- DPRINT("%s() = STATUS_INVALID_HANDLE\n",__FUNCTION__);
- return(STATUS_INVALID_HANDLE);
+ return(Status);
}
if (ByteOffset==NULL)
}
KeInitializeEvent(&Event,NotificationEvent,FALSE);
+ DPRINT("FileObject %x\n",FileObject);
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
FileObject->DeviceObject,
Buffer,
return(Status);
}
+NTSTATUS NtWriteFile(HANDLE FileHandle,
+ HANDLE EventHandle,
+ PIO_APC_ROUTINE ApcRoutine,
+ PVOID ApcContext,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PVOID Buffer,
+ ULONG Length,
+ PLARGE_INTEGER ByteOffset,
+ PULONG Key)
+{
+ return(ZwWriteFile(FileHandle,
+ EventHandle,
+ ApcRoutine,
+ ApcContext,
+ IoStatusBlock,
+ Buffer,
+ Length,
+ ByteOffset,
+ Key));
+}
+
NTSTATUS ZwWriteFile(HANDLE FileHandle,
HANDLE EventHandle,
PIO_APC_ROUTINE ApcRoutine,
IoStatusBlock);
DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject);
Status = IoCallDriver(FileObject->DeviceObject,Irp);
- if (Status==STATUS_PENDING)
+ if (Status==STATUS_PENDING && (FileObject->Flags & FO_SYNCHRONOUS_IO))
{
KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
Status = Irp->IoStatus.Status;
return(Status);
}
+NTSTATUS STDCALL NtReadFileScatter(IN HANDLE FileHandle,
+ IN HANDLE Event OPTIONAL,
+ IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
+ IN PVOID UserApcContext OPTIONAL,
+ OUT PIO_STATUS_BLOCK UserIoStatusBlock,
+ IN FILE_SEGMENT_ELEMENT BufferDescription[],
+ IN ULONG BufferLength,
+ IN PLARGE_INTEGER ByteOffset,
+ IN PULONG Key OPTIONAL)
+{
+ return(ZwReadFileScatter(FileHandle,
+ Event,
+ UserApcRoutine,
+ UserApcContext,
+ UserIoStatusBlock,
+ BufferDescription,
+ BufferLength,
+ ByteOffset,
+ Key));
+}
+
+NTSTATUS STDCALL ZwReadFileScatter(IN HANDLE FileHandle,
+ IN HANDLE Event OPTIONAL,
+ IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL,
+ IN PVOID UserApcContext OPTIONAL,
+ OUT PIO_STATUS_BLOCK UserIoStatusBlock,
+ IN FILE_SEGMENT_ELEMENT BufferDescription[],
+ IN ULONG BufferLength,
+ IN PLARGE_INTEGER ByteOffset,
+ IN PULONG Key OPTIONAL)
+{
+ UNIMPLEMENTED;
+}
+
+
+NTSTATUS STDCALL NtWriteFileGather(IN HANDLE FileHandle,
+ IN HANDLE Event OPTIONAL,
+ IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
+ IN PVOID ApcContext OPTIONAL,
+ OUT PIO_STATUS_BLOCK IoStatusBlock,
+ IN FILE_SEGMENT_ELEMENT BufferDescription[],
+ IN ULONG BufferLength,
+ IN PLARGE_INTEGER ByteOffset,
+ IN PULONG Key OPTIONAL)
+{
+ return(ZwWriteFileGather(FileHandle,
+ Event,
+ ApcRoutine,
+ ApcContext,
+ IoStatusBlock,
+ BufferDescription,
+ BufferLength,
+ ByteOffset,
+ Key));
+}
+
+NTSTATUS STDCALL ZwWriteFileGather(IN HANDLE FileHandle,
+ IN HANDLE Event OPTIONAL,
+ IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
+ IN PVOID ApcContext OPTIONAL,
+ OUT PIO_STATUS_BLOCK IoStatusBlock,
+ IN FILE_SEGMENT_ELEMENT BufferDescription[],
+ IN ULONG BufferLength,
+ IN PLARGE_INTEGER ByteOffset,
+ IN PULONG Key OPTIONAL)
+{
+ UNIMPLEMENTED;
+}
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/vpb.c
- * PURPOSE: Volume Parameters Block managment
+ * PURPOSE: Volume Parameter Block managment
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY:
* Created 22/05/98
#include <ddk/ntddk.h>
#include <internal/string.h>
+#include <internal/ob.h>
#include <internal/debug.h>
DeviceObject->Vpb = Vpb;
}
+
+PIRP IoBuildVolumeInformationIrp(ULONG MajorFunction,
+ PFILE_OBJECT FileObject,
+ PVOID FSInformation,
+ ULONG Length,
+ CINT FSInformationClass,
+ PIO_STATUS_BLOCK IoStatusBlock,
+ PKEVENT Event)
+{
+ PIRP Irp;
+ PIO_STACK_LOCATION StackPtr;
+ PDEVICE_OBJECT DeviceObject;
+
+ DeviceObject = FileObject->DeviceObject;
+
+ Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE);
+ if (Irp==NULL)
+ {
+ return(NULL);
+ }
+
+ Irp->AssociatedIrp.SystemBuffer = FSInformation;
+
+ StackPtr = IoGetNextIrpStackLocation(Irp);
+ StackPtr->MajorFunction = MajorFunction;
+ StackPtr->MinorFunction = 0;
+ StackPtr->Flags = 0;
+ StackPtr->Control = 0;
+ StackPtr->DeviceObject = DeviceObject;
+ StackPtr->FileObject = FileObject;
+ Irp->UserEvent = Event;
+ Irp->UserIosb = IoStatusBlock;
+
+ if (MajorFunction == IRP_MJ_QUERY_VOLUME_INFORMATION)
+ {
+ StackPtr->Parameters.SetVolume.Length = Length;
+ StackPtr->Parameters.SetVolume.FileInformationClass =
+ FSInformationClass;
+ }
+ else
+ {
+ StackPtr->Parameters.QueryVolume.Length = Length;
+ StackPtr->Parameters.QueryVolume.FileInformationClass =
+ FSInformationClass;
+ }
+ return(Irp);
+}
+
+NTSTATUS STDCALL NtQueryVolumeInformationFile(
+ IN HANDLE FileHandle,
+ OUT PIO_STATUS_BLOCK IoStatusBlock,
+ OUT PVOID FSInformation,
+ IN ULONG Length,
+ IN CINT FSInformationClass)
+
+/*
+ * FUNCTION: Queries the volume information
+ * ARGUMENTS:
+ * FileHandle = Handle to a file object on the target volume
+ * ReturnLength = DataWritten
+ * FSInformation = Caller should supply storage for the information
+ * structure.
+ * Length = Size of the information structure
+ * FSInformationClass = Index to a information structure
+ *
+ * FileFsVolumeInformation FILE_FS_VOLUME_INFORMATION
+ * FileFsLabelInformation FILE_FS_LABEL_INFORMATION
+ * FileFsSizeInformation FILE_FS_SIZE_INFORMATION
+ * FileFsDeviceInformation FILE_FS_DEVICE_INFORMATION
+ * FileFsAttributeInformation FILE_FS_ATTRIBUTE_INFORMATION
+ * FileFsControlInformation
+ * FileFsQuotaQueryInformation --
+ * FileFsQuotaSetInformation --
+ * FileFsMaximumInformation
+ *
+ * RETURNS: Status
+ */
+{
+ return(ZwQueryVolumeInformationFile(FileHandle,IoStatusBlock,FSInformation,
+ Length,FSInformationClass));
+}
+
+NTSTATUS
+STDCALL
+ZwQueryVolumeInformationFile(
+ IN HANDLE FileHandle,
+ OUT PIO_STATUS_BLOCK IoStatusBlock,
+ OUT PVOID FSInformation,
+ IN ULONG Length,
+ IN CINT FSInformationClass)
+{
+ PFILE_OBJECT FileObject;
+ PDEVICE_OBJECT DeviceObject;
+ PIRP Irp;
+ KEVENT Event;
+ NTSTATUS Status;
+
+ Status = ObReferenceObjectByHandle(FileHandle,
+ FILE_READ_ATTRIBUTES,
+ NULL,
+ UserMode,
+ (PVOID*)&FileObject,
+ NULL);
+ if (Status != STATUS_SUCCESS)
+ {
+ return(Status);
+ }
+
+ DeviceObject = FileObject->DeviceObject;
+
+ KeInitializeEvent(&Event,NotificationEvent,FALSE);
+
+ Irp = IoBuildVolumeInformationIrp(IRP_MJ_QUERY_VOLUME_INFORMATION,
+ FileObject,
+ FSInformation,
+ Length,
+ FSInformationClass,
+ IoStatusBlock,
+ &Event);
+ Status = IoCallDriver(DeviceObject,Irp);
+ if (Status == STATUS_PENDING)
+ {
+ KeWaitForSingleObject(&Event,UserRequest,KernelMode,FALSE,NULL);
+ Status = IoStatusBlock->Status;
+ }
+ return(Status);
+}
+
+NTSTATUS
+STDCALL
+NtSetVolumeInformationFile(
+ IN HANDLE FileHandle,
+ IN CINT VolumeInformationClass,
+ PVOID VolumeInformation,
+ ULONG Length
+ )
+{
+ return(ZwSetVolumeInformationFile(FileHandle,VolumeInformationClass,
+ VolumeInformation,Length));
+}
+
+NTSTATUS
+STDCALL
+ZwSetVolumeInformationFile(
+ IN HANDLE FileHandle,
+ IN CINT VolumeInformationClass,
+ PVOID VolumeInformation,
+ ULONG Length
+ )
+{
+
+ PFILE_OBJECT FileObject;
+ PDEVICE_OBJECT DeviceObject;
+ PIRP Irp;
+ KEVENT Event;
+ NTSTATUS Status;
+
+ Status = ObReferenceObjectByHandle(FileHandle,
+ FILE_WRITE_ATTRIBUTES,
+ NULL,
+ UserMode,
+ (PVOID*)&FileObject,
+ NULL);
+ if (Status != STATUS_SUCCESS)
+ {
+ return(Status);
+ }
+
+ DeviceObject = FileObject->DeviceObject;
+
+ KeInitializeEvent(&Event,NotificationEvent,FALSE);
+
+ Irp = IoBuildVolumeInformationIrp(IRP_MJ_SET_VOLUME_INFORMATION,
+ FileObject,
+ VolumeInformation,
+ Length,
+ VolumeInformationClass,
+ NULL,
+ &Event);
+ Status = IoCallDriver(DeviceObject,Irp);
+ if (Status == STATUS_PENDING)
+ {
+ KeWaitForSingleObject(&Event,UserRequest,KernelMode,FALSE,NULL);
+ }
+ return(Status);
+}
#include <internal/symbol.h>
#include <internal/module.h>
-#include <internal/hal/page.h>
-#include <internal/hal/segment.h>
+#include <internal/mmhal.h>
+#include <internal/i386/segment.h>
//#define NDEBUG
#include <internal/debug.h>
start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]);
if (start < ((int)&end))
{
+ DbgPrint("start %x end %x\n",start,(int)&end);
DbgPrint("Kernel booted incorrectly, aborting\n");
+ DbgPrint("Reduce the amount of uninitialized data\n");
for(;;);
}
DPRINT("MmGetPhysicalAddress(start) = %x\n",MmGetPhysicalAddress(start));
* Enter idle loop
*/
printk("Finished main()\n");
- for (;;);
+ PsTerminateSystemThread(STATUS_SUCCESS);
}
for (i=0; i<mod->nsyms; i++)
{
get_symbol_name(mod,i,name);
-// DPRINT("Scanning %s Value %x\n",name,mod->sym_list[i].e_value);
+ DPRINT("Scanning %s Value %x\n",name,mod->sym_list[i].e_value);
if (strcmp(name,sname)==0)
{
DPRINT("Returning %x\n",mod->sym_list[i].e_value);
}
}
- DPRINT("Allocate base: %x\n",mod->base);
+ DbgPrint("Module base: %x\n",mod->base);
/*
* Find the entry point
-
all: kimage
#
#
include hal/x86/sources
+NT_OBJECTS = nt/port.o nt/channel.o nt/ntevent.o nt/nttimer.o nt/atom.o \
+ nt/evtpair.o nt/ntsem.o nt/mutant.o nt/misc.o nt/plugplay.o \
+ nt/profile.o
+
RTL_OBJECTS = rtl/vsprintf.o rtl/lookas.o rtl/unicode.o rtl/strtok.o \
rtl/time.o rtl/unalign.o rtl/mem.o rtl/largeint.o rtl/ctype.o \
rtl/list.o rtl/slist.o rtl/interlck.o rtl/return.o \
KE_OBJECTS = ke/main.o ke/timer.o ke/error.o ke/catch.o ke/exports.o \
ke/module.o ke/dpc.o ke/wait.o ke/kqueue.o ke/dispatch.o \
ke/sem.o ke/critical.o ke/event.o ke/apc.o ke/bug.o \
- ke/mutex.o ke/kernel.o
+ ke/mutex.o ke/kernel.o ke/ldt.o ke/apchelp.o
+
+MM_OBJECTS = mm/mm.o mm/freelist.o mm/pool.o mm/virtual.o \
+ mm/mdl.o mm/zone.o mm/special.o mm/paging.o \
+ mm/section.o mm/marea.o mm/ppool.o mm/npool.o
-MM_OBJECTS = mm/mm.o mm/freelist.o mm/pool.o mm/pageflt.o mm/virtual.o \
- mm/mdl.o mm/zone.o mm/special.o \
- mm/section.o mm/marea.o
-
IO_OBJECTS = io/iomgr.o io/create.o io/irp.o io/device.o io/rw.o \
io/queue.o io/drvlck.o io/timer.o io/share.o io/errlog.o \
io/shutdown.o io/fdisk.o io/cancel.o io/error.o io/arc.o \
io/dpc.o io/symlink.o io/adapter.o io/cntrller.o io/mdl.o \
io/resource.o io/event.o io/process.o io/file.o io/ioctrl.o \
- io/fs.o io/vpb.o io/buildirp.o
+ io/fs.o io/vpb.o io/buildirp.o io/flush.o io/dir.o io/iocomp.o \
+ io/mailslot.o io/npipe.o io/lock.o io/page.o io/cleanup.o
OB_OBJECTS = ob/object.o ob/handle.o ob/namespc.o
-PS_OBJECTS = ps/psmgr.o ps/thread.o ps/process.o ps/idle.o
+PS_OBJECTS = ps/psmgr.o ps/thread.o ps/process.o ps/idle.o ps/kill.o \
+ ps/tinfo.o
EX_OBJECTS = ex/work.o ex/fmutex.o ex/resource.o ex/time.o ex/interlck.o \
- ex/callback.o
+ ex/callback.o ex/napi.o ex/power.o ex/sysinfo.o ex/locale.o \
+ ex/stamp.o
SE_OBJECTS = se/semgr.o
-CFG_OBJECTS = cfg/registry.o
+CM_OBJECTS = cm/registry.o
TST_OBJECTS = tst/test.o tst/sshell.o tst/readline.o
LDR_OBJECTS = ldr/loader.o
-OBJECTS = $(HAL_OBJECTS) $(KE_OBJECTS) $(RTL_OBJECTS) $(MM_OBJECTS) \
- $(IO_OBJECTS) $(OB_OBJECTS) $(PS_OBJECTS) $(EX_OBJECTS) \
- $(SE_OBJECTS) $(CFG_OBJECTS) $(TST_OBJECTS) $(DBG_OBJECTS)
+CC_OBJECTS = cc/cacheman.o cc/block.o
+
+objects/hal.o: $(HAL_OBJECTS)
+ $(LD) -r $(HAL_OBJECTS) -o objects/hal.o
+
+objects/io.o: $(IO_OBJECTS)
+ $(LD) -r $(IO_OBJECTS) -o objects/io.o
+
+objects/ke.o: $(KE_OBJECTS)
+ $(LD) -r $(KE_OBJECTS) -o objects/ke.o
+
+objects/rtl.o: $(RTL_OBJECTS)
+ $(LD) -r $(RTL_OBJECTS) -o objects/rtl.o
+
+objects/mm.o: $(MM_OBJECTS)
+ $(LD) -r $(MM_OBJECTS) -o objects/mm.o
+
+objects/ob.o: $(OB_OBJECTS)
+ $(LD) -r $(OB_OBJECTS) -o objects/ob.o
+
+objects/ps.o: $(PS_OBJECTS)
+ $(LD) -r $(PS_OBJECTS) -o objects/ps.o
+
+objects/ex.o: $(EX_OBJECTS)
+ $(LD) -r $(EX_OBJECTS) -o objects/ex.o
+objects/se.o: $(SE_OBJECTS)
+ $(LD) -r $(SE_OBJECTS) -o objects/se.o
+
+objects/cm.o: $(CM_OBJECTS)
+ $(LD) -r $(CM_OBJECTS) -o objects/cm.o
+
+objects/tst.o: $(TST_OBJECTS)
+ $(LD) -r $(TST_OBJECTS) -o objects/tst.o
+
+objects/dbg.o: $(DBG_OBJECTS)
+ $(LD) -r $(DBG_OBJECTS) -o objects/dbg.o
+
+objects/nt.o: $(NT_OBJECTS)
+ $(LD) -r $(NT_OBJECTS) -o objects/nt.o
+
+objects/cc.o: $(CC_OBJECTS)
+ $(LD) -r $(CC_OBJECTS) -o objects/cc.o
+
+OBJECTS = objects/hal.o objects/ke.o objects/rtl.o objects/mm.o \
+ objects/io.o objects/ob.o objects/ps.o objects/ex.o \
+ objects/se.o objects/cm.o objects/tst.o objects/dbg.o\
+ objects/nt.o objects/cc.o
+
+
utils/export/export$(EXE_POSTFIX): utils/export/export.c
$(NATIVE_CC) -g utils/export/export.c -o utils/export/export$(EXE_POSTFIX)
$(CC) $(CFLAGS) -c ke/exports.c -o ke/exports.o
kimage: $(OBJECTS)
- $(LD) --defsym _end=end --defsym _etext=etext --oformat=$(KERNEL_BFD_TARGET) -Ttext c0000000 $(LDFLAGS) $(OBJECTS) libgcc.a -o kimage
+ $(LD) --defsym _end=end --defsym _etext=etext --oformat=$(KERNEL_BFD_TARGET) -Ttext c0000000 $(LDFLAGS) $(OBJECTS) $(LIBGCC) -o kimage
+ $(OBJCOPY) -S --gap-fill=0 -O binary kimage kimage.bin
+
+old_kimage: $(OBJECTS)
+ $(LD) --defsym _end=end --defsym _etext=etext --oformat=$(KERNEL_BFD_TARGET) -Ttext c0000000 $(LDFLAGS) $(OBJECTS) $(LIBGCC) -o kimage
$(NM) --numeric-sort kimage > kernel.sym
$(OBJCOPY) -S --gap-fill=0 -O binary kimage kimage.bin
dummy:
-
+
+ex/napi.o: ex/napi.c ../include/ntdll/napi.h
+
+WITH_DEBUGGING = yes
+WIN32_LEAN_AND_MEAN = yes
include ../rules.mak
#include <ddk/ntddk.h>
#include <internal/mm.h>
-#include <internal/hal/page.h>
+#include <internal/mmhal.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
-VOID MmDumpMemoryAreas(VOID)
+VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead)
{
PLIST_ENTRY current_entry;
MEMORY_AREA* current;
- PLIST_ENTRY ListHead = &SystemAreaList;
ULONG i;
+ DbgPrint("MmDumpMemoryAreas()\n");
+
current_entry = ListHead->Flink;
while (current_entry!=ListHead)
{
current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry);
- DPRINT("Base %x Length %x End %x Attributes %x Flink %x\n",
+ DbgPrint("Base %x Length %x End %x Attributes %x Flink %x\n",
current->BaseAddress,current->Length,
current->BaseAddress+current->Length,current->Attributes,
current->Entry.Flink);
current_entry = current_entry->Flink;
}
+ DbgPrint("Finished MmDumpMemoryAreas()\n");
}
VOID MmLockMemoryAreaList(ULONG Address, PKIRQL oldlvl)
}
+VOID MmLockMemoryAreaListByMode(KPROCESSOR_MODE Mode, PKIRQL oldlvl)
+{
+ if (Mode == KernelMode)
+ {
+ KeAcquireSpinLock(&SystemAreaListLock,oldlvl);
+ }
+ else
+ {
+ PKPROCESS CurrentProcess = KeGetCurrentProcess();
+
+ KeAcquireSpinLock(&(CurrentProcess->SpinLock),oldlvl);
+ }
+}
+
+VOID MmUnlockMemoryAreaListByMode(KPROCESSOR_MODE Mode, PKIRQL oldlvl)
+{
+ if (Mode == KernelMode)
+ {
+ KeReleaseSpinLock(&SystemAreaListLock,*oldlvl);
+ }
+ else
+ {
+ PKPROCESS CurrentProcess = KeGetCurrentProcess();
+ KeReleaseSpinLock(&(CurrentProcess->SpinLock),*oldlvl);
+ }
+
+}
+
-static PLIST_ENTRY MmGetRelatedListHead(ULONG BaseAddress)
+static PLIST_ENTRY MmGetRelatedListHead(PEPROCESS Process, ULONG BaseAddress)
{
if (BaseAddress >= KERNEL_BASE)
{
}
else
{
- PEPROCESS CurrentProcess = PsGetCurrentProcess();
- if (CurrentProcess==NULL)
- {
- return(NULL);
- }
- return(&(CurrentProcess->Pcb.MemoryAreaList));
+ return(&(Process->Pcb.MemoryAreaList));
}
}
PLIST_ENTRY current_entry;
MEMORY_AREA* current;
- MmDumpMemoryAreas();
+// MmDumpMemoryAreas();
DPRINT("MmInternalOpenMemoryAreaByAddress(ListHead %x, Address %x)\n",
ListHead,Address);
if (current->BaseAddress <= Address &&
(current->BaseAddress + current->Length) > Address)
{
+ DPRINT("%s() = %x\n",__FUNCTION__,current);
return(current);
}
if (current->BaseAddress > Address)
{
+ DPRINT("%s() = NULL\n",__FUNCTION__);
return(NULL);
}
current_entry = current_entry->Flink;
}
+ DPRINT("%s() = NULL\n",__FUNCTION__);
return(NULL);
}
MEMORY_AREA* current;
ULONG Extent;
- DPRINT("MmInternalOpenMemoryAreaByRegion()\n",0);
+ DPRINT("MmInternalOpenMemoryAreaByRegion(ListHead %x, Address %x, "
+ "Length %x)\n",ListHead,Address,Length);
- MmDumpMemoryAreas();
+// MmDumpMemoryAreas();
current_entry = ListHead->Flink;
while (current_entry!=ListHead)
{
current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry);
+ DPRINT("current->BaseAddress %x current->Length %x\n",
+ current->BaseAddress,current->Length);
if (current->BaseAddress >= Address &&
current->BaseAddress <= (Address+Length))
{
- DPRINT("Finished MmInternalOpenMemoryAreaByRegion()\n",0);
+ DPRINT("Finished MmInternalOpenMemoryAreaByRegion() = %x\n",
+ current);
return(current);
}
Extent = current->BaseAddress + current->Length;
if (Extent > Address &&
Extent < (Address+Length))
{
- DPRINT("Finished MmInternalOpenMemoryAreaByRegion()\n",0);
+ DPRINT("Finished MmInternalOpenMemoryAreaByRegion() = %x\n",
+ current);
return(current);
}
if (current->BaseAddress <= Address &&
Extent >= (Address+Length))
{
- DPRINT("Finished MmInternalOpenMemoryAreaByRegion()\n",0);
+ DPRINT("Finished MmInternalOpenMemoryAreaByRegion() = %x\n",
+ current);
return(current);
}
if (current->BaseAddress >= (Address+Length))
{
- DPRINT("Finished MmInternalOpenMemoryAreaByRegion()\n",0);
+ DPRINT("Finished MmInternalOpenMemoryAreaByRegion()= NULL\n",0);
return(NULL);
}
current_entry = current_entry->Flink;
}
- DPRINT("Finished MmInternalOpenMemoryAreaByRegion()\n",0);
+ DPRINT("Finished MmInternalOpenMemoryAreaByRegion() = NULL\n",0);
return(NULL);
}
-MEMORY_AREA* MmOpenMemoryAreaByRegion(ULONG Address, ULONG Length)
+MEMORY_AREA* MmOpenMemoryAreaByRegion(PEPROCESS Process, ULONG Address,
+ ULONG Length)
{
KIRQL oldlvl;
MEMORY_AREA* Result;
PLIST_ENTRY ListHead;
+ DPRINT("MmOpenMemoryByRegion(Process %x, Address %x, Length %x)\n",
+ Process,Address,Length);
+
MmLockMemoryAreaList(Address,&oldlvl);
- ListHead = MmGetRelatedListHead(Address);
+ ListHead = MmGetRelatedListHead(Process,Address);
Result = MmInternalOpenMemoryAreaByRegion(ListHead,Address,Length);
MmUnlockMemoryAreaList(Address,&oldlvl);
return(Result);
}
-MEMORY_AREA* MmOpenMemoryAreaByRegionWithoutLock(ULONG Address, ULONG Length)
+MEMORY_AREA* MmOpenMemoryAreaByRegionWithoutLock(PEPROCESS Process,
+ ULONG Address, ULONG Length)
{
MEMORY_AREA* Result;
PLIST_ENTRY ListHead;
- ListHead = MmGetRelatedListHead(Address);
+ ListHead = MmGetRelatedListHead(Process, Address);
Result = MmInternalOpenMemoryAreaByRegion(ListHead,Address,Length);
return(Result);
}
-MEMORY_AREA* MmOpenMemoryAreaByAddress(ULONG Address)
+MEMORY_AREA* MmOpenMemoryAreaByAddress(PEPROCESS Process, PVOID Address)
{
KIRQL oldlvl;
MEMORY_AREA* Result;
DPRINT("MmOpenMemoryAreaByAddress(Address %x)\n",Address);
MmLockMemoryAreaList(Address,&oldlvl);
- ListHead = MmGetRelatedListHead(Address);
+ ListHead = MmGetRelatedListHead(Process, Address);
Result = MmInternalOpenMemoryAreaByAddress(ListHead,Address);
MmUnlockMemoryAreaList(Address,&oldlvl);
return(Result);
}
-MEMORY_AREA* MmOpenMemoryAreaByAddressWithoutLock(ULONG Address)
+MEMORY_AREA* MmOpenMemoryAreaByAddressWithoutLock(PEPROCESS Process,
+ ULONG Address)
{
MEMORY_AREA* Result;
PLIST_ENTRY ListHead;
- ListHead = MmGetRelatedListHead(Address);
+ ListHead = MmGetRelatedListHead(Process, Address);
Result = MmInternalOpenMemoryAreaByAddress(ListHead,Address);
return(Result);
}
-static VOID MmInsertMemoryAreaWithoutLock(MEMORY_AREA* marea)
+static VOID MmInsertMemoryAreaWithoutLock(PEPROCESS Process,
+ MEMORY_AREA* marea)
{
PLIST_ENTRY ListHead;
PLIST_ENTRY current_entry;
DPRINT("marea->BaseAddress %x\n",marea->BaseAddress);
DPRINT("marea->Length %x\n",marea->Length);
- ListHead=MmGetRelatedListHead(marea->BaseAddress);
+ ListHead=MmGetRelatedListHead(Process,marea->BaseAddress);
current_entry = ListHead->Flink;
CHECKPOINT;
if (IsListEmpty(ListHead))
// CHECKPOINT;
current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry);
next = CONTAINING_RECORD(current_entry->Flink,MEMORY_AREA,Entry);
+ assert(current->BaseAddress != marea->BaseAddress);
+ assert(next->BaseAddress != marea->BaseAddress);
if (current->BaseAddress < marea->BaseAddress &&
current->Entry.Flink==ListHead)
{
current_entry->Flink = inserted_entry;
- inserted_entry->Flink=&ListHead;
+ inserted_entry->Flink=ListHead;
inserted_entry->Blink=current_entry;
return;
}
InsertTailList(ListHead,inserted_entry);
}
-static ULONG MmFindGapWithoutLock(KPROCESSOR_MODE Mode, ULONG Length)
+static ULONG MmFindGapWithoutLock(PEPROCESS Process,
+ KPROCESSOR_MODE Mode, ULONG Length)
{
PLIST_ENTRY ListHead;
PLIST_ENTRY current_entry;
DPRINT("MmFindGapWithoutLock(Mode %x Length %x)\n",Mode,Length);
+
if (Mode == KernelMode)
{
ListHead = &SystemAreaList;
}
else
{
- ListHead = &(KeGetCurrentProcess()->MemoryAreaList);
+ ListHead = &(Process->Pcb.MemoryAreaList);
}
}
current_entry = current_entry->Flink;
}
+
+ if (current_entry == ListHead)
+ {
+ assert(Mode==UserMode);
+ return(MM_LOWEST_USER_ADDRESS);
+ }
+
current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry);
//DbgPrint("current %x returning %x\n",current,current->BaseAddress+
// current->Length);
return(STATUS_SUCCESS);
}
-NTSTATUS MmFreeMemoryArea(PVOID BaseAddress,
+NTSTATUS MmFreeMemoryArea(PEPROCESS Process,
+ PVOID BaseAddress,
ULONG Length,
BOOLEAN FreePages)
{
ULONG i;
KIRQL oldlvl;
+ DPRINT("MmFreeMemoryArea(Process %x, BaseAddress %x, Length %x,"
+ "FreePages %d)\n",Process,BaseAddress,Length,FreePages);
+
MmLockMemoryAreaList((ULONG)BaseAddress,&oldlvl);
- MemoryArea = MmOpenMemoryAreaByAddressWithoutLock((ULONG)BaseAddress);
- if (MemoryArea!=NULL)
+ MemoryArea = MmOpenMemoryAreaByAddressWithoutLock(Process,
+ (ULONG)BaseAddress);
+ if (MemoryArea==NULL)
{
MmUnlockMemoryAreaList((ULONG)BaseAddress,&oldlvl);
return(STATUS_UNSUCCESSFUL);
return(STATUS_SUCCESS);
}
+NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea)
+{
+ MemoryArea->LockCount++;
+}
+
+NTSTATUS MmUnlockMemoryArea(MEMORY_AREA* MemoryArea)
+{
+ MemoryArea->LockCount--;
+}
+
+PMEMORY_AREA MmSplitMemoryArea(PEPROCESS Process,
+ PMEMORY_AREA OriginalMemoryArea,
+ PVOID BaseAddress,
+ ULONG Length,
+ ULONG NewType,
+ ULONG NewAttributes)
+{
+ KIRQL oldlvl;
+ PMEMORY_AREA Result;
+ PMEMORY_AREA Split;
+
+ Result = ExAllocatePool(NonPagedPool,sizeof(MEMORY_AREA));
+ RtlZeroMemory(Result,sizeof(MEMORY_AREA));
+ Result->Type=NewType;
+ Result->BaseAddress=BaseAddress;
+ Result->Length=Length;
+ Result->Attributes=NewAttributes;
+ Result->LockCount=0;
+
+ MmLockMemoryAreaList(OriginalMemoryArea->BaseAddress,&oldlvl);
+
+// MmDumpMemoryAreas(MmGetRelatedListHead(Process,BaseAddress));
+
+ if (BaseAddress == OriginalMemoryArea->BaseAddress)
+ {
+ OriginalMemoryArea->BaseAddress = BaseAddress + Length;
+ OriginalMemoryArea->Length = OriginalMemoryArea->Length - Length;
+ MmInsertMemoryAreaWithoutLock(Process,Result);
+ MmUnlockMemoryAreaList(OriginalMemoryArea->BaseAddress,&oldlvl);
+
+// MmDumpMemoryAreas(MmGetRelatedListHead(Process,BaseAddress));
+
+ return(Result);
+ }
+ if ((BaseAddress + Length) ==
+ (OriginalMemoryArea->BaseAddress + OriginalMemoryArea->Length))
+ {
+ OriginalMemoryArea->Length = OriginalMemoryArea->Length - Length;
+ MmInsertMemoryAreaWithoutLock(Process,Result);
+ MmUnlockMemoryAreaList(OriginalMemoryArea->BaseAddress,&oldlvl);
+
+// MmDumpMemoryAreas(MmGetRelatedListHead(Process,BaseAddress));
+
+ return(Result);
+ }
+
+ Split = ExAllocatePool(NonPagedPool,sizeof(MEMORY_AREA));
+ RtlCopyMemory(Split,OriginalMemoryArea,sizeof(MEMORY_AREA));
+ Split->BaseAddress = BaseAddress + Length;
+ Split->Length = OriginalMemoryArea->Length - (((ULONG)BaseAddress)
+ + Length);
+
+ OriginalMemoryArea->Length = BaseAddress - OriginalMemoryArea->BaseAddress;
+
+ MmUnlockMemoryAreaList(OriginalMemoryArea->BaseAddress,&oldlvl);
+
+// MmDumpMemoryAreas(MmGetRelatedListHead(Process,BaseAddress));
+
+ return(Split);
+}
+
NTSTATUS MmCreateMemoryArea(KPROCESSOR_MODE Mode,
+ PEPROCESS Process,
ULONG Type,
- PULONG BaseAddress,
+ PVOID* BaseAddress,
ULONG Length,
ULONG Attributes,
MEMORY_AREA** Result)
DPRINT("MmCreateMemoryArea(Mode %x, Type %d, BaseAddress %x,"
"*BaseAddress %x, Length %x, Attributes %x, Result %x)\n",
Mode,Type,BaseAddress,*BaseAddress,Length,Attributes,Result);
-// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000));
- MmLockMemoryAreaList(*BaseAddress,&oldlvl);
-// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000));
+
+
+ if ((*BaseAddress)==0)
+ {
+ MmLockMemoryAreaListByMode(Mode,&oldlvl);
+ }
+ else
+ {
+ MmLockMemoryAreaList(*BaseAddress,&oldlvl);
+ }
+
if ((*BaseAddress)==0)
{
- *BaseAddress = MmFindGapWithoutLock(Mode,PAGE_ROUND_UP(Length)
+ *BaseAddress = MmFindGapWithoutLock(Process,Mode,PAGE_ROUND_UP(Length)
+(PAGESIZE*2));
if ((*BaseAddress)==0)
{
- MmUnlockMemoryAreaList(*BaseAddress,&oldlvl);
+ MmUnlockMemoryAreaListByMode(Mode,&oldlvl);
return(STATUS_UNSUCCESSFUL);
}
(*BaseAddress)=(*BaseAddress)+PAGESIZE;
}
else
{
- if (MmOpenMemoryAreaByRegionWithoutLock(*BaseAddress,Length)!=NULL)
+ (*BaseAddress) = PAGE_ROUND_DOWN((*BaseAddress));
+ if (MmOpenMemoryAreaByRegionWithoutLock(Process,*BaseAddress,
+ Length)!=NULL)
{
MmUnlockMemoryAreaList(*BaseAddress,&oldlvl);
return(STATUS_UNSUCCESSFUL);
}
}
-// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000));
*Result = ExAllocatePool(NonPagedPool,sizeof(MEMORY_AREA));
-// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000));
RtlZeroMemory(*Result,sizeof(MEMORY_AREA));
-// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000));
(*Result)->Type=Type;
(*Result)->BaseAddress=*BaseAddress;
(*Result)->Length=Length;
(*Result)->Attributes=Attributes;
- DPRINT("&SystemAreaList %x ",&SystemAreaList);
- DPRINT("SystemAreaList.Flink %x ",SystemAreaList.Flink);
-// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000));
- MmInsertMemoryAreaWithoutLock(*Result);
-// DbgPrint("(%s:%d) Start1 %x\n",__FILE__,__LINE__,
-// *((unsigned int *)0xc0017000));
+ (*Result)->LockCount=0;
+
+ MmInsertMemoryAreaWithoutLock(Process,*Result);
MmUnlockMemoryAreaList(*BaseAddress,&oldlvl);
-// DbgPrint("Start1 %x\n",*((unsigned int *)0xc0017000));
- DPRINT("SystemAreaList.Flink %x ",SystemAreaList.Flink);
- DPRINT("(*Result)->Entry.Flink %x\n",(*Result)->Entry.Flink);
- MmDumpMemoryAreas();
+
+
return(STATUS_SUCCESS);
}
- /*
+/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/mdl.c
#include <ddk/ntddk.h>
#include <internal/mm.h>
-#include <internal/hal/page.h>
+#include <internal/mmhal.h>
#include <internal/string.h>
#define NDEBUG
* MDL is updated
*/
{
- UNIMPLEMENTED;
+ /* It is harmless to leave this one as a stub */
}
PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode)
PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE);
MmCreateMemoryArea(KernelMode,
+ PsGetCurrentProcess(),
MEMORY_AREA_MDL_MAPPING,
&base,
Mdl->ByteCount + Mdl->ByteOffset,
&Result);
CHECKPOINT;
mdl_pages = (ULONG *)(Mdl + 1);
- for (i=0; i<(PAGE_ROUND_UP(Mdl->ByteCount + Mdl->ByteOffset)/PAGESIZE); i++)
+ for (i=0; i<(PAGE_ROUND_UP(Mdl->ByteCount+Mdl->ByteOffset)/PAGESIZE); i++)
{
DPRINT("Writing %x with physical address %x\n",
base+(i*PAGESIZE),mdl_pages[i]);
- DPRINT("&((PULONG)(Mdl+1))[i] %x\n",&mdl_pages[i]);
- set_page(base+(i*PAGESIZE),PA_READ + PA_SYSTEM,
- mdl_pages[i]);
+ set_page(base+(i*PAGESIZE),PA_READ + PA_SYSTEM,mdl_pages[i]);
}
DPRINT("base %x\n",base);
+ Mdl->MdlFlags = Mdl->MdlFlags | MDL_MAPPED_TO_SYSTEM_VA;
return(base + Mdl->ByteOffset);
}
-VOID MmUnmapLockedPages(PVOID BaseAddress, PMDL MemoryDescriptorList)
+VOID MmUnmapLockedPages(PVOID BaseAddress, PMDL Mdl)
/*
* FUNCTION: Releases a mapping set up by a preceding call to MmMapLockedPages
* ARGUMENTS:
* MemoryDescriptorList = MDL describing the mapped pages
*/
{
- (void)MmFreeMemoryArea(BaseAddress,MemoryDescriptorList->ByteCount,FALSE);
+ (void)MmFreeMemoryArea(PsGetCurrentProcess(),BaseAddress-Mdl->ByteOffset,
+ Mdl->ByteCount,FALSE);
}
VOID MmPrepareMdlForReuse(PMDL Mdl)
DPRINT("MmProbeAndLockPages(Mdl %x)\n",Mdl);
DPRINT("StartVa %x\n",Mdl->StartVa);
- marea = MmOpenMemoryAreaByAddress((ULONG)Mdl->StartVa);
+ marea = MmOpenMemoryAreaByAddress(PsGetCurrentProcess(),
+ (ULONG)Mdl->StartVa);
DPRINT("marea %x\n",marea);
printk("Area is invalid\n");
ExRaiseStatus(STATUS_INVALID_PARAMETER);
}
-
- /*
- * Check the permissions
- */
- #if 0
- switch(Operation)
- {
- case IoReadAccess:
- if (marea->access&PAGE_GUARD || marea->access&PAGE_NOACCESS)
- {
- ExRaiseStatus(STATUS_INVALID_PARAMETER);
- }
- break;
-
- case IoWriteAccess:
- case IoModifyAccess:
- if (marea->access&PAGE_GUARD || marea->access&PAGE_READONLY)
- {
- printk("Invalid area protections\n");
- ExRaiseStatus(STATUS_INVALID_PARAMETER);
- }
- break;
-
- default:
- printk("Invalid operation type at %s:%d in %s\n",__FILE__,__LINE__,
- __FUNCTION__);
- KeBugCheck(UNEXPECTED_KERNEL_MODE_TRAP);
- }
- #endif
-
+
/*
* Lock the memory area
* (We can't allow it to be freed while an I/O operation to it is
for (i=0;i<(PAGE_ROUND_UP(Mdl->ByteOffset+Mdl->ByteCount)/PAGESIZE);i++)
{
- Address = Mdl->StartVa + (i*PAGESIZE);
+ Address = Mdl->StartVa + (i*PAGESIZE);
mdl_pages[i]=MmGetPhysicalAddress(Address).LowPart;
DPRINT("mdl_pages[i] %x\n",mdl_pages[i]);
}
*/
{
int va;
+ Mdl->MdlFlags = Mdl->MdlFlags | MDL_SOURCE_IS_NONPAGED_POOL;
for (va=0; va<Mdl->Size; va++)
{
((PULONG)(Mdl + 1))[va] = MmGetPhysicalAddress(
#include <internal/linkage.h>
#include <ddk/ntddk.h>
+#define NDEBUG
#include <internal/debug.h>
typedef long long int LLI, *PLLI;
{
LLI RC, A1, A2;
+ DPRINT("Addend1.LowPart %d Addend1.HighPart %d\n",
+ Addend1.LowPart,Addend1.HighPart);
+ DPRINT("Addend2.LowPart %d Addend2.HighPart %d\n",
+ Addend2.LowPart,Addend2.HighPart);
+
A1 = LLIFromLI(Addend1);
A2 = LLIFromLI(Addend2);
RC = A1 + A2;
+ DPRINT("RC %d\n",(unsigned int)RC);
+
return LIFromLLI(RC);
}
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/string.h>
+#include <internal/mm.h>
+#include <internal/mmhal.h>
+#include <internal/i386/segment.h>
+#include <internal/ps.h>
//#define NDEBUG
#include <internal/debug.h>
printk("Beginning Thread A\n");
for (;;)
-// for (i=0;i<10;i++)
{
KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL);
printk("AAA ");
KeSetEvent(&event,IO_NO_INCREMENT,FALSE);
- for (i=0;i<10000;i++);
}
}
printk("Beginning Thread B\n");
for(;;)
-// for (i=0;i<10;i++)
{
KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL);
printk("BBB ");
KeSetEvent(&event,IO_NO_INCREMENT,FALSE);
- for (i=0;i<100000;i++);
}
}
for(;;);
}
-void TstGeneralWrite(VOID)
+VOID ExExecuteShell(VOID)
{
+ HANDLE ShellHandle;
+ HANDLE ThreadHandle;
+ PVOID BaseAddress;
+ HANDLE SectionHandle;
OBJECT_ATTRIBUTES attr;
HANDLE hfile;
- char buf[512];
ANSI_STRING afilename;
UNICODE_STRING ufilename;
+ LARGE_INTEGER SectionOffset;
+ ULONG Size;
+ CONTEXT Context;
- DbgPrint("Opening test device\n");
- RtlInitAnsiString(&afilename,"\\Device\\SDisk");
- RtlAnsiStringToUnicodeString(&ufilename,&afilename,TRUE);
- InitializeObjectAttributes(&attr,&ufilename,0,NULL,NULL);
- ZwOpenFile(&hfile,0,&attr,NULL,0,0);
- if (hfile==NULL)
- {
- DbgPrint("Failed to open test device\n");
- return;
- }
- ZwReadFile(hfile,
- NULL,
- NULL,
- NULL,
- NULL,
- buf,
- 512,
- 0,
- 0);
- DbgPrint("buf %s\n",buf);
- }
-
-void TstParallelPortWrite(VOID)
-{
- HANDLE hfile;
-
- DbgPrint("Opening parallel port\n");
-// hfile = CreateFile("\\Device\\Parallel",0,0,0,0,0,0);
- if (hfile==NULL)
- {
- DbgPrint("Failed to open parallel port\n");
- }
- // WriteFile(hfile,"hello world",strlen("hello world"),NULL,NULL);
-}
+ ZwCreateProcess(&ShellHandle,
+ PROCESS_ALL_ACCESS,
+ NULL,
+ SystemProcessHandle,
+ FALSE,
+ NULL,
+ NULL,
+ NULL);
-void TstKeyboardRead(VOID)
-{
- OBJECT_ATTRIBUTES attr;
- HANDLE hfile;
- ANSI_STRING afilename;
- UNICODE_STRING ufilename;
- KEY_EVENT_RECORD key[2];
-
- DbgPrint("Opening keyboard\n");
- RtlInitAnsiString(&afilename,"\\Device\\Keyboard");
+ RtlInitAnsiString(&afilename,"\\??\\C:\\reactos\\system\\shell.bin");
RtlAnsiStringToUnicodeString(&ufilename,&afilename,TRUE);
InitializeObjectAttributes(&attr,&ufilename,0,NULL,NULL);
- ZwOpenFile(&hfile,0,&attr,NULL,0,0);
+ ZwOpenFile(&hfile,FILE_ALL_ACCESS,&attr,NULL,0,0);
if (hfile==NULL)
{
- DbgPrint("Failed to open keyboard\n");
+ DbgPrint("Failed to open file\n");
return;
}
- for(;;)
- {
- ZwReadFile(hfile,
- NULL,
- NULL,
+
+ ZwCreateSection(&SectionHandle,
+ SECTION_ALL_ACCESS,
NULL,
NULL,
- &key[0],
- sizeof(KEY_EVENT_RECORD)*2,
- 0,
- 0);
- DbgPrint("%c",key[0].AsciiChar);
-// DbgPrint("%c",key[1].AsciiChar);
- }
- }
+ PAGE_READWRITE,
+ MEM_COMMIT,
+ hfile);
+
+ BaseAddress = (PVOID)0x10000;
+ SectionOffset.HighPart = 0;
+ SectionOffset.LowPart = 0;
+ Size = 0x6000;
+ ZwMapViewOfSection(SectionHandle,
+ ShellHandle,
+ &BaseAddress,
+ 0,
+ 0x6000,
+ &SectionOffset,
+ &Size,
+ 0,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+
+ memset(&Context,0,sizeof(CONTEXT));
+
+ Context.SegSs = USER_DS;
+ Context.Esp = 0x2000;
+ Context.EFlags = 0x202;
+ Context.SegCs = USER_CS;
+ Context.Eip = 0x10000;
+ Context.SegDs = USER_DS;
+ Context.SegEs = USER_DS;
+ Context.SegFs = USER_DS;
+ Context.SegGs = USER_DS;
+
+ BaseAddress = 0x1000;
+ ZwAllocateVirtualMemory(ShellHandle,
+ &BaseAddress,
+ 0,
+ PAGESIZE,
+ MEM_COMMIT,
+ PAGE_READWRITE);
+
+
+ ZwCreateThread(&ThreadHandle,
+ THREAD_ALL_ACCESS,
+ NULL,
+ ShellHandle,
+ NULL,
+ &Context,
+ NULL,
+ FALSE);
+}
/* IDE TEST STUFF ***********************************************************/
#define ENTRIES_PER_BLOCK (512 / sizeof(ROOT_DIR_ENTRY))
-void TstFileRead(VOID)
-{
- OBJECT_ATTRIBUTES attr;
- HANDLE hfile;
- ANSI_STRING afilename;
- UNICODE_STRING ufilename;
- char ch;
- IO_STATUS_BLOCK IoStatusBlock;
-
- DbgPrint("Opening file\n");
- RtlInitAnsiString(&afilename,"\\??\\C:\\my_other_directory\\..\\"
- "my_valid_directory\\apc.txt");
- RtlAnsiStringToUnicodeString(&ufilename,&afilename,TRUE);
- InitializeObjectAttributes(&attr,&ufilename,0,NULL,NULL);
- ZwOpenFile(&hfile,0,&attr,NULL,0,0);
- if (hfile==NULL)
- {
- DbgPrint("Failed to open file\n");
- return;
- }
- while (1)
- {
-// CHECKPOINT;
- ZwReadFile(hfile,
- NULL,
- NULL,
- NULL,
- &IoStatusBlock,
- &ch,
- 1,
- NULL,
- NULL);
- DbgPrint("%c",ch);
- }
- CHECKPOINT;
- }
-
void TstIDERead(void)
{
BOOLEAN TestFailed;
void TstBegin()
{
+ ExExecuteShell();
// TstFileRead();
// TstGeneralWrite();
// TstThreadSupport();
// TstKeyboardRead();
- TstIDERead();
+// TstIDERead();
// TstKeyboardRead();
// TstShell();
}
#
# Choose various options
#
+ifeq ($(HOST),elf-linux)
+NASM_FORMAT = elf
+PREFIX =
+KERNEL_BFD_TARGET = elf32-i386
+EXE_POSTFIX =
+CP = cp
+endif
+
ifeq ($(HOST),djgpp-linux)
NASM_FORMAT = coff
PREFIX = dos-
KERNEL_BFD_TARGET = coff-i386
EXE_POSTFIX =
CP = cp
+LIBGCC = ./libgcc.a
endif
ifeq ($(HOST),mingw32-linux)
NASM_FORMAT = win32
-PREFIX = i386-mingw32
+PREFIX = /opt/gnu/bin/i386-mingw32-
KERNEL_BFD_TARGET = pe-i386
-EXE_POSTFIX
+EXE_POSTFIX =
CP = cp
+DLLTOOL = $(PREFIX)dlltool --as=$(PREFIX)as
+LIBGCC = /opt/gnu/lib/gcc-lib/i386-mingw32/2.8.0/libgcc.a
endif
ifeq ($(HOST),djgpp-msdos)
KERNEL_BFD_TARGET = coff-go32
EXE_POSTFIX = .exe
CP = copy
+LIBGCC = libgcc.a
endif
ifeq ($(HOST),mingw32-windows)
#
# Create variables for all the compiler tools
#
-DEFINES = -DCHECKED_BUILD -DWIN32_LEAN_AND_MEAN -DDBG
+ifeq ($(WITH_DEBUGGING),yes)
+DEBUGGING_CFLAGS = -g
+else
+DEBUGGING_CFLAGS =
+endif
+
+DEFINES = -DDBG
+
+ifeq ($(WIN32_LEAN_AND_MEAN),yes)
+LEAN_AND_MEAN_DEFINE = -DWIN32_LEAN_AND_MEAN
+else
+LEAN_AND_MEAN_DEFINE =
+endif
+
CC = $(PREFIX)gcc
NATIVE_CC = gcc
-CFLAGS = -O2 -I../../../include -I../../include -I../include -fno-builtin $(DEFINES) -Wall -Wstrict-prototypes
+CFLAGS = -O2 -I../../../include -I../../include -I../include -fno-builtin \
+ $(LEAN_AND_MEAN_DEFINE) $(DEFINES) -Wall -Wstrict-prototypes $(DEBUGGING_CFLAGS)
CXXFLAGS = $(CFLAGS)
-ASM = nasm
-NFLAGS = -i../include/ -f$(NASM_FORMAT)
+NASM_CMD = nasm
+NFLAGS = -i../../include/ -i../include/ -pinternal/asm.inc -f$(NASM_FORMAT) -d$(NASM_FORMAT)
LD = $(PREFIX)ld
NM = $(PREFIX)nm
OBJCOPY = $(PREFIX)objcopy
STRIP = $(PREFIX)strip
AS = $(PREFIX)gcc -c -x assembler-with-cpp
CPP = $(PREFIX)cpp
+AR = $(PREFIX)ar
%.o: %.cc
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.asm
- $(ASM) $(NFLAGS) $< -o $@
+ $(NASM_CMD) $(NFLAGS) $< -o $@
RULES_MAK_INCLUDED = 1