Skip to content

Commit 6756267

Browse files
committed
attempt to reproduce issue #300
1 parent 3fc7603 commit 6756267

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

lib/native/win32-x86.jar

3 Bytes
Binary file not shown.

native/testlib.c

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved
1+
/* Copyright (c) 2007-2013 Timothy Wall, All Rights Reserved
22
*
33
* This library is free software; you can redistribute it and/or
44
* modify it under the terms of the GNU Lesser General Public
@@ -941,6 +941,33 @@ callInt32StdCallCallback(int32_t (__stdcall *func)(int32_t arg, int32_t arg2),
941941
return value;
942942
}
943943

944+
EXPORT int32_t __stdcall
945+
callBugCallback(void (__stdcall *func)(long,int,double,
946+
const char*,const char*,
947+
double,long,long,long),
948+
long arg1, int arg2, double arg3,
949+
const char* arg4, const char* arg5,
950+
double arg6, long arg7, long arg8, long arg9) {
951+
void* sp1 = NULL;
952+
void* sp2 = NULL;
953+
int value = -1;
954+
955+
#if defined(_MSC_VER)
956+
__asm mov sp1, esp;
957+
(*func)(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
958+
__asm mov sp2, esp;
959+
#elif defined(__GNUC__)
960+
asm volatile (" movl %%esp,%0" : "=g" (sp1));
961+
(*func)(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
962+
asm volatile (" movl %%esp,%0" : "=g" (sp2));
963+
#endif
964+
965+
if (sp1 != sp2) {
966+
return -1;
967+
}
968+
return 0;
969+
}
970+
944971
#endif /* _WIN32 && !_WIN64 */
945972

946973
#include <jni.h>

test/com/sun/jna/win32/W32StdCallTest.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
1+
/* Copyright (c) 2007-2014 Timothy Wall, All Rights Reserved
22
*
33
* This library is free software; you can redistribute it and/or
44
* modify it under the terms of the GNU Lesser General Public
@@ -23,6 +23,7 @@
2323
import com.sun.jna.Library;
2424
import com.sun.jna.Native;
2525
import com.sun.jna.NativeLibrary;
26+
import com.sun.jna.NativeLong;
2627
import com.sun.jna.Structure;
2728

2829
/**
@@ -54,6 +55,15 @@ interface Int32Callback extends StdCallCallback {
5455
int callback(int arg, int arg2);
5556
}
5657
int callInt32StdCallCallback(Int32Callback c, int arg, int arg2);
58+
interface BugCallback extends StdCallCallback {
59+
void callback(NativeLong arg1, int arg2, double arg3,
60+
String arg4, String arg5, double arg6,
61+
NativeLong arg7, NativeLong arg8, NativeLong arg9);
62+
}
63+
int callBugCallback(BugCallback c, NativeLong arg1, int arg2,
64+
double arg3, String arg4, String arg5,
65+
double arg6, NativeLong arg7,
66+
NativeLong arg8, NativeLong arg9);
5767
}
5868

5969
public static void main(java.lang.String[] argList) {
@@ -136,4 +146,25 @@ public int callback(int arg, int arg2) {
136146
}
137147
assertEquals("Wrong stdcall callback return", -3, value);
138148
}
149+
150+
public void testCallBugCallback() {
151+
final boolean[] called = { false };
152+
TestLibrary.BugCallback cb = new TestLibrary.BugCallback() {
153+
public void callback(NativeLong arg1, int arg2, double arg3,
154+
String arg4, String arg5, double arg6,
155+
NativeLong arg7, NativeLong arg8,
156+
NativeLong arg9) {
157+
called[0] = true;
158+
}
159+
};
160+
int value = testlib.callBugCallback(cb, new NativeLong(1),
161+
2, 3, "four", "five", 6,
162+
new NativeLong(7),
163+
new NativeLong(8),
164+
new NativeLong(9));
165+
assertTrue("stdcall callback not called", called[0]);
166+
if (value == -1) {
167+
fail("stdcall callback did not restore the stack pointer");
168+
}
169+
}
139170
}

0 commit comments

Comments
 (0)