Changeset 183176 in webkit
- Timestamp:
- Apr 23, 2015 12:28:48 AM (9 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r183172 r183176 1 2015-04-23 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [UNIX] Simplify the file descriptor handling in SharedMemory 4 https://bugs.webkit.org/show_bug.cgi?id=144046 5 6 Reviewed by Darin Adler. 7 8 Simplify the file descriptor handling and clarify its ownership by 9 using IPC::Attachment in SharedMemory::Handle instead of fd and 10 size members. SharedMemory::Handle::adoptFromAttachment() has been 11 renamed as SharedMemory::Handle::adoptAttachment() and receives an 12 IPC::Attachment. And SharedMemory::Handle::releaseToAttachment() 13 has been renamed as SharedMemory::Handle::releaseAttachment(). 14 15 * Platform/IPC/Attachment.h: Add move constructor and move assigned operator. 16 * Platform/IPC/Connection.h: 17 (IPC::Connection::identifierIsNull): A file descriptor is null 18 when it's -1 no 0. 19 * Platform/IPC/unix/AttachmentUnix.cpp: 20 (IPC::Attachment::Attachment): 21 (IPC::Attachment::operator=): 22 (IPC::Attachment::dispose): Reset the file descriptor after 23 closing it. 24 * Platform/IPC/unix/ConnectionUnix.cpp: 25 (IPC::Connection::processMessage): Use 26 SharedMemory::Handle::adoptAttachment() that receives an 27 IPC::Attachment now. 28 (IPC::Connection::sendOutgoingMessage): Use 29 SharedMemory::Handle::releaseAttachment(). 30 * Platform/SharedMemory.h: 31 * Platform/unix/SharedMemoryUnix.cpp: 32 (WebKit::SharedMemory::Handle::Handle): Remove initializers for 33 file descriptor and size members. 34 (WebKit::SharedMemory::Handle::clear): Dispose the attachment. 35 (WebKit::SharedMemory::Handle::isNull): Handle is null if the 36 attachment file descriptor is -1. 37 (WebKit::SharedMemory::Handle::encode): Use releaseAttachment(). 38 (WebKit::SharedMemory::Handle::decode): Use adoptAttachment(). 39 (WebKit::SharedMemory::Handle::releaseAttachment): Implement it 40 using move. 41 (WebKit::SharedMemory::Handle::adoptAttachment): Ditto. 42 (WebKit::SharedMemory::map): Use 43 IPC::Attachment::releaseFileDescriptor() instead of manually 44 changing the member. 45 (WebKit::SharedMemory::createHandle): Initialize the handle 46 attachment with the duplicated file descriptor and size. 47 1 48 2015-04-22 Darin Adler <darin@apple.com> 2 49 -
trunk/Source/WebKit2/Platform/IPC/Attachment.h
r161148 r183176 54 54 Attachment(mach_port_name_t port, mach_msg_type_name_t disposition); 55 55 #elif USE(UNIX_DOMAIN_SOCKETS) 56 Attachment(Attachment&&); 57 Attachment& operator=(Attachment&&); 58 Attachment(const Attachment&) = default; 59 Attachment& operator=(Attachment&) = default; 56 60 Attachment(int fileDescriptor, size_t); 57 61 Attachment(int fileDescriptor); … … 86 90 mach_msg_type_name_t m_disposition; 87 91 #elif USE(UNIX_DOMAIN_SOCKETS) 88 int m_fileDescriptor ;92 int m_fileDescriptor { -1 }; 89 93 size_t m_size; 90 94 #endif -
trunk/Source/WebKit2/Platform/IPC/Connection.h
r182086 r183176 130 130 #elif USE(UNIX_DOMAIN_SOCKETS) 131 131 typedef int Identifier; 132 static bool identifierIsNull(Identifier identifier) { return !identifier; }132 static bool identifierIsNull(Identifier identifier) { return identifier == -1; } 133 133 134 134 struct SocketPair { -
trunk/Source/WebKit2/Platform/IPC/unix/AttachmentUnix.cpp
r161156 r183176 46 46 } 47 47 48 Attachment::Attachment(Attachment&& attachment) 49 : m_type(attachment.m_type) 50 , m_fileDescriptor(attachment.m_fileDescriptor) 51 , m_size(attachment.m_size) 52 { 53 attachment.m_type = Uninitialized; 54 attachment.m_fileDescriptor = -1; 55 attachment.m_size = 0; 56 } 57 58 Attachment& Attachment::operator=(Attachment&& attachment) 59 { 60 m_type = attachment.m_type; 61 attachment.m_type = Uninitialized; 62 m_fileDescriptor = attachment.m_fileDescriptor; 63 attachment.m_fileDescriptor = -1; 64 m_size = attachment.m_size; 65 attachment.m_size = 0; 66 67 return *this; 68 } 69 48 70 void Attachment::dispose() 49 71 { 50 if (m_fileDescriptor != -1) 51 closeWithRetry(m_fileDescriptor); 72 if (m_fileDescriptor == -1) 73 return; 74 75 closeWithRetry(m_fileDescriptor); 76 m_fileDescriptor = -1; 52 77 } 53 78 -
trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp
r182776 r183176 248 248 249 249 WebKit::SharedMemory::Handle handle; 250 handle.adopt FromAttachment(m_fileDescriptors[attachmentFileDescriptorCount - 1], attachmentInfo[attachmentCount].getSize());250 handle.adoptAttachment(IPC::Attachment(m_fileDescriptors[attachmentFileDescriptorCount - 1], attachmentInfo[attachmentCount].getSize())); 251 251 252 252 oolMessageBody = WebKit::SharedMemory::map(handle, WebKit::SharedMemory::Protection::ReadOnly); … … 446 446 memcpy(oolMessageBody->data(), encoder->buffer(), encoder->bufferSize()); 447 447 448 attachments.append(handle.release ToAttachment());448 attachments.append(handle.releaseAttachment()); 449 449 } 450 450 -
trunk/Source/WebKit2/Platform/SharedMemory.h
r182845 r183176 70 70 71 71 #if USE(UNIX_DOMAIN_SOCKETS) 72 IPC::Attachment release ToAttachment() const;73 void adopt FromAttachment(int fileDescriptor, size_t);72 IPC::Attachment releaseAttachment() const; 73 void adoptAttachment(IPC::Attachment&&); 74 74 #endif 75 75 private: … … 77 77 #if OS(DARWIN) 78 78 mutable mach_port_t m_port; 79 size_t m_size; 79 80 #elif USE(UNIX_DOMAIN_SOCKETS) 80 mutable int m_fileDescriptor;81 mutable IPC::Attachment m_attachment; 81 82 #endif 82 size_t m_size;83 83 }; 84 84 -
trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp
r182776 r183176 48 48 49 49 SharedMemory::Handle::Handle() 50 : m_fileDescriptor(-1)51 , m_size(0)52 50 { 53 51 } … … 60 58 void SharedMemory::Handle::clear() 61 59 { 62 if (!isNull()) 63 closeWithRetry(m_fileDescriptor); 60 m_attachment.dispose(); 64 61 } 65 62 66 63 bool SharedMemory::Handle::isNull() const 67 64 { 68 return m_ fileDescriptor== -1;65 return m_attachment.fileDescriptor() == -1; 69 66 } 70 67 71 68 void SharedMemory::Handle::encode(IPC::ArgumentEncoder& encoder) const 72 69 { 73 encoder << release ToAttachment();70 encoder << releaseAttachment(); 74 71 } 75 72 … … 83 80 return false; 84 81 85 handle.adopt FromAttachment(attachment.releaseFileDescriptor(), attachment.size());82 handle.adoptAttachment(WTF::move(attachment)); 86 83 return true; 87 84 } 88 85 89 IPC::Attachment SharedMemory::Handle::releaseToAttachment() const 90 { 91 int temp = m_fileDescriptor; 92 m_fileDescriptor = -1; 93 return IPC::Attachment(temp, m_size); 94 } 95 96 void SharedMemory::Handle::adoptFromAttachment(int fileDescriptor, size_t size) 97 { 98 ASSERT(!m_size); 86 IPC::Attachment SharedMemory::Handle::releaseAttachment() const 87 { 88 ASSERT(!isNull()); 89 return WTF::move(m_attachment); 90 } 91 92 void SharedMemory::Handle::adoptAttachment(IPC::Attachment&& attachment) 93 { 99 94 ASSERT(isNull()); 100 95 101 m_fileDescriptor = fileDescriptor; 102 m_size = size; 96 m_attachment = WTF::move(attachment); 103 97 } 104 98 … … 162 156 ASSERT(!handle.isNull()); 163 157 164 void* data = mmap(0, handle.m_ size, accessModeMMap(protection), MAP_SHARED, handle.m_fileDescriptor, 0);158 void* data = mmap(0, handle.m_attachment.size(), accessModeMMap(protection), MAP_SHARED, handle.m_attachment.fileDescriptor(), 0); 165 159 if (data == MAP_FAILED) 166 return 0;160 return nullptr; 167 161 168 162 RefPtr<SharedMemory> instance = adoptRef(new SharedMemory()); 169 163 instance->m_data = data; 170 instance->m_fileDescriptor = handle.m_fileDescriptor; 171 instance->m_size = handle.m_size; 172 handle.m_fileDescriptor = -1; 164 instance->m_fileDescriptor = handle.m_attachment.releaseFileDescriptor(); 165 instance->m_size = handle.m_attachment.size(); 173 166 return instance; 174 167 } … … 203 196 } 204 197 } 205 handle.m_fileDescriptor = duplicatedHandle; 206 handle.m_size = m_size; 198 handle.m_attachment = IPC::Attachment(duplicatedHandle, m_size); 207 199 return true; 208 200 }
Note: See TracChangeset
for help on using the changeset viewer.