file mapping between process



  • My process "A" use QFile.map(...) to map a portion of NVRAM device (it is at /dev/sram0) to a struct of data inside process A. So I don't need to care about saving variables to NVRAM, it happens transparent for me. It works ok.

    MyNvStruct * nvInfo:
    QFile nvfile;
    nvfile.setFileName("/dev/sram0");
    nvfile.open(QIODevice::ReadWrite);
    nvInfo = reinterpret_cast<MyNvStruct *>(nvfile.map(0,sizeof(MyNvStruct)));
    

    Now I need to use another portion of such a NVRAM device inside another process, process B. I dont need to share anything between process A and B , just to use the rest of NVRAM resourse inside another process.

    Is it possible to reopen /dev/sram0 with ReadWrite property inside another process?
    I would map NVRAM from sizeof(MyNvStruct) on.
    Both process run simultaneously and should access NVRAM resourse separately.

    Thanks in advance



  • /dev/sram0 will not be deleted by map so you can pass it to another process, an alternative would be to use a QLocalSocket to make the 2 processes talk to each other.

    P.S.
    This:
    nvInfo = reinterpret_cast<MyNvStruct *>(nvfile.map(0,sizeof(MyNvStruct)));
    Has the potential to create endless headaches if you ever assign memory on the heap inside MyNvStruct or the binary version you use in process A is different from the one in process B

    if you are interested in a pre-built memory map take a look here: http://pastebin.com/SBZBeKWN

    It uses QDataStream::operator>> and QDataStream::operator<< of the class to read from and write to the mapped device, you need to implement:

    QDataStream&  operator<<(QDataStream & stream, const MyNvStruct& flows);
    QDataStream& operator>>(QDataStream & stream, MyNvStruct& flows);
    

    and then you can use the device more or less how you use QMap



  • VRonin, thank you for your quick response.
    I dont need to share memory between these 2 process, neither talk to each other. I just need to use /sram0 device (from advantech platforms) from 2 different process. taking care of course of not mapping the same portion of NVRAM in both process.

    Regarding headaches, I understand your advice. MyNvStruct is a very basic struct with just a couple of int and unsigned long, It does not grow dynamically. I am aware of this.

    So, It is posible open sram0 file from different process and thus share this NVRAM resourse, I have just tested. My question is now if this is a solid and well seen way to use NVRAM from different processess.
    Thank you very much



  • As long as you access it just for reading it should be safe


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.