detectar el tipo de fallo a la hora de un SIGSEGV en Linux

"Mario Rodriguez Villanea" <[email protected]>
Newsgroups gmane.org.user-groups.linux.gulcr
Message-ID <[email protected]>
Hola a todo mundo, estoy trabajando en una aplicacion que entre otras
cosas debe atrapar los signals de SIGSEGV (segmentation fault) y
determinar si el fault fue debido a una lectura o escritura.

Buscando en internet encontre lo siguiente:

 void sigsegvHandler(int sig,  siginfo_t *sip, void *uap) {
	char	*vadr = (char *)sip->si_addr;
	int writing = ((ucontext_t*)uap)->uc_mcontext.cr2;
        .......
}

Pero no estoy muy seguro si este cr2 realmente contiene la informacion que
requiero para determinar si el fault fue de lectura o escritura. Buscando
en los encabezados de linux encontre la definicion de estos tipos:

/* Context to describe whole processor state.  */
typedef struct
{
	gregset_t gregs;
	/* Due to Linux's history we have to use a pointer here.  The SysV/i386
	ABI requires a struct with the values.  */
	fpregset_t fpregs;
	unsigned long int oldmask;
	unsigned long int cr2;
} mcontext_t;


/* Userlevel context.  */
typedef struct ucontext
{
	unsigned long int uc_flags;
	struct ucontext *uc_link;
	stack_t uc_stack;
	mcontext_t uc_mcontext;
	__sigset_t uc_sigmask;
	struct _libc_fpstate __fpregs_mem;
} ucontext_t;


Pero no se habla mayor cosa del famoso unsigned long int cr2

Alguna idea de como determinar si un fault fue por lectura o escritura?


-- 
Desuscripción: escriba a [email protected], tema 'unsubscribe'
Problemas a: [email protected].  http://gulcr.org/ListasDeCorreo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.