none
Pointer to data & IOCTLS RRS feed

  • Question

  • Hello,

    I have to following piece of code :

    BOOL bRet = FALSE; int error; DWORD dwBytesReturned; tsTAGFLASHWRITE flashWrite; tsTAGFLASHWRITERESULT flashWriteResult; int position = 0; int lasterror = 0; FILE* fp = fopen("\\Disk\\etx_fpga.hop", "r"); DWORD e = ::GetLastError(); int e2 = errno; byte *data = NULL; if (e2 == 0) { //find file size fseek(fp, 0L, SEEK_END); size = ftell(fp); fseek(fp, 0L, SEEK_SET); data = (byte*)malloc( size); fread(data, 1, size, fp); s_HopHdr *hopfile = (s_HopHdr*)data;

    //check magic number if ((data[6] != 0x35) || (data[7] != 0x12)) { throw new Framework::Exception::EnsorException; } flashWrite.position = 0; flashWrite.magicNumber = MAGIC_NUMBER; flashWrite.data = data; flashWrite.size = size; flashWriteResult.error = 0; int FLASH_WRITE = CTL_CODE(FILE_DEVICE_UNKNOWN, CTL_FLASH_FLASH_WRITE, METHOD_BUFFERED, FILE_ANY_ACCESS); bRet = DeviceIoControl(m_flash, FLASH_WRITE, (void*)&flashWrite,sizeof(tsTAGFLASHWRITE ), (void*)&flashWriteResult, sizeof(tsTAGFLASHWRITERESULT), &dwBytesReturned, NULL); error = GetLastError( ); }

    And the structure used for the input buffer (flashWrite)

    typedef struct tagFlashWrite
    {
        BYTE        position;
        DWORD       magicNumber;    // can only write if one knows the correct magic number
        VOID*       data;
        DWORD       size;
    } tsTAGFLASHWRITE, *ptsTAGFLASHWRITE;

    So basically  i am sending a pointer with the ioctl call, which points to the data in the read file.

    Someone told me that i do not need to use ceopencallerbuffer().  Which is strange since i the IOCTL is an other process which should result in the pointer, pointing to other/random data.  

    Why don't i need to use ceopencallerbuffer(), or better, what system guarantees that my second process (ioctl) can acces the correct data trough the pointer.

    Regards Kevin,

    Friday, November 22, 2013 12:57 PM

Answers

  • The driver will need to call CeOpenCallerBuffer() to marshal the data pointer.  The reason is that data is an embedded pointer.   The pointer to the struct is passed in on the stack and is automatically marshelled for the driver.

    Does the driver actually do something with the result?  If so, it must need to allocate space for data since you aren't and the app will need to marshel the returned embedded pointer.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    • Proposed as answer by balajitrv1 Friday, November 22, 2013 6:54 PM
    • Marked as answer by Kevin Deckx Monday, November 25, 2013 2:47 PM
    Friday, November 22, 2013 3:40 PM
    Moderator

All replies

  • The driver will need to call CeOpenCallerBuffer() to marshal the data pointer.  The reason is that data is an embedded pointer.   The pointer to the struct is passed in on the stack and is automatically marshelled for the driver.

    Does the driver actually do something with the result?  If so, it must need to allocate space for data since you aren't and the app will need to marshel the returned embedded pointer.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    • Proposed as answer by balajitrv1 Friday, November 22, 2013 6:54 PM
    • Marked as answer by Kevin Deckx Monday, November 25, 2013 2:47 PM
    Friday, November 22, 2013 3:40 PM
    Moderator
  • Thanks 
    • Edited by Kevin Deckx Monday, November 25, 2013 2:48 PM
    Monday, November 25, 2013 2:48 PM