* [Linux-ia64] correct seg fault address on ia-64??
@ 2001-11-14 16:03 Pereira, D LailaX E
2001-11-14 16:42 ` n0ano
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Pereira, D LailaX E @ 2001-11-14 16:03 UTC (permalink / raw)
To: linux-ia64
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);
exit(1);
}
int main(){
int s;
struct sigaction sa;
int temp;
page_size=getpagesize();
printf("Pagesize : %d ,PID=%d\n",page_size,(int)getpid());
fflush(stdout);
/*SEGV handler setup*/
sa.sa_handler=(void*)&segv_handler;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask,SIGIO);
sigaddset(&sa.sa_mask,SIGALRM);
sa.sa_flags=SA_SIGINFO;
if (sigaction(SIGSEGV,&sa,NULL)){
printf(" Error assigning signal!\n");
}
x=(int*)malloc(2*page_size);
/* 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 );
//x[0]E6;
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?
temp=x[0];
return 0;
}
When I run the program on a ia-64 machine (linux OS) , then I get the
following output:
Pagesize : 16384 ,PID(513
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(471
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,
ubp_av=0x80000fffffffb848,
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 ()
(gdb)....
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.
d'laila
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-ia64] correct seg fault address on ia-64??
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
@ 2001-11-14 16:42 ` n0ano
2001-11-14 16:45 ` Andreas Schwab
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: n0ano @ 2001-11-14 16:42 UTC (permalink / raw)
To: linux-ia64
D'Laila-
Remember that longs and pointers are 64 bits. The `%x' format
to `printf' says to print out a 32-bit integer so you wind up
truncating the upper 32-bits of the address. Just change your
format to `%lx' and you should print out the right address.
On Wed, Nov 14, 2001 at 08:03:57AM -0800, Pereira, D LailaX E wrote:
>
> 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);
> exit(1);
> }
>
>
> int main(){
> int s;
> struct sigaction sa;
> int temp;
>
> page_size=getpagesize();
> printf("Pagesize : %d ,PID=%d\n",page_size,(int)getpid());
> fflush(stdout);
>
> /*SEGV handler setup*/
> sa.sa_handler=(void*)&segv_handler;
> sigemptyset(&sa.sa_mask);
> sigaddset(&sa.sa_mask,SIGIO);
> sigaddset(&sa.sa_mask,SIGALRM);
>
> sa.sa_flags=SA_SIGINFO;
>
> if (sigaction(SIGSEGV,&sa,NULL)){
> printf(" Error assigning signal!\n");
> }
>
> x=(int*)malloc(2*page_size);
>
> /* 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 );
> //x[0]E6;
>
> 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?
> temp=x[0];
> return 0;
> }
>
>
> When I run the program on a ia-64 machine (linux OS) , then I get the
> following output:
> Pagesize : 16384 ,PID(513
> 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(471
> 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,
> ubp_av=0x80000fffffffb848,
> 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 ()
> (gdb)....
>
>
> 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.
>
> d'laila
> _______________________________________________
> Linux-IA64 mailing list
> Linux-IA64@linuxia64.org
> http://lists.linuxia64.org/lists/listinfo/linux-ia64
--
Don Dugger
"Censeo Toto nos in Kansa esse decisse." - D. Gale
n0ano@indstorage.com
Ph: 303/652-0870x117
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-ia64] correct seg fault address on ia-64??
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
2001-11-14 16:42 ` n0ano
@ 2001-11-14 16:45 ` Andreas Schwab
2001-11-14 16:49 ` Dan Pop
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Andreas Schwab @ 2001-11-14 16:45 UTC (permalink / raw)
To: linux-ia64
"Pereira, D LailaX E" <d.lailax.e.pereira@intel.com> writes:
|> /* 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)));
Never ever cast pointers to int! Modern C gives you all you need:
uintptr_t.
Andreas.
--
Andreas Schwab "And now for something
Andreas.Schwab@suse.de completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-ia64] correct seg fault address on ia-64??
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
2001-11-14 16:42 ` n0ano
2001-11-14 16:45 ` Andreas Schwab
@ 2001-11-14 16:49 ` Dan Pop
2001-11-14 17:22 ` Rich Altmaier
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Dan Pop @ 2001-11-14 16:49 UTC (permalink / raw)
To: linux-ia64
On Wed, 14 Nov 2001, Pereira, D LailaX E wrote:
> x=(int*)malloc(2*page_size);
>
> /* 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)));
^^^^^
This conversion is the WRONG thing: you are losing significant bits
from the 64-bit pointer's value!
> printf("Address: %x\n",x );
And this is the wrong way of displaying a pointer, which is not a
32-bit entity and definitely not an unsigned int. The right way of
doing it is:
printf("Address: %p\n", (void *)x);
> .............
> 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(471
> 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,
> ubp_av=0x80000fffffffb848,
> 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 ()
> (gdb)....
>
>
> 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.
You're confusing data addresses and code addresses. You're displaying
the value of a pointer, which is a (badly formed) data address, while
gdb is displaying the address of the instruction that generated the
fault, i.e. a code address.
Dan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-ia64] correct seg fault address on ia-64??
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
` (2 preceding siblings ...)
2001-11-14 16:49 ` Dan Pop
@ 2001-11-14 17:22 ` Rich Altmaier
2001-11-14 17:49 ` Christoph Hellwig
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Rich Altmaier @ 2001-11-14 17:22 UTC (permalink / raw)
To: linux-ia64
Such horrible things are being done in source code in the 64bit
environment. Is there any kind of "porting guide" available?
A long time ago we did a porting guide for MIPSPro, see
http://techpubs.sgi.com/library/tpl/cgi-bin/init.cgi
in search enter: mipspro 64-bit
and take a look at the MIPSpro 64-bit Porting and Transition Guide,
select Chapter 3, second portion (first portion is Fortran, second is C).
What is out there for gcc?
Thanks, Rich
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-ia64] correct seg fault address on ia-64??
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
` (3 preceding siblings ...)
2001-11-14 17:22 ` Rich Altmaier
@ 2001-11-14 17:49 ` Christoph Hellwig
2001-11-14 18:02 ` n0ano
2001-11-14 18:51 ` Rok Sosic
6 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2001-11-14 17:49 UTC (permalink / raw)
To: linux-ia64
On Wed, Nov 14, 2001 at 09:22:31AM -0800, Rich Altmaier wrote:
> What is out there for gcc?
gcc -W -Werror..
Seriously, gcc supports 64bit targets for a _very_ long time now
(more than 5 years) - people should have gotten their code cleaned
up..
Christoph
--
Of course it doesn't work. We've performed a software upgrade.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-ia64] correct seg fault address on ia-64??
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
` (4 preceding siblings ...)
2001-11-14 17:49 ` Christoph Hellwig
@ 2001-11-14 18:02 ` n0ano
2001-11-14 18:51 ` Rok Sosic
6 siblings, 0 replies; 8+ messages in thread
From: n0ano @ 2001-11-14 18:02 UTC (permalink / raw)
To: linux-ia64
Rich-
A while back someone from SCO made a presentation at one of the
early Intel Developer Forums about just this topic. I can't
find it in a quick search of either the SCO (now Caldera) or
Intel sites. Maybe someone from Caldera or Intel can see if
that presentation is still available.
On Wed, Nov 14, 2001 at 09:22:31AM -0800, Rich Altmaier wrote:
> Such horrible things are being done in source code in the 64bit
> environment. Is there any kind of "porting guide" available?
> A long time ago we did a porting guide for MIPSPro, see
>
> http://techpubs.sgi.com/library/tpl/cgi-bin/init.cgi
> in search enter: mipspro 64-bit
> and take a look at the MIPSpro 64-bit Porting and Transition Guide,
> select Chapter 3, second portion (first portion is Fortran, second is C).
>
> What is out there for gcc?
> Thanks, Rich
>
>
>
> _______________________________________________
> Linux-IA64 mailing list
> Linux-IA64@linuxia64.org
> http://lists.linuxia64.org/lists/listinfo/linux-ia64
--
Don Dugger
"Censeo Toto nos in Kansa esse decisse." - D. Gale
n0ano@indstorage.com
Ph: 303/652-0870x117
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-ia64] correct seg fault address on ia-64??
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
` (5 preceding siblings ...)
2001-11-14 18:02 ` n0ano
@ 2001-11-14 18:51 ` Rok Sosic
6 siblings, 0 replies; 8+ messages in thread
From: Rok Sosic @ 2001-11-14 18:51 UTC (permalink / raw)
To: linux-ia64
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1616 bytes --]
Hi,
perhaps you meant our presentation on Turbolinux for IA64 at the August
2000 Forum which included a list of issues when porting from IA32 to IA64.
The presentation is included in the attachment.
Cheers,
Rok
On Wed, 14 Nov 2001 n0ano@indstorage.com wrote:
> Rich-
>
> A while back someone from SCO made a presentation at one of the
> early Intel Developer Forums about just this topic. I can't
> find it in a quick search of either the SCO (now Caldera) or
> Intel sites. Maybe someone from Caldera or Intel can see if
> that presentation is still available.
>
> On Wed, Nov 14, 2001 at 09:22:31AM -0800, Rich Altmaier wrote:
> > Such horrible things are being done in source code in the 64bit
> > environment. Is there any kind of "porting guide" available?
> > A long time ago we did a porting guide for MIPSPro, see
> >
> > http://techpubs.sgi.com/library/tpl/cgi-bin/init.cgi
> > in search enter: mipspro 64-bit
> > and take a look at the MIPSpro 64-bit Porting and Transition Guide,
> > select Chapter 3, second portion (first portion is Fortran, second is C).
> >
> > What is out there for gcc?
> > Thanks, Rich
> >
> >
> >
> > _______________________________________________
> > Linux-IA64 mailing list
> > Linux-IA64@linuxia64.org
> > http://lists.linuxia64.org/lists/listinfo/linux-ia64
>
> --
> Don Dugger
> "Censeo Toto nos in Kansa esse decisse." - D. Gale
> n0ano@indstorage.com
> Ph: 303/652-0870x117
>
> _______________________________________________
> Linux-IA64 mailing list
> Linux-IA64@linuxia64.org
> http://lists.linuxia64.org/lists/listinfo/linux-ia64
>
[-- Attachment #2: Type: APPLICATION/MSWORD, Size: 98304 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2001-11-14 18:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-11-14 16:03 [Linux-ia64] correct seg fault address on ia-64?? Pereira, D LailaX E
2001-11-14 16:42 ` n0ano
2001-11-14 16:45 ` Andreas Schwab
2001-11-14 16:49 ` Dan Pop
2001-11-14 17:22 ` Rich Altmaier
2001-11-14 17:49 ` Christoph Hellwig
2001-11-14 18:02 ` n0ano
2001-11-14 18:51 ` Rok Sosic
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox