Chromium Code Reviews| 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..ed00234e08a7454229cd1a9af1c9902eb23be7f9 |
| --- /dev/null |
| +++ b/ppapi/proxy/file_mapping_resource_posix.cc |
| @@ -0,0 +1,91 @@ |
| +// 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::DoMap( |
| + 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::DoUnmap(const void* address, int64_t length) { |
| + int result = munmap(const_cast<void*>(address), static_cast<size_t>(length)); |
|
bbudge
2014/01/25 01:04:55
Since we don't otherwise use result could it just
dmichael (off chromium)
2014/01/27 18:29:53
Done.
|
| + if (result) |
| + return ErrnoToPPError(errno); |
| + return PP_OK; |
| +} |
| + |
| +// static |
| +int64_t FileMappingResource::DoGetMapPageSize() { |
| + // TODO(dmichael): It might be better to port sys_info_posix.cc to NaCl and |
|
bbudge
2014/01/25 01:04:55
That file just calls getpagesize() and the rest is
dmichael (off chromium)
2014/01/27 18:29:53
Done.
|
| + // call Sysinfo::VMAllocationGranularity. |
| + return getpagesize(); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |