Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1068)

Unified Diff: ppapi/proxy/file_mapping_resource_posix.cc

Issue 69663002: PPAPI: Implement PPB_FileMapping on POSIX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix missing return Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/file_mapping_resource.cc ('k') | ppapi/proxy/file_mapping_resource_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/file_mapping_resource_posix.cc
diff --git a/ppapi/proxy/file_mapping_resource_posix.cc b/ppapi/proxy/file_mapping_resource_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eda29cfe88c7608095a8e1520c8eab11e04bea59
--- /dev/null
+++ b/ppapi/proxy/file_mapping_resource_posix.cc
@@ -0,0 +1,89 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/file_mapping_resource.h"
+
+#include <stdio.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include "ppapi/c/pp_errors.h"
+
+namespace ppapi {
+namespace proxy {
+
+namespace {
+
+int32_t ErrnoToPPError(int error_code) {
+ switch (error_code) {
+ case EACCES:
+ return PP_ERROR_NOACCESS;
+ case EAGAIN:
+ return PP_ERROR_NOMEMORY;
+ case EINVAL:
+ return PP_ERROR_BADARGUMENT;
+ case ENFILE:
+ case ENOMEM:
+ return PP_ERROR_NOMEMORY;
+ default:
+ return PP_ERROR_FAILED;
+ }
+}
+
+} // namespace
+
+// static
+FileMappingResource::MapResult FileMappingResource::DoMapBlocking(
+ scoped_refptr<FileIOResource::FileHandleHolder> handle,
+ void* address_hint,
+ int64_t length,
+ uint32_t map_protection,
+ uint32_t map_flags,
+ int64_t offset) {
+ int prot_for_mmap = 0;
+ if (map_protection & PP_FILEMAPPROTECTION_READ)
+ prot_for_mmap |= PROT_READ;
+ if (map_protection & PP_FILEMAPPROTECTION_WRITE)
+ prot_for_mmap |= PROT_WRITE;
+ if (prot_for_mmap == 0)
+ prot_for_mmap = PROT_NONE;
+
+ int flags_for_mmap = 0;
+ if (map_flags & PP_FILEMAPFLAG_SHARED)
+ flags_for_mmap |= MAP_SHARED;
+ if (map_flags & PP_FILEMAPFLAG_PRIVATE)
+ flags_for_mmap |= MAP_PRIVATE;
+ if (map_flags & PP_FILEMAPFLAG_FIXED)
+ flags_for_mmap |= MAP_FIXED;
+
+ MapResult map_result;
+ map_result.address =
+ mmap(address_hint,
+ static_cast<size_t>(length),
+ prot_for_mmap,
+ flags_for_mmap,
+ handle->raw_handle(),
+ static_cast<off_t>(offset));
+ if (map_result.address != MAP_FAILED)
+ map_result.result = PP_OK;
+ else
+ map_result.result = ErrnoToPPError(errno);
+ return map_result;
+}
+
+// static
+int32_t FileMappingResource::DoUnmapBlocking(const void* address,
+ int64_t length) {
+ if (munmap(const_cast<void*>(address), static_cast<size_t>(length)))
+ return ErrnoToPPError(errno);
+ return PP_OK;
+}
+
+// static
+int64_t FileMappingResource::DoGetMapPageSize() {
+ return getpagesize();
+}
+
+} // namespace proxy
+} // namespace ppapi
« no previous file with comments | « ppapi/proxy/file_mapping_resource.cc ('k') | ppapi/proxy/file_mapping_resource_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698