- Fix MmCreateKernelStack to actually take into account the GuiStack parameter.
[reactos.git] / reactos / ntoskrnl / include / internal / ntoskrnl.h
index dcec0c8..e50921b 100644 (file)
@@ -81,132 +81,27 @@ RtlpLogException(IN PEXCEPTION_RECORD ExceptionRecord,
                  IN PVOID ContextData,
                  IN ULONG Size);
 
-#define ExRaiseStatus RtlRaiseStatus
-
-/*
- * Inlined Probing Macros
- */
-static __inline
-NTSTATUS
-NTAPI
-ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest,
-                             KPROCESSOR_MODE CurrentMode,
-                             IN PUNICODE_STRING UnsafeSrc)
+/* FIXME: Interlocked functions that need to be made into a public header */
+FORCEINLINE
+LONG
+InterlockedAnd(IN OUT LONG volatile *Target,
+               IN LONG Set)
 {
-    NTSTATUS Status = STATUS_SUCCESS;
-    PVOID Buffer;
-    ASSERT(Dest != NULL);
+    LONG i;
+    LONG j;
 
-    /* Probe the structure and buffer*/
-    if(CurrentMode != KernelMode)
-    {
-        _SEH_TRY
-        {
-            ProbeForRead(UnsafeSrc,
-                         sizeof(UNICODE_STRING),
-                         sizeof(ULONG));
-            *Dest = *UnsafeSrc;
-            if(Dest->Length > 0)
-            {
-                ProbeForRead(Dest->Buffer,
-                             Dest->Length,
-                             sizeof(WCHAR));
-            }
-        }
-        _SEH_HANDLE
-        {
-            Status = _SEH_GetExceptionCode();
-        }
-        _SEH_END;
-
-        if (!NT_SUCCESS(Status)) return Status;
-    }
-    else
-    {
-        /* Just copy it directly */
-        *Dest = *UnsafeSrc;
-    }
+    j = *Target;
+    do {
+        i = j;
+        j = InterlockedCompareExchange((PLONG)Target,
+                                       i & Set,
+                                       i);
 
-    /* Allocate space for the buffer */
-    Buffer = ExAllocatePool(PagedPool, Dest->MaximumLength);
+    } while (i != j);
 
-    if (Buffer != NULL)
-    {
-        /* Copy it */
-        RtlCopyMemory(Buffer, Dest->Buffer, Dest->MaximumLength);
-
-        /* Set it as the buffer */
-        Dest->Buffer = Buffer;
-    }
-    else
-        Status = STATUS_INSUFFICIENT_RESOURCES;
-
-    /* Return */
-    return Status;
-}
-
-static __inline
-VOID
-NTAPI
-ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString,
-                             KPROCESSOR_MODE CurrentMode)
-{
-    if(CurrentMode != KernelMode) ExFreePool(CapturedString->Buffer);
+    return j;
 }
 
