Skip to content

Commit

Permalink
attempt to reproduce issue #300
Browse files Browse the repository at this point in the history
  • Loading branch information
twall committed Jan 12, 2014
1 parent 3fc7603 commit 6756267
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
Binary file modified lib/native/win32-x86.jar
Binary file not shown.
29 changes: 28 additions & 1 deletion native/testlib.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved
/* Copyright (c) 2007-2013 Timothy Wall, All Rights Reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -941,6 +941,33 @@ callInt32StdCallCallback(int32_t (__stdcall *func)(int32_t arg, int32_t arg2),
return value;
}

EXPORT int32_t __stdcall
callBugCallback(void (__stdcall *func)(long,int,double,
const char*,const char*,
double,long,long,long),
long arg1, int arg2, double arg3,
const char* arg4, const char* arg5,
double arg6, long arg7, long arg8, long arg9) {
void* sp1 = NULL;
void* sp2 = NULL;
int value = -1;

#if defined(_MSC_VER)
__asm mov sp1, esp;
(*func)(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
__asm mov sp2, esp;
#elif defined(__GNUC__)
asm volatile (" movl %%esp,%0" : "=g" (sp1));
(*func)(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
asm volatile (" movl %%esp,%0" : "=g" (sp2));
#endif

if (sp1 != sp2) {
return -1;
}
return 0;
}

#endif /* _WIN32 && !_WIN64 */

#include <jni.h>
Expand Down
33 changes: 32 additions & 1 deletion test/com/sun/jna/win32/W32StdCallTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
/* Copyright (c) 2007-2014 Timothy Wall, All Rights Reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -23,6 +23,7 @@
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.NativeLong;
import com.sun.jna.Structure;

/**
Expand Down Expand Up @@ -54,6 +55,15 @@ interface Int32Callback extends StdCallCallback {
int callback(int arg, int arg2);
}
int callInt32StdCallCallback(Int32Callback c, int arg, int arg2);
interface BugCallback extends StdCallCallback {
void callback(NativeLong arg1, int arg2, double arg3,
String arg4, String arg5, double arg6,
NativeLong arg7, NativeLong arg8, NativeLong arg9);
}
int callBugCallback(BugCallback c, NativeLong arg1, int arg2,
double arg3, String arg4, String arg5,
double arg6, NativeLong arg7,
NativeLong arg8, NativeLong arg9);
}

public static void main(java.lang.String[] argList) {
Expand Down Expand Up @@ -136,4 +146,25 @@ public int callback(int arg, int arg2) {
}
assertEquals("Wrong stdcall callback return", -3, value);
}

public void testCallBugCallback() {
final boolean[] called = { false };
TestLibrary.BugCallback cb = new TestLibrary.BugCallback() {
public void callback(NativeLong arg1, int arg2, double arg3,
String arg4, String arg5, double arg6,
NativeLong arg7, NativeLong arg8,
NativeLong arg9) {
called[0] = true;
}
};
int value = testlib.callBugCallback(cb, new NativeLong(1),
2, 3, "four", "five", 6,
new NativeLong(7),
new NativeLong(8),
new NativeLong(9));
assertTrue("stdcall callback not called", called[0]);
if (value == -1) {
fail("stdcall callback did not restore the stack pointer");
}
}
}

0 comments on commit 6756267

Please sign in to comment.