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