mmap() problems betrween process

Hi All!,

I been trying to share memory between two process but without luck. The
first process will create the share memory without problem, but it’s the
second process that giving me problems. The second process will open the
share memory object without problems with sh_open(), but when I use mmap()
it always returns NOT SUPPORTED(48). Also the share memory name and size
is: “/dev/shmem/SCDM” and 8192bytes, thus I am using shmem an not a file
system. Below is the code I am using:

////////////////////////////////////////////////////////////////////////////
/////
Process #1: (Creates the Share memory object)
////////////////////////////////////////////////////////////////////////////
////
fw_error CDataModule::Create( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );
FW_PRECONDITION( size > 0 );

fw_int16 osErr, shmem_fd;
unsigned char *addr; // Use for the share memory addresse

osErr = EOK; // No error set

// What do we create here share memory
if ( (shmem_fd = shm_open( name, O_EXCL|O_CREAT|O_RDWR, 0777 )) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Size the File
ftruncate( shmem_fd, size + sizeof(_Header));

// the only process that can get here is ESLServices
if ((addr = (unsigned char*)mmap(0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}
// closing the file decriptor since we do not need it anymore
close(shmem_fd);
}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Create( %s ) Name to long\n”,
name );
else if ( osErr == EEXIST )
return err_KnownModule;
else if ( osErr == ENOSPC )
return err_KnownModule; // No RAM results even though the DM exists.
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Create( %s ) returned
unexcepted error %d\n”, name, osErr );

FW_POSTCONDITION( addr != 0 ); // check to make sure we ahve a address

(unsigned char*)m_pHeader = addr; // Address back from mmap.
m_pHeader->MagicNum = MagicNum;
m_pHeader->MaxSize = size;
m_pHeader->AllocatedSize = 0;
m_pHeader->pRoot = 0;
m_pDataStart = (fw_int8*)( m_pHeader+1 ); // data starts right after the
header
m_Lock.Initialize( m_pHeader->Lock, fw_true );

Dump();

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}
////////////////////////////////////////////////////////////////////////////
/////////////////////////////
Process #2:
////////////////////////////////////////////////////////////////////////////
////////////////////////////
fw_error CDataModule::Open( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );

fw_int16 osErr = 0;
fw_int16 shmem_fd;
unsigned char* addr; // Use for the share memory addresse
//unsigned char* tmpaddr; // Use for the share memory addresse


//tmpaddr = 0x40100000;

//Dump();

// What do we create here share memory
if ( shmem_fd = shm_open( name, O_EXCL|O_RDWR, 0777 ) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Lets get the address space of the share Memory
//addr = (unsigned char*)m_pHeader; // Address back from mmap.

//ftruncate( shmem_fd, size);

// We map to the same space has ESLServices
if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_NOSYNCFILE|MAP_SHARED, shmem_fd, 0)) ==
MAP_FAILED)
//if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}

close(shmem_fd);

}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Open( %s ) Name to long\n”,
name );
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Open returns unexpected
error %d\n”, osErr );


FW_POSTCONDITION( addr != 0 );

(unsigned char*)m_pHeader = addr; // Address back from mmap.

// debug
Dump();
// debug

if ( m_pHeader->MagicNum != MagicNum )
return fw_errmsg( err_InvalidModule, “CDataModule::Open( %s ) invalid
module\n”, name );

m_pDataStart = (fw_int8*)( m_pHeader+1 );
m_Lock.Initialize( m_pHeader->Lock );

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}

“Stephane Grenier” <sgrenier@excalibur.com> wrote in message
news:9te1hr$bj$1@inn.qnx.com

Hi All!,

I been trying to share memory between two process but without luck. The
first process will create the share memory without problem, but it’s the
second process that giving me problems. The second process will open the
share memory object without problems with sh_open(), but when I use mmap()
it always returns NOT SUPPORTED(48). Also the share memory name and size
is: “/dev/shmem/SCDM” and 8192bytes, thus I am using shmem an not a file
system. Below is the code I am using:

