* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
@ 2004-01-05 19:19 ` Luck, Tony
2004-01-05 19:52 ` umut aymakoglu
` (7 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Luck, Tony @ 2004-01-05 19:19 UTC (permalink / raw)
To: linux-ia64
> Hi -
> The gcc version is gcc-3.2-29 and the flags we pass
> to gcc are : -O -ansi -fwritable-strings -fsigned-char
> -D_GNU_SOURCE -D_REENTRANT
I have gcc 3.2.3 ... but it appears to not do anything
strange to my test program with those options.
main()
{
char *x = "7chars!";
strcmp(x, "This is 24 chars long!!!");
}
with those options. Do you have any include files that
might be redefining strcmp as memcmp?
-Tony
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
2004-01-05 19:19 ` Luck, Tony
@ 2004-01-05 19:52 ` umut aymakoglu
2004-01-05 20:10 ` Luck, Tony
` (6 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: umut aymakoglu @ 2004-01-05 19:52 UTC (permalink / raw)
To: linux-ia64
Probably the location of "x" is not at the end of the
shared memory segment. In /usr/include/bits/string2.h
strcmp is defined as memcmp which must be getting
picked up.
thanks,
Umut
--- "Luck, Tony" <tony.luck@intel.com> wrote:
> > Hi -
> > The gcc version is gcc-3.2-29 and the flags we
> pass
> > to gcc are : -O -ansi -fwritable-strings
> -fsigned-char
> > -D_GNU_SOURCE -D_REENTRANT
>
> I have gcc 3.2.3 ... but it appears to not do
> anything
> strange to my test program with those options.
>
> main()
> {
> char *x = "7chars!";
>
> strcmp(x, "This is 24 chars long!!!");
> }
>
> with those options. Do you have any include files
> that
> might be redefining strcmp as memcmp?
>
> -Tony
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
2004-01-05 19:19 ` Luck, Tony
2004-01-05 19:52 ` umut aymakoglu
@ 2004-01-05 20:10 ` Luck, Tony
2004-01-05 22:06 ` David Mosberger
` (5 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Luck, Tony @ 2004-01-05 20:10 UTC (permalink / raw)
To: linux-ia64
The <bits/string2.h> on my machine (came from the
glibc-devel-2.3.2-63 package in RedHat EL3). Looks
like it will only convert a strcmp to a memcmp if
*both* the arguments are constant:
# define strcmp(s1, s2) \
__extension__ \
({ size_t __s1_len, __s2_len; \
(__builtin_constant_p (s1) && __builtin_constant_p (s2) \
&& (__s1_len = strlen (s1), __s2_len = strlen (s2), \
(!__string2_1bptr_p (s1) || __s1_len >= 4) \
&& (!__string2_1bptr_p (s2) || __s2_len >= 4)) \
? memcmp ((__const char *) (s1), (__const char *) (s2), \
(__s1_len < __s2_len ? __s1_len : __s2_len) + 1) \
: (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
&& (__s1_len = strlen (s1), __s1_len < 4) \
? (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
? __strcmp_cc (s1, s2, __s1_len) \
: __strcmp_cg (s1, s2, __s1_len)) \
: (__builtin_constant_p (s2) && __string2_1bptr_p (s2) \
&& (__s2_len = strlen (s2), __s2_len < 4) \
? (__builtin_constant_p (s1) && __string2_1bptr_p (s1) \
? __strcmp_cc (s1, s2, __s2_len) \
: __strcmp_gc (s1, s2, __s2_len)) \
: strcmp (s1, s2)))); })
(I say "looks like" because I'm getting dizzy trying to match
parentheses in that expression). Clearly your test case managed
to convert to memcmp when the first argument was not a constant
string ... which caused you grief.
-Tony
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
` (2 preceding siblings ...)
2004-01-05 20:10 ` Luck, Tony
@ 2004-01-05 22:06 ` David Mosberger
2004-01-06 0:04 ` umut aymakoglu
` (4 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: David Mosberger @ 2004-01-05 22:06 UTC (permalink / raw)
To: linux-ia64
>>>>> On Mon, 5 Jan 2004 11:19:36 -0800, "Luck, Tony" <tony.luck@intel.com> said:
>> Hi - The gcc version is gcc-3.2-29 and the flags we pass to gcc
>> are : -O -ansi -fwritable-strings -fsigned-char -D_GNU_SOURCE
>> -D_REENTRANT
Tony> I have gcc 3.2.3 ... but it appears to not do anything strange
Tony> to my test program with those options.
Tony> main() { char *x = "7chars!";
Tony> strcmp(x, "This is 24 chars long!!!"); }
Tony> with those options. Do you have any include files that might
Tony> be redefining strcmp as memcmp?
In earlier versions of libc, there were some mem/str-related routines
which were too aggressive in prefetching. Perhaps Jes remembers the
details, but I'd definitely recommend to make sure you're running the
latest libc for your distro.
--david
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
` (3 preceding siblings ...)
2004-01-05 22:06 ` David Mosberger
@ 2004-01-06 0:04 ` umut aymakoglu
2004-01-06 1:14 ` Luck, Tony
` (3 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: umut aymakoglu @ 2004-01-06 0:04 UTC (permalink / raw)
To: linux-ia64
Ok - I have a small repro that segvs.
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <stdlib.h>
#define SHMBASE 0x200000000
#define AL (1024*1024)
#define MAXSEGMENTS 1
#ifndef SHM_R
#define SHM_R 0400
#endif
#ifndef SHM_W
#define SHM_W 0660
#endif
#define SHM_MODE ( SHM_R | SHM_W | IPC_CREAT )
#define KEY2SUCKS 0x52435200
unsigned long sizes[MAXSEGMENTS] ={720896};
main()
{
int shmid[MAXSEGMENTS];
char *shmptr[MAXSEGMENTS];
long addr,mykey,loop,addr_save,attempts=0;
int i;
char *name;
addr = SHMBASE;
mykey = KEY2SUCKS;
attempts = 0;
for( loop=0;loop<MAXSEGMENTS;loop++ )
{
shmid[loop]=shmget((key_t)mykey,sizes[loop],SHM_MODE);
shmptr[loop]=(char
*)shmat(shmid[loop],(void*)addr,0);
/* ALign the size on SHMLBA(16K) */
sizes[loop]=(sizes[loop] + SHMLBA - 1) & ~(SHMLBA -1);
addr=shmptr[attempts]+(unsigned long)sizes[loop];
addr_save = addr;
printf("addr1 = %p\n",addr);
/* aLign the Address on 1MB */
addr=(char *)(((unsigned long)addr + AL-1) & ~(AL-1));
printf("addr2 = %p\n",addr);
attempts++;
mykey++;
}
name = ((unsigned long)addr_save - 16);
printf("%p\n",name);
strcpy(name, "sqlexec");
ret = strcmp(name,"aaaaaaaaaaaaaaaaaaaaaaaa");
for( loop=0;loop<attempts;loop++ )
shmctl( shmid[loop],IPC_RMID,0 );
printf( "\n\tRemoved All Segments ... \n\n");
exit( 0 );
}
%gcc -O -o x x.c
%./x
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
` (4 preceding siblings ...)
2004-01-06 0:04 ` umut aymakoglu
@ 2004-01-06 1:14 ` Luck, Tony
2004-01-06 1:38 ` umut aymakoglu
` (2 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Luck, Tony @ 2004-01-06 1:14 UTC (permalink / raw)
To: linux-ia64
Didn't compile ... "ret" undefined ... so I fixed that, but
then it SEGV'd on the "strcpy" ... it didn't make it to the
strcmp().
-Tony
> -----Original Message-----
> From: umut aymakoglu [mailto:umutaymak@yahoo.com]
> Sent: Monday, January 05, 2004 4:04 PM
> To: Luck, Tony; linux-ia64@vger.kernel.org
> Cc: umuta@us.ibm.com
> Subject: RE: segv at strcmp
>
>
> Ok - I have a small repro that segvs.
>
>
>
> #include <stdio.h>
> #include <sys/ipc.h>
> #include <sys/shm.h>
> #include <string.h>
> #include <stdlib.h>
>
>
> #define SHMBASE 0x200000000
> #define AL (1024*1024)
> #define MAXSEGMENTS 1
>
>
> #ifndef SHM_R
> #define SHM_R 0400
> #endif
> #ifndef SHM_W
> #define SHM_W 0660
> #endif
>
> #define SHM_MODE ( SHM_R | SHM_W | IPC_CREAT )
> #define KEY2SUCKS 0x52435200
>
> unsigned long sizes[MAXSEGMENTS] ={720896};
>
> main()
> {
>
> int shmid[MAXSEGMENTS];
> char *shmptr[MAXSEGMENTS];
> long addr,mykey,loop,addr_save,attempts=0;
> int i;
> char *name;
>
>
> addr = SHMBASE;
> mykey = KEY2SUCKS;
> attempts = 0;
>
> for( loop=0;loop<MAXSEGMENTS;loop++ )
> {
>
> shmid[loop]=shmget((key_t)mykey,sizes[loop],SHM_MODE);
> shmptr[loop]=(char
> *)shmat(shmid[loop],(void*)addr,0);
>
> /* ALign the size on SHMLBA(16K) */
> sizes[loop]=(sizes[loop] + SHMLBA - 1) & ~(SHMLBA -1);
> addr=shmptr[attempts]+(unsigned long)sizes[loop];
> addr_save = addr;
> printf("addr1 = %p\n",addr);
>
> /* aLign the Address on 1MB */
> addr=(char *)(((unsigned long)addr + AL-1) & ~(AL-1));
>
> printf("addr2 = %p\n",addr);
> attempts++;
> mykey++;
> }
>
> name = ((unsigned long)addr_save - 16);
> printf("%p\n",name);
> strcpy(name, "sqlexec");
> ret = strcmp(name,"aaaaaaaaaaaaaaaaaaaaaaaa");
>
>
> for( loop=0;loop<attempts;loop++ )
> shmctl( shmid[loop],IPC_RMID,0 );
>
> printf( "\n\tRemoved All Segments ... \n\n");
> exit( 0 );
> }
>
> %gcc -O -o x x.c
> %./x
>
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
>
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
` (5 preceding siblings ...)
2004-01-06 1:14 ` Luck, Tony
@ 2004-01-06 1:38 ` umut aymakoglu
2004-01-06 2:01 ` Chen, Kenneth W
2004-01-06 19:58 ` umut aymakoglu
8 siblings, 0 replies; 14+ messages in thread
From: umut aymakoglu @ 2004-01-06 1:38 UTC (permalink / raw)
To: linux-ia64
[-- Attachment #1: Type: text/plain, Size: 2632 bytes --]
probably either shmget or shmat failed. There should
not be any shmget or shmat error.
i attached a working one.
thanks,
Umut
--- "Luck, Tony" <tony.luck@intel.com> wrote:
> Didn't compile ... "ret" undefined ... so I fixed
> that, but
> then it SEGV'd on the "strcpy" ... it didn't make it
> to the
> strcmp().
>
> -Tony
>
> > -----Original Message-----
> > From: umut aymakoglu [mailto:umutaymak@yahoo.com]
> > Sent: Monday, January 05, 2004 4:04 PM
> > To: Luck, Tony; linux-ia64@vger.kernel.org
> > Cc: umuta@us.ibm.com
> > Subject: RE: segv at strcmp
> >
> >
> > Ok - I have a small repro that segvs.
> >
> >
> >
> > #include <stdio.h>
> > #include <sys/ipc.h>
> > #include <sys/shm.h>
> > #include <string.h>
> > #include <stdlib.h>
> >
> >
> > #define SHMBASE 0x200000000
> > #define AL (1024*1024)
> > #define MAXSEGMENTS 1
> >
> >
> > #ifndef SHM_R
> > #define SHM_R 0400
> > #endif
> > #ifndef SHM_W
> > #define SHM_W 0660
> > #endif
> >
> > #define SHM_MODE ( SHM_R | SHM_W | IPC_CREAT )
> > #define KEY2SUCKS 0x52435200
> >
> > unsigned long sizes[MAXSEGMENTS] ={720896};
> >
> > main()
> > {
> >
> > int shmid[MAXSEGMENTS];
> > char *shmptr[MAXSEGMENTS];
> > long addr,mykey,loop,addr_save,attempts=0;
> > int i;
> > char *name;
> >
> >
> > addr = SHMBASE;
> > mykey = KEY2SUCKS;
> > attempts = 0;
> >
> > for( loop=0;loop<MAXSEGMENTS;loop++ )
> > {
> >
> >
>
shmid[loop]=shmget((key_t)mykey,sizes[loop],SHM_MODE);
> > shmptr[loop]=(char
> > *)shmat(shmid[loop],(void*)addr,0);
> >
> > /* ALign the size on SHMLBA(16K) */
> > sizes[loop]=(sizes[loop] + SHMLBA - 1) & ~(SHMLBA
> -1);
> > addr=shmptr[attempts]+(unsigned long)sizes[loop];
> > addr_save = addr;
> > printf("addr1 = %p\n",addr);
> >
> > /* aLign the Address on 1MB */
> > addr=(char *)(((unsigned long)addr + AL-1) &
> ~(AL-1));
> >
> > printf("addr2 = %p\n",addr);
> > attempts++;
> > mykey++;
> > }
> >
> > name = ((unsigned long)addr_save - 16);
> > printf("%p\n",name);
> > strcpy(name, "sqlexec");
> > ret = strcmp(name,"aaaaaaaaaaaaaaaaaaaaaaaa");
> >
> >
> > for( loop=0;loop<attempts;loop++ )
> > shmctl( shmid[loop],IPC_RMID,0 );
> >
> > printf( "\n\tRemoved All Segments ... \n\n");
> > exit( 0 );
> > }
> >
> > %gcc -O -o x x.c
> > %./x
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > New Yahoo! Photos - easier uploading and sharing.
> > http://photos.yahoo.com/
> >
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
[-- Attachment #2: x.c --]
[-- Type: text/plain, Size: 1726 bytes --]
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <stdlib.h>
#define SHMBASE 0x200000000
#define AL (1024*1024)
#define MAXSEGMENTS 1
#ifndef SHM_R
#define SHM_R 0400
#endif
#ifndef SHM_W
#define SHM_W 0660
#endif
#define SHM_MODE ( SHM_R | SHM_W | IPC_CREAT ) /* Mode Read Write */
#define KEY2SUCKS 0x52435200 /* Shared Mem Key */
unsigned long sizes[MAXSEGMENTS] ={720896};
main()
{
int shmid[MAXSEGMENTS];
char *shmptr[MAXSEGMENTS];
long addr,mykey,loop,addr_save,attempts=0;
int i,ret;
char *name;
addr = SHMBASE;
mykey = KEY2SUCKS;
attempts = 0;
for( loop=0;loop<MAXSEGMENTS;loop++ )
{
if ((shmid[loop]= shmget( (key_t)mykey,sizes[loop],SHM_MODE)) == -1)
{
printf("shmget error\n");
goto bad;
}
if((shmptr[loop]=(char *)shmat(shmid[loop],(void*)addr,0 )) == (void*)-1)
{
printf("shmat error\n");
goto bad;
}
/* ALign the size on SHMLBA(16K) */
sizes[loop] = (sizes[loop] + SHMLBA - 1) & ~(SHMLBA - 1);
addr = shmptr[attempts] + (unsigned long)sizes[loop];
addr_save = addr;
printf("addr1 = %p\n",addr);
/* aLign the Address on 1MB */
addr = (char *)(((unsigned long)addr + AL-1) & ~(AL-1));
printf("addr2 = %p\n",addr);
attempts++;
mykey++;
} /* end for loop */
name = ((unsigned long)addr_save - 16);
printf("%p\n",name);
strcpy(name, "sqlexec");
ret = strcmp(name,"aaaaaaaaaaaaaaaaaaaaaaaa");
bad:
for( loop=0;loop<attempts;loop++ )
shmctl( shmid[loop],IPC_RMID,0 );
printf( "\n\tRemoved All Segments ... \n\n");
exit( 0 );
}
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
` (6 preceding siblings ...)
2004-01-06 1:38 ` umut aymakoglu
@ 2004-01-06 2:01 ` Chen, Kenneth W
2004-01-06 19:58 ` umut aymakoglu
8 siblings, 0 replies; 14+ messages in thread
From: Chen, Kenneth W @ 2004-01-06 2:01 UTC (permalink / raw)
To: linux-ia64
The size rounding is wrong:
sizes[loop] = (sizes[loop] + SHMLBA - 1) & ~(SHMLBA - 1);
will make addr falls outside the shared memory segment, which is the
reason why segfault on strcpy. Once that is fixed, it doesn't segfault
on strcmp either.
- Ken
-----Original Message-----
From: linux-ia64-owner@vger.kernel.org
[mailto:linux-ia64-owner@vger.kernel.org] On Behalf Of umut aymakoglu
Sent: Monday, January 05, 2004 5:38 PM
To: Luck, Tony; linux-ia64@vger.kernel.org
Cc: umuta@us.ibm.com
Subject: RE: segv at strcmp
probably either shmget or shmat failed. There should
not be any shmget or shmat error.
i attached a working one.
thanks,
Umut
--- "Luck, Tony" <tony.luck@intel.com> wrote:
> Didn't compile ... "ret" undefined ... so I fixed
> that, but
> then it SEGV'd on the "strcpy" ... it didn't make it
> to the
> strcmp().
>
> -Tony
>
> > -----Original Message-----
> > From: umut aymakoglu [mailto:umutaymak@yahoo.com]
> > Sent: Monday, January 05, 2004 4:04 PM
> > To: Luck, Tony; linux-ia64@vger.kernel.org
> > Cc: umuta@us.ibm.com
> > Subject: RE: segv at strcmp
> >
> >
> > Ok - I have a small repro that segvs.
> >
> >
> >
> > #include <stdio.h>
> > #include <sys/ipc.h>
> > #include <sys/shm.h>
> > #include <string.h>
> > #include <stdlib.h>
> >
> >
> > #define SHMBASE 0x200000000
> > #define AL (1024*1024)
> > #define MAXSEGMENTS 1
> >
> >
> > #ifndef SHM_R
> > #define SHM_R 0400
> > #endif
> > #ifndef SHM_W
> > #define SHM_W 0660
> > #endif
> >
> > #define SHM_MODE ( SHM_R | SHM_W | IPC_CREAT )
> > #define KEY2SUCKS 0x52435200
> >
> > unsigned long sizes[MAXSEGMENTS] ={720896};
> >
> > main()
> > {
> >
> > int shmid[MAXSEGMENTS];
> > char *shmptr[MAXSEGMENTS];
> > long addr,mykey,loop,addr_save,attempts=0;
> > int i;
> > char *name;
> >
> >
> > addr = SHMBASE;
> > mykey = KEY2SUCKS;
> > attempts = 0;
> >
> > for( loop=0;loop<MAXSEGMENTS;loop++ )
> > {
> >
> >
>
shmid[loop]=shmget((key_t)mykey,sizes[loop],SHM_MODE);
> > shmptr[loop]=(char
> > *)shmat(shmid[loop],(void*)addr,0);
> >
> > /* ALign the size on SHMLBA(16K) */
> > sizes[loop]=(sizes[loop] + SHMLBA - 1) & ~(SHMLBA
> -1);
> > addr=shmptr[attempts]+(unsigned long)sizes[loop];
> > addr_save = addr;
> > printf("addr1 = %p\n",addr);
> >
> > /* aLign the Address on 1MB */
> > addr=(char *)(((unsigned long)addr + AL-1) &
> ~(AL-1));
> >
> > printf("addr2 = %p\n",addr);
> > attempts++;
> > mykey++;
> > }
> >
> > name = ((unsigned long)addr_save - 16);
> > printf("%p\n",name);
> > strcpy(name, "sqlexec");
> > ret = strcmp(name,"aaaaaaaaaaaaaaaaaaaaaaaa");
> >
> >
> > for( loop=0;loop<attempts;loop++ )
> > shmctl( shmid[loop],IPC_RMID,0 );
> >
> > printf( "\n\tRemoved All Segments ... \n\n");
> > exit( 0 );
> > }
> >
> > %gcc -O -o x x.c
> > %./x
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > New Yahoo! Photos - easier uploading and sharing.
> > http://photos.yahoo.com/
> >
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
^ permalink raw reply [flat|nested] 14+ messages in thread* RE: segv at strcmp
2004-01-05 19:08 umut aymakoglu
` (7 preceding siblings ...)
2004-01-06 2:01 ` Chen, Kenneth W
@ 2004-01-06 19:58 ` umut aymakoglu
8 siblings, 0 replies; 14+ messages in thread
From: umut aymakoglu @ 2004-01-06 19:58 UTC (permalink / raw)
To: linux-ia64
[-- Attachment #1: Type: text/plain, Size: 4058 bytes --]
The problem seems to be the gcc 3.2-29 we have on
United Linux 1.0. The binary built with this does not
also work on RedHat. The binary built with gcc
3.2.3-20 on Redhat works fine.
The problem with the segv at strcpy() was due to the
unaligned size. I have attached the corrected program.
Does anybody know where i can find the latest fixpack
on United Linux 1.0?
thanks,
Umut
--- "Chen, Kenneth W" <kenneth.w.chen@intel.com>
wrote:
> The size rounding is wrong:
>
> sizes[loop] = (sizes[loop] + SHMLBA - 1) & ~(SHMLBA
> - 1);
>
> will make addr falls outside the shared memory
> segment, which is the
> reason why segfault on strcpy. Once that is fixed,
> it doesn't segfault
> on strcmp either.
>
> - Ken
>
>
> -----Original Message-----
> From: linux-ia64-owner@vger.kernel.org
> [mailto:linux-ia64-owner@vger.kernel.org] On Behalf
> Of umut aymakoglu
> Sent: Monday, January 05, 2004 5:38 PM
> To: Luck, Tony; linux-ia64@vger.kernel.org
> Cc: umuta@us.ibm.com
> Subject: RE: segv at strcmp
>
>
> probably either shmget or shmat failed. There should
> not be any shmget or shmat error.
>
> i attached a working one.
>
> thanks,
> Umut
>
>
>
> --- "Luck, Tony" <tony.luck@intel.com> wrote:
> > Didn't compile ... "ret" undefined ... so I fixed
> > that, but
> > then it SEGV'd on the "strcpy" ... it didn't make
> it
> > to the
> > strcmp().
> >
> > -Tony
> >
> > > -----Original Message-----
> > > From: umut aymakoglu
> [mailto:umutaymak@yahoo.com]
> > > Sent: Monday, January 05, 2004 4:04 PM
> > > To: Luck, Tony; linux-ia64@vger.kernel.org
> > > Cc: umuta@us.ibm.com
> > > Subject: RE: segv at strcmp
> > >
> > >
> > > Ok - I have a small repro that segvs.
> > >
> > >
> > >
> > > #include <stdio.h>
> > > #include <sys/ipc.h>
> > > #include <sys/shm.h>
> > > #include <string.h>
> > > #include <stdlib.h>
> > >
> > >
> > > #define SHMBASE 0x200000000
> > > #define AL (1024*1024)
> > > #define MAXSEGMENTS 1
> > >
> > >
> > > #ifndef SHM_R
> > > #define SHM_R 0400
> > > #endif
> > > #ifndef SHM_W
> > > #define SHM_W 0660
> > > #endif
> > >
> > > #define SHM_MODE ( SHM_R | SHM_W | IPC_CREAT
> )
> > > #define KEY2SUCKS 0x52435200
> > >
> > > unsigned long sizes[MAXSEGMENTS] ={720896};
> > >
> > > main()
> > > {
> > >
> > > int shmid[MAXSEGMENTS];
> > > char *shmptr[MAXSEGMENTS];
> > > long addr,mykey,loop,addr_save,attempts=0;
> > > int i;
> > > char *name;
> > >
> > >
> > > addr = SHMBASE;
> > > mykey = KEY2SUCKS;
> > > attempts = 0;
> > >
> > > for( loop=0;loop<MAXSEGMENTS;loop++ )
> > > {
> > >
> > >
> >
>
shmid[loop]=shmget((key_t)mykey,sizes[loop],SHM_MODE);
> > > shmptr[loop]=(char
> > > *)shmat(shmid[loop],(void*)addr,0);
> > >
> > > /* ALign the size on SHMLBA(16K) */
> > > sizes[loop]=(sizes[loop] + SHMLBA - 1) &
> ~(SHMLBA
> > -1);
> > > addr=shmptr[attempts]+(unsigned
> long)sizes[loop];
> > > addr_save = addr;
> > > printf("addr1 = %p\n",addr);
> > >
> > > /* aLign the Address on 1MB */
> > > addr=(char *)(((unsigned long)addr + AL-1) &
> > ~(AL-1));
> > >
> > > printf("addr2 = %p\n",addr);
> > > attempts++;
> > > mykey++;
> > > }
> > >
> > > name = ((unsigned long)addr_save - 16);
> > > printf("%p\n",name);
> > > strcpy(name, "sqlexec");
> > > ret = strcmp(name,"aaaaaaaaaaaaaaaaaaaaaaaa");
> > >
> > >
> > > for( loop=0;loop<attempts;loop++ )
> > > shmctl( shmid[loop],IPC_RMID,0 );
> > >
> > > printf( "\n\tRemoved All Segments ... \n\n");
> > > exit( 0 );
> > > }
> > >
> > > %gcc -O -o x x.c
> > > %./x
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > New Yahoo! Photos - easier uploading and
> sharing.
> > > http://photos.yahoo.com/
> > >
>
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
[-- Attachment #2: x.c --]
[-- Type: text/plain, Size: 1749 bytes --]
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <stdlib.h>
#define SHMBASE 0x200000000
#define AL (1024*1024)
#define MAXSEGMENTS 1
#ifndef SHM_R
#define SHM_R 0400
#endif
#ifndef SHM_W
#define SHM_W 0660
#endif
#define SHM_MODE ( SHM_R | SHM_W | IPC_CREAT ) /* Mode Read Write */
#define KEY2SUCKS 0x52435200 /* Shared Mem Key */
unsigned long sizes[MAXSEGMENTS] ={1024*1024};
main()
{
int shmid[MAXSEGMENTS];
char *shmptr[MAXSEGMENTS];
long addr,mykey,loop,addr_save,attempts=0;
int i,ret;
char *name;
addr = SHMBASE;
mykey = KEY2SUCKS;
attempts = 0;
for( loop=0;loop<MAXSEGMENTS;loop++ )
{
printf("size before= %d\n",sizes[loop]);
if ((shmid[loop]= shmget( (key_t)mykey,sizes[loop],SHM_MODE)) == -1)
{
printf("shmget error\n");
goto bad;
}
if((shmptr[loop]=(char *)shmat(shmid[loop],(void*)addr,0 )) == (void*)-1)
{
printf("shmat error\n");
goto bad;
}
sizes[loop] = (sizes[loop] + AL - 1) & ~(AL - 1);
printf("size before= %d\n",sizes[loop]);
addr = shmptr[attempts] + (unsigned long)sizes[loop];
printf("addr1 = %p\n",addr);
attempts++;
mykey++;
/* aLign the Address on 1MB */
addr = (char *)(((unsigned long)addr + AL-1) & ~(AL-1));
printf("addr2 = %p\n",addr);
} /* end for loop */
name = ((unsigned long)addr - 16);
printf("%p\n",name);
strcpy(name, "sqlexec");
ret = strcmp(name,"aaaaaaaaaaaaaaaaaaaaaaaa");
bad:
for( loop=0;loop<attempts;loop++ )
shmctl( shmid[loop],IPC_RMID,0 );
printf( "\n\tRemoved All Segments ... \n\n");
exit( 0 );
}
^ permalink raw reply [flat|nested] 14+ messages in thread