/* $Id$ */
/** @file
* SUP Testcase - Exploring some NT Query APIs.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct FLAGDESC
{
ULONG f;
const char *psz;
} FLAGDESC;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
{
{
if (fWithSpace)
{
*pszBuf++ = ' ';
*pcbBuf += 1;
}
}
return pszBuf;
}
static char *stringifyAppendUnknownFlags(uint32_t fFlags, char *pszBuf, size_t *pcbBuf, bool fWithSpace)
{
{
fWithSpace = true;
}
return pszBuf;
}
static char *stringifyFlags(uint32_t fFlags, char *pszBuf, size_t cbBuf, PCFLAGDESC paFlagDesc, size_t cFlagDesc)
{
if (fFlags)
{
{
if (fFlags & paFlagDesc[i].f)
{
fFlags &= ~paFlagDesc[i].f;
}
}
if (fFlags)
}
else
{
pszBuf[0] = '0';
}
return pszBufStart;
}
{
{
{ MEM_PRIVATE, "PRIVATE" },
{ MEM_MAPPED, "MAPPED" },
{ MEM_IMAGE, "IMAGE" },
};
}
{
{
{ MEM_FREE, "FREE" },
{ MEM_COMMIT, "COMMIT" },
{ MEM_RESERVE, "RESERVE" },
{ MEM_DECOMMIT, "DECOMMMIT" },
};
}
{
{
{ PAGE_NOACCESS, "NOACCESS" },
{ PAGE_READONLY, "READONLY" },
{ PAGE_READWRITE, "READWRITE" },
{ PAGE_WRITECOPY, "WRITECOPY" },
{ PAGE_EXECUTE, "EXECUTE" },
{ PAGE_EXECUTE_READ, "EXECUTE_READ" },
{ PAGE_EXECUTE_READWRITE, "EXECUTE_READWRITE" },
{ PAGE_EXECUTE_WRITECOPY, "EXECUTE_WRITECOPY" },
{ PAGE_GUARD, "GUARD" },
{ PAGE_NOCACHE, "NOCACHE" },
{ PAGE_WRITECOMBINE, "WRITECOMBINE" },
};
}
static void tstQueryVirtualMemory(void)
{
RTTestISub("NtQueryVirtualMemory");
for (;;)
{
(void const *)uPtrWhere,
&MemInfo,
sizeof(MemInfo),
&cbActual);
if (!NT_SUCCESS(rcNt))
{
break;
}
/* stringify the memory state. */
);
{
else
RTTestIPrintf(RTTESTLVL_ALWAYS, " %s", stringifyMemProt(MemInfo.AllocationProtect, szAllocProt, sizeof(szAllocProt)));
}
/* Image or mapped, then try get a file name. */
{
union
{
WCHAR awcPadding[UNICODE_STRING_MAX_CHARS + (sizeof(UNICODE_STRING_MAX_CHARS) + 1) / sizeof(WCHAR)];
} uBuf;
cbActual = 0;
(void const *)uPtrWhere,
&uBuf,
sizeof(uBuf),
&cbActual);
if (NT_SUCCESS(rcNt))
else
{
}
}
/* Advance. */
//cbAdvance = 0;
break;
}
}
static void tstQueryInformationProcess(void)
{
RTTestISub("NtQueryInformationProcess");
/* Basic info */
if (NT_SUCCESS(rcNt))
" UniqueProcessId = %#x (%6d)\n"
" InheritedFromUniqueProcessId = %#x (%6d)\n"
" ExitStatus = %#x\n"
" PebBaseAddress = %p\n"
" AffinityMask = %#zx\n"
" BasePriority = %#zx\n"
,
);
/* Debugger present? */
cbActual = 0;
if (NT_SUCCESS(rcNt))
/* Debug object handle, whatever that is... */
cbActual = 0;
if (NT_SUCCESS(rcNt))
else if (rcNt == STATUS_PORT_NOT_SET)
RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessDebugObjectHandle: rcNt=%#x (STATUS_PORT_NOT_SET)\n", uPtr);
else
/* 32-bit app on 64-bit host? */
cbActual = 0;
if (NT_SUCCESS(rcNt))
/* Process image name (NT). */
struct
{
} StrBuf;
cbActual = 0;
if (NT_SUCCESS(rcNt))
/* Process image name (Win32) - Not available on Windows 2003. */
cbActual = 0;
if (rcNt != STATUS_INVALID_INFO_CLASS)
{
if (NT_SUCCESS(rcNt))
}
else
RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessImageFileNameWin32: Not supported (STATUS_INVALID_INFO_CLASS).\n");
/* Process image mapping - Not available on Windows 2003. */
cbActual = 0;
if (NT_SUCCESS(rcNt))
else if (rcNt == STATUS_OBJECT_TYPE_MISMATCH)
RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessImageFileMapping: rcNt=%#x (STATUS_OBJECT_TYPE_MISMATCH)\n", rcNt);
else if (rcNt == STATUS_INVALID_INFO_CLASS)
RTTestIPrintf(RTTESTLVL_ALWAYS, "ProcessImageFileMapping: Not supported (STATUS_INVALID_INFO_CLASS).\n");
else
/* Handles. Broken for 64-bit input. */
cbActual = 0;
if (NT_SUCCESS(rcNt))
else
/* Execute flags. */
#if 0 /* fails... wrong process handle? */
cbActual = 0;
if (NT_SUCCESS(rcNt))
else
#endif
/** @todo ProcessImageInformation */
}
{
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
{
if (argc >= 3)
if (g_hProcess == NULL)
{
return RTTestSummaryAndDestroy(g_hTest);
}
}
return RTTestSummaryAndDestroy(g_hTest);
}