From 35cc27eee07f9c5c7be9cca12fd8788e8d08c4ce Mon Sep 17 00:00:00 2001 From: Rex Jolliff Date: Fri, 28 Aug 1998 23:24:42 +0000 Subject: [PATCH] This commit was generated by cvs2svn to compensate for changes in r21, which included commits to RCS files with non-trunk default branches. svn path=/trunk/; revision=22 --- reactos/include/ddk/defines.h | 6 +- reactos/include/ddk/iotypes.h | 22 ++ reactos/include/ddk/kefuncs.h | 6 + reactos/include/ddk/ketypes.h | 4 +- reactos/include/ddk/mmfuncs.h | 13 +- reactos/include/ddk/mmtypes.h | 23 +- reactos/include/ddk/ntddk.h | 5 +- reactos/include/ddk/obfuncs.h | 3 + reactos/include/ddk/obtypes.h | 16 +- reactos/include/ddk/rtl.h | 2 +- reactos/include/internal/iomgr.h | 2 +- reactos/include/internal/objmgr.h | 6 +- reactos/include/internal/version.h | 4 +- reactos/include/string.h | 2 +- reactos/include/wstring.h | 497 +---------------------------- reactos/ntoskrnl/exports.lst | 2 + reactos/ntoskrnl/hal/x86/page.c | 4 +- reactos/ntoskrnl/hal/x86/printk.c | 35 +- reactos/ntoskrnl/io/create.c | 88 +++-- reactos/ntoskrnl/io/device.c | 21 +- reactos/ntoskrnl/io/iomgr.c | 32 +- reactos/ntoskrnl/io/irp.c | 175 ++++++++-- reactos/ntoskrnl/io/mdl.c | 6 +- reactos/ntoskrnl/io/rw.c | 288 ++++++++--------- reactos/ntoskrnl/io/symlink.c | 33 +- reactos/ntoskrnl/io/timer.c | 4 +- reactos/ntoskrnl/ke/apc.c | 39 +++ reactos/ntoskrnl/ke/bug.c | 2 +- reactos/ntoskrnl/ke/exports.c | 4 + reactos/ntoskrnl/makefile_rex | 17 +- reactos/ntoskrnl/mm/mdl.c | 116 +++++-- reactos/ntoskrnl/mm/pool.c | 24 +- reactos/ntoskrnl/mm/virtual.c | 55 +++- reactos/ntoskrnl/ob/namespc.c | 217 ++++++------- reactos/ntoskrnl/ob/object.c | 103 ++++-- reactos/ntoskrnl/ps/thread.c | 1 + reactos/ntoskrnl/rtl/unicode.c | 235 ++++++-------- reactos/ntoskrnl/tst/test.c | 86 +++-- 38 files changed, 1080 insertions(+), 1118 deletions(-) diff --git a/reactos/include/ddk/defines.h b/reactos/include/ddk/defines.h index 413e5af3240..861c0682cdb 100644 --- a/reactos/include/ddk/defines.h +++ b/reactos/include/ddk/defines.h @@ -39,8 +39,8 @@ enum */ enum { - STATUS_SUCCESS, - STATUS_INSUFFICIENT_RESOURCES, + STATUS_SUCCESS = 0x0, + STATUS_INSUFFICIENT_RESOURCES = 0x80000000, STATUS_OBJECT_NAME_EXISTS, STATUS_OBJECT_NAME_COLLISION, // STATUS_DATATYPE_MISALIGNMENT, @@ -179,7 +179,9 @@ enum STATUS_NO_MEDIA_IN_DRIVE, STATUS_VERIFY_REQUIRED, STATUS_UNRECOGNIZED_MEDIA, + STATUS_UNRECOGNIZED_VOLUME, // STATUS_WRONG_VOLUME, + STATUS_FS_DRIVER_REQUIRED, }; /* diff --git a/reactos/include/ddk/iotypes.h b/reactos/include/ddk/iotypes.h index fb863d3e113..8463ca11572 100644 --- a/reactos/include/ddk/iotypes.h +++ b/reactos/include/ddk/iotypes.h @@ -63,6 +63,7 @@ typedef VOID (*PIO_APC_ROUTINE) (PVOID ApcContext, /* * PURPOSE: Special timer associated with each device + * NOTES: This is a guess */ typedef struct _IO_TIMER { @@ -192,6 +193,27 @@ typedef struct _IO_COMPLETION_CONTEXT ULONG Key; } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT; +#define FO_FILE_OPEN 0x00000001 +#define FO_SYNCHRONOUS_IO 0x00000002 +#define FO_ALERTABLE_IO 0x00000004 +#define FO_NO_INTERMEDIATE_BUFFERING 0x00000008 +#define FO_WRITE_THROUGH 0x00000010 +#define FO_SEQUENTIAL_ONLY 0x00000020 +#define FO_CACHE_SUPPORTED 0x00000040 +#define FO_NAMED_PIPE 0x00000080 +#define FO_STREAM_FILE 0x00000100 +#define FO_MAILSLOT 0x00000200 +#define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400 +#define FO_DIRECT_DEVICE_OPEN 0x00000800 +#define FO_FILE_MODIFIED 0x00001000 +#define FO_FILE_SIZE_CHANGED 0x00002000 +#define FO_CLEANUP_COMPLETE 0x00004000 +#define FO_TEMPORARY_FILE 0x00008000 +#define FO_DELETE_ON_CLOSE 0x00010000 +#define FO_OPENED_CASE_SENSITIVE 0x00020000 +#define FO_HANDLE_CREATED 0x00040000 +#define FO_FILE_FAST_IO_READ 0x00080000 + typedef struct _FILE_OBJECT { CSHORT Type; diff --git a/reactos/include/ddk/kefuncs.h b/reactos/include/ddk/kefuncs.h index a15a0f8f245..c73c1b1f42c 100644 --- a/reactos/include/ddk/kefuncs.h +++ b/reactos/include/ddk/kefuncs.h @@ -3,6 +3,12 @@ /* KERNEL FUNCTIONS ********************************************************/ +VOID KeDrainApcQueue(VOID); +VOID KeInitializeApc(PKAPC Apc, PKNORMAL_ROUTINE NormalRoutine, + PVOID NormalContext, + PKTHREAD TargetThread); +BOOLEAN KeInsertQueueApc(PKAPC Apc); + /* * FUNCTION: Acquires a spinlock so the caller can synchronize access to * data diff --git a/reactos/include/ddk/ketypes.h b/reactos/include/ddk/ketypes.h index 23b1744a086..3ccdcbbd9b4 100644 --- a/reactos/include/ddk/ketypes.h +++ b/reactos/include/ddk/ketypes.h @@ -34,7 +34,7 @@ typedef struct USHORT WaitType; } KWAIT_BLOCK, *PKWAIT_BLOCK; - +#define _KTHREAD _ETHREAD typedef struct _ETHREAD /* @@ -47,7 +47,7 @@ typedef struct _ETHREAD /* * PURPOSE: Head of the queue of apcs */ - LIST_ENTRY apc_queue_head; + LIST_ENTRY ApcQueueHead; /* * PURPOSE: Entry in the linked list of threads diff --git a/reactos/include/ddk/mmfuncs.h b/reactos/include/ddk/mmfuncs.h index 248d1e9df27..dac198a8207 100644 --- a/reactos/include/ddk/mmfuncs.h +++ b/reactos/include/ddk/mmfuncs.h @@ -1,5 +1,7 @@ /* MEMORY MANAGMENT ******************************************************/ +#include + /* * FUNCTION: Determines if the given virtual address is page aligned */ @@ -27,7 +29,16 @@ * Size = Size of range * RETURNS: The number of pages */ -#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va, Size) +extern inline unsigned int ADDRESS_AND_SIZE_TO_SPAN_PAGES(PVOID Va, + ULONG Size) +{ + ULONG HighestAddr; + ULONG LowestAddr; + + HighestAddr = PAGE_ROUND_UP(Size + ((ULONG)Va)); + LowestAddr = PAGE_ROUND_DOWN((ULONG)Va); + return((HighestAddr - LowestAddr) / PAGESIZE); +} /* * FUNCTION: Returns FALSE is the pointer is NULL, TRUE otherwise diff --git a/reactos/include/ddk/mmtypes.h b/reactos/include/ddk/mmtypes.h index 351d71aeac8..b0012913a3c 100644 --- a/reactos/include/ddk/mmtypes.h +++ b/reactos/include/ddk/mmtypes.h @@ -1,4 +1,25 @@ - typedef struct _MDL + +enum +{ + MDL_MAPPED_TO_SYSTEM_VA = 0x1, + MDL_PAGES_LOCKED = 0x2, + MDL_SOURCE_IS_NONPAGED_POOL = 0x4, + MDL_ALLOCATED_FIXED_SIZE = 0x8, + MDL_PARTIAL = 0x10, + MDL_PARTIAL_HAS_BEEN_MAPPED = 0x20, + MDL_IO_PAGE_READ = 0x40, + MDL_WRITE_OPERATION = 0x80, + MDL_PARENT_MAPPED_SYSTEM_VA = 0x100, + MDL_LOCK_HELD = 0x200, + MDL_SCATTER_GATHER_VA = 0x400, + MDL_IO_SPACE = 0x800, + MDL_NETWORK_HEADER = 0x1000, + MDL_MAPPING_CAN_FAIL = 0x2000, + MDL_ALLOCATED_MUST_SUCCEED = 0x4000, + MDL_64_BIT_VA = 0x8000, +}; + +typedef struct _MDL /* * PURPOSE: Describes a user buffer passed to a system API */ diff --git a/reactos/include/ddk/ntddk.h b/reactos/include/ddk/ntddk.h index bfb5255d9dd..0f52a2c50a0 100644 --- a/reactos/include/ddk/ntddk.h +++ b/reactos/include/ddk/ntddk.h @@ -64,9 +64,8 @@ enum { #include #include #include - -ULONG DbgPrint(PCH Format,...); - +#include + #ifdef __cplusplus }; #endif diff --git a/reactos/include/ddk/obfuncs.h b/reactos/include/ddk/obfuncs.h index 76cb1c2db71..6aa30d52510 100644 --- a/reactos/include/ddk/obfuncs.h +++ b/reactos/include/ddk/obfuncs.h @@ -42,3 +42,6 @@ NTSTATUS ObReferenceObjectByPointer(PVOID Object, ACCESS_MASK DesiredAccess, POBJECT_TYPE ObjectType, KPROCESSOR_MODE AccessMode); + +NTSTATUS ObOpenObjectByName(POBJECT_ATTRIBUTES ObjectAttributes, + PVOID* Object); diff --git a/reactos/include/ddk/obtypes.h b/reactos/include/ddk/obtypes.h index 12c8c1eb6e2..9678c3114b5 100644 --- a/reactos/include/ddk/obtypes.h +++ b/reactos/include/ddk/obtypes.h @@ -133,17 +133,9 @@ typedef struct _OBJECT typedef struct _OBJECT_ATTRIBUTES { ULONG Length; - - /* - * PURPOSE: Attributes of the object - */ + HANDLE RootDirectory; + PUNICODE_STRING ObjectName; ULONG Attributes; - - SECURITY_DESCRIPTOR SecurityDescriptor; -// SecurityQualityOfService - - struct _DIRECTORY_OBJECT* parent; - UNICODE_STRING name; - UNICODE_STRING path; - + PVOID SecurityDescriptor; + PVOID SecurityQualityOfService; } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES; diff --git a/reactos/include/ddk/rtl.h b/reactos/include/ddk/rtl.h index d7e708f33c6..c4e7df7435a 100644 --- a/reactos/include/ddk/rtl.h +++ b/reactos/include/ddk/rtl.h @@ -226,7 +226,7 @@ VOID RtlStoreUshort(PUSHORT Address, USHORT Value); BOOLEAN RtlTimeFieldsToTime(PTIME_FIELDS TimeFields, PLARGE_INTEGER Time); VOID RtlTimeToTimeFields(PLARGE_INTEGER Time, PTIME_FIELDS TimeFields); PWSTR RtlStrtok(PUNICODE_STRING _string, PWSTR _sep, PWSTR* temp); - +VOID RtlGetCallersAddress(PVOID* CallersAddress); typedef struct { ULONG Length; diff --git a/reactos/include/internal/iomgr.h b/reactos/include/internal/iomgr.h index 3068ce2bcb1..a7766704da0 100644 --- a/reactos/include/internal/iomgr.h +++ b/reactos/include/internal/iomgr.h @@ -22,6 +22,6 @@ NTSTATUS InitalizeLoadedDriver(PDRIVER_INITIALIZE entry); VOID IoInitCancelHandling(VOID); - +VOID IoInitSymbolicLinkImplementation(VOID); #endif diff --git a/reactos/include/internal/objmgr.h b/reactos/include/internal/objmgr.h index 5614812bb13..0c621aea0da 100644 --- a/reactos/include/internal/objmgr.h +++ b/reactos/include/internal/objmgr.h @@ -40,6 +40,7 @@ enum OBJTYP_SYMLNK, OBJTYP_DEVICE, OBJTYP_THREAD, + OBJTYP_FILE, OBJTYP_MAX, }; @@ -47,7 +48,7 @@ BOOL ObAddObjectToNameSpace(PUNICODE_STRING path, POBJECT_HEADER Object); VOID ObRegisterType(CSHORT id, OBJECT_TYPE* type); -VOID ObInitializeObjectHeader(CSHORT id, PUNICODE_STRING name, +VOID ObInitializeObjectHeader(CSHORT id, PWSTR name, POBJECT_HEADER obj); /* @@ -58,9 +59,8 @@ VOID ObInitializeObjectHeader(CSHORT id, PUNICODE_STRING name, */ ULONG ObSizeOf(CSHORT Type); HANDLE ObAddHandle(PVOID obj); - +PVOID ObLookupObject(HANDLE rooth, PWSTR _string); PVOID ObGetObjectByHandle(HANDLE h); -PVOID ObLookupObject(PDIRECTORY_OBJECT root, PUNICODE_STRING _string); PVOID ObGenericCreateObject(PHANDLE Handle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, diff --git a/reactos/include/internal/version.h b/reactos/include/internal/version.h index 3ae250cec74..a7510460baf 100644 --- a/reactos/include/internal/version.h +++ b/reactos/include/internal/version.h @@ -9,9 +9,9 @@ #ifndef __VERSION_H #define __VERSION_H -#define KERNEL_VERSION "0.0.8" +#define KERNEL_VERSION "0.0.9" #define KERNEL_MAJOR_VERSION 0 #define KERNEL_MINOR_VERSION 0 -#define KERNEL_PATCH_LEVEL 8 +#define KERNEL_PATCH_LEVEL 9 #endif diff --git a/reactos/include/string.h b/reactos/include/string.h index 3ed9470c43a..0d9c811dbc5 100644 --- a/reactos/include/string.h +++ b/reactos/include/string.h @@ -38,7 +38,7 @@ extern __kernel_size_t strnlen(const char *,__kernel_size_t); extern __kernel_size_t strspn(const char *,const char *); extern int strcmp(const char *,const char *); extern int strncmp(const char *,const char *,__kernel_size_t); -extern int stricmp(const char* cs,const char * ct) +extern int stricmp(const char* cs,const char * ct); extern int strnicmp(const char* cs,const char * ct, size_t count); extern void * memset(void *,int,__kernel_size_t); diff --git a/reactos/include/wstring.h b/reactos/include/wstring.h index bf4912ad374..578ed7851e2 100644 --- a/reactos/include/wstring.h +++ b/reactos/include/wstring.h @@ -27,8 +27,8 @@ extern wchar_t * wcscat(wchar_t *, const wchar_t *); extern wchar_t * wcsncat(wchar_t *, const wchar_t *, __kernel_size_t); extern int wcscmp(const wchar_t *,const wchar_t *); extern int wcsncmp(const wchar_t *,const wchar_t *,__kernel_size_t); -extern wchar_t * wcschr(const wchar_t *,int); -extern wchar_t * wcsrchr(const wchar_t *,int); +wchar_t* wcschr(wchar_t* str, wchar_t ch); +extern wchar_t * wcsrchr(const wchar_t *,wchar_t); extern wchar_t * wcspbrk(const wchar_t *,const wchar_t *); extern wchar_t * wcstok(wchar_t *,const wchar_t *); extern wchar_t * wcsstr(const wchar_t *,const wchar_t *); @@ -36,499 +36,6 @@ extern size_t wcsnlen(const wchar_t * s, size_t count); extern int wcsicmp(const wchar_t* cs,const wchar_t * ct); extern int wcsnicmp(const wchar_t* cs,const wchar_t * ct, size_t count); - -/* - * Include machine specific inline routines - */ -//#ifndef _I386_STRING_H_ -//#define _I386_STRING_H_ - -/* - * On a 486 or Pentium, we are better off not using the - * byte string operations. But on a 386 or a PPro the - * byte string ops are faster than doing it by hand - * (MUCH faster on a Pentium). - * - * Also, the byte strings actually work correctly. Forget - * the i486 routines for now as they may be broken.. - */ - -#if FIXED_486_STRING && (CPU == 486 || CPU == 586) - #include -#else - -/* - * This string-include defines all string functions as inline - * functions. Use gcc. It also assumes ds=es=data space, this should be - * normal. Most of the string-functions are rather heavily hand-optimized, - * see especially wcstok,wcsstr,wcs[c]spn. They should work, but are not - * very easy to understand. Everything is done entirely within the register - * set, making the functions fast and clean. String instructions have been - * used through-out, making for "slightly" unclear code :-) - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - - - -#define __HAVE_ARCH_WCSCPY -extern inline wchar_t * wcscpy(wchar_t * dest,const wchar_t *src) -{ -__asm__ __volatile__( - "cld\n" - "1:\tlodsw\n\t" - "stosw\n\t" - "testw %%eax,%%eax\n\t" - "jne 1b" - : /* no output */ - :"S" (src),"D" (dest):"esi","edi","eax","memory"); -return dest; -} - -#define __HAVE_ARCH_WCSNCPY -inline wchar_t * wcsncpy(wchar_t * dest,const wchar_t *src,size_t count) -{ -__asm__ __volatile__( - "cld\n" - "1:\tdecl %2\n\t" - "js 2f\n\t" - "lodsw\n\t" - "stosw\n\t" - "testw %%eax,%%eax\n\t" - "jne 1b\n\t" - "rep\n\t" - "stosw\n" - "2:" - : /* no output */ - :"S" (src),"D" (dest),"c" (count):"esi","edi","eax","ecx","memory"); -return dest; -} - -#define __HAVE_ARCH_WCSCAT -inline wchar_t * wcscat(wchar_t * dest,const wchar_t * src) -{ -__asm__ __volatile__( - "cld\n\t" - "repnz\n\t" - "scasw\n\t" - "decl %1\n" - "decl %1\n\t" - "1:\tlodsw\n\t" - "stosw\n\t" - "testw %%eax,%%eax\n\t" - "jne 1b" - : /* no output */ - :"S" (src),"D" (dest),"a" (0),"c" (0xffffffff):"esi","edi","eax","ecx"); -return dest; -} - -#define __HAVE_ARCH_WCSNCAT -inline wchar_t * wcsncat(wchar_t * dest,const wchar_t * src,size_t count) -{ -__asm__ __volatile__( - "cld\n\t" - "repnz\n\t" - "scasw\n\t" - "decl %1\n\t" - "movl %4,%3\n" - "decl %1\n\t" - "1:\tdecl %3\n\t" - "js 2f\n\t" - "lodsw\n\t" - "stosw\n\t" - "testw %%eax,%%eax\n\t" - "jne 1b\n" - "2:\txorl %2,%2\n\t" - "stosw" - : /* no output */ - :"S" (src),"D" (dest),"a" (0),"c" (0xffffffff),"g" (count) - :"esi","edi","eax","ecx","memory"); -return dest; -} - -#define __HAVE_ARCH_WCSCMP -inline int wcscmp(const wchar_t* cs,const wchar_t * ct) -{ -register int __res; -__asm__ __volatile__( - "cld\n" - "1:\tlodsw\n\t" - "scasw\n\t" - "jne 2f\n\t" - "testw %%eax,%%eax\n\t" - "jne 1b\n\t" - "xorl %%eax,%%eax\n\t" - "jmp 3f\n" - "2:\tsbbl %%eax,%%eax\n\t" - "orw $1,%%eax\n" - "3:" - :"=a" (__res):"S" (cs),"D" (ct):"esi","edi"); -return __res; -} - -#define __HAVE_ARCH_WCSNCMP -inline int wcsncmp(const wchar_t * cs,const wchar_t * ct,size_t count) -{ -register int __res; -__asm__ __volatile__( - "cld\n" - "1:\tdecl %3\n\t" - "js 2f\n\t" - "lodsw\n\t" - "scasw\n\t" - "jne 3f\n\t" - "testw %%eax,%%eax\n\t" - "jne 1b\n" - "2:\txorl %%eax,%%eax\n\t" - "jmp 4f\n" - "3:\tsbbl %%eax,%%eax\n\t" - "orw $1,%%eax\n" - "4:" - :"=a" (__res):"S" (cs),"D" (ct),"c" (count):"esi","edi","ecx"); -return __res; -} - -#define __HAVE_ARCH_WCSCHR -inline wchar_t * wcschr(const wchar_t * s, int c) -{ -register wchar_t * __res; -__asm__ __volatile__( - "cld\n\t" - "movw %%eax,%%edx\n" - "1:\tlodsw\n\t" - "cmpw %%edx,%%eax\n\t" - "je 2f\n\t" - "testw %%eax,%%eax\n\t" - "jne 1b\n\t" - "movl $1,%1\n" - "2:\tmovl %1,%0\n\t" - "decl %0\n\t" - "decl %0\n\t" - :"=a" (__res):"S" (s),"0" (c):"esi"); -return __res; -} - -#define __HAVE_ARCH_WCSRCHR -inline wchar_t * wcsrchr(const wchar_t * s, int c) -{ -register wchar_t * __res; -__asm__ __volatile__( - "cld\n\t" - "movw %%eax,%%edx\n" - "1:\tlodsw\n\t" - "cmpw %%edx,%%eax\n\t" - "jne 2f\n\t" - "leal -2(%%esi),%0\n" - "2:\ttestw %%eax,%%eax\n\t" - "jne 1b" - :"=d" (__res):"0" (0),"S" (s),"a" (c):"eax","esi"); -return __res; -} - -#define __HAVE_ARCH_WCSSPN -inline size_t wcsspn(const wchar_t * cs, const wchar_t * ct) -{ -register wchar_t * __res; -__asm__ __volatile__( - "cld\n\t" - "movl %4,%%edi\n\t" - "repne\n\t" - "scasw\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "movl %%ecx,%%edx\n" - "1:\tlodsw\n\t" - "testw %%eax,%%eax\n\t" - "je 2f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasb\n\t" - "je 1b\n" - "2:\tdecl %0" - :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - :"eax","ecx","edx","edi"); -return __res-cs; -} - -#define __HAVE_ARCH_WCSCSPN -inline size_t wcscspn(const wchar_t * cs, const wchar_t * ct) -{ -register wchar_t * __res; -__asm__ __volatile__( - "cld\n\t" - "movl %4,%%edi\n\t" - "repne\n\t" - "scasw\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "movl %%ecx,%%edx\n" - "1:\tlodsw\n\t" - "testw %%eax,%%eax\n\t" - "je 2f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasw\n\t" - "jne 1b\n" - "2:\tdecl %0" - :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - :"eax","ecx","edx","edi"); -return __res-cs; -} - -#define __HAVE_ARCH_STRPBRK -inline wchar_t * wcspbrk(const wchar_t * cs,const wchar_t * ct) -{ -register wchar_t * __res; -__asm__ __volatile__( - "cld\n\t" - "movl %4,%%edi\n\t" - "repne\n\t" - "scasw\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "movl %%ecx,%%edx\n" - "1:\tlodsw\n\t" - "testw %%eax,%%eax\n\t" - "je 2f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasw\n\t" - "jne 1b\n\t" - "decl %0\n\t" - "jmp 3f\n" - "2:\txorl %0,%0\n" - "3:" - :"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct) - :"eax","ecx","edx","edi"); -return __res; -} - -#define __HAVE_ARCH_WCSSTR -inline wchar_t * wcsstr(const wchar_t * cs,const wchar_t * ct) -{ -register wchar_t * __res; -__asm__ __volatile__( - "cld\n\t" \ - "movl %4,%%edi\n\t" - "repne\n\t" - "scasw\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ - "movl %%ecx,%%edx\n" - "1:\tmovl %4,%%edi\n\t" - "movl %%esi,%%eax\n\t" - "movl %%edx,%%ecx\n\t" - "repe\n\t" - "cmpsw\n\t" - "je 2f\n\t" /* also works for empty string, see above */ - "xchgl %%eax,%%esi\n\t" - "incl %%esi\n\t" - "cmpw $0,-1(%%eax)\n\t" - "jne 1b\n\t" - "xorl %%eax,%%eax\n\t" - "2:" - :"=a" (__res):"0" (0),"c" (0xffffffff),"S" (cs),"g" (ct) - :"ecx","edx","edi","esi"); -return __res; -} - - -#define __HAVE_ARCH_WCSLEN -inline size_t wcslen(const wchar_t * s) -{ -register int __res; -__asm__ __volatile__( - "cld\n\t" - "repne\n\t" - "scasw\n\t" - "notl %0\n\t" - "decl %0" - :"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"edi"); -return __res; -} - - - -#define __HAVE_ARCH_WCSTOK - - -inline wchar_t * wcstok(wchar_t * s,const wchar_t * ct) -{ - -register wchar_t * __res; -__asm__ __volatile__( - "testl %1,%1\n\t" - "jne 1f\n\t" - "testl %0,%0\n\t" - "je 8f\n\t" - "movl %0,%1\n" - "1:\txorl %0,%0\n\t" - "movl $-1,%%ecx\n\t" - "xorl %%eax,%%eax\n\t" - "cld\n\t" - "movl %4,%%edi\n\t" - "repnz\n\t" - "scasw\n\t" - "notl %%ecx\n\t" - "decl %%ecx\n\t" - "decl %%ecx\n\t" - "je 7f\n\t" /* empty delimiter-string */ - "movl %%ecx,%%edx\n" - "2:\tlodsw\n\t" - "testw %%eax,%%eax\n\t" - "je 7f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasw\n\t" - "je 2b\n\t" - "decl %1\n\t" - "decl %1\n\t" - "cmpw $0,(%1)\n\t" - "je 7f\n\t" - "movl %1,%0\n" - "3:\tlodsw\n\t" - "testw %%eax,%%eax\n\t" - "je 5f\n\t" - "movl %4,%%edi\n\t" - "movl %%edx,%%ecx\n\t" - "repne\n\t" - "scasw\n\t" - "jne 3b\n\t" - "decl %1\n\t" - "decl %1\n\t" - "decl %1\n\t" - "decl %1\n\t" - "cmpw $0,(%1)\n\t" - "je 5f\n\t" - "movw $0,(%1)\n\t" - "incl %1\n\t" - "incl %1\n\t" - "jmp 6f\n" - "5:\txorl %1,%1\n" - "6:\tcmpw $0,(%0)\n\t" - "jne 7f\n\t" - "xorl %0,%0\n" - "7:\ttestl %0,%0\n\t" - "jne 8f\n\t" - "movl %0,%1\n" - "8:" - :"=b" (__res),"=S" (___wcstok) - :"0" (___wcstok),"1" (s),"g" (ct) - :"eax","ecx","edx","edi","memory"); - -return __res; -} - - -#define __HAVE_ARCH_WCSNNLEN -inline size_t wcsnlen(const wchar_t * s, size_t count) -{ -register int __res; -__asm__ __volatile__( - "movl %1,%0\n\t" - "jmp 2f\n" - "1:\tcmpw $0,(%0)\n\t" - "je 3f\n\t" - "incl %0\n" - "2:\tdecl %2\n\t" - "cmpl $-1,%2\n\t" - "jne 1b\n" - "3:\tsubl %1,%0" - :"=a" (__res) - :"c" (s),"d" (count) - :"edx"); -return __res; -} - - - -#define __HAVE_ARCH_WCSICMP -inline int wcsicmp(const wchar_t* cs,const wchar_t * ct) -{ -register int __res; - - -__asm__ __volatile__( - "cld\n" - "1:\tmovw (%%esi), %%eax\n\t" - "movw (%%edi), %%edx \n\t" - "cmpw $0x5A, %%eax\n\t" - "ja 2f\t\n" - "cmpw $0x40, %%eax\t\n" - "jbe 2f\t\n" - "addw $0x20, %%eax\t\n" - "2:\t cmpw $0x5A, %%edx\t\n" - "ja 3f\t\n" - "cmpw $0x40, %%edx\t\n" - "jbe 3f\t\n" - "addw $0x20, %%edx\t\n" - "3:\t inc %%esi\t\n" - "inc %%esi\t\n" - "inc %%edi\t\n" - "inc %%edi\t\n" - "cmpw %%eax, %%edx\t\n" - "jne 4f\n\t" - "cmpw $00, %%eax\n\t" - "jne 1b\n\t" - "xorl %%eax,%%eax\n\t" - "jmp 5f\n" - "4:\tsbbl %%eax,%%eax\n\t" - "orw $1,%%eax\n" - "5:" - :"=a" (__res):"S" (cs),"D" (ct):"esi","edi"); - -return __res; -} - - -#define __HAVE_ARCH_WCSNICMP -inline int wcsnicmp(const wchar_t* cs,const wchar_t * ct, size_t count) -{ -register int __res; - - -__asm__ __volatile__( - "cld\n" - "1:\t decl %3\n\t" - "js 6f\n\t" - "movw (%%esi), %%eax\n\t" - "movw (%%edi), %%edx \n\t" - "cmpw $0x5A, %%eax\n\t" - "ja 2f\t\n" - "cmpw $0x40, %%eax\t\n" - "jbe 2f\t\n" - "addw $0x20, %%eax\t\n" - "2:\t cmpw $0x5A, %%edx\t\n" - "ja 3f\t\n" - "cmpw $0x40, %%edx\t\n" - "jbe 3f\t\n" - "addw $0x20, %%edx\t\n" - "3:\t inc %%esi\t\n" - "inc %%esi\t\n" - "inc %%edi\t\n" - "inc %%edi\t\n" - "cmpw %%eax, %%edx\t\n" - "jne 4f\n\t" - "cmpw $00, %%eax\n\t" - "jne 1b\n\t" - "6:xorl %%eax,%%eax\n\t" - "jmp 5f\n" - "4:\tsbbl %%eax,%%eax\n\t" - "orw $1,%%eax\n" - "5:" - :"=a" (__res):"S" (cs),"D" (ct), "c" (count):"esi","edi", "ecx"); - - -return __res; -} - -//#endif -#endif - #ifdef __cplusplus } #endif diff --git a/reactos/ntoskrnl/exports.lst b/reactos/ntoskrnl/exports.lst index c078ea0f774..ca14ad90464 100644 --- a/reactos/ntoskrnl/exports.lst +++ b/reactos/ntoskrnl/exports.lst @@ -7,6 +7,8 @@ # # # +free_page +get_dma_page DbgPrint printk ExAcquireFastMutex diff --git a/reactos/ntoskrnl/hal/x86/page.c b/reactos/ntoskrnl/hal/x86/page.c index e74f0465e13..9ff4805aaca 100644 --- a/reactos/ntoskrnl/hal/x86/page.c +++ b/reactos/ntoskrnl/hal/x86/page.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top directory - * PROJECT: ReactOS kernel v0.0.2 - * FILE: hal/page.cc + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/hal/x86/page.c * PURPOSE: low level memory managment manipulation * PROGRAMER: David Welch * UPDATE HISTORY: diff --git a/reactos/ntoskrnl/hal/x86/printk.c b/reactos/ntoskrnl/hal/x86/printk.c index 6815f0f0362..70a1964fe31 100644 --- a/reactos/ntoskrnl/hal/x86/printk.c +++ b/reactos/ntoskrnl/hal/x86/printk.c @@ -232,7 +232,40 @@ int bad_user_access_length(void) ULONG DbgPrint(PCH Format, ...) { - UNIMPLEMENTED; + char buffer[256]; + char* str=buffer; + va_list ap; + unsigned int eflags; + + /* + * Because this is used by alomost every subsystem including irqs it + * must be atomic. The following code sequence disables interrupts after + * saving the previous state of the interrupt flag + */ + __asm__("pushf\n\tpop %0\n\tcli\n\t" + : "=m" (eflags) + : /* */); + + /* + * Process the format string into a fixed length buffer using the + * standard C RTL function + */ + va_start(ap,Format); + vsprintf(buffer,Format,ap); + va_end(ap); + + while ((*str)!=0) + { + putchar(*str); + str++; + } + + /* + * Restore the interrupt flag + */ + __asm__("push %0\n\tpopf\n\t" + : + : "m" (eflags)); } void InitConsole(boot_param* bp) diff --git a/reactos/ntoskrnl/io/create.c b/reactos/ntoskrnl/io/create.c index a2436afcf64..830e9cb2589 100644 --- a/reactos/ntoskrnl/io/create.c +++ b/reactos/ntoskrnl/io/create.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/iomgr/create.cc + * FILE: ntoskrnl/io/create.c * PURPOSE: Handling file create/open apis * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -15,6 +15,7 @@ #include #include #include +#include #define NDEBUG #include @@ -43,59 +44,54 @@ NTSTATUS ZwOpenFile(PHANDLE FileHandle, ULONG ShareAccess, ULONG OpenOptions) { - UNIMPLEMENTED; -} - -HANDLE STDCALL CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - HANDLE hTemplateFile) -{ - PDEVICE_OBJECT DeviceObject; + PVOID Object; + NTSTATUS Status; PIRP Irp; - HANDLE hfile; - UNICODE_STRING filename; - ANSI_STRING afilename; + KEVENT Event; + PDEVICE_OBJECT DeviceObject; + PFILE_OBJECT FileObject; + PIO_STACK_LOCATION StackLoc; - RtlInitAnsiString(&afilename,lpFileName); - RtlAnsiStringToUnicodeString(&filename,&afilename,TRUE); - DeviceObject = ObLookupObject(NULL,&filename); - DPRINT("Sending IRP for IRP_MJ_CREATE to %x\n",DeviceObject); - if (DeviceObject==NULL) - { - DPRINT("(%s:%d) Object not found\n",__FILE__,__LINE__); - return(NULL); - } - - hfile = ObAddHandle(DeviceObject); + assert_irql(PASSIVE_LEVEL); - /* - * Tell the device we are openining it - */ - Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE); - if (Irp==NULL) - { - return(NULL); + *FileHandle=0; + + Status = ObOpenObjectByName(ObjectAttributes,&Object); + DPRINT("Object %x Status %x\n",Object,Status); + if (!NT_SUCCESS(Status)) + { + return(Status); } - DPRINT("Preparing IRP\n"); + DeviceObject = (PDEVICE_OBJECT)Object; + + FileObject = ObGenericCreateObject(FileHandle,0,NULL,OBJTYP_FILE); + DPRINT("FileObject %x DeviceObject %x\n",FileObject,DeviceObject); + memset(FileObject,0,sizeof(FILE_OBJECT)); + FileObject->DeviceObject=DeviceObject; + FileObject->Flags = FileObject->Flags | FO_DIRECT_DEVICE_OPEN; - /* - * Set up the stack location - */ - Irp->Stack[Irp->CurrentLocation].MajorFunction = IRP_MJ_CREATE; - Irp->Stack[Irp->CurrentLocation].MinorFunction = 0; - Irp->Stack[Irp->CurrentLocation].Flags = 0; - Irp->Stack[Irp->CurrentLocation].Control = 0; - Irp->Stack[Irp->CurrentLocation].DeviceObject = DeviceObject; -// Irp->Stack[Irp->StackPtr].FileObject = &files[hfile]; + KeInitializeEvent(&Event,NotificationEvent,FALSE); - DPRINT("Sending IRP\n"); + Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); + if (Irp==NULL) + { + return(STATUS_UNSUCCESSFUL); + } + + StackLoc = IoGetNextIrpStackLocation(Irp); + DPRINT("StackLoc %x\n",StackLoc); + StackLoc->MajorFunction = IRP_MJ_CREATE; + StackLoc->MinorFunction = 0; + StackLoc->Flags = 0; + StackLoc->Control = 0; + StackLoc->DeviceObject = DeviceObject; + StackLoc->FileObject=FileObject; + DPRINT("DeviceObject %x\n",DeviceObject); + DPRINT("DeviceObject->DriverObject %x\n",DeviceObject->DriverObject); IoCallDriver(DeviceObject,Irp); - DPRINT("Returning %x\n",hfile); - return(hfile); + return(STATUS_SUCCESS); } + diff --git a/reactos/ntoskrnl/io/device.c b/reactos/ntoskrnl/io/device.c index 18c988dd3db..7830583ed7e 100644 --- a/reactos/ntoskrnl/io/device.c +++ b/reactos/ntoskrnl/io/device.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/iomgr/device.cc + * FILE: ntoskrnl/io/device.c * PURPOSE: Manage devices * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -22,6 +22,16 @@ /* FUNCTIONS ***************************************************************/ +NTSTATUS ZwLoadDriver(PUNICODE_STRING DriverServiceName) +/* + * FUNCTION: Loads a driver + * ARGUMENTS: + * DriverServiceName = Name of the service to load (registry key) + * RETURNS: Status + */ +{ +} + NTSTATUS IoAttachDeviceByPointer(PDEVICE_OBJECT SourceDevice, PDEVICE_OBJECT TargetDevice) { @@ -143,7 +153,10 @@ NTSTATUS IoCreateDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT dev; OBJECT_ATTRIBUTES dev_attr; HANDLE devh; - + + DPRINT("IoCreateDevice(DriverObject %x, DeviceName %w)\n",DriverObject, + DeviceName->Buffer); + InitializeObjectAttributes(&dev_attr,DeviceName,0,NULL,NULL); dev = ObGenericCreateObject(&devh,0,&dev_attr,OBJTYP_DEVICE); @@ -166,6 +179,9 @@ NTSTATUS IoCreateDevice(PDRIVER_OBJECT DriverObject, } dev->DriverObject = DriverObject; + DPRINT("dev %x\n",dev); + DPRINT("dev->DriverObject %x\n",dev->DriverObject); + dev->CurrentIrp=NULL; dev->Flags=0; @@ -181,6 +197,7 @@ NTSTATUS IoCreateDevice(PDRIVER_OBJECT DriverObject, dev->AlignmentRequirement=1; *DeviceObject=dev; + DPRINT("dev->DriverObject %x\n",dev->DriverObject); return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/io/iomgr.c b/reactos/ntoskrnl/io/iomgr.c index b523aa30cc7..ea15e165cb0 100644 --- a/reactos/ntoskrnl/io/iomgr.c +++ b/reactos/ntoskrnl/io/iomgr.c @@ -17,7 +17,7 @@ /* GLOBALS *******************************************************************/ -OBJECT_TYPE DeviceObjectType = {{NULL,0,0}, +OBJECT_TYPE DeviceObjectType = {{0,0,NULL}, 0, 0, ULONG_MAX, @@ -33,6 +33,23 @@ OBJECT_TYPE DeviceObjectType = {{NULL,0,0}, NULL, NULL, }; + +OBJECT_TYPE FileObjectType = {{0,0,NULL}, + 0, + 0, + ULONG_MAX, + ULONG_MAX, + sizeof(FILE_OBJECT), + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + }; /* FUNCTIONS ****************************************************************/ @@ -44,12 +61,25 @@ VOID IoInit(VOID) UNICODE_STRING string; ANSI_STRING astring; + /* + * Register iomgr types + */ + RtlInitAnsiString(&astring,"Device"); + RtlAnsiStringToUnicodeString(&DeviceObjectType.TypeName,&astring,TRUE); ObRegisterType(OBJTYP_DEVICE,&DeviceObjectType); + + RtlInitAnsiString(&astring,"File"); + RtlAnsiStringToUnicodeString(&FileObjectType.TypeName,&astring,TRUE); + ObRegisterType(OBJTYP_FILE,&FileObjectType); + /* + * Create the device directory + */ RtlInitAnsiString(&astring,"\\Device"); RtlAnsiStringToUnicodeString(&string,&astring,TRUE); InitializeObjectAttributes(&attr,&string,0,NULL,NULL); ZwCreateDirectoryObject(&handle,0,&attr); IoInitCancelHandling(); + IoInitSymbolicLinkImplementation(); } diff --git a/reactos/ntoskrnl/io/irp.c b/reactos/ntoskrnl/io/irp.c index 01891dd15ab..b7feaeb016d 100644 --- a/reactos/ntoskrnl/io/irp.c +++ b/reactos/ntoskrnl/io/irp.c @@ -89,8 +89,75 @@ PIRP IoBuildAsynchronousFsdRequest(ULONG MajorFunction, ULONG Length, PLARGE_INTEGER StartingOffset, PIO_STATUS_BLOCK IoStatusBlock) +/* + * FUNCTION: Allocates and sets up an IRP to be sent to lower level drivers + * ARGUMENTS: + * MajorFunction = One of IRP_MJ_READ, IRP_MJ_WRITE, + * IRP_MJ_FLUSH_BUFFERS or IRP_MJ_SHUTDOWN + * DeviceObject = Device object to send the irp to + * Buffer = Buffer into which data will be read or written + * Length = Length in bytes of the irp to be allocated + * StartingOffset = Starting offset on the device + * IoStatusBlock (OUT) = Storage for the result of the operation + * RETURNS: The IRP allocated on success, or + * NULL on failure + */ { - UNIMPLEMENTED; + PIRP Irp; + PIO_STACK_LOCATION StackPtr; + + 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->Flags = 0; + StackPtr->Control = 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; + } + + return(Irp); } PIRP IoBuildDeviceIoControlRequest(ULONG IoControlCode, @@ -113,29 +180,78 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction, PLARGE_INTEGER StartingOffset, PKEVENT Event, PIO_STATUS_BLOCK IoStatusBlock) +/* + * FUNCTION: Allocates and builds an IRP to be sent synchronously to lower + * level driver(s) + * ARGUMENTS: + * MajorFunction = Major function code, one of IRP_MJ_READ, + * IRP_MJ_WRITE, IRP_MJ_FLUSH_BUFFERS, IRP_MJ_SHUTDOWN + * DeviceObject = Target device object + * Buffer = Buffer containing data for a read or write + * Length = Length in bytes of the information to be transferred + * StartingOffset = Offset to begin the read/write from + * Event (OUT) = Will be set when the operation is complete + * IoStatusBlock (OUT) = Set to the status of the operation + * RETURNS: The IRP allocated on success, or + * NULL on failure + */ { - PDRIVER_OBJECT DriverObject = DeviceObject->DriverObject; - PIRP irp; + PIRP Irp; PIO_STACK_LOCATION StackPtr; - - /* - * Allocate an IRP for the transfer - */ - irp = IoAllocateIrp(DeviceObject->StackSize,TRUE); - if (irp==NULL) + + Irp = IoAllocateIrp(DeviceObject->StackSize,TRUE); + if (Irp==NULL) { - printk("Failed to allocate IRP\n"); - return(FALSE); + return(NULL); } - /* - * Prepare the parameter in the next IO stack location - */ - StackPtr = IoGetNextIrpStackLocation(irp); + 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; + Irp->UserEvent = Event; + + StackPtr = IoGetNextIrpStackLocation(Irp); StackPtr->MajorFunction = MajorFunction; StackPtr->MinorFunction = 0; StackPtr->Flags = 0; StackPtr->Control = 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; + } + + return(Irp); } USHORT IoSizeOfIrp(CCHAR StackSize) @@ -204,13 +320,15 @@ NTSTATUS IoCallDriver(PDEVICE_OBJECT DevObject, PIRP irp) { PDRIVER_OBJECT drv = DevObject->DriverObject; IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(irp); - + DPRINT("Deviceobject %x\n",DevObject); + DPRINT("Irp %x\n",irp); irp->Tail.Overlay.CurrentStackLocation--; irp->CurrentLocation--; 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)); } @@ -272,7 +390,7 @@ VOID IoSetCompletionRoutine(PIRP Irp, } } -VOID IoCompleteRequest(IRP* Irp, CCHAR PriorityBoost) +VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost) /* * FUNCTION: Indicates the caller has finished all processing for a given * I/O request and is returning the given IRP to the I/O manager @@ -282,9 +400,15 @@ VOID IoCompleteRequest(IRP* Irp, CCHAR PriorityBoost) * thread making the request */ { - unsigned int i; + unsigned int i=0; + unsigned int stack_size; - for (i=0;i<0;i++) + DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d)\n", + Irp,PriorityBoost); + DPRINT("Irp->Stack[i].DeviceObject->StackSize %x\n", + Irp->Stack[i].DeviceObject->StackSize); + stack_size = Irp->Stack[i].DeviceObject->StackSize; + for (i=0;iStack[i].CompletionRoutine!=NULL) { @@ -292,4 +416,17 @@ VOID IoCompleteRequest(IRP* Irp, CCHAR PriorityBoost) Irp->Stack[i].CompletionContext); } } + + if (Irp->UserEvent!=NULL) + { + KeSetEvent(Irp->UserEvent,PriorityBoost,FALSE); + } + if (Irp->UserIosb!=NULL) + { + *Irp->UserIosb=Irp->IoStatus; + } + + /* + * If the + */ } diff --git a/reactos/ntoskrnl/io/mdl.c b/reactos/ntoskrnl/io/mdl.c index 7df6c991ee7..f4d1e519948 100644 --- a/reactos/ntoskrnl/io/mdl.c +++ b/reactos/ntoskrnl/io/mdl.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/io/mdl.c + * PURPOSE: Io manager mdl functions * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -62,7 +62,7 @@ VOID IoBuildPartialMdl(PMDL SourceMdl, } VOID IoFreeMdl(PMDL Mdl) -{ +{ MmUnmapLockedPages(MmGetSystemAddressForMdl(Mdl),Mdl); MmUnlockPages(Mdl); ExFreePool(Mdl); diff --git a/reactos/ntoskrnl/io/rw.c b/reactos/ntoskrnl/io/rw.c index ac64be3b6f3..96011371cdc 100644 --- a/reactos/ntoskrnl/io/rw.c +++ b/reactos/ntoskrnl/io/rw.c @@ -17,7 +17,7 @@ #include #include -//#define NDEBUG +#define NDEBUG #include #ifndef NDEBUG @@ -38,191 +38,157 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, PLARGE_INTEGER ByteOffset, PULONG Key) { - UNIMPLEMENTED; -} - -NTSTATUS ZwWriteFile(HANDLE FileHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER ByteOffset, - PULONG Key) -{ - UNIMPLEMENTED; -} - -static BOOL WriteDevice(PDEVICE_OBJECT dev, LPVOID lpBuffer, - DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, - LPOVERLAPPED lpOverlapped) -{ - PDRIVER_OBJECT drv = dev->DriverObject; - PIRP irp; + COMMON_BODY_HEADER* hdr = ObGetObjectByHandle(FileHandle); + PFILE_OBJECT FileObject = (PFILE_OBJECT)hdr; + PIRP Irp; PIO_STACK_LOCATION StackPtr; - DPRINT("dev %x drv %x\n",dev,drv); - - /* - * Build an irp for the transfer - */ - irp = IoAllocateIrp(dev->StackSize,TRUE); - if (irp==NULL) + if (hdr==NULL) { - printk("Failed to allocate IRP\n"); - return(FALSE); + return(STATUS_INVALID_HANDLE); } - /* - * Prepare the user buffer - */ - DPRINT1("Preparing user buffer\n"); - irp->UserBuffer = (LPVOID)lpBuffer; // This handles the 'neither' method - if (dev->Flags&DO_BUFFERED_IO) + Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize,TRUE); + if (Irp==NULL) + { + return(STATUS_UNSUCCESSFUL); + } + + Irp->UserBuffer = (LPVOID)Buffer; + if (FileObject->DeviceObject->Flags&DO_BUFFERED_IO) { DPRINT1("Doing buffer i/o\n"); - irp->AssociatedIrp.SystemBuffer = (PVOID) - ExAllocatePool(NonPagedPool,nNumberOfBytesToWrite); - if (irp->AssociatedIrp.SystemBuffer==NULL) + Irp->AssociatedIrp.SystemBuffer = (PVOID) + ExAllocatePool(NonPagedPool,Length); + if (Irp->AssociatedIrp.SystemBuffer==NULL) { - return(FALSE); + return(STATUS_UNSUCCESSFUL); } - memcpy(irp->AssociatedIrp.SystemBuffer,lpBuffer,nNumberOfBytesToWrite); - irp->UserBuffer = NULL; + Irp->UserBuffer = NULL; } - if (dev->Flags&DO_DIRECT_IO) + if (FileObject->DeviceObject->Flags&DO_DIRECT_IO) { DPRINT1("Doing direct i/o\n"); - irp->MdlAddress = MmCreateMdl(NULL,lpBuffer,nNumberOfBytesToWrite); - MmProbeAndLockPages(irp->MdlAddress,UserMode,IoWriteAccess); - irp->UserBuffer = NULL; - irp->AssociatedIrp.SystemBuffer = NULL; + Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length); + MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess); + Irp->UserBuffer = NULL; + Irp->AssociatedIrp.SystemBuffer = NULL; } - /* - * Set up the stack location - */ - StackPtr = IoGetNextIrpStackLocation(irp); - StackPtr->MajorFunction = IRP_MJ_WRITE; - StackPtr->MinorFunction = 0; - StackPtr->Flags = 0; - StackPtr->Control = 0; - StackPtr->DeviceObject = dev; - StackPtr->FileObject = NULL; - StackPtr->Parameters.Write.Length = nNumberOfBytesToWrite; - - DPRINT1("Sending IRP\n"); - IoCallDriver(dev,irp); - - - /* - * Free the above buffer - */ -} - -WINBOOL STDCALL WriteFile(HANDLE hFile, LPCVOID lpBuffer, - DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, - LPOVERLAPPED lpOverlapped) -{ - COMMON_BODY_HEADER* hdr = ObGetObjectByHandle(hFile); - - if (hdr->Type==OBJTYP_DEVICE) - { - return(WriteDevice(hdr,lpBuffer,nNumberOfBytesToWrite, - lpNumberOfBytesWritten,lpOverlapped)); - } - return(FALSE); -} - -static BOOL ReadDevice(PDEVICE_OBJECT dev, LPVOID lpBuffer, - DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, - LPOVERLAPPED lpOverlapped) -{ - PDRIVER_OBJECT drv = dev->DriverObject; - PIRP irp; - PIO_STACK_LOCATION StackPtr; - - DPRINT("dev %x drv %x\n",dev,drv); - - /* - * Build an irp for the transfer - */ - irp = IoAllocateIrp(dev->StackSize,TRUE); - if (irp==NULL) - { - printk("Failed to allocate IRP\n"); - return(FALSE); - } - - /* - * Prepare the user buffer - */ - DPRINT1("Preparing user buffer\n"); - irp->UserBuffer = (LPVOID)lpBuffer; // This handles the 'neither' method - if (dev->Flags&DO_BUFFERED_IO) - { - DPRINT1("Doing buffer i/o\n"); - irp->AssociatedIrp.SystemBuffer = (PVOID) - ExAllocatePool(NonPagedPool,nNumberOfBytesToWrite); - if (irp->AssociatedIrp.SystemBuffer==NULL) - { - return(FALSE); - } - memcpy(irp->AssociatedIrp.SystemBuffer,lpBuffer,nNumberOfBytesToWrite); - irp->UserBuffer = NULL; - } - if (dev->Flags&DO_DIRECT_IO) - { - DPRINT1("Doing direct i/o\n"); - - irp->MdlAddress = MmCreateMdl(NULL,lpBuffer,nNumberOfBytesToWrite); - MmProbeAndLockPages(irp->MdlAddress,UserMode,IoWriteAccess); - irp->UserBuffer = NULL; - irp->AssociatedIrp.SystemBuffer = NULL; - } - - /* - * Set up the stack location - */ - StackPtr = IoGetNextIrpStackLocation(irp); + StackPtr = IoGetNextIrpStackLocation(Irp); + DPRINT("StackPtr %x\n",StackPtr); StackPtr->MajorFunction = IRP_MJ_READ; StackPtr->MinorFunction = 0; StackPtr->Flags = 0; StackPtr->Control = 0; - StackPtr->DeviceObject = dev; - StackPtr->FileObject = NULL; - StackPtr->Parameters.Write.Length = nNumberOfBytesToWrite; + StackPtr->DeviceObject = FileObject->DeviceObject; + StackPtr->FileObject = FileObject; + StackPtr->Parameters.Write.Length = Length; + if (ByteOffset!=NULL) + { + StackPtr->Parameters.Write.ByteOffset.LowPart = ByteOffset->LowPart; + StackPtr->Parameters.Write.ByteOffset.HighPart = ByteOffset->HighPart; + } + else + { + StackPtr->Parameters.Write.ByteOffset.LowPart = 0; + StackPtr->Parameters.Write.ByteOffset.HighPart = 0; + } + if (Key!=NULL) + { + StackPtr->Parameters.Write.Key = *Key; + } + else + { + StackPtr->Parameters.Write.Key = 0; + } - DPRINT1("Sending IRP\n"); - IoCallDriver(dev,irp); - - - /* - * Free the above buffer - */ - DPRINT1("Finished ReadDevice\n"); + DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject); + IoCallDriver(FileObject->DeviceObject,Irp); + memcpy(Buffer,Irp->AssociatedIrp.SystemBuffer,Length); + return(STATUS_SUCCESS); } - - -WINBOOL STDCALL ReadFile(HANDLE hFile, LPVOID lpBuffer, - DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, - LPOVERLAPPED lpOverlapped) +NTSTATUS ZwWriteFile(HANDLE FileHandle, + HANDLE Event, + PIO_APC_ROUTINE ApcRoutine, + PVOID ApcContext, + PIO_STATUS_BLOCK IoStatusBlock, + PVOID Buffer, + ULONG Length, + PLARGE_INTEGER ByteOffset, + PULONG Key) { - COMMON_BODY_HEADER* hdr = ObGetObjectByHandle(hFile); + COMMON_BODY_HEADER* hdr = ObGetObjectByHandle(FileHandle); + PFILE_OBJECT FileObject = (PFILE_OBJECT)hdr; + PIRP Irp; + PIO_STACK_LOCATION StackPtr; - if (hdr->Type==OBJTYP_DEVICE) + if (hdr==NULL) { - return(ReadDevice((PDEVICE_OBJECT)hdr,lpBuffer,nNumberOfBytesToWrite, - lpNumberOfBytesWritten,lpOverlapped)); + return(STATUS_INVALID_HANDLE); } - return(FALSE); + + Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize,TRUE); + if (Irp==NULL) + { + return(STATUS_UNSUCCESSFUL); + } + + Irp->UserBuffer = (LPVOID)Buffer; + if (FileObject->DeviceObject->Flags&DO_BUFFERED_IO) + { + DPRINT1("Doing buffer i/o\n"); + Irp->AssociatedIrp.SystemBuffer = (PVOID) + ExAllocatePool(NonPagedPool,Length); + if (Irp->AssociatedIrp.SystemBuffer==NULL) + { + return(STATUS_UNSUCCESSFUL); + } + memcpy(Irp->AssociatedIrp.SystemBuffer,Buffer,Length); + Irp->UserBuffer = NULL; + } + if (FileObject->DeviceObject->Flags&DO_DIRECT_IO) + { + DPRINT1("Doing direct i/o\n"); + + Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length); + MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoReadAccess); + Irp->UserBuffer = NULL; + Irp->AssociatedIrp.SystemBuffer = NULL; + } + + StackPtr = IoGetNextIrpStackLocation(Irp); + DPRINT("StackPtr %x\n",StackPtr); + StackPtr->MajorFunction = IRP_MJ_WRITE; + StackPtr->MinorFunction = 0; + StackPtr->Flags = 0; + StackPtr->Control = 0; + StackPtr->DeviceObject = FileObject->DeviceObject; + StackPtr->FileObject = FileObject; + StackPtr->Parameters.Write.Length = Length; + if (ByteOffset!=NULL) + { + StackPtr->Parameters.Write.ByteOffset.LowPart = ByteOffset->LowPart; + StackPtr->Parameters.Write.ByteOffset.HighPart = ByteOffset->HighPart; + } + else + { + StackPtr->Parameters.Write.ByteOffset.LowPart = 0; + StackPtr->Parameters.Write.ByteOffset.HighPart = 0; + } + if (Key!=NULL) + { + StackPtr->Parameters.Write.Key = *Key; + } + else + { + StackPtr->Parameters.Write.Key = 0; + } + + DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject); + IoCallDriver(FileObject->DeviceObject,Irp); + return(STATUS_SUCCESS); } - diff --git a/reactos/ntoskrnl/io/symlink.c b/reactos/ntoskrnl/io/symlink.c index 47132628b2e..8b99e477ed7 100644 --- a/reactos/ntoskrnl/io/symlink.c +++ b/reactos/ntoskrnl/io/symlink.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/iomgr/symlink.c + * FILE: ntoskrnl/io/symlink.c * PURPOSE: Implements symbolic links * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -16,12 +16,41 @@ #include +/* GLOBALS ******************************************************************/ + +typedef struct +{ + PVOID Target; +} SYMBOLIC_LINK_OBJECT; + +OBJECT_TYPE SymlinkObjectType = {{NULL,0,0}, + 0, + 0, + ULONG_MAX, + ULONG_MAX, + sizeof(SYMBOLIC_LINK_OBJECT), + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + }; + /* FUNCTIONS *****************************************************************/ +VOID IoInitSymbolicLinkImplementation(VOID) +{ + +} + NTSTATUS IoCreateUnprotectedSymbolicLink(PUNICODE_STRING SymbolicLinkName, PUNICODE_STRING DeviceName) { - UNIMPLEMENTED; + return(IoCreateSymbolicLink(SymbolicLinkName,DeviceName)); } NTSTATUS IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName, diff --git a/reactos/ntoskrnl/io/timer.c b/reactos/ntoskrnl/io/timer.c index 9376a2cb5df..d5dd74b67c0 100644 --- a/reactos/ntoskrnl/io/timer.c +++ b/reactos/ntoskrnl/io/timer.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/iomgr/timer.c - * PURPOSE: IO timers + * FILE: ntoskrnl/io/timer.c + * PURPOSE: io timers * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 diff --git a/reactos/ntoskrnl/ke/apc.c b/reactos/ntoskrnl/ke/apc.c index 1f21f37ba8d..5d8951158db 100644 --- a/reactos/ntoskrnl/ke/apc.c +++ b/reactos/ntoskrnl/ke/apc.c @@ -13,8 +13,47 @@ #include #include #include +#include #include /* FUNCTIONS *****************************************************************/ +VOID KeDrainApcQueue(VOID) +{ + PLIST_ENTRY current_entry; + PKAPC current; + + current_entry = KeGetCurrentThread()->ApcQueueHead.Flink; + while (current_entry!=NULL) + { + current = CONTAINING_RECORD(current_entry,KAPC,ApcListEntry); + current->NormalRoutine(current->NormalContext, + current->SystemArgument1, + current->SystemArgument2); + current_entry = current_entry->Flink; + } +} + +VOID KeInitializeApc(PKAPC Apc, PKNORMAL_ROUTINE NormalRoutine, + PVOID NormalContext, + PKTHREAD TargetThread) +{ + memset(Apc,0,sizeof(KAPC)); + Apc->Thread = TargetThread; + Apc->NormalRoutine=NormalRoutine; + Apc->NormalContext=NormalContext; + Apc->Inserted=FALSE; +} + +BOOLEAN KeInsertQueueApc(PKAPC Apc) +{ + if (Apc->Inserted) + { + return(FALSE); + } + Apc->Inserted=TRUE; + InsertTailList(&Apc->Thread->ApcQueueHead,&Apc->ApcListEntry); + return(TRUE); +} + diff --git a/reactos/ntoskrnl/ke/bug.c b/reactos/ntoskrnl/ke/bug.c index fa0171ee776..84a95d5dbc8 100644 --- a/reactos/ntoskrnl/ke/bug.c +++ b/reactos/ntoskrnl/ke/bug.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c + * FILE: ntoskrnl/ke/bug.c * PURPOSE: Graceful system shutdown if a bug is detected * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: diff --git a/reactos/ntoskrnl/ke/exports.c b/reactos/ntoskrnl/ke/exports.c index 7bc5f6330b8..d5645a8213b 100644 --- a/reactos/ntoskrnl/ke/exports.c +++ b/reactos/ntoskrnl/ke/exports.c @@ -8,6 +8,8 @@ #ifdef __cplusplus extern "C" { #endif +void free_page(void); +void get_dma_page(void); void DbgPrint(void); void printk(void); void ExAcquireFastMutex(void); @@ -378,6 +380,8 @@ void sprintf(void); } #endif export symbol_table[]={ +{"_free_page",(unsigned int)free_page}, +{"_get_dma_page",(unsigned int)get_dma_page}, {"_DbgPrint",(unsigned int)DbgPrint}, {"_printk",(unsigned int)printk}, {"_ExAcquireFastMutex",(unsigned int)ExAcquireFastMutex}, diff --git a/reactos/ntoskrnl/makefile_rex b/reactos/ntoskrnl/makefile_rex index c2e766abcd8..d07160b5d21 100644 --- a/reactos/ntoskrnl/makefile_rex +++ b/reactos/ntoskrnl/makefile_rex @@ -8,7 +8,8 @@ include hal/x86/sources 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/list.o rtl/slist.o rtl/interlck.o rtl/return.o \ + rtl/wstring.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 \ @@ -24,13 +25,15 @@ 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/resource.o io/event.o io/process.o io/file.o io/ioctrl.o \ + io/fs.o OB_OBJECTS = ob/object.o ob/handle.o ob/namespc.o PS_OBJECTS = ps/psmgr.o ps/thread.o ps/process.o -EX_OBJECTS = ex/work.o ex/fmutex.o ex/resource.o ex/time.o ex/interlck.o +EX_OBJECTS = ex/work.o ex/fmutex.o ex/resource.o ex/time.o ex/interlck.o \ + ex/callback.o SE_OBJECTS = se/semgr.o @@ -38,10 +41,14 @@ CFG_OBJECTS = cfg/registry.o TST_OBJECTS = tst/test.o +DBG_OBJECTS = dbg/brkpoint.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) - + $(SE_OBJECTS) $(CFG_OBJECTS) $(TST_OBJECTS) $(DBG_OBJECTS) + utils/export/export$(EXE_POSTFIX): utils/export/export.c $(NATIVE_CC) -g utils/export/export.c -o utils/export/export$(EXE_POSTFIX) diff --git a/reactos/ntoskrnl/mm/mdl.c b/reactos/ntoskrnl/mm/mdl.c index e313418a460..7dab6306113 100644 --- a/reactos/ntoskrnl/mm/mdl.c +++ b/reactos/ntoskrnl/mm/mdl.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/mm/mdl.cc + * FILE: ntoskrnl/mm/mdl.c * PURPOSE: Manipulates MDLs * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -15,19 +15,45 @@ #include #include +#define NDEBUG #include /* FUNCTIONS ***************************************************************/ VOID MmUnlockPages(PMDL MemoryDescriptorList) +/* + * FUNCTION: Unlocks the physical pages described by a given MDL + * ARGUMENTS: + * MemoryDescriptorList = MDL describing the buffer to be unlocked + */ { UNIMPLEMENTED; } -PVOID MmMapLockedPages(PMDL MemoryDescriptorList, KPROCESSOR_MODE AccessMode) +PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode) { - UNIMPLEMENTED; + PVOID base; + unsigned int i; + ULONG* mdl_pages=NULL; + + DPRINT("Mdl->ByteCount %x\n",Mdl->ByteCount); + DPRINT("PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE) %x\n", + PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE); + + base = VirtualAlloc((LPVOID)0,Mdl->ByteCount,MEM_COMMIT, + PAGE_SYSTEM + PAGE_EXECUTE_READWRITE); + mdl_pages = (ULONG *)(Mdl + 1); + for (i=0; i<(PAGE_ROUND_UP(Mdl->ByteCount)/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]); + } + DPRINT("base %x\n",base); + return(base + Mdl->ByteOffset); } VOID MmUnmapLockedPages(PVOID BaseAddress, PMDL MemoryDescriptorList) @@ -56,20 +82,36 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, * Operation = Operation to probe for */ { - /* - * Find the memory area containing the buffer - */ ULONG* mdl_pages=NULL; int i; - memory_area* marea=find_first_marea(memory_area_list_head, - (ULONG)Mdl->StartVa, - Mdl->ByteCount); + memory_area* marea; + + DPRINT("MmProbeAndLockPages(Mdl %x)\n",Mdl); + DPRINT("StartVa %x\n",Mdl->StartVa); + + if (Mdl->StartVa > KERNEL_BASE) + { + marea=find_first_marea(system_memory_area_list_head, + (ULONG)Mdl->StartVa, + Mdl->ByteCount); + } + else + { + marea=find_first_marea(memory_area_list_head, + (ULONG)Mdl->StartVa, + Mdl->ByteCount); + } + + DPRINT("marea %x\n",marea); + + /* * Check the area is valid */ if (marea==NULL || (marea->base+marea->length) < ((ULONG)Mdl->StartVa)) { + printk("Area is invalid\n"); ExRaiseStatus(STATUS_INVALID_PARAMETER); } @@ -89,6 +131,7 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, case IoModifyAccess: if (marea->access&PAGE_GUARD || marea->access&PAGE_READONLY) { + printk("Invalid area protections\n"); ExRaiseStatus(STATUS_INVALID_PARAMETER); } break; @@ -108,7 +151,7 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, /* * Lock the pages */ - mdl_pages = (ULONG *)(Mdl + sizeof(MDL)); + mdl_pages = (ULONG *)(Mdl + 1); for (i=0;i<(PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE);i++) { @@ -119,6 +162,8 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, } mdl_pages[i]=MmGetPhysicalAddress((PVOID)(PAGE_ROUND_DOWN(Mdl->StartVa) +(i*PAGESIZE))); + DPRINT("mdl_pages[i] %x\n",mdl_pages[i]); + DPRINT("&mdl_pages[i] %x\n",&mdl_pages[i]); } } @@ -151,13 +196,9 @@ ULONG MmSizeOfMdl(PVOID Base, ULONG Length) * Length = number of bytes to map */ { - unsigned int len=PAGE_ROUND_UP(Length)/PAGESIZE; - - if (!IS_PAGE_ALIGNED(Base)) - { - len++; - } + unsigned int len=ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base,Length); + DPRINT("MmSizeOfMdl() %x\n",sizeof(MDL)+(len*sizeof(ULONG))); return(sizeof(MDL)+(len*sizeof(ULONG))); } @@ -167,12 +208,32 @@ PVOID MmGetMdlVirtualAddress(PMDL Mdl) } PVOID MmGetSystemAddressForMdl(PMDL Mdl) +/* + * FUNCTION: Returns a nonpaged system-space virtual address for the buffer + * described by the MDL. It maps the physical pages described by a given + * MDL into system space, if they are not already mapped to system space. + * ARGUMENTS: + * Mdl = Mdl to map + * RETURNS: The base system-space virtual address that maps the physical + * pages described by the given MDL. + */ { - Mdl->MappedSystemVa = MmMapLockedPages(Mdl,KernelMode); + if (!( (Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) || + (Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) )) + { + Mdl->MappedSystemVa = MmMapLockedPages(Mdl,KernelMode); + } return(Mdl->MappedSystemVa); } VOID MmBuildMdlForNonPagedPool(PMDL Mdl) +/* + * FUNCTION: Fills in the corresponding physical page array of a given + * MDL for a buffer in nonpaged system space + * ARGUMENTS: + * Mdl = Points to an MDL that supplies a virtual address, + * byte offset and length + */ { int va; for (va=0; vaSize; va++) @@ -180,21 +241,25 @@ VOID MmBuildMdlForNonPagedPool(PMDL Mdl) ((PULONG)(Mdl + 1))[va] = MmGetPhysicalAddress( Mdl->StartVa+ (va * PAGESIZE)); } + Mdl->MappedSystemVa = Mdl->StartVa; } VOID MmInitializeMdl(PMDL MemoryDescriptorList, PVOID Base, ULONG Length) +/* + * FUNCTION: Initializes the header of an MDL + * ARGUMENTS: + * MemoryDescriptorList = Points to the MDL to be initialized + * BaseVa = Points to the base virtual address of a buffer + * Length = Specifies the length (in bytes) of a buffer + */ { memset(MemoryDescriptorList,0,sizeof(MDL)); MemoryDescriptorList->StartVa = PAGE_ROUND_DOWN(Base); MemoryDescriptorList->ByteOffset = Base - PAGE_ROUND_DOWN(Base); MemoryDescriptorList->MdlFlags = 0; MemoryDescriptorList->ByteCount = Length; - MemoryDescriptorList->Size = PAGE_ROUND_UP(Length) / PAGESIZE; - if (!IS_PAGE_ALIGNED(Base)) - { - MemoryDescriptorList->Size = MemoryDescriptorList->Size - + sizeof(ULONG); - } + MemoryDescriptorList->Size = sizeof(MDL) + + (ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base,Length) * sizeof(ULONG)); MemoryDescriptorList->Process = PsGetCurrentProcess(); } @@ -211,7 +276,10 @@ PMDL MmCreateMdl(PMDL MemoryDescriptorList, PVOID Base, ULONG Length) { if (MemoryDescriptorList == NULL) { - MemoryDescriptorList = (PMDL)ExAllocatePool(NonPagedPool,sizeof(MDL)); + ULONG Size; + + Size = MmSizeOfMdl(Base,Length); + MemoryDescriptorList = (PMDL)ExAllocatePool(NonPagedPool,Size); if (MemoryDescriptorList==NULL) { return(NULL); diff --git a/reactos/ntoskrnl/mm/pool.c b/reactos/ntoskrnl/mm/pool.c index 75431409939..f8f211416f0 100644 --- a/reactos/ntoskrnl/mm/pool.c +++ b/reactos/ntoskrnl/mm/pool.c @@ -10,6 +10,7 @@ * in take_block (if current bigger than required) * in remove_from_used_list * in ExFreePool + * 23/08/98: Fixes from Robert Bergkvist (fragdance@hotmail.com) */ /* INCLUDES ****************************************************************/ @@ -250,15 +251,20 @@ static void remove_from_free_list(block_hdr* current) } else { - if (current->previous!=NULL) - { - current->previous->next=current->next; - } - if (current->next!=NULL) - { - DPRINT("current->previous %x\n",current->previous); - current->next->previous=current->previous; - } + if (current->next==NULL) + { + current->previous->next=NULL; + } + else if (current->previous==NULL) + { + current->next->previous=NULL; + free_list_head=current->next; + } + else + { + current->next->previous=current->previous; + current->previous->next=current->next; + } } nr_free_blocks--; } diff --git a/reactos/ntoskrnl/mm/virtual.c b/reactos/ntoskrnl/mm/virtual.c index 9fbb182a681..e4fd6dc8eca 100644 --- a/reactos/ntoskrnl/mm/virtual.c +++ b/reactos/ntoskrnl/mm/virtual.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top directory - * PROJECT: ReactOS kernel v0.0.2 - * FILE: mm/virtual.cc + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/mm/virtual.c * PURPOSE: implementing the Virtualxxx section of the win32 api * PROGRAMMER: David Welch * UPDATE HISTORY: @@ -22,17 +22,22 @@ /* TYPES *******************************************************************/ +extern unsigned int etext; +extern unsigned int end; + /* * These two are statically declared because mm is initalized before the * memory pool */ -static memory_area kernel_area_desc; +static memory_area kernel_text_desc; +static memory_area kernel_data_desc; +static memory_area kernel_param_desc; static memory_area kernel_pool_desc; /* * Head of the list of system memory areas */ -memory_area* system_memory_area_list_head=&kernel_area_desc; +memory_area* system_memory_area_list_head=&kernel_text_desc; /* * Head of the list of user memory areas (this should be per process) @@ -62,16 +67,33 @@ void VirtualInit(boot_param* bp) /* * Setup the system area descriptor list */ - kernel_area_desc.base = KERNEL_BASE; - kernel_area_desc.length = kernel_len; - kernel_area_desc.next = &kernel_pool_desc; - kernel_area_desc.load_page=NULL; + kernel_text_desc.base = KERNEL_BASE; + kernel_text_desc.length = ((ULONG)&etext) - KERNEL_BASE; + kernel_text_desc.previous = NULL; + kernel_text_desc.next = &kernel_data_desc; + kernel_text_desc.load_page=NULL; + kernel_text_desc.access = PAGE_EXECUTE_READ; + + kernel_data_desc.base = PAGE_ROUND_UP(((ULONG)&etext)); + kernel_data_desc.length = ((ULONG)&end) - kernel_text_desc.base; + kernel_data_desc.previous = &kernel_text_desc; + kernel_data_desc.next = &kernel_param_desc; + kernel_data_desc.load_page=NULL; + kernel_data_desc.access = PAGE_READWRITE; + + kernel_param_desc.base = PAGE_ROUND_UP(((ULONG)&end)); + kernel_param_desc.length = kernel_len - (kernel_data_desc.length + + kernel_text_desc.length); + kernel_param_desc.previous = &kernel_data_desc; + kernel_param_desc.next = &kernel_pool_desc; + kernel_param_desc.load_page=NULL; /* * The kmalloc area starts one page after the kernel area */ kernel_pool_desc.base = KERNEL_BASE+ PAGE_ROUND_UP(kernel_len) + PAGESIZE; kernel_pool_desc.length = NONPAGED_POOL_SIZE; + kernel_pool_desc.previous = &kernel_param_desc; kernel_pool_desc.next = NULL; kernel_pool_desc.load_page=NULL; @@ -98,8 +120,10 @@ memory_area* find_first_marea(memory_area* list_head, unsigned int base, { if (current==NULL) { +// printk("current is null\n"); return(NULL); } +// printk("current %x current->base %x\n",current,current->base); if (current->base == base && length==0) { return(current); @@ -210,11 +234,14 @@ static LPVOID allocate_marea(DWORD dwSize, DWORD flAllocationType, */ { memory_area* current=*list_head; + memory_area* previous; memory_area* ndesc=NULL; + previous=current; while (current!=NULL) { last_addr = PAGE_ROUND_UP(current->base + current->length); + previous=current; current=current->next; } ndesc = ExAllocatePool(NonPagedPool,sizeof(memory_area)); @@ -223,14 +250,14 @@ static LPVOID allocate_marea(DWORD dwSize, DWORD flAllocationType, ndesc->lock=FALSE; ndesc->base=last_addr+PAGESIZE; ndesc->length=dwSize; - ndesc->previous=current; - if (current!=NULL) + ndesc->previous=previous; + if (previous!=NULL) { - ndesc->next=current->next; - current->next=ndesc; - if (current->next!=NULL) + ndesc->next=previous->next; + previous->next=ndesc; + if (previous->next!=NULL) { - current->next->previous=ndesc; + previous->next->previous=ndesc; } } else diff --git a/reactos/ntoskrnl/ob/namespc.c b/reactos/ntoskrnl/ob/namespc.c index aabbda0e05e..9b6ac7cd969 100644 --- a/reactos/ntoskrnl/ob/namespc.c +++ b/reactos/ntoskrnl/ob/namespc.c @@ -11,11 +11,11 @@ /* INCLUDES ***************************************************************/ #include +#include #include #include #include #include -#include #define NDEBUG #include @@ -48,6 +48,78 @@ static struct /* FUNCTIONS **************************************************************/ +NTSTATUS ZwOpenDirectoryObject(PHANDLE DirectoryHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes) +{ + PVOID Object; + NTSTATUS Status; + + Status = ObOpenObjectByName(ObjectAttributes,&Object); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + if (BODY_TO_HEADER(Object)->Type!=OBJTYP_DIRECTORY) + { + return(STATUS_UNSUCCESSFUL); + } + + *DirectoryHandle = ObAddHandle(Object); + return(STATUS_SUCCESS); +} + +NTSTATUS ZwQueryDirectoryObject(IN HANDLE DirObjHandle, + OUT POBJDIR_INFORMATION DirObjInformation, + IN ULONG BufferLength, + IN BOOLEAN GetNextIndex, + IN BOOLEAN IgnoreInputIndex, + IN OUT PULONG ObjectIndex, + OUT PULONG DataWritten OPTIONAL) +{ + POBJECT_HEADER hdr = ObGetObjectByHandle(DirObjHandle); + PDIRECTORY_OBJECT dir = (PDIRECTORY_OBJECT)(HEADER_TO_BODY(hdr)); + PLIST_ENTRY current_entry; + POBJECT_HEADER current; + PWSTR outbuffer = (PWSTR)(ObjectIndex); + + current_entry = dir->head.Flink; + while (current_entry!=NULL) + { + current = CONTAINING_RECORD(current_entry,OBJECT_HEADER,entry); + if (BufferLength < wstrlen(current->name.Buffer)) + { + return(STATUS_SUCCESS); + } + BufferLength = BufferLength - wstrlen(current->name.Buffer); +// wcscpy(outbuffer,current->name.Buffer); + outbuffer = outbuffer + wstrlen(current->name.Buffer); + current_entry = current_entry->Flink; + } + return(STATUS_SUCCESS); +} + + +NTSTATUS ObOpenObjectByName(POBJECT_ATTRIBUTES ObjectAttributes, + PVOID* Object) +{ + + DPRINT("ObOpenObjectByName(ObjectAttributes %x, Object %x)\n", + ObjectAttributes,Object); + DPRINT("ObjectAttributes = {ObjectName %x ObjectName->Buffer %w}\n", + ObjectAttributes->ObjectName,ObjectAttributes->ObjectName->Buffer); + + *Object = ObLookupObject(ObjectAttributes->RootDirectory, + ObjectAttributes->ObjectName->Buffer); + DPRINT("*Object %x\n",*Object); + if ((*Object)==NULL) + { + return(STATUS_NO_SUCH_FILE); + } + return(STATUS_SUCCESS); +} + void ObjNamespcInit(void) /* * FUNCTION: Initialize the object manager namespace @@ -92,20 +164,6 @@ NTSTATUS ZwCreateDirectoryObject(PHANDLE DirectoryHandle, return(STATUS_SUCCESS); } -PWSTR Rtlstrrchr(PUNICODE_STRING string, WCHAR c) -{ - int i; - DPRINT("string->Length %d\n",string->Length); - for (i=(string->Length-1);i>=0;i--) - { - if (string->Buffer[i]==c) - { - return(&string->Buffer[i]); - } - } - return(NULL); -} - VOID InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes, PUNICODE_STRING ObjectName, ULONG Attributes, @@ -127,70 +185,15 @@ VOID InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes, * to RootDirectory */ { - UNICODE_STRING path; - PWSTR name = NULL; - PDIRECTORY_OBJECT parent_dir; - - DPRINT("InitalizeObjectAttributes(ObjectName %w)\n",ObjectName->Buffer); - - if (RootDirectory!=NULL) - { - ObReferenceObjectByHandle(RootDirectory,DIRECTORY_TRAVERSE,NULL, - UserMode,(PVOID*)&parent_dir,NULL); - } - else - { - parent_dir = HEADER_TO_BODY((POBJECT_HEADER)&namespc_root); - } - - ASSERT_IRQL(PASSIVE_LEVEL); - - path.Buffer = ExAllocatePool(NonPagedPool, - ObjectName->Length*sizeof(WCHAR)); - path.MaximumLength = ObjectName->Length; - RtlCopyUnicodeString(&path,ObjectName); - - /* - * Seperate the path into the name of the object and the name of its - * direct parent directory - */ - name = Rtlstrrchr(&path,'\\'); - *name=0; - - /* - * Find the objects parent directory - */ - DPRINT("parent_dir %x\n",&(parent_dir->Type)); - parent_dir=(PDIRECTORY_OBJECT)ObLookupObject(parent_dir,&path); - if (parent_dir==NULL) - { - return; - } - - /* - * Make sure the parent directory doesn't disappear - */ - ObReferenceObjectByPointer(parent_dir,DIRECTORY_CREATE_OBJECT,NULL, - UserMode); - - InitializedAttributes->Attributes = Attributes; - InitializedAttributes->parent = parent_dir; - RtlInitUnicodeString(&InitializedAttributes->name,name+1); - InitializedAttributes->path = path; -} - -int _wcscmp(wchar_t* str1, wchar_t* str2) -{ - while ( (*str1)==(*str2) ) - { - str1++; - str2++; - if ( (*str1)==((wchar_t)0) && (*str1)==((wchar_t)0) ) - { - return(0); - } - } - return( (*str1) - (*str2) ); + DPRINT("InitializeObjectAttributes(InitializedAttributes %x " + "ObjectName %x Attributes %x RootDirectory %x)\n", + InitializedAttributes,ObjectName,Attributes,RootDirectory); + InitializedAttributes->Length=sizeof(OBJECT_ATTRIBUTES); + InitializedAttributes->RootDirectory=RootDirectory; + InitializedAttributes->ObjectName=ObjectName; + InitializedAttributes->Attributes=Attributes; + InitializedAttributes->SecurityDescriptor=SecurityDescriptor; + InitializedAttributes->SecurityQualityOfService=NULL; } static PVOID ObDirLookup(PDIRECTORY_OBJECT dir, PWSTR name) @@ -205,12 +208,24 @@ static PVOID ObDirLookup(PDIRECTORY_OBJECT dir, PWSTR name) { LIST_ENTRY* current = ((PDIRECTORY_OBJECT)dir)->head.Flink; POBJECT_HEADER current_obj; - DPRINT("ObDirLookup(dir %x, name %w\n",dir,name); + DPRINT("ObDirLookup(dir %x, name %w)\n",dir,name); + if (name[0]==0) + { + return(BODY_TO_HEADER(dir)); + } + if (name[0]=='.'&&name[1]==0) + { + return(BODY_TO_HEADER(dir)); + } + if (name[0]=='.'&&name[1]=='.'&&name[2]==0) + { + UNIMPLEMENTED; + return(NULL); + } while (current!=NULL) { current_obj = CONTAINING_RECORD(current,OBJECT_HEADER,entry); - DPRINT("current_obj->name %w\n",current_obj->name.Buffer); - if ( _wcscmp(current_obj->name.Buffer, name)==0) + if ( wcscmp(current_obj->name.Buffer, name)==0) { return(current_obj); } @@ -244,20 +259,7 @@ VOID ObCreateEntry(PDIRECTORY_OBJECT parent,POBJECT_HEADER Object) InsertTailList(&parent->head,&Object->entry); } -wchar_t* _wcschr(wchar_t* str, wchar_t ch) -{ - while ((*str)!=((wchar_t)0)) - { - if ((*str)==ch) - { - return(str); - } - str++; - } - return(NULL); -} - -PVOID ObLookupObject(PDIRECTORY_OBJECT root, PUNICODE_STRING _string) +PVOID ObLookupObject(HANDLE rooth, PWSTR string) /* * FUNCTION: Lookup an object within the system namespc * ARGUMENTS: @@ -269,30 +271,31 @@ PVOID ObLookupObject(PDIRECTORY_OBJECT root, PUNICODE_STRING _string) { PWSTR current; PWSTR next; - PDIRECTORY_OBJECT current_dir = root; + PDIRECTORY_OBJECT current_dir = NULL; POBJECT_HEADER current_hdr; - PWSTR string; - DPRINT("root %x string %w\n",root,_string->Buffer); + DPRINT("root %x string %w\n",rooth,string); - if (root==NULL) + if (rooth==NULL) { current_dir = HEADER_TO_BODY(&(namespc_root.hdr)); } + else + { + ObReferenceObjectByHandle(rooth,DIRECTORY_TRAVERSE,NULL, + UserMode,(PVOID*)¤t_dir,NULL); + } /* * Bit of a hack this */ - if (_string->Buffer[0]==0) + if (string[0]==0) { DPRINT("current_dir %x\n",current_dir); DPRINT("type %d\n",current_dir->Type); return(current_dir); } - string=(PWSTR)ExAllocatePool(NonPagedPool,(_string->Length+1)*2); - wcscpy(string,_string->Buffer); - DPRINT("string = %w\n",string); if (string[0]!='\\') @@ -304,7 +307,7 @@ PVOID ObLookupObject(PDIRECTORY_OBJECT root, PUNICODE_STRING _string) current = string+1; DPRINT("current %w\n",current); - next = _wcschr(string+1,'\\'); + next = wcschr(string+1,'\\'); if (next!=NULL) { *next=0; @@ -341,7 +344,7 @@ PVOID ObLookupObject(PDIRECTORY_OBJECT root, PUNICODE_STRING _string) current_dir = HEADER_TO_BODY(current_hdr); current = next+1; - next = _wcschr(next+1,'\\'); + next = wcschr(next+1,'\\'); if (next!=NULL) { *next=0; @@ -353,11 +356,9 @@ PVOID ObLookupObject(PDIRECTORY_OBJECT root, PUNICODE_STRING _string) current_hdr = ObDirLookup(current_dir,current); if (current_hdr==NULL) { - ExFreePool(string); return(NULL); } DPRINT("Returning %x %x\n",current_hdr,HEADER_TO_BODY(current_hdr)); - ExFreePool(string); return(HEADER_TO_BODY(current_hdr)); } diff --git a/reactos/ntoskrnl/ob/object.c b/reactos/ntoskrnl/ob/object.c index 83c93bb8aa3..4b6492ccd4e 100644 --- a/reactos/ntoskrnl/ob/object.c +++ b/reactos/ntoskrnl/ob/object.c @@ -13,6 +13,7 @@ #include #include #include +#include #define NDEBUG #include @@ -37,9 +38,14 @@ PVOID ObGenericCreateObject(PHANDLE Handle, CSHORT Type) { POBJECT_HEADER hdr = NULL; + UNICODE_STRING ObjectName; + PWSTR path; + PWSTR name; + PDIRECTORY_OBJECT parent; - DPRINT("ObGenericCreateObject(Handle %x ObjectAttributes %x Type %x)\n", - Handle,ObjectAttributes,Type); + DPRINT("ObGenericCreateObject(Handle %x, DesiredAccess %x," + "ObjectAttributes %x, Type %x)\n",Handle,DesiredAccess,ObjectAttributes, + Type); /* * Allocate the object body and header @@ -49,30 +55,56 @@ PVOID ObGenericCreateObject(PHANDLE Handle, { return(NULL); } + + /* + * If unnamed then initalize + */ + if (ObjectAttributes==NULL) + { + ObInitializeObjectHeader(Type,NULL,hdr); + *Handle = ObAddHandle(HEADER_TO_BODY(hdr)); + return(HEADER_TO_BODY(hdr)); + } + + /* + * Copy the object name into a buffer + */ + DPRINT("ObjectAttributes->ObjectName %x\n",ObjectAttributes->ObjectName); + DPRINT("ObjectAttributes->ObjectName->Length %d\n", + ObjectAttributes->ObjectName->Length); + ObjectName.MaximumLength = ObjectAttributes->ObjectName->Length; + ObjectName.Buffer = ExAllocatePool(NonPagedPool, + ((ObjectAttributes->ObjectName->Length+1)*2)); + if (ObjectName.Buffer==NULL) + { + return(NULL); + } + RtlCopyUnicodeString(&ObjectName,ObjectAttributes->ObjectName); + + /* + * Seperate the name into a path and name + */ + name = wcsrchr(ObjectName.Buffer,'\\'); + if (name==NULL) + { + name=ObjectName.Buffer; + path=NULL; + } + else + { + path=ObjectName.Buffer; + *name=0; + name=name+1; + } + + parent = ObLookupObject(ObjectAttributes->RootDirectory,path); /* * Initialize the object header */ - if (ObjectAttributes!=NULL) - { - ObInitializeObjectHeader(Type,&ObjectAttributes->name,hdr); - } - else - { - ObInitializeObjectHeader(Type,NULL,hdr); - } - -// DPRINT("ObjectAttributes->parent->Type %d\n", -// ObjectAttributes->parent->Type); - if (ObjectAttributes!=NULL) - { - /* - * Add the object to its parent directory - */ - DPRINT("hdr->name.Buffer %x\n",hdr->name.Buffer); - ObCreateEntry(ObjectAttributes->parent,hdr); - } - + ObInitializeObjectHeader(Type,name,hdr); + ObCreateEntry(parent,hdr); + DPRINT("Handle %x\n",Handle); *Handle = ObAddHandle(HEADER_TO_BODY(hdr)); @@ -81,6 +113,8 @@ PVOID ObGenericCreateObject(PHANDLE Handle, ULONG ObSizeOf(CSHORT Type) { + DPRINT("ObSizeOf(Type %d)\n",Type); + DPRINT("ObSizeOf() Returning %d\n",ObjectTypes[Type]->PagedPoolCharge); return(ObjectTypes[Type]->PagedPoolCharge); } @@ -95,7 +129,7 @@ VOID ObRegisterType(CSHORT id, POBJECT_TYPE type) ObjectTypes[id]=type; } -VOID ObInitializeObjectHeader(CSHORT id, PUNICODE_STRING name, +VOID ObInitializeObjectHeader(CSHORT id, PWSTR name, POBJECT_HEADER obj) /* * FUNCTION: Creates a new object @@ -104,10 +138,12 @@ VOID ObInitializeObjectHeader(CSHORT id, PUNICODE_STRING name, * obj = Pointer to the header of the object */ { + PWSTR temp_name; + if (name!=NULL) { DPRINT("ObInitializeObjectHeader(id %d name %w obj %x)\n",id, - name->Buffer,obj); + name,obj); } else { @@ -125,13 +161,13 @@ VOID ObInitializeObjectHeader(CSHORT id, PUNICODE_STRING name, } else { - obj->name.Length = 0; - obj->name.MaximumLength = name->Length; + DPRINT("name %w\n",name); + obj->name.MaximumLength = wstrlen(name); obj->name.Buffer = ExAllocatePool(NonPagedPool, - (name->Length+1)*sizeof(WCHAR)); - DPRINT("obj->name.Buffer %x\n",obj->name.Buffer); - RtlCopyUnicodeString(&obj->name,name); - DPRINT("obj->name.Buffer %x\n",obj->name.Buffer); + (obj->name.MaximumLength+1)*2); + DPRINT("name %w\n",name); + RtlInitUnicodeString(&obj->name,name); + DPRINT("name %w\n",obj->name.Buffer); } } @@ -150,10 +186,11 @@ NTSTATUS ObReferenceObjectByPointer(PVOID ObjectBody, * RETURNS: Status */ { - POBJECT_HEADER Object = BODY_TO_HEADER(ObjectBody); + POBJECT_HEADER Object; DPRINT("ObReferenceObjectByPointer(%x %x)\n",ObjectBody,Object); - + + Object = BODY_TO_HEADER(ObjectBody); Object->RefCount++; return(STATUS_SUCCESS); } @@ -180,7 +217,7 @@ NTSTATUS ZwClose(HANDLE Handle) { PVOID ObjectBody; - ASSERT_IRQL(PASSIVE_LEVEL); + assert_irql(PASSIVE_LEVEL); ObjectBody = ObGetObjectByHandle(Handle); if (ObjectBody == NULL) diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 29239efb582..b06eedd7feb 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -310,6 +310,7 @@ NTSTATUS PsCreateSystemThread(PHANDLE ThreadHandle, ExInterlockedInsertHeadList(&ThreadListHead,&thread->Entry, &ThreadListLock); + InitializeListHead(&thread->ApcQueueHead); return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/rtl/unicode.c b/reactos/ntoskrnl/rtl/unicode.c index c1514b4642e..62d7141d869 100644 --- a/reactos/ntoskrnl/rtl/unicode.c +++ b/reactos/ntoskrnl/rtl/unicode.c @@ -9,6 +9,7 @@ */ #include +#include #include @@ -30,59 +31,40 @@ WCHAR wtoupper(WCHAR c) { if((c>='a') && (c<='z')) return c+Aa_Difference; return c; -} - -unsigned long wstrlen(PWSTR s) -{ - WCHAR c=' '; - unsigned int len=0; - - while(c!=0) { - c=*s; - s++; - len++; - }; - s-=len; - - return len-1; -} +}; ULONG RtlAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString) { return AnsiString->Length*2; -} +}; NTSTATUS RtlAnsiStringToUnicodeString(IN OUT PUNICODE_STRING DestinationString, - IN PANSI_STRING SourceString, - IN BOOLEAN AllocateDestinationString) + IN PANSI_STRING SourceString, IN BOOLEAN AllocateDestinationString) { - unsigned long i; - - if (AllocateDestinationString==TRUE) - { - DestinationString->Buffer=ExAllocatePool(NonPagedPool, - (SourceString->Length+1)*2); - DestinationString->MaximumLength=SourceString->Length; - } + unsigned long i; - DestinationString->Length=SourceString->Length; - - memset(DestinationString->Buffer,0,SourceString->Length*2); - - for (i=0; iLength; i++) - { - *DestinationString->Buffer=*SourceString->Buffer; - - SourceString->Buffer++; - DestinationString->Buffer++; - }; - *DestinationString->Buffer=0; - - SourceString->Buffer-=SourceString->Length; - DestinationString->Buffer-=SourceString->Length; - - return STATUS_SUCCESS; -} + if(AllocateDestinationString==TRUE) { + DestinationString->Buffer=ExAllocatePool(NonPagedPool, SourceString->Length*2+1); + DestinationString->MaximumLength=SourceString->Length; + }; + + DestinationString->Length=SourceString->Length; + memset(DestinationString->Buffer, 0, SourceString->Length*2); + + for (i=0; iLength; i++) + { + *DestinationString->Buffer=*SourceString->Buffer; + + SourceString->Buffer++; + DestinationString->Buffer++; + }; + *DestinationString->Buffer=0; + + SourceString->Buffer-=SourceString->Length; + DestinationString->Buffer-=SourceString->Length; + + return STATUS_SUCCESS; +}; NTSTATUS RtlAppendUnicodeStringToString(IN OUT PUNICODE_STRING Destination, IN PUNICODE_STRING Source) @@ -104,7 +86,7 @@ NTSTATUS RtlAppendUnicodeStringToString(IN OUT PUNICODE_STRING Destination, Destination->Length+=Source->Length; return STATUS_SUCCESS; -} +}; NTSTATUS RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination, IN PWSTR Source) @@ -126,12 +108,12 @@ NTSTATUS RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination, Destination->Length+=slen; return STATUS_SUCCESS; -} +}; NTSTATUS RtlCharToInteger(IN PCSZ String, IN ULONG Base, IN OUT PULONG Value) { *Value=simple_strtoul((const char *)String, NULL, Base); -} +}; LONG RtlCompareString(PSTRING String1, PSTRING String2, BOOLEAN CaseInsensitive) { @@ -160,7 +142,7 @@ LONG RtlCompareString(PSTRING String1, PSTRING String2, BOOLEAN CaseInsensitive) String2->Buffer-=i; return 0; -} +}; LONG RtlCompareUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInsensitive) @@ -194,7 +176,7 @@ LONG RtlCompareUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, String2->Buffer-=i; return 0; -} +}; VOID RtlCopyString(IN OUT PSTRING DestinationString, IN PSTRING SourceString) { @@ -202,7 +184,6 @@ VOID RtlCopyString(IN OUT PSTRING DestinationString, IN PSTRING SourceString) if(SourceString==NULL) { DestinationString->Length=0; - DestinationString->Buffer=NULL; } else { if(SourceString->LengthMaximumLength) { copylen=SourceString->Length; @@ -211,62 +192,40 @@ VOID RtlCopyString(IN OUT PSTRING DestinationString, IN PSTRING SourceString) }; for(i=0; iBuffer)=*(SourceString->Buffer); - DestinationString++; - SourceString++; + *DestinationString->Buffer=*SourceString->Buffer; + DestinationString->Buffer++; + SourceString->Buffer++; }; *DestinationString->Buffer=0; DestinationString->Buffer-=copylen; SourceString->Buffer-=copylen; }; -} +}; VOID RtlCopyUnicodeString(IN OUT PUNICODE_STRING DestinationString, IN PUNICODE_STRING SourceString) { - unsigned long copylen, i; - WCHAR* src; - WCHAR* dest; - - DPRINT("RtlCopyUnicodeString(Dest %x Source %x)\n",DestinationString, - SourceString); - DPRINT("Dest->Length %d Dest->Buffer %x\n",DestinationString->Length, - DestinationString->Buffer); - if (SourceString!=NULL) - { - DPRINT("Source->Length %d Source->Buffer %x\n",SourceString->Length, - SourceString->Buffer); - } - - if(SourceString==NULL) - { - DestinationString->Length=0; - } - else - { - DestinationString->Length=SourceString->Length; - if(SourceString->LengthMaximumLength) - { - copylen=SourceString->Length; - } - else - { - copylen=DestinationString->MaximumLength; - } - DPRINT("Beginning copy of length %d\n",copylen); - src = SourceString->Buffer; - dest = DestinationString->Buffer; - for(i=0; iBuffer); - *dest=0; - DPRINT("Finished copy %x\n",DestinationString->Buffer); - } -} + unsigned long copylen, i; + + if(SourceString==NULL) { + DestinationString->Length=0; + } else { + if(SourceString->LengthMaximumLength) { + copylen=SourceString->Length; + } else { + copylen=DestinationString->MaximumLength; + }; + for(i=0; iBuffer=*SourceString->Buffer; + DestinationString->Buffer++; + SourceString->Buffer++; + }; + *DestinationString->Buffer=0; + DestinationString->Buffer-=copylen; + SourceString->Buffer-=copylen; + }; +}; BOOLEAN RtlEqualString(PSTRING String1, PSTRING String2, BOOLEAN CaseInsensitive) { @@ -300,7 +259,7 @@ BOOLEAN RtlEqualString(PSTRING String1, PSTRING String2, BOOLEAN CaseInsensitive String2->Buffer-=i; return TRUE; -} +}; BOOLEAN RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInsensitive) @@ -335,17 +294,17 @@ BOOLEAN RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, String2->Buffer-=i; return TRUE; -} +}; VOID RtlFreeAnsiString(IN PANSI_STRING AnsiString) { ExFreePool(AnsiString->Buffer); -} +}; VOID RtlFreeUnicodeString(IN PUNICODE_STRING UnicodeString) { ExFreePool(UnicodeString->Buffer); -} +}; VOID RtlInitAnsiString(IN OUT PANSI_STRING DestinationString, IN PCSZ SourceString) @@ -361,7 +320,7 @@ VOID RtlInitAnsiString(IN OUT PANSI_STRING DestinationString, DestinationString->MaximumLength=DestSize+1; }; DestinationString->Buffer=(PCHAR)SourceString; -} +}; VOID RtlInitString(IN OUT PSTRING DestinationString, IN PCSZ SourceString) @@ -369,7 +328,7 @@ VOID RtlInitString(IN OUT PSTRING DestinationString, DestinationString->Length=strlen((char *)SourceString); DestinationString->MaximumLength=strlen((char *)SourceString)+1; DestinationString->Buffer=SourceString; -} +}; VOID RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString) @@ -388,7 +347,7 @@ VOID RtlInitUnicodeString(IN OUT PUNICODE_STRING DestinationString, DestinationString->Buffer=(PWSTR)SourceString; }; -} +}; NTSTATUS RtlIntegerToUnicodeString(IN ULONG Value, IN ULONG Base, /* optional */ IN OUT PUNICODE_STRING String) @@ -396,7 +355,7 @@ NTSTATUS RtlIntegerToUnicodeString(IN ULONG Value, IN ULONG Base, char *str; unsigned long len, i; - str=ExAllocatePool(NonPagedPool, 100); + str=ExAllocatePool(NonPagedPool, 1024); if(Base==16) { sprintf(str, "%x", Value); } else @@ -424,37 +383,35 @@ NTSTATUS RtlIntegerToUnicodeString(IN ULONG Value, IN ULONG Base, ExFreePool(str); return STATUS_SUCCESS; -} +}; NTSTATUS RtlUnicodeStringToAnsiString(IN OUT PANSI_STRING DestinationString, IN PUNICODE_STRING SourceString, IN BOOLEAN AllocateDestinationString) { - unsigned long i; - WCHAR* dest; - char* src; - - if(AllocateDestinationString==TRUE) - { - DestinationString->Buffer=ExAllocatePool(NonPagedPool, - (SourceString->Length+1)*2); - DestinationString->MaximumLength=SourceString->Length; - } + unsigned long i; - DestinationString->Length=SourceString->Length; - - dest = DestinationString->Buffer; - src = SourceString->Buffer; - for(i=0; iLength; i++) - { - *dest=*src; - src++; - dest++; - } - *DestinationString->Buffer=0; + if(AllocateDestinationString==TRUE) { - return STATUS_SUCCESS; -} + // Causes excetion 14(0) in _Validate_Free_List + DestinationString->Buffer=ExAllocatePool(NonPagedPool, SourceString->Length+1); + DestinationString->MaximumLength=SourceString->Length+1; + }; + + DestinationString->Length=SourceString->Length; + + for(i=0; iLength; i++) { + *DestinationString->Buffer=*SourceString->Buffer; + DestinationString->Buffer++; + SourceString->Buffer++; + }; + *DestinationString->Buffer=0; + + DestinationString->Buffer-=SourceString->Length; + SourceString->Buffer-=SourceString->Length; + + return STATUS_SUCCESS; +}; NTSTATUS RtlUnicodeStringToInteger(IN PUNICODE_STRING String, IN ULONG Base, OUT PULONG Value) @@ -511,7 +468,7 @@ NTSTATUS RtlUnicodeStringToInteger(IN PUNICODE_STRING String, IN ULONG Base, *Value=simple_strtoul(str, NULL, Base); ExFreePool(str); -} +}; NTSTATUS RtlUpcaseUnicodeString(IN OUT PUNICODE_STRING DestinationString, IN PUNICODE_STRING SourceString, @@ -520,15 +477,15 @@ NTSTATUS RtlUpcaseUnicodeString(IN OUT PUNICODE_STRING DestinationString, unsigned long i; if(AllocateDestinationString==TRUE) { - DestinationString->Buffer=ExAllocatePool(NonPagedPool, SourceString->Length+1); + DestinationString->Buffer=ExAllocatePool(NonPagedPool, SourceString->Length*2+1); DestinationString->Length=SourceString->Length; - DestinationString->MaximumLength-SourceString->Length+1; + DestinationString->MaximumLength=SourceString->Length+1; }; for(i=0; iLength; i++) { *DestinationString->Buffer=wtoupper(*SourceString->Buffer); - DestinationString++; - SourceString++; + DestinationString->Buffer++; + SourceString->Buffer++; }; *DestinationString->Buffer=0; @@ -536,7 +493,7 @@ NTSTATUS RtlUpcaseUnicodeString(IN OUT PUNICODE_STRING DestinationString, SourceString->Buffer-=SourceString->Length; return STATUS_SUCCESS; -} +}; VOID RtlUpcaseString(IN OUT PSTRING DestinationString, IN PSTRING SourceString) @@ -551,11 +508,11 @@ VOID RtlUpcaseString(IN OUT PSTRING DestinationString, for(i=0; iBuffer=toupper(*SourceString->Buffer); - DestinationString++; - SourceString++; + DestinationString->Buffer++; + SourceString->Buffer++; }; *DestinationString->Buffer=0; DestinationString->Buffer-=len; SourceString->Buffer-=len; -} +}; diff --git a/reactos/ntoskrnl/tst/test.c b/reactos/ntoskrnl/tst/test.c index 2f7d8a992fd..ae67188dfb5 100644 --- a/reactos/ntoskrnl/tst/test.c +++ b/reactos/ntoskrnl/tst/test.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: ntoskrnl/test/test.c + * FILE: ntoskrnl/tst/test.c * PURPOSE: Kernel regression tests * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -11,41 +11,52 @@ /* INCLUDES *****************************************************************/ #include - +#include #include #include #define NDEBUG #include +#include + /* GLOBALS ******************************************************************/ static KEVENT event; /* FUNCTIONS ****************************************************************/ +NTSTATUS TstPlaySound(void) +{ + HANDLE hfile; + + /* + * Open the parallel port + */ + printk("Opening Waveout\n"); +// hfile = CreateFile("\\Device\\WaveOut",0,0,0,0,0,0); + if (hfile == NULL) + { + printk("File open failed\n"); + } + else + { +// WriteFile(hfile,wave,wavelength,NULL,NULL); + } +} + NTSTATUS TstFirstThread(PVOID start) { printk("Beginning Thread A\n"); - for(;;) - { - KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); - KeClearEvent(&event); - printk("AAA "); - KeSetEvent(&event,IO_NO_INCREMENT,TRUE); - } + KeClearEvent(&event); + KeSetEvent(&event,IO_NO_INCREMENT,TRUE); } NTSTATUS TstSecondThread(PVOID start) { printk("Beginning Thread B\n"); - for(;;) - { - KeSetEvent(&event,IO_NO_INCREMENT,TRUE); - KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); - KeClearEvent(&event); - printk("BBB "); - } + KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); + printk("Ending Thread B\n"); } NTSTATUS TstThreadSupport() @@ -53,22 +64,53 @@ NTSTATUS TstThreadSupport() HANDLE th1, th2; KeInitializeEvent(&event,SynchronizationEvent,FALSE); - PsCreateSystemThread(&th1,0,NULL,NULL,NULL,TstFirstThread,NULL); +// PsCreateSystemThread(&th1,0,NULL,NULL,NULL,TstFirstThread,NULL); + KeClearEvent(&event); PsCreateSystemThread(&th2,0,NULL,NULL,NULL,TstSecondThread,NULL); for(;;); } +void TstGeneralWrite() +{ + OBJECT_ATTRIBUTES attr; + HANDLE hfile; + char buf[256]; + ANSI_STRING afilename; + UNICODE_STRING ufilename; + + DbgPrint("Opening test device\n"); + RtlInitAnsiString(&afilename,"\\Device\\Test"); + 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; + } + strcpy(buf,"hello world"); + ZwWriteFile(hfile, + NULL, + NULL, + NULL, + NULL, + buf, + strlen(buf), + 0, + 0); + } + void TstParallelPortWrite() { HANDLE hfile; DbgPrint("Opening parallel port\n"); - hfile = CreateFile("\\Device\\Parallel",0,0,0,0,0,0); +// 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); + // WriteFile(hfile,"hello world",strlen("hello world"),NULL,NULL); } void TstKeyboardRead() @@ -76,7 +118,7 @@ void TstKeyboardRead() KEY_EVENT_RECORD key; HANDLE hfile; - hfile = CreateFile("\\Device\\Keyboard",0,0,0,0,0,0); +// hfile = CreateFile("\\Device\\Keyboard",0,0,0,0,0,0); if (hfile == NULL) { printk("Failed to open keyboard\n"); @@ -84,7 +126,7 @@ void TstKeyboardRead() } for (;;) { - ReadFile(hfile,&key,sizeof(KEY_EVENT_RECORD),NULL,NULL); +// ReadFile(hfile,&key,sizeof(KEY_EVENT_RECORD),NULL,NULL); printk("%c",key.AsciiChar); for(;;); } @@ -92,6 +134,6 @@ void TstKeyboardRead() void TstBegin() { - TstKeyboardRead(); + TstGeneralWrite(); }