-/*
- * NOTE: Alignment of the pointers is not verified!
- */
-#define ProbeForWriteGenericType(Ptr, Type)                                    \
-    do {                                                                       \
-        if ((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) ||          \
-            (ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) { \
-            RtlRaiseStatus (STATUS_ACCESS_VIOLATION);                          \
-        }                                                                      \
-        *(volatile Type *)(Ptr) = *(volatile Type *)(Ptr);                     \
-    } while (0)
-
-#define ProbeForWriteBoolean(Ptr) ProbeForWriteGenericType(Ptr, BOOLEAN)
-#define ProbeForWriteUchar(Ptr) ProbeForWriteGenericType(Ptr, UCHAR)
-#define ProbeForWriteChar(Ptr) ProbeForWriteGenericType(Ptr, Char)
-#define ProbeForWriteUshort(Ptr) ProbeForWriteGenericType(Ptr, USHORT)
-#define ProbeForWriteShort(Ptr) ProbeForWriteGenericType(Ptr, SHORT)
-#define ProbeForWriteUlong(Ptr) ProbeForWriteGenericType(Ptr, ULONG)
-#define ProbeForWriteLong(Ptr) ProbeForWriteGenericType(Ptr, LONG)
-#define ProbeForWriteUint(Ptr) ProbeForWriteGenericType(Ptr, UINT)
-#define ProbeForWriteInt(Ptr) ProbeForWriteGenericType(Ptr, INT)
-#define ProbeForWriteUlonglong(Ptr) ProbeForWriteGenericType(Ptr, ULONGLONG)
-#define ProbeForWriteLonglong(Ptr) ProbeForWriteGenericType(Ptr, LONGLONG)
-#define ProbeForWriteLonglong(Ptr) ProbeForWriteGenericType(Ptr, LONGLONG)
-#define ProbeForWritePointer(Ptr) ProbeForWriteGenericType(Ptr, PVOID)
-#define ProbeForWriteHandle(Ptr) ProbeForWriteGenericType(Ptr, HANDLE)
-#define ProbeForWriteLangid(Ptr) ProbeForWriteGenericType(Ptr, LANGID)
-#define ProbeForWriteLargeInteger(Ptr) ProbeForWriteGenericType(&(Ptr)->QuadPart, LONGLONG)
-#define ProbeForWriteUlargeInteger(Ptr) ProbeForWriteGenericType(&(Ptr)->QuadPart, ULONGLONG)
-
-#define ProbeForReadGenericType(Ptr, Type, Default)                            \
-    (((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) ||                \
-        (ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) ?   \
-            ExRaiseStatus (STATUS_ACCESS_VIOLATION), Default :                    \
-            *(Type *)(Ptr))
-
-#define ProbeForReadBoolean(Ptr) ProbeForReadGenericType(Ptr, BOOLEAN, FALSE)
-#define ProbeForReadUchar(Ptr) ProbeForReadGenericType(Ptr, UCHAR, 0)
-#define ProbeForReadChar(Ptr) ProbeForReadGenericType(Ptr, CHAR, 0)
-#define ProbeForReadUshort(Ptr) ProbeForReadGenericType(Ptr, USHORT, 0)
-#define ProbeForReadShort(Ptr) ProbeForReadGenericType(Ptr, SHORT, 0)
-#define ProbeForReadUlong(Ptr) ProbeForReadGenericType(Ptr, ULONG, 0)
-#define ProbeForReadLong(Ptr) ProbeForReadGenericType(Ptr, LONG, 0)
-#define ProbeForReadUint(Ptr) ProbeForReadGenericType(Ptr, UINT, 0)
-#define ProbeForReadInt(Ptr) ProbeForReadGenericType(Ptr, INT, 0)
-#define ProbeForReadUlonglong(Ptr) ProbeForReadGenericType(Ptr, ULONGLONG, 0)
-#define ProbeForReadLonglong(Ptr) ProbeForReadGenericType(Ptr, LONGLONG, 0)
-#define ProbeForReadPointer(Ptr) ProbeForReadGenericType(Ptr, PVOID, NULL)
-#define ProbeForReadHandle(Ptr) ProbeForReadGenericType(Ptr, HANDLE, NULL)
-#define ProbeForReadLangid(Ptr) ProbeForReadGenericType(Ptr, LANGID, 0)
-#define ProbeForReadLargeInteger(Ptr) ((LARGE_INTEGER)ProbeForReadGenericType(&(Ptr)->QuadPart, LONGLONG, 0))
-#define ProbeForReadUlargeInteger(Ptr) ((ULARGE_INTEGER)ProbeForReadGenericType(&(Ptr)->QuadPart, ULONGLONG, 0))
-
 /*
  * generic information class probing code
  */
@@ -232,7 +127,7 @@ typedef struct _INFORMATION_CLASS_INFO
 #define ICI_SQ(SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags)        \
   { SizeQuery, SizeSet, AlignmentQuery, AlignmentSet, Flags }
 
-static inline NTSTATUS
+static __inline NTSTATUS
 DefaultSetInfoBufferCheck(UINT Class,
                           const INFORMATION_CLASS_INFO *ClassList,
                           UINT ClassListEntries,
@@ -281,7 +176,7 @@ DefaultSetInfoBufferCheck(UINT Class,
     return Status;
 }
 
-static inline NTSTATUS
+static __inline NTSTATUS
 DefaultQueryInfoBufferCheck(UINT Class,
                             const INFORMATION_CLASS_INFO *ClassList,
                             UINT ClassListEntries,
@@ -359,9 +254,5 @@ DefaultQueryInfoBufferCheck(UINT Class,
 #endif
 
 #endif
-/*
- *
- */
-#define MM_STACK_SIZE             (3*4096)
 
 #endif /* INCLUDE_INTERNAL_NTOSKRNL_H */