Unable to write to specific region of RAM using mmap

43 views Asked by At

The context is that this is happening in a application in QNX. The said RAM is also accessible from another CPU on the bus (which is running baremetal so can directly access the contents of the mem by just de-referencing).

base = mmap(NULL, size_of_buf, PROT_READ | PROT_WRITE | PROT_NOCACHE, MAP_SHARED | MAP_ANON | MAP_PHYS, NOFD, offset_to_buf);

At this point, I write say 4 bytes to this address. Should I be able to now see this change from the other CPU? What about after an msync() call? My understanding was that the MAP_SHARED was to make sure that the changes are propagated down to the memory.

NOTE: I've tried it with the following because qnx seems to want me to have special abilities to access physical RAM:

procmgr_ability(0,
    PROCMGR_AOP_ALLOW | PROCMGR_ADN_NONROOT | PROCMGR_AID_KEYDATA,
    PROCMGR_AOP_ALLOW | PROCMGR_ADN_NONROOT | PROCMGR_AID_IO,
    PROCMGR_AOP_ALLOW | PROCMGR_ADN_NONROOT | PROCMGR_AID_MEM_PHYS,
    PROCMGR_AOP_ALLOW | PROCMGR_ADN_NONROOT | PROCMGR_AID_PRIORITY,
    PROCMGR_AOP_DENY  | PROCMGR_ADN_NONROOT | PROCMGR_AOP_LOCK      | PROCMGR_AID_EOL);

I do not see the change happening. After spending the whole day googling am quite confused and in desperate need of help.

EDIT: So, it's embarrassing, but the reason was simple enough. The memory base for the CPU running QNX was independent of the memory base for the CPU running bare metal. This was why the QNX side was giving me errors since I was trying to access a region memory it didn't have access to.

0

There are 0 answers