Bug 189741 - [Linux] Use memfd_create when available in SharedMemory implementation
Summary: [Linux] Use memfd_create when available in SharedMemory implementation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk, InRadar
Depends on:
Blocks:
 
Reported: 2018-09-19 03:04 PDT by Carlos Garcia Campos
Modified: 2018-11-07 06:25 PST (History)
3 users (show)

See Also:


Attachments
Patch (5.00 KB, patch)
2018-09-19 03:08 PDT, Carlos Garcia Campos
mcatanzaro: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2018-09-19 03:04:55 PDT
Instead of shm_open.
Comment 1 Carlos Garcia Campos 2018-09-19 03:08:22 PDT
Created attachment 350101 [details]
Patch
Comment 2 Michael Catanzaro 2018-09-19 06:59:25 PDT
Comment on attachment 350101 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=350101&action=review

In this case, I would check for sys/memfd.h instead of linux/memfd.h and use memfd_create() directly if it's available (glibc 2.27 or newer) rather than using syscall(). Then you don't have to check for EINTR or ENOSYS.

This way works too, of course.

> Source/WebKit/Platform/unix/SharedMemoryUnix.cpp:128
> +        if (errno == ENOSYS)
> +            return fileDescriptor;

Surely this isn't right? You should just remove this condition and fall through to isMemFdAvailable = false, right?

> Source/WebKit/Platform/unix/SharedMemoryUnix.cpp:154
> -        WTFLogAlways("Failed to create shared memory file %s: %s", tempName.data(), strerror(errno));
> +        WTFLogAlways("Failed to create shared memory file: %s", strerror(errno));

Drop the word "file"
Comment 3 Carlos Garcia Campos 2018-09-20 00:04:23 PDT
(In reply to Michael Catanzaro from comment #2)
> Comment on attachment 350101 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=350101&action=review
> 
> In this case, I would check for sys/memfd.h instead of linux/memfd.h and use
> memfd_create() directly if it's available (glibc 2.27 or newer) rather than
> using syscall(). Then you don't have to check for EINTR or ENOSYS.
> 
> This way works too, of course.

I'm assuming this is available in more systems, no?

> > Source/WebKit/Platform/unix/SharedMemoryUnix.cpp:128
> > +        if (errno == ENOSYS)
> > +            return fileDescriptor;
> 
> Surely this isn't right? You should just remove this condition and fall
> through to isMemFdAvailable = false, right?

Yes, I changed this several times and ended up with the wrong check. Good catch!

> > Source/WebKit/Platform/unix/SharedMemoryUnix.cpp:154
> > -        WTFLogAlways("Failed to create shared memory file %s: %s", tempName.data(), strerror(errno));
> > +        WTFLogAlways("Failed to create shared memory file: %s", strerror(errno));
> 
> Drop the word "file"

Sure.
Comment 4 Michael Catanzaro 2018-09-20 09:11:38 PDT
(In reply to Carlos Garcia Campos from comment #3)
> I'm assuming this is available in more systems, no?

The syscall was added years before the glibc interface, but so what? It's nicer to use the glibc function, and there is a fallback, after all. syscall() is used in the sandbox code because it's really needed there, but here it's not: there is a fallback.
Comment 5 Carlos Garcia Campos 2018-09-22 00:54:35 PDT
(In reply to Michael Catanzaro from comment #4)
> (In reply to Carlos Garcia Campos from comment #3)
> > I'm assuming this is available in more systems, no?
> 
> The syscall was added years before the glibc interface, but so what? It's
> nicer to use the glibc function, and there is a fallback, after all.
> syscall() is used in the sandbox code because it's really needed there, but
> here it's not: there is a fallback.

I still don't understand why sandbox code can't use SharedMemory.
Comment 6 Carlos Garcia Campos 2018-11-07 06:24:17 PST
Committed r237922: <https://trac.webkit.org/changeset/237922>
Comment 7 Radar WebKit Bug Importer 2018-11-07 06:25:49 PST
<rdar://problem/45873944>