Changeset 69532 in webkit
- Timestamp:
- Oct 11, 2010 3:15:21 PM (14 years ago)
- Location:
- trunk/WebKit2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit2/ChangeLog
r69531 r69532 1 2010-10-11 Adam Roben <aroben@apple.com> 2 3 Implement SharedMemory on Windows 4 5 This makes visited links be colored correctly. 6 7 Fixes <http://webkit.org/b/47499> <rdar://problem/8422725>. 8 9 Reviewed by Anders Carlsson. 10 11 * Platform/SharedMemory.h: Add Windows-specific members to 12 SharedMemory and SharedMemory::Handle. 13 14 * Platform/win/SharedMemoryWin.cpp: 15 (WebKit::SharedMemory::Handle::Handle): Initialize our members. 16 (WebKit::SharedMemory::Handle::~Handle): Close our HANDLE if we have 17 one. 18 (WebKit::SharedMemory::Handle::encode): Encode our size, HANDLE, and 19 PID. Null out our HANDLE member, as it is now the receiving process's 20 responsibility to close the HANDLE. 21 (WebKit::SharedMemory::Handle::decode): Copy the handle from the 22 sending process into the receiving process and close the HANDLE the 23 sending process gave us. 24 (WebKit::SharedMemory::create): Map some memory and store it in a new 25 SharedMemory object. 26 (WebKit::accessRights): Helper function to convert a 27 SharedMemory::Protection to a file-mapping access right. 28 (WebKit::SharedMemory::create): Map the memory represented by the 29 Handle, and adopt the HANDLE from it. 30 (WebKit::SharedMemory::~SharedMemory): Clean up our memory mapping. 31 (WebKit::SharedMemory::createHandle): Give the Handle a copy of our 32 HANDLE with the specified protection. 33 1 34 2010-10-11 Adam Roben <aroben@apple.com> 2 35 -
trunk/WebKit2/Platform/SharedMemory.h
r68353 r69532 59 59 #if PLATFORM(MAC) 60 60 mutable mach_port_t m_port; 61 #elif PLATFORM(WIN) 62 mutable HANDLE m_handle; 61 63 #endif 62 64 size_t m_size; … … 82 84 size_t m_size; 83 85 void* m_data; 86 #if PLATFORM(WIN) 87 HANDLE m_handle; 88 #endif 84 89 }; 85 90 -
trunk/WebKit2/Platform/win/SharedMemoryWin.cpp
r65484 r69532 26 26 #include "SharedMemory.h" 27 27 28 #define DISABLE_NOT_IMPLEMENTED_WARNINGS 1 29 #include "NotImplemented.h" 28 #include "ArgumentDecoder.h" 29 #include "ArgumentEncoder.h" 30 #include <wtf/RefPtr.h> 30 31 31 32 namespace WebKit { 32 33 33 34 SharedMemory::Handle::Handle() 35 : m_handle(0) 36 , m_size(0) 34 37 { 35 notImplemented();36 38 } 37 39 38 40 SharedMemory::Handle::~Handle() 39 41 { 40 notImplemented(); 42 if (!m_handle) 43 return; 44 45 ::CloseHandle(m_handle); 41 46 } 42 47 43 48 void SharedMemory::Handle::encode(CoreIPC::ArgumentEncoder* encoder) const 44 49 { 45 notImplemented(); 50 encoder->encodeUInt64(m_size); 51 52 // Hand off ownership of our HANDLE to the receiving process. It will close it for us. 53 // FIXME: If the receiving process crashes before it receives the memory, the memory will be 54 // leaked. See <http://webkit.org/b/47502>. 55 encoder->encodeUInt64(reinterpret_cast<uint64_t>(m_handle)); 56 m_handle = 0; 57 58 // Send along our PID so that the receiving process can duplicate the HANDLE for its own use. 59 encoder->encodeUInt32(::GetCurrentProcessId()); 46 60 } 47 61 48 62 bool SharedMemory::Handle::decode(CoreIPC::ArgumentDecoder* decoder, Handle& handle) 49 63 { 50 notImplemented(); 51 return false; 64 ASSERT_ARG(handle, !handle.m_handle); 65 ASSERT_ARG(handle, !handle.m_size); 66 67 uint64_t size; 68 if (!decoder->decodeUInt64(size)) 69 return false; 70 71 uint64_t sourceHandle; 72 if (!decoder->decodeUInt64(sourceHandle)) 73 return false; 74 75 uint32_t sourcePID; 76 if (!decoder->decodeUInt32(sourcePID)) 77 return false; 78 79 HANDLE sourceProcess = ::OpenProcess(PROCESS_DUP_HANDLE, FALSE, sourcePID); 80 if (!sourceProcess) 81 return false; 82 83 // Copy the handle into our process and close the handle that the sending process created for us. 84 HANDLE duplicatedHandle; 85 BOOL success = ::DuplicateHandle(sourceProcess, reinterpret_cast<HANDLE>(sourceHandle), ::GetCurrentProcess(), &duplicatedHandle, 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); 86 87 ::CloseHandle(sourceProcess); 88 89 if (!success) 90 return false; 91 92 handle.m_handle = duplicatedHandle; 93 handle.m_size = size; 94 return true; 52 95 } 53 96 54 97 PassRefPtr<SharedMemory> SharedMemory::create(size_t size) 55 98 { 56 notImplemented(); 99 HANDLE handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, 0); 100 if (!handle) 101 return 0; 102 103 void* baseAddress = ::MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, size); 104 if (!baseAddress) { 105 ::CloseHandle(handle); 106 return 0; 107 } 108 109 RefPtr<SharedMemory> memory = adoptRef(new SharedMemory); 110 memory->m_size = size; 111 memory->m_data = baseAddress; 112 memory->m_handle = handle; 113 114 return memory.release(); 115 } 116 117 static DWORD accessRights(SharedMemory::Protection protection) 118 { 119 switch (protection) { 120 case SharedMemory::ReadOnly: 121 return FILE_MAP_READ; 122 case SharedMemory::ReadWrite: 123 // FILE_MAP_WRITE implies read access, too. 124 return FILE_MAP_WRITE; 125 } 126 127 ASSERT_NOT_REACHED(); 57 128 return 0; 58 129 } … … 60 131 PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection) 61 132 { 62 notImplemented(); 63 return 0; 133 DWORD desiredAccess = accessRights(protection); 134 135 void* baseAddress = ::MapViewOfFile(handle.m_handle, desiredAccess, 0, 0, handle.m_size); 136 if (!baseAddress) 137 return 0; 138 139 RefPtr<SharedMemory> memory = adoptRef(new SharedMemory); 140 memory->m_size = handle.m_size; 141 memory->m_data = baseAddress; 142 143 // Adopt the HANDLE. 144 memory->m_handle = handle.m_handle; 145 handle.m_handle = 0; 146 147 return memory.release(); 64 148 } 65 149 66 150 SharedMemory::~SharedMemory() 67 151 { 68 notImplemented(); 152 ASSERT(m_data); 153 ASSERT(m_handle); 154 155 ::UnmapViewOfFile(m_data); 156 ::CloseHandle(m_handle); 69 157 } 70 158 71 159 bool SharedMemory::createHandle(Handle& handle, Protection protection) 72 160 { 73 notImplemented(); 74 return false; 161 ASSERT_ARG(handle, !handle.m_handle); 162 ASSERT_ARG(handle, !handle.m_size); 163 164 HANDLE processHandle = ::GetCurrentProcess(); 165 166 HANDLE duplicatedHandle; 167 if (!::DuplicateHandle(processHandle, m_handle, processHandle, &duplicatedHandle, accessRights(protection), FALSE, 0)) 168 return false; 169 170 handle.m_handle = duplicatedHandle; 171 handle.m_size = m_size; 172 return true; 75 173 } 76 174
Note: See TracChangeset
for help on using the changeset viewer.