2 * reactos memory areas 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 "captive/mm.h" /* self, for captive_flProtect_to_mmap_prot() */
23 #include "reactos/internal/mm.h" /* self */
24 #include "reactos/ntos/types.h" /* for PVOID etc. */
25 #include <glib/gmessages.h>
26 #include <sys/mman.h> /* for PROT_NONE etc. */
31 * @Length: Length (in bytes) of the area to allocate. Does not have to be page
32 * aligned. Value 0 is forbidden.
34 * Allocates @Length area with %PAGE_READWRITE flags.
36 * Returns: Allocated address space if the allocation was successful.
38 PVOID MmAllocateSection(IN ULONG Length)
40 int mmap_prot=captive_flProtect_to_mmap_prot(PAGE_READWRITE);
43 g_return_val_if_fail(Length>0,NULL);
45 Length=(Length|(PAGE_SIZE-1))+1; /* round up to PAGE_SIZE */
51 MAP_PRIVATE|MAP_ANONYMOUS, /* flags */
52 -1, /* fd; ignored due to MAP_ANONYMOUS */
53 0); /* offset; ignored due to MAP_ANONYMOUS */
54 g_return_val_if_fail(r!=NULL,NULL);
56 captive_mmap_map_new(r,Length,mmap_prot);
64 * MmFlushImageSection:
65 * @SectionObjectPointer: Section to flush description.
66 * %NULL value is forbidden.
67 * @FlushType: %MmFlushForDelete or %MmFlushForWrite.
69 * Function flushes any cached #ImageSectionObject.
70 * libcaptive does not cache any images and therefore this function is a NOP there.
72 * Returns: %TRUE if the operation was successful.
74 BOOLEAN MmFlushImageSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer,IN MMFLUSH_TYPE FlushType)
76 g_return_val_if_fail(SectionObjectPointer!=NULL,FALSE);
77 g_return_val_if_fail(FlushType==MmFlushForDelete || FlushType==MmFlushForWrite,FALSE);
79 g_return_val_if_fail(SectionObjectPointer->ImageSectionObject==NULL,FALSE); /* NOT IMPLEMENTED YET */
81 return TRUE; /* No section mapped or it was successfuly flushed. */
85 BOOLEAN MmCanFileBeTruncated(IN PSECTION_OBJECT_POINTERS SectionObjectPointer,IN PLARGE_INTEGER NewFileSize)
87 g_return_val_if_fail(SectionObjectPointer!=NULL,FALSE); /* means do not allow truncation */
88 /* 'NewFileSize' may by NULL
89 * Passed as NULL by ntfs.sys of NT-5.1sp1; FIXME: What does it mean?
92 g_assert(!NewFileSize || NewFileSize->QuadPart>=0);
94 return TRUE; /* allowed */