2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
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; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 IntUserHeapCommitRoutine(IN PVOID Base
,
28 IN OUT PVOID
*CommitAddress
,
29 IN OUT PSIZE_T CommitSize
)
31 PW32PROCESS W32Process
;
32 PW32HEAP_USER_MAPPING Mapping
;
33 PVOID UserBase
= NULL
;
35 SIZE_T Delta
= (SIZE_T
)((ULONG_PTR
)(*CommitAddress
) - (ULONG_PTR
)Base
);
37 W32Process
= PsGetCurrentProcessWin32Process();
39 if (W32Process
!= NULL
)
41 /* search for the mapping */
42 Mapping
= &W32Process
->HeapMappings
;
43 while (Mapping
!= NULL
)
45 if (Mapping
->KernelMapping
== Base
)
47 UserBase
= Mapping
->UserMapping
;
51 Mapping
= Mapping
->Next
;
54 ASSERT(UserBase
!= NULL
);
60 extern PSECTION_OBJECT GlobalUserHeapSection
;
62 /* HACK: This needs to be handled during startup only... */
63 ASSERT(Base
== (PVOID
)GlobalUserHeap
);
65 /* temporarily map it into user space */
67 Status
= MmMapViewOfSection(GlobalUserHeapSection
,
68 PsGetCurrentProcess(),
76 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
78 if (!NT_SUCCESS(Status
))
83 UserBase
= (PVOID
)((ULONG_PTR
)UserBase
+ Delta
);
85 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
91 if (NT_SUCCESS(Status
))
93 *CommitAddress
= (PVOID
)((ULONG_PTR
)UserBase
+ Delta
);
96 if (W32Process
== NULL
)
98 MmUnmapViewOfSection(PsGetCurrentProcess(),
106 IntUserHeapCreate(IN PSECTION_OBJECT SectionObject
,
107 IN PVOID
*SystemMappedBase
,
110 PVOID MappedView
= NULL
;
111 LARGE_INTEGER Offset
;
112 ULONG ViewSize
= PAGE_SIZE
;
113 RTL_HEAP_PARAMETERS Parameters
= {0};
119 /* Commit the first page before creating the heap! */
120 Status
= MmMapViewOfSection(SectionObject
,
121 PsGetCurrentProcess(),
129 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
130 if (!NT_SUCCESS(Status
))
133 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
138 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
140 MmUnmapViewOfSection(PsGetCurrentProcess(),
143 if (!NT_SUCCESS(Status
))
146 /* Create the heap, don't serialize in kmode! The caller is responsible
147 to synchronize the heap! */
148 Parameters
.Length
= sizeof(Parameters
);
149 Parameters
.InitialCommit
= PAGE_SIZE
;
150 Parameters
.InitialReserve
= (SIZE_T
)HeapSize
;
151 Parameters
.CommitRoutine
= IntUserHeapCommitRoutine
;
153 hHeap
= RtlCreateHeap(HEAP_ZERO_MEMORY
| HEAP_NO_SERIALIZE
,
164 UserCreateHeap(OUT PSECTION_OBJECT
*SectionObject
,
165 IN OUT PVOID
*SystemBase
,
168 LARGE_INTEGER SizeHeap
;
172 SizeHeap
.QuadPart
= HeapSize
;
174 /* create the section and map it into session space */
175 Status
= MmCreateSection((PVOID
*)SectionObject
,
179 PAGE_EXECUTE_READWRITE
, /* would prefer PAGE_READWRITE, but thanks to RTL heaps... */
184 if (!NT_SUCCESS(Status
))
186 SetLastNtError(Status
);
190 Status
= MmMapViewInSystemSpace(*SectionObject
,
193 if (!NT_SUCCESS(Status
))
195 ObDereferenceObject(*SectionObject
);
196 *SectionObject
= NULL
;
198 SetLastNtError(Status
);
202 /* create the heap */
203 hHeap
= IntUserHeapCreate(*SectionObject
,
209 ObDereferenceObject(*SectionObject
);
210 *SectionObject
= NULL
;
212 SetLastNtError(STATUS_UNSUCCESSFUL
);