public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/14767] New: gcjlib under FreeBSD does not forward SIGSEGV to SA_SIGINFO handler
@ 2004-03-29  4:13 andrew dot gray at anu dot edu dot au
  2004-03-30  0:41 ` [Bug libgcj/14767] " andrew dot gray at anu dot edu dot au
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: andrew dot gray at anu dot edu dot au @ 2004-03-29  4:13 UTC (permalink / raw)
  To: java-prs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-04-19  7:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-29  4:13 [Bug libgcj/14767] New: gcjlib under FreeBSD does not forward SIGSEGV to SA_SIGINFO handler andrew dot gray at anu dot edu dot au
2004-03-30  0:41 ` [Bug libgcj/14767] " andrew dot gray at anu dot edu dot au
2004-03-30  2:45 ` ljrittle at gcc dot gnu dot org
2004-03-30  7:40 ` andrew dot gray at anu dot edu dot au
2004-04-07 20:30 ` Hans dot Boehm at hp dot com
2004-04-08  0:32 ` andrew dot gray at anu dot edu dot au
2004-04-19  7:18 ` andrew dot gray at anu dot edu dot au

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).