locked
Unable to execute Oracle statements after exceuting longjmp() from signal handler RRS feed

  • Question

  • Hi,

        We are trying to execute 64-bit code written in PRO*C and Oracle10g on Windows. There are two projects in the workspace - a main executable(main_prorate.exe, which contains main()) and a dynamic link library (prorate_lib.dll). We need to incorporate signal handling in the code, to handle seg-faults and CTRL+C events. We have used setjmp() and longjmp() functions to do this. We have observed different behavior of the code in 32-bit and 64-bit Windows :

    1) On 32-bit Windows, longjmp statement just won't work, and program gives an "Access-Violation" error.

    2) On 64-bit Windows, control is transferred to the statement immediately following setjmp(). Any C code after this is executed, but program gives "Stack-overflow" error when it tries to execute any Oracle query/statement(including if we try to print sqlca.sqlcode)
    two

    I have two questions :

    1) Why the different behavior in Win32 and Win64 bit applications?

    2) If all the code(main() function and signal handling code) is written in a single project, it works fine. Why so? Are we making some mistake? If so, what is the correct way to do it?


    Below is the pseudo-code that we have written :

    In main_prorate.exe : main_prorate.pc
    int main()
    {
        int retval;
        connect_to_db();

        /* Loop to listen to any incoming requests */
        while(1)
        {
            /* Code to check if user submitted any request.
            ....
            */

            /* Call to function from prorate_lib.dll to process request */
            retval = prorate();   

            /* If any error in processing, display error message
               and fetch the next request for processing. */
            if(retval == -1)
            {
                printf("Error in processing request\n");
            }
        }
    }

    In prorate_lib.dll : prorate_main.pc

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h> 
    #include <signal.h>
    #include <setjmp.h>
    #include <sys/types.h>
    #include <windows.h>
    #include <process.h>
    EXEC SQL INCLUDE SQLCA;
    EXEC SQL INCLUDE ORACA;

    jmp_buf  g_jmp_var;
    int prorate()
    {
        EXEC SQL BEGIN DECLARE SECTION;
        varchar process_date[25];
        EXEC SQL END DECLARE SECTION;

        int retval = 0;

        trap_signal()   
        retval = setjmp(g_jmp_var);
        if(retval == -1)
        {
            /* Statement giving error after control is
            transferred here after executing longjmp() */

            printf("SQL - Code = %d", sqlca.sqlcode);       
            return -1
        }

        /* Some data processing code like Insert and Update queries here,
        which could generate a seg-fault or CTRL+C event.
        ....
        */

    }

    In prorate_lib.dll : prorate_signal.pc
    #include <signal.h>
    #include <setjmp.h>
    #include <string.h>
    #include <sqlca.h>
    #include <oraca.h>

    extern jmp_buf   g_jmp_var;
    void trap_sigint(int);
    void trap_sigill(int);
    void trap_sigabrt(int);
    void trap_sigfpe(int);
    void trap_sigsegv(int);
    void trap_sigterm(int);

    int trap_signal()
    {
        signal (SIGINT, trap_sigint);
        signal (SIGILL, trap_sigill);
        signal (SIGABRT, trap_sigabrt);
        signal (SIGFPE, trap_sigfpe);
        signal (SIGSEGV, trap_sigsegv);
        signal (SIGTERM, trap_sigterm);
    }

    void trap_sigint(int signum)
    {
       
       /*Interrrupt Signal Trapped */

    /* Any Oracle query here, like writing error to database works fine. */

        /* Error in 32-bit, but works fine in 64-bit */
        longjmp(jmp_buff, -1);   
    }

    void trap_sigill(int signum)
    {
        /*Illegal Instruction Signal Trapped */

    /* Any Oracle query here, like writing error to database works fine. */

        longjmp(jmp_buff, -1);   
    }

    void trap_sigabrt(int signum)
    {   
        /*Abort Signal Trapped */

    /* Any Oracle query here, like writing error to database works fine. */
        longjmp(jmp_buff, -1);   
    }

    void trap_sigfpe(int signum)
    {
        /* Floating Point Exception Trapped */

    /* Any Oracle query here, like writing error to database works fine. */
        longjmp(jmp_buff, -1);   
    }

    void trap_sigsegv(int signum)
    {

    /*Segmentation Violation Trapped */
    /* Any Oracle query here, like writing error to database works fine. */

        longjmp(jmp_buff, -1);   
    }

    void trap_sigterm(int signum)
    {

    /*Software Termination Signal Trapped */

    /* Any Oracle query here, like writing error to database works fine. */
        longjmp(jmp_buff, -1);   
    }

    Do tell if we are missing something, or making some error. Any prompt reply will be appreciated.

    Thanks and Regards,

    Sheetal

    • Moved by Yi Feng Li Monday, May 17, 2010 7:06 AM ProC and Oracle Issue (From:Visual C++ General)
    Sunday, May 16, 2010 5:36 AM

All replies

  • Hi SheetalAtre,

    In Visual C++ General Forum, we discuss general questions about Microsoft Visual C++, including the development environment, libraries, setup, debugger, samples, and documentation.

     

    Your issue is related to PRO*C and Oracle 10g. We are not familiar with those technologies. We believe the best way to get support is to post your question to forums which is owned by PRO*C and Oracle.

     

    Thank you for your understanding

    Yi Feng Li


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 17, 2010 7:04 AM