Signal Handling in JNI side

175 views
Skip to first unread message

Aniket Kulkarni

unread,
May 8, 2023, 8:12:54 AM5/8/23
to Java Native Access
Hello All,

Greeting.
I am Aniket. I am new to this community, hoping to get solution here.

I have created a dll file from c program.
There is a crash(SIGSEGV) in that dll for which signal handler in c is implementead
If I use the dll in another c language code, the signal handler is getting call program is exiting gracefully.
But If I tried to run the same dll function through java code, java program is crashing, why???

I am totally new JAVA, please guide me to solve this

doing all this x64 windows machine with visual studio 2019 IDE to create DLL and Eclipse for JAVA code
But want to creatr cross platform code, which can run on windows as well as linux

P.S. - I know I am rereferring NULL pointer in Addition(), that is just to trigger SIGSEGV fault, so signal_handler can get call...But currently that is not happening, instead JVM is handling that signalC Code Part 1.pngC Code Part 2.pngJAVA Code.png

Matthias Bläsing

unread,
May 8, 2023, 2:35:08 PM5/8/23
to jna-...@googlegroups.com
Hi Aniket,

Am Montag, dem 08.05.2023 um 05:12 -0700 schrieb Aniket Kulkarni:
> I have created a dll file from c program.
> There is a crash(SIGSEGV) in that dll for which signal handler in c
> is implementead
> If I use the dll in another c language code, the signal handler is
> getting call program is exiting gracefully.
> But If I tried to run the same dll function through java code, java
> program is crashing, why???

The HotspotVM uses signal handlers internally and thus will normally
not allow "normal" code to use them.

More information can be found here:

https://docs.oracle.com/en/java/javase/17/troubleshoot/handle-signals-and-exceptions.html#GUID-CB49A2A7-2A9F-4C18-948F-6D4A96FF688D

> doing all this x64 windows machine with visual studio 2019 IDE to
> create DLL and Eclipse for JAVA code
> But want to creatr cross platform code, which can run on windows as
> well as linux

If this is your library: Don't use signals to communicate programming
errors. If I remember correctly you have no guarantee, where a signal
handler is invoked and thus you might get lucky, but you can fail hard.

HTH

Matthias

Aniket Kulkarni

unread,
May 9, 2023, 1:56:19 AM5/9/23
to jna-...@googlegroups.com
Hello Matthias,

Thanks for your guidance.
just a question - Is there any way to modify HotspotVM's signal handler, so alongside VM's message. I can at least print my statements alongside it.


--
You received this message because you are subscribed to a topic in the Google Groups "Java Native Access" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jna-users/9rKCDu7wviM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/4ceb042b6dac6d3289d71a813cc81e8a596089e9.camel%40doppel-helix.eu.


--
Regards,

Aniket Kulkarni

Software Engineer

Fortytwo Labs

7558579044
Aniket....@fortytwo42.in
https://www.fortytwolabs.com/
202, Siddh Icon, Baner, Pune, India
facebook
linkedin


-----------Confidentiality statement and Disclaimer----------

This e-mail transmission may contain confidential, proprietary and/or legally privileged information and is intended only for the individual or entity named in the e-mail address. Any disclosure, copying, distribution, or reliance upon the contents of this e-mail not authorized by the sender is strictly prohibited. If you have received this e-mail transmission in error, please immediately reply to the sender, so that proper delivery of the e-mail can be effected, and then please delete the message from your Inbox.

Any content of this message and its attachments that does not relate to the official business of Fortytwo42 Technology Innovations Private Limited must be taken not to have been sent or endorsed by any of them. 

Email communications are not private and no warranty is made that e-mail communications are timely, secure or free from computer virus or other defect.

Matthias Bläsing

unread,
May 9, 2023, 11:54:19 AM5/9/23
to jna-...@googlegroups.com
Hi Aniket,

Am Dienstag, dem 09.05.2023 um 11:26 +0530 schrieb Aniket Kulkarni:
>
> Thanks for your guidance.
> just a question - Is there any way to modify HotspotVM's signal
> handler, so alongside VM's message. I can at least print my
> statements alongside it.
>

Sorry, I can't tell you more, than the documentation about the signal
chaining mechanism already referenced.

Greetings

Matthias

Neil C Smith

unread,
May 9, 2023, 1:04:00 PM5/9/23
to jna-...@googlegroups.com
On Tue, 9 May 2023 at 06:56, Aniket Kulkarni
<aniket....@fortytwo42.in> wrote:
> just a question - Is there any way to modify HotspotVM's signal handler, so alongside VM's message. I can at least print my statements alongside it.

In theory you can attach signal handlers on the Java side, but whether
they can handle or do anything useful with this case is another
matter!

There are sun.misc.Signal(Handler) classes in the jdk.unsupported module.

You could look at (or borrow) the code from JLine 3 that uses these
via reflection -
https://github.com/jline/jline3/blob/master/terminal/src/main/java/org/jline/utils/Signals.java

Best wishes,

Neil

--
Neil C Smith
Codelerity Ltd.
www.codelerity.com

Codelerity Ltd. is a company registered in England and Wales
Registered company number : 12063669
Registered office address : Office 4 219 Kensington High Street,
Kensington, London, England, W8 6BD
Reply all
Reply to author
Forward
0 new messages