blob: b9d48dbcb1c4ae2c3ae8d4764c7fc723626d4f3e [file] [log] [blame]
[email protected]bde3d5d2014-01-23 19:26:041{{+bindTo:partials.standard_nacl_article}}
2
3<section id="technical-overview">
4<span id="overview"></span><h1 id="technical-overview"><span id="overview"></span>Technical Overview</h1>
[email protected]26420f22014-01-24 18:06:135<div class="contents local" id="contents" style="display: none">
[email protected]bde3d5d2014-01-23 19:26:046<ul class="small-gap">
7<li><a class="reference internal" href="#introduction" id="id2">Introduction</a></li>
8<li><a class="reference internal" href="#why-use-native-client" id="id3">Why use Native Client?</a></li>
9<li><a class="reference internal" href="#common-use-cases" id="id4">Common use cases</a></li>
10<li><p class="first"><a class="reference internal" href="#how-native-client-works" id="id5">How Native Client works</a></p>
11<ul class="small-gap">
12<li><a class="reference internal" href="#security" id="id6">Security</a></li>
13<li><a class="reference internal" href="#portability" id="id7">Portability</a></li>
14<li><a class="reference internal" href="#toolchains" id="id8">Toolchains</a></li>
15</ul>
16</li>
17<li><p class="first"><a class="reference internal" href="#native-client-in-a-web-application" id="id9">Native Client in a web application</a></p>
18<ul class="small-gap">
19<li><a class="reference internal" href="#pepper-plugin-api" id="id10">Pepper Plugin API</a></li>
20</ul>
21</li>
22<li><a class="reference internal" href="#versioning" id="id11">Versioning</a></li>
23<li><a class="reference internal" href="#where-to-start" id="id12">Where to start</a></li>
24</ul>
[email protected]26420f22014-01-24 18:06:1325
[email protected]c3c19f12014-08-06 18:01:4326</div><h2 id="introduction">Introduction</h2>
[email protected]bde3d5d2014-01-23 19:26:0427<p><strong>Native Client</strong> (NaCl) is an open-source technology for running native
28compiled code in the browser, with the goal of maintaining the portability
29and safety that users expect from web applications. Native Client expands web
30programming beyond JavaScript, enabling developers to enhance their web
31applications using their preferred language. This document describes some of
32the key benefits and common use cases of Native Client.</p>
33<p>Google has implemented the open-source <a class="reference external" href="http://www.chromium.org/nativeclient">Native Client project</a> in the Chrome browser on Windows, Mac,
34Linux, and Chrome OS. The <a class="reference internal" href="/native-client/sdk/download.html"><em>Native Client Software Development Kit (SDK)</em></a>, itself an open-source project, lets developers create web
35applications that use NaCl and run in Chrome across multiple platforms.</p>
36<p>A web application that uses Native Client generally consists of a combination of
37JavaScript, HTML, CSS, and a NaCl module that is written in a language supported
38by the SDK. The NaCl SDK currently supports C and C++; as compilers for
39additional languages are developed, the SDK will be updated to support those
40languages as well.</p>
41<img alt="/native-client/images/web-app-with-nacl.png" src="/native-client/images/web-app-with-nacl.png" />
[email protected]bde3d5d2014-01-23 19:26:0442<h2 id="why-use-native-client">Why use Native Client?</h2>
43<p>Native Client open-source technology is designed to run compiled code
44securely inside a browser at near-native speeds. Native Client puts web
45applications on the same playing field as traditional (locally-run)
46software&#8212;it provides the means to fully harness the client&#8217;s computational
47resources for applications such as 3D games, multimedia editors, CAD modeling,
48client-side data analytics, and interactive simulations.
49Native Client also aims to give C and C++ (and eventually other languages) the
50same level of portability and safety that JavaScript provides on the web today.</p>
51<p>Here are a few of the key benefits that Native Client offers:</p>
52<ul class="small-gap">
53<li><strong>Graphics, audio, and much more:</strong> Run native code modules that render 2D
54and 3D graphics, play audio, respond to mouse and keyboard events, run on
55multiple threads, and access memory directly&#8212;all without requiring
56the user to install a plugin.</li>
57<li><strong>Portability:</strong> Write your applications once and you&#8217;ll be able to run them
58across operating systems (Windows, Linux, Mac, and Chrome OS) and CPU
59architectures (x86 and ARM).</li>
60<li><strong>Easy migration path to the web:</strong> Many developers and companies have years
61of work invested in existing desktop applications. Native Client makes the
62transition from the desktop to a web application significantly easier because
63it supports C and C++.</li>
64<li><strong>Security:</strong> Native Client uses a double sandbox model designed to protect
65the user&#8217;s system from malicious or buggy applications. This model offers the
66safety of traditional web applications without sacrificing performance and
67without requiring users to install a plugin.</li>
68<li><strong>Performance:</strong> Native Client allows web applications to run at speeds
69comparable to desktop applications (within 5-15% of native speed).
70Native Client also allows applications to harness all available CPU cores via
71a threading API; this enables demanding applications such as console-quality
72games to run inside the browser.</li>
73</ul>
[email protected]bde3d5d2014-01-23 19:26:0474<h2 id="common-use-cases">Common use cases</h2>
75<p>Typical use cases for Native Client include the following:</p>
76<ul class="small-gap">
77<li><strong>Existing software components:</strong> With support for C and C++, Native
78Client enables you to reuse existing software modules in
79web applications&#8212;you don&#8217;t need to rewrite and debug code
80that&#8217;s already proven to work well.</li>
81<li><strong>Legacy desktop applications:</strong> Native Client provides a smooth migration
82path from desktop applications to the web. You can port and recompile existing
83code for the computation engine of your application directly to Native Client,
84and need repurpose only the user interface and event handling portions to the
85new browser platform. Native Client allows you to embed existing functionality
86directly into the browser. At the same time, your application can take
87advantage of things the browser does well: handling user interaction and
88processing events, based on the latest developments in HTML5.</li>
89<li><strong>Heavy computation in enterprise applications:</strong> Native Client can handle the
90number crunching required by large-scale enterprise applications. To ensure
91protection of user data, Native Client enables you to build complex
92cryptographic algorithms directly into the browser so that unencrypted data
93never goes out over the network.</li>
94<li><strong>Multimedia applications:</strong> Codecs for processing sounds, images, and movies
95can be added to the browser in a Native Client module.</li>
96<li><strong>Games:</strong> Native Client lets web applications run at close to native
97speed, reuse existing multithreaded/multicore C/C++ code bases, and
98access low-latency audio, networking APIs, and OpenGL ES with programmable
99shaders. Native Client is a natural fit for running a physics engine or
100artificial intelligence module that powers a sophisticated web game.
101Native Client also enables applications to run unchanged across
102many platforms.</li>
103<li><strong>Any application that requires acceleration</strong>: Native Client fits seamlessly
104into web applications&#8212;it&#8217;s up to you to decide to what extent to use it.
105Use of Native Client covers the full spectrum from complete applications to
106small optimized routines that accelerate vital parts of web apps.</li>
107</ul>
[email protected]c3c19f12014-08-06 18:01:43108<h2 id="how-native-client-works"><span id="link-how-nacl-works"></span>How Native Client works</h2>
[email protected]bde3d5d2014-01-23 19:26:04109<p>Native Client is an umbrella name for a set of interrelated software components
110that work together to provide a way to develop C/C++ applications and run them
111securely on the web.</p>
112<p>At a high level, Native Client consists of:</p>
113<ul class="small-gap">
114<li><strong>Toolchains</strong>: collections of development tools (compilers, linkers, etc.)
115that transform C/C++ code to Native Client modules.</li>
116<li><strong>Runtime components</strong>: components embedded in the browser or other
117host platforms that allow execution of Native Client modules
118securely and efficiently.</li>
119</ul>
120<p>The following diagram shows how these components interact:</p>
121<img alt="/native-client/images/nacl-pnacl-component-diagram.png" src="/native-client/images/nacl-pnacl-component-diagram.png" />
122<p>The left side of the diagram shows how to use Portable Native Client
123(PNaCl, pronounced &#8220;pinnacle&#8221;). Developers use the PNaCl toolchain
124to produce a single, portable (<strong>pexe</strong>) module. At runtime, a translator
125built into the browser translates the pexe into native code for the
126relevant client architecture.</p>
127<p>The right side of the diagram shows how to use traditional (non-portable)
128Native Client. Developers use a nacl-gcc based toolchain to produce multiple
129architecture-dependent (<strong>nexe</strong>) modules, which are packaged into an
130application. At runtime, the browser decides which nexe to load based
131on the architecture of the client machine.</p>
[email protected]bde3d5d2014-01-23 19:26:04132<h3 id="security">Security</h3>
133<p>Since Native Client permits the execution of native code on client machines,
134special security measures have to be implemented:</p>
135<ul class="small-gap">
136<li>The NaCl sandbox ensures that code accesses system resources only through
137safe, whitelisted APIs, and operates within its limits without attempting to
138interfere with other code running either within the browser or outside it.</li>
139<li>The NaCl validator statically analyzes code prior to running it
140to make sure it only uses code and data patterns that are permitted and safe.</li>
141</ul>
142<p>The above security measures are in addition to the existing sandbox in the
143Chrome browser&#8212;the Native Client module always executes in a process with
144restricted permissions. The only interaction between this process and the
145outside world is through sanctioned browser interfaces. Because of the
146combination of the NaCl sandbox and the Chrome sandbox, we say that
147Native Client employs a double sandbox design.</p>
[email protected]bde3d5d2014-01-23 19:26:04148<h3 id="portability">Portability</h3>
149<p>Portable Native Client (PNaCl, prounounced &#8220;pinnacle&#8221;) employs state-of-the-art
150compiler technology to compile C/C++ source code to a portable bitcode
151executable (<strong>pexe</strong>). PNaCl bitcode is an OS- and architecture-independent
152format that can be freely distributed on the web and <a class="reference internal" href="#link-nacl-in-web-apps"><em>embedded in web
153applications</em></a>.</p>
154<p>The PNaCl translator is a component embedded in the Chrome browser; its task is
155to run pexe modules. Internally, the translator compiles a pexe to a nexe
156(a native executable for the client platform&#8217;s architecture), and then executes
157the nexe within the Native Client sandbox as described above. It also uses
158intelligent caching to avoid re-compiling the pexe if it was previously compiled
159on the client&#8217;s browser.</p>
160<p>Native Client also supports the execution of nexe modules directly in the
161browser. However, since nexes contain architecture-specific machine code,
162they are not allowed to be distributed on the open web&#8212;they can only be
163used as part of applications and extensions that are installed from the
164Chrome Web Store.</p>
165<p>For more details on the difference between NaCl and PNaCl, see
166<a class="reference internal" href="/native-client/nacl-and-pnacl.html"><em>NaCl and PNaCl</em></a>.</p>
[email protected]c3c19f12014-08-06 18:01:43167<h3 id="toolchains"><span id="id1"></span>Toolchains</h3>
[email protected]bde3d5d2014-01-23 19:26:04168<p>A toolchain is a set of tools used to create an application from a set of
169source files. In the case of Native Client, a toolchain consists of a compiler,
170linker, assembler and other tools that are used to convert an
171application written in C/C++ into a module that is loadable by the browser.</p>
172<p>The Native Client SDK provides two toolchains:</p>
173<ul class="small-gap">
174<li>a <strong>PNaCl toolchain</strong> for generating portable NaCl modules (pexe files)</li>
175<li>a <strong>gcc-based toolchain (nacl-gcc)</strong> for generating non-portable NaCl modules
176(nexe files)</li>
177</ul>
178<p>The PNaCl toolchain is recommended for most applications. The nacl-gcc
179toolchain should only be used for applications that will not be distributed
180on the open web.</p>
[email protected]c3c19f12014-08-06 18:01:43181<h2 id="native-client-in-a-web-application"><span id="link-nacl-in-web-apps"></span>Native Client in a web application</h2>
[email protected]bde3d5d2014-01-23 19:26:04182<p id="application-files">A Native Client application consists of a set of files:</p>
183<ul class="small-gap">
184<li><strong>HTML</strong>, <strong>CSS</strong>, and <strong>JavaScript</strong> files, as in any modern web
185application. The JavaScript code is responsible for communicating with the
186NaCl module.</li>
187<li>A <strong>pexe</strong> (portable NaCl) file. This module uses the <a class="reference internal" href="#link-pepper"><em>Pepper</em></a> API, which provides the bridge to JavaScript and
188browser resources.</li>
189<li>A Native Client <strong>manifest</strong> file that specifies the pexe to load, along with
190some loading options. This manifest file is embedded into the HTML page
191through an <code>&lt;embed&gt;</code> tag, as shown in the figure below.</li>
192</ul>
193<img alt="/native-client/images/nacl-in-a-web-app.png" src="/native-client/images/nacl-in-a-web-app.png" />
194<p>For more details, see <a class="reference internal" href="/native-client/devguide/coding/application-structure.html"><em>Application Structure</em></a>.</p>
[email protected]c3c19f12014-08-06 18:01:43195<h3 id="pepper-plugin-api"><span id="link-pepper"></span>Pepper Plugin API</h3>
[email protected]bde3d5d2014-01-23 19:26:04196<p>The Pepper Plugin API (PPAPI), called <strong>Pepper</strong> for convenience, is an
197open-source, cross-platform C/C++ API for web browser plugins. From the point
198of view of Native Client, Pepper allows a C/C++ module to communicate with
199the hosting browser and get access to system-level functions in a safe and
200portable way. One of the security constraints in Native Client is that modules
201cannot make any OS-level calls directly. Pepper provides analogous APIs that
202modules can target instead.</p>
203<p>You can use the Pepper APIs to gain access to the full array of browser
204capabilities, including:</p>
205<ul class="small-gap">
206<li><a class="reference internal" href="/native-client/devguide/coding/message-system.html"><em>Talking to the JavaScript code in your application</em></a> from the C++ code in your NaCl module.</li>
207<li><a class="reference internal" href="/native-client/devguide/coding/file-io.html"><em>Doing file I/O</em></a>.</li>
208<li><a class="reference internal" href="/native-client/devguide/coding/audio.html"><em>Playing audio</em></a>.</li>
209<li><a class="reference internal" href="/native-client/devguide/coding/3D-graphics.html"><em>Rendering 3D graphics</em></a>.</li>
210</ul>
211<p>Pepper includes both a C API and a C++ API. The C++ API is a set of bindings
212written on top of the C API. For additional information about Pepper, see
213<a class="reference external" href="http://code.google.com/p/ppapi/wiki/Concepts">Pepper Concepts</a>.</p>
[email protected]bde3d5d2014-01-23 19:26:04214<h2 id="versioning">Versioning</h2>
215<p>Chrome is released on a six week cycle, and developer versions of Chrome are
216pushed to the public beta channel three weeks before each release. As with any
217software, each release of Chrome may include changes to Native Client and the
218Pepper interfaces that may require modification to existing applications.
219However, modules compiled for one version of Pepper/Chrome should work with
[email protected]2547c912014-04-30 20:45:02220subsequent versions of Pepper/Chrome. The SDK includes multiple versions of the
221Pepper APIs to help developers make adjustments to API changes and take
222advantage of new features: <a class="reference external" href="/native-client/pepper_stable">stable</a>, <a class="reference external" href="/native-client/pepper_beta">beta</a> and <a class="reference external" href="/native-client/pepper_dev">dev</a>.</p>
[email protected]bde3d5d2014-01-23 19:26:04223<h2 id="where-to-start">Where to start</h2>
224<p>The <a class="reference internal" href="/native-client/quick-start.html"><em>Quick Start</em></a> document provides links to downloads and
225documentation that should help you get started with developing and distributing
226Native Client applications.</p>
[email protected]c3c19f12014-08-06 18:01:43227</section>
[email protected]bde3d5d2014-01-23 19:26:04228
229{{/partials.standard_nacl_article}}