* 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
*/
-PVOID STDCALL
+PVOID APIENTRY
EngAllocMem(ULONG Flags,
ULONG MemSize,
ULONG Tag)
/*
* @implemented
*/
-VOID STDCALL
+VOID APIENTRY
EngFreeMem(PVOID Mem)
{
ExFreePool(Mem);
/*
* @implemented
*/
-PVOID STDCALL
+PVOID APIENTRY
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;
}
/*
* @implemented
*/
-VOID STDCALL
+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 */
}
PVOID
-NTAPI
+APIENTRY
HackSecureVirtualMemory(
IN PVOID Address,
IN SIZE_T Size,
return NULL;
}
- _SEH_TRY
+ _SEH2_TRY
{
MmProbeAndLockPages(mdl, UserMode, Operation);
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
+ Status = _SEH2_GetExceptionCode();
}
- _SEH_END
+ _SEH2_END
if (!NT_SUCCESS(Status))
{
}
VOID
-NTAPI
+APIENTRY
HackUnsecureVirtualMemory(
IN PVOID SecureHandle)
{
/*
* @implemented
*/
-HANDLE STDCALL
+HANDLE APIENTRY
EngSecureMem(PVOID Address, ULONG Length)
{
+ return (HANDLE)-1; // HACK!!!
return MmSecureVirtualMemory(Address, Length, PAGE_READWRITE);
}
/*
* @implemented
*/
-VOID STDCALL
+VOID APIENTRY
EngUnsecureMem(HANDLE Mem)
{
- return MmUnsecureVirtualMemory((PVOID) Mem);
+ if (Mem == (HANDLE)-1) return; // HACK!!!
+ MmUnsecureVirtualMemory((PVOID) Mem);
}
/* EOF */