I’m guessing here but the name of your shared memory should start with /.
In your case the name should be “/SCDM”. This is POSIX behavior.


////////////////////////////////////////////////////////////////////////////
/////
Process #1: (Creates the Share memory object)

////////////////////////////////////////////////////////////////////////////
////
fw_error CDataModule::Create( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );
FW_PRECONDITION( size > 0 );

fw_int16 osErr, shmem_fd;
unsigned char *addr; // Use for the share memory addresse

osErr = EOK; // No error set

// What do we create here share memory
if ( (shmem_fd = shm_open( name, O_EXCL|O_CREAT|O_RDWR, 0777 )) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Size the File
ftruncate( shmem_fd, size + sizeof(_Header));

// the only process that can get here is ESLServices
if ((addr = (unsigned char*)mmap(0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}
// closing the file decriptor since we do not need it anymore
close(shmem_fd);
}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Create( %s ) Name to
long\n”,
name );
else if ( osErr == EEXIST )
return err_KnownModule;
else if ( osErr == ENOSPC )
return err_KnownModule; // No RAM results even though the DM exists.
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Create( %s ) returned
unexcepted error %d\n”, name, osErr );

FW_POSTCONDITION( addr != 0 ); // check to make sure we ahve a address

(unsigned char*)m_pHeader = addr; // Address back from mmap.
m_pHeader->MagicNum = MagicNum;
m_pHeader->MaxSize = size;
m_pHeader->AllocatedSize = 0;
m_pHeader->pRoot = 0;
m_pDataStart = (fw_int8*)( m_pHeader+1 ); // data starts right after the
header
m_Lock.Initialize( m_pHeader->Lock, fw_true );

Dump();

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}

////////////////////////////////////////////////////////////////////////////
/////////////////////////////
Process #2:

////////////////////////////////////////////////////////////////////////////
////////////////////////////
fw_error CDataModule::Open( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );

fw_int16 osErr = 0;
fw_int16 shmem_fd;
unsigned char* addr; // Use for the share memory addresse
//unsigned char* tmpaddr; // Use for the share memory addresse


//tmpaddr = 0x40100000;

//Dump();

// What do we create here share memory
if ( shmem_fd = shm_open( name, O_EXCL|O_RDWR, 0777 ) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Lets get the address space of the share Memory
//addr = (unsigned char*)m_pHeader; // Address back from mmap.

//ftruncate( shmem_fd, size);

// We map to the same space has ESLServices
if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_NOSYNCFILE|MAP_SHARED, shmem_fd, 0))

MAP_FAILED)
//if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}

close(shmem_fd);

}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Open( %s ) Name to long\n”,
name );
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Open returns unexpected
error %d\n”, osErr );


FW_POSTCONDITION( addr != 0 );

(unsigned char*)m_pHeader = addr; // Address back from mmap.

// debug
Dump();
// debug

if ( m_pHeader->MagicNum != MagicNum )
return fw_errmsg( err_InvalidModule, “CDataModule::Open( %s ) invalid
module\n”, name );

m_pDataStart = (fw_int8*)( m_pHeader+1 );
m_Lock.Initialize( m_pHeader->Lock );

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}

\

Hi All!,

I have rename the name to now “/SCDM” instead of “/dev/shmem/SCDM” when I
open the share memory.
What give!!

Cheers!, Steph

“Mario Charest” <mcharest@clipzinformatic.com> wrote in message
news:9te3h4$2ij$1@inn.qnx.com

“Stephane Grenier” <> sgrenier@excalibur.com> > wrote in message
news:9te1hr$bj$> 1@inn.qnx.com> …
Hi All!,

I been trying to share memory between two process but without luck. The
first process will create the share memory without problem, but it’s the
second process that giving me problems. The second process will open
the
share memory object without problems with sh_open(), but when I use
mmap()
it always returns NOT SUPPORTED(48). Also the share memory name and
size
is: “/dev/shmem/SCDM” and 8192bytes, thus I am using shmem an not a file
system. Below is the code I am using:


