[cfe-dev] clang via JNI + libclang-c

Renato Golin renato.golin at linaro.org
Fri Oct 11 02:28:43 PDT 2013


On 11 October 2013 10:17, Anton Smirnov <dev at antonsmirnov.name> wrote:

> i tried to hold CXIndex as static variable in native code (array of
> pointers to be more detailed) and pass just index to java back and then
> pass index to native code in order to hold variable in native code without
> passing.
>
> Still the same result.
>

So, IIRC, it's not the stack itself (stack variables), but the return
value, that on Intel is at the bottom of the stack. So it doesn't matter
where your native objects live, if you try to return them (or a pointer to
them), and the stack itself is too small, it'd subtract too much from the
stack pointer and then wouldn't find the correct return value because the
offset would be negative, and you get corrupted pointers.

Adding a "int a[1024]" to each function fixed the problem because even
subtracting a lot, it'd never be negative when compared to the return
value, and going back to the return address was still possible. Give it a
try, at least to see if that's the problem we're looking for.

Be wary that that was 10 years ago, JNI may have bred some new bugs since
then...

cheers,
--renato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131011/f288417b/attachment.html>


More information about the cfe-dev mailing list