summaryrefslogtreecommitdiff
path: root/Source/WebKit2/Platform/unix
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/Platform/unix')
-rw-r--r--Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp124
-rw-r--r--Source/WebKit2/Platform/unix/EnvironmentUtilities.h42
-rw-r--r--Source/WebKit2/Platform/unix/LoggingUnix.cpp41
-rw-r--r--Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp119
4 files changed, 269 insertions, 57 deletions
diff --git a/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp b/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp
new file mode 100644
index 000000000..0de876715
--- /dev/null
+++ b/Source/WebKit2/Platform/unix/EnvironmentUtilities.cpp
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EnvironmentUtilities.h"
+
+#include <wtf/text/CString.h>
+
+namespace WebKit {
+
+namespace EnvironmentUtilities {
+
+void stripValuesEndingWithString(const char* environmentVariable, const char* searchValue)
+{
+ ASSERT(environmentVariable);
+ ASSERT(searchValue);
+
+ // Grab the current value of the environment variable.
+ char* environmentValue = getenv(environmentVariable);
+
+ if (!environmentValue || environmentValue[0] == '\0')
+ return;
+
+ // Set up the strings we'll be searching for.
+ size_t searchLength = strlen(searchValue);
+ if (!searchLength)
+ return;
+
+ Vector<char> searchValueWithColonVector;
+ searchValueWithColonVector.grow(searchLength + 2);
+ char* searchValueWithColon = searchValueWithColonVector.data();
+ size_t searchLengthWithColon = searchLength + 1;
+
+ memcpy(searchValueWithColon, searchValue, searchLength);
+ searchValueWithColon[searchLength] = ':';
+ searchValueWithColon[searchLengthWithColon] = '\0';
+
+ // Loop over environmentValueBuffer, removing any components that match the search value ending with a colon.
+ char* componentStart = environmentValue;
+ char* match = strstr(componentStart, searchValueWithColon);
+ bool foundAnyMatches = match != NULL;
+ while (match != NULL) {
+ // Update componentStart to point to the colon immediately preceding the match.
+ char* nextColon = strstr(componentStart, ":");
+ while (nextColon && nextColon < match) {
+ componentStart = nextColon;
+ nextColon = strstr(componentStart + 1, ":");
+ }
+
+ // Copy over everything right of the match to the current component start, and search from there again.
+ if (componentStart[0] == ':') {
+ // If componentStart points to a colon, copy the colon over.
+ strcpy(componentStart, match + searchLength);
+ } else {
+ // Otherwise, componentStart still points to the beginning of environmentValueBuffer, so don't copy over the colon.
+ // The edge case is if the colon is the last character in the string, so "match + searchLengthWithoutColon + 1" is the
+ // null terminator of the original input, in which case this is still safe.
+ strcpy(componentStart, match + searchLengthWithColon);
+ }
+
+ match = strstr(componentStart, searchValueWithColon);
+ }
+
+ // Search for the value without a trailing colon, seeing if the original input ends with it.
+ match = strstr(componentStart, searchValue);
+ while (match != NULL) {
+ if (match[searchLength] == '\0')
+ break;
+ match = strstr(match + 1, searchValue);
+ }
+
+ // Since the original input ends with the search, strip out the last component.
+ if (match) {
+ // Update componentStart to point to the colon immediately preceding the match.
+ char* nextColon = strstr(componentStart, ":");
+ while (nextColon && nextColon < match) {
+ componentStart = nextColon;
+ nextColon = strstr(componentStart + 1, ":");
+ }
+
+ // Whether componentStart points to the original string or the last colon, putting the null terminator there will get us the desired result.
+ componentStart[0] = '\0';
+
+ foundAnyMatches = true;
+ }
+
+ // If we found no matches, don't change anything.
+ if (!foundAnyMatches)
+ return;
+
+ // If we have nothing left, just unset the variable
+ if (environmentValue[0] == '\0') {
+ unsetenv(environmentVariable);
+ return;
+ }
+
+ setenv(environmentVariable, environmentValue, 1);
+}
+
+} // namespace EnvironmentUtilities
+
+} // namespace WebKit
diff --git a/Source/WebKit2/Platform/unix/EnvironmentUtilities.h b/Source/WebKit2/Platform/unix/EnvironmentUtilities.h
new file mode 100644
index 000000000..fed77bc3f
--- /dev/null
+++ b/Source/WebKit2/Platform/unix/EnvironmentUtilities.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EnvironmentUtilities_h
+#define EnvironmentUtilities_h
+
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+namespace EnvironmentUtilities {
+
+void stripValuesEndingWithString(const char* environmentVariable, const char* search);
+
+} // namespace EnvironmentUtilities
+
+} // namespace WebKit
+
+#endif // #define EnvironmentUtilities_h
+
diff --git a/Source/WebKit2/Platform/unix/LoggingUnix.cpp b/Source/WebKit2/Platform/unix/LoggingUnix.cpp
new file mode 100644
index 000000000..8014a5dcf
--- /dev/null
+++ b/Source/WebKit2/Platform/unix/LoggingUnix.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "Logging.h"
+
+namespace WebKit {
+
+#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
+
+String logLevelString()
+{
+ return getenv("WEBKIT_DEBUG");
+}
+
+#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
+
+}
diff --git a/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp b/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp
index 5beba1370..c246312f9 100644
--- a/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp
+++ b/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp
@@ -29,8 +29,8 @@
#if USE(UNIX_DOMAIN_SOCKETS)
#include "SharedMemory.h"
-#include "ArgumentDecoder.h"
-#include "ArgumentEncoder.h"
+#include "Decoder.h"
+#include "Encoder.h"
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -43,61 +43,71 @@
#include <wtf/RandomNumber.h>
#include <wtf/UniStdExtras.h>
#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
namespace WebKit {
SharedMemory::Handle::Handle()
- : m_fileDescriptor(-1)
- , m_size(0)
{
}
SharedMemory::Handle::~Handle()
{
- if (!isNull())
- closeWithRetry(m_fileDescriptor);
+}
+
+void SharedMemory::Handle::clear()
+{
+ m_attachment = IPC::Attachment();
}
bool SharedMemory::Handle::isNull() const
{
- return m_fileDescriptor == -1;
+ return m_attachment.fileDescriptor() == -1;
}
-void SharedMemory::Handle::encode(IPC::ArgumentEncoder& encoder) const
+void SharedMemory::Handle::encode(IPC::Encoder& encoder) const
{
- encoder << releaseToAttachment();
+ encoder << releaseAttachment();
}
-bool SharedMemory::Handle::decode(IPC::ArgumentDecoder& decoder, Handle& handle)
+bool SharedMemory::Handle::decode(IPC::Decoder& decoder, Handle& handle)
{
- ASSERT_ARG(handle, !handle.m_size);
ASSERT_ARG(handle, handle.isNull());
IPC::Attachment attachment;
if (!decoder.decode(attachment))
return false;
- handle.adoptFromAttachment(attachment.releaseFileDescriptor(), attachment.size());
+ handle.adoptAttachment(WTFMove(attachment));
return true;
}
-IPC::Attachment SharedMemory::Handle::releaseToAttachment() const
+IPC::Attachment SharedMemory::Handle::releaseAttachment() const
{
- int temp = m_fileDescriptor;
- m_fileDescriptor = -1;
- return IPC::Attachment(temp, m_size);
+ return WTFMove(m_attachment);
}
-void SharedMemory::Handle::adoptFromAttachment(int fileDescriptor, size_t size)
+void SharedMemory::Handle::adoptAttachment(IPC::Attachment&& attachment)
{
- ASSERT(!m_size);
ASSERT(isNull());
- m_fileDescriptor = fileDescriptor;
- m_size = size;
+ m_attachment = WTFMove(attachment);
}
-PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
+static inline int accessModeMMap(SharedMemory::Protection protection)
+{
+ switch (protection) {
+ case SharedMemory::Protection::ReadOnly:
+ return PROT_READ;
+ case SharedMemory::Protection::ReadWrite:
+ return PROT_READ | PROT_WRITE;
+ }
+
+ ASSERT_NOT_REACHED();
+ return PROT_READ | PROT_WRITE;
+}
+
+RefPtr<SharedMemory> SharedMemory::create(void* address, size_t size, Protection protection)
{
CString tempName;
@@ -111,7 +121,7 @@ PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
} while (fileDescriptor == -1 && errno == EINTR);
}
if (fileDescriptor == -1) {
- WTFLogAlways("Failed to create shared memory file %s", tempName.data());
+ WTFLogAlways("Failed to create shared memory file %s: %s", tempName.data(), strerror(errno));
return 0;
}
@@ -123,7 +133,7 @@ PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
}
}
- void* data = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
+ void* data = mmap(address, size, accessModeMMap(protection), MAP_SHARED, fileDescriptor, 0);
if (data == MAP_FAILED) {
closeWithRetry(fileDescriptor);
shm_unlink(tempName.data());
@@ -139,66 +149,61 @@ PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
return instance.release();
}
-static inline int accessModeMMap(SharedMemory::Protection protection)
+RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
{
- switch (protection) {
- case SharedMemory::ReadOnly:
- return PROT_READ;
- case SharedMemory::ReadWrite:
- return PROT_READ | PROT_WRITE;
- }
-
- ASSERT_NOT_REACHED();
- return PROT_READ | PROT_WRITE;
+ return SharedMemory::create(nullptr, size, SharedMemory::Protection::ReadWrite);
}
-PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection)
+RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection)
{
ASSERT(!handle.isNull());
- void* data = mmap(0, handle.m_size, accessModeMMap(protection), MAP_SHARED, handle.m_fileDescriptor, 0);
+ int fd = handle.m_attachment.releaseFileDescriptor();
+ void* data = mmap(0, handle.m_attachment.size(), accessModeMMap(protection), MAP_SHARED, fd, 0);
+ closeWithRetry(fd);
if (data == MAP_FAILED)
- return 0;
+ return nullptr;
+ RefPtr<SharedMemory> instance = wrapMap(data, handle.m_attachment.size(), -1);
+ instance->m_fileDescriptor = std::nullopt;
+ instance->m_isWrappingMap = false;
+ return instance;
+}
+
+RefPtr<SharedMemory> SharedMemory::wrapMap(void* data, size_t size, int fileDescriptor)
+{
RefPtr<SharedMemory> instance = adoptRef(new SharedMemory());
instance->m_data = data;
- instance->m_fileDescriptor = handle.m_fileDescriptor;
- instance->m_size = handle.m_size;
- handle.m_fileDescriptor = -1;
+ instance->m_size = size;
+ instance->m_fileDescriptor = fileDescriptor;
+ instance->m_isWrappingMap = true;
return instance;
}
SharedMemory::~SharedMemory()
{
+ if (m_isWrappingMap)
+ return;
+
munmap(m_data, m_size);
- closeWithRetry(m_fileDescriptor);
+ if (m_fileDescriptor)
+ closeWithRetry(m_fileDescriptor.value());
}
bool SharedMemory::createHandle(Handle& handle, Protection)
{
- ASSERT_ARG(handle, !handle.m_size);
ASSERT_ARG(handle, handle.isNull());
+ ASSERT(m_fileDescriptor);
// FIXME: Handle the case where the passed Protection is ReadOnly.
// See https://bugs.webkit.org/show_bug.cgi?id=131542.
- int duplicatedHandle;
- while ((duplicatedHandle = dup(m_fileDescriptor)) == -1) {
- if (errno != EINTR) {
- ASSERT_NOT_REACHED();
- return false;
- }
- }
-
- while (fcntl(duplicatedHandle, F_SETFD, FD_CLOEXEC) == -1) {
- if (errno != EINTR) {
- ASSERT_NOT_REACHED();
- closeWithRetry(duplicatedHandle);
- return false;
- }
+ int duplicatedHandle = dupCloseOnExec(m_fileDescriptor.value());
+ if (duplicatedHandle == -1) {
+ ASSERT_NOT_REACHED();
+ return false;
}
- handle.m_fileDescriptor = duplicatedHandle;
- handle.m_size = m_size;
+ handle.m_attachment = IPC::Attachment(duplicatedHandle, m_size);
return true;
}