This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
[Bug libgcj/14767] New: gcjlib under FreeBSD does not forward SIGSEGV to SA_SIGINFO handler
- From: "andrew dot gray at anu dot edu dot au" <gcc-bugzilla at gcc dot gnu dot org>
- To: java-prs at gcc dot gnu dot org
- Date: 29 Mar 2004 04:13:37 -0000
- Subject: [Bug libgcj/14767] New: gcjlib under FreeBSD does not forward SIGSEGV to SA_SIGINFO handler
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Under FreeBSD, gcjlib does not always forward SIGSEGV signals to the
application code correctly. Specifically, if the application has
specified a handler setting the SA_SIGINFO bit in the flags argument
of sigaction, then gcjlib calls the handler with a small integer as
the second argument. To corectly forward the signal gcjlib needs to
call the handler with a pointer to a siginfo_t as the second argument.
The following small program demonstrates the problem:
gcjsigsegv.cc:
#include <iostream>
#include <signal.h>
#include <gcj/cni.h>
#include "AdvancedMath.h"
void fault_handler(int sig, siginfo_t * info, void *uap);
int main(int argc, char* argv[])
{
int i;
int j;
int k;
int *p;
bool use_java = (argc > 1);
struct sigaction sa;
sa.sa_sigaction = &fault_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &sa, 0);
if (use_java)
{
std::cout << "Using Java\n";
JvCreateJavaVM(NULL);
JvAttachCurrentThread(NULL, NULL);
}
else
std::cout << "Not using Java\n";
i = 2;
j = 3;
p = &k;
if (use_java)
k = AdvancedMath::add(i , j);
else
k = i + j;
std::cout << "k = " << k << "\n";
std::cout << "*p = " << *p << "\n";
p = 0;
std::cout << "*p = " << *p << "\n";
return 0;
}
void fault_handler(int sig, siginfo_t * info, void * uap)
{
std::cout << "Caught fault\n";
std::cout << "sig = " << sig << "\n";
std::cout << "info = " << info << "\n";
if (reinterpret_cast<int>(info) != 12)
std::cout << "info->si_code = " << info->si_code << "\n";
std::cout << "Exiting\n";
exit(2);
}
AdvancedMath.java:
public class AdvancedMath {
public static int add(int a, int b) {
return a + b;
}
}
Build the program with the following commands:
gcj -c -o AdvancedMath.o AdvancedMath.java
gcj -C AdvancedMath.java
gcjh AdvancedMath
g++ -c -o gcjsigsegv.o gcjsigsegv.cc
gcj -pthread -o gcjsigsegv gcjsigsegv.o AdvancedMath.o -lstdc++
Running the program without any arguments shows what happens when the
application receives the SIGSEGV directly:
$ ./gcjsigsegv
Not using Java
k = 5
*p = 5
Caught fault
sig = 11
info = 0xbfbffa38
info->si_code = 12
Exiting
Running the program with an argument demonstrates the problem:
$ ./gcjsigsegv j
Using Java
Caught fault
sig = 11
info = 0xc
Exiting
Note that the second argument to fault_handler is now "0xc" when it
should be a pointer to a siginfo_t, as it was when Java was not used.
Looking at the code for the GC_write_fault_handler function in the
boehm-gc/os_dep.c file, it appears that, for FreeBSD, the code does
not take into account the POSIX SA_SIGINFO handler prototype that is
supported by FreeBDS.
I am planning to code a fix for this problem.
--
Summary: gcjlib under FreeBSD does not forward SIGSEGV to
SA_SIGINFO handler
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andrew dot gray at anu dot edu dot au
CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
dot org
GCC build triplet: i386-portbld-freebsd4.8
GCC host triplet: i386-portbld-freebsd4.8
GCC target triplet: i386-portbld-freebsd4.8
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14767