MapViewOfFile() used in 64 and 32 bit appz together

Discussion in 'Windows 64bit' started by Angela Yan, Apr 11, 2007.

  1. Angela Yan

    Angela Yan Guest

    Hi,

    Not sure whether this is the right group to post.. If I post at the wrong
    group, please indicate which group i should post the message. :)

    Anyway, I am recompling one of my old Appz from 32 bit to 64 bit to run in
    vista. The appz will use loadlibrary to load a static dll to open a file and
    write. In vista 64 bit OS, I have both 64bit version of appz and 32bit
    version of appz running together and a crash occurs.

    These are the steps I tried:
    1. Launch 64bit Appz, it will map the file into memory using
    MapViewOfFile(hHandle, FILE_MAP_WRITE, 0,0,0). Write something to the
    memory.
    2. Launch 32bit Appz, it can map the same file into memory successfully. But
    when it tries to 'write' the same thing to the memory using memcpy, an
    access violation occurs.

    In windbg memory window, I found that the source address of memcpy in 32 bit
    appz points to somewhere that cannot be seen/accessed by memory window. It
    seems like that part of memory has been paged out or sth.. Although the
    source address is near the end of the file, but still, it is within the
    filesize range and it seems that the last few K bytes of the file have been
    paged out.

    I read msdn on MapViewOfFile and still had no clue at all.. anyone knows
    what is happening here?

    By the way, if I run the 64bit or 32 bit appz alone there won't have any
    problem. The crash occurs only when I launch both Appz together for the
    first time. If I have launched either 32 or 64 bit Appz before, launching
    both Appz together won't cause any access violation also.

    Thanks.
    Angela
     
    Angela Yan, Apr 11, 2007
    #1
    1. Advertising

  2. Angela Yan

    Angela Yan Guest

    Let me simplify my question.

    BYTE Buffer[256] = {0};
    .....

    if (hFile != INVALID_HANDLE_VALUE)
    {
    hFileMapping = CreateFileMapping(hFile,NULL, PAGE_READWRITE, 0,0,
    FileName);
    if (hFileMapping != NULL)
    {
    pMappedView = (BYTE *)MapViewOfFile(hFileMapping, FILE_MAP_WRITE,
    0,0,0);
    if (pMappedView != NULL)
    {
    // Say file size is 0x92000 Bytes
    memcpy(Buffer, pMappedView + 0x91D00, 20) //Copy 20 bytes
    from location pMappedView + 0x91D00 to buffer
    }
    }
    }

    Compile the code in 32 bit and 64 bit respectively. Launch 64 bit appz then
    followed 32 bit Appz (Sequence does not matter), the second Appz will crash
    at the "memcpy()" call because the location pMappedView + 0x91D00 is not
    accessible.

    Thanks in advance.

    Angela


    "Angela Yan" <> wrote in message
    news:O$QuK7%...
    > Hi,
    >
    > Not sure whether this is the right group to post.. If I post at the wrong
    > group, please indicate which group i should post the message. :)
    >
    > Anyway, I am recompling one of my old Appz from 32 bit to 64 bit to run in
    > vista. The appz will use loadlibrary to load a static dll to open a file
    > and write. In vista 64 bit OS, I have both 64bit version of appz and 32bit
    > version of appz running together and a crash occurs.
    >
    > These are the steps I tried:
    > 1. Launch 64bit Appz, it will map the file into memory using
    > MapViewOfFile(hHandle, FILE_MAP_WRITE, 0,0,0). Write something to the
    > memory.
    > 2. Launch 32bit Appz, it can map the same file into memory successfully.
    > But when it tries to 'write' the same thing to the memory using memcpy, an
    > access violation occurs.
    >
    > In windbg memory window, I found that the source address of memcpy in 32
    > bit appz points to somewhere that cannot be seen/accessed by memory
    > window. It seems like that part of memory has been paged out or sth..
    > Although the source address is near the end of the file, but still, it is
    > within the filesize range and it seems that the last few K bytes of the
    > file have been paged out.
    >
    > I read msdn on MapViewOfFile and still had no clue at all.. anyone knows
    > what is happening here?
    >
    > By the way, if I run the 64bit or 32 bit appz alone there won't have any
    > problem. The crash occurs only when I launch both Appz together for the
    > first time. If I have launched either 32 or 64 bit Appz before, launching
    > both Appz together won't cause any access violation also.
    >
    > Thanks.
    > Angela
    >
     
    Angela Yan, Apr 13, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CNewman

    Can WPA and WEP be used together?

    CNewman, Oct 18, 2005, in forum: Wireless Networking
    Replies:
    1
    Views:
    1,500
    McSpreader
    Oct 18, 2005
  2. =?Utf-8?B?UGV0ZXI=?=

    MapViewOfFile() for file larger than 4GByte?

    =?Utf-8?B?UGV0ZXI=?=, Sep 27, 2005, in forum: Windows 64bit
    Replies:
    6
    Views:
    3,820
    Mercury
    Sep 28, 2005
  3. Robin
    Replies:
    6
    Views:
    460
    John John
    Oct 21, 2007
  4. Homer J. Simpson
    Replies:
    5
    Views:
    787
    Jim Barry
    Jan 19, 2009
  5. David B.
    Replies:
    0
    Views:
    518
    David B.
    Jan 20, 2009
Loading...

Share This Page