blob: 7886ddcbc6878fac0790a6502687a7e6428cebdb [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
jmedleyd80305562014-08-25 16:41:5245applications on the same playing field as desktop software&#8212;it provides the
46means to fully harness the client&#8217;s computational resources for applications
47such as 3D games, multimedia editors, CAD modeling,
[email protected]bde3d5d2014-01-23 19:26:0448client-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>
jmedleyd80305562014-08-25 16:41:5251<p>Important benefits of Native Client include:</p>
[email protected]bde3d5d2014-01-23 19:26:0452<ul class="small-gap">
jmedleyd80305562014-08-25 16:41:5253<li><strong>Graphics, audio, and much more:</strong> Running native code modules that render 2D
[email protected]bde3d5d2014-01-23 19:26:0454and 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>
jmedleyd80305562014-08-25 16:41:5257<li><strong>Portability:</strong> Writing your applications once and running them on operating
58systems (Windows, Linux, Mac, and Chrome OS) and CPU architectures (x86 and
59ARM).</li>
60<li><strong>Easy migration path to the web:</strong> Leveraging years of work in existing
61desktop applications. Native Client makes the transition from the desktop to a
62web application significantly easier because it supports C and C++.</li>
63<li><strong>Security:</strong> Protecting the user&#8217;s system from malicious or buggy
64applications through Native Client&#8217;s double sandbox model. This model offers
65the safety of traditional web applications without sacrificing performance and
[email protected]bde3d5d2014-01-23 19:26:0466without requiring users to install a plugin.</li>
jmedleyd80305562014-08-25 16:41:5267<li><strong>Performance:</strong> Running at speeds comparable to desktop applications (within
685-15% of native speed). Native Client also allows applications to harness all
69available CPU cores via a threading API; this enables demanding applications
70such as console-quality games to run inside the browser.</li>
[email protected]bde3d5d2014-01-23 19:26:0471</ul>
[email protected]bde3d5d2014-01-23 19:26:0472<h2 id="common-use-cases">Common use cases</h2>
73<p>Typical use cases for Native Client include the following:</p>
74<ul class="small-gap">
75<li><strong>Existing software components:</strong> With support for C and C++, Native
jmedleyd80305562014-08-25 16:41:5276Client lets you to reuse existing software modules in web applications. You
77don&#8217;t need to rewrite and debug code that already works.</li>
[email protected]bde3d5d2014-01-23 19:26:0478<li><strong>Legacy desktop applications:</strong> Native Client provides a smooth migration
79path from desktop applications to the web. You can port and recompile existing
80code for the computation engine of your application directly to Native Client,
jmedleyd80305562014-08-25 16:41:5281and need rebuild only the user interface and event handling portions for the
82browser.</li>
[email protected]bde3d5d2014-01-23 19:26:0483<li><strong>Heavy computation in enterprise applications:</strong> Native Client can handle the
84number crunching required by large-scale enterprise applications. To ensure
85protection of user data, Native Client enables you to build complex
86cryptographic algorithms directly into the browser so that unencrypted data
87never goes out over the network.</li>
88<li><strong>Multimedia applications:</strong> Codecs for processing sounds, images, and movies
89can be added to the browser in a Native Client module.</li>
90<li><strong>Games:</strong> Native Client lets web applications run at close to native
91speed, reuse existing multithreaded/multicore C/C++ code bases, and
92access low-latency audio, networking APIs, and OpenGL ES with programmable
93shaders. Native Client is a natural fit for running a physics engine or
94artificial intelligence module that powers a sophisticated web game.
95Native Client also enables applications to run unchanged across
96many platforms.</li>
97<li><strong>Any application that requires acceleration</strong>: Native Client fits seamlessly
98into web applications&#8212;it&#8217;s up to you to decide to what extent to use it.
99Use of Native Client covers the full spectrum from complete applications to
jmedleyd80305562014-08-25 16:41:52100small optimized routines that accelerate vital parts of web applications.</li>
[email protected]bde3d5d2014-01-23 19:26:04101</ul>
[email protected]c3c19f12014-08-06 18:01:43102<h2 id="how-native-client-works"><span id="link-how-nacl-works"></span>How Native Client works</h2>
jmedleyd80305562014-08-25 16:41:52103<p>Native Client is an umbrella name for a set of related software components that
104provide a way to develop C/C++ applications and run them securely on the web.</p>
[email protected]bde3d5d2014-01-23 19:26:04105<p>At a high level, Native Client consists of:</p>
106<ul class="small-gap">
jmedleyd80305562014-08-25 16:41:52107<li><strong>Toolchains</strong>: Collections of development tools (compilers, linkers, etc.)
[email protected]bde3d5d2014-01-23 19:26:04108that transform C/C++ code to Native Client modules.</li>
109<li><strong>Runtime components</strong>: components embedded in the browser or other
110host platforms that allow execution of Native Client modules
111securely and efficiently.</li>
112</ul>
113<p>The following diagram shows how these components interact:</p>
114<img alt="/native-client/images/nacl-pnacl-component-diagram.png" src="/native-client/images/nacl-pnacl-component-diagram.png" />
115<p>The left side of the diagram shows how to use Portable Native Client
116(PNaCl, pronounced &#8220;pinnacle&#8221;). Developers use the PNaCl toolchain
117to produce a single, portable (<strong>pexe</strong>) module. At runtime, a translator
118built into the browser translates the pexe into native code for the
jmedleyd80305562014-08-25 16:41:52119relevant client architecture. Translation occurs before any code is executed.</p>
120<p>The right side of the diagram shows how to use (non-portable) Native Client.
121Developers use a nacl-gcc based toolchain to produce multiple
[email protected]bde3d5d2014-01-23 19:26:04122architecture-dependent (<strong>nexe</strong>) modules, which are packaged into an
123application. At runtime, the browser decides which nexe to load based
124on the architecture of the client machine.</p>
[email protected]bde3d5d2014-01-23 19:26:04125<h3 id="security">Security</h3>
126<p>Since Native Client permits the execution of native code on client machines,
127special security measures have to be implemented:</p>
128<ul class="small-gap">
129<li>The NaCl sandbox ensures that code accesses system resources only through
130safe, whitelisted APIs, and operates within its limits without attempting to
131interfere with other code running either within the browser or outside it.</li>
132<li>The NaCl validator statically analyzes code prior to running it
133to make sure it only uses code and data patterns that are permitted and safe.</li>
134</ul>
135<p>The above security measures are in addition to the existing sandbox in the
136Chrome browser&#8212;the Native Client module always executes in a process with
137restricted permissions. The only interaction between this process and the
138outside world is through sanctioned browser interfaces. Because of the
139combination of the NaCl sandbox and the Chrome sandbox, we say that
140Native Client employs a double sandbox design.</p>
[email protected]bde3d5d2014-01-23 19:26:04141<h3 id="portability">Portability</h3>
142<p>Portable Native Client (PNaCl, prounounced &#8220;pinnacle&#8221;) employs state-of-the-art
143compiler technology to compile C/C++ source code to a portable bitcode
144executable (<strong>pexe</strong>). PNaCl bitcode is an OS- and architecture-independent
145format that can be freely distributed on the web and <a class="reference internal" href="#link-nacl-in-web-apps"><em>embedded in web
146applications</em></a>.</p>
147<p>The PNaCl translator is a component embedded in the Chrome browser; its task is
148to run pexe modules. Internally, the translator compiles a pexe to a nexe
149(a native executable for the client platform&#8217;s architecture), and then executes
150the nexe within the Native Client sandbox as described above. It also uses
151intelligent caching to avoid re-compiling the pexe if it was previously compiled
152on the client&#8217;s browser.</p>
153<p>Native Client also supports the execution of nexe modules directly in the
154browser. However, since nexes contain architecture-specific machine code,
155they are not allowed to be distributed on the open web&#8212;they can only be
156used as part of applications and extensions that are installed from the
157Chrome Web Store.</p>
158<p>For more details on the difference between NaCl and PNaCl, see
159<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:43160<h3 id="toolchains"><span id="id1"></span>Toolchains</h3>
[email protected]bde3d5d2014-01-23 19:26:04161<p>A toolchain is a set of tools used to create an application from a set of
162source files. In the case of Native Client, a toolchain consists of a compiler,
163linker, assembler and other tools that are used to convert an
164application written in C/C++ into a module that is loadable by the browser.</p>
165<p>The Native Client SDK provides two toolchains:</p>
166<ul class="small-gap">
167<li>a <strong>PNaCl toolchain</strong> for generating portable NaCl modules (pexe files)</li>
168<li>a <strong>gcc-based toolchain (nacl-gcc)</strong> for generating non-portable NaCl modules
169(nexe files)</li>
170</ul>
171<p>The PNaCl toolchain is recommended for most applications. The nacl-gcc
172toolchain should only be used for applications that will not be distributed
173on the open web.</p>
[email protected]c3c19f12014-08-06 18:01:43174<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:04175<p id="application-files">A Native Client application consists of a set of files:</p>
176<ul class="small-gap">
177<li><strong>HTML</strong>, <strong>CSS</strong>, and <strong>JavaScript</strong> files, as in any modern web
178application. The JavaScript code is responsible for communicating with the
179NaCl module.</li>
180<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
181browser resources.</li>
182<li>A Native Client <strong>manifest</strong> file that specifies the pexe to load, along with
183some loading options. This manifest file is embedded into the HTML page
184through an <code>&lt;embed&gt;</code> tag, as shown in the figure below.</li>
185</ul>
186<img alt="/native-client/images/nacl-in-a-web-app.png" src="/native-client/images/nacl-in-a-web-app.png" />
187<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:43188<h3 id="pepper-plugin-api"><span id="link-pepper"></span>Pepper Plugin API</h3>
[email protected]bde3d5d2014-01-23 19:26:04189<p>The Pepper Plugin API (PPAPI), called <strong>Pepper</strong> for convenience, is an
190open-source, cross-platform C/C++ API for web browser plugins. From the point
191of view of Native Client, Pepper allows a C/C++ module to communicate with
192the hosting browser and get access to system-level functions in a safe and
193portable way. One of the security constraints in Native Client is that modules
194cannot make any OS-level calls directly. Pepper provides analogous APIs that
195modules can target instead.</p>
196<p>You can use the Pepper APIs to gain access to the full array of browser
197capabilities, including:</p>
198<ul class="small-gap">
199<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>
200<li><a class="reference internal" href="/native-client/devguide/coding/file-io.html"><em>Doing file I/O</em></a>.</li>
201<li><a class="reference internal" href="/native-client/devguide/coding/audio.html"><em>Playing audio</em></a>.</li>
202<li><a class="reference internal" href="/native-client/devguide/coding/3D-graphics.html"><em>Rendering 3D graphics</em></a>.</li>
203</ul>
204<p>Pepper includes both a C API and a C++ API. The C++ API is a set of bindings
205written on top of the C API. For additional information about Pepper, see
206<a class="reference external" href="http://code.google.com/p/ppapi/wiki/Concepts">Pepper Concepts</a>.</p>
[email protected]bde3d5d2014-01-23 19:26:04207<h2 id="versioning">Versioning</h2>
208<p>Chrome is released on a six week cycle, and developer versions of Chrome are
209pushed to the public beta channel three weeks before each release. As with any
210software, each release of Chrome may include changes to Native Client and the
211Pepper interfaces that may require modification to existing applications.
212However, modules compiled for one version of Pepper/Chrome should work with
[email protected]2547c912014-04-30 20:45:02213subsequent versions of Pepper/Chrome. The SDK includes multiple versions of the
214Pepper APIs to help developers make adjustments to API changes and take
215advantage 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:04216<h2 id="where-to-start">Where to start</h2>
217<p>The <a class="reference internal" href="/native-client/quick-start.html"><em>Quick Start</em></a> document provides links to downloads and
218documentation that should help you get started with developing and distributing
219Native Client applications.</p>
[email protected]c3c19f12014-08-06 18:01:43220</section>
[email protected]bde3d5d2014-01-23 19:26:04221
222{{/partials.standard_nacl_article}}