native client: accelerating web applications
DESCRIPTION
Some applications require high-performance client-side computation. Native Client is a technology for running native code in web applications, with the goal of maintaining the browser neutrality, OS portability, and safety that people expect from web apps. This talk will give a brief overview of the architecture of Native Client. We'll then look at some specific example applications as well as strategies for how to use native code to handle compute intensive tasks within web applications using SRPC, Shared Memory and NPAPI. Watch a video at http://www.bestechvideos.com/2009/06/04/google-i-o-2009-using-native-code-to-build-compute-intensive-web-applicationsTRANSCRIPT
![Page 1: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/1.jpg)
![Page 2: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/2.jpg)
Native Client: Accelerating Web Applications
Brad Chen, David Sehr, Nicholas Fullagar28 May 2009
![Page 3: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/3.jpg)
Why Native Code?
Close the gap between desktop and web apps...PerformanceChoice of programming languageLeverage legacy code
… but do not sacrificePortabilitySafety
![Page 4: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/4.jpg)
What we mean by “Performance”
Key performance features includePOSIX-like thread supportStraightforward access to vector instructionsHand-coded assembler
Substantially all the CPU performanceof desktop applications
![Page 5: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/5.jpg)
What does it mean for the Web?
Desktop CPU performance will enable Web apps with:Safer multimedia codecsReal-time audio and video synthesisReal-time physics simulationsLocal audio/video analysis and recognitionMultimedia editorsFlexible, high-throughput cryptographyApplication-specific data compression…
Together with O3D we will enable:High quality gamesCAD applications…
![Page 6: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/6.jpg)
The Life of a NaCl-Enabled Web App
![Page 7: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/7.jpg)
The Life of a NaCl-Enabled Web App
![Page 8: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/8.jpg)
The Life of a NaCl-Enabled Web App
<html>...<object src=”game.nexe”>
![Page 9: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/9.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 10: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/10.jpg)
The Life of a NaCl-Enabled Web App
<html>...<embed src=”game.nexe”>
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 11: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/11.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 12: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/12.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 13: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/13.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
!!!
![Page 14: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/14.jpg)
The Life of a NaCl-Enabled Web App
<html>...<embed src=”game.nexe”>
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 15: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/15.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 16: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/16.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 17: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/17.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 18: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/18.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
<html>...<object src=”game.nexe”>
![Page 19: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/19.jpg)
The Life of a NaCl-Enabled Web App
Native ClientHelper
![Page 20: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/20.jpg)
Native Client Security
![Page 21: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/21.jpg)
Native Client Security
Our goal: make native code at least as safe as JavaScript. Steps we’ve taken include:
Multiple internal security reviewsOpen sourced our system; encouraged critical public reviewPublished a peer reviewed technical paper in the IEEE Symposium on Security and Privacy
See http://oakland09.cs.virginia.edu
Held an Security Contest
![Page 22: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/22.jpg)
Native Client Security Contest
25 February to 5 May 2009Over 400 teams and 600 individuals participated22 valid issues submittedProfile of valid issues:
Inner sandbox (1 + 1 prior to contest)Outer sandbox (not yet enabled)Binary module loaderTrampoline interfaces (1 – direction flag)IMC communications interfaceNPAPI interface (3 – including same origin issues)System calls (1 – unmap / map)Browser integration (8)
![Page 23: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/23.jpg)
Example Security Contest Issues
#50: data16 prefix with two-byte control flow instructions
We had assumed data16 only applied to data arithmetic, and was safe with all two-byte instructionsProblem: data16 also impacts some address calculations
Solution: disallow data16 for most two-byte instructions
Solution: protect bottom 64KB of the address space
#51: stack-smashing attack via eflags direction flag
eflags state was preserved across trusted runtime calls
Problem: Some Windows APIs use rep movs without checking flag direction
Solution: use cld to clear flags during trusted runtime calls
![Page 24: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/24.jpg)
NaCl Today and Tomorrow
![Page 25: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/25.jpg)
Native Client Research Release
TodayNPAPI pluginx86-32 onlyRaster graphicsMirrored public SVN
![Page 26: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/26.jpg)
Native Client Developer Release…
TodayNPAPI pluginx86-32 onlyRaster graphicsMirrored public SVN
The FutureBuilt into browser
Web WorkersRevised NPAPI
x86-32, x86-64, ARMO3D integrationDevelop off public SVN
![Page 27: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/27.jpg)
Preview: Native Web Workers
Web Workers: Simple threading model for the browser No shared data, no DOM accesspostMessage, XMLHttpRequest, openDatabaseSee specification at http://whatwg.org/ww
Goals of Native Web Workers:Support workers in C, C++, Ruby, ...Maintain the simplicity of the Web Worker modelSupport 'low frequency' applications
![Page 28: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/28.jpg)
Demo: Native Web Workers
![Page 29: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/29.jpg)
Preview: Revised NPAPI
Plugin use today is very limitedWell known security issuesPop-up boxes asking unreasonable questionsAPI is under-specifiedWeb portability falls apart
Creating a brighter future for pluginsAddress known misfeatures of NPAPI, ActiveXAvoid limitations of Web Workers
High frequency applicationsReal-time applicationsSynchronous DOM access
![Page 30: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/30.jpg)
An H.264 Video Player
![Page 31: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/31.jpg)
Porting a H.264 transcoder from Linux
Based on a Google internal H.264 decoderOriginal test code decoded H.264 into raw frames20-line change to create simple video player230-lines to add audio and frame-rate control
Porting a Linux application to Native Client can be very simple.
![Page 32: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/32.jpg)
g264_unittest.c
int main(int argc, char *argv[]) {...#ifdef __native_client__int r = nacl_multimedia_init(NACL_SUBSYSTEM_VIDEO);if (-1 == r) {printf("Multimedia system failed to initialize! errno: %d\n", errno);exit(-1);}r = nacl_video_init(NACL_VIDEO_FORMAT_RGB, image_width, image_height);if (-1 == r) {printf("Video subsystem failed to initialize! errno; %d\n", errno);exit(-1);}write_file_ptr = NULL;#elsewrite_file_ptr = fopen("output.yuv", "wb");#endif...
![Page 33: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/33.jpg)
g264_unittest.c
...#ifdef __native_client__YV12toRGB24_generic(img->luma_sample, img->luma_width,img->chroma_sample[0], img->chroma_sample[1],img->chroma_width, RGB24_out,img->luma_width, img->luma_height,img->luma_width);
r = nacl_video_update(RGB24_out);if (-1 == r) {printf("nacl_video_update() returned %d\n", errno);}#elsefwrite(img->luma_sample, frame_size, 1, write_file_ptr);fwrite(img->chroma_sample[0], frame_size>>2, 1, write_file_ptr);fwrite(img->chroma_sample[1], frame_size>>2, 1, write_file_ptr);#endif...
![Page 34: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/34.jpg)
Demo: H.264 Video Decoder
![Page 35: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/35.jpg)
Demo: Native Client Darkroom
![Page 36: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/36.jpg)
Contribute
Please visit us at http://code.google.com/p/nativeclientWrite new appsPort existing C/C++ librariesHelp us test
![Page 37: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/37.jpg)
Questions?
On the web: http://code.google.com/p/nativeclient
Today at Google IO:Client Fireside Chat: 1pm
Native Client Office Hours: 3pm
Related projects:Chromium: http://dev.chromium.org
O3D: http://code.google.com/p/o3d
![Page 38: Native Client: Accelerating Web Applications](https://reader033.vdocuments.us/reader033/viewer/2022051108/5466a585b4af9ff5748b47e7/html5/thumbnails/38.jpg)