I’m guessing here but the name of your shared memory should start with /.
In your case the name should be “/SCDM”. This is POSIX behavior.




////////////////////////////////////////////////////////////////////////////
/////
Process #1: (Creates the Share memory object)


////////////////////////////////////////////////////////////////////////////
////
fw_error CDataModule::Create( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );
FW_PRECONDITION( size > 0 );

fw_int16 osErr, shmem_fd;
unsigned char *addr; // Use for the share memory addresse

osErr = EOK; // No error set

// What do we create here share memory
if ( (shmem_fd = shm_open( name, O_EXCL|O_CREAT|O_RDWR, 0777 )) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Size the File
ftruncate( shmem_fd, size + sizeof(_Header));

// the only process that can get here is ESLServices
if ((addr = (unsigned char*)mmap(0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}
// closing the file decriptor since we do not need it anymore
close(shmem_fd);
}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Create( %s ) Name to
long\n”,
name );
else if ( osErr == EEXIST )
return err_KnownModule;
else if ( osErr == ENOSPC )
return err_KnownModule; // No RAM results even though the DM exists.
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Create( %s ) returned
unexcepted error %d\n”, name, osErr );

FW_POSTCONDITION( addr != 0 ); // check to make sure we ahve a address

(unsigned char*)m_pHeader = addr; // Address back from mmap.
m_pHeader->MagicNum = MagicNum;
m_pHeader->MaxSize = size;
m_pHeader->AllocatedSize = 0;
m_pHeader->pRoot = 0;
m_pDataStart = (fw_int8*)( m_pHeader+1 ); // data starts right after
the
header
m_Lock.Initialize( m_pHeader->Lock, fw_true );

Dump();

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}


////////////////////////////////////////////////////////////////////////////
/////////////////////////////
Process #2:


////////////////////////////////////////////////////////////////////////////
////////////////////////////
fw_error CDataModule::Open( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );

fw_int16 osErr = 0;
fw_int16 shmem_fd;
unsigned char* addr; // Use for the share memory addresse
//unsigned char* tmpaddr; // Use for the share memory addresse


//tmpaddr = 0x40100000;

//Dump();

// What do we create here share memory
if ( shmem_fd = shm_open( name, O_EXCL|O_RDWR, 0777 ) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Lets get the address space of the share Memory
//addr = (unsigned char*)m_pHeader; // Address back from mmap.

//ftruncate( shmem_fd, size);

// We map to the same space has ESLServices
if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_NOSYNCFILE|MAP_SHARED, shmem_fd, 0))

MAP_FAILED)
//if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}

close(shmem_fd);

}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Open( %s ) Name to
long\n”,
name );
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Open returns
unexpected
error %d\n”, osErr );


FW_POSTCONDITION( addr != 0 );

(unsigned char*)m_pHeader = addr; // Address back from mmap.

// debug
Dump();
// debug

if ( m_pHeader->MagicNum != MagicNum )
return fw_errmsg( err_InvalidModule, “CDataModule::Open( %s ) invalid
module\n”, name );

m_pDataStart = (fw_int8*)( m_pHeader+1 );
m_Lock.Initialize( m_pHeader->Lock );

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}



\

Ok!, long day!,

I am stil having the same behavior, with “/SCDM” or “/dev/shmem/SCDM”.
mmap() will return NOT SUPPORTED(48) everytime I open it share memory object
from the second process. No error when doing shm_open().

Cheers!, Steph

“Stephane Grenier” <sgrenier@excalibur.com> wrote in message
news:9tehin$fod$1@inn.qnx.com

Hi All!,

I have rename the name to now “/SCDM” instead of “/dev/shmem/SCDM” when I
open the share memory.
What give!!

Cheers!, Steph

“Mario Charest” <> mcharest@clipzinformatic.com> > wrote in message
news:9te3h4$2ij$> 1@inn.qnx.com> …

