OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 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. |
| 4 */ |
| 5 |
| 6 /* From ppb_file_mapping.idl modified Wed Jan 22 10:45:15 2014. */ |
| 7 |
| 8 #ifndef PPAPI_C_PPB_FILE_MAPPING_H_ |
| 9 #define PPAPI_C_PPB_FILE_MAPPING_H_ |
| 10 |
| 11 #include "ppapi/c/pp_completion_callback.h" |
| 12 #include "ppapi/c/pp_instance.h" |
| 13 #include "ppapi/c/pp_macros.h" |
| 14 #include "ppapi/c/pp_resource.h" |
| 15 #include "ppapi/c/pp_stdint.h" |
| 16 |
| 17 #define PPB_FILEMAPPING_INTERFACE_0_1 "PPB_FileMapping;0.1" /* dev */ |
| 18 /** |
| 19 * @file |
| 20 * This file defines methods for mapping and unmapping files into and out of |
| 21 * memory. |
| 22 */ |
| 23 |
| 24 |
| 25 /** |
| 26 * @addtogroup Enums |
| 27 * @{ |
| 28 */ |
| 29 /** |
| 30 * The PP_FileMapProtection values indicate the permissions requested for the |
| 31 * file mapping. These should be used in a uint32_t bitfield. |
| 32 */ |
| 33 typedef enum { |
| 34 /** Requests read access to the mapped address. */ |
| 35 PP_FILEMAPPROTECTION_READ = 1u << 0, |
| 36 /** Requests write access to the mapped address. */ |
| 37 PP_FILEMAPPROTECTION_WRITE = 1u << 1 |
| 38 } PP_FileMapProtection; |
| 39 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FileMapProtection, 4); |
| 40 |
| 41 /** |
| 42 * The PP_FileMapFlags contain flag values for use with Map(). |
| 43 */ |
| 44 typedef enum { |
| 45 /** |
| 46 * Requests a shared mapping. If this flag is set, changes written to the |
| 47 * memory region will be reflected in the underlying file and will thus |
| 48 * eventually be visible to other processes which have opened the file. The |
| 49 * file may not actually be updated until Unmap() is called. This is only |
| 50 * valid if the PPB_FileIO resource was opened with write permission. |
| 51 */ |
| 52 PP_FILEMAPFLAG_SHARED = 1u << 0, |
| 53 /** |
| 54 * Requests a copy-on-write mapping. If this flag is set, changes are not |
| 55 * written to the underlying file, but only in the memory of the process |
| 56 * (copy-on-write). |
| 57 */ |
| 58 PP_FILEMAPFLAG_PRIVATE = 1u << 1, |
| 59 /** |
| 60 * Forces Map() to map the file contents at the provided |address|. If Map() |
| 61 * can not comply, Map() will fail. |
| 62 */ |
| 63 PP_FILEMAPFLAG_FIXED = 1u << 2 |
| 64 } PP_FileMapFlags; |
| 65 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_FileMapFlags, 4); |
| 66 /** |
| 67 * @} |
| 68 */ |
| 69 |
| 70 /** |
| 71 * @addtogroup Interfaces |
| 72 * @{ |
| 73 */ |
| 74 /** |
| 75 * PPB_FileMapping contains functions for mapping and unmapping files into and |
| 76 * out of memory. |
| 77 */ |
| 78 struct PPB_FileMapping_0_1 { /* dev */ |
| 79 /** |
| 80 * Map() maps the contents from an offset of the file into memory. |
| 81 * |
| 82 * @param[in] instance A <code>PP_Instance</code> identifying one instance of |
| 83 * a module. |
| 84 * @param[in] file_io A <code>PP_Resource</code> corresponding to a file. |
| 85 * @param[in] length The number of bytes to map. |
| 86 * @param[in] map_protection A bitfield containing values from |
| 87 * <code>PP_FileMapProtection</code>, indicating what memory operations |
| 88 * should be permitted on the mapped region. |
| 89 * @param[in] map_flags A bitfield containing values from |
| 90 * <code>PP_FileMapFlags</code>, providing options for the behavior of Map. |
| 91 * If the region is to be writeable, then exactly one of |
| 92 * <code>PP_FILEMAPFLAG_SHARED</code> or <code>PP_FILEMAPFLAG_PRIVATE</code> |
| 93 * must be set. |
| 94 * @param[in] offset The offset into the file. Must be a multiple of the |
| 95 * Map page size as returned by GetMapPageSize(). |
| 96 * @param[inout] address The value of <code>*address</code>, if non-NULL, |
| 97 * will be used as a hint to determine where in memory the file should be |
| 98 * mapped. If the value is NULL, the host operating system will choose |
| 99 * <code>address</code>. Upon Map() completing, <code>*address</code> will |
| 100 * contain the actual memory location at which the file was mapped. If the |
| 101 * plugin provides a non-NULL <code>*address</code>, it must be a multiple of |
| 102 * the map page size as returned by GetMapPageSize(). |
| 103 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 104 * completion of Map(). |
| 105 * |
| 106 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 107 */ |
| 108 int32_t (*Map)(PP_Instance instance, |
| 109 PP_Resource file_io, |
| 110 int64_t length, |
| 111 uint32_t map_protection, |
| 112 uint32_t map_flags, |
| 113 int64_t offset, |
| 114 void** address, |
| 115 struct PP_CompletionCallback callback); |
| 116 /** |
| 117 * Unmap() deletes the mapping of the specified address. The specified |
| 118 * address must have been retrieved with Map(). |
| 119 * @param[in] instance A <code>PP_Instance</code> identifying the instance. |
| 120 * @param[in] address The starting address of the address in memory to |
| 121 * be unmapped. |
| 122 * @param[in] length The length of the region to unmap. |
| 123 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 124 * completion of Unmap(). |
| 125 * |
| 126 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 127 */ |
| 128 int32_t (*Unmap)(PP_Instance instance, |
| 129 const void* address, |
| 130 int64_t length, |
| 131 struct PP_CompletionCallback callback); |
| 132 /** |
| 133 * GetMapPageSize() retrieves the size of pages that Map() uses. |
| 134 * |
| 135 * @param[in] instance A <code>PP_Instance</code> identifying the instance. |
| 136 * |
| 137 * @return The size of pages that Map() uses. Returns 0 on failure. |
| 138 */ |
| 139 int64_t (*GetMapPageSize)(PP_Instance instance); |
| 140 }; |
| 141 /** |
| 142 * @} |
| 143 */ |
| 144 |
| 145 #endif /* PPAPI_C_PPB_FILE_MAPPING_H_ */ |
| 146 |
OLD | NEW |