• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_NACL_COMMON_NACL_TYPES_H_
6 #define COMPONENTS_NACL_COMMON_NACL_TYPES_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 #include <utility>
12 #include <vector>
13 
14 #include "base/memory/read_only_shared_memory_region.h"
15 #include "base/memory/writable_shared_memory_region.h"
16 #include "base/process/process_handle.h"
17 #include "build/build_config.h"
18 #include "ipc/ipc_channel.h"
19 #include "ipc/ipc_platform_file.h"
20 
21 namespace nacl {
22 
23 // We allocate a page of shared memory for sharing crash information from
24 // trusted code in the NaCl process to the renderer.
25 static const int kNaClCrashInfoShmemSize = 4096;
26 static const int kNaClCrashInfoMaxLogSize = 1024;
27 
28 // Types of untrusted NaCl processes.
29 enum NaClAppProcessType {
30   kUnknownNaClProcessType,
31   // Runs user-provided *native* code. Enabled for Chrome Web Store apps.
32   kNativeNaClProcessType,
33   // Runs user-provided code that is translated from *bitcode* by an
34   // in-browser PNaCl translator.
35   kPNaClProcessType,
36   // Runs pnacl-llc/linker *native* code. These nexes are browser-provided
37   // (not user-provided).
38   kPNaClTranslatorProcessType,
39   kNumNaClProcessTypes
40 };
41 
42 // Represents a request to prefetch a file that's listed in the "files" section
43 // of a NaCl manifest file.
44 struct NaClResourcePrefetchRequest {
45   NaClResourcePrefetchRequest();
46   NaClResourcePrefetchRequest(const std::string& file_key,
47                               const std::string& resource_url);
48   ~NaClResourcePrefetchRequest();
49 
50   std::string file_key;  // a key for open_resource.
51   std::string resource_url;
52 };
53 
54 // Represents a single prefetched file that's listed in the "files" section of
55 // a NaCl manifest file.
56 struct NaClResourcePrefetchResult {
57   NaClResourcePrefetchResult();
58   NaClResourcePrefetchResult(const IPC::PlatformFileForTransit& file,
59                              const base::FilePath& file_path,
60                              const std::string& file_key);
61   ~NaClResourcePrefetchResult();
62 
63   IPC::PlatformFileForTransit file;
64   base::FilePath file_path_metadata;  // a key for validation caching
65   std::string file_key;  // a key for open_resource
66 };
67 
68 // Parameters sent to the NaCl process when we start it.
69 struct NaClStartParams {
70   NaClStartParams();
71 
72   NaClStartParams(const NaClStartParams&) = delete;
73   NaClStartParams& operator=(const NaClStartParams&) = delete;
74 
75   NaClStartParams(NaClStartParams&& other);
76 
77   ~NaClStartParams();
78 
79   IPC::PlatformFileForTransit nexe_file;
80   // Used only as a key for validation caching.
81   base::FilePath nexe_file_path_metadata;
82 
83   IPC::PlatformFileForTransit irt_handle;
84 #if BUILDFLAG(IS_POSIX)
85   IPC::PlatformFileForTransit debug_stub_server_bound_socket;
86 #endif
87 
88   bool validation_cache_enabled;
89   std::string validation_cache_key;
90   // Chrome version string. Sending the version string over IPC avoids linkage
91   // issues in cases where NaCl is not compiled into the main Chromium
92   // executable or DLL.
93   std::string version;
94 
95   bool enable_debug_stub;
96 
97   NaClAppProcessType process_type;
98 
99   // For NaCl <-> renderer crash information reporting.
100   base::WritableSharedMemoryRegion crash_info_shmem_region;
101 
102   // NOTE: Any new fields added here must also be added to the IPC
103   // serialization in nacl_messages.h and (for POD fields) the constructor
104   // in nacl_types.cc.
105 };
106 
107 // Parameters sent to the browser process to have it launch a NaCl process.
108 //
109 // If you change this, you will also need to update the IPC serialization in
110 // nacl_host_messages.h.
111 struct NaClLaunchParams {
112   NaClLaunchParams();
113   NaClLaunchParams(const std::string& manifest_url,
114                    const IPC::PlatformFileForTransit& nexe_file,
115                    uint64_t nexe_token_lo,
116                    uint64_t nexe_token_hi,
117                    const std::vector<NaClResourcePrefetchRequest>&
118                        resource_prefetch_request_list,
119                    int render_frame_id,
120                    uint32_t permission_bits,
121                    NaClAppProcessType process_type);
122   NaClLaunchParams(const NaClLaunchParams& other);
123   ~NaClLaunchParams();
124 
125   std::string manifest_url;
126   // On Windows, the HANDLE passed here is valid in the renderer's context.
127   // It's the responsibility of the browser to duplicate this handle properly
128   // for passing it to the plugin.
129   IPC::PlatformFileForTransit nexe_file = IPC::InvalidPlatformFileForTransit();
130   uint64_t nexe_token_lo = 0;
131   uint64_t nexe_token_hi = 0;
132   std::vector<NaClResourcePrefetchRequest> resource_prefetch_request_list;
133 
134   int render_frame_id = 0;
135   uint32_t permission_bits = 0;
136 
137   NaClAppProcessType process_type = kUnknownNaClProcessType;
138 };
139 
140 struct NaClLaunchResult {
141   NaClLaunchResult();
142   NaClLaunchResult(
143       const IPC::ChannelHandle& ppapi_ipc_channel_handle,
144       const IPC::ChannelHandle& trusted_ipc_channel_handle,
145       const IPC::ChannelHandle& manifest_service_ipc_channel_handle,
146       base::ProcessId plugin_pid,
147       int plugin_child_id,
148       base::ReadOnlySharedMemoryRegion crash_info_shmem_region);
149 
150   NaClLaunchResult(const NaClLaunchResult&) = delete;
151   NaClLaunchResult& operator=(const NaClLaunchResult&) = delete;
152 
153   ~NaClLaunchResult();
154 
155   // For plugin <-> renderer PPAPI communication.
156   IPC::ChannelHandle ppapi_ipc_channel_handle;
157 
158   // For plugin loader <-> renderer control communication (loading and
159   // starting nexe).
160   IPC::ChannelHandle trusted_ipc_channel_handle;
161 
162   // For plugin <-> renderer ManifestService communication.
163   IPC::ChannelHandle manifest_service_ipc_channel_handle;
164 
165   base::ProcessId plugin_pid;
166   int plugin_child_id;
167 
168   // For NaCl <-> renderer crash information reporting.
169   base::ReadOnlySharedMemoryRegion crash_info_shmem_region;
170 };
171 
172 }  // namespace nacl
173 
174 #endif  // COMPONENTS_NACL_COMMON_NACL_TYPES_H_
175