[PATCH 2/3] ntdll/tests: Add tests for runtime 64-bit shift functions.
Zebediah Figura
wine at gitlab.winehq.org
Mon Jul 4 19:54:16 CDT 2022
From: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/ntdll/tests/large_int.c | 72 ++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/dlls/ntdll/tests/large_int.c b/dlls/ntdll/tests/large_int.c
index 9635cac24ad..a8f628ae989 100644
--- a/dlls/ntdll/tests/large_int.c
+++ b/dlls/ntdll/tests/large_int.c
@@ -39,6 +39,7 @@ static LONGLONG (WINAPI *p_allrem)( LONGLONG a, LONGLONG b );
static LONGLONG (WINAPI *p_allmul)( LONGLONG a, LONGLONG b );
static ULONGLONG (WINAPI *p_aulldiv)( ULONGLONG a, ULONGLONG b );
static ULONGLONG (WINAPI *p_aullrem)( ULONGLONG a, ULONGLONG b );
+static void *p_allshl, *p_allshr, *p_aullshr;
static void InitFunctionPtrs(void)
{
@@ -54,8 +55,11 @@ static void InitFunctionPtrs(void)
p_alldiv = (void *)GetProcAddress(hntdll, "_alldiv");
p_allrem = (void *)GetProcAddress(hntdll, "_allrem");
p_allmul = (void *)GetProcAddress(hntdll, "_allmul");
+ p_allshl = (void *)GetProcAddress(hntdll, "_allshl");
+ p_allshr = (void *)GetProcAddress(hntdll, "_allshr");
p_aulldiv = (void *)GetProcAddress(hntdll, "_aulldiv");
p_aullrem = (void *)GetProcAddress(hntdll, "_aullrem");
+ p_aullshr = (void *)GetProcAddress(hntdll, "_aullshr");
} /* if */
}
@@ -445,9 +449,24 @@ static void test_RtlLargeIntegerToChar(void)
static void test_builtins(void)
{
#ifdef __i386__
+ void *code_mem;
ULONGLONG u;
LONGLONG l;
+ static const BYTE call_shift_code[] =
+ {
+ 0x31, 0xc0, /* xorl %eax,%eax */
+ 0x31, 0xd2, /* xorl %edx,%edx */
+ 0x31, 0xc9, /* xorl %ecx,%ecx */
+ 0x87, 0x44, 0x24, 0x08, /* xchgl 8(%esp),%eax */
+ 0x87, 0x54, 0x24, 0x0c, /* xchgl 12(%esp),%edx */
+ 0x87, 0x4c, 0x24, 0x10, /* xchgl 16(%esp),%ecx */
+ 0xff, 0x64, 0x24, 0x04, /* jmp *4(%esp) */
+ };
+ LONGLONG (__cdecl *call_shift_func)(void *func, LONGLONG a, LONG b);
+
+ code_mem = VirtualAlloc(NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+
l = p_alldiv(100, 7);
ok(l == 14, "_alldiv returned %s\n", wine_dbgstr_longlong(l));
@@ -489,6 +508,59 @@ static void test_builtins(void)
l = p_allmul(0x300000001ll, 4);
ok(l == 0xc00000004, "_allmul = %s\n", wine_dbgstr_longlong(l));
+
+ memcpy(code_mem, call_shift_code, sizeof(call_shift_code));
+ call_shift_func = code_mem;
+
+ l = call_shift_func(p_allshl, 0x0123456789abcdefll, 12);
+ ok(l == 0x3456789abcdef000ll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshl, 0x0123456789abcdefll, 44);
+ ok(l == 0xbcdef00000000000ll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshl, 0x0123456789abcdefll, 88);
+ todo_wine ok(!l, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshl, 0x0123456789abcdefll, 0x88);
+ todo_wine ok(!l, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshl, 0x0123456789abcdefll, 0x108);
+ ok(l == 0x23456789abcdef00ll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshr, 0x0123456789abcdefll, 12);
+ ok(l == 0x0123456789abcll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshr, 0x0123456789abcdefll, 44);
+ ok(l == 0x01234ll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshr, 0x0123456789abcdefll, 88);
+ todo_wine ok(!l, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshr, 0x8123456789abcdefll, 12);
+ ok(l == 0xfff8123456789abcll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshr, 0x8123456789abcdefll, 44);
+ ok(l == 0xfffffffffff81234ll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshr, 0x8123456789abcdefll, 88);
+ todo_wine ok(l == -1ll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_allshr, 0x8123456789abcdefll, 0x108);
+ ok(l == 0xff8123456789abcdll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 12);
+ ok(l == 0x8123456789abcll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 44);
+ ok(l == 0x81234ll, "got %#I64x\n", l);
+
+ l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 88);
+ todo_wine ok(!l, "got %#I64x\n", l);
+
+ l = call_shift_func(p_aullshr, 0x8123456789abcdefll, 0x108);
+ ok(l == 0x8123456789abcdll, "got %#I64x\n", l);
+
+ VirtualFree(code_mem, 0, MEM_RELEASE);
#endif /* __i386__ */
}
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/375
More information about the wine-devel
mailing list