public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: umut aymakoglu <umutaymak@yahoo.com>
To: linux-ia64@vger.kernel.org
Subject: RE: segv at strcmp
Date: Tue, 06 Jan 2004 01:38:27 +0000	[thread overview]
Message-ID: <20040106013827.37645.qmail@web60004.mail.yahoo.com> (raw)
In-Reply-To: <20040105190848.66033.qmail@web60006.mail.yahoo.com>

[-- 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 );

}

  parent reply	other threads:[~2004-01-06  1:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-05 19:08 segv at strcmp 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
2004-01-06  0:04 ` umut aymakoglu
2004-01-06  1:14 ` Luck, Tony
2004-01-06  1:38 ` umut aymakoglu [this message]
2004-01-06  2:01 ` Chen, Kenneth W
2004-01-06 19:58 ` umut aymakoglu
  -- strict thread matches above, loose matches on Subject: below --
2003-12-24 23:13 umut aymakoglu
2003-12-24 23:44 ` Jeff Woods
2003-12-25  0:25 ` Luck, Tony
2003-12-25  1:11 ` Zhu, Yi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040106013827.37645.qmail@web60004.mail.yahoo.com \
    --to=umutaymak@yahoo.com \
    --cc=linux-ia64@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox