Bug 43535 - Add shared memory abstraction
Summary: Add shared memory abstraction
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Anders Carlsson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2010-08-04 20:15 PDT by Anders Carlsson
Modified: 2010-08-05 11:03 PDT (History)
1 user (show)

See Also:


Attachments
Patch (17.34 KB, patch)
2010-08-04 20:41 PDT, Anders Carlsson
aroben: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anders Carlsson 2010-08-04 20:15:48 PDT
Add shared memory abstraction
Comment 1 Anders Carlsson 2010-08-04 20:30:05 PDT
<rdar://problem/8275295>
Comment 2 Anders Carlsson 2010-08-04 20:41:50 PDT
Created attachment 63538 [details]
Patch
Comment 3 WebKit Review Bot 2010-08-04 20:43:31 PDT
Attachment 63538 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style']" exit_code: 1
WebKit2/Platform/SharedMemory.h:34:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
WebKit2/Platform/win/SharedMemoryWin.cpp:26:  Found header this file implements before WebCore config.h. Should be: config.h, primary header, blank line, and then alphabetically sorted.  [build/include_order] [4]
WebKit2/Platform/mac/SharedMemoryMac.cpp:26:  Found header this file implements before WebCore config.h. Should be: config.h, primary header, blank line, and then alphabetically sorted.  [build/include_order] [4]
Total errors found: 3 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Adam Roben (:aroben) 2010-08-05 06:26:54 PDT
Comment on attachment 63538 [details]
Patch

> +void SharedMemory::Handle::encode(CoreIPC::ArgumentEncoder& encoder) const
> +{
> +    ASSERT(m_port);
> +    ASSERT(m_size);
> +    
> +    encoder.encodeUInt64(m_size);
> +    encoder.encode(CoreIPC::MachPort(m_port, MACH_MSG_TYPE_COPY_SEND));
> +    const_cast<Handle*>(this)->m_port = MACH_PORT_NULL;
> +}

Making m_port mutable seems preferable.

> +bool SharedMemory::Handle::decode(CoreIPC::ArgumentDecoder& decoder, Handle& handle)
> +{
> +    ASSERT(!handle.m_port);
> +    ASSERT(!handle.m_size);
> +
> +
> +    uint64_t size;

Extra newline here.

> +PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
> +{
> +    mach_vm_address_t address;
> +    kern_return_t kr = mach_vm_allocate(mach_task_self(), &address, round_page(size), VM_FLAGS_ANYWHERE);
> +    if (kr != KERN_SUCCESS)
> +        return 0;
> +
> +    RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
> +    sharedMemory->m_size = size;
> +    sharedMemory->m_data = (void*)address;

Is the cast really needed? A C++ cast would be nicer if so.

> +PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection)
> +{
> +    if (!handle.m_port)
> +        return 0;
> +    
> +    // Map the memory.
> +    vm_prot_t vmProtection = machProtection(protection);
> +    mach_vm_address_t mappedAddress;
> +    kern_return_t kr = mach_vm_map(mach_task_self(), &mappedAddress, handle.m_size, 0, VM_FLAGS_ANYWHERE, handle.m_port, 0, false, vmProtection, vmProtection, VM_INHERIT_NONE);
> +    if (kr != KERN_SUCCESS)
> +        return 0;
> +
> +    RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
> +    sharedMemory->m_size = handle.m_size;
> +    sharedMemory->m_data = (void*)mappedAddress;

Ditto.

> +SharedMemory::~SharedMemory()
> +{
> +    if (!m_data)
> +        return;
> +    
> +    kern_return_t kr = mach_vm_deallocate(mach_task_self(), (vm_address_t)m_data, round_page(m_size));

C++ cast would be better.

> +bool SharedMemory::createHandle(Handle& handle, Protection protection)
> +{
> +    ASSERT(!handle.m_port);
> +    ASSERT(!handle.m_size);
> +
> +    mach_vm_address_t address = (vm_address_t)m_data;

Here, too!

> +unsigned SharedMemory::systemPageSize()
> +{
> +    static unsigned pageSize = 0;
> +
> +    if (!pageSize) {
> +        SYSTEM_INFO systemInfo;
> +        ::GetSystemInfo(&systemInfo);
> +        pageSize = systemInfo.dwPageSize;
> +    }
> +
> +    return pageSize;
> +}

Thanks!

> +++ b/WebKit2/win/WebKit2.vcproj
> @@ -1364,6 +1364,10 @@
>  				RelativePath="..\Platform\WorkItem.h"
>  				>
>  			</File>
> +            <File
> +            	RelativePath="..\Platform\SharedMemory.h"
> +            >
> +            </File>

VS wants you to use tabs. Copying-and-pasting an existing <File> element is usually the best way to go.

r=me
Comment 5 Darin Adler 2010-08-05 10:56:45 PDT
Comment on attachment 63538 [details]
Patch

> +#include <wtf/Noncopyable.h>
> +#include <wtf/PassRefPtr.h>
> +#include <wtf/RefCounted.h>

No need to include Noncopyable if you include RefCounted.
Comment 6 Anders Carlsson 2010-08-05 11:03:22 PDT
Committed r64765: <http://trac.webkit.org/changeset/64765>