2003-03-22 00:21:35 +00:00
|
|
|
/* Unit test suite for Rtl* API functions
|
|
|
|
*
|
|
|
|
* Copyright 2003 Thomas Mertes
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-03-22 00:21:35 +00:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* We use function pointers here as there is no import library for NTDLL on
|
|
|
|
* windows.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2004-08-14 00:42:12 +00:00
|
|
|
#include "ntdll_test.h"
|
2010-08-20 03:50:19 +00:00
|
|
|
#include "inaddr.h"
|
2003-03-22 00:21:35 +00:00
|
|
|
|
2005-08-10 15:00:32 +00:00
|
|
|
#ifndef __WINE_WINTERNL_H
|
|
|
|
|
|
|
|
typedef struct _RTL_HANDLE
|
|
|
|
{
|
|
|
|
struct _RTL_HANDLE * Next;
|
|
|
|
} RTL_HANDLE;
|
|
|
|
|
|
|
|
typedef struct _RTL_HANDLE_TABLE
|
|
|
|
{
|
|
|
|
ULONG MaxHandleCount;
|
|
|
|
ULONG HandleSize;
|
|
|
|
ULONG Unused[2];
|
|
|
|
PVOID NextFree;
|
|
|
|
PVOID FirstHandle;
|
|
|
|
PVOID ReservedMemory;
|
|
|
|
PVOID MaxHandle;
|
|
|
|
} RTL_HANDLE_TABLE;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-08-20 03:50:19 +00:00
|
|
|
/* avoid #include <winsock2.h> */
|
|
|
|
#undef htons
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
#define htons(s) ((USHORT)(s))
|
|
|
|
#else /* WORDS_BIGENDIAN */
|
|
|
|
static inline USHORT __my_ushort_swap(USHORT s)
|
|
|
|
{
|
|
|
|
return (s >> 8) | (s << 8);
|
|
|
|
}
|
|
|
|
#define htons(s) __my_ushort_swap(s)
|
|
|
|
#endif /* WORDS_BIGENDIAN */
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-22 00:21:35 +00:00
|
|
|
/* Function ptrs for ntdll calls */
|
|
|
|
static HMODULE hntdll = 0;
|
2003-07-18 22:55:15 +00:00
|
|
|
static SIZE_T (WINAPI *pRtlCompareMemory)(LPCVOID,LPCVOID,SIZE_T);
|
2003-04-08 00:56:01 +00:00
|
|
|
static SIZE_T (WINAPI *pRtlCompareMemoryUlong)(PULONG, SIZE_T, ULONG);
|
2008-11-28 22:51:45 +00:00
|
|
|
static NTSTATUS (WINAPI *pRtlDeleteTimer)(HANDLE, HANDLE, HANDLE);
|
2003-07-18 22:55:15 +00:00
|
|
|
static VOID (WINAPI *pRtlMoveMemory)(LPVOID,LPCVOID,SIZE_T);
|
|
|
|
static VOID (WINAPI *pRtlFillMemory)(LPVOID,SIZE_T,BYTE);
|
|
|
|
static VOID (WINAPI *pRtlFillMemoryUlong)(LPVOID,SIZE_T,ULONG);
|
|
|
|
static VOID (WINAPI *pRtlZeroMemory)(LPVOID,SIZE_T);
|
2003-04-08 00:56:01 +00:00
|
|
|
static ULONGLONG (WINAPIV *pRtlUlonglongByteSwap)(ULONGLONG source);
|
|
|
|
static ULONG (WINAPI *pRtlUniform)(PULONG);
|
|
|
|
static ULONG (WINAPI *pRtlRandom)(PULONG);
|
|
|
|
static BOOLEAN (WINAPI *pRtlAreAllAccessesGranted)(ACCESS_MASK, ACCESS_MASK);
|
|
|
|
static BOOLEAN (WINAPI *pRtlAreAnyAccessesGranted)(ACCESS_MASK, ACCESS_MASK);
|
2003-07-18 22:55:15 +00:00
|
|
|
static DWORD (WINAPI *pRtlComputeCrc32)(DWORD,const BYTE*,INT);
|
2004-12-07 14:47:13 +00:00
|
|
|
static void (WINAPI * pRtlInitializeHandleTable)(ULONG, ULONG, RTL_HANDLE_TABLE *);
|
|
|
|
static BOOLEAN (WINAPI * pRtlIsValidIndexHandle)(const RTL_HANDLE_TABLE *, ULONG, RTL_HANDLE **);
|
|
|
|
static NTSTATUS (WINAPI * pRtlDestroyHandleTable)(RTL_HANDLE_TABLE *);
|
|
|
|
static RTL_HANDLE * (WINAPI * pRtlAllocateHandle)(RTL_HANDLE_TABLE *, ULONG *);
|
|
|
|
static BOOLEAN (WINAPI * pRtlFreeHandle)(RTL_HANDLE_TABLE *, RTL_HANDLE *);
|
2005-11-15 12:03:46 +00:00
|
|
|
static NTSTATUS (WINAPI *pRtlAllocateAndInitializeSid)(PSID_IDENTIFIER_AUTHORITY,BYTE,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,PSID*);
|
|
|
|
static NTSTATUS (WINAPI *pRtlFreeSid)(PSID);
|
2010-02-02 12:47:06 +00:00
|
|
|
static struct _TEB * (WINAPI *pNtCurrentTeb)(void);
|
|
|
|
static DWORD (WINAPI *pRtlGetThreadErrorMode)(void);
|
|
|
|
static NTSTATUS (WINAPI *pRtlSetThreadErrorMode)(DWORD, LPDWORD);
|
2010-08-20 03:50:19 +00:00
|
|
|
static IMAGE_BASE_RELOCATION *(WINAPI *pLdrProcessRelocationBlock)(void*,UINT,USHORT*,INT_PTR);
|
|
|
|
static CHAR * (WINAPI *pRtlIpv4AddressToStringA)(const IN_ADDR *, LPSTR);
|
|
|
|
static NTSTATUS (WINAPI *pRtlIpv4AddressToStringExA)(const IN_ADDR *, USHORT, LPSTR, PULONG);
|
|
|
|
|
2010-02-02 12:47:06 +00:00
|
|
|
static HMODULE hkernel32 = 0;
|
|
|
|
static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
|
2010-08-19 18:07:01 +00:00
|
|
|
|
|
|
|
|
2003-07-18 22:55:15 +00:00
|
|
|
#define LEN 16
|
|
|
|
static const char* src_src = "This is a test!"; /* 16 bytes long, incl NUL */
|
|
|
|
static ULONG src_aligned_block[4];
|
|
|
|
static ULONG dest_aligned_block[32];
|
|
|
|
static const char *src = (const char*)src_aligned_block;
|
|
|
|
static char* dest = (char*)dest_aligned_block;
|
2003-03-22 00:21:35 +00:00
|
|
|
|
|
|
|
static void InitFunctionPtrs(void)
|
|
|
|
{
|
|
|
|
hntdll = LoadLibraryA("ntdll.dll");
|
2004-02-07 01:03:17 +00:00
|
|
|
ok(hntdll != 0, "LoadLibrary failed\n");
|
2003-03-22 00:21:35 +00:00
|
|
|
if (hntdll) {
|
2003-07-18 22:55:15 +00:00
|
|
|
pRtlCompareMemory = (void *)GetProcAddress(hntdll, "RtlCompareMemory");
|
2003-03-22 00:21:35 +00:00
|
|
|
pRtlCompareMemoryUlong = (void *)GetProcAddress(hntdll, "RtlCompareMemoryUlong");
|
2008-11-28 22:51:45 +00:00
|
|
|
pRtlDeleteTimer = (void *)GetProcAddress(hntdll, "RtlDeleteTimer");
|
2003-07-18 22:55:15 +00:00
|
|
|
pRtlMoveMemory = (void *)GetProcAddress(hntdll, "RtlMoveMemory");
|
|
|
|
pRtlFillMemory = (void *)GetProcAddress(hntdll, "RtlFillMemory");
|
|
|
|
pRtlFillMemoryUlong = (void *)GetProcAddress(hntdll, "RtlFillMemoryUlong");
|
|
|
|
pRtlZeroMemory = (void *)GetProcAddress(hntdll, "RtlZeroMemory");
|
2003-04-08 00:56:01 +00:00
|
|
|
pRtlUlonglongByteSwap = (void *)GetProcAddress(hntdll, "RtlUlonglongByteSwap");
|
2003-03-22 00:21:35 +00:00
|
|
|
pRtlUniform = (void *)GetProcAddress(hntdll, "RtlUniform");
|
2003-04-08 00:56:01 +00:00
|
|
|
pRtlRandom = (void *)GetProcAddress(hntdll, "RtlRandom");
|
|
|
|
pRtlAreAllAccessesGranted = (void *)GetProcAddress(hntdll, "RtlAreAllAccessesGranted");
|
|
|
|
pRtlAreAnyAccessesGranted = (void *)GetProcAddress(hntdll, "RtlAreAnyAccessesGranted");
|
2003-07-18 22:55:15 +00:00
|
|
|
pRtlComputeCrc32 = (void *)GetProcAddress(hntdll, "RtlComputeCrc32");
|
2004-12-07 14:47:13 +00:00
|
|
|
pRtlInitializeHandleTable = (void *)GetProcAddress(hntdll, "RtlInitializeHandleTable");
|
|
|
|
pRtlIsValidIndexHandle = (void *)GetProcAddress(hntdll, "RtlIsValidIndexHandle");
|
|
|
|
pRtlDestroyHandleTable = (void *)GetProcAddress(hntdll, "RtlDestroyHandleTable");
|
|
|
|
pRtlAllocateHandle = (void *)GetProcAddress(hntdll, "RtlAllocateHandle");
|
|
|
|
pRtlFreeHandle = (void *)GetProcAddress(hntdll, "RtlFreeHandle");
|
2005-11-15 12:03:46 +00:00
|
|
|
pRtlAllocateAndInitializeSid = (void *)GetProcAddress(hntdll, "RtlAllocateAndInitializeSid");
|
|
|
|
pRtlFreeSid = (void *)GetProcAddress(hntdll, "RtlFreeSid");
|
2010-02-02 12:47:06 +00:00
|
|
|
pNtCurrentTeb = (void *)GetProcAddress(hntdll, "NtCurrentTeb");
|
|
|
|
pRtlGetThreadErrorMode = (void *)GetProcAddress(hntdll, "RtlGetThreadErrorMode");
|
|
|
|
pRtlSetThreadErrorMode = (void *)GetProcAddress(hntdll, "RtlSetThreadErrorMode");
|
2010-08-19 18:07:01 +00:00
|
|
|
pLdrProcessRelocationBlock = (void *)GetProcAddress(hntdll, "LdrProcessRelocationBlock");
|
2010-08-20 03:50:19 +00:00
|
|
|
pRtlIpv4AddressToStringA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringA");
|
|
|
|
pRtlIpv4AddressToStringExA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringExA");
|
2010-02-02 12:47:06 +00:00
|
|
|
}
|
|
|
|
hkernel32 = LoadLibraryA("kernel32.dll");
|
|
|
|
ok(hkernel32 != 0, "LoadLibrary failed\n");
|
|
|
|
if (hkernel32) {
|
|
|
|
pIsWow64Process = (void *)GetProcAddress(hkernel32, "IsWow64Process");
|
2003-07-18 22:55:15 +00:00
|
|
|
}
|
|
|
|
strcpy((char*)src_aligned_block, src_src);
|
|
|
|
ok(strlen(src) == 15, "Source must be 16 bytes long!\n");
|
2003-03-22 00:21:35 +00:00
|
|
|
}
|
|
|
|
|
2003-07-18 22:55:15 +00:00
|
|
|
#define COMP(str1,str2,cmplen,len) size = pRtlCompareMemory(str1, str2, cmplen); \
|
|
|
|
ok(size == len, "Expected %ld, got %ld\n", size, (SIZE_T)len)
|
|
|
|
|
|
|
|
static void test_RtlCompareMemory(void)
|
|
|
|
{
|
|
|
|
SIZE_T size;
|
|
|
|
|
|
|
|
if (!pRtlCompareMemory)
|
2010-01-13 12:44:44 +00:00
|
|
|
{
|
|
|
|
win_skip("RtlCompareMemory is not available\n");
|
2003-07-18 22:55:15 +00:00
|
|
|
return;
|
2010-01-13 12:44:44 +00:00
|
|
|
}
|
2003-07-18 22:55:15 +00:00
|
|
|
|
|
|
|
strcpy(dest, src);
|
|
|
|
|
|
|
|
COMP(src,src,0,0);
|
|
|
|
COMP(src,src,LEN,LEN);
|
|
|
|
dest[0] = 'x';
|
|
|
|
COMP(src,dest,LEN,0);
|
|
|
|
}
|
2003-03-22 00:21:35 +00:00
|
|
|
|
|
|
|
static void test_RtlCompareMemoryUlong(void)
|
|
|
|
{
|
|
|
|
ULONG a[10];
|
|
|
|
ULONG result;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if (!pRtlCompareMemoryUlong)
|
|
|
|
{
|
|
|
|
win_skip("RtlCompareMemoryUlong is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-22 00:21:35 +00:00
|
|
|
a[0]= 0x0123;
|
|
|
|
a[1]= 0x4567;
|
|
|
|
a[2]= 0x89ab;
|
|
|
|
a[3]= 0xcdef;
|
|
|
|
result = pRtlCompareMemoryUlong(a, 0, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 0, "RtlCompareMemoryUlong(%p, 0, 0x0123) returns %u, expected 0\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 3, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %u, expected 0\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 4, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 5, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 7, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 8, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 9, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 4, 0x0127);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 0, "RtlCompareMemoryUlong(%p, 4, 0x0127) returns %u, expected 0\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 4, 0x7123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 0, "RtlCompareMemoryUlong(%p, 4, 0x7123) returns %u, expected 0\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 16, 0x4567);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 0, "RtlCompareMemoryUlong(%p, 16, 0x4567) returns %u, expected 0\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
|
|
|
|
a[1]= 0x0123;
|
|
|
|
result = pRtlCompareMemoryUlong(a, 3, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 0, "RtlCompareMemoryUlong(%p, 3, 0x0123) returns %u, expected 0\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 4, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 4, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 5, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 5, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 7, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 4, "RtlCompareMemoryUlong(%p, 7, 0x0123) returns %u, expected 4\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 8, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 8, "RtlCompareMemoryUlong(%p, 8, 0x0123) returns %u, expected 8\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
result = pRtlCompareMemoryUlong(a, 9, 0x0123);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(result == 8, "RtlCompareMemoryUlong(%p, 9, 0x0123) returns %u, expected 8\n", a, result);
|
2003-03-22 00:21:35 +00:00
|
|
|
}
|
|
|
|
|
2003-07-18 22:55:15 +00:00
|
|
|
#define COPY(len) memset(dest,0,sizeof(dest_aligned_block)); pRtlMoveMemory(dest, src, len)
|
|
|
|
#define CMP(str) ok(strcmp(dest,str) == 0, "Expected '%s', got '%s'\n", str, dest)
|
|
|
|
|
|
|
|
static void test_RtlMoveMemory(void)
|
|
|
|
{
|
|
|
|
if (!pRtlMoveMemory)
|
2010-01-13 12:44:44 +00:00
|
|
|
{
|
|
|
|
win_skip("RtlMoveMemory is not available\n");
|
2003-07-18 22:55:15 +00:00
|
|
|
return;
|
2010-01-13 12:44:44 +00:00
|
|
|
}
|
2003-07-18 22:55:15 +00:00
|
|
|
|
|
|
|
/* Length should be in bytes and not rounded. Use strcmp to ensure we
|
|
|
|
* didn't write past the end (it checks for the final NUL left by memset)
|
|
|
|
*/
|
|
|
|
COPY(0); CMP("");
|
|
|
|
COPY(1); CMP("T");
|
|
|
|
COPY(2); CMP("Th");
|
|
|
|
COPY(3); CMP("Thi");
|
|
|
|
COPY(4); CMP("This");
|
|
|
|
COPY(5); CMP("This ");
|
|
|
|
COPY(6); CMP("This i");
|
|
|
|
COPY(7); CMP("This is");
|
|
|
|
COPY(8); CMP("This is ");
|
|
|
|
COPY(9); CMP("This is a");
|
|
|
|
|
|
|
|
/* Overlapping */
|
|
|
|
strcpy(dest, src); pRtlMoveMemory(dest, dest + 1, strlen(src) - 1);
|
|
|
|
CMP("his is a test!!");
|
|
|
|
strcpy(dest, src); pRtlMoveMemory(dest + 1, dest, strlen(src));
|
|
|
|
CMP("TThis is a test!");
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemory(dest,len,'x')
|
|
|
|
|
|
|
|
static void test_RtlFillMemory(void)
|
|
|
|
{
|
|
|
|
if (!pRtlFillMemory)
|
2010-01-13 12:44:44 +00:00
|
|
|
{
|
|
|
|
win_skip("RtlFillMemory is not available\n");
|
2003-07-18 22:55:15 +00:00
|
|
|
return;
|
2010-01-13 12:44:44 +00:00
|
|
|
}
|
2003-07-18 22:55:15 +00:00
|
|
|
|
|
|
|
/* Length should be in bytes and not rounded. Use strcmp to ensure we
|
|
|
|
* didn't write past the end (the remainder of the string should match)
|
|
|
|
*/
|
|
|
|
FILL(0); CMP("This is a test!");
|
|
|
|
FILL(1); CMP("xhis is a test!");
|
|
|
|
FILL(2); CMP("xxis is a test!");
|
|
|
|
FILL(3); CMP("xxxs is a test!");
|
|
|
|
FILL(4); CMP("xxxx is a test!");
|
|
|
|
FILL(5); CMP("xxxxxis a test!");
|
|
|
|
FILL(6); CMP("xxxxxxs a test!");
|
|
|
|
FILL(7); CMP("xxxxxxx a test!");
|
|
|
|
FILL(8); CMP("xxxxxxxxa test!");
|
|
|
|
FILL(9); CMP("xxxxxxxxx test!");
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LFILL(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlFillMemoryUlong(dest,len,val)
|
|
|
|
|
|
|
|
static void test_RtlFillMemoryUlong(void)
|
|
|
|
{
|
|
|
|
ULONG val = ('x' << 24) | ('x' << 16) | ('x' << 8) | 'x';
|
|
|
|
if (!pRtlFillMemoryUlong)
|
2010-01-13 12:44:44 +00:00
|
|
|
{
|
|
|
|
win_skip("RtlFillMemoryUlong is not available\n");
|
2003-07-18 22:55:15 +00:00
|
|
|
return;
|
2010-01-13 12:44:44 +00:00
|
|
|
}
|
2003-07-18 22:55:15 +00:00
|
|
|
|
|
|
|
/* Length should be in bytes and not rounded. Use strcmp to ensure we
|
|
|
|
* didn't write past the end (the remainder of the string should match)
|
|
|
|
*/
|
|
|
|
LFILL(0); CMP("This is a test!");
|
|
|
|
LFILL(1); CMP("This is a test!");
|
|
|
|
LFILL(2); CMP("This is a test!");
|
|
|
|
LFILL(3); CMP("This is a test!");
|
|
|
|
LFILL(4); CMP("xxxx is a test!");
|
|
|
|
LFILL(5); CMP("xxxx is a test!");
|
|
|
|
LFILL(6); CMP("xxxx is a test!");
|
|
|
|
LFILL(7); CMP("xxxx is a test!");
|
|
|
|
LFILL(8); CMP("xxxxxxxxa test!");
|
|
|
|
LFILL(9); CMP("xxxxxxxxa test!");
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ZERO(len) memset(dest,0,sizeof(dest_aligned_block)); strcpy(dest, src); pRtlZeroMemory(dest,len)
|
|
|
|
#define MCMP(str) ok(memcmp(dest,str,LEN) == 0, "Memcmp failed\n")
|
|
|
|
|
|
|
|
static void test_RtlZeroMemory(void)
|
|
|
|
{
|
|
|
|
if (!pRtlZeroMemory)
|
2010-01-13 12:44:44 +00:00
|
|
|
{
|
|
|
|
win_skip("RtlZeroMemory is not available\n");
|
2003-07-18 22:55:15 +00:00
|
|
|
return;
|
2010-01-13 12:44:44 +00:00
|
|
|
}
|
2003-07-18 22:55:15 +00:00
|
|
|
|
|
|
|
/* Length should be in bytes and not rounded. */
|
|
|
|
ZERO(0); MCMP("This is a test!");
|
|
|
|
ZERO(1); MCMP("\0his is a test!");
|
|
|
|
ZERO(2); MCMP("\0\0is is a test!");
|
|
|
|
ZERO(3); MCMP("\0\0\0s is a test!");
|
|
|
|
ZERO(4); MCMP("\0\0\0\0 is a test!");
|
|
|
|
ZERO(5); MCMP("\0\0\0\0\0is a test!");
|
|
|
|
ZERO(6); MCMP("\0\0\0\0\0\0s a test!");
|
|
|
|
ZERO(7); MCMP("\0\0\0\0\0\0\0 a test!");
|
|
|
|
ZERO(8); MCMP("\0\0\0\0\0\0\0\0a test!");
|
|
|
|
ZERO(9); MCMP("\0\0\0\0\0\0\0\0\0 test!");
|
|
|
|
}
|
2003-03-22 00:21:35 +00:00
|
|
|
|
2003-04-08 00:56:01 +00:00
|
|
|
static void test_RtlUlonglongByteSwap(void)
|
|
|
|
{
|
|
|
|
ULONGLONG result;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if ( !pRtlUlonglongByteSwap )
|
|
|
|
{
|
|
|
|
win_skip("RtlUlonglongByteSwap is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-02 04:21:17 +00:00
|
|
|
if ( pRtlUlonglongByteSwap( 0 ) != 0 )
|
|
|
|
{
|
|
|
|
win_skip("Broken RtlUlonglongByteSwap in win2k\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-08-06 22:09:11 +00:00
|
|
|
result = pRtlUlonglongByteSwap( ((ULONGLONG)0x76543210 << 32) | 0x87654321 );
|
|
|
|
ok( (((ULONGLONG)0x21436587 << 32) | 0x10325476) == result,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUlonglongByteSwap(0x7654321087654321) returns 0x%x%08x, expected 0x2143658710325476\n",
|
2006-08-22 22:16:51 +00:00
|
|
|
(DWORD)(result >> 32), (DWORD)result);
|
2003-04-08 00:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-22 00:21:35 +00:00
|
|
|
static void test_RtlUniform(void)
|
|
|
|
{
|
|
|
|
ULONGLONG num;
|
|
|
|
ULONG seed;
|
|
|
|
ULONG seed_bak;
|
|
|
|
ULONG expected;
|
|
|
|
ULONG result;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if (!pRtlUniform)
|
|
|
|
{
|
|
|
|
win_skip("RtlUniform is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-22 00:21:35 +00:00
|
|
|
/*
|
|
|
|
* According to the documentation RtlUniform is using D.H. Lehmer's 1948
|
|
|
|
* algorithm. This algorithm is:
|
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + const_2) % const_3;
|
|
|
|
*
|
|
|
|
* According to the documentation the random number is distributed over
|
|
|
|
* [0..MAXLONG]. Therefore const_3 is MAXLONG + 1:
|
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + const_2) % (MAXLONG + 1);
|
|
|
|
*
|
2003-04-08 00:56:01 +00:00
|
|
|
* Because MAXLONG is 0x7fffffff (and MAXLONG + 1 is 0x80000000) the
|
|
|
|
* algorithm can be expressed without division as:
|
2003-03-22 00:21:35 +00:00
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + const_2) & MAXLONG;
|
|
|
|
*
|
|
|
|
* To find out const_2 we just call RtlUniform with seed set to 0:
|
|
|
|
*/
|
|
|
|
seed = 0;
|
|
|
|
expected = 0x7fffffc3;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 0)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
/*
|
|
|
|
* The algorithm is now:
|
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + 0x7fffffc3) & MAXLONG;
|
|
|
|
*
|
|
|
|
* To find out const_1 we can use:
|
|
|
|
*
|
|
|
|
* const_1 = RtlUniform(1) - 0x7fffffc3;
|
|
|
|
*
|
|
|
|
* If that does not work a search loop can try all possible values of
|
|
|
|
* const_1 and compare to the result to RtlUniform(1).
|
|
|
|
* This way we find out that const_1 is 0xffffffed.
|
|
|
|
*
|
|
|
|
* For seed = 1 the const_2 is 0x7fffffc4:
|
|
|
|
*/
|
|
|
|
seed = 1;
|
|
|
|
expected = seed * 0xffffffed + 0x7fffffc3 + 1;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 1)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
/*
|
|
|
|
* For seed = 2 the const_2 is 0x7fffffc3:
|
|
|
|
*/
|
|
|
|
seed = 2;
|
|
|
|
expected = seed * 0xffffffed + 0x7fffffc3;
|
|
|
|
result = pRtlUniform(&seed);
|
2007-01-09 18:49:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Windows Vista uses different algorithms, so skip the rest of the tests
|
|
|
|
* until that is figured out. Trace output for the failures is about 10.5 MB!
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (result == 0x7fffff9f) {
|
2007-08-21 10:09:40 +00:00
|
|
|
skip("Most likely running on Windows Vista which uses a different algorithm\n");
|
2007-01-09 18:49:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-22 00:21:35 +00:00
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 2)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
2007-01-09 18:49:26 +00:00
|
|
|
|
2003-03-22 00:21:35 +00:00
|
|
|
/*
|
|
|
|
* More tests show that if seed is odd the result must be incremented by 1:
|
|
|
|
*/
|
|
|
|
seed = 3;
|
|
|
|
expected = seed * 0xffffffed + 0x7fffffc3 + (seed & 1);
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-12-06 13:43:33 +00:00
|
|
|
"RtlUniform(&seed (seed == 3)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
|
|
|
|
seed = 0x6bca1aa;
|
|
|
|
expected = seed * 0xffffffed + 0x7fffffc3;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 0x6bca1aa)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
|
|
|
|
seed = 0x6bca1ab;
|
|
|
|
expected = seed * 0xffffffed + 0x7fffffc3 + 1;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 0x6bca1ab)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
/*
|
|
|
|
* When seed is 0x6bca1ac there is an exception:
|
|
|
|
*/
|
|
|
|
seed = 0x6bca1ac;
|
|
|
|
expected = seed * 0xffffffed + 0x7fffffc3 + 2;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 0x6bca1ac)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
/*
|
|
|
|
* Note that up to here const_3 is not used
|
|
|
|
* (the highest bit of the result is not set).
|
|
|
|
*
|
|
|
|
* Starting with 0x6bca1ad: If seed is even the result must be incremented by 1:
|
|
|
|
*/
|
|
|
|
seed = 0x6bca1ad;
|
|
|
|
expected = (seed * 0xffffffed + 0x7fffffc3) & MAXLONG;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 0x6bca1ad)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
|
|
|
|
seed = 0x6bca1ae;
|
|
|
|
expected = (seed * 0xffffffed + 0x7fffffc3 + 1) & MAXLONG;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlUniform(&seed (seed == 0x6bca1ae)) returns %x, expected %x\n",
|
2003-03-22 00:21:35 +00:00
|
|
|
result, expected);
|
|
|
|
/*
|
|
|
|
* There are several ranges where for odd or even seed the result must be
|
|
|
|
* incremented by 1. You can see this ranges in the following test.
|
|
|
|
*
|
|
|
|
* For a full test use one of the following loop heads:
|
|
|
|
*
|
|
|
|
* for (num = 0; num <= 0xffffffff; num++) {
|
|
|
|
* seed = num;
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* seed = 0;
|
|
|
|
* for (num = 0; num <= 0xffffffff; num++) {
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
seed = 0;
|
|
|
|
for (num = 0; num <= 100000; num++) {
|
|
|
|
|
|
|
|
expected = seed * 0xffffffed + 0x7fffffc3;
|
|
|
|
if (seed < 0x6bca1ac) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed == 0x6bca1ac) {
|
|
|
|
expected = (expected + 2) & MAXLONG;
|
|
|
|
} else if (seed < 0xd79435c) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x1435e50b) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x1af286ba) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x21af2869) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x286bca18) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x2f286bc7) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x35e50d77) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x3ca1af26) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x435e50d5) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x4a1af284) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x50d79433) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x579435e2) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x5e50d792) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x650d7941) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x6bca1af0) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x7286bc9f) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x79435e4e) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x7ffffffd) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x86bca1ac) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed == 0x86bca1ac) {
|
|
|
|
expected = (expected + 1) & MAXLONG;
|
|
|
|
} else if (seed < 0x8d79435c) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0x9435e50b) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0x9af286ba) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xa1af2869) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0xa86bca18) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xaf286bc7) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed == 0xaf286bc7) {
|
|
|
|
expected = (expected + 2) & MAXLONG;
|
|
|
|
} else if (seed < 0xb5e50d77) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xbca1af26) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0xc35e50d5) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xca1af284) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0xd0d79433) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xd79435e2) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0xde50d792) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xe50d7941) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0xebca1af0) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xf286bc9f) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else if (seed < 0xf9435e4e) {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} else if (seed < 0xfffffffd) {
|
|
|
|
expected = (expected + (~seed & 1)) & MAXLONG;
|
|
|
|
} else {
|
|
|
|
expected = expected + (seed & 1);
|
|
|
|
} /* if */
|
|
|
|
seed_bak = seed;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"test: 0x%x%08x RtlUniform(&seed (seed == %x)) returns %x, expected %x\n",
|
2006-08-22 22:16:51 +00:00
|
|
|
(DWORD)(num >> 32), (DWORD)num, seed_bak, result, expected);
|
2003-03-22 00:21:35 +00:00
|
|
|
ok(seed == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"test: 0x%x%08x RtlUniform(&seed (seed == %x)) sets seed to %x, expected %x\n",
|
2006-08-22 22:16:51 +00:00
|
|
|
(DWORD)(num >> 32), (DWORD)num, seed_bak, result, expected);
|
2003-03-22 00:21:35 +00:00
|
|
|
} /* for */
|
|
|
|
/*
|
|
|
|
* Further investigation shows: In the different regions the highest bit
|
|
|
|
* is set or cleared when even or odd seeds need an increment by 1.
|
2003-04-08 00:56:01 +00:00
|
|
|
* This leads to a simplified algorithm:
|
|
|
|
*
|
|
|
|
* seed = seed * 0xffffffed + 0x7fffffc3;
|
|
|
|
* if (seed == 0xffffffff || seed == 0x7ffffffe) {
|
|
|
|
* seed = (seed + 2) & MAXLONG;
|
|
|
|
* } else if (seed == 0x7fffffff) {
|
|
|
|
* seed = 0;
|
|
|
|
* } else if ((seed & 0x80000000) == 0) {
|
|
|
|
* seed = seed + (~seed & 1);
|
|
|
|
* } else {
|
|
|
|
* seed = (seed + (seed & 1)) & MAXLONG;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* This is also the algorithm used for RtlUniform of wine (see dlls/ntdll/rtl.c).
|
|
|
|
*
|
|
|
|
* Now comes the funny part:
|
|
|
|
* It took me one weekend, to find the complicated algorithm and one day more,
|
|
|
|
* to find the simplified algorithm. Several weeks later I found out: The value
|
2004-02-09 22:07:42 +00:00
|
|
|
* MAXLONG (=0x7fffffff) is never returned, neither with the native function
|
2003-04-08 00:56:01 +00:00
|
|
|
* nor with the simplified algorithm. In reality the native function and our
|
|
|
|
* function return a random number distributed over [0..MAXLONG-1]. Note
|
2004-07-23 23:02:09 +00:00
|
|
|
* that this is different from what native documentation states [0..MAXLONG].
|
2003-04-08 00:56:01 +00:00
|
|
|
* Expressed with D.H. Lehmer's 1948 algorithm it looks like:
|
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + const_2) % MAXLONG;
|
|
|
|
*
|
|
|
|
* Further investigations show that the real algorithm is:
|
|
|
|
*
|
|
|
|
* seed = (seed * 0x7fffffed + 0x7fffffc3) % MAXLONG;
|
|
|
|
*
|
|
|
|
* This is checked with the test below:
|
|
|
|
*/
|
|
|
|
seed = 0;
|
|
|
|
for (num = 0; num <= 100000; num++) {
|
|
|
|
expected = (seed * 0x7fffffed + 0x7fffffc3) % 0x7fffffff;
|
|
|
|
seed_bak = seed;
|
|
|
|
result = pRtlUniform(&seed);
|
|
|
|
ok(result == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"test: 0x%x%08x RtlUniform(&seed (seed == %x)) returns %x, expected %x\n",
|
2006-08-22 22:16:51 +00:00
|
|
|
(DWORD)(num >> 32), (DWORD)num, seed_bak, result, expected);
|
2003-04-08 00:56:01 +00:00
|
|
|
ok(seed == expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"test: 0x%x%08x RtlUniform(&seed (seed == %x)) sets seed to %x, expected %x\n",
|
2006-08-22 22:16:51 +00:00
|
|
|
(DWORD)(num >> 32), (DWORD)num, seed_bak, result, expected);
|
2003-04-08 00:56:01 +00:00
|
|
|
} /* for */
|
|
|
|
/*
|
|
|
|
* More tests show that RtlUniform does not return 0x7ffffffd for seed values
|
|
|
|
* in the range [0..MAXLONG-1]. Additionally 2 is returned twice. This shows
|
|
|
|
* that there is more than one cycle of generated randon numbers ...
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-12 11:30:08 +00:00
|
|
|
static ULONG my_RtlRandom(PULONG seed)
|
2003-04-08 00:56:01 +00:00
|
|
|
{
|
|
|
|
static ULONG saved_value[128] =
|
|
|
|
{ /* 0 */ 0x4c8bc0aa, 0x4c022957, 0x2232827a, 0x2f1e7626, 0x7f8bdafb, 0x5c37d02a, 0x0ab48f72, 0x2f0c4ffa,
|
|
|
|
/* 8 */ 0x290e1954, 0x6b635f23, 0x5d3885c0, 0x74b49ff8, 0x5155fa54, 0x6214ad3f, 0x111e9c29, 0x242a3a09,
|
|
|
|
/* 16 */ 0x75932ae1, 0x40ac432e, 0x54f7ba7a, 0x585ccbd5, 0x6df5c727, 0x0374dad1, 0x7112b3f1, 0x735fc311,
|
|
|
|
/* 24 */ 0x404331a9, 0x74d97781, 0x64495118, 0x323e04be, 0x5974b425, 0x4862e393, 0x62389c1d, 0x28a68b82,
|
|
|
|
/* 32 */ 0x0f95da37, 0x7a50bbc6, 0x09b0091c, 0x22cdb7b4, 0x4faaed26, 0x66417ccd, 0x189e4bfa, 0x1ce4e8dd,
|
|
|
|
/* 40 */ 0x5274c742, 0x3bdcf4dc, 0x2d94e907, 0x32eac016, 0x26d33ca3, 0x60415a8a, 0x31f57880, 0x68c8aa52,
|
|
|
|
/* 48 */ 0x23eb16da, 0x6204f4a1, 0x373927c1, 0x0d24eb7c, 0x06dd7379, 0x2b3be507, 0x0f9c55b1, 0x2c7925eb,
|
|
|
|
/* 56 */ 0x36d67c9a, 0x42f831d9, 0x5e3961cb, 0x65d637a8, 0x24bb3820, 0x4d08e33d, 0x2188754f, 0x147e409e,
|
|
|
|
/* 64 */ 0x6a9620a0, 0x62e26657, 0x7bd8ce81, 0x11da0abb, 0x5f9e7b50, 0x23e444b6, 0x25920c78, 0x5fc894f0,
|
|
|
|
/* 72 */ 0x5e338cbb, 0x404237fd, 0x1d60f80f, 0x320a1743, 0x76013d2b, 0x070294ee, 0x695e243b, 0x56b177fd,
|
|
|
|
/* 80 */ 0x752492e1, 0x6decd52f, 0x125f5219, 0x139d2e78, 0x1898d11e, 0x2f7ee785, 0x4db405d8, 0x1a028a35,
|
|
|
|
/* 88 */ 0x63f6f323, 0x1f6d0078, 0x307cfd67, 0x3f32a78a, 0x6980796c, 0x462b3d83, 0x34b639f2, 0x53fce379,
|
|
|
|
/* 96 */ 0x74ba50f4, 0x1abc2c4b, 0x5eeaeb8d, 0x335a7a0d, 0x3973dd20, 0x0462d66b, 0x159813ff, 0x1e4643fd,
|
|
|
|
/* 104 */ 0x06bc5c62, 0x3115e3fc, 0x09101613, 0x47af2515, 0x4f11ec54, 0x78b99911, 0x3db8dd44, 0x1ec10b9b,
|
|
|
|
/* 112 */ 0x5b5506ca, 0x773ce092, 0x567be81a, 0x5475b975, 0x7a2cde1a, 0x494536f5, 0x34737bb4, 0x76d9750b,
|
|
|
|
/* 120 */ 0x2a1f6232, 0x2e49644d, 0x7dddcbe7, 0x500cebdb, 0x619dab9e, 0x48c626fe, 0x1cda3193, 0x52dabe9d };
|
|
|
|
ULONG rand;
|
|
|
|
int pos;
|
|
|
|
ULONG result;
|
|
|
|
|
|
|
|
rand = (*seed * 0x7fffffed + 0x7fffffc3) % 0x7fffffff;
|
|
|
|
*seed = (rand * 0x7fffffed + 0x7fffffc3) % 0x7fffffff;
|
|
|
|
pos = *seed & 0x7f;
|
|
|
|
result = saved_value[pos];
|
|
|
|
saved_value[pos] = rand;
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void test_RtlRandom(void)
|
|
|
|
{
|
|
|
|
ULONGLONG num;
|
|
|
|
ULONG seed;
|
|
|
|
ULONG seed_bak;
|
|
|
|
ULONG seed_expected;
|
|
|
|
ULONG result;
|
|
|
|
ULONG result_expected;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if (!pRtlRandom)
|
|
|
|
{
|
|
|
|
win_skip("RtlRandom is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-08 00:56:01 +00:00
|
|
|
/*
|
|
|
|
* Unlike RtlUniform, RtlRandom is not documented. We guess that for
|
|
|
|
* RtlRandom D.H. Lehmer's 1948 algorithm is used like stated in
|
|
|
|
* the documentation of the RtlUniform function. This algorithm is:
|
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + const_2) % const_3;
|
|
|
|
*
|
|
|
|
* According to the RtlUniform documentation the random number is
|
|
|
|
* distributed over [0..MAXLONG], but in reality it is distributed
|
|
|
|
* over [0..MAXLONG-1]. Therefore const_3 might be MAXLONG + 1 or
|
|
|
|
* MAXLONG:
|
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + const_2) % (MAXLONG + 1);
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* seed = (seed * const_1 + const_2) % MAXLONG;
|
|
|
|
*
|
|
|
|
* To find out const_2 we just call RtlRandom with seed set to 0:
|
|
|
|
*/
|
|
|
|
seed = 0;
|
|
|
|
result_expected = 0x320a1743;
|
|
|
|
seed_expected =0x44b;
|
|
|
|
result = pRtlRandom(&seed);
|
2007-01-09 18:49:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Windows Vista uses different algorithms, so skip the rest of the tests
|
|
|
|
* until that is figured out. Trace output for the failures is about 10.5 MB!
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (seed == 0x3fc) {
|
2007-08-21 10:09:40 +00:00
|
|
|
skip("Most likely running on Windows Vista which uses a different algorithm\n");
|
2007-01-09 18:49:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-08 00:56:01 +00:00
|
|
|
ok(result == result_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"pRtlRandom(&seed (seed == 0)) returns %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
result, result_expected);
|
|
|
|
ok(seed == seed_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"pRtlRandom(&seed (seed == 0)) sets seed to %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
seed, seed_expected);
|
|
|
|
/*
|
|
|
|
* Seed is not equal to result as with RtlUniform. To see more we
|
2008-04-08 21:22:43 +00:00
|
|
|
* call RtlRandom again with seed set to 0:
|
2003-04-08 00:56:01 +00:00
|
|
|
*/
|
|
|
|
seed = 0;
|
|
|
|
result_expected = 0x7fffffc3;
|
|
|
|
seed_expected =0x44b;
|
|
|
|
result = pRtlRandom(&seed);
|
|
|
|
ok(result == result_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlRandom(&seed (seed == 0)) returns %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
result, result_expected);
|
|
|
|
ok(seed == seed_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlRandom(&seed (seed == 0)) sets seed to %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
seed, seed_expected);
|
|
|
|
/*
|
|
|
|
* Seed is set to the same value as before but the result is different.
|
2008-04-21 05:17:27 +00:00
|
|
|
* To see more we call RtlRandom again with seed set to 0:
|
2003-03-22 00:21:35 +00:00
|
|
|
*/
|
2003-04-08 00:56:01 +00:00
|
|
|
seed = 0;
|
|
|
|
result_expected = 0x7fffffc3;
|
|
|
|
seed_expected =0x44b;
|
|
|
|
result = pRtlRandom(&seed);
|
|
|
|
ok(result == result_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlRandom(&seed (seed == 0)) returns %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
result, result_expected);
|
|
|
|
ok(seed == seed_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlRandom(&seed (seed == 0)) sets seed to %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
seed, seed_expected);
|
|
|
|
/*
|
2008-04-21 05:17:27 +00:00
|
|
|
* Seed is again set to the same value as before. This time we also
|
2003-04-08 00:56:01 +00:00
|
|
|
* have the same result as before. Interestingly the value of the
|
|
|
|
* result is 0x7fffffc3 which is the same value used in RtlUniform
|
|
|
|
* as const_2. If we do
|
|
|
|
*
|
|
|
|
* seed = 0;
|
|
|
|
* result = RtlUniform(&seed);
|
|
|
|
*
|
|
|
|
* we get the same result (0x7fffffc3) as with
|
|
|
|
*
|
|
|
|
* seed = 0;
|
|
|
|
* RtlRandom(&seed);
|
|
|
|
* seed = 0;
|
|
|
|
* result = RtlRandom(&seed);
|
|
|
|
*
|
|
|
|
* And there is another interesting thing. If we do
|
|
|
|
*
|
|
|
|
* seed = 0;
|
|
|
|
* RtlUniform(&seed);
|
|
|
|
* RtlUniform(&seed);
|
|
|
|
*
|
|
|
|
* seed is set to the value 0x44b which ist the same value that
|
|
|
|
*
|
|
|
|
* seed = 0;
|
|
|
|
* RtlRandom(&seed);
|
|
|
|
*
|
2004-12-20 19:27:06 +00:00
|
|
|
* assigns to seed. Putting these two findings together leads to
|
2008-04-08 21:22:43 +00:00
|
|
|
* the conclusion that RtlRandom saves the value in some variable,
|
2003-04-08 00:56:01 +00:00
|
|
|
* like in the following algorithm:
|
|
|
|
*
|
|
|
|
* result = saved_value;
|
|
|
|
* saved_value = RtlUniform(&seed);
|
|
|
|
* RtlUniform(&seed);
|
|
|
|
* return(result);
|
|
|
|
*
|
|
|
|
* Now we do further tests with seed set to 1:
|
|
|
|
*/
|
|
|
|
seed = 1;
|
|
|
|
result_expected = 0x7a50bbc6;
|
|
|
|
seed_expected =0x5a1;
|
|
|
|
result = pRtlRandom(&seed);
|
|
|
|
ok(result == result_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlRandom(&seed (seed == 1)) returns %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
result, result_expected);
|
|
|
|
ok(seed == seed_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"RtlRandom(&seed (seed == 1)) sets seed to %x, expected %x\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
seed, seed_expected);
|
|
|
|
/*
|
|
|
|
* If there is just one saved_value the result now would be
|
|
|
|
* 0x7fffffc3. From this test we can see that there is more than
|
|
|
|
* one saved_value, like with this algorithm:
|
|
|
|
*
|
|
|
|
* result = saved_value[pos];
|
|
|
|
* saved_value[pos] = RtlUniform(&seed);
|
|
|
|
* RtlUniform(&seed);
|
|
|
|
* return(result);
|
|
|
|
*
|
2004-12-20 19:27:06 +00:00
|
|
|
* But how is the value of pos determined? The calls to RtlUniform
|
2003-04-08 00:56:01 +00:00
|
|
|
* create a sequence of random numbers. Every second random number
|
|
|
|
* is put into the saved_value array and is used in some later call
|
|
|
|
* of RtlRandom as result. The only reasonable source to determine
|
|
|
|
* pos are the random numbers generated by RtlUniform which are not
|
|
|
|
* put into the saved_value array. This are the values of seed
|
2004-12-20 19:27:06 +00:00
|
|
|
* between the two calls of RtlUniform as in this algorithm:
|
2003-04-08 00:56:01 +00:00
|
|
|
*
|
|
|
|
* rand = RtlUniform(&seed);
|
|
|
|
* RtlUniform(&seed);
|
|
|
|
* pos = position(seed);
|
|
|
|
* result = saved_value[pos];
|
|
|
|
* saved_value[pos] = rand;
|
|
|
|
* return(result);
|
|
|
|
*
|
2004-12-20 19:27:06 +00:00
|
|
|
* What remains to be determined is: The size of the saved_value array,
|
2003-04-08 00:56:01 +00:00
|
|
|
* the initial values of the saved_value array and the function
|
2004-12-20 19:27:06 +00:00
|
|
|
* position(seed). These tests are not shown here.
|
|
|
|
* The result of these tests is: The size of the saved_value array
|
2003-04-08 00:56:01 +00:00
|
|
|
* is 128, the initial values can be seen in the my_RtlRandom
|
|
|
|
* function and the position(seed) function is (seed & 0x7f).
|
|
|
|
*
|
|
|
|
* For a full test of RtlRandom use one of the following loop heads:
|
|
|
|
*
|
|
|
|
* for (num = 0; num <= 0xffffffff; num++) {
|
|
|
|
* seed = num;
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* seed = 0;
|
|
|
|
* for (num = 0; num <= 0xffffffff; num++) {
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
seed = 0;
|
|
|
|
for (num = 0; num <= 100000; num++) {
|
|
|
|
seed_bak = seed;
|
|
|
|
seed_expected = seed;
|
|
|
|
result_expected = my_RtlRandom(&seed_expected);
|
|
|
|
/* The following corrections are necessary because the */
|
|
|
|
/* previous tests changed the saved_value array */
|
|
|
|
if (num == 0) {
|
|
|
|
result_expected = 0x7fffffc3;
|
|
|
|
} else if (num == 81) {
|
|
|
|
result_expected = 0x7fffffb1;
|
|
|
|
} /* if */
|
|
|
|
result = pRtlRandom(&seed);
|
|
|
|
ok(result == result_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"test: 0x%x%08x RtlUniform(&seed (seed == %x)) returns %x, expected %x\n",
|
2006-08-22 22:16:51 +00:00
|
|
|
(DWORD)(num >> 32), (DWORD)num, seed_bak, result, result_expected);
|
2003-04-08 00:56:01 +00:00
|
|
|
ok(seed == seed_expected,
|
2006-10-13 21:33:02 +00:00
|
|
|
"test: 0x%x%08x RtlUniform(&seed (seed == %x)) sets seed to %x, expected %x\n",
|
2006-08-22 22:16:51 +00:00
|
|
|
(DWORD)(num >> 32), (DWORD)num, seed_bak, result, seed_expected);
|
2003-04-08 00:56:01 +00:00
|
|
|
} /* for */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ACCESS_MASK GrantedAccess;
|
|
|
|
ACCESS_MASK DesiredAccess;
|
|
|
|
BOOLEAN result;
|
|
|
|
} all_accesses_t;
|
|
|
|
|
|
|
|
static const all_accesses_t all_accesses[] = {
|
|
|
|
{0xFEDCBA76, 0xFEDCBA76, 1},
|
|
|
|
{0x00000000, 0xFEDCBA76, 0},
|
|
|
|
{0xFEDCBA76, 0x00000000, 1},
|
|
|
|
{0x00000000, 0x00000000, 1},
|
|
|
|
{0xFEDCBA76, 0xFEDCBA70, 1},
|
|
|
|
{0xFEDCBA70, 0xFEDCBA76, 0},
|
|
|
|
{0xFEDCBA76, 0xFEDC8A76, 1},
|
|
|
|
{0xFEDC8A76, 0xFEDCBA76, 0},
|
|
|
|
{0xFEDCBA76, 0xC8C4B242, 1},
|
|
|
|
{0xC8C4B242, 0xFEDCBA76, 0},
|
|
|
|
};
|
|
|
|
#define NB_ALL_ACCESSES (sizeof(all_accesses)/sizeof(*all_accesses))
|
|
|
|
|
|
|
|
|
|
|
|
static void test_RtlAreAllAccessesGranted(void)
|
|
|
|
{
|
2006-06-13 12:03:19 +00:00
|
|
|
unsigned int test_num;
|
2003-04-08 00:56:01 +00:00
|
|
|
BOOLEAN result;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if (!pRtlAreAllAccessesGranted)
|
|
|
|
{
|
|
|
|
win_skip("RtlAreAllAccessesGranted is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-08 00:56:01 +00:00
|
|
|
for (test_num = 0; test_num < NB_ALL_ACCESSES; test_num++) {
|
|
|
|
result = pRtlAreAllAccessesGranted(all_accesses[test_num].GrantedAccess,
|
|
|
|
all_accesses[test_num].DesiredAccess);
|
|
|
|
ok(all_accesses[test_num].result == result,
|
2006-10-13 21:33:02 +00:00
|
|
|
"(test %d): RtlAreAllAccessesGranted(%08x, %08x) returns %d, expected %d\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
test_num, all_accesses[test_num].GrantedAccess,
|
|
|
|
all_accesses[test_num].DesiredAccess,
|
|
|
|
result, all_accesses[test_num].result);
|
|
|
|
} /* for */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ACCESS_MASK GrantedAccess;
|
|
|
|
ACCESS_MASK DesiredAccess;
|
|
|
|
BOOLEAN result;
|
|
|
|
} any_accesses_t;
|
|
|
|
|
|
|
|
static const any_accesses_t any_accesses[] = {
|
|
|
|
{0xFEDCBA76, 0xFEDCBA76, 1},
|
|
|
|
{0x00000000, 0xFEDCBA76, 0},
|
|
|
|
{0xFEDCBA76, 0x00000000, 0},
|
|
|
|
{0x00000000, 0x00000000, 0},
|
|
|
|
{0xFEDCBA76, 0x01234589, 0},
|
|
|
|
{0x00040000, 0xFEDCBA76, 1},
|
|
|
|
{0x00040000, 0xFED8BA76, 0},
|
|
|
|
{0xFEDCBA76, 0x00040000, 1},
|
|
|
|
{0xFED8BA76, 0x00040000, 0},
|
|
|
|
};
|
|
|
|
#define NB_ANY_ACCESSES (sizeof(any_accesses)/sizeof(*any_accesses))
|
|
|
|
|
|
|
|
|
|
|
|
static void test_RtlAreAnyAccessesGranted(void)
|
|
|
|
{
|
2006-06-13 12:03:19 +00:00
|
|
|
unsigned int test_num;
|
2003-04-08 00:56:01 +00:00
|
|
|
BOOLEAN result;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if (!pRtlAreAnyAccessesGranted)
|
|
|
|
{
|
|
|
|
win_skip("RtlAreAnyAccessesGranted is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-08 00:56:01 +00:00
|
|
|
for (test_num = 0; test_num < NB_ANY_ACCESSES; test_num++) {
|
|
|
|
result = pRtlAreAnyAccessesGranted(any_accesses[test_num].GrantedAccess,
|
|
|
|
any_accesses[test_num].DesiredAccess);
|
|
|
|
ok(any_accesses[test_num].result == result,
|
2006-10-13 21:33:02 +00:00
|
|
|
"(test %d): RtlAreAnyAccessesGranted(%08x, %08x) returns %d, expected %d\n",
|
2003-04-08 00:56:01 +00:00
|
|
|
test_num, any_accesses[test_num].GrantedAccess,
|
|
|
|
any_accesses[test_num].DesiredAccess,
|
|
|
|
result, any_accesses[test_num].result);
|
|
|
|
} /* for */
|
2003-03-22 00:21:35 +00:00
|
|
|
}
|
|
|
|
|
2005-06-16 15:52:44 +00:00
|
|
|
static void test_RtlComputeCrc32(void)
|
2003-07-18 22:55:15 +00:00
|
|
|
{
|
|
|
|
DWORD crc = 0;
|
|
|
|
|
|
|
|
if (!pRtlComputeCrc32)
|
2010-01-13 12:44:44 +00:00
|
|
|
{
|
|
|
|
win_skip("RtlComputeCrc32 is not available\n");
|
2003-07-18 22:55:15 +00:00
|
|
|
return;
|
2010-01-13 12:44:44 +00:00
|
|
|
}
|
2003-07-18 22:55:15 +00:00
|
|
|
|
2006-12-12 21:45:42 +00:00
|
|
|
crc = pRtlComputeCrc32(crc, (const BYTE *)src, LEN);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(crc == 0x40861dc2,"Expected 0x40861dc2, got %8x\n", crc);
|
2003-07-18 22:55:15 +00:00
|
|
|
}
|
2003-03-22 00:21:35 +00:00
|
|
|
|
2004-12-07 14:47:13 +00:00
|
|
|
|
|
|
|
typedef struct MY_HANDLE
|
|
|
|
{
|
|
|
|
RTL_HANDLE RtlHandle;
|
|
|
|
void * MyValue;
|
|
|
|
} MY_HANDLE;
|
|
|
|
|
|
|
|
static inline void RtlpMakeHandleAllocated(RTL_HANDLE * Handle)
|
|
|
|
{
|
|
|
|
ULONG_PTR *AllocatedBit = (ULONG_PTR *)(&Handle->Next);
|
|
|
|
*AllocatedBit = *AllocatedBit | 1;
|
|
|
|
}
|
|
|
|
|
2005-06-16 15:52:44 +00:00
|
|
|
static void test_HandleTables(void)
|
2004-12-07 14:47:13 +00:00
|
|
|
{
|
|
|
|
BOOLEAN result;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG Index;
|
|
|
|
MY_HANDLE * MyHandle;
|
|
|
|
RTL_HANDLE_TABLE HandleTable;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if (!pRtlInitializeHandleTable)
|
|
|
|
{
|
|
|
|
win_skip("RtlInitializeHandleTable is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-07 14:47:13 +00:00
|
|
|
pRtlInitializeHandleTable(0x3FFF, sizeof(MY_HANDLE), &HandleTable);
|
|
|
|
MyHandle = (MY_HANDLE *)pRtlAllocateHandle(&HandleTable, &Index);
|
|
|
|
ok(MyHandle != NULL, "RtlAllocateHandle failed\n");
|
|
|
|
RtlpMakeHandleAllocated(&MyHandle->RtlHandle);
|
|
|
|
MyHandle = NULL;
|
|
|
|
result = pRtlIsValidIndexHandle(&HandleTable, Index, (RTL_HANDLE **)&MyHandle);
|
|
|
|
ok(result, "Handle %p wasn't valid\n", MyHandle);
|
|
|
|
result = pRtlFreeHandle(&HandleTable, &MyHandle->RtlHandle);
|
|
|
|
ok(result, "Couldn't free handle %p\n", MyHandle);
|
|
|
|
status = pRtlDestroyHandleTable(&HandleTable);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(status == STATUS_SUCCESS, "RtlDestroyHandleTable failed with error 0x%08x\n", status);
|
2004-12-07 14:47:13 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 12:03:46 +00:00
|
|
|
static void test_RtlAllocateAndInitializeSid(void)
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
SID_IDENTIFIER_AUTHORITY sia = {{ 1, 2, 3, 4, 5, 6 }};
|
|
|
|
PSID psid;
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
if (!pRtlAllocateAndInitializeSid)
|
|
|
|
{
|
|
|
|
win_skip("RtlAllocateAndInitializeSid is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-15 12:03:46 +00:00
|
|
|
ret = pRtlAllocateAndInitializeSid(&sia, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(!ret, "RtlAllocateAndInitializeSid error %08x\n", ret);
|
2005-11-15 12:03:46 +00:00
|
|
|
ret = pRtlFreeSid(psid);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(!ret, "RtlFreeSid error %08x\n", ret);
|
2005-11-15 12:03:46 +00:00
|
|
|
|
2010-01-13 12:44:53 +00:00
|
|
|
/* these tests crash on XP */
|
|
|
|
if (0)
|
|
|
|
{
|
2011-02-10 23:15:39 +00:00
|
|
|
pRtlAllocateAndInitializeSid(NULL, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid);
|
|
|
|
pRtlAllocateAndInitializeSid(&sia, 0, 1, 2, 3, 4, 5, 6, 7, 8, NULL);
|
2010-01-13 12:44:53 +00:00
|
|
|
}
|
2005-11-15 12:03:46 +00:00
|
|
|
|
|
|
|
ret = pRtlAllocateAndInitializeSid(&sia, 9, 1, 2, 3, 4, 5, 6, 7, 8, &psid);
|
2006-10-13 21:33:02 +00:00
|
|
|
ok(ret == STATUS_INVALID_SID, "wrong error %08x\n", ret);
|
2005-11-15 12:03:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-28 22:51:45 +00:00
|
|
|
static void test_RtlDeleteTimer(void)
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
2010-01-13 12:44:44 +00:00
|
|
|
|
|
|
|
if (!pRtlDeleteTimer)
|
|
|
|
{
|
|
|
|
win_skip("RtlDeleteTimer is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-28 22:51:45 +00:00
|
|
|
ret = pRtlDeleteTimer(NULL, NULL, NULL);
|
2008-12-01 16:34:48 +00:00
|
|
|
ok(ret == STATUS_INVALID_PARAMETER_1 ||
|
|
|
|
ret == STATUS_INVALID_PARAMETER, /* W2K */
|
|
|
|
"expected STATUS_INVALID_PARAMETER_1 or STATUS_INVALID_PARAMETER, got %x\n", ret);
|
2008-11-28 22:51:45 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 12:47:06 +00:00
|
|
|
static void test_RtlThreadErrorMode(void)
|
|
|
|
{
|
|
|
|
DWORD oldmode;
|
|
|
|
BOOL is_wow64;
|
|
|
|
DWORD mode;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!pRtlGetThreadErrorMode || !pRtlSetThreadErrorMode)
|
|
|
|
{
|
2010-02-02 12:50:16 +00:00
|
|
|
win_skip("RtlGetThreadErrorMode and/or RtlSetThreadErrorMode not available\n");
|
2010-02-02 12:47:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pIsWow64Process || !pIsWow64Process(GetCurrentProcess(), &is_wow64))
|
|
|
|
is_wow64 = FALSE;
|
|
|
|
|
|
|
|
oldmode = pRtlGetThreadErrorMode();
|
|
|
|
|
|
|
|
status = pRtlSetThreadErrorMode(0x70, &mode);
|
|
|
|
ok(status == STATUS_SUCCESS ||
|
|
|
|
status == STATUS_WAIT_1, /* Vista */
|
|
|
|
"RtlSetThreadErrorMode failed with error 0x%08x\n", status);
|
|
|
|
ok(mode == oldmode,
|
|
|
|
"RtlSetThreadErrorMode returned mode 0x%x, expected 0x%x\n",
|
|
|
|
mode, oldmode);
|
|
|
|
ok(pRtlGetThreadErrorMode() == 0x70,
|
|
|
|
"RtlGetThreadErrorMode returned 0x%x, expected 0x%x\n", mode, 0x70);
|
|
|
|
if (!is_wow64 && pNtCurrentTeb)
|
|
|
|
ok(pNtCurrentTeb()->HardErrorDisabled == 0x70,
|
|
|
|
"The TEB contains 0x%x, expected 0x%x\n",
|
|
|
|
pNtCurrentTeb()->HardErrorDisabled, 0x70);
|
|
|
|
|
|
|
|
status = pRtlSetThreadErrorMode(0, &mode);
|
|
|
|
ok(status == STATUS_SUCCESS ||
|
|
|
|
status == STATUS_WAIT_1, /* Vista */
|
|
|
|
"RtlSetThreadErrorMode failed with error 0x%08x\n", status);
|
|
|
|
ok(mode == 0x70,
|
|
|
|
"RtlSetThreadErrorMode returned mode 0x%x, expected 0x%x\n",
|
|
|
|
mode, 0x70);
|
|
|
|
ok(pRtlGetThreadErrorMode() == 0,
|
|
|
|
"RtlGetThreadErrorMode returned 0x%x, expected 0x%x\n", mode, 0);
|
|
|
|
if (!is_wow64 && pNtCurrentTeb)
|
|
|
|
ok(pNtCurrentTeb()->HardErrorDisabled == 0,
|
|
|
|
"The TEB contains 0x%x, expected 0x%x\n",
|
|
|
|
pNtCurrentTeb()->HardErrorDisabled, 0);
|
|
|
|
|
|
|
|
for (mode = 1; mode; mode <<= 1)
|
|
|
|
{
|
|
|
|
status = pRtlSetThreadErrorMode(mode, NULL);
|
|
|
|
if (mode & 0x70)
|
|
|
|
ok(status == STATUS_SUCCESS ||
|
|
|
|
status == STATUS_WAIT_1, /* Vista */
|
|
|
|
"RtlSetThreadErrorMode(%x,NULL) failed with error 0x%08x\n",
|
|
|
|
mode, status);
|
|
|
|
else
|
|
|
|
ok(status == STATUS_INVALID_PARAMETER_1,
|
|
|
|
"RtlSetThreadErrorMode(%x,NULL) returns 0x%08x, "
|
|
|
|
"expected STATUS_INVALID_PARAMETER_1\n",
|
|
|
|
mode, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
pRtlSetThreadErrorMode(oldmode, NULL);
|
|
|
|
}
|
|
|
|
|
2010-08-19 18:07:01 +00:00
|
|
|
static void test_LdrProcessRelocationBlock(void)
|
|
|
|
{
|
|
|
|
IMAGE_BASE_RELOCATION *ret;
|
|
|
|
USHORT reloc;
|
|
|
|
DWORD addr32;
|
|
|
|
SHORT addr16;
|
|
|
|
|
|
|
|
if(!pLdrProcessRelocationBlock) {
|
|
|
|
win_skip("LdrProcessRelocationBlock not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr32 = 0x50005;
|
|
|
|
reloc = IMAGE_REL_BASED_HIGHLOW<<12;
|
|
|
|
ret = pLdrProcessRelocationBlock(&addr32, 1, &reloc, 0x500050);
|
|
|
|
ok((USHORT*)ret == &reloc+1, "ret = %p, expected %p\n", ret, &reloc+1);
|
|
|
|
ok(addr32 == 0x550055, "addr32 = %x, expected 0x550055\n", addr32);
|
|
|
|
|
|
|
|
addr16 = 0x505;
|
|
|
|
reloc = IMAGE_REL_BASED_HIGH<<12;
|
|
|
|
ret = pLdrProcessRelocationBlock(&addr16, 1, &reloc, 0x500060);
|
|
|
|
ok((USHORT*)ret == &reloc+1, "ret = %p, expected %p\n", ret, &reloc+1);
|
|
|
|
ok(addr16 == 0x555, "addr16 = %x, expected 0x555\n", addr16);
|
|
|
|
|
|
|
|
addr16 = 0x505;
|
|
|
|
reloc = IMAGE_REL_BASED_LOW<<12;
|
|
|
|
ret = pLdrProcessRelocationBlock(&addr16, 1, &reloc, 0x500060);
|
|
|
|
ok((USHORT*)ret == &reloc+1, "ret = %p, expected %p\n", ret, &reloc+1);
|
|
|
|
ok(addr16 == 0x565, "addr16 = %x, expected 0x565\n", addr16);
|
|
|
|
}
|
|
|
|
|
2010-08-20 03:50:19 +00:00
|
|
|
static void test_RtlIpv4AddressToString(void)
|
|
|
|
{
|
|
|
|
CHAR buffer[20];
|
|
|
|
CHAR *res;
|
|
|
|
IN_ADDR ip;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if (!pRtlIpv4AddressToStringA)
|
|
|
|
{
|
|
|
|
win_skip("RtlIpv4AddressToStringA not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ip.S_un.S_un_b.s_b1 = 1;
|
|
|
|
ip.S_un.S_un_b.s_b2 = 2;
|
|
|
|
ip.S_un.S_un_b.s_b3 = 3;
|
|
|
|
ip.S_un.S_un_b.s_b4 = 4;
|
|
|
|
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringA(&ip, buffer);
|
|
|
|
len = strlen(buffer);
|
|
|
|
ok(res == (buffer + len), "got %p with '%s' (expected %p)\n", res, buffer, buffer + len);
|
|
|
|
|
|
|
|
res = pRtlIpv4AddressToStringA(&ip, NULL);
|
|
|
|
ok( (res == (char *)~0) ||
|
|
|
|
broken(res == (char *)0 + len), /* XP and w2003 */
|
|
|
|
"got %p (expected ~0)\n", res);
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
/* this crashes in windows */
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringA(NULL, buffer);
|
|
|
|
trace("got %p with '%s'\n", res, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
/* this crashes in windows */
|
|
|
|
res = pRtlIpv4AddressToStringA(NULL, NULL);
|
|
|
|
trace("got %p\n", res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RtlIpv4AddressToStringEx(void)
|
|
|
|
{
|
|
|
|
CHAR ip_1234[] = "1.2.3.4";
|
|
|
|
CHAR ip_1234_80[] = "1.2.3.4:80";
|
|
|
|
LPSTR expect;
|
|
|
|
CHAR buffer[30];
|
|
|
|
NTSTATUS res;
|
|
|
|
IN_ADDR ip;
|
|
|
|
ULONG size;
|
|
|
|
DWORD used;
|
|
|
|
USHORT port;
|
|
|
|
|
|
|
|
if (!pRtlIpv4AddressToStringExA)
|
|
|
|
{
|
|
|
|
win_skip("RtlIpv4AddressToStringExA not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ip.S_un.S_un_b.s_b1 = 1;
|
|
|
|
ip.S_un.S_un_b.s_b2 = 2;
|
|
|
|
ip.S_un.S_un_b.s_b3 = 3;
|
|
|
|
ip.S_un.S_un_b.s_b4 = 4;
|
|
|
|
|
|
|
|
port = htons(80);
|
|
|
|
expect = ip_1234_80;
|
|
|
|
|
|
|
|
size = sizeof(buffer);
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
used = strlen(buffer);
|
|
|
|
ok( (res == STATUS_SUCCESS) &&
|
|
|
|
(size == strlen(expect) + 1) && !strcmp(buffer, expect),
|
|
|
|
"got 0x%x and size %d with '%s'\n", res, size, buffer);
|
|
|
|
|
|
|
|
size = used + 1;
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
ok( (res == STATUS_SUCCESS) &&
|
|
|
|
(size == strlen(expect) + 1) && !strcmp(buffer, expect),
|
|
|
|
"got 0x%x and size %d with '%s'\n", res, size, buffer);
|
|
|
|
|
|
|
|
size = used;
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
|
|
|
|
"got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
|
|
|
|
res, size, buffer, used + 1);
|
|
|
|
|
|
|
|
size = used - 1;
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
|
|
|
|
"got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
|
|
|
|
res, size, buffer, used + 1);
|
|
|
|
|
|
|
|
|
|
|
|
/* to get only the ip, use 0 as port */
|
|
|
|
port = 0;
|
|
|
|
expect = ip_1234;
|
|
|
|
|
|
|
|
size = sizeof(buffer);
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
used = strlen(buffer);
|
|
|
|
ok( (res == STATUS_SUCCESS) &&
|
|
|
|
(size == strlen(expect) + 1) && !strcmp(buffer, expect),
|
|
|
|
"got 0x%x and size %d with '%s'\n", res, size, buffer);
|
|
|
|
|
|
|
|
size = used + 1;
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
ok( (res == STATUS_SUCCESS) &&
|
|
|
|
(size == strlen(expect) + 1) && !strcmp(buffer, expect),
|
|
|
|
"got 0x%x and size %d with '%s'\n", res, size, buffer);
|
|
|
|
|
|
|
|
size = used;
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
|
|
|
|
"got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
|
|
|
|
res, size, buffer, used + 1);
|
|
|
|
|
|
|
|
size = used - 1;
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, port, buffer, &size);
|
|
|
|
ok( (res == STATUS_INVALID_PARAMETER) && (size == used + 1),
|
|
|
|
"got 0x%x and %d with '%s' (expected STATUS_INVALID_PARAMETER and %d)\n",
|
|
|
|
res, size, buffer, used + 1);
|
|
|
|
|
|
|
|
|
|
|
|
/* parameters are checked */
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, 0, buffer, NULL);
|
|
|
|
ok(res == STATUS_INVALID_PARAMETER,
|
|
|
|
"got 0x%x with '%s' (expected STATUS_INVALID_PARAMETER)\n", res, buffer);
|
|
|
|
|
|
|
|
size = sizeof(buffer);
|
|
|
|
res = pRtlIpv4AddressToStringExA(&ip, 0, NULL, &size);
|
|
|
|
ok( res == STATUS_INVALID_PARAMETER,
|
|
|
|
"got 0x%x and size %d (expected STATUS_INVALID_PARAMETER)\n", res, size);
|
|
|
|
|
|
|
|
size = sizeof(buffer);
|
|
|
|
memset(buffer, '#', sizeof(buffer) - 1);
|
|
|
|
buffer[sizeof(buffer) -1] = 0;
|
|
|
|
res = pRtlIpv4AddressToStringExA(NULL, 0, buffer, &size);
|
|
|
|
ok( res == STATUS_INVALID_PARAMETER,
|
|
|
|
"got 0x%x and size %d with '%s' (expected STATUS_INVALID_PARAMETER)\n",
|
|
|
|
res, size, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-22 00:21:35 +00:00
|
|
|
START_TEST(rtl)
|
|
|
|
{
|
|
|
|
InitFunctionPtrs();
|
|
|
|
|
2010-01-13 12:44:44 +00:00
|
|
|
test_RtlCompareMemory();
|
|
|
|
test_RtlCompareMemoryUlong();
|
|
|
|
test_RtlMoveMemory();
|
|
|
|
test_RtlFillMemory();
|
|
|
|
test_RtlFillMemoryUlong();
|
|
|
|
test_RtlZeroMemory();
|
|
|
|
test_RtlUlonglongByteSwap();
|
|
|
|
test_RtlUniform();
|
|
|
|
test_RtlRandom();
|
|
|
|
test_RtlAreAllAccessesGranted();
|
|
|
|
test_RtlAreAnyAccessesGranted();
|
|
|
|
test_RtlComputeCrc32();
|
|
|
|
test_HandleTables();
|
|
|
|
test_RtlAllocateAndInitializeSid();
|
|
|
|
test_RtlDeleteTimer();
|
2010-02-02 12:47:06 +00:00
|
|
|
test_RtlThreadErrorMode();
|
2010-08-19 18:07:01 +00:00
|
|
|
test_LdrProcessRelocationBlock();
|
2010-08-20 03:50:19 +00:00
|
|
|
test_RtlIpv4AddressToString();
|
|
|
|
test_RtlIpv4AddressToStringEx();
|
2003-03-22 00:21:35 +00:00
|
|
|
}
|