Hi Everyone;
I am attempting to create a device driver for a PCI shared memory device.
The problem I have right now is that I am not sure what to do with memory
that I have mmapped to close both the file descriptor for the shared memory
object and unmap the memory. I mmap memory to the device like this:
fd=shm_open(“Physical”, O_RDWR, 0777);
…do some stuff here
mem_ptr1=mmap(0,0x400000,prots,flags,fd,scr_reg.Base_Address_Regs[1]);
mem_ptr=mmap(0,0x400000,prots,flags,fd,scr_reg.Base_Address_Regs[2]);
shm_unlink(“Physical”);
munmap((void*)mem_ptr1,0x400000);
munmap((void*)mem_ptr,0x400000);
I looked at some examples in the QNX Library Reference II manual and I see
that munmap() is never called in the example code for the shm_open()
function. Also I see from the following page on the QNX online knowledge
base:
http://qdn.qnx.com/support/bok/solution.qnx?9417 that I should unmap the
memory mapped by mmap via munmap and close the shared memory file
descriptor. What about shm_unlink though? So my question is what I should
do? I have tried this with the following results:
1st attempt
shm_open
mmaps
close(fd);
shm_unlink (“Physical”);
munmaps
This resulted in shm_unlink reporting invalid argument from errno.
2nd attempt
shm_open
mmaps
shm_unlink(“Physical”);
close(fd);
munmaps
This resulted in shm_unlink reporting invalid argument from errno.
3rd attempt
shm_open
mmaps
close(fd)
munmaps
munmaps works fine? Errno is not set when doing this (scratches head a
little)
4th attempt
shm_open
mmaps
munmaps
close(fd);
munmap works ok like this too, maybe it doesn’t matter?
What should I do, could someone please help me!!!
Chris Fought