summaryrefslogtreecommitdiffstats
path: root/ppapi/api/ppb_file_mapping.idl
blob: 2a10946c58d329c80c749cec408c75d0ec9d47d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Copyright 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.
 */


/**
 * This file defines methods for mapping and unmapping files into and out of
 * memory.
 */

label Chrome {
  [channel=dev] M34 = 0.1
};

/**
 * The PP_FileMapProtection values indicate the permissions requested for the
 * file mapping. These should be used in a uint32_t bitfield.
 */
[assert_size(4)]
enum PP_FileMapProtection {
  /** Requests read access to the mapped address. */
  PP_FILEMAPPROTECTION_READ = 1u << 0,

  /** Requests write access to the mapped address. */
  PP_FILEMAPPROTECTION_WRITE = 1u << 1
};

/**
 * The PP_FileMapFlags contain flag values for use with Map().
 */
[assert_size(4)]
enum PP_FileMapFlags {
  /**
   * Requests a shared mapping. If this flag is set, changes written to the
   * memory region will be reflected in the underlying file and will thus
   * eventually be visible to other processes which have opened the file. The
   * file may not actually be updated until Unmap() is called. This is only
   * valid if the PPB_FileIO resource was opened with write permission.
   */
  PP_FILEMAPFLAG_SHARED = 1u << 0,

  /**
   * Requests a copy-on-write mapping. If this flag is set, changes are not
   * written to the underlying file, but only in the memory of the process
   * (copy-on-write).
   */
  PP_FILEMAPFLAG_PRIVATE = 1u << 1,

  /**
   * Forces Map() to map the file contents at the provided |address|. If Map()
   * can not comply, Map() will fail.
   */
  PP_FILEMAPFLAG_FIXED = 1u << 2
};

/**
 *  PPB_FileMapping contains functions for mapping and unmapping files into and
 *  out of memory.
 */
[singleton]
interface PPB_FileMapping {
  /**
   * Map() maps the contents from an offset of the file into memory.
   *
   * @param[in] instance A <code>PP_Instance</code> identifying one instance of
   * a module.
   * @param[in] file_io A <code>PPB_FileIO</code> <code>PP_Resource</code>
   * corresponding to the file that should be mapped in to memory.
   * @param[in] length The number of bytes to map.
   * @param[in] map_protection A bitfield containing values from
   * <code>PP_FileMapProtection</code>, indicating what memory operations
   * should be permitted on the mapped region.
   * @param[in] map_flags A bitfield containing values from
   * <code>PP_FileMapFlags</code>, providing options for the behavior of Map.
   * If the region is to be writeable, then exactly one of
   * <code>PP_FILEMAPFLAG_SHARED</code> or <code>PP_FILEMAPFLAG_PRIVATE</code>
   * must be set.
   * @param[in] offset The offset into the file. Must be a multiple of the
   * Map page size as returned by GetMapPageSize().
   * @param[inout] address The value of <code>*address</code>, if non-NULL,
   * will be used as a hint to determine where in memory the file should be
   * mapped. If the value is NULL, the host operating system will choose
   * <code>address</code>. Upon Map() completing, <code>*address</code> will
   * contain the actual memory location at which the file was mapped. If the
   * plugin provides a non-NULL <code>*address</code>, it must be a multiple of
   * the map page size as returned by GetMapPageSize().
   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
   * completion of Map().
   *
   * @return An int32_t containing an error code from <code>pp_errors.h</code>.
   */
  int32_t Map([in] PP_Instance instance,
              [in] PP_Resource file_io,
              [in] int64_t length,
              [in] uint32_t map_protection,
              [in] uint32_t map_flags,
              [in] int64_t offset,
              [inout] mem_ptr_t address,
              [in] PP_CompletionCallback callback);

  /**
   * Unmap() deletes the mapping of the specified address.  The specified
   * address must have been retrieved with Map().
   * @param[in] instance A <code>PP_Instance</code> identifying the instance.
   * @param[in] address The starting address of the address in memory to
   * be unmapped.
   * @param[in] length The length of the region to unmap.
   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
   * completion of Unmap().
   *
   * @return An int32_t containing an error code from <code>pp_errors.h</code>.
   */
  int32_t Unmap([in] PP_Instance instance,
                [in] mem_t address,
                [in] int64_t length,
                [in] PP_CompletionCallback callback);

  /**
   * GetMapPageSize() retrieves the size of pages that Map() uses.
   *
   * @param[in] instance A <code>PP_Instance</code> identifying the instance.
   *
   * @return The size of pages that Map() uses. Returns 0 on failure.
   */
  [on_failure=0]
  int64_t GetMapPageSize(PP_Instance instance);
};