Changeset 82651 in webkit


Ignore:
Timestamp:
Mar 31, 2011 6:05:40 PM (13 years ago)
Author:
Adam Roben
Message:

Add SharedMemory::adopt, which can take ownership of an existing file mapping object

Fixes <http://webkit.org/b/57599> Need a way to wrap an existing file mapping object in a
SharedMemory

Reviewed by Anders Carlsson.

  • Platform/SharedMemory.h: Added adopt.
  • Platform/win/SharedMemoryWin.cpp:

(WebKit::SharedMemory::create): Moved code to adopt the HANDLE from here...
(WebKit::SharedMemory::adopt): ...to here.

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r82649 r82651  
     12011-03-31  Adam Roben  <aroben@apple.com>
     2
     3        Add SharedMemory::adopt, which can take ownership of an existing file mapping object
     4
     5        Fixes <http://webkit.org/b/57599> Need a way to wrap an existing file mapping object in a
     6        SharedMemory
     7
     8        Reviewed by Anders Carlsson.
     9
     10        * Platform/SharedMemory.h: Added adopt.
     11
     12        * Platform/win/SharedMemoryWin.cpp:
     13        (WebKit::SharedMemory::create): Moved code to adopt the HANDLE from here...
     14        (WebKit::SharedMemory::adopt): ...to here.
     15
    1162011-03-31  Chang Shu  <cshu@webkit.org>
    217
  • trunk/Source/WebKit2/Platform/SharedMemory.h

    r78513 r82651  
    8383    static PassRefPtr<SharedMemory> create(const Handle&, Protection);
    8484   
     85#if PLATFORM(WIN)
     86    static PassRefPtr<SharedMemory> adopt(HANDLE, size_t, Protection);
     87#endif
     88
    8589    ~SharedMemory();
    8690
  • trunk/Source/WebKit2/Platform/win/SharedMemoryWin.cpp

    r82615 r82651  
    146146PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection)
    147147{
    148     if (handle.isNull())
     148    RefPtr<SharedMemory> memory = adopt(handle.m_handle, handle.m_size, protection);
     149    if (!memory)
     150        return 0;
     151
     152    // The SharedMemory object now owns the HANDLE.
     153    handle.m_handle = 0;
     154
     155    return memory.release();
     156}
     157
     158PassRefPtr<SharedMemory> SharedMemory::adopt(HANDLE handle, size_t size, Protection protection)
     159{
     160    if (!handle)
    149161        return 0;
    150162
    151163    DWORD desiredAccess = accessRights(protection);
    152164
    153     void* baseAddress = ::MapViewOfFile(handle.m_handle, desiredAccess, 0, 0, handle.m_size);
     165    void* baseAddress = ::MapViewOfFile(handle, desiredAccess, 0, 0, size);
    154166    ASSERT_WITH_MESSAGE(baseAddress, "::MapViewOfFile failed with error %lu", ::GetLastError());
    155167    if (!baseAddress)
     
    157169
    158170    RefPtr<SharedMemory> memory = adoptRef(new SharedMemory);
    159     memory->m_size = handle.m_size;
     171    memory->m_size = size;
    160172    memory->m_data = baseAddress;
    161 
    162     // Adopt the HANDLE.
    163     memory->m_handle = handle.m_handle;
    164     handle.m_handle = 0;
     173    memory->m_handle = handle;
    165174
    166175    return memory.release();
Note: See TracChangeset for help on using the changeset viewer.