2 * reactos MemoryArea emulation of libcaptive
3 * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "reactos/internal/mm.h" /* self */
23 #include <glib/gmessages.h>
24 #include <glib/gmem.h>
25 #include "captive/macros.h"
30 * @Process: #PEPROCESS owning the memory being allocated. Ignored by libcaptive.
31 * %NULL value is forbidden.
32 * @AddressSpace: #PMADDRESS_SPACE where to place the allocation. Ignored by libcaptive.
33 * %NULL value is forbidden.
34 * @Type: Unknown. Ignored by libcaptive (copied to target @Result).
35 * @BaseAddress: Requests/returns required/allocated memory fixed address.
36 * FIXME: Pointed value required %NULL by libcaptive.
37 * %NULL pointer is forbidden.
38 * @Length: Allocation length. %PAGE_SIZE round up by libcaptive (FIXME: needed?).
39 * @Attributes: Unknown. Ignored by libcaptive (copied to target @Result).
40 * @Result: Returns new allocated #MEMORY_AREA. Previous pointed value lost.
41 * %NULL pointer is forbidden.
42 * @FixedAddress: Whether @BaseAddress points to the required address.
43 * FIXME: %FALSE required by libcaptive.
44 * @TopDown: %TRUE if we should search the area from the top of memory address space.
45 * Ignored by libcaptive.
47 * Reserves the memory of size @Length from @AddressSpace.
48 * FIXME: libcaptive currently does not enqueue this allocation to @AddressSpace.
50 * libcaptive currently automatically fills the reserved memory space with a real
51 * read/write non-executable memory pages allocated by MmAllocateSection().
52 * It is currently being (mis)used by ntoskrnl/cc/view.c/CcRosCreateCacheSegment().
53 * This preallocation should not hurt as our memory just may get overriden
56 * Returns: %STATUS_SUCCESS if the allocation was successful.
57 * @Result will contain a new #MEMORY_AREA in such case.
59 NTSTATUS MmCreateMemoryArea(PEPROCESS Process,PMADDRESS_SPACE AddressSpace,
60 ULONG Type,PVOID* BaseAddress,ULONG Length,ULONG Attributes,MEMORY_AREA** Result,BOOL FixedAddress,BOOL TopDown)
64 g_return_val_if_fail(Process!=NULL,STATUS_INVALID_PARAMETER);
65 g_return_val_if_fail(AddressSpace!=NULL,STATUS_INVALID_PARAMETER);
66 g_return_val_if_fail(BaseAddress!=NULL,STATUS_INVALID_PARAMETER);
67 g_return_val_if_fail(Length>0,STATUS_INVALID_PARAMETER);
69 /* FIXME: Fixed allocations not implemented yet */
70 g_assert(*BaseAddress==NULL && !FixedAddress);
72 /* round-up - is it needed? */
73 Length=(Length|(PAGE_SIZE-1))+1;
75 /* We allocate the memory although it is not expected from such W32 call */
76 *BaseAddress=MmAllocateSection(Length);
77 g_assert(*BaseAddress!=NULL);
79 /* FIXME: Why is reactos doring '(*BaseAddress)+=PAGE_SIZE'
80 * in ntoskrnl/mm/marea.c/MmCreateMemoryArea() ?
83 captive_new0(*Result);
86 marea->BaseAddress=*BaseAddress;
88 marea->Attributes=Attributes;
90 marea->Process=Process;
92 marea->DeleteInProgress=FALSE;
94 return STATUS_SUCCESS;