“Stephane Grenier” <> sgrenier@excalibur.com> > wrote in message
news:9te1hr$bj$> 1@inn.qnx.com> …
Hi All!,

I been trying to share memory between two process but without luck.
The
first process will create the share memory without problem, but it’s
the
second process that giving me problems. The second process will open
the
share memory object without problems with sh_open(), but when I use
mmap()
it always returns NOT SUPPORTED(48). Also the share memory name and
size
is: “/dev/shmem/SCDM” and 8192bytes, thus I am using shmem an not a
file
system. Below is the code I am using:


I’m guessing here but the name of your shared memory should start with
/.
In your case the name should be “/SCDM”. This is POSIX behavior.





////////////////////////////////////////////////////////////////////////////
/////
Process #1: (Creates the Share memory object)



////////////////////////////////////////////////////////////////////////////
////
fw_error CDataModule::Create( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );
FW_PRECONDITION( size > 0 );

fw_int16 osErr, shmem_fd;
unsigned char *addr; // Use for the share memory addresse

osErr = EOK; // No error set

// What do we create here share memory
if ( (shmem_fd = shm_open( name, O_EXCL|O_CREAT|O_RDWR, 0777 ))
== -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Size the File
ftruncate( shmem_fd, size + sizeof(_Header));

// the only process that can get here is ESLServices
if ((addr = (unsigned char*)mmap(0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_SHARED, shmem_fd, 0)) ==
MAP_FAILED)
{
osErr = errno;
}
// closing the file decriptor since we do not need it anymore
close(shmem_fd);
}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Create( %s ) Name to
long\n”,
name );
else if ( osErr == EEXIST )
return err_KnownModule;
else if ( osErr == ENOSPC )
return err_KnownModule; // No RAM results even though the DM
exists.
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Create( %s )
returned
unexcepted error %d\n”, name, osErr );

FW_POSTCONDITION( addr != 0 ); // check to make sure we ahve a
address

(unsigned char*)m_pHeader = addr; // Address back from mmap.
m_pHeader->MagicNum = MagicNum;
m_pHeader->MaxSize = size;
m_pHeader->AllocatedSize = 0;
m_pHeader->pRoot = 0;
m_pDataStart = (fw_int8*)( m_pHeader+1 ); // data starts right after
the
header
m_Lock.Initialize( m_pHeader->Lock, fw_true );

Dump();

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}



////////////////////////////////////////////////////////////////////////////
/////////////////////////////
Process #2:



////////////////////////////////////////////////////////////////////////////
////////////////////////////
fw_error CDataModule::Open( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );

fw_int16 osErr = 0;
fw_int16 shmem_fd;
unsigned char* addr; // Use for the share memory addresse
//unsigned char* tmpaddr; // Use for the share memory addresse


//tmpaddr = 0x40100000;

//Dump();

// What do we create here share memory
if ( shmem_fd = shm_open( name, O_EXCL|O_RDWR, 0777 ) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Lets get the address space of the share Memory
//addr = (unsigned char*)m_pHeader; // Address back from mmap.

//ftruncate( shmem_fd, size);

// We map to the same space has ESLServices
if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_NOSYNCFILE|MAP_SHARED, shmem_fd,
0))

MAP_FAILED)
//if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}

close(shmem_fd);

}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Open( %s ) Name to
long\n”,
name );
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Open returns
unexpected
error %d\n”, osErr );


FW_POSTCONDITION( addr != 0 );

(unsigned char*)m_pHeader = addr; // Address back from mmap.

// debug
Dump();
// debug

if ( m_pHeader->MagicNum != MagicNum )
return fw_errmsg( err_InvalidModule, “CDataModule::Open( %s )
invalid
module\n”, name );

m_pDataStart = (fw_int8*)( m_pHeader+1 );
m_Lock.Initialize( m_pHeader->Lock );

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}





\

Afternoon,

Try getting rid of the ftruncate in Process two.

I’ve also attached some sample code that uses shared memory.

Untar and unzip it, then type make in the semaphores directory.


Cheers,
-Brian

