+MmCreateMemoryArea()
authorshort <>
Sun, 10 Nov 2002 20:58:21 +0000 (20:58 +0000)
committershort <>
Sun, 10 Nov 2002 20:58:21 +0000 (20:58 +0000)
src/libcaptive/mm/Makefile.am
src/libcaptive/mm/marea.c [new file with mode: 0644]

index 788d50f..092bab5 100644 (file)
@@ -21,6 +21,7 @@ include $(top_srcdir)/src/libcaptive/Makefile-libcaptive.am
 
 noinst_LTLIBRARIES=libmm.la
 libmm_la_SOURCES= \
+               marea.c \
                mdl.c \
                mminit.c \
                page.c \
diff --git a/src/libcaptive/mm/marea.c b/src/libcaptive/mm/marea.c
new file mode 100644 (file)
index 0000000..42f6677
--- /dev/null
@@ -0,0 +1,93 @@
+/* $Id$
+ * reactos MemoryArea emulation of libcaptive
+ * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+#include "config.h"
+
+#include "reactos/internal/mm.h"       /* self */
+#include <glib/gmessages.h>
+#include <glib/gmem.h>
+#include "captive/macros.h"
+
+
+/**
+ * MmCreateMemoryArea:
+ * @Process: #PEPROCESS owning the memory being allocated. Ignored by libcaptive.
+ * %NULL value is forbidden.
+ * @AddressSpace: #PMADDRESS_SPACE where to place the allocation. Ignored by libcaptive.
+ * %NULL value is forbidden.
+ * @Type: Unknown. Ignored by libcaptive (copied to target @Result).
+ * @BaseAddress: Requests/returns required/allocated memory fixed address.
+ * FIXME: Pointed value required %NULL by libcaptive.
+ * %NULL pointer is forbidden.
+ * @Length: Allocation length. %PAGE_SIZE round up by libcaptive (FIXME: needed?).
+ * @Attributes: Unknown. Ignored by libcaptive (copied to target @Result).
+ * @Result: Returns new allocated #MEMORY_AREA. Previous pointed value lost.
+ * %NULL pointer is forbidden.
+ * @FixedAddress: Whether @BaseAddress points to the required address.
+ * FIXME: %FALSE required by libcaptive.
+ *
+ * Reserves the memory of size @Length from @AddressSpace.
+ * FIXME: libcaptive currently does not enqueue this allocation to @AddressSpace.
+ *
+ * libcaptive currently automatically fills the reserved memory space with a real
+ * read/write non-executable memory pages allocated by MmAllocateSection().
+ * It is currently being (mis)used by ntoskrnl/cc/view.c/CcRosCreateCacheSegment().
+ * This preallocation should not hurt as our memory just may get overriden
+ * by another one.
+ *
+ * Returns: %STATUS_SUCCESS if the allocation was successful.
+ * @Result will contain a new #MEMORY_AREA in such case.
+ */
+NTSTATUS MmCreateMemoryArea(PEPROCESS Process,PMADDRESS_SPACE AddressSpace,
+               ULONG Type,PVOID* BaseAddress,ULONG Length,ULONG Attributes,MEMORY_AREA** Result,BOOL FixedAddress)
+{
+MEMORY_AREA *marea;
+
+       g_return_val_if_fail(Process!=NULL,STATUS_INVALID_PARAMETER);
+       g_return_val_if_fail(AddressSpace!=NULL,STATUS_INVALID_PARAMETER);
+       g_return_val_if_fail(BaseAddress!=NULL,STATUS_INVALID_PARAMETER);
+       g_return_val_if_fail(Length>0,STATUS_INVALID_PARAMETER);
+
+       /* FIXME: Fixed allocations not implemented yet */
+       g_assert(*BaseAddress==NULL && !FixedAddress);
+
+       /* round-up - is it needed? */
+       Length=(Length|(PAGE_SIZE-1))+1;
+
+       /* We allocate the memory although it is not expected from such W32 call */
+       *BaseAddress=MmAllocateSection(Length);
+       g_assert(*BaseAddress!=NULL);
+
+       /* FIXME: Why is reactos doring '(*BaseAddress)+=PAGE_SIZE'
+        * in ntoskrnl/mm/marea.c/MmCreateMemoryArea() ?
+        */
+
+       captive_new0(*Result);
+       marea=*Result;
+       marea->Type=Type;
+       marea->BaseAddress=*BaseAddress;
+       marea->Length=Length;
+       marea->Attributes=Attributes;
+       marea->LockCount=0;
+       marea->Process=Process;
+       marea->PageOpCount=0;
+       marea->DeleteInProgress=FALSE;
+
+       return STATUS_SUCCESS;
+}