1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
$NetBSD: patch-Source_WebKit2_Platform_unix_SharedMemoryUnix.cpp,v 1.1 2014/12/30 17:23:48 adam Exp $
* Try to use /tmp/* file like shared memory, I am not sure.
--- Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp.orig 2013-11-27 01:01:51.000000000 +0000
+++ Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp
@@ -139,14 +139,25 @@ PassRefPtr<SharedMemory> SharedMemory::c
PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
{
CString tempName;
+ CString buf;
int fileDescriptor = -1;
for (int tries = 0; fileDescriptor == -1 && tries < 10; ++tries) {
String name = String("/WK2SharedMemory.") + String::number(static_cast<unsigned>(WTF::randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)));
tempName = name.utf8();
+ String bbuf = String("/tmp") + name;
+ buf = bbuf.utf8();
do {
+#if !defined(__NetBSD__)
fileDescriptor = shm_open(tempName.data(), O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR);
+#else
+ fileDescriptor = open(buf.data(), O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR);
+ if (fileDescriptor == -1 && errno == EEXIST) {
+ unlink(buf.data());
+ fileDescriptor = open(buf.data(), O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR);
+ }
+#endif
} while (fileDescriptor == -1 && errno == EINTR);
}
if (fileDescriptor == -1) {
@@ -157,7 +168,12 @@ PassRefPtr<SharedMemory> SharedMemory::c
while (ftruncate(fileDescriptor, size) == -1) {
if (errno != EINTR) {
closeWithRetry(fileDescriptor);
+#if !defined(__NetBSD__)
shm_unlink(tempName.data());
+#else
+ close(fileDescriptor);
+ unlink(buf.data());
+#endif
return 0;
}
}
@@ -165,11 +181,21 @@ PassRefPtr<SharedMemory> SharedMemory::c
void* data = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
if (data == MAP_FAILED) {
closeWithRetry(fileDescriptor);
+#if !defined(__NetBSD__)
shm_unlink(tempName.data());
+#else
+ close(fileDescriptor);
+ unlink(buf.data());
+#endif
return 0;
}
+#if !defined(__NetBSD__)
shm_unlink(tempName.data());
+#else
+ close(fileDescriptor);
+ unlink(buf.data());
+#endif
RefPtr<SharedMemory> instance = adoptRef(new SharedMemory());
instance->m_data = data;
|