+================================================+
Brian K. Hlady bhlady@qnx.com
OEM Support Rep QSSL
+================================================+



begin 666 shmem_ex.tgz
M’XL(*'2^CL``^U9>W/:2!+/O]*GZ")QEX>@AC8LN/4$8P3KL!V8ZSY[A4 M0AI %Y X2=CQ>?W=KWM&$I)!.-ZRG4NMVE5&FD<_9J9_T]TRV' Q+AGTOZB_ M>!I2RHI2J]5>*$CUVD[L%ZE<W<&^^MM*O5)5JE5\+K_%IQ>@/)$^,5JXGN8
MO’ T5Y^81NX^_I_47II6OIT83!XYWJ&:1<G[^58T]0<KK1ISIC:EHT9<7XF
M&6P:&6P$!ZT/IQ]E"=\L>E75L:@>=QMJBK(\J5M&K
JN2YS/,CJMN5ZH$]P
M$[:!?9[>8@VC1:6[IFVE0=9DF(=YI3E86&YYMAB!IB6!U/38CGY1I9&H^G"
MG4#VZ+33R>WA^]S!A%D47GFH(3,^9:[N[5C?/6VW(NOUGFCWV_U!NWC(SAL
MM#NM@UW@[9D"A6"B’<>EMJ0IIRU+TIPIA99TH:VXV7Q^5;&-6!3EVTRVK?Y
M\8QZB$$/,RS!'NN?^+HF4C5"%JS]RQQY8V8TG[Z+
;SDSS\E L%LFZ^+FY
MU-2IB5/QH-$OUV:=N;^CO87CGMQGLG#4FX@“U7GO,C#<=%];MC/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O%++)Z1!GWQ/CE()XG^E3./U7JEDL;ST’+[Q"L9O’W>[Q4>PST)V.
ML.<.$J#+"%C
A"-BN"U)9:6RR6H0#@@1%/TJ3=?E3>R=XU1#:.[P%GH'JA+ MYZ HGL?=0#BS$GF'WH3#O=R%#S*16QX]*.II>W):0R:*^K]?1GON_+_ZME9? MYO_TC/G_3BWU_^>@OTG^GY#EQ^H"P>NR.! ID@2!JLBQOZL.:8VG#+W@84!
M"NF0,(+8!JF)JF! WQ?Q7)<#)5(4H]RAS,>[C=T’2/N//B#,:JU&,C(0:>
M,&=FNBYFHRX%+TJ]7H=L4#20)9+UT
(#
(D/36P=1,L/Z^H/3UE^%%_\,.@ M9ZA )-8@))&L]S%)X4$C7C)!YF\/_\UT/^'"R\K2:8>RD1I38GB'#,?QLD8\ MLH^6-J2@M &_1&V#&V=:IA>/L46B0BI8"86 /)2%<O\O2>W?-JN5TLSS+V:> MCYEW]J>,S0D2RPI.T7\X]91<F@C9LK))I3/M&_&FA7P"45L"NM]_5#%%:EI
M1>]Q
GK<QYKT=146<] 0B81G4IEA$]SQ*;1-D5FQ\D0<P=8SB2D#IBMN(F*#
M9S0]SL6K90D$W@C/.)9U_WU(?Q++GJ)_5Q3*GE L82B&W5A34WKVTI0\^RU ME)122BFEE%)**:644DHII9122BFEE%)**:644DHII9122BFEE%+Z6?0_4&A- %0P!0````
end

“Stephane Grenier” <sgrenier@excalibur.com> wrote in message
news:9te1hr$bj$1@inn.qnx.com

Hi All!,

I been trying to share memory between two process but without luck. The
first process will create the share memory without problem, but it’s the
second process that giving me problems. The second process will open the
share memory object without problems with sh_open(), but when I use mmap()
it always returns NOT SUPPORTED(48). Also the share memory name and size
is: “/dev/shmem/SCDM” and 8192bytes, thus I am using shmem an not a file
system. Below is the code I am using:

The name must contain a single forward slash at the start to be POSIX
compliant. So use “/SCDM”. Look further down too:

////////////////////////////////////////////////////////////////////////////
/////
Process #1: (Creates the Share memory object)

////////////////////////////////////////////////////////////////////////////
////
fw_error CDataModule::Create( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );
FW_PRECONDITION( size > 0 );

fw_int16 osErr, shmem_fd;

File descriptors have type int which is 32 bits on most platforms. Are you
sure you meant fw_int16? Probably won’t make a difference since fds usually
have low numbers. Connection ids however can have big numbers, so be
careful.

unsigned char *addr; // Use for the share memory addresse

osErr = EOK; // No error set

// What do we create here share memory
if ( (shmem_fd = shm_open( name, O_EXCL|O_CREAT|O_RDWR, 0777 )) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Size the File
ftruncate( shmem_fd, size + sizeof(_Header));

// the only process that can get here is ESLServices
if ((addr = (unsigned char*)mmap(0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}
// closing the file decriptor since we do not need it anymore
close(shmem_fd);
}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Create( %s ) Name to
long\n”,
name );
else if ( osErr == EEXIST )
return err_KnownModule;
else if ( osErr == ENOSPC )
return err_KnownModule; // No RAM results even though the DM exists.
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Create( %s ) returned
unexcepted error %d\n”, name, osErr );

FW_POSTCONDITION( addr != 0 ); // check to make sure we ahve a address

(unsigned char*)m_pHeader = addr; // Address back from mmap.

The above code is non-standard and doesn’t even compile on any C++ compiler
I know of except for g++. The cast produces an rvalue, but then you assign
to it which requires a modifiable lvalue. The fact that the code appears to
work on g++ must be an extension - ahh, 6.8 on
gcc.gnu.org/onlinedocs/gcc_6.html. Try the more explicit and portable:

m_pHeader = reinterpret_cast<_Header*>(addr);

or if you don’t use the new style C++ casts (you should):

m_pHeader = (_Header*)addr;

m_pHeader->MagicNum = MagicNum;
m_pHeader->MaxSize = size;
m_pHeader->AllocatedSize = 0;
m_pHeader->pRoot = 0;
m_pDataStart = (fw_int8*)( m_pHeader+1 ); // data starts right after the
header
m_Lock.Initialize( m_pHeader->Lock, fw_true );

Dump();

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}

////////////////////////////////////////////////////////////////////////////
/////////////////////////////
Process #2:

////////////////////////////////////////////////////////////////////////////
////////////////////////////
fw_error CDataModule::Open( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );

fw_int16 osErr = 0;
fw_int16 shmem_fd;

32 bit again.

unsigned char* addr; // Use for the share memory addresse
file://unsigned char* tmpaddr; // Use for the share memory addresse


file://tmpaddr = 0x40100000;

file://Dump();

// What do we create here share memory
if ( shmem_fd = shm_open( name, O_EXCL|O_RDWR, 0777 ) == -1)

Why the O_EXCL flag? I think it only makes sense with O_CREAT.

{
osErr = errno;
}
else // We need to size and map the share memory
{
// Lets get the address space of the share Memory
file://addr = (unsigned char*)m_pHeader; // Address back from mmap.

file://ftruncate( shmem_fd, size);

// We map to the same space has ESLServices
if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_NOSYNCFILE|MAP_SHARED, shmem_fd, 0))

MAP_FAILED)

The qnx docs don’t mention MAP_NOSYNCFILE. That’s probably your problem -
remove it.

Tom

I cannot find MAP_NOSYNCFILE anywhere in the documentation. Is this a new
flag or has it been obsoleted?

Rex

“Stephane Grenier” <sgrenier@excalibur.com> wrote in message
news:9te1hr$bj$1@inn.qnx.com

Hi All!,

I been trying to share memory between two process but without luck. The
first process will create the share memory without problem, but it’s the
second process that giving me problems. The second process will open the
share memory object without problems with sh_open(), but when I use mmap()
it always returns NOT SUPPORTED(48). Also the share memory name and size
is: “/dev/shmem/SCDM” and 8192bytes, thus I am using shmem an not a file
system. Below is the code I am using:


