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