Re-implement for unix target, address checking in ND_Address_Check: now use sigaction() and siglingjmp() instead of signal().

Minor code clean-up.
This commit is contained in:
agibert 2004-08-02 21:26:03 +00:00
parent 77330558f0
commit 64baaa1bc5
3 changed files with 112 additions and 48 deletions

View File

@ -1,9 +1,9 @@
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $RCSfile: node.h,v $ */ /* $RCSfile: node.h,v $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $Revision: 2.7 $ */ /* $Revision: 2.8 $ */
/* $Name: $ */ /* $Name: $ */
/* $Date: 2004/08/01 23:18:37 $ */ /* $Date: 2004/08/02 21:26:03 $ */
/* $Author: agibert $ */ /* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -37,10 +37,9 @@
extern "C" { extern "C" {
#endif #endif
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef _LIBVER_SUPPORT #ifdef _LIBVER_SUPPORT

View File

@ -1,9 +1,9 @@
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $RCSfile: libnode.c,v $ */ /* $RCSfile: libnode.c,v $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $Revision: 2.10 $ */ /* $Revision: 2.11 $ */
/* $Name: $ */ /* $Name: $ */
/* $Date: 2004/08/01 23:18:38 $ */ /* $Date: 2004/08/02 21:26:03 $ */
/* $Author: agibert $ */ /* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -34,7 +34,7 @@
#include <libnode.h> #include <libnode.h>
#ifdef _LIBVER_SUPPORT #ifdef _LIBVER_SUPPORT
VER_INFO_EXPORT( libnode, "$Revision: 2.10 $", "$Name: $", __FILE__, "$Author: agibert $") VER_INFO_EXPORT( libnode, "$Revision: 2.11 $", "$Name: $", __FILE__, "$Author: agibert $")
#endif #endif
@ -63,7 +63,7 @@ NDT_Status ND_Default_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT
Command_Name = "NDD_CMD_MANAGER_VERSION"; Command_Name = "NDD_CMD_MANAGER_VERSION";
*Version_Name_Ptr = "$Revision: 2.10 $ $Name: $ $Date: 2004/08/01 23:18:38 $ $Author: agibert $"; *Version_Name_Ptr = "$Revision: 2.11 $ $Name: $ $Date: 2004/08/02 21:26:03 $ $Author: agibert $";
return( NDS_OK); return( NDS_OK);
} }
@ -369,7 +369,7 @@ NDT_Status ND_OpenStruct_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id,
Command_Name = "NDD_CMD_MANAGER_VERSION"; Command_Name = "NDD_CMD_MANAGER_VERSION";
*Version_Name_Ptr = "$Revision: 2.10 $ $Name: $ $Date: 2004/08/01 23:18:38 $ $Author: agibert $"; *Version_Name_Ptr = "$Revision: 2.11 $ $Name: $ $Date: 2004/08/02 21:26:03 $ $Author: agibert $";
return( NDS_OK); return( NDS_OK);
} }
@ -5565,26 +5565,81 @@ void ND_Tree_Link_Recursive_Check( NDT_Node *Node_Ptr, int *Nb_Detected_Ptr,
NDT_Status ND_Address_Check( void *Address) NDT_Status ND_Address_Check( void *Address)
{ {
#if !defined(_MSC_VER)
NDT_Status status;
int rc;
int test; int test;
struct sigaction act =
{
ND_Signal_Trap, //
0, //
0, // sa_mask
0, // sa_flags
0 //
}, oact_bus, oact_segv;
NDG_Base.Sig_Trapped = 0; NDG_Base.Sig_Trapped = 0;
/* On trappe les signaux SIGBUS et SIGSEGV */
// signal( SIGBUS, NDG_Base.Signal_Trap); Win32
// signal( SIGSEGV, NDG_Base.Signal_Trap); Win32 /* Trap SIGBUS and SIGSEGV */
if( ( rc = sigaction( SIGBUS, &act, &oact_bus)) != 0)
{
sprintf( NDG_Base.Err_String, "Error ND_Address_Check: sigaction (Add SIGBUS Hdl) rc: %d errno: %d", rc, errno);
ND_Error_Print();
return( NDS_KO);
}
if( ( rc = sigaction( SIGSEGV, &act, &oact_segv)) != 0)
{
sprintf( NDG_Base.Err_String, "Error ND_Address_Check: sigaction (Add SIGSEGV Hdl) rc: %d errno: %d", rc, errno);
ND_Error_Print();
return( NDS_KO);
}
/* On tente d'accéder à l'adresse fournie */ /* On tente d'accéder à l'adresse fournie */
if( sigsetjmp( NDG_Base.SigLongJmp_Env, 1) == 0 )
{
test = *( (int *)Address); test = *( (int *)Address);
// sigrelse( SIGBUS); Win32 status = NDS_OK;
// sigrelse( SIGSEGV); Win32 }
else
{
status = NDS_KO;
}
if( NDG_Base.Sig_Trapped != 0) return( NDS_KO);
/* Untrap SIGBUS and SIGSEGV */
if( ( rc = sigaction( SIGBUS, &oact_bus, &act)) != 0)
{
sprintf( NDG_Base.Err_String, "Error ND_Address_Check: sigaction (Remove SIGBUS Hdl) rc: %d errno: %d", rc, errno);
ND_Error_Print();
return( NDS_KO);
}
if( ( rc = sigaction( SIGSEGV, &oact_segv, &act)) != 0)
{
sprintf( NDG_Base.Err_String, "Error ND_Address_Check: sigaction (Remove SIGSEGV Hdl) rc: %d errno: %d", rc, errno);
ND_Error_Print();
return( NDS_KO);
}
return( status);
#else
return( NDS_OK); return( NDS_OK);
#endif
} }
@ -5598,6 +5653,8 @@ NDT_Status ND_Address_Check( void *Address)
void ND_Signal_Trap( int Sig_Num) void ND_Signal_Trap( int Sig_Num)
{ {
NDG_Base.Sig_Trapped = Sig_Num; NDG_Base.Sig_Trapped = Sig_Num;
siglongjmp( NDG_Base.SigLongJmp_Env, 1);
} }

