[YAROTOWS] Reintegrate the branch. For a brighter future.
[reactos.git] / reactos / subsystems / win32 / win32k / eng / mem.c
index 8ec3aa5..1fb81b3 100644 (file)
@@ -12,9 +12,9 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  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.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 /* $Id$
  *
  *                 3/7/1999: Created
  */
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
 
-typedef struct _USERMEMHEADER
-  {
-  ULONG Tag;
-  ULONG MemSize;
-  }
-USERMEMHEADER, *PUSERMEMHEADER;
-
 /*
  * @implemented
  */
@@ -76,21 +69,19 @@ EngAllocUserMem(SIZE_T cj, ULONG Tag)
 {
   PVOID NewMem = NULL;
   NTSTATUS Status;
-  SIZE_T MemSize = sizeof(USERMEMHEADER) + cj;
-  PUSERMEMHEADER Header;
+  SIZE_T MemSize = cj;
 
-  Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &NewMem, 0, &MemSize, MEM_COMMIT, PAGE_READWRITE);
+  Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &NewMem, 0, &MemSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
 
   if (! NT_SUCCESS(Status))
     {
       return NULL;
     }
 
-  Header = (PUSERMEMHEADER) NewMem;
-  Header->Tag = Tag;
-  Header->MemSize = cj;
+  /* TODO: Add allocation info to AVL tree (stored inside W32PROCESS structure) */
+  //hSecure = EngSecureMem(NewMem, cj);
 
-  return (PVOID)(Header + 1);
+  return NewMem;
 }
 
 /*
@@ -99,10 +90,12 @@ EngAllocUserMem(SIZE_T cj, ULONG Tag)
 VOID APIENTRY
 EngFreeUserMem(PVOID pv)
 {
-  PUSERMEMHEADER Header = ((PUSERMEMHEADER) pv) - 1;
-  SIZE_T MemSize = sizeof(USERMEMHEADER) + Header->MemSize;
+  PVOID BaseAddress = pv;
+  SIZE_T MemSize = 0;
+
+  ZwFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &MemSize, MEM_RELEASE);
 
-  ZwFreeVirtualMemory(NtCurrentProcess(), (PVOID *) &Header, &MemSize, MEM_RELEASE);
+  /* TODO: Remove allocation info from AVL tree */
 }
 
 
@@ -174,6 +167,7 @@ HackUnsecureVirtualMemory(
 HANDLE APIENTRY
 EngSecureMem(PVOID Address, ULONG Length)
 {
+    return (HANDLE)-1; // HACK!!!
   return MmSecureVirtualMemory(Address, Length, PAGE_READWRITE);
 }
 
@@ -183,7 +177,8 @@ EngSecureMem(PVOID Address, ULONG Length)
 VOID APIENTRY
 EngUnsecureMem(HANDLE Mem)
 {
-  return MmUnsecureVirtualMemory((PVOID) Mem);
+    if (Mem == (HANDLE)-1) return;  // HACK!!!
+  MmUnsecureVirtualMemory((PVOID) Mem);
 }
 
 /* EOF */