From 29dc9906b27fca64705acd9a4a1371a3ca504b7c Mon Sep 17 00:00:00 2001 From: kobalicekp Date: Tue, 25 Mar 2014 10:52:17 +0100 Subject: [PATCH] Added another test trying to exploit issue #9 --- src/app/test/testx86.cpp | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/app/test/testx86.cpp b/src/app/test/testx86.cpp index 034fdb9..f488bd4 100644 --- a/src/app/test/testx86.cpp +++ b/src/app/test/testx86.cpp @@ -2291,6 +2291,64 @@ struct X86Test_CallRecursive : public X86Test { } }; +// ============================================================================ +// [X86Test_CallMisc1] +// ============================================================================ + +struct X86Test_CallMisc1 : public X86Test { + X86Test_CallMisc1() : X86Test("[Call] Misc #1") {} + + static void add(PodVector& tests) { + tests.append(new X86Test_CallMisc1()); + } + + static void dummy(int a, int b) {} + + virtual void compile(Compiler& c) { + GpVar val(c, kVarTypeInt32, "val"); + Label skip(c); + + X86X64FuncNode* func = c.addFunc(kFuncConvHost, FuncBuilder2()); + + GpVar aa(c, kVarTypeInt32, "aa"); + GpVar ab(c, kVarTypeInt32, "ab"); + + c.setArg(0, aa); + c.setArg(1, ab); + + GpVar a(c, kVarTypeInt32, "a"); + GpVar b(c, kVarTypeInt32, "b"); + + c.alloc(a, eax); + c.alloc(b, ebx); + + c.mov(a, aa); + c.mov(b, ab); + + X86X64CallNode* call = c.call(imm_ptr(dummy), kFuncConvHost, FuncBuilder2()); + call->setArg(0, a); + call->setArg(1, b); + + c.add(aa, ab); + c.ret(aa); + + c.endFunc(); + } + + virtual bool run(void* _func, StringBuilder& result, StringBuilder& expect) { + typedef int (*Func)(int, int); + Func func = asmjit_cast(_func); + + int resultRet = func(44, 199); + int expectRet = 243; + + result.setFormat("ret=%d", resultRet); + expect.setFormat("ret=%d", expectRet); + + return resultRet == expectRet; + } +}; + // ============================================================================ // [X86Test_Dummy] // ============================================================================ @@ -2416,6 +2474,7 @@ X86TestSuite::X86TestSuite() : ADD_TEST(X86Test_CallConditional); ADD_TEST(X86Test_CallMultiple); ADD_TEST(X86Test_CallRecursive); + ADD_TEST(X86Test_CallMisc1); // Dummy. // ADD_TEST(X86Test_Dummy);