[Linux-ia64] correct seg fault address on ia-64??

From: Pereira, D LailaX E <d.lailax.e.pereira_at_intel.com>
Date: 2001-11-15 03:03:57
Hi ,

In the following program, I was trying to obtain the address where a
segmentation fault is caused. 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/mman.h>

int *x;
int page_size;

void segv_handler( int sig, siginfo_t *sip,struct sigcontext *scp){

  void *vadr=sip->si_addr;
  unsigned long *pc;
  unsigned long instr;
  int  readwrite;

  if (sig==SIGSEGV){
    printf("\nSegv handler ..\n");
  printf("vaddr : %x \n",vadr);
  readwrite=(((*(unsigned long*)scp->sc_ip)>>21)&1);
  printf("Read or write %d\n",readwrite);

int main(){
  int s;
  struct sigaction sa;
  int temp;

  printf("Pagesize : %d ,PID=%d\n",page_size,(int)getpid());

  /*SEGV handler setup*/


  if (sigaction(SIGSEGV,&sa,NULL)){
    printf(" Error assigning signal!\n");


 /* Align to a multiple of page_size, assumed to be a power of two */
  x = (int *)((long)(((int) (long)x + page_size-1) & ~(page_size-1)));
  printf("Address:  %x\n",x );

  s=mprotect(x,page_size,PROT_NONE);  //make it none access
  printf("Page protection : NONE : try reading the page\n ");
  printf("segv should arise now ...\n");
  //read the page ... segv?
  return 0;

When I run the program on a ia-64 machine (linux OS) , then I get the
following output: 
Pagesize : 16384 ,PID=28513
Address:  4000
Page protection : NONE : try reading the page
 segv should arise now ...

Segv handler ..
vaddr : 4000 
Read or write 0

However , when I ran the program thru gdb, I got the following:
Reading symbols from a.out...done.
(gdb) run ex3.c
Pagesize : 16384 ,PID=28471
Address:  4000
Page protection : NONE : try reading the page
 segv should arise now ...

Program received signal SIGSEGV, Segmentation fault.
0x40000000000010e0 in main ()
(gdb) where 
#0  0x40000000000010e0 in main ()
#1  0x20000000000906b0 in __libc_start_main (
    main=0x40000000000013e8 <_fini+408>, argc=2, 
    init=0x40000000000013b8 <_fini+360>, 
    fini=0x200000000003db30 <_dl_debug_mask>, 
    rtld_fini=0x20000000002581c8 <_dl_get_origin+632>, 
    stack_end=0x80000fffffffb840) at ../sysdeps/generic/libc-start.c:129
#2  0x40000000000010b0 in main ()

So thru, gdb the seg fault address is "0x40000000000010e0" , is my
interpretation right ?? 
Why is that when I run the program on itanium , I get the address as "4000"
and thru gdb as " 0x40000000000010e0". What is wrong?? Please let me know.


Received on Wed Nov 14 08:04:09 2001

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:05 EST