1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/proxy/file_mapping_resource.h"
11 #include "ppapi/c/pp_errors.h"
18 int32_t ErrnoToPPError(int error_code
) {
21 return PP_ERROR_NOACCESS
;
23 return PP_ERROR_NOMEMORY
;
25 return PP_ERROR_BADARGUMENT
;
28 return PP_ERROR_NOMEMORY
;
30 return PP_ERROR_FAILED
;
37 FileMappingResource::MapResult
FileMappingResource::DoMapBlocking(
38 scoped_refptr
<FileIOResource::FileHandleHolder
> handle
,
41 uint32_t map_protection
,
44 int prot_for_mmap
= 0;
45 if (map_protection
& PP_FILEMAPPROTECTION_READ
)
46 prot_for_mmap
|= PROT_READ
;
47 if (map_protection
& PP_FILEMAPPROTECTION_WRITE
)
48 prot_for_mmap
|= PROT_WRITE
;
49 if (prot_for_mmap
== 0)
50 prot_for_mmap
= PROT_NONE
;
52 int flags_for_mmap
= 0;
53 if (map_flags
& PP_FILEMAPFLAG_SHARED
)
54 flags_for_mmap
|= MAP_SHARED
;
55 if (map_flags
& PP_FILEMAPFLAG_PRIVATE
)
56 flags_for_mmap
|= MAP_PRIVATE
;
57 if (map_flags
& PP_FILEMAPFLAG_FIXED
)
58 flags_for_mmap
|= MAP_FIXED
;
63 static_cast<size_t>(length
),
67 static_cast<off_t
>(offset
));
68 if (map_result
.address
!= MAP_FAILED
)
69 map_result
.result
= PP_OK
;
71 map_result
.result
= ErrnoToPPError(errno
);
76 int32_t FileMappingResource::DoUnmapBlocking(const void* address
,
78 if (munmap(const_cast<void*>(address
), static_cast<size_t>(length
)))
79 return ErrnoToPPError(errno
);
84 int64_t FileMappingResource::DoGetMapPageSize() {