////////////////////////////////////////////////////////////////////////////
/////
Process #1: (Creates the Share memory object)

////////////////////////////////////////////////////////////////////////////
////
fw_error CDataModule::Create( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );
FW_PRECONDITION( size > 0 );

fw_int16 osErr, shmem_fd;
unsigned char *addr; // Use for the share memory addresse

osErr = EOK; // No error set

// What do we create here share memory
if ( (shmem_fd = shm_open( name, O_EXCL|O_CREAT|O_RDWR, 0777 )) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Size the File
ftruncate( shmem_fd, size + sizeof(_Header));

// the only process that can get here is ESLServices
if ((addr = (unsigned char*)mmap(0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}
// closing the file decriptor since we do not need it anymore
close(shmem_fd);
}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Create( %s ) Name to
long\n”,
name );
else if ( osErr == EEXIST )
return err_KnownModule;
else if ( osErr == ENOSPC )
return err_KnownModule; // No RAM results even though the DM exists.
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Create( %s ) returned
unexcepted error %d\n”, name, osErr );

FW_POSTCONDITION( addr != 0 ); // check to make sure we ahve a address

(unsigned char*)m_pHeader = addr; // Address back from mmap.
m_pHeader->MagicNum = MagicNum;
m_pHeader->MaxSize = size;
m_pHeader->AllocatedSize = 0;
m_pHeader->pRoot = 0;
m_pDataStart = (fw_int8*)( m_pHeader+1 ); // data starts right after the
header
m_Lock.Initialize( m_pHeader->Lock, fw_true );

Dump();

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}

////////////////////////////////////////////////////////////////////////////
/////////////////////////////
Process #2:

////////////////////////////////////////////////////////////////////////////
////////////////////////////
fw_error CDataModule::Open( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );

fw_int16 osErr = 0;
fw_int16 shmem_fd;
unsigned char* addr; // Use for the share memory addresse
//unsigned char* tmpaddr; // Use for the share memory addresse


//tmpaddr = 0x40100000;

//Dump();

// What do we create here share memory
if ( shmem_fd = shm_open( name, O_EXCL|O_RDWR, 0777 ) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Lets get the address space of the share Memory
//addr = (unsigned char*)m_pHeader; // Address back from mmap.

//ftruncate( shmem_fd, size);

// We map to the same space has ESLServices
if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_NOSYNCFILE|MAP_SHARED, shmem_fd, 0))

MAP_FAILED)
//if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}

close(shmem_fd);

}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Open( %s ) Name to long\n”,
name );
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Open returns unexpected
error %d\n”, osErr );


FW_POSTCONDITION( addr != 0 );

(unsigned char*)m_pHeader = addr; // Address back from mmap.

// debug
Dump();
// debug

if ( m_pHeader->MagicNum != MagicNum )
return fw_errmsg( err_InvalidModule, “CDataModule::Open( %s ) invalid
module\n”, name );

m_pDataStart = (fw_int8*)( m_pHeader+1 );
m_Lock.Initialize( m_pHeader->Lock );

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}

\

“Stephane Grenier” <sgrenier@excalibur.com> wrote in message
news:9te1hr$bj$1@inn.qnx.com

Hi All!,

I been trying to share memory between two process but without luck. The
first process will create the share memory without problem, but it’s the
second process that giving me problems. The second process will open the
share memory object without problems with sh_open(), but when I use mmap()
it always returns NOT SUPPORTED(48). Also the share memory name and size
is: “/dev/shmem/SCDM” and 8192bytes, thus I am using shmem an not a file
system. Below is the code I am using:

The name must contain a single forward slash at the start to be POSIX
compliant. So use “/SCDM”. Look further down…

////////////////////////////////////////////////////////////////////////////
/////
Process #1: (Creates the Share memory object)

