The offset parameter to mmap should be zero in this case.

Colin 

Sent from my BlackBerry 10 smartphone on the Rogers network.
From: Fuquan Liu
Sent: Friday, August 16, 2013 4:25 AM
To: ostech-core_os
Reply To: ostech-core_os@community.qnx.com
Subject: Create named shared memory at destinated physical address

When I tried to create named shared memory at destinated physical address using shm_open(), shm_ctl_special() and mmap() as below code, it doesn't work. The returned address from mmap always point to 0x80100000 and this address can't be written to.

Please help to see why it doesn’t work.

#define SharedName "SHARED_MEMORY_C5"

#define ARM_PTE_V6_SP_TEX_MASK_CACHED    ARM_PTE_V6_SP_TEX(5)
#define ARM_PTE_V6_SP_TEX_MASK_NONCACHED ARM_PTE_V6_SP_TEX(1)

#define PTE_CACHED_SPECIAL_BITS \
        (ARM_PTE_V6_SP_TEX_MASK_CACHED | ARM_PTE_CB | ARM_PTE_V6_SP_XN)

#define PTE_NONCACHED_SPECIAL_BITS \
    (ARM_PTE_V6_S | ARM_PTE_V6_SP_TEX_MASK_NONCACHED | ARM_PTE_V6_SP_XN)

      size_t size = 0x800000;
      unsigned int PhyAddr = 0xc5000000;


int main(int argc, char *argv[]) {

        int                     fd;
    char *pDstAddr;


    fd = shm_open(SharedName , O_CREAT | O_TRUNC | O_EXCL | O_RDWR,
        0666);

    shm_unlink(SharedName );

    shm_ctl_special(fd, SHMCTL_PHYS,
       PhyAddr, size, PTE_CACHED_SPECIAL_BITS);

    pDstAddr = (char*)mmap(NULL, size,
        (PROT_READ | PROT_WRITE), MAP_SHARED,
        fd, (off_t)0 + PhyAddr);

    printf( "That means: %s\n", strerror( errno ) );

      *pDstAddr = 0x55;

      return EXIT_SUCCESS;
}




_______________________________________________

OSTech
http://community.qnx.com/sf/go/post104247
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com