View File

@ -1,9 +1,9 @@
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $RCSfile: libnode.h,v $ */ /* $RCSfile: libnode.h,v $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* $Revision: 2.5 $ */ /* $Revision: 2.6 $ */
/* $Name: $ */ /* $Name: $ */
/* $Date: 2004/08/01 23:18:38 $ */ /* $Date: 2004/08/02 21:26:03 $ */
/* $Author: agibert $ */ /* $Author: agibert $ */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -29,11 +29,18 @@
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#if !defined(_MSC_VER)
# include <errno.h>
# include <signal.h> # include <signal.h>
# include <setjmp.h>
#endif
//#include <dlfcn.h> //#include <dlfcn.h>
#include <node.h> #include <node.h>
@ -78,6 +85,7 @@ typedef struct NDT_Base
char Err_String[512]; char Err_String[512];
FILE *Err_Stream; FILE *Err_Stream;
int Sig_Trapped; int Sig_Trapped;
sigjmp_buf SigLongJmp_Env;
NDT_Symbol *Symbol_First_Ptr; NDT_Symbol *Symbol_First_Ptr;
NDT_Index_Type OpenStruct_Index_Type[1]; NDT_Index_Type OpenStruct_Index_Type[1];
NDT_Root *OpenStruct_Ptr; NDT_Root *OpenStruct_Ptr;
@ -89,7 +97,7 @@ NDT_Base NDG_Base =
NDD_TRUE, NDD_TRUE,
"", "",
(FILE *)-1, (FILE *)-1,
0, 0,{},
(NDT_Symbol *)NULL, (NDT_Symbol *)NULL,
{ NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO}, { NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO},
(NDT_Root *)NULL (NDT_Root *)NULL