////////////////////////////////////////////////////////////////////////////
////
fw_error CDataModule::Create( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );
FW_PRECONDITION( size > 0 );

fw_int16 osErr, shmem_fd;

File descriptors have type int which is 32 bits on most platforms. Are you
sure you meant fw_int16? Probably won’t make a difference since fds usually
have low numbers. Connection ids however can have big numbers, so be
careful.

unsigned char *addr; // Use for the share memory addresse

osErr = EOK; // No error set

// What do we create here share memory
if ( (shmem_fd = shm_open( name, O_EXCL|O_CREAT|O_RDWR, 0777 )) == -1)
{
osErr = errno;
}
else // We need to size and map the share memory
{
// Size the File
ftruncate( shmem_fd, size + sizeof(_Header));

// the only process that can get here is ESLServices
if ((addr = (unsigned char*)mmap(0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_SHARED, shmem_fd, 0)) == MAP_FAILED)
{
osErr = errno;
}
// closing the file decriptor since we do not need it anymore
close(shmem_fd);
}

if ( osErr == ENAMETOOLONG )
return fw_errmsg( err_BadName, “CDataModule::Create( %s ) Name to
long\n”,
name );
else if ( osErr == EEXIST )
return err_KnownModule;
else if ( osErr == ENOSPC )
return err_KnownModule; // No RAM results even though the DM exists.
else if ( osErr != fw_success )
return fw_errmsg( fw_err_unknown, “CDataModule::Create( %s ) returned
unexcepted error %d\n”, name, osErr );

FW_POSTCONDITION( addr != 0 ); // check to make sure we ahve a address

(unsigned char*)m_pHeader = addr; // Address back from mmap.

The above code is non-standard and doesn’t even compile on any C++ compiler
I know of except for g++. The cast produces an rvalue, but then you assign
to it which requires a modifiable lvalue. The fact that the code appears to
work as you expect on g++ must be an extension - ahh, 6.8 on
gcc.gnu.org/onlinedocs/gcc_6.html. Try the more explicit and portable:

m_pHeader = reinterpret_cast<_Header*>(addr);

or if you don’t use the new style C++ casts (you should):

m_pHeader = (_Header*)addr;

m_pHeader->MagicNum = MagicNum;
m_pHeader->MaxSize = size;
m_pHeader->AllocatedSize = 0;
m_pHeader->pRoot = 0;
m_pDataStart = (fw_int8*)( m_pHeader+1 ); // data starts right after the
header
m_Lock.Initialize( m_pHeader->Lock, fw_true );

Dump();

FW_POSTCONDITION( m_pDataStart != 0 );

return fw_success;
}

////////////////////////////////////////////////////////////////////////////
/////////////////////////////
Process #2:

////////////////////////////////////////////////////////////////////////////
////////////////////////////
fw_error CDataModule::Open( const char* name, fw_int32 size )
{
FW_PRECONDITION( name != 0 );

fw_int16 osErr = 0;
fw_int16 shmem_fd;

32 bit again.

unsigned char* addr; // Use for the share memory addresse
file://unsigned char* tmpaddr; // Use for the share memory addresse


file://tmpaddr = 0x40100000;

file://Dump();

// What do we create here share memory
if ( shmem_fd = shm_open( name, O_EXCL|O_RDWR, 0777 ) == -1)

Why the O_EXCL flag? I think it only makes sense with O_CREAT.

{
osErr = errno;
}
else // We need to size and map the share memory
{
// Lets get the address space of the share Memory
file://addr = (unsigned char*)m_pHeader; // Address back from mmap.

file://ftruncate( shmem_fd, size);

// We map to the same space has ESLServices
if ((addr =(unsigned char*)mmap( 0, size + sizeof(_Header),
PROT_WRITE|PROT_EXEC|PROT_READ, MAP_NOSYNCFILE|MAP_SHARED, shmem_fd, 0))

MAP_FAILED)

The qnx docs don’t mention MAP_NOSYNCFILE. That’s probably your problem -
remove it.

Tom