Alright i’m at the bottom of the barrel about this problem.
I am trying to port some device driver code from 6.1 to 6.2.1 and I can’t successfully get shared memory mapping to work between processes . When I run checks in the resource command using a new pointer mapped with the shared memory file descriptor I get all of the data from the memory mapped region just fine. However when I make the same call in another process using the same file descriptor that I just used in the original process, all of the bytes read from the shared memory region are null. Here’s the relevant code
Resource manager:
[code] s_glb.apc8620_pbase=PCI_MEM_ADDR(buff32[0]);
printf(“Assigned s_glb.apc8620_pbase to %x\n”, buff32[0]);
s_glb.apc8620_port_length=sysconf(_SC_PAGE_SIZE);
// memory map the IO space to our own pointer
s_glb.apc8620_vbase=mmap_device_memory(NULL,
s_glb.apc8620_port_length,
PROT_READ|PROT_WRITE|
PROT_NOCACHE,
MAP_SHARED,
s_glb.apc8620_pbase);
if(s_glb.apc8620_vbase==MAP_FAILED)
{
perror(“apc8620 mmap_device failed:”);
exit(EXIT_FAILURE);
}
// Here the memory sharing funkiness begins
/* open the shared memory object, create it if it doesn’t exist */
strcpy(devName,"/dev/apc8620RM");
// copy name to global status struct passed to clients in devctl(GET_STATUS)
strcpy(s_glb.memName,devName);
printf(“Memory Name: %s\n”, devName);
// create shared memory object
fd = shm_open(devName,O_RDWR|O_CREAT,0);
if ( fd == -1 ) {
perror(“shm_open failed:”);
exit(EXIT_FAILURE);
}
/* overlay the shared memory object on the physical memory /
if ( shm_ctl(fd, SHMCTL_ANON|SHMCTL_PHYS|SHMCTL_GLOBAL,
s_glb.apc8620_pbase,
s_glb.apc8620_port_length) == -1 )
{
perror(“shm_ctl failed:”);
close(fd);
munmap((char)s_glb.apc8620_vbase,s_glb.apc8620_port_length);
shm_unlink(devName);
exit(EXIT_FAILURE);
}
ptr = mmap ( 0, len, PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED, fd, 0);
if ( ptr == MAP_FAILED)
{
fprintf( stderr, “mmap failed!”);
}
[/code]
Second process:
[code] printf(“Opening shared memory and getting status\n”);
// open apc8620 to get its status
if ((smem_info.device_fd = open("/dev/apc8620", O_RDONLY)) == -1) {
printf(“Error opening device\n”);
return(NULL);
}
if(devctl(smem_info.device_fd,APC8620_GET_STATUS,&data,
sizeof(data),NULL)<0)
{
printf(“apc8620_open: APC8620_GET_STATUS failed”);
return(NULL);
}
smem_info.port_length=data.stx.apc8620_port_length;
strcpy(smem_info.memName,data.stx.memName);
smem_info.mem_fd = shm_open(data.stx.memName, O_RDWR,0);
if( smem_info.mem_fd == -1 ) {
perror("shm_open failed:");
exit(EXIT_FAILURE);
}
// the other half of the memory funkiness
// map the shared memory from the server to the client
/*
smem_info.base= mmap(NULL,smem_info.port_length,
PROT_READ|PROT_WRITE|PROT_NOCACHE,
MAP_SHARED,smem_info.mem_fd,0);
*/
ptr = mmap ( NULL, data.stx.apc8620_port_length,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED, smem_info.mem_fd, 0);
if ( ptr == MAP_FAILED)
{
fprintf( stderr, "map failed!");
}
[/code]
loading up both processes into GDB, dumping
x /1024xb ptr
from the resource manager (first code section) returns 1024 bytes of accurate information.
However
x /1024xb ptr
from the second process (with the breakpoints set at the end in both of those code sections) returns 1024 bytes of 0x00.
There has to be something i’m missing…
On a possibly related note: In the resource manager, unless I use both SHMCTL_ANON and SHMCTL_PHYS together shm_ctl returns Function not Implemented. (The original code for 6.1 did not use SHMCTL_ANON, also the sample code from the shm_ctl() documentation at www.qnx.com returns Function not Implemented (it does not use SHMCTL_ANON)).
Can anyone spot anything wrong in this or have any ideas on things to try? I’m basically just out of ideas for what it could possibly be.
I’ve verified every data member and function argument that I think is relevant to these calls and they all check out. Its almost as if QNX has a devil set aside for me =)
One thing i’ve heard mentioned around the lab is that some lower level functionality of QNX was removed from the Non commercial release (which i’m using) between 6.1 and 6.2.1… I hope that’s not it because i’m hoping to get the onboard network working with QNX 6.3…
The credibility of this concern is heightened by the fact that the sample code given in the qnx documentation (www.qnx.com) for shm_ctl, which covers simple shared memory also causes shm_ctl to return Function not Implemented. =/
Might I just not have some package that I need?
Appreciative of